EncodingContext: Fix ASSERT when encoding on ended pass. When ValidateCanEncodeOn was processing the State::Open case, it ASSERTed that we were in the case where the top level encoder is used while locked, while this code path could also be reached when encoding on an ended pass. Adds a regression test. Bug: 361717709, 361992469 Change-Id: I7d088cb46e092b122516834e033258e7603e63ae Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/204034 Reviewed-by: Brandon Jones <bajones@google.com> Reviewed-by: Loko Kung <lokokung@google.com> Reviewed-by: Brandon Jones <bajones@chromium.org> Auto-Submit: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/native/EncodingContext.h b/src/dawn/native/EncodingContext.h index 006a47f..be8a22a 100644 --- a/src/dawn/native/EncodingContext.h +++ b/src/dawn/native/EncodingContext.h
@@ -115,11 +115,15 @@ // 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 4991b78..23ba064 100644 --- a/src/dawn/tests/unittests/validation/CommandBufferValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/CommandBufferValidationTests.cpp
@@ -442,5 +442,14 @@ } } +// 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