From 3a5e765f233a95011ff34c6e8bcc9c6b0f33180b Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 21 Nov 2018 09:47:19 +0000 Subject: [PATCH] BindGroupLayout: Fix off-by-one kMaxBindingsPerGroup validation BUG=chromium:906370 Change-Id: I95659856398523931b8aacf1e9a9239ac85f1156 Reviewed-on: https://dawn-review.googlesource.com/c/2567 Reviewed-by: Kai Ninomiya Reviewed-by: Shaobo Yan Reviewed-by: Corentin Wallez Commit-Queue: Corentin Wallez --- src/dawn_native/BindGroupLayout.cpp | 2 +- .../validation/BindGroupValidationTests.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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} + })); +}