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