diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index a14e53c9fd..7556724d93 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -152,6 +152,10 @@ namespace dawn_native { bindingsSet.insert(bindingNumber); } + if (bindingsSet.size() > kMaxBindingsPerGroup) { + return DAWN_VALIDATION_ERROR("The number of bindings exceeds kMaxBindingsPerGroup."); + } + if (dynamicUniformBufferCount > kMaxDynamicUniformBufferCount) { return DAWN_VALIDATION_ERROR( "The number of dynamic uniform buffer exceeds the maximum value"); diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index b7f0120fb9..2c441d6ed9 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -521,6 +521,28 @@ TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutBindingUnbounded) { wgpu::BindingType::UniformBuffer}}); } +// Test that there can't be more than kMaxBindingPerGroup bindings per group +TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutMaxBindings) { + wgpu::BindGroupLayoutBinding bindings[kMaxBindingsPerGroup + 1]; + + for (uint32_t i = 0; i < kMaxBindingsPerGroup + 1; i++) { + bindings[i].type = wgpu::BindingType::UniformBuffer; + bindings[i].binding = i; + bindings[i].visibility = wgpu::ShaderStage::Compute; + } + + wgpu::BindGroupLayoutDescriptor desc; + desc.bindings = bindings; + + // Control case: kMaxBindingsPerGroup bindings is allowed. + desc.bindingCount = kMaxBindingsPerGroup; + device.CreateBindGroupLayout(&desc); + + // Error case: kMaxBindingsPerGroup + 1 bindings is not allowed. + desc.bindingCount = kMaxBindingsPerGroup + 1; + ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&desc)); +} + // This test verifies that the BindGroupLayout bindings are correctly validated, even if the // binding ids are out-of-order. TEST_F(BindGroupLayoutValidationTest, BindGroupBinding) {