From a329997e27b4300ee7914d46d48d487825b3b4c6 Mon Sep 17 00:00:00 2001 From: Li Hao Date: Thu, 25 Nov 2021 01:11:57 +0000 Subject: [PATCH] Add features of depth24unorm-stencil8 and depth32float-stencil8 texture formats The depth240unorm-stencil8 and depth32float-stencil8 are optional features. Enable them and add validation tests for texture creation and texture view creation. They are unimplmented on backends, skip their end2end tests. TODO: add validtion for copy commands. BUG=dawn:690 Change-Id: I980631d2f3fa6397a6125221a76980a15c8cb2f5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/68220 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Hao Li --- dawn.json | 112 +++++++++--------- src/dawn_native/Features.cpp | 8 ++ src/dawn_native/Features.h | 2 + src/dawn_native/Format.cpp | 7 +- src/dawn_native/Format.h | 2 +- src/dawn_native/d3d12/TextureD3D12.cpp | 8 ++ src/dawn_native/metal/TextureMTL.mm | 4 + src/dawn_native/vulkan/AdapterVk.cpp | 10 ++ src/dawn_native/vulkan/AdapterVk.h | 2 + src/dawn_native/vulkan/DeviceVk.cpp | 23 +--- src/dawn_native/vulkan/TextureVk.cpp | 4 + .../ReadOnlyDepthStencilAttachmentTests.cpp | 46 ++++++- .../validation/TextureValidationTests.cpp | 71 +++++++++-- .../validation/TextureViewValidationTests.cpp | 98 +++++++++++++++ src/utils/TextureUtils.cpp | 6 + src/utils/TextureUtils.h | 25 ++-- 16 files changed, 333 insertions(+), 95 deletions(-) diff --git a/dawn.json b/dawn.json index 3445fe23b1..e95b07ed69 100644 --- a/dawn.json +++ b/dawn.json @@ -1117,6 +1117,8 @@ {"name": "timestamp query", "type": "bool", "default": "false"}, {"name": "multi planar formats", "type": "bool", "default": "false"}, {"name": "depth clamping", "type": "bool", "default": "false"}, + {"name": "depth24 unorm stencil8", "type": "bool", "default": "false"}, + {"name": "depth32 float stencil8", "type": "bool", "default": "false"}, {"name": "invalid feature", "type": "bool", "default": "false"}, {"name": "dawn internal usages", "type": "bool", "default": "false"}, {"name": "limits", "type": "supported limits"} @@ -2429,64 +2431,66 @@ {"value": 38, "name": "depth16 unorm"}, {"value": 39, "name": "depth24 plus"}, {"value": 40, "name": "depth24 plus stencil8"}, - {"value": 41, "name": "depth32 float"}, + {"value": 41, "name": "depth24 unorm stencil8"}, + {"value": 42, "name": "depth32 float"}, + {"value": 43, "name": "depth32 float stencil8"}, - {"value": 42, "name": "BC1 RGBA unorm", "jsrepr": "'bc1-rgba-unorm'"}, - {"value": 43, "name": "BC1 RGBA unorm srgb", "jsrepr": "'bc1-rgba-unorm-srgb'"}, - {"value": 44, "name": "BC2 RGBA unorm", "jsrepr": "'bc2-rgba-unorm'"}, - {"value": 45, "name": "BC2 RGBA unorm srgb", "jsrepr": "'bc2-rgba-unorm-srgb'"}, - {"value": 46, "name": "BC3 RGBA unorm", "jsrepr": "'bc3-rgba-unorm'"}, - {"value": 47, "name": "BC3 RGBA unorm srgb", "jsrepr": "'bc3-rgba-unorm-srgb'"}, - {"value": 48, "name": "BC4 R unorm", "jsrepr": "'bc4-r-unorm'"}, - {"value": 49, "name": "BC4 R snorm", "jsrepr": "'bc4-r-snorm'"}, - {"value": 50, "name": "BC5 RG unorm", "jsrepr": "'bc5-rg-unorm'"}, - {"value": 51, "name": "BC5 RG snorm", "jsrepr": "'bc5-rg-snorm'"}, - {"value": 52, "name": "BC6H RGB ufloat", "jsrepr": "'bc6h-rgb-ufloat'"}, - {"value": 53, "name": "BC6H RGB float", "jsrepr": "'bc6h-rgb-float'"}, - {"value": 54, "name": "BC7 RGBA unorm", "jsrepr": "'bc7-rgba-unorm'"}, - {"value": 55, "name": "BC7 RGBA unorm srgb", "jsrepr": "'bc7-rgba-unorm-srgb'"}, + {"value": 44, "name": "BC1 RGBA unorm", "jsrepr": "'bc1-rgba-unorm'"}, + {"value": 45, "name": "BC1 RGBA unorm srgb", "jsrepr": "'bc1-rgba-unorm-srgb'"}, + {"value": 46, "name": "BC2 RGBA unorm", "jsrepr": "'bc2-rgba-unorm'"}, + {"value": 47, "name": "BC2 RGBA unorm srgb", "jsrepr": "'bc2-rgba-unorm-srgb'"}, + {"value": 48, "name": "BC3 RGBA unorm", "jsrepr": "'bc3-rgba-unorm'"}, + {"value": 49, "name": "BC3 RGBA unorm srgb", "jsrepr": "'bc3-rgba-unorm-srgb'"}, + {"value": 50, "name": "BC4 R unorm", "jsrepr": "'bc4-r-unorm'"}, + {"value": 51, "name": "BC4 R snorm", "jsrepr": "'bc4-r-snorm'"}, + {"value": 52, "name": "BC5 RG unorm", "jsrepr": "'bc5-rg-unorm'"}, + {"value": 53, "name": "BC5 RG snorm", "jsrepr": "'bc5-rg-snorm'"}, + {"value": 54, "name": "BC6H RGB ufloat", "jsrepr": "'bc6h-rgb-ufloat'"}, + {"value": 55, "name": "BC6H RGB float", "jsrepr": "'bc6h-rgb-float'"}, + {"value": 56, "name": "BC7 RGBA unorm", "jsrepr": "'bc7-rgba-unorm'"}, + {"value": 57, "name": "BC7 RGBA unorm srgb", "jsrepr": "'bc7-rgba-unorm-srgb'"}, - {"value": 56, "name": "ETC2 RGB8 unorm", "jsrepr": "'etc2-rgb8unorm'"}, - {"value": 57, "name": "ETC2 RGB8 unorm srgb", "jsrepr": "'etc2-rgb8unorm-srgb'"}, - {"value": 58, "name": "ETC2 RGB8A1 unorm", "jsrepr": "'etc2-rgb8a1unorm'"}, - {"value": 59, "name": "ETC2 RGB8A1 unorm srgb", "jsrepr": "'etc2-rgb8a1unorm-srgb'"}, - {"value": 60, "name": "ETC2 RGBA8 unorm", "jsrepr": "'etc2-rgba8unorm'"}, - {"value": 61, "name": "ETC2 RGBA8 unorm srgb", "jsrepr": "'etc2-rgba8unorm-srgb'"}, - {"value": 62, "name": "EAC R11 unorm", "jsrepr": "'eac-r11unorm'"}, - {"value": 63, "name": "EAC R11 snorm", "jsrepr": "'eac-r11snorm'"}, - {"value": 64, "name": "EAC RG11 unorm", "jsrepr": "'eac-rg11unorm'"}, - {"value": 65, "name": "EAC RG11 snorm", "jsrepr": "'eac-rg11snorm'"}, + {"value": 58, "name": "ETC2 RGB8 unorm", "jsrepr": "'etc2-rgb8unorm'"}, + {"value": 59, "name": "ETC2 RGB8 unorm srgb", "jsrepr": "'etc2-rgb8unorm-srgb'"}, + {"value": 60, "name": "ETC2 RGB8A1 unorm", "jsrepr": "'etc2-rgb8a1unorm'"}, + {"value": 61, "name": "ETC2 RGB8A1 unorm srgb", "jsrepr": "'etc2-rgb8a1unorm-srgb'"}, + {"value": 62, "name": "ETC2 RGBA8 unorm", "jsrepr": "'etc2-rgba8unorm'"}, + {"value": 63, "name": "ETC2 RGBA8 unorm srgb", "jsrepr": "'etc2-rgba8unorm-srgb'"}, + {"value": 64, "name": "EAC R11 unorm", "jsrepr": "'eac-r11unorm'"}, + {"value": 65, "name": "EAC R11 snorm", "jsrepr": "'eac-r11snorm'"}, + {"value": 66, "name": "EAC RG11 unorm", "jsrepr": "'eac-rg11unorm'"}, + {"value": 67, "name": "EAC RG11 snorm", "jsrepr": "'eac-rg11snorm'"}, - {"value": 66, "name": "ASTC 4x4 unorm", "jsrepr": "'astc-4x4-unorm'"}, - {"value": 67, "name": "ASTC 4x4 unorm srgb", "jsrepr": "'astc-4x4-unorm-srgb'"}, - {"value": 68, "name": "ASTC 5x4 unorm", "jsrepr": "'astc-5x4-unorm'"}, - {"value": 69, "name": "ASTC 5x4 unorm srgb", "jsrepr": "'astc-5x4-unorm-srgb'"}, - {"value": 70, "name": "ASTC 5x5 unorm", "jsrepr": "'astc-5x5-unorm'"}, - {"value": 71, "name": "ASTC 5x5 unorm srgb", "jsrepr": "'astc-5x5-unorm-srgb'"}, - {"value": 72, "name": "ASTC 6x5 unorm", "jsrepr": "'astc-6x5-unorm'"}, - {"value": 73, "name": "ASTC 6x5 unorm srgb", "jsrepr": "'astc-6x5-unorm-srgb'"}, - {"value": 74, "name": "ASTC 6x6 unorm", "jsrepr": "'astc-6x6-unorm'"}, - {"value": 75, "name": "ASTC 6x6 unorm srgb", "jsrepr": "'astc-6x6-unorm-srgb'"}, - {"value": 76, "name": "ASTC 8x5 unorm", "jsrepr": "'astc-8x5-unorm'"}, - {"value": 77, "name": "ASTC 8x5 unorm srgb", "jsrepr": "'astc-8x5-unorm-srgb'"}, - {"value": 78, "name": "ASTC 8x6 unorm", "jsrepr": "'astc-8x6-unorm'"}, - {"value": 79, "name": "ASTC 8x6 unorm srgb", "jsrepr": "'astc-8x6-unorm-srgb'"}, - {"value": 80, "name": "ASTC 8x8 unorm", "jsrepr": "'astc-8x8-unorm'"}, - {"value": 81, "name": "ASTC 8x8 unorm srgb", "jsrepr": "'astc-8x8-unorm-srgb'"}, - {"value": 82, "name": "ASTC 10x5 unorm", "jsrepr": "'astc-10x5-unorm'"}, - {"value": 83, "name": "ASTC 10x5 unorm srgb", "jsrepr": "'astc-10x5-unorm-srgb'"}, - {"value": 84, "name": "ASTC 10x6 unorm", "jsrepr": "'astc-10x6-unorm'"}, - {"value": 85, "name": "ASTC 10x6 unorm srgb", "jsrepr": "'astc-10x6-unorm-srgb'"}, - {"value": 86, "name": "ASTC 10x8 unorm", "jsrepr": "'astc-10x8-unorm'"}, - {"value": 87, "name": "ASTC 10x8 unorm srgb", "jsrepr": "'astc-10x8-unorm-srgb'"}, - {"value": 88, "name": "ASTC 10x10 unorm", "jsrepr": "'astc-10x10-unorm'"}, - {"value": 89, "name": "ASTC 10x10 unorm srgb", "jsrepr": "'astc-10x10-unorm-srgb'"}, - {"value": 90, "name": "ASTC 12x10 unorm", "jsrepr": "'astc-12x10-unorm'"}, - {"value": 91, "name": "ASTC 12x10 unorm srgb", "jsrepr": "'astc-12x10-unorm-srgb'"}, - {"value": 92, "name": "ASTC 12x12 unorm", "jsrepr": "'astc-12x12-unorm'"}, - {"value": 93, "name": "ASTC 12x12 unorm srgb", "jsrepr": "'astc-12x12-unorm-srgb'"}, + {"value": 68, "name": "ASTC 4x4 unorm", "jsrepr": "'astc-4x4-unorm'"}, + {"value": 69, "name": "ASTC 4x4 unorm srgb", "jsrepr": "'astc-4x4-unorm-srgb'"}, + {"value": 70, "name": "ASTC 5x4 unorm", "jsrepr": "'astc-5x4-unorm'"}, + {"value": 71, "name": "ASTC 5x4 unorm srgb", "jsrepr": "'astc-5x4-unorm-srgb'"}, + {"value": 72, "name": "ASTC 5x5 unorm", "jsrepr": "'astc-5x5-unorm'"}, + {"value": 73, "name": "ASTC 5x5 unorm srgb", "jsrepr": "'astc-5x5-unorm-srgb'"}, + {"value": 74, "name": "ASTC 6x5 unorm", "jsrepr": "'astc-6x5-unorm'"}, + {"value": 75, "name": "ASTC 6x5 unorm srgb", "jsrepr": "'astc-6x5-unorm-srgb'"}, + {"value": 76, "name": "ASTC 6x6 unorm", "jsrepr": "'astc-6x6-unorm'"}, + {"value": 77, "name": "ASTC 6x6 unorm srgb", "jsrepr": "'astc-6x6-unorm-srgb'"}, + {"value": 78, "name": "ASTC 8x5 unorm", "jsrepr": "'astc-8x5-unorm'"}, + {"value": 79, "name": "ASTC 8x5 unorm srgb", "jsrepr": "'astc-8x5-unorm-srgb'"}, + {"value": 80, "name": "ASTC 8x6 unorm", "jsrepr": "'astc-8x6-unorm'"}, + {"value": 81, "name": "ASTC 8x6 unorm srgb", "jsrepr": "'astc-8x6-unorm-srgb'"}, + {"value": 82, "name": "ASTC 8x8 unorm", "jsrepr": "'astc-8x8-unorm'"}, + {"value": 83, "name": "ASTC 8x8 unorm srgb", "jsrepr": "'astc-8x8-unorm-srgb'"}, + {"value": 84, "name": "ASTC 10x5 unorm", "jsrepr": "'astc-10x5-unorm'"}, + {"value": 85, "name": "ASTC 10x5 unorm srgb", "jsrepr": "'astc-10x5-unorm-srgb'"}, + {"value": 86, "name": "ASTC 10x6 unorm", "jsrepr": "'astc-10x6-unorm'"}, + {"value": 87, "name": "ASTC 10x6 unorm srgb", "jsrepr": "'astc-10x6-unorm-srgb'"}, + {"value": 88, "name": "ASTC 10x8 unorm", "jsrepr": "'astc-10x8-unorm'"}, + {"value": 89, "name": "ASTC 10x8 unorm srgb", "jsrepr": "'astc-10x8-unorm-srgb'"}, + {"value": 90, "name": "ASTC 10x10 unorm", "jsrepr": "'astc-10x10-unorm'"}, + {"value": 91, "name": "ASTC 10x10 unorm srgb", "jsrepr": "'astc-10x10-unorm-srgb'"}, + {"value": 92, "name": "ASTC 12x10 unorm", "jsrepr": "'astc-12x10-unorm'"}, + {"value": 93, "name": "ASTC 12x10 unorm srgb", "jsrepr": "'astc-12x10-unorm-srgb'"}, + {"value": 94, "name": "ASTC 12x12 unorm", "jsrepr": "'astc-12x12-unorm'"}, + {"value": 95, "name": "ASTC 12x12 unorm srgb", "jsrepr": "'astc-12x12-unorm-srgb'"}, - {"value": 94, "name": "R8 BG8 Biplanar 420 unorm", "tags": ["dawn"]} + {"value": 96, "name": "R8 BG8 Biplanar 420 unorm", "tags": ["dawn"]} ] }, "texture usage": { diff --git a/src/dawn_native/Features.cpp b/src/dawn_native/Features.cpp index 2ec7ec3925..b09caf20b1 100644 --- a/src/dawn_native/Features.cpp +++ b/src/dawn_native/Features.cpp @@ -64,6 +64,14 @@ namespace dawn_native { {"depth-clamping", "Clamp depth to [0, 1] in NDC space instead of clipping", "https://bugs.chromium.org/p/dawn/issues/detail?id=716"}, &WGPUDeviceProperties::depthClamping}, + {Feature::Depth24UnormStencil8, + {"depth24unorm-stencil8", "Support depth24unorm-stencil8 texture format", + "https://bugs.chromium.org/p/dawn/issues/detail?id=690"}, + &WGPUDeviceProperties::depth24UnormStencil8}, + {Feature::Depth32FloatStencil8, + {"depth32float-stencil8", "Support depth32float-stencil8 texture format", + "https://bugs.chromium.org/p/dawn/issues/detail?id=690"}, + &WGPUDeviceProperties::depth32FloatStencil8}, {Feature::DawnInternalUsages, {"dawn-internal-usages", "Add internal usages to resources to affect how the texture is allocated, but not " diff --git a/src/dawn_native/Features.h b/src/dawn_native/Features.h index 35bdf4f8b9..699ddc794e 100644 --- a/src/dawn_native/Features.h +++ b/src/dawn_native/Features.h @@ -31,6 +31,8 @@ namespace dawn_native { PipelineStatisticsQuery, TimestampQuery, DepthClamping, + Depth24UnormStencil8, + Depth32FloatStencil8, // Dawn-specific DawnInternalUsages, diff --git a/src/dawn_native/Format.cpp b/src/dawn_native/Format.cpp index a6ebe4849d..c8d0588369 100644 --- a/src/dawn_native/Format.cpp +++ b/src/dawn_native/Format.cpp @@ -335,8 +335,13 @@ namespace dawn_native { AddDepthFormat(wgpu::TextureFormat::Depth24Plus, 4, true); AddMultiAspectFormat(wgpu::TextureFormat::Depth24PlusStencil8, Aspect::Depth | Aspect::Stencil, wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Stencil8, true, true, 2); + bool isD24S8Supported = device->IsFeatureEnabled(Feature::Depth24UnormStencil8); + AddMultiAspectFormat(wgpu::TextureFormat::Depth24UnormStencil8, + Aspect::Depth | Aspect::Stencil, wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Stencil8, true, isD24S8Supported, 2); AddDepthFormat(wgpu::TextureFormat::Depth32Float, 4, true); - // TODO(dawn:690): Implement Depth24UnormStencil8, Depth32FloatStencil8. + bool isD32S8Supported = device->IsFeatureEnabled(Feature::Depth32FloatStencil8); + AddMultiAspectFormat(wgpu::TextureFormat::Depth32FloatStencil8, + Aspect::Depth | Aspect::Stencil, wgpu::TextureFormat::Depth32Float, wgpu::TextureFormat::Stencil8, true, isD32S8Supported, 2); // BC compressed formats bool isBCFormatSupported = device->IsFeatureEnabled(Feature::TextureCompressionBC); diff --git a/src/dawn_native/Format.h b/src/dawn_native/Format.h index 1e2798704d..f2e83ff823 100644 --- a/src/dawn_native/Format.h +++ b/src/dawn_native/Format.h @@ -77,7 +77,7 @@ namespace dawn_native { // The number of formats Dawn knows about. Asserts in BuildFormatTable ensure that this is the // exact number of known format. - static constexpr size_t kKnownFormatCount = 94; + static constexpr size_t kKnownFormatCount = 96; struct Format; using FormatTable = std::array; diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index 084634c1e1..ccfbbd8f96 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -252,6 +252,10 @@ namespace dawn_native { namespace d3d12 { case wgpu::TextureFormat::R8BG8Biplanar420Unorm: // TODO(dawn:666): implement stencil8 case wgpu::TextureFormat::Stencil8: + // TODO(dawn:690): implement depth24unorm-stencil8 + case wgpu::TextureFormat::Depth24UnormStencil8: + // TODO(dawn:690): implement depth32float-stencil8 + case wgpu::TextureFormat::Depth32FloatStencil8: case wgpu::TextureFormat::Undefined: UNREACHABLE(); } @@ -421,6 +425,10 @@ namespace dawn_native { namespace d3d12 { // TODO(dawn:666): implement stencil8 case wgpu::TextureFormat::Stencil8: + // TODO(dawn:690): implement depth24unorm-stencil8 + case wgpu::TextureFormat::Depth24UnormStencil8: + // TODO(dawn:690): implement depth32float-stencil8 + case wgpu::TextureFormat::Depth32FloatStencil8: case wgpu::TextureFormat::Undefined: UNREACHABLE(); } diff --git a/src/dawn_native/metal/TextureMTL.mm b/src/dawn_native/metal/TextureMTL.mm index 4edde099df..c415a55baf 100644 --- a/src/dawn_native/metal/TextureMTL.mm +++ b/src/dawn_native/metal/TextureMTL.mm @@ -321,6 +321,10 @@ namespace dawn_native { namespace metal { // TODO(dawn:666): implement stencil8 case wgpu::TextureFormat::Stencil8: + // TODO(dawn:690): implement depth24unorm-stencil8 + case wgpu::TextureFormat::Depth24UnormStencil8: + // TODO(dawn:690): implement depth32float-stencil8 + case wgpu::TextureFormat::Depth32FloatStencil8: case wgpu::TextureFormat::Undefined: UNREACHABLE(); } diff --git a/src/dawn_native/vulkan/AdapterVk.cpp b/src/dawn_native/vulkan/AdapterVk.cpp index 10ae4f2a7d..8f50465a20 100644 --- a/src/dawn_native/vulkan/AdapterVk.cpp +++ b/src/dawn_native/vulkan/AdapterVk.cpp @@ -40,6 +40,16 @@ namespace dawn_native { namespace vulkan { return mBackend; } + bool Adapter::IsDepthStencilFormatSupported(VkFormat format) { + ASSERT(format == VK_FORMAT_D16_UNORM_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT || + format == VK_FORMAT_D32_SFLOAT_S8_UINT); + + VkFormatProperties properties; + GetBackend()->GetFunctions().GetPhysicalDeviceFormatProperties(mPhysicalDevice, format, + &properties); + return properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; + } + MaybeError Adapter::InitializeImpl() { DAWN_TRY_ASSIGN(mDeviceInfo, GatherDeviceInfo(*this)); diff --git a/src/dawn_native/vulkan/AdapterVk.h b/src/dawn_native/vulkan/AdapterVk.h index 548370ad6a..a13c0695fe 100644 --- a/src/dawn_native/vulkan/AdapterVk.h +++ b/src/dawn_native/vulkan/AdapterVk.h @@ -36,6 +36,8 @@ namespace dawn_native { namespace vulkan { VkPhysicalDevice GetPhysicalDevice() const; Backend* GetBackend() const; + bool IsDepthStencilFormatSupported(VkFormat format); + private: MaybeError InitializeImpl() override; MaybeError InitializeSupportedFeaturesImpl() override; diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index d5db95df5e..02fc43bf4b 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -497,25 +497,10 @@ namespace dawn_native { namespace vulkan { } void Device::ApplyDepth24PlusS8Toggle() { - VkPhysicalDevice physicalDevice = ToBackend(GetAdapter())->GetPhysicalDevice(); - - bool supportsD32s8 = false; - { - VkFormatProperties properties; - fn.GetPhysicalDeviceFormatProperties(physicalDevice, VK_FORMAT_D32_SFLOAT_S8_UINT, - &properties); - supportsD32s8 = - properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; - } - - bool supportsD24s8 = false; - { - VkFormatProperties properties; - fn.GetPhysicalDeviceFormatProperties(physicalDevice, VK_FORMAT_D24_UNORM_S8_UINT, - &properties); - supportsD24s8 = - properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; - } + bool supportsD32s8 = + ToBackend(GetAdapter())->IsDepthStencilFormatSupported(VK_FORMAT_D32_SFLOAT_S8_UINT); + bool supportsD24s8 = + ToBackend(GetAdapter())->IsDepthStencilFormatSupported(VK_FORMAT_D24_UNORM_S8_UINT); ASSERT(supportsD32s8 || supportsD24s8); diff --git a/src/dawn_native/vulkan/TextureVk.cpp b/src/dawn_native/vulkan/TextureVk.cpp index 1c97dd9ec7..4162615112 100644 --- a/src/dawn_native/vulkan/TextureVk.cpp +++ b/src/dawn_native/vulkan/TextureVk.cpp @@ -419,6 +419,10 @@ namespace dawn_native { namespace vulkan { case wgpu::TextureFormat::R8BG8Biplanar420Unorm: // TODO(dawn:666): implement stencil8 case wgpu::TextureFormat::Stencil8: + // TODO(dawn:690): implement depth24unorm-stencil8 + case wgpu::TextureFormat::Depth24UnormStencil8: + // TODO(dawn:690): implement depth32float-stencil8 + case wgpu::TextureFormat::Depth32FloatStencil8: case wgpu::TextureFormat::Undefined: break; } diff --git a/src/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp b/src/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp index 9d475c598b..af0338e401 100644 --- a/src/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp +++ b/src/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp @@ -33,6 +33,33 @@ class ReadOnlyDepthStencilAttachmentTests uint32_t stencilInitValue; uint32_t stencilRefValue; }; + + std::vector GetRequiredFeatures() override { + switch (GetParam().mTextureFormat) { + case wgpu::TextureFormat::Depth24UnormStencil8: + if (SupportsFeatures({"depth24unorm-stencil8"})) { + mIsFormatSupported = true; + return {"depth24unorm-stencil8"}; + } + + return {}; + case wgpu::TextureFormat::Depth32FloatStencil8: + if (SupportsFeatures({"depth32float-stencil8"})) { + mIsFormatSupported = true; + return {"depth32float-stencil8"}; + } + + return {}; + default: + mIsFormatSupported = true; + return {}; + } + } + + bool IsFormatSupported() const { + return mIsFormatSupported; + } + wgpu::RenderPipeline CreateRenderPipeline(wgpu::TextureAspect aspect, wgpu::TextureFormat format) { utils::ComboRenderPipelineDescriptor pipelineDescriptor; @@ -158,9 +185,18 @@ class ReadOnlyDepthStencilAttachmentTests wgpu::CommandBuffer commands = commandEncoder.Finish(); queue.Submit(1, &commands); } + + private: + bool mIsFormatSupported = false; }; -class ReadOnlyDepthAttachmentTests : public ReadOnlyDepthStencilAttachmentTests {}; +class ReadOnlyDepthAttachmentTests : public ReadOnlyDepthStencilAttachmentTests { + protected: + void SetUp() override { + ReadOnlyDepthStencilAttachmentTests::SetUp(); + DAWN_TEST_UNSUPPORTED_IF(!IsFormatSupported()); + } +}; TEST_P(ReadOnlyDepthAttachmentTests, Test) { wgpu::Texture colorTexture = @@ -185,7 +221,13 @@ TEST_P(ReadOnlyDepthAttachmentTests, Test) { {kSize, kSize / 2}); } -class ReadOnlyStencilAttachmentTests : public ReadOnlyDepthStencilAttachmentTests {}; +class ReadOnlyStencilAttachmentTests : public ReadOnlyDepthStencilAttachmentTests { + protected: + void SetUp() override { + ReadOnlyDepthStencilAttachmentTests::SetUp(); + DAWN_TEST_UNSUPPORTED_IF(!IsFormatSupported()); + } +}; TEST_P(ReadOnlyStencilAttachmentTests, Test) { wgpu::Texture colorTexture = diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp index df93cc06c5..9dbf0d058b 100644 --- a/src/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -28,6 +28,11 @@ namespace { wgpu::TextureFormat::RGBA8Snorm, }; + wgpu::TextureDimension kDimensions[] = { + wgpu::TextureDimension::e1D, + wgpu::TextureDimension::e3D, + }; + class TextureValidationTest : public ValidationTest { protected: void SetUp() override { @@ -426,21 +431,13 @@ namespace { TEST_F(TextureValidationTest, DepthStencilFormatsFor3D) { wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); - wgpu::TextureDimension dimensions[] = { - wgpu::TextureDimension::e1D, - wgpu::TextureDimension::e3D, - }; - - // TODO(dawn:690): Uncomment these depth/stencil formats after we implement them in Dawn. wgpu::TextureFormat depthStencilFormats[] = { wgpu::TextureFormat::Stencil8, wgpu::TextureFormat::Depth16Unorm, wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureFormat::Depth32Float, - // wgpu::TextureFormat::Depth24UnormStencil8, - // wgpu::TextureFormat::Depth32FloatStencil8, }; - for (wgpu::TextureDimension dimension : dimensions) { + for (wgpu::TextureDimension dimension : kDimensions) { for (wgpu::TextureFormat format : depthStencilFormats) { descriptor.format = format; descriptor.dimension = dimension; @@ -551,6 +548,22 @@ namespace { ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); } + // Test that the creation of a texture with depth24unorm-stencil8 will fail when the feature + // Depth24UnormStencil8 is not enabled. + TEST_F(TextureValidationTest, UseD24S8FormatWithoutEnablingFeature) { + wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); + descriptor.format = wgpu::TextureFormat::Depth24UnormStencil8; + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } + + // Test that the creation of a texture with depth32float-stencil8 will fail when the feature + // Depth32FloatStencil8 is not enabled. + TEST_F(TextureValidationTest, UseD32S8FormatWithoutEnablingFeature) { + wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); + descriptor.format = wgpu::TextureFormat::Depth32FloatStencil8; + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } + // Test that the creation of a texture with BC format will fail when the feature // textureCompressionBC is not enabled. TEST_F(TextureValidationTest, UseBCFormatWithoutEnablingFeature) { @@ -581,6 +594,46 @@ namespace { } } + class D24S8TextureFormatsValidationTests : public TextureValidationTest { + protected: + WGPUDevice CreateTestDevice() override { + dawn_native::DeviceDescriptor descriptor; + descriptor.requiredFeatures = {"depth24unorm-stencil8"}; + return adapter.CreateDevice(&descriptor); + } + }; + + // Test that depth24unorm-stencil8 format is invalid for 3D texture + TEST_F(D24S8TextureFormatsValidationTests, DepthStencilFormatsFor3D) { + wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); + + for (wgpu::TextureDimension dimension : kDimensions) { + descriptor.format = wgpu::TextureFormat::Depth24UnormStencil8; + descriptor.dimension = dimension; + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } + } + + class D32S8TextureFormatsValidationTests : public TextureValidationTest { + protected: + WGPUDevice CreateTestDevice() override { + dawn_native::DeviceDescriptor descriptor; + descriptor.requiredFeatures = {"depth32float-stencil8"}; + return adapter.CreateDevice(&descriptor); + } + }; + + // Test that depth32float-stencil8 format is invalid for 3D texture + TEST_F(D32S8TextureFormatsValidationTests, DepthStencilFormatsFor3D) { + wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); + + for (wgpu::TextureDimension dimension : kDimensions) { + descriptor.format = wgpu::TextureFormat::Depth32FloatStencil8; + descriptor.dimension = dimension; + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } + } + // TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with // compressed texture formats. class CompressedTextureFormatsValidationTests : public TextureValidationTest { diff --git a/src/tests/unittests/validation/TextureViewValidationTests.cpp b/src/tests/unittests/validation/TextureViewValidationTests.cpp index 886422d7e5..2583fbaaf8 100644 --- a/src/tests/unittests/validation/TextureViewValidationTests.cpp +++ b/src/tests/unittests/validation/TextureViewValidationTests.cpp @@ -54,6 +54,16 @@ namespace { return device.CreateTexture(&descriptor); } + wgpu::Texture CreateDepthStencilTexture(wgpu::Device& device, wgpu::TextureFormat format) { + wgpu::TextureDescriptor descriptor = {}; + descriptor.size = {kWidth, kHeight, kDepth}; + descriptor.usage = + wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::RenderAttachment; + descriptor.mipLevelCount = kDefaultMipLevels; + descriptor.format = format; + return device.CreateTexture(&descriptor); + } + wgpu::TextureViewDescriptor CreateDefaultViewDescriptor(wgpu::TextureViewDimension dimension) { wgpu::TextureViewDescriptor descriptor; descriptor.format = kDefaultTextureFormat; @@ -639,4 +649,92 @@ namespace { } } + class D24S8TextureViewValidationTests : public ValidationTest { + protected: + WGPUDevice CreateTestDevice() override { + dawn_native::DeviceDescriptor descriptor; + descriptor.requiredFeatures = {"depth24unorm-stencil8"}; + return adapter.CreateDevice(&descriptor); + } + }; + + // Test that the selected TextureAspects must exist in the Depth24UnormStencil8 texture format + TEST_F(D24S8TextureViewValidationTests, AspectMustExist) { + wgpu::Texture texture = + CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth24UnormStencil8); + + // Can select: All, DepthOnly, and StencilOnly from Depth24UnormStencil8 + { + wgpu::TextureViewDescriptor viewDescriptor = {}; + viewDescriptor.aspect = wgpu::TextureAspect::All; + texture.CreateView(&viewDescriptor); + + viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly; + texture.CreateView(&viewDescriptor); + + viewDescriptor.aspect = wgpu::TextureAspect::StencilOnly; + texture.CreateView(&viewDescriptor); + } + } + + // Test the format compatibility rules when creating a texture view. + TEST_F(D24S8TextureViewValidationTests, TextureViewFormatCompatibility) { + wgpu::Texture texture = + CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth24UnormStencil8); + + wgpu::TextureViewDescriptor base2DTextureViewDescriptor = + CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D); + + // It is an error to create a texture view in color format on a depth-stencil texture. + { + wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor; + descriptor.format = wgpu::TextureFormat::RGBA8Unorm; + ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); + } + } + + class D32S8TextureViewValidationTests : public ValidationTest { + protected: + WGPUDevice CreateTestDevice() override { + dawn_native::DeviceDescriptor descriptor; + descriptor.requiredFeatures = {"depth32float-stencil8"}; + return adapter.CreateDevice(&descriptor); + } + }; + + // Test that the selected TextureAspects must exist in the Depth32FloatStencil8 texture format + TEST_F(D32S8TextureViewValidationTests, AspectMustExist) { + wgpu::Texture texture = + CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth32FloatStencil8); + + // Can select: All, DepthOnly, and StencilOnly from Depth32FloatStencil8 + { + wgpu::TextureViewDescriptor viewDescriptor = {}; + viewDescriptor.aspect = wgpu::TextureAspect::All; + texture.CreateView(&viewDescriptor); + + viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly; + texture.CreateView(&viewDescriptor); + + viewDescriptor.aspect = wgpu::TextureAspect::StencilOnly; + texture.CreateView(&viewDescriptor); + } + } + + // Test the format compatibility rules when creating a texture view. + TEST_F(D32S8TextureViewValidationTests, TextureViewFormatCompatibility) { + wgpu::Texture texture = + CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth32FloatStencil8); + + wgpu::TextureViewDescriptor base2DTextureViewDescriptor = + CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D); + + // It is an error to create a texture view in color format on a depth-stencil texture. + { + wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor; + descriptor.format = wgpu::TextureFormat::RGBA8Unorm; + ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor)); + } + } + } // anonymous namespace diff --git a/src/utils/TextureUtils.cpp b/src/utils/TextureUtils.cpp index 4d09195f07..a56815a0ff 100644 --- a/src/utils/TextureUtils.cpp +++ b/src/utils/TextureUtils.cpp @@ -233,6 +233,8 @@ namespace utils { case wgpu::TextureFormat::Depth24Plus: case wgpu::TextureFormat::Depth24PlusStencil8: + case wgpu::TextureFormat::Depth24UnormStencil8: + case wgpu::TextureFormat::Depth32FloatStencil8: // Block size of a multi-planar format depends on aspect. case wgpu::TextureFormat::R8BG8Biplanar420Unorm: @@ -287,6 +289,8 @@ namespace utils { case wgpu::TextureFormat::Depth24Plus: case wgpu::TextureFormat::Depth24PlusStencil8: case wgpu::TextureFormat::Depth16Unorm: + case wgpu::TextureFormat::Depth24UnormStencil8: + case wgpu::TextureFormat::Depth32FloatStencil8: return 1u; case wgpu::TextureFormat::BC1RGBAUnorm: @@ -403,6 +407,8 @@ namespace utils { case wgpu::TextureFormat::Depth24Plus: case wgpu::TextureFormat::Depth24PlusStencil8: case wgpu::TextureFormat::Depth16Unorm: + case wgpu::TextureFormat::Depth24UnormStencil8: + case wgpu::TextureFormat::Depth32FloatStencil8: return 1u; case wgpu::TextureFormat::BC1RGBAUnorm: diff --git a/src/utils/TextureUtils.h b/src/utils/TextureUtils.h index 121763ac95..9fe3e48b09 100644 --- a/src/utils/TextureUtils.h +++ b/src/utils/TextureUtils.h @@ -22,7 +22,8 @@ #include "common/Assert.h" namespace utils { - static constexpr std::array kAllTextureFormats = { + // TODO(dawn:666, 570): Add Stencil8, Depth16Unorm formats if they are implemented. + static constexpr std::array kAllTextureFormats = { wgpu::TextureFormat::R8Unorm, wgpu::TextureFormat::R8Snorm, wgpu::TextureFormat::R8Uint, @@ -62,6 +63,8 @@ namespace utils { wgpu::TextureFormat::Depth32Float, wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Depth24PlusStencil8, + wgpu::TextureFormat::Depth24UnormStencil8, + wgpu::TextureFormat::Depth32FloatStencil8, wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb, wgpu::TextureFormat::BC2RGBAUnorm, @@ -179,18 +182,22 @@ namespace utils { kBCFormats.size() + kETC2Formats.size() + kASTCFormats.size(), "Number of compressed format must equal number of BC, ETC2, and ASTC formats."); - // TODO(dawn:666, 570, 690): Add more depth/stencil formats if Stencil8, Depth16Unorm, - // Depth24UnormStencil8, Depth32FloatStencil8 are implemented. - static constexpr std::array kDepthFormats = { - wgpu::TextureFormat::Depth32Float, - wgpu::TextureFormat::Depth24Plus, - wgpu::TextureFormat::Depth24PlusStencil8, + // TODO(dawn:666, 570): Add more depth/stencil formats if Stencil8, Depth16Unorm are + // implemented. + static constexpr std::array kDepthFormats = { + wgpu::TextureFormat::Depth32Float, wgpu::TextureFormat::Depth24Plus, + wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureFormat::Depth24UnormStencil8, + wgpu::TextureFormat::Depth32FloatStencil8, }; - static constexpr std::array kStencilFormats = { + static constexpr std::array kStencilFormats = { wgpu::TextureFormat::Depth24PlusStencil8, + wgpu::TextureFormat::Depth24UnormStencil8, + wgpu::TextureFormat::Depth32FloatStencil8, }; - static constexpr std::array kDepthAndStencilFormats = { + static constexpr std::array kDepthAndStencilFormats = { wgpu::TextureFormat::Depth24PlusStencil8, + wgpu::TextureFormat::Depth24UnormStencil8, + wgpu::TextureFormat::Depth32FloatStencil8, }; bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format);