Fix misplaced ASSERT in bind group validation

Fixed: dawn:614
Change-Id: I06e4c89f34a1705346620dea074e3d469cbd1409
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/55900
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2021-06-24 23:05:51 +00:00 committed by Dawn LUCI CQ
parent 700a5fb869
commit a9faf7f74a
2 changed files with 34 additions and 3 deletions

View File

@ -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");

View File

@ -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(