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 <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Corentin Wallez 2019-07-11 14:57:15 +00:00 committed by Commit Bot service account
parent ea2d558479
commit 002395300f
3 changed files with 55 additions and 10 deletions

View File

@ -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 |
constexpr dawn::TextureUsageBit kValidCompressedUsages =
dawn::TextureUsageBit::Sampled | dawn::TextureUsageBit::CopySrc |
dawn::TextureUsageBit::CopyDst;
if (descriptor->usage & (~kValidUsage)) {
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 {};

View File

@ -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) {
{

View File

@ -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.