diff --git a/src/dawn_native/BindGroup.cpp b/src/dawn_native/BindGroup.cpp index a51b9ff1ce..d590117cb8 100644 --- a/src/dawn_native/BindGroup.cpp +++ b/src/dawn_native/BindGroup.cpp @@ -155,11 +155,10 @@ namespace dawn_native { break; } case BindingInfoType::StorageTexture: { - ASSERT(!texture->IsMultisampledTexture()); - if (!(texture->GetUsage() & wgpu::TextureUsage::Storage)) { return DAWN_VALIDATION_ERROR("Storage Texture binding usage mismatch"); } + ASSERT(!texture->IsMultisampledTexture()); if (texture->GetFormat().format != bindingInfo.storageTexture.format) { return DAWN_VALIDATION_ERROR("Storage texture format mismatch"); diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index 1057567807..430ca11a0d 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -388,7 +388,7 @@ TEST_F(BindGroupValidationTest, ExternalTextureBindingType) { } } -// Check that a texture must have the correct usage +// Check that a texture binding must have the correct usage TEST_F(BindGroupValidationTest, TextureUsage) { wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout( device, {{0, wgpu::ShaderStage::Fragment, wgpu::TextureSampleType::Float}}); @@ -403,6 +403,38 @@ TEST_F(BindGroupValidationTest, TextureUsage) { ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, outputTextureView}})); } +// Check that a storage texture binding must have the correct usage +TEST_F(BindGroupValidationTest, StorageTextureUsage) { + wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout( + device, {{0, wgpu::ShaderStage::Compute, wgpu::StorageTextureAccess::ReadOnly, + wgpu::TextureFormat::RGBA8Uint}}); + + wgpu::TextureDescriptor descriptor; + descriptor.dimension = wgpu::TextureDimension::e2D; + descriptor.size = {16, 16, 1}; + descriptor.sampleCount = 1; + descriptor.mipLevelCount = 1; + descriptor.usage = wgpu::TextureUsage::Storage; + descriptor.format = wgpu::TextureFormat::RGBA8Uint; + + wgpu::TextureView view = device.CreateTexture(&descriptor).CreateView(); + + // Control case: setting a storage texture view works. + utils::MakeBindGroup(device, layout, {{0, view}}); + + // Sampled texture is invalid with storage buffer binding + descriptor.usage = wgpu::TextureUsage::Sampled; + descriptor.format = wgpu::TextureFormat::RGBA8Unorm; + view = device.CreateTexture(&descriptor).CreateView(); + ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, view}})); + + // Multisampled texture is invalid with storage buffer binding + // Regression case for crbug.com/dawn/614 where this hit an ASSERT. + descriptor.sampleCount = 4; + view = device.CreateTexture(&descriptor).CreateView(); + ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, view}})); +} + // Check that a texture must have the correct component type TEST_F(BindGroupValidationTest, TextureComponentType) { wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(