From 5073fb5685c8cce4e6107d2549249cbccbbaff29 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Wed, 9 Mar 2022 00:07:31 +0000 Subject: [PATCH] Fix BindGroupLayoutEntry validation message for no bindings types set Fixed: dawn:1318 Change-Id: I9c5953d77c9758f0814fa50a98f5f813daf5e705 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/83061 Reviewed-by: Brandon Jones Commit-Queue: Austin Eng --- src/dawn/native/BindGroupLayout.cpp | 4 +++ .../validation/BindGroupValidationTests.cpp | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/dawn/native/BindGroupLayout.cpp b/src/dawn/native/BindGroupLayout.cpp index 9f5e151f5c..f535545466 100644 --- a/src/dawn/native/BindGroupLayout.cpp +++ b/src/dawn/native/BindGroupLayout.cpp @@ -141,6 +141,10 @@ namespace dawn::native { bindingType = BindingInfoType::ExternalTexture; } + DAWN_INVALID_IF(bindingMemberCount == 0, + "BindGroupLayoutEntry had none of buffer, sampler, texture, " + "storageTexture, or externalTexture set"); + DAWN_INVALID_IF(bindingMemberCount != 1, "BindGroupLayoutEntry had more than one of buffer, sampler, texture, " "storageTexture, or externalTexture set"); diff --git a/src/dawn/tests/unittests/validation/BindGroupValidationTests.cpp b/src/dawn/tests/unittests/validation/BindGroupValidationTests.cpp index 95ffef1871..87a2c3c763 100644 --- a/src/dawn/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/BindGroupValidationTests.cpp @@ -964,6 +964,33 @@ TEST_F(BindGroupLayoutValidationTest, DynamicAndTypeCompatibility) { }); } +// Test that it is invalid to create a BGL with more than one binding type set. +TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutEntryTooManySet) { + wgpu::BindGroupLayoutEntry entry = {}; + entry.binding = 0; + entry.visibility = wgpu::ShaderStage::Fragment; + entry.buffer.type = wgpu::BufferBindingType::Uniform; + entry.sampler.type = wgpu::SamplerBindingType::Filtering; + + wgpu::BindGroupLayoutDescriptor descriptor; + descriptor.entryCount = 1; + descriptor.entries = &entry; + ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&descriptor), + testing::HasSubstr("had more than one of")); +} + +// Test that it is invalid to create a BGL with none one of buffer, +// sampler, texture, storageTexture, or externalTexture set. +TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutEntryNoneSet) { + wgpu::BindGroupLayoutEntry entry = {}; + + wgpu::BindGroupLayoutDescriptor descriptor; + descriptor.entryCount = 1; + descriptor.entries = &entry; + ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&descriptor), + testing::HasSubstr("had none of")); +} + // This test verifies that visibility of bindings in BindGroupLayout can be none TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutVisibilityNone) { utils::MakeBindGroupLayout(device,