diff --git a/src/dawn/native/EncodingContext.h b/src/dawn/native/EncodingContext.h index 006a47f6e06..be8a22ace89 100644 --- a/src/dawn/native/EncodingContext.h +++ b/src/dawn/native/EncodingContext.h @@ -115,11 +115,15 @@ class EncodingContext { // change. DAWN_INVALID_IF(encoder->IsError(), "Recording in an error %s.", encoder); - // The top level encoder was used when a pass encoder was current. - DAWN_ASSERT(mCurrentEncoder != mTopLevelEncoder); + // This happens when the CommandEncoder is used while a pass is open. + DAWN_INVALID_IF(encoder == mTopLevelEncoder, + "Recording in %s which is locked while %s is open.", encoder, + mCurrentEncoder); + + // The remaining case is when an encoder is ended but we still try to encode + // commands in it. return DAWN_VALIDATION_ERROR( - "Command cannot be recorded while %s is locked and %s is currently open.", - mTopLevelEncoder, mCurrentEncoder); + "Commands cannot be recorded in %s which has already been ended.", encoder); } } return {}; diff --git a/src/dawn/tests/unittests/validation/CommandBufferValidationTests.cpp b/src/dawn/tests/unittests/validation/CommandBufferValidationTests.cpp index 4991b781471..23ba064b7fe 100644 --- a/src/dawn/tests/unittests/validation/CommandBufferValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/CommandBufferValidationTests.cpp @@ -442,5 +442,14 @@ TEST_F(CommandBufferValidationTest, EncodeAfterDeviceDestroyed) { } } +// Test that an error is produced when encoding happens after ending a pass. +TEST_F(CommandBufferValidationTest, EncodeAfterEndingPass) { + wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); + wgpu::ComputePassEncoder pass = encoder.BeginComputePass(); + pass.End(); + pass.PushDebugGroup("Foo"); + ASSERT_DEVICE_ERROR(encoder.Finish()); +} + } // anonymous namespace } // namespace dawn