Check bindgroup validity first in SetBindGroup

bindgroup->GetLayout() was called before checking the bindgroup is an
error, causing an assert to fire in Debug. Adds a regression unittest.

BUG=dawn:196

Change-Id: I58e95879a7f2a7cf5c47c7b228f7e3b5bb72d8ea
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9560
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2019-07-30 06:49:09 +00:00 committed by Commit Bot service account
parent 34f8bd8c48
commit 7b57c5bb77
2 changed files with 13 additions and 2 deletions

View File

@ -75,8 +75,6 @@ namespace dawn_native {
uint32_t dynamicOffsetCount,
const uint64_t* dynamicOffsets) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
const BindGroupLayoutBase* layout = group->GetLayout();
DAWN_TRY(GetDevice()->ValidateObject(group));
if (groupIndex >= kMaxBindGroups) {
@ -84,6 +82,7 @@ namespace dawn_native {
}
// Dynamic offsets count must match the number required by the layout perfectly.
const BindGroupLayoutBase* layout = group->GetLayout();
if (layout->GetDynamicBufferCount() != dynamicOffsetCount) {
return DAWN_VALIDATION_ERROR("dynamicOffset count mismatch");
}

View File

@ -729,3 +729,15 @@ TEST_F(SetBindGroupValidationTest, BindingSizeOutOfBoundDynamicStorageBuffer) {
TestComputePassBindGroup(bindGroup, offsets.data(), 2, false);
}
// Test that an error is produced (and no ASSERTs fired) when using an error bindgroup in
// SetBindGroup
TEST_F(SetBindGroupValidationTest, ErrorBindGroup) {
// Bindgroup creation fails because not all bindings are specified.
dawn::BindGroup bindGroup;
ASSERT_DEVICE_ERROR(bindGroup = utils::MakeBindGroup(device, mBindGroupLayout, {}));
TestRenderPassBindGroup(bindGroup, nullptr, 0, false);
TestComputePassBindGroup(bindGroup, nullptr, 0, false);
}