diff --git a/src/dawn_native/BindGroup.cpp b/src/dawn_native/BindGroup.cpp index a6db7cfc41..205a1588ff 100644 --- a/src/dawn_native/BindGroup.cpp +++ b/src/dawn_native/BindGroup.cpp @@ -132,17 +132,10 @@ namespace dawn_native { DAWN_TRY(ValidateBufferBinding(device, binding, dawn::BufferUsageBit::Storage)); break; case dawn::BindingType::SampledTexture: - if (layoutInfo.dynamic[bindingIndex]) { - return DAWN_VALIDATION_ERROR( - "SampledTextures are expected to be not dynamic"); - } DAWN_TRY( ValidateTextureBinding(device, binding, dawn::TextureUsageBit::Sampled)); break; case dawn::BindingType::Sampler: - if (layoutInfo.dynamic[bindingIndex]) { - return DAWN_VALIDATION_ERROR("Samplers are expected to be not dynamic"); - } DAWN_TRY(ValidateSamplerBinding(device, binding)); break; } diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index 9dcdce4474..e64635964d 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -31,7 +31,7 @@ namespace dawn_native { std::bitset bindingsSet; for (uint32_t i = 0; i < descriptor->bindingCount; ++i) { - auto& binding = descriptor->bindings[i]; + const BindGroupLayoutBinding& binding = descriptor->bindings[i]; DAWN_TRY(ValidateShaderStageBit(binding.visibility)); DAWN_TRY(ValidateBindingType(binding.type)); @@ -41,6 +41,19 @@ namespace dawn_native { if (bindingsSet[binding.binding]) { return DAWN_VALIDATION_ERROR("some binding index was specified more than once"); } + + switch (binding.type) { + case dawn::BindingType::UniformBuffer: + case dawn::BindingType::StorageBuffer: + break; + case dawn::BindingType::SampledTexture: + case dawn::BindingType::Sampler: + if (binding.dynamic) { + return DAWN_VALIDATION_ERROR("Samplers and textures cannot be dynamic"); + } + break; + } + bindingsSet.set(binding.binding); } return {}; diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index a222a574e1..4b73cda838 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -422,13 +422,35 @@ TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutBindingOOB) { // This test verifies that the BindGroupLayout bindings are correctly validated, even if the // binding ids are out-of-order. TEST_F(BindGroupLayoutValidationTest, BindGroupBinding) { - auto layout = utils::MakeBindGroupLayout( + utils::MakeBindGroupLayout( device, { {1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}, {0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}, }); } +// Check that dynamic = true is only allowed with buffer bindings. +TEST_F(BindGroupLayoutValidationTest, DynamicAndTypeCompatibility) { + utils::MakeBindGroupLayout( + device, { + {0, dawn::ShaderStageBit::Compute, dawn::BindingType::UniformBuffer, true}, + }); + + utils::MakeBindGroupLayout( + device, { + {0, dawn::ShaderStageBit::Compute, dawn::BindingType::StorageBuffer, true}, + }); + + ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout( + device, { + {0, dawn::ShaderStageBit::Compute, dawn::BindingType::SampledTexture, true}, + })); + + ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout( + device, { + {0, dawn::ShaderStageBit::Compute, dawn::BindingType::Sampler, true}, + })); +} // This test verifies that the BindGroupLayout cache is successfully caching/deduplicating objects. //