diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index a1da4c6e3e..98f9373a57 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -513,7 +513,6 @@ namespace dawn_native { uint32_t width = 0; uint32_t height = 0; Ref attachmentState; - mEncodingContext.WillBeginRenderPass(); bool success = mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { uint32_t sampleCount = 0; @@ -523,6 +522,7 @@ namespace dawn_native { ASSERT(width > 0 && height > 0 && sampleCount > 0); + mEncodingContext.WillBeginRenderPass(); BeginRenderPassCmd* cmd = allocator->Allocate(Command::BeginRenderPass); diff --git a/src/tests/unittests/validation/CommandBufferValidationTests.cpp b/src/tests/unittests/validation/CommandBufferValidationTests.cpp index 67eda7e442..bf97c7cbe1 100644 --- a/src/tests/unittests/validation/CommandBufferValidationTests.cpp +++ b/src/tests/unittests/validation/CommandBufferValidationTests.cpp @@ -146,6 +146,31 @@ TEST_F(CommandBufferValidationTest, BeginComputePassBeforeEndPreviousPass) { } } +// Test that beginning a render pass before ending the previous pass causes an error. +TEST_F(CommandBufferValidationTest, BeginRenderPassBeforeEndPreviousPass) { + DummyRenderPass dummyRenderPass(device); + + // Beginning a render pass before ending the render pass causes an error. + { + wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); + wgpu::RenderPassEncoder renderPass1 = encoder.BeginRenderPass(&dummyRenderPass); + wgpu::RenderPassEncoder renderPass2 = encoder.BeginRenderPass(&dummyRenderPass); + renderPass2.EndPass(); + renderPass1.EndPass(); + ASSERT_DEVICE_ERROR(encoder.Finish()); + } + + // Beginning a compute pass before ending a compute pass causes an error. + { + wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); + wgpu::ComputePassEncoder computePass = encoder.BeginComputePass(); + wgpu::RenderPassEncoder renderPass = encoder.BeginRenderPass(&dummyRenderPass); + renderPass.EndPass(); + computePass.EndPass(); + ASSERT_DEVICE_ERROR(encoder.Finish()); + } +} + // Test that encoding command after a successful finish produces an error TEST_F(CommandBufferValidationTest, CallsAfterASuccessfulFinish) { // A buffer that can be used in CopyBufferToBuffer