Validate that storage texture views have a single miplevel

Validate the storage texture views have a miplevel of 1 when creating
bind group. This validation is added in
https://github.com/gpuweb/gpuweb/pull/2285.
Also fix a bug in unittest BindGroupValidationTest.TextureBindingType.

Bug: dawn:1212
Change-Id: If32400ed1e4f3049b8b8979e6e6133bada36b45c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/71380
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
This commit is contained in:
Zhaoming Jiang 2021-12-02 05:38:30 +00:00 committed by Dawn LUCI CQ
parent c871df0b19
commit 3a036ab698
2 changed files with 70 additions and 1 deletions

View File

@ -182,6 +182,10 @@ namespace dawn_native {
"Dimension (%s) of %s doesn't match the expected dimension (%s).", "Dimension (%s) of %s doesn't match the expected dimension (%s).",
entry.textureView->GetDimension(), entry.textureView, entry.textureView->GetDimension(), entry.textureView,
bindingInfo.storageTexture.viewDimension); bindingInfo.storageTexture.viewDimension);
DAWN_INVALID_IF(entry.textureView->GetLevelCount() != 1,
"mipLevelCount (%u) of %s expected to be 1.",
entry.textureView->GetLevelCount(), entry.textureView);
break; break;
} }
default: default:

View File

@ -218,7 +218,7 @@ TEST_F(BindGroupValidationTest, TextureBindingType) {
// Setting the sampler as well is an error // Setting the sampler as well is an error
binding.sampler = mSampler; binding.sampler = mSampler;
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor)); ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
binding.textureView = nullptr; binding.sampler = nullptr;
// Setting the buffer as well is an error // Setting the buffer as well is an error
binding.buffer = mUBO; binding.buffer = mUBO;
@ -552,6 +552,71 @@ TEST_F(BindGroupValidationTest, TextureDimension) {
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, arrayTextureView}})); ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, arrayTextureView}}));
} }
// Check that a storage texture binding must have a texture view with a mipLevelCount of 1
TEST_F(BindGroupValidationTest, StorageTextureViewLayerCount) {
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Compute, wgpu::StorageTextureAccess::WriteOnly,
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::StorageBinding;
descriptor.format = wgpu::TextureFormat::RGBA8Uint;
wgpu::Texture textureNoMip = device.CreateTexture(&descriptor);
descriptor.mipLevelCount = 3;
wgpu::Texture textureMip = device.CreateTexture(&descriptor);
// Control case: setting a storage texture view on a texture with only one mip level works
{
wgpu::TextureView view = textureNoMip.CreateView();
utils::MakeBindGroup(device, layout, {{0, view}});
}
// Setting a storage texture view with mipLevelCount=1 on a texture of multiple mip levels is
// valid
{
wgpu::TextureViewDescriptor viewDesc = {};
viewDesc.aspect = wgpu::TextureAspect::All;
viewDesc.dimension = wgpu::TextureViewDimension::e2D;
viewDesc.format = wgpu::TextureFormat::RGBA8Uint;
viewDesc.baseMipLevel = 0;
viewDesc.mipLevelCount = 1;
// Setting texture view with lod 0 is valid
wgpu::TextureView view = textureMip.CreateView(&viewDesc);
utils::MakeBindGroup(device, layout, {{0, view}});
// Setting texture view with other lod is also valid
viewDesc.baseMipLevel = 2;
view = textureMip.CreateView(&viewDesc);
utils::MakeBindGroup(device, layout, {{0, view}});
}
// Texture view with mipLevelCount > 1 is invalid
{
wgpu::TextureViewDescriptor viewDesc = {};
viewDesc.aspect = wgpu::TextureAspect::All;
viewDesc.dimension = wgpu::TextureViewDimension::e2D;
viewDesc.format = wgpu::TextureFormat::RGBA8Uint;
viewDesc.baseMipLevel = 0;
viewDesc.mipLevelCount = 2;
// Setting texture view with lod 0 and 1 is invalid
wgpu::TextureView view = textureMip.CreateView(&viewDesc);
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, view}}));
// Setting texture view with lod 1 and 2 is invalid
viewDesc.baseMipLevel = 1;
view = textureMip.CreateView(&viewDesc);
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, view}}));
}
}
// Check that a UBO must have the correct usage // Check that a UBO must have the correct usage
TEST_F(BindGroupValidationTest, BufferUsageUBO) { TEST_F(BindGroupValidationTest, BufferUsageUBO) {
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(