From 5f4bcbb9467f994daf8f1629bdeb35014d7f6015 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Thu, 28 Mar 2019 00:14:50 +0000 Subject: [PATCH] Disallow creating multisampled 2D array textures Currently we decide not to support multisampled 2D array textures because on Metal they are only available on macOS version greater than 10.14. This patch also removes the compatibility check between cube map texture views and sample counts because currently the sample count of 2D array textures is always equal to 1. BUG=dawn:56 TEST=dawn_unittests Change-Id: I9736c977192409c79572f061fa1b7681b5b3e6c8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6000 Reviewed-by: Corentin Wallez Reviewed-by: Kai Ninomiya Commit-Queue: Jiawei Shao --- src/dawn_native/Texture.cpp | 37 ++++++------------- .../validation/TextureValidationTests.cpp | 9 +++++ .../validation/TextureViewValidationTests.cpp | 24 ------------ 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index c97cdfde5c..223d8552a3 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -47,22 +47,6 @@ namespace dawn_native { } } - bool IsTextureViewDimensionCompatibleWithTextureSampleCount( - dawn::TextureViewDimension textureViewDimension, - const uint32_t sampleCount) { - switch (textureViewDimension) { - case dawn::TextureViewDimension::Cube: - case dawn::TextureViewDimension::CubeArray: - return sampleCount == 1; - case dawn::TextureViewDimension::e2D: - case dawn::TextureViewDimension::e2DArray: - return true; - default: - UNREACHABLE(); - return false; - } - } - // TODO(jiawei.shao@intel.com): support validation on all texture view dimensions bool IsArrayLayerValidForTextureViewDimension( dawn::TextureViewDimension textureViewDimension, @@ -104,9 +88,17 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("The sample count of the texture is not supported."); } - if (descriptor->sampleCount > 1 && descriptor->mipLevelCount > 1) { - return DAWN_VALIDATION_ERROR( - "The mipmap level count of a multisampled texture must be 1."); + if (descriptor->sampleCount > 1) { + if (descriptor->mipLevelCount > 1) { + return DAWN_VALIDATION_ERROR( + "The mipmap level count of a multisampled texture must be 1."); + } + + // Multisampled 2D array texture is not supported because on Metal it requires the + // version of macOS be greater than 10.14. + if (descriptor->arrayLayerCount > 1) { + return DAWN_VALIDATION_ERROR("Multisampled 2D array texture is not supported."); + } } return {}; @@ -128,13 +120,6 @@ namespace dawn_native { "original texture"); } - if (!IsTextureViewDimensionCompatibleWithTextureSampleCount( - descriptor->dimension, texture->GetSampleCount())) { - return DAWN_VALIDATION_ERROR( - "The dimension of the texture view is not compatible with the sample count of " - "the original texture"); - } - if (!IsTextureSizeValidForTextureViewDimension(descriptor->dimension, texture->GetSize())) { return DAWN_VALIDATION_ERROR( diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp index df755c5b0d..cfe722e16f 100644 --- a/src/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -84,6 +84,15 @@ TEST_F(TextureValidationTest, SampleCount) { ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); } + + // Currently we do not support multisampled 2D array textures. + { + dawn::TextureDescriptor descriptor = defaultDescriptor; + descriptor.sampleCount = 4; + descriptor.arrayLayerCount = 2; + + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } } // Test that it is valid to destroy a texture diff --git a/src/tests/unittests/validation/TextureViewValidationTests.cpp b/src/tests/unittests/validation/TextureViewValidationTests.cpp index 589812c1bd..9eda487364 100644 --- a/src/tests/unittests/validation/TextureViewValidationTests.cpp +++ b/src/tests/unittests/validation/TextureViewValidationTests.cpp @@ -200,30 +200,6 @@ TEST_F(TextureViewValidationTest, CreateCubeMapTextureView) { descriptor.arrayLayerCount = 12; ASSERT_DEVICE_ERROR(nonSquareTexture.CreateTextureView(&descriptor)); } - - // It is an error to create a cube map texture view on a multisampled texture. - { - constexpr uint32_t kSampleCount = 4; - dawn::Texture multisampledTexture = Create2DArrayTexture(device, kDefaultArrayLayers, - kWidth, kHeight, 1, kSampleCount); - dawn::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor; - descriptor.dimension = dawn::TextureViewDimension::Cube; - descriptor.arrayLayerCount = 6; - descriptor.mipLevelCount = 1; - ASSERT_DEVICE_ERROR(multisampledTexture.CreateTextureView(&descriptor)); - } - - // It is an error to create a cube map array texture view on a multisampled texture. - { - constexpr uint32_t kSampleCount = 4; - dawn::Texture multisampledTexture = Create2DArrayTexture(device, kDefaultArrayLayers, - kWidth, kHeight, 1, kSampleCount); - dawn::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor; - descriptor.dimension = dawn::TextureViewDimension::CubeArray; - descriptor.arrayLayerCount = 12; - descriptor.mipLevelCount = 1; - ASSERT_DEVICE_ERROR(multisampledTexture.CreateTextureView(&descriptor)); - } } // Test the format compatibility rules when creating a texture view.