CommandBuffer/PassEncoders: Correctly validate we can record
BUG= Change-Id: I2e2567942544d6c28ad5d948f5f7c5962790341e Reviewed-on: https://dawn-review.googlesource.com/c/2564 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
3a5e765f23
commit
a14a070de0
|
@ -593,9 +593,20 @@ namespace dawn_native {
|
|||
return DAWN_VALIDATION_ERROR("Unfinished render pass");
|
||||
}
|
||||
|
||||
MaybeError CommandBufferBuilder::ValidateCanRecordTopLevelCommands() const {
|
||||
if (mEncodingState != EncodingState::TopLevel) {
|
||||
return DAWN_VALIDATION_ERROR("Command cannot be recorded inside a pass");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Implementation of the API's command recording methods
|
||||
|
||||
ComputePassEncoderBase* CommandBufferBuilder::BeginComputePass() {
|
||||
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
||||
|
||||
mEncodingState = EncodingState::ComputePass;
|
||||
|
@ -603,6 +614,10 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
RenderPassEncoderBase* CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
|
||||
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BeginRenderPassCmd* cmd = mAllocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
|
||||
new (cmd) BeginRenderPassCmd;
|
||||
cmd->info = info;
|
||||
|
@ -616,6 +631,10 @@ namespace dawn_native {
|
|||
BufferBase* destination,
|
||||
uint32_t destinationOffset,
|
||||
uint32_t size) {
|
||||
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
CopyBufferToBufferCmd* copy =
|
||||
mAllocator.Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
|
||||
new (copy) CopyBufferToBufferCmd;
|
||||
|
@ -638,6 +657,10 @@ namespace dawn_native {
|
|||
uint32_t depth,
|
||||
uint32_t level,
|
||||
uint32_t slice) {
|
||||
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rowPitch == 0) {
|
||||
rowPitch = ComputeDefaultRowPitch(texture, width);
|
||||
}
|
||||
|
@ -670,6 +693,10 @@ namespace dawn_native {
|
|||
BufferBase* buffer,
|
||||
uint32_t bufferOffset,
|
||||
uint32_t rowPitch) {
|
||||
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rowPitch == 0) {
|
||||
rowPitch = ComputeDefaultRowPitch(texture, width);
|
||||
}
|
||||
|
|
|
@ -115,6 +115,8 @@ namespace dawn_native {
|
|||
MaybeError ValidateComputePass();
|
||||
MaybeError ValidateRenderPass(RenderPassDescriptorBase* renderPass);
|
||||
|
||||
MaybeError ValidateCanRecordTopLevelCommands() const;
|
||||
|
||||
void ConsumeError(ErrorData* error);
|
||||
|
||||
CommandAllocator mAllocator;
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace dawn_native {
|
|||
|
||||
MaybeError ProgrammablePassEncoder::ValidateCanRecordCommands() const {
|
||||
if (mAllocator == nullptr) {
|
||||
return DAWN_VALIDATION_ERROR("Recording in an already ended computePassEncoder");
|
||||
return DAWN_VALIDATION_ERROR("Recording in an already ended pass encoder");
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -31,6 +31,10 @@ namespace dawn_native {
|
|||
uint32_t instanceCount,
|
||||
uint32_t firstVertex,
|
||||
uint32_t firstInstance) {
|
||||
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
DrawArraysCmd* draw = mAllocator->Allocate<DrawArraysCmd>(Command::DrawArrays);
|
||||
new (draw) DrawArraysCmd;
|
||||
draw->vertexCount = vertexCount;
|
||||
|
@ -43,6 +47,10 @@ namespace dawn_native {
|
|||
uint32_t instanceCount,
|
||||
uint32_t firstIndex,
|
||||
uint32_t firstInstance) {
|
||||
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
DrawElementsCmd* draw = mAllocator->Allocate<DrawElementsCmd>(Command::DrawElements);
|
||||
new (draw) DrawElementsCmd;
|
||||
draw->indexCount = indexCount;
|
||||
|
@ -63,6 +71,10 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
void RenderPassEncoderBase::SetStencilReference(uint32_t reference) {
|
||||
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetStencilReferenceCmd* cmd =
|
||||
mAllocator->Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
|
||||
new (cmd) SetStencilReferenceCmd;
|
||||
|
@ -70,6 +82,10 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
void RenderPassEncoderBase::SetBlendColor(float r, float g, float b, float a) {
|
||||
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetBlendColorCmd* cmd = mAllocator->Allocate<SetBlendColorCmd>(Command::SetBlendColor);
|
||||
new (cmd) SetBlendColorCmd;
|
||||
cmd->r = r;
|
||||
|
@ -82,6 +98,10 @@ namespace dawn_native {
|
|||
uint32_t y,
|
||||
uint32_t width,
|
||||
uint32_t height) {
|
||||
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetScissorRectCmd* cmd = mAllocator->Allocate<SetScissorRectCmd>(Command::SetScissorRect);
|
||||
new (cmd) SetScissorRectCmd;
|
||||
cmd->x = x;
|
||||
|
@ -91,7 +111,9 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
void RenderPassEncoderBase::SetIndexBuffer(BufferBase* buffer, uint32_t offset) {
|
||||
// TODO(kainino@chromium.org): validation
|
||||
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetIndexBufferCmd* cmd = mAllocator->Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
|
||||
new (cmd) SetIndexBufferCmd;
|
||||
|
@ -103,7 +125,9 @@ namespace dawn_native {
|
|||
uint32_t count,
|
||||
BufferBase* const* buffers,
|
||||
uint32_t const* offsets) {
|
||||
// TODO(kainino@chromium.org): validation
|
||||
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetVertexBuffersCmd* cmd =
|
||||
mAllocator->Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
|
||||
|
|
Loading…
Reference in New Issue