diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index 999d550024..8e3034fa43 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -246,6 +246,8 @@ namespace dawn::native { const Format* format) { DAWN_TRY(dawn::native::ValidateTextureUsage(usage)); + DAWN_INVALID_IF(usage == wgpu::TextureUsage::None, "The texture usage must not be 0."); + constexpr wgpu::TextureUsage kValidCompressedUsages = wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst; diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp index e81cd0b1ca..34ff923b8b 100644 --- a/src/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -70,6 +70,25 @@ namespace { wgpu::TextureFormat::RGBA8Unorm; }; + // Test the validation of non-zero texture usage + TEST_F(TextureValidationTest, UsageNonZero) { + wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); + + // Descriptor with proper usage is allowed + { + descriptor.usage = wgpu::TextureUsage::RenderAttachment; + + device.CreateTexture(&descriptor); + } + + // It is an error to create a texture with zero usage + { + descriptor.usage = wgpu::TextureUsage::None; + + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } + } + // Test the validation of sample count TEST_F(TextureValidationTest, SampleCount) { wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); diff --git a/src/tests/unittests/validation/VideoViewsValidationTests.cpp b/src/tests/unittests/validation/VideoViewsValidationTests.cpp index 8f028e7dac..46ad5b2151 100644 --- a/src/tests/unittests/validation/VideoViewsValidationTests.cpp +++ b/src/tests/unittests/validation/VideoViewsValidationTests.cpp @@ -43,7 +43,7 @@ namespace { // Test texture views compatibility rules. TEST_F(VideoViewsValidation, CreateViewFails) { wgpu::Texture videoTexture = CreateVideoTextureForTest( - wgpu::TextureFormat::R8BG8Biplanar420Unorm, wgpu::TextureUsage::None); + wgpu::TextureFormat::R8BG8Biplanar420Unorm, wgpu::TextureUsage::TextureBinding); wgpu::TextureViewDescriptor viewDesc = {}; @@ -66,7 +66,7 @@ namespace { wgpu::TextureDescriptor desc; desc.format = wgpu::TextureFormat::RGBA8Unorm; desc.dimension = wgpu::TextureDimension::e2D; - desc.usage = wgpu::TextureUsage::None; + desc.usage = wgpu::TextureUsage::TextureBinding; desc.size = {1, 1, 1}; wgpu::Texture texture = device.CreateTexture(&desc); @@ -91,7 +91,7 @@ namespace { // Test texture views compatibility rules. TEST_F(VideoViewsValidation, CreateViewSucceeds) { wgpu::Texture yuvTexture = CreateVideoTextureForTest( - wgpu::TextureFormat::R8BG8Biplanar420Unorm, wgpu::TextureUsage::None); + wgpu::TextureFormat::R8BG8Biplanar420Unorm, wgpu::TextureUsage::TextureBinding); // Per plane view formats unspecified. wgpu::TextureViewDescriptor planeViewDesc = {};