From 002395300f9ed7487a197a271b53d19764da7816 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 11 Jul 2019 14:57:15 +0000 Subject: [PATCH] Make RG11B10 non-renderable. This also adds the extra validation needed to support non-renderable formats, as well as tests for it BUG=dawn:128 Change-Id: I3bc79b641aa0fd5e3358f89a87f2e457d0ecc58a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8760 Commit-Queue: Corentin Wallez Reviewed-by: Jiawei Shao --- src/dawn_native/Texture.cpp | 24 ++++++++++------- .../RenderPipelineValidationTests.cpp | 26 ++++++++++++++++++- .../validation/TextureValidationTests.cpp | 15 +++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index 2c3ffa5301..a216fb7dda 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -161,8 +161,9 @@ namespace dawn_native { case dawn::TextureFormat::BGRA8Unorm: case dawn::TextureFormat::BGRA8UnormSrgb: case dawn::TextureFormat::RGB10A2Unorm: - case dawn::TextureFormat::RG11B10Float: return MakeColorFormat(format, true, 4); + case dawn::TextureFormat::RG11B10Float: + return MakeColorFormat(format, false, 4); case dawn::TextureFormat::RG32Uint: case dawn::TextureFormat::RG32Sint: @@ -307,14 +308,19 @@ namespace dawn_native { MaybeError ValidateTextureUsage(const TextureDescriptor* descriptor, const Format& format) { DAWN_TRY(ValidateTextureUsageBit(descriptor->usage)); - if (format.isCompressed) { - constexpr dawn::TextureUsageBit kValidUsage = dawn::TextureUsageBit::Sampled | - dawn::TextureUsageBit::CopySrc | - dawn::TextureUsageBit::CopyDst; - if (descriptor->usage & (~kValidUsage)) { - return DAWN_VALIDATION_ERROR( - "Compressed texture format is incompatible with the texture usage"); - } + + constexpr dawn::TextureUsageBit kValidCompressedUsages = + dawn::TextureUsageBit::Sampled | dawn::TextureUsageBit::CopySrc | + dawn::TextureUsageBit::CopyDst; + if (format.isCompressed && (descriptor->usage & (~kValidCompressedUsages))) { + return DAWN_VALIDATION_ERROR( + "Compressed texture format is incompatible with the texture usage"); + } + + if (!format.isRenderable && + (descriptor->usage & dawn::TextureUsageBit::OutputAttachment)) { + return DAWN_VALIDATION_ERROR( + "Non-renderable format used with OutputAttachment usage"); } return {}; diff --git a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp index 60da2a16de..279963d376 100644 --- a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp @@ -51,7 +51,8 @@ TEST_F(RenderPipelineValidationTest, CreationSuccess) { device.CreateRenderPipeline(&descriptor); } -TEST_F(RenderPipelineValidationTest, ColorState) { +// Tests that at least one color state is required. +TEST_F(RenderPipelineValidationTest, ColorStateRequired) { { // This one succeeds because attachment 0 is the color attachment utils::ComboRenderPipelineDescriptor descriptor(device); @@ -72,6 +73,29 @@ TEST_F(RenderPipelineValidationTest, ColorState) { } } +// Tests that the color formats must be renderable. +TEST_F(RenderPipelineValidationTest, NonRenderableFormat) { + { + // Succeeds because RGBA8Unorm is renderable + utils::ComboRenderPipelineDescriptor descriptor(device); + descriptor.cVertexStage.module = vsModule; + descriptor.cFragmentStage.module = fsModule; + descriptor.cColorStates[0]->format = dawn::TextureFormat::RGBA8Unorm; + + device.CreateRenderPipeline(&descriptor); + } + + { + // Fails because RG11B10Float is non-renderable + utils::ComboRenderPipelineDescriptor descriptor(device); + descriptor.cVertexStage.module = vsModule; + descriptor.cFragmentStage.module = fsModule; + descriptor.cColorStates[0]->format = dawn::TextureFormat::RG11B10Float; + + ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); + } +} + /// Tests that the sample count of the render pipeline must be valid. TEST_F(RenderPipelineValidationTest, SampleCount) { { diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp index 1ed72dfa23..bef154eaef 100644 --- a/src/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -235,6 +235,21 @@ TEST_F(TextureValidationTest, EncodeDestroySubmit) { ASSERT_DEVICE_ERROR(queue.Submit(1, &commands)); } +// Test it is an error to create an OutputAttachment texture with a non-renderable format. +TEST_F(TextureValidationTest, NonRenderableAndOutputAttachment) { + dawn::TextureDescriptor descriptor; + descriptor.size = {1, 1, 1}; + descriptor.usage = dawn::TextureUsageBit::OutputAttachment; + + // Succeeds because RGBA8Unorm is renderable + descriptor.format = dawn::TextureFormat::RGBA8Unorm; + device.CreateTexture(&descriptor); + + // Fails because RG11B10Float is non-renderable + descriptor.format = dawn::TextureFormat::RG11B10Float; + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); +} + // TODO(jiawei.shao@intel.com): use compressed texture formats as extensions. // TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with // compressed texture formats.