From b166b99f8633d0a12c1847e0434b2aec7923dd47 Mon Sep 17 00:00:00 2001 From: jchen10 Date: Thu, 16 Sep 2021 05:29:44 +0000 Subject: [PATCH] Treat 'mipLevelCount == 0' as error It's no longer a valid default value. Bug: dawn:1026 Change-Id: I9de656f29c8b7673de412cef35dcfb8a45121ac7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64165 Reviewed-by: Jiawei Shao Reviewed-by: Corentin Wallez Commit-Queue: Jie A Chen --- src/dawn_native/Texture.cpp | 4 +-- .../validation/TextureViewValidationTests.cpp | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index d2b6548c0e..cb1f741d2e 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -418,9 +418,7 @@ namespace dawn_native { } } - // TODO(jie.a.chen@intel.com): Remove 'desc.mipLevelCount == 0' once the WebGPU change is - // landed. - if (desc.mipLevelCount == 0 || desc.mipLevelCount == wgpu::kMipLevelCountUndefined) { + if (desc.mipLevelCount == wgpu::kMipLevelCountUndefined) { desc.mipLevelCount = texture->GetNumMipLevels() - desc.baseMipLevel; } return desc; diff --git a/src/tests/unittests/validation/TextureViewValidationTests.cpp b/src/tests/unittests/validation/TextureViewValidationTests.cpp index a07d3d9db3..886422d7e5 100644 --- a/src/tests/unittests/validation/TextureViewValidationTests.cpp +++ b/src/tests/unittests/validation/TextureViewValidationTests.cpp @@ -79,6 +79,13 @@ namespace { ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); } + // It is an error to create a view with zero 'mipLevelCount'. + { + wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor; + descriptor.mipLevelCount = 0; + ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); + } + // It is OK to create a 2D texture view on a 2D texture. { wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor; @@ -160,6 +167,14 @@ namespace { ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); } + // It is an error to create a view with zero 'mipLevelCount'. + { + wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor; + descriptor.dimension = wgpu::TextureViewDimension::e2D; + descriptor.mipLevelCount = 0; + ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); + } + // It is OK to create a 2D texture view on a 2D array texture. { wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor; @@ -231,6 +246,13 @@ namespace { ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); } + // It is an error to create a view with zero 'mipLevelCount'. + { + wgpu::TextureViewDescriptor descriptor = base3DTextureViewDescriptor; + descriptor.mipLevelCount = 0; + ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); + } + // It is OK to create a 3D texture view on a 3D texture. { wgpu::TextureViewDescriptor descriptor = base3DTextureViewDescriptor; @@ -475,6 +497,14 @@ namespace { ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); } + // It is an error to create a view with zero 'mipLevelCount'. + { + wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor; + descriptor.dimension = wgpu::TextureViewDimension::Cube; + descriptor.mipLevelCount = 0; + ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); + } + // It is OK to create a cube map texture view with arrayLayerCount == 6. { wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;