Add InjectValidationError to command encoder

Needed to implement bytesPerRow/rowsPerImage validation
in Blink.

Bug: dawn:566
Change-Id: I60e9ebd57e40d5043e7277cdc560cbf673bc2576
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/32582
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2020-11-14 01:24:03 +00:00 committed by Commit Bot service account
parent b38a9c3ee7
commit 464aaeb558
6 changed files with 32 additions and 2 deletions

View File

@ -356,6 +356,13 @@
{"name": "copy size", "type": "extent 3D", "annotation": "const*"}
]
},
{
"name": "inject validation error",
"args": [
{"name": "message", "type": "char", "annotation": "const*", "length": "strlen"}
],
"TODO": "enga@: Make this a Dawn extension"
},
{
"name": "insert debug marker",
"args": [

View File

@ -712,6 +712,12 @@ namespace dawn_native {
});
}
void CommandEncoder::InjectValidationError(const char* message) {
if (mEncodingContext.CheckCurrentEncoder(this)) {
mEncodingContext.HandleError(InternalErrorType::Validation, message);
}
}
void CommandEncoder::InsertDebugMarker(const char* groupLabel) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
InsertDebugMarkerCmd* cmd =

View File

@ -61,6 +61,7 @@ namespace dawn_native {
const TextureCopyView* destination,
const Extent3D* copySize);
void InjectValidationError(const char* message);
void InsertDebugMarker(const char* groupLabel);
void PopDebugGroup();
void PushDebugGroup(const char* groupLabel);

View File

@ -55,6 +55,8 @@ namespace dawn_native {
void EncodingContext::HandleError(InternalErrorType type, const char* message) {
if (!IsFinished()) {
// Encoding should only generate validation errors.
ASSERT(type == InternalErrorType::Validation);
// If the encoding context is not finished, errors are deferred until
// Finish() is called.
if (!mGotError) {

View File

@ -53,8 +53,7 @@ namespace dawn_native {
return false;
}
template <typename EncodeFunction>
inline bool TryEncode(const ObjectBase* encoder, EncodeFunction&& encodeFunction) {
inline bool CheckCurrentEncoder(const ObjectBase* encoder) {
if (DAWN_UNLIKELY(encoder != mCurrentEncoder)) {
if (mCurrentEncoder != mTopLevelEncoder) {
// The top level encoder was used when a pass encoder was current.
@ -66,6 +65,14 @@ namespace dawn_native {
}
return false;
}
return true;
}
template <typename EncodeFunction>
inline bool TryEncode(const ObjectBase* encoder, EncodeFunction&& encodeFunction) {
if (!CheckCurrentEncoder(encoder)) {
return false;
}
ASSERT(!mWasMovedToIterator);
return !ConsumedError(encodeFunction(&mAllocator));
}

View File

@ -180,3 +180,10 @@ TEST_F(CommandBufferValidationTest, CallsAfterAFailedFinish) {
ASSERT_DEVICE_ERROR(encoder.CopyBufferToBuffer(copyBuffer, 0, copyBuffer, 0, 0));
}
// Test that calling inject validation error produces an error.
TEST_F(CommandBufferValidationTest, InjectValidationError) {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.InjectValidationError("my error");
ASSERT_DEVICE_ERROR(encoder.Finish());
}