From 1184e46f873bc595502e9f2ade13cbd6cf5c28f3 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Thu, 19 Jul 2018 09:52:31 -0400 Subject: [PATCH] Fix bind group binding ID validation. (#227) * Fix bind group binding ID validation. Use the binding, not the iterator index. --- src/backend/BindGroupLayout.cpp | 3 ++- .../unittests/validation/BindGroupValidationTests.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/BindGroupLayout.cpp b/src/backend/BindGroupLayout.cpp index 62abb97959..08c0009601 100644 --- a/src/backend/BindGroupLayout.cpp +++ b/src/backend/BindGroupLayout.cpp @@ -36,7 +36,8 @@ namespace backend { DAWN_TRY(ValidateShaderStageBit(binding.visibility)); DAWN_TRY(ValidateBindingType(binding.type)); - DAWN_TRY_ASSERT(!bindingsSet[i], "some binding index was specified more than once"); + DAWN_TRY_ASSERT(!bindingsSet[binding.binding], + "some binding index was specified more than once"); bindingsSet.set(binding.binding); } return {}; diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index 89ed87bbf1..3963f63569 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -122,3 +122,13 @@ TEST_F(BindGroupValidationTest, BindGroupLayoutCache) { // Caching should cause these to be the same. ASSERT_EQ(layout1.Get(), layout2.Get()); } + +// This test verifies that the BindGroupLayout bindings are correctly validated, even if the +// binding ids are out-of-order. +TEST_F(BindGroupValidationTest, BindGroupBinding) { + auto layout = utils::MakeBindGroupLayout( + device, { + {1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}, + {0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}, + }); +}