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 <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2022-04-20 04:01:39 +00:00 committed by Dawn LUCI CQ
parent ec571b5774
commit 93a2bed032
5 changed files with 33 additions and 11 deletions

View File

@ -309,6 +309,13 @@ namespace dawn::native {
"format (%s).", "format (%s).",
usage, wgpu::TextureUsage::RenderAttachment, format->format); 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( DAWN_INVALID_IF(
!format->supportsStorageUsage && (usage & wgpu::TextureUsage::StorageBinding), !format->supportsStorageUsage && (usage & wgpu::TextureUsage::StorageBinding),
"The texture usage (%s) includes %s, which is incompatible with the format (%s).", "The texture usage (%s) includes %s, which is incompatible with the format (%s).",

View File

@ -301,7 +301,7 @@ DAWN_INSTANTIATE_TEST_P(
{wgpu::TextureAspect::All}, {wgpu::TextureAspect::All},
{wgpu::TextureUsage(wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc), {wgpu::TextureUsage(wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc),
wgpu::TextureUsage::CopySrc}, wgpu::TextureUsage::CopySrc},
{wgpu::TextureDimension::e2D, wgpu::TextureDimension::e3D}, {wgpu::TextureDimension::e2D},
{1u, 7u}, // depth or array layers {1u, 7u}, // depth or array layers
{4u}, // mip count {4u}, // mip count
{0u, 1u, 2u, 3u}, // mip {0u, 1u, 2u, 3u}, // mip

View File

@ -72,6 +72,7 @@ namespace {
{ {
wgpu::TextureDescriptor textureDescriptor = CreateTextureDescriptor(); wgpu::TextureDescriptor textureDescriptor = CreateTextureDescriptor();
textureDescriptor.dimension = wgpu::TextureDimension::e3D; textureDescriptor.dimension = wgpu::TextureDimension::e3D;
textureDescriptor.usage = wgpu::TextureUsage::TextureBinding;
wgpu::Texture internalTexture = device.CreateTexture(&textureDescriptor); wgpu::Texture internalTexture = device.CreateTexture(&textureDescriptor);
wgpu::ExternalTextureDescriptor externalDesc; wgpu::ExternalTextureDescriptor externalDesc;

View File

@ -178,6 +178,7 @@ namespace {
// Test the validation of the mip level count // Test the validation of the mip level count
TEST_F(TextureValidationTest, MipLevelCount) { TEST_F(TextureValidationTest, MipLevelCount) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
defaultDescriptor.usage = wgpu::TextureUsage::TextureBinding;
// mipLevelCount == 1 is allowed // mipLevelCount == 1 is allowed
{ {
@ -456,12 +457,13 @@ namespace {
// Test the validation of 3D texture size // Test the validation of 3D texture size
TEST_F(TextureValidationTest, 3DTextureSize) { TEST_F(TextureValidationTest, 3DTextureSize) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
defaultDescriptor.dimension = wgpu::TextureDimension::e3D;
defaultDescriptor.usage = wgpu::TextureUsage::TextureBinding;
wgpu::Limits supportedLimits = GetSupportedLimits().limits; wgpu::Limits supportedLimits = GetSupportedLimits().limits;
// Out-of-bound texture dimension is not allowed // Out-of-bound texture dimension is not allowed
{ {
wgpu::TextureDescriptor descriptor = defaultDescriptor; wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.dimension = wgpu::TextureDimension::e3D;
descriptor.size = {supportedLimits.maxTextureDimension3D + 1u, 1, 1}; descriptor.size = {supportedLimits.maxTextureDimension3D + 1u, 1, 1};
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
@ -476,7 +478,6 @@ namespace {
// Zero-sized texture is not allowed // Zero-sized texture is not allowed
{ {
wgpu::TextureDescriptor descriptor = defaultDescriptor; wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.dimension = wgpu::TextureDimension::e3D;
descriptor.size = {0, 1, 1}; descriptor.size = {0, 1, 1};
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
@ -491,7 +492,6 @@ namespace {
// Texture size less than max dimension is allowed // Texture size less than max dimension is allowed
{ {
wgpu::TextureDescriptor descriptor = defaultDescriptor; wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.dimension = wgpu::TextureDimension::e3D;
descriptor.size = {supportedLimits.maxTextureDimension3D >> 1, descriptor.size = {supportedLimits.maxTextureDimension3D >> 1,
supportedLimits.maxTextureDimension3D >> 1, supportedLimits.maxTextureDimension3D >> 1,
@ -502,7 +502,6 @@ namespace {
// Texture size equal to max dimension is allowed // Texture size equal to max dimension is allowed
{ {
wgpu::TextureDescriptor descriptor = defaultDescriptor; wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.dimension = wgpu::TextureDimension::e3D;
descriptor.size = {supportedLimits.maxTextureDimension3D, descriptor.size = {supportedLimits.maxTextureDimension3D,
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<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 it is an error to create a texture with format "Undefined".
TEST_F(TextureValidationTest, TextureFormatUndefined) { TEST_F(TextureValidationTest, TextureFormatUndefined) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();

View File

@ -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 [ 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/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 # Triaged failures
# KEEP # KEEP