Skip to content

Commit

Permalink
Only allow creating 2D textures with RenderAttachment usage
Browse files Browse the repository at this point in the history
BUG=dawn:1364
TEST=dawn_unittests

Change-Id: I49cdeeac8b951c3715211fc3b3b71934a19a6e64
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86622
Reviewed-by: Corentin Wallez <[email protected]>
Commit-Queue: Jiawei Shao <[email protected]>
  • Loading branch information
Jiawei-Shao authored and Dawn LUCI CQ committed Apr 20, 2022
1 parent ec571b5 commit 93a2bed
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/dawn/native/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down
2 changes: 1 addition & 1 deletion src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 24 additions & 4 deletions src/dawn/tests/unittests/validation/TextureValidationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<wgpu::TextureDimension, 3> 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();
Expand Down
6 changes: 0 additions & 6 deletions webgpu-cts/expectations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93a2bed

Please sign in to comment.