From 93a2bed032a9e386905b88d70761d093bb567840 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Wed, 20 Apr 2022 04:01:39 +0000 Subject: [PATCH] Only allow creating 2D textures with RenderAttachment usage BUG=dawn:1364 TEST=dawn_unittests Change-Id: I49cdeeac8b951c3715211fc3b3b71934a19a6e64 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86622 Reviewed-by: Corentin Wallez Commit-Queue: Jiawei Shao --- src/dawn/native/Texture.cpp | 7 +++++ .../end2end/NonzeroTextureCreationTests.cpp | 2 +- .../validation/ExternalTextureTests.cpp | 1 + .../validation/TextureValidationTests.cpp | 28 ++++++++++++++++--- webgpu-cts/expectations.txt | 6 ---- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp index cabef76fe0..75b3c0c522 100644 --- a/src/dawn/native/Texture.cpp +++ b/src/dawn/native/Texture.cpp @@ -309,6 +309,13 @@ namespace dawn::native { "format (%s).", usage, wgpu::TextureUsage::RenderAttachment, format->format); + DAWN_INVALID_IF( + descriptor->dimension != wgpu::TextureDimension::e2D && + (usage & wgpu::TextureUsage::RenderAttachment), + "The texture usage (%s) includes %s, which is incompatible with the texture " + "dimension (%s).", + usage, wgpu::TextureUsage::RenderAttachment, descriptor->dimension); + DAWN_INVALID_IF( !format->supportsStorageUsage && (usage & wgpu::TextureUsage::StorageBinding), "The texture usage (%s) includes %s, which is incompatible with the format (%s).", diff --git a/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp b/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp index 19f412a6f9..365b150e1d 100644 --- a/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp +++ b/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp @@ -301,7 +301,7 @@ DAWN_INSTANTIATE_TEST_P( {wgpu::TextureAspect::All}, {wgpu::TextureUsage(wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc), wgpu::TextureUsage::CopySrc}, - {wgpu::TextureDimension::e2D, wgpu::TextureDimension::e3D}, + {wgpu::TextureDimension::e2D}, {1u, 7u}, // depth or array layers {4u}, // mip count {0u, 1u, 2u, 3u}, // mip diff --git a/src/dawn/tests/unittests/validation/ExternalTextureTests.cpp b/src/dawn/tests/unittests/validation/ExternalTextureTests.cpp index 57cb301b63..3c4aba3742 100644 --- a/src/dawn/tests/unittests/validation/ExternalTextureTests.cpp +++ b/src/dawn/tests/unittests/validation/ExternalTextureTests.cpp @@ -72,6 +72,7 @@ namespace { { wgpu::TextureDescriptor textureDescriptor = CreateTextureDescriptor(); textureDescriptor.dimension = wgpu::TextureDimension::e3D; + textureDescriptor.usage = wgpu::TextureUsage::TextureBinding; wgpu::Texture internalTexture = device.CreateTexture(&textureDescriptor); wgpu::ExternalTextureDescriptor externalDesc; diff --git a/src/dawn/tests/unittests/validation/TextureValidationTests.cpp b/src/dawn/tests/unittests/validation/TextureValidationTests.cpp index 3136c769d3..ac0192e904 100644 --- a/src/dawn/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/TextureValidationTests.cpp @@ -178,6 +178,7 @@ namespace { // Test the validation of the mip level count TEST_F(TextureValidationTest, MipLevelCount) { wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); + defaultDescriptor.usage = wgpu::TextureUsage::TextureBinding; // mipLevelCount == 1 is allowed { @@ -456,12 +457,13 @@ namespace { // Test the validation of 3D texture size TEST_F(TextureValidationTest, 3DTextureSize) { wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); + defaultDescriptor.dimension = wgpu::TextureDimension::e3D; + defaultDescriptor.usage = wgpu::TextureUsage::TextureBinding; wgpu::Limits supportedLimits = GetSupportedLimits().limits; // Out-of-bound texture dimension is not allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.dimension = wgpu::TextureDimension::e3D; descriptor.size = {supportedLimits.maxTextureDimension3D + 1u, 1, 1}; ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); @@ -476,7 +478,6 @@ namespace { // Zero-sized texture is not allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.dimension = wgpu::TextureDimension::e3D; descriptor.size = {0, 1, 1}; ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); @@ -491,7 +492,6 @@ namespace { // Texture size less than max dimension is allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.dimension = wgpu::TextureDimension::e3D; descriptor.size = {supportedLimits.maxTextureDimension3D >> 1, supportedLimits.maxTextureDimension3D >> 1, @@ -502,7 +502,6 @@ namespace { // Texture size equal to max dimension is allowed { wgpu::TextureDescriptor descriptor = defaultDescriptor; - descriptor.dimension = wgpu::TextureDimension::e3D; descriptor.size = {supportedLimits.maxTextureDimension3D, supportedLimits.maxTextureDimension3D, @@ -625,6 +624,27 @@ namespace { } } + // Test it is an error to create a RenderAttachment texture with the texture dimensions that + // doesn't support TextureUsage::RenderAttachment texture usages. + TEST_F(TextureValidationTest, TextureDimensionNotSupportRenderAttachment) { + wgpu::TextureDescriptor descriptor; + descriptor.size = {1, 1, 1}; + descriptor.format = wgpu::TextureFormat::RGBA8Unorm; + descriptor.usage = wgpu::TextureUsage::RenderAttachment; + + constexpr std::array kTextureDimensions = { + {wgpu::TextureDimension::e1D, wgpu::TextureDimension::e2D, + wgpu::TextureDimension::e3D}}; + for (wgpu::TextureDimension dimension : kTextureDimensions) { + descriptor.dimension = dimension; + if (dimension == wgpu::TextureDimension::e2D) { + device.CreateTexture(&descriptor); + } else { + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } + } + } + // Test it is an error to create a texture with format "Undefined". TEST_F(TextureValidationTest, TextureFormatUndefined) { wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); diff --git a/webgpu-cts/expectations.txt b/webgpu-cts/expectations.txt index 1303d6774d..6ae1323dd2 100644 --- a/webgpu-cts/expectations.txt +++ b/webgpu-cts/expectations.txt @@ -463,12 +463,6 @@ crbug.com/tint/1500 [ nvidia release win ] webgpu:shader,execution,shader_io,com crbug.com/dawn/0000 [ mac ] webgpu:api,operation,command_buffer,copyTextureToTexture:color_textures,non_compressed,* [ Failure ] crbug.com/dawn/0000 [ win ] webgpu:api,operation,command_buffer,copyTextureToTexture:color_textures,non_compressed,* [ Failure ] -################################################################################ -# crbug.com/dawn/1364 Add validation that render attachments must be 2D (array) textures -# KEEP -################################################################################ -crbug.com/dawn/1364 webgpu:api,validation,createTexture:texture_usage:* [ Failure ] - ################################################################################ # Triaged failures # KEEP