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");
|
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
|
// Implementation of the API's command recording methods
|
||||||
|
|
||||||
ComputePassEncoderBase* CommandBufferBuilder::BeginComputePass() {
|
ComputePassEncoderBase* CommandBufferBuilder::BeginComputePass() {
|
||||||
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
||||||
|
|
||||||
mEncodingState = EncodingState::ComputePass;
|
mEncodingState = EncodingState::ComputePass;
|
||||||
|
@ -603,6 +614,10 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderPassEncoderBase* CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
|
RenderPassEncoderBase* CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
|
||||||
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
BeginRenderPassCmd* cmd = mAllocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
|
BeginRenderPassCmd* cmd = mAllocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
|
||||||
new (cmd) BeginRenderPassCmd;
|
new (cmd) BeginRenderPassCmd;
|
||||||
cmd->info = info;
|
cmd->info = info;
|
||||||
|
@ -616,6 +631,10 @@ namespace dawn_native {
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint32_t destinationOffset,
|
uint32_t destinationOffset,
|
||||||
uint32_t size) {
|
uint32_t size) {
|
||||||
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CopyBufferToBufferCmd* copy =
|
CopyBufferToBufferCmd* copy =
|
||||||
mAllocator.Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
|
mAllocator.Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
|
||||||
new (copy) CopyBufferToBufferCmd;
|
new (copy) CopyBufferToBufferCmd;
|
||||||
|
@ -638,6 +657,10 @@ namespace dawn_native {
|
||||||
uint32_t depth,
|
uint32_t depth,
|
||||||
uint32_t level,
|
uint32_t level,
|
||||||
uint32_t slice) {
|
uint32_t slice) {
|
||||||
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (rowPitch == 0) {
|
if (rowPitch == 0) {
|
||||||
rowPitch = ComputeDefaultRowPitch(texture, width);
|
rowPitch = ComputeDefaultRowPitch(texture, width);
|
||||||
}
|
}
|
||||||
|
@ -670,6 +693,10 @@ namespace dawn_native {
|
||||||
BufferBase* buffer,
|
BufferBase* buffer,
|
||||||
uint32_t bufferOffset,
|
uint32_t bufferOffset,
|
||||||
uint32_t rowPitch) {
|
uint32_t rowPitch) {
|
||||||
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (rowPitch == 0) {
|
if (rowPitch == 0) {
|
||||||
rowPitch = ComputeDefaultRowPitch(texture, width);
|
rowPitch = ComputeDefaultRowPitch(texture, width);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,8 @@ namespace dawn_native {
|
||||||
MaybeError ValidateComputePass();
|
MaybeError ValidateComputePass();
|
||||||
MaybeError ValidateRenderPass(RenderPassDescriptorBase* renderPass);
|
MaybeError ValidateRenderPass(RenderPassDescriptorBase* renderPass);
|
||||||
|
|
||||||
|
MaybeError ValidateCanRecordTopLevelCommands() const;
|
||||||
|
|
||||||
void ConsumeError(ErrorData* error);
|
void ConsumeError(ErrorData* error);
|
||||||
|
|
||||||
CommandAllocator mAllocator;
|
CommandAllocator mAllocator;
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace dawn_native {
|
||||||
|
|
||||||
MaybeError ProgrammablePassEncoder::ValidateCanRecordCommands() const {
|
MaybeError ProgrammablePassEncoder::ValidateCanRecordCommands() const {
|
||||||
if (mAllocator == nullptr) {
|
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;
|
return nullptr;
|
||||||
|
|
|
@ -31,6 +31,10 @@ namespace dawn_native {
|
||||||
uint32_t instanceCount,
|
uint32_t instanceCount,
|
||||||
uint32_t firstVertex,
|
uint32_t firstVertex,
|
||||||
uint32_t firstInstance) {
|
uint32_t firstInstance) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DrawArraysCmd* draw = mAllocator->Allocate<DrawArraysCmd>(Command::DrawArrays);
|
DrawArraysCmd* draw = mAllocator->Allocate<DrawArraysCmd>(Command::DrawArrays);
|
||||||
new (draw) DrawArraysCmd;
|
new (draw) DrawArraysCmd;
|
||||||
draw->vertexCount = vertexCount;
|
draw->vertexCount = vertexCount;
|
||||||
|
@ -43,6 +47,10 @@ namespace dawn_native {
|
||||||
uint32_t instanceCount,
|
uint32_t instanceCount,
|
||||||
uint32_t firstIndex,
|
uint32_t firstIndex,
|
||||||
uint32_t firstInstance) {
|
uint32_t firstInstance) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DrawElementsCmd* draw = mAllocator->Allocate<DrawElementsCmd>(Command::DrawElements);
|
DrawElementsCmd* draw = mAllocator->Allocate<DrawElementsCmd>(Command::DrawElements);
|
||||||
new (draw) DrawElementsCmd;
|
new (draw) DrawElementsCmd;
|
||||||
draw->indexCount = indexCount;
|
draw->indexCount = indexCount;
|
||||||
|
@ -63,6 +71,10 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPassEncoderBase::SetStencilReference(uint32_t reference) {
|
void RenderPassEncoderBase::SetStencilReference(uint32_t reference) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetStencilReferenceCmd* cmd =
|
SetStencilReferenceCmd* cmd =
|
||||||
mAllocator->Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
|
mAllocator->Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
|
||||||
new (cmd) SetStencilReferenceCmd;
|
new (cmd) SetStencilReferenceCmd;
|
||||||
|
@ -70,6 +82,10 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPassEncoderBase::SetBlendColor(float r, float g, float b, float a) {
|
void RenderPassEncoderBase::SetBlendColor(float r, float g, float b, float a) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetBlendColorCmd* cmd = mAllocator->Allocate<SetBlendColorCmd>(Command::SetBlendColor);
|
SetBlendColorCmd* cmd = mAllocator->Allocate<SetBlendColorCmd>(Command::SetBlendColor);
|
||||||
new (cmd) SetBlendColorCmd;
|
new (cmd) SetBlendColorCmd;
|
||||||
cmd->r = r;
|
cmd->r = r;
|
||||||
|
@ -82,6 +98,10 @@ namespace dawn_native {
|
||||||
uint32_t y,
|
uint32_t y,
|
||||||
uint32_t width,
|
uint32_t width,
|
||||||
uint32_t height) {
|
uint32_t height) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetScissorRectCmd* cmd = mAllocator->Allocate<SetScissorRectCmd>(Command::SetScissorRect);
|
SetScissorRectCmd* cmd = mAllocator->Allocate<SetScissorRectCmd>(Command::SetScissorRect);
|
||||||
new (cmd) SetScissorRectCmd;
|
new (cmd) SetScissorRectCmd;
|
||||||
cmd->x = x;
|
cmd->x = x;
|
||||||
|
@ -91,7 +111,9 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPassEncoderBase::SetIndexBuffer(BufferBase* buffer, uint32_t offset) {
|
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);
|
SetIndexBufferCmd* cmd = mAllocator->Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
|
||||||
new (cmd) SetIndexBufferCmd;
|
new (cmd) SetIndexBufferCmd;
|
||||||
|
@ -103,7 +125,9 @@ namespace dawn_native {
|
||||||
uint32_t count,
|
uint32_t count,
|
||||||
BufferBase* const* buffers,
|
BufferBase* const* buffers,
|
||||||
uint32_t const* offsets) {
|
uint32_t const* offsets) {
|
||||||
// TODO(kainino@chromium.org): validation
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetVertexBuffersCmd* cmd =
|
SetVertexBuffersCmd* cmd =
|
||||||
mAllocator->Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
|
mAllocator->Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
|
||||||
|
|
Loading…
Reference in New Issue