diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index b9306b7501..0098fa6708 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -35,7 +35,7 @@ namespace dawn_native { DAWN_TRY(ValidateShaderStageBit(binding.visibility)); DAWN_TRY(ValidateBindingType(binding.type)); - if (binding.binding > kMaxBindingsPerGroup) { + if (binding.binding >= kMaxBindingsPerGroup) { return DAWN_VALIDATION_ERROR("some binding index exceeds the maximum value"); } if (bindingsSet[binding.binding]) { diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index 931b64dfc3..2937987841 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -13,11 +13,14 @@ // limitations under the License. #include "tests/unittests/validation/ValidationTest.h" + +#include "common/Constants.h" #include "utils/DawnHelpers.h" class BindGroupValidationTest : public ValidationTest { }; +// Tests constraints on the buffer view offset for bind groups. TEST_F(BindGroupValidationTest, BufferViewOffset) { auto layout = utils::MakeBindGroupLayout( device, { @@ -129,3 +132,16 @@ TEST_F(BindGroupValidationTest, BindGroupBinding) { {0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}, }); } + +// Tests setting OOB checks for kMaxBindingsPerGroup in bind group layouts. +TEST_F(BindGroupValidationTest, BindGroupLayoutBindingOOB) { + // Checks that kMaxBindingsPerGroup - 1 is valid. + utils::MakeBindGroupLayout(device, { + {kMaxBindingsPerGroup - 1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer} + }); + + // Checks that kMaxBindingsPerGroup is OOB + ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout(device, { + {kMaxBindingsPerGroup, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer} + })); +}