From 1177c970d6c0d148fa4078333d4479e109234646 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 17 Jan 2023 19:06:12 +0000 Subject: [PATCH] Add Metal workaround to allocate stencil8 as combined depth-stencil Stencil8 textures don't work correctly on some drivers. Workaround by allocating a combined depth-stencil texture instead. Suppress newly added test on Windows ANGLE Bug: dawn:1389, dawn:1637 Change-Id: Iea03e8f3e5e7f663ffc7b344ab007a73836557cc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116846 Reviewed-by: Loko Kung Kokoro: Austin Eng Commit-Queue: Austin Eng --- src/dawn/native/Toggles.cpp | 5 ++ src/dawn/native/Toggles.h | 1 + src/dawn/native/metal/CommandBufferMTL.mm | 5 +- src/dawn/native/metal/DeviceMTL.mm | 3 + src/dawn/native/metal/RenderPipelineMTL.mm | 4 +- src/dawn/native/metal/SwapChainMTL.mm | 2 +- src/dawn/native/metal/TextureMTL.h | 3 +- src/dawn/native/metal/TextureMTL.mm | 65 +++++++++++++++---- src/dawn/native/metal/UtilsMetal.h | 2 - src/dawn/native/metal/UtilsMetal.mm | 19 ------ .../tests/end2end/DepthStencilCopyTests.cpp | 20 +++--- .../tests/end2end/DepthStencilLoadOpTests.cpp | 4 +- .../end2end/DepthStencilSamplingTests.cpp | 5 +- .../end2end/NonzeroTextureCreationTests.cpp | 49 +++++++++++++- webgpu-cts/expectations.txt | 1 - 15 files changed, 132 insertions(+), 56 deletions(-) diff --git a/src/dawn/native/Toggles.cpp b/src/dawn/native/Toggles.cpp index 2eef777ddb..8a2b11727e 100644 --- a/src/dawn/native/Toggles.cpp +++ b/src/dawn/native/Toggles.cpp @@ -326,6 +326,11 @@ static constexpr ToggleEnumAndInfoList kToggleNameAndInfoList = {{ "resources. This toggle is enabled by default on D3D12 backends using Intel Gen9.5 and Gen11 " "GPUs due to a driver issue on Intel D3D12 driver.", "https://crbug.com/1237175"}}, + {Toggle::MetalUseCombinedDepthStencilFormatForStencil8, + {"metal_use_combined_depth_stencil_format_for_stencil8", + "Use a combined depth stencil format instead of stencil8. The stencil8 format alone does not " + "work correctly.", + "https://crbug.com/dawn/1389"}}, {Toggle::DisallowDeprecatedAPIs, {"disallow_deprecated_apis", "Disallow all deprecated paths by changing the deprecation warnings to validation error for " diff --git a/src/dawn/native/Toggles.h b/src/dawn/native/Toggles.h index dc928dac8b..9aa6b86c2d 100644 --- a/src/dawn/native/Toggles.h +++ b/src/dawn/native/Toggles.h @@ -82,6 +82,7 @@ enum class Toggle { MetalUseMockBlitEncoderForWriteTimestamp, VulkanSplitCommandBufferOnDepthStencilComputeSampleAfterRenderPass, D3D12Allocate2DTexturewithCopyDstAsCommittedResource, + MetalUseCombinedDepthStencilFormatForStencil8, DisallowDeprecatedAPIs, // Unresolved issues. diff --git a/src/dawn/native/metal/CommandBufferMTL.mm b/src/dawn/native/metal/CommandBufferMTL.mm index 397591ac5f..5c37721b40 100644 --- a/src/dawn/native/metal/CommandBufferMTL.mm +++ b/src/dawn/native/metal/CommandBufferMTL.mm @@ -658,7 +658,7 @@ void RecordCopyBufferToTexture(CommandRecordingContext* commandContext, TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit( texture, mipLevel, origin, copySize, bufferSize, offset, bytesPerRow, rowsPerImage, aspect); - MTLBlitOption blitOption = ComputeMTLBlitOption(texture->GetFormat(), aspect); + MTLBlitOption blitOption = texture->ComputeMTLBlitOption(aspect); for (const auto& copyInfo : splitCopies) { uint64_t bufferOffset = copyInfo.bufferOffset; @@ -881,8 +881,7 @@ MaybeError CommandBuffer::FillCommands(CommandRecordingContext* commandContext) dst.bytesPerRow, dst.rowsPerImage, src.aspect); for (const auto& copyInfo : splitCopies) { - MTLBlitOption blitOption = - ComputeMTLBlitOption(texture->GetFormat(), src.aspect); + MTLBlitOption blitOption = texture->ComputeMTLBlitOption(src.aspect); uint64_t bufferOffset = copyInfo.bufferOffset; switch (texture->GetDimension()) { diff --git a/src/dawn/native/metal/DeviceMTL.mm b/src/dawn/native/metal/DeviceMTL.mm index a8db843c3f..5e075e8805 100644 --- a/src/dawn/native/metal/DeviceMTL.mm +++ b/src/dawn/native/metal/DeviceMTL.mm @@ -269,6 +269,9 @@ void Device::InitTogglesFromDriver() { ForceSetToggle(Toggle::NoWorkaroundIndirectBaseVertexNotApplied, true); } } + if (gpu_info::IsAMD(vendorId) || gpu_info::IsIntel(vendorId)) { + SetToggle(Toggle::MetalUseCombinedDepthStencilFormatForStencil8, true); + } #endif } diff --git a/src/dawn/native/metal/RenderPipelineMTL.mm b/src/dawn/native/metal/RenderPipelineMTL.mm index 9b9ccb4295..e082198134 100644 --- a/src/dawn/native/metal/RenderPipelineMTL.mm +++ b/src/dawn/native/metal/RenderPipelineMTL.mm @@ -364,7 +364,7 @@ MaybeError RenderPipeline::Initialize() { const auto& fragmentOutputsWritten = fragmentStage.metadata->fragmentOutputsWritten; for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) { descriptorMTL.colorAttachments[static_cast(i)].pixelFormat = - MetalPixelFormat(GetColorAttachmentFormat(i)); + MetalPixelFormat(GetDevice(), GetColorAttachmentFormat(i)); const ColorTargetState* descriptor = GetColorTargetState(i); ComputeBlendDesc(descriptorMTL.colorAttachments[static_cast(i)], descriptor, fragmentOutputsWritten[i]); @@ -374,7 +374,7 @@ MaybeError RenderPipeline::Initialize() { if (HasDepthStencilAttachment()) { wgpu::TextureFormat depthStencilFormat = GetDepthStencilFormat(); const Format& internalFormat = GetDevice()->GetValidInternalFormat(depthStencilFormat); - MTLPixelFormat metalFormat = MetalPixelFormat(depthStencilFormat); + MTLPixelFormat metalFormat = MetalPixelFormat(GetDevice(), depthStencilFormat); if (internalFormat.HasDepth()) { descriptorMTL.depthAttachmentPixelFormat = metalFormat; diff --git a/src/dawn/native/metal/SwapChainMTL.mm b/src/dawn/native/metal/SwapChainMTL.mm index 60fb77e4f1..f7f4538e01 100644 --- a/src/dawn/native/metal/SwapChainMTL.mm +++ b/src/dawn/native/metal/SwapChainMTL.mm @@ -106,7 +106,7 @@ MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) { [*mLayer setFramebufferOnly:(GetUsage() == wgpu::TextureUsage::RenderAttachment)]; [*mLayer setDevice:ToBackend(GetDevice())->GetMTLDevice()]; - [*mLayer setPixelFormat:MetalPixelFormat(GetFormat())]; + [*mLayer setPixelFormat:MetalPixelFormat(GetDevice(), GetFormat())]; #if DAWN_PLATFORM_IS(MACOS) if (@available(macos 10.13, *)) { diff --git a/src/dawn/native/metal/TextureMTL.h b/src/dawn/native/metal/TextureMTL.h index f4ae94e823..19c23b13c2 100644 --- a/src/dawn/native/metal/TextureMTL.h +++ b/src/dawn/native/metal/TextureMTL.h @@ -32,7 +32,7 @@ class CommandRecordingContext; class Device; struct MTLSharedEventAndSignalValue; -MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format); +MTLPixelFormat MetalPixelFormat(const DeviceBase* device, wgpu::TextureFormat format); MaybeError ValidateIOSurfaceCanBeWrapped(const DeviceBase* device, const TextureDescriptor* descriptor, IOSurfaceRef ioSurface); @@ -55,6 +55,7 @@ class Texture final : public TextureBase { IOSurfaceRef GetIOSurface(); NSPRef> CreateFormatView(wgpu::TextureFormat format); + MTLBlitOption ComputeMTLBlitOption(Aspect aspect) const; void EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext, const SubresourceRange& range); diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm index 42d752471e..4dc6a94d56 100644 --- a/src/dawn/native/metal/TextureMTL.mm +++ b/src/dawn/native/metal/TextureMTL.mm @@ -221,7 +221,7 @@ MTLStorageMode kIOSurfaceStorageMode = MTLStorageModePrivate; #endif } // namespace -MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format) { +MTLPixelFormat MetalPixelFormat(const DeviceBase* device, wgpu::TextureFormat format) { switch (format) { case wgpu::TextureFormat::R8Unorm: return MTLPixelFormatR8Unorm; @@ -315,6 +315,9 @@ MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format) { UNREACHABLE(); } case wgpu::TextureFormat::Stencil8: + if (device->IsToggleEnabled(Toggle::MetalUseCombinedDepthStencilFormatForStencil8)) { + return MTLPixelFormatDepth32Float_Stencil8; + } return MTLPixelFormatStencil8; #if DAWN_PLATFORM_IS(MACOS) @@ -644,7 +647,13 @@ NSRef Texture::CreateMetalTextureDescriptor() const { // between linear space and sRGB. For example, creating bgra8Unorm texture view on // rgba8Unorm texture or creating rgba8Unorm_srgb texture view on rgab8Unorm texture. mtlDesc.usage = MetalTextureUsage(GetFormat(), GetInternalUsage()); - mtlDesc.pixelFormat = MetalPixelFormat(GetFormat().format); + mtlDesc.pixelFormat = MetalPixelFormat(GetDevice(), GetFormat().format); + if (GetDevice()->IsToggleEnabled(Toggle::MetalUseCombinedDepthStencilFormatForStencil8) && + GetFormat().format == wgpu::TextureFormat::Stencil8) { + // If we used a combined depth stencil format instead of stencil8, we need + // MTLTextureUsagePixelFormatView to reinterpet as stencil8. + mtlDesc.usage |= MTLTextureUsagePixelFormatView; + } mtlDesc.mipmapLevelCount = GetNumMipLevels(); mtlDesc.storageMode = MTLStorageModePrivate; @@ -817,10 +826,10 @@ NSPRef> Texture::CreateFormatView(wgpu::TextureFormat format) { return mMtlTexture; } - ASSERT(AllowFormatReinterpretationWithoutFlag(MetalPixelFormat(GetFormat().format), - MetalPixelFormat(format))); + ASSERT(AllowFormatReinterpretationWithoutFlag(MetalPixelFormat(GetDevice(), GetFormat().format), + MetalPixelFormat(GetDevice(), format))); return AcquireNSPRef( - [mMtlTexture.Get() newTextureViewWithPixelFormat:MetalPixelFormat(format)]); + [mMtlTexture.Get() newTextureViewWithPixelFormat:MetalPixelFormat(GetDevice(), format)]); } MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, @@ -995,7 +1004,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, continue; } - MTLBlitOption blitOption = ComputeMTLBlitOption(GetFormat(), aspect); + MTLBlitOption blitOption = ComputeMTLBlitOption(aspect); [commandContext->EnsureBlit() copyFromBuffer:uploadBuffer sourceOffset:uploadHandle.startOffset @@ -1020,6 +1029,26 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, return {}; } +MTLBlitOption Texture::ComputeMTLBlitOption(Aspect aspect) const { + ASSERT(HasOneBit(aspect)); + ASSERT(GetFormat().aspects & aspect); + MTLPixelFormat format = MetalPixelFormat(GetDevice(), GetFormat().format); + + if (format == MTLPixelFormatDepth32Float_Stencil8) { + // We only provide a blit option if the format has both depth and stencil. + // It is invalid to provide a blit option otherwise. + switch (aspect) { + case Aspect::Depth: + return MTLBlitOptionDepthFromDepthStencil; + case Aspect::Stencil: + return MTLBlitOptionStencilFromDepthStencil; + default: + UNREACHABLE(); + } + } + return MTLBlitOptionNone; +} + void Texture::EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext, const SubresourceRange& range) { if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) { @@ -1042,6 +1071,7 @@ ResultOrError> TextureView::Create(TextureBase* texture, } MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { + DeviceBase* device = GetDevice(); Texture* texture = ToBackend(GetTexture()); // Texture could be destroyed by the time we make a view. @@ -1051,7 +1081,15 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { id mtlTexture = texture->GetMTLTexture(); - if (!RequiresCreatingNewTextureView(texture, descriptor)) { + bool needsNewView = RequiresCreatingNewTextureView(texture, descriptor); + if (device->IsToggleEnabled(Toggle::MetalUseCombinedDepthStencilFormatForStencil8) && + GetTexture()->GetFormat().format == wgpu::TextureFormat::Stencil8) { + // If MetalUseCombinedDepthStencilFormatForStencil8 is true and the format is Stencil8, + // we used a combined format instead on texture allocation. + // We need a new view to view it as stencil8. + needsNewView = true; + } + if (!needsNewView) { mMtlTextureView = mtlTexture; } else if (texture->GetFormat().IsMultiPlanar()) { NSRef mtlDescRef = AcquireNSRef([MTLTextureDescriptor new]); @@ -1059,7 +1097,7 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { mtlDesc.sampleCount = texture->GetSampleCount(); mtlDesc.usage = MetalTextureUsage(texture->GetFormat(), texture->GetInternalUsage()); - mtlDesc.pixelFormat = MetalPixelFormat(descriptor->format); + mtlDesc.pixelFormat = MetalPixelFormat(device, descriptor->format); mtlDesc.mipmapLevelCount = texture->GetNumMipLevels(); mtlDesc.storageMode = kIOSurfaceStorageMode; @@ -1083,10 +1121,11 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { return DAWN_INTERNAL_ERROR("Failed to create MTLTexture view for external texture."); } } else { - MTLPixelFormat viewFormat = MetalPixelFormat(descriptor->format); - MTLPixelFormat textureFormat = MetalPixelFormat(GetTexture()->GetFormat().format); - if (descriptor->aspect == wgpu::TextureAspect::StencilOnly && - textureFormat != MTLPixelFormatStencil8) { + MTLPixelFormat viewFormat = MetalPixelFormat(device, descriptor->format); + MTLPixelFormat textureFormat = MetalPixelFormat(device, GetTexture()->GetFormat().format); + + Aspect aspect = SelectFormatAspects(GetFormat(), descriptor->aspect); + if (aspect == Aspect::Stencil && textureFormat != MTLPixelFormatStencil8) { if (@available(macOS 10.12, iOS 10.0, *)) { if (textureFormat == MTLPixelFormatDepth32Float_Stencil8) { viewFormat = MTLPixelFormatX32_Stencil8; @@ -1097,7 +1136,7 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { // TODO(enga): Add a workaround to back combined depth/stencil textures // with Sampled usage using two separate textures. // Or, consider always using the workaround for D32S8. - GetDevice()->ConsumedError( + device->ConsumedError( DAWN_DEVICE_LOST_ERROR("Cannot create stencil-only texture view of " "combined depth/stencil format.")); } diff --git a/src/dawn/native/metal/UtilsMetal.h b/src/dawn/native/metal/UtilsMetal.h index f202e04fa8..a1722aab1f 100644 --- a/src/dawn/native/metal/UtilsMetal.h +++ b/src/dawn/native/metal/UtilsMetal.h @@ -79,8 +79,6 @@ void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext const TextureCopy& dst, const Extent3D& size); -MTLBlitOption ComputeMTLBlitOption(const Format& format, Aspect aspect); - // Allow use MTLStoreActionStoreAndMultismapleResolve because the logic in the backend is // first to compute what the "best" Metal render pass descriptor is, then fix it up if we // are not on macOS 10.12 (i.e. the EmulateStoreAndMSAAResolve toggle is on). diff --git a/src/dawn/native/metal/UtilsMetal.mm b/src/dawn/native/metal/UtilsMetal.mm index 6741e68516..ca4692f706 100644 --- a/src/dawn/native/metal/UtilsMetal.mm +++ b/src/dawn/native/metal/UtilsMetal.mm @@ -336,25 +336,6 @@ void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext } } -MTLBlitOption ComputeMTLBlitOption(const Format& format, Aspect aspect) { - ASSERT(HasOneBit(aspect)); - ASSERT(format.aspects & aspect); - - if (IsSubset(Aspect::Depth | Aspect::Stencil, format.aspects)) { - // We only provide a blit option if the format has both depth and stencil. - // It is invalid to provide a blit option otherwise. - switch (aspect) { - case Aspect::Depth: - return MTLBlitOptionDepthFromDepthStencil; - case Aspect::Stencil: - return MTLBlitOptionStencilFromDepthStencil; - default: - UNREACHABLE(); - } - } - return MTLBlitOptionNone; -} - MaybeError EncodeMetalRenderPass(Device* device, CommandRecordingContext* commandContext, MTLRenderPassDescriptor* mtlRenderPass, diff --git a/src/dawn/tests/end2end/DepthStencilCopyTests.cpp b/src/dawn/tests/end2end/DepthStencilCopyTests.cpp index 5fc3d54aae..2defaae896 100644 --- a/src/dawn/tests/end2end/DepthStencilCopyTests.cpp +++ b/src/dawn/tests/end2end/DepthStencilCopyTests.cpp @@ -899,13 +899,13 @@ DAWN_INSTANTIATE_TEST_P(DepthCopyFromBufferTests, std::vector(kValidDepthCopyFromBufferFormats.begin(), kValidDepthCopyFromBufferFormats.end())); -DAWN_INSTANTIATE_TEST_P(StencilCopyTests, - {D3D12Backend(), - D3D12Backend({"d3d12_use_temp_buffer_in_depth_stencil_texture_and_buffer_" - "copy_with_non_zero_buffer_offset"}), - MetalBackend(), OpenGLBackend(), OpenGLESBackend(), - // Test with the vulkan_use_s8 toggle forced on and off. - VulkanBackend({"vulkan_use_s8"}, {}), - VulkanBackend({}, {"vulkan_use_s8"})}, - std::vector(utils::kStencilFormats.begin(), - utils::kStencilFormats.end())); +DAWN_INSTANTIATE_TEST_P( + StencilCopyTests, + {D3D12Backend(), + D3D12Backend({"d3d12_use_temp_buffer_in_depth_stencil_texture_and_buffer_" + "copy_with_non_zero_buffer_offset"}), + MetalBackend(), MetalBackend({"metal_use_combined_depth_stencil_format_for_stencil8"}), + OpenGLBackend(), OpenGLESBackend(), + // Test with the vulkan_use_s8 toggle forced on and off. + VulkanBackend({"vulkan_use_s8"}, {}), VulkanBackend({}, {"vulkan_use_s8"})}, + std::vector(utils::kStencilFormats.begin(), utils::kStencilFormats.end())); diff --git a/src/dawn/tests/end2end/DepthStencilLoadOpTests.cpp b/src/dawn/tests/end2end/DepthStencilLoadOpTests.cpp index ae002911b9..45e7b68073 100644 --- a/src/dawn/tests/end2end/DepthStencilLoadOpTests.cpp +++ b/src/dawn/tests/end2end/DepthStencilLoadOpTests.cpp @@ -285,7 +285,9 @@ TEST_P(StencilClearValueOverflowTest, StencilClearValueOverFlowUint16) { DAWN_INSTANTIATE_TEST_P(StencilClearValueOverflowTest, {D3D12Backend(), D3D12Backend({}, {"use_d3d12_render_pass"}), - MetalBackend(), OpenGLBackend(), OpenGLESBackend(), VulkanBackend()}, + MetalBackend(), + MetalBackend({"metal_use_combined_depth_stencil_format_for_stencil8"}), + OpenGLBackend(), OpenGLESBackend(), VulkanBackend()}, {wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureFormat::Depth32FloatStencil8, wgpu::TextureFormat::Stencil8}, {Check::CopyStencil, Check::StencilTest}); diff --git a/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp b/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp index 65cb53863e..21547cdbab 100644 --- a/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp +++ b/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp @@ -934,7 +934,8 @@ DAWN_INSTANTIATE_TEST_P(DepthSamplingTest, utils::kDepthFormats.end())); DAWN_INSTANTIATE_TEST_P(StencilSamplingTest, - {D3D12Backend(), MetalBackend(), OpenGLBackend(), OpenGLESBackend(), - VulkanBackend()}, + {D3D12Backend(), MetalBackend(), + MetalBackend({"metal_use_combined_depth_stencil_format_for_stencil8"}), + OpenGLBackend(), OpenGLESBackend(), VulkanBackend()}, std::vector(utils::kStencilFormats.begin(), utils::kStencilFormats.end())); diff --git a/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp b/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp index 9676f54be2..c10b87668b 100644 --- a/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp +++ b/src/dawn/tests/end2end/NonzeroTextureCreationTests.cpp @@ -108,6 +108,12 @@ class NonzeroTextureCreationTests : public DawnTestWithParams { DAWN_TEST_UNSUPPORTED_IF(GetParam().mFormat == wgpu::TextureFormat::BC1RGBAUnorm && (IsOpenGL() || IsOpenGLES())); + // TODO(crbug.com/dawn/1637): Failures with ANGLE only with some format/aspect + DAWN_SUPPRESS_TEST_IF(IsWindows() && IsANGLE() && + GetParam().mAspect == wgpu::TextureAspect::All && + (GetParam().mFormat == wgpu::TextureFormat::Stencil8 || + GetParam().mFormat == wgpu::TextureFormat::Depth32Float)); + wgpu::TextureDescriptor descriptor; descriptor.dimension = GetParam().mDimension; descriptor.size.width = kSize; @@ -190,6 +196,14 @@ class NonzeroTextureCreationTests : public DawnTestWithParams { } break; } + case wgpu::TextureFormat::Stencil8: { + uint32_t texelCount = mipSize * mipSize * depthOrArrayLayers; + std::vector expectedStencil(texelCount, 1); + EXPECT_TEXTURE_EQ(expectedStencil.data(), texture, {0, 0, 0}, + {mipSize, mipSize, depthOrArrayLayers}, mip, + wgpu::TextureAspect::StencilOnly); + break; + } case wgpu::TextureFormat::BC1RGBAUnorm: { // Set buffer with dirty data so we know it is cleared by the lazy cleared // texture copy @@ -241,6 +255,7 @@ class NonzeroNonrenderableTextureCreationTests : public NonzeroTextureCreationTe class NonzeroCompressedTextureCreationTests : public NonzeroTextureCreationTests {}; class NonzeroDepthTextureCreationTests : public NonzeroTextureCreationTests {}; class NonzeroDepthStencilTextureCreationTests : public NonzeroTextureCreationTests {}; +class NonzeroStencilTextureCreationTests : public NonzeroTextureCreationTests {}; class NonzeroMultisampledTextureCreationTests : public NonzeroTextureCreationTests {}; } // anonymous namespace @@ -270,6 +285,11 @@ TEST_P(NonzeroDepthStencilTextureCreationTests, TextureCreationClears) { Run(); } +// Test that texture clears to a non-zero value because toggle is enabled. +TEST_P(NonzeroStencilTextureCreationTests, TextureCreationClears) { + Run(); +} + // Test that texture clears to a non-zero value because toggle is enabled. TEST_P(NonzeroMultisampledTextureCreationTests, TextureCreationClears) { Run(); @@ -352,7 +372,7 @@ DAWN_INSTANTIATE_TEST_P(NonzeroDepthTextureCreationTests, VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}, {"lazy_clear_resource_on_first_use"})}, {wgpu::TextureFormat::Depth32Float}, - {wgpu::TextureAspect::DepthOnly}, + {wgpu::TextureAspect::All, wgpu::TextureAspect::DepthOnly}, {wgpu::TextureUsage(wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc), wgpu::TextureUsage::CopySrc}, @@ -387,12 +407,39 @@ DAWN_INSTANTIATE_TEST_P( {1u} // sample count ); +DAWN_INSTANTIATE_TEST_P( + NonzeroStencilTextureCreationTests, + {D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}, + {"lazy_clear_resource_on_first_use"}), + MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}, + {"lazy_clear_resource_on_first_use"}), + OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}, + {"lazy_clear_resource_on_first_use"}), + OpenGLESBackend({"nonzero_clear_resources_on_creation_for_testing"}, + {"lazy_clear_resource_on_first_use"}), + VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}, + {"lazy_clear_resource_on_first_use"})}, + {wgpu::TextureFormat::Stencil8}, + {wgpu::TextureAspect::All, wgpu::TextureAspect::StencilOnly}, + {wgpu::TextureUsage(wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc | + wgpu::TextureUsage::TextureBinding), + wgpu::TextureUsage(wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::CopySrc)}, + {wgpu::TextureDimension::e2D}, + {1u, 7u}, // depth or array layers + {4u}, // mip count + {0u, 1u, 2u, 3u}, // mip + {1u} // sample count +); + DAWN_INSTANTIATE_TEST_P( NonzeroMultisampledTextureCreationTests, {D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}, {"lazy_clear_resource_on_first_use"}), MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}, {"lazy_clear_resource_on_first_use"}), + MetalBackend({"nonzero_clear_resources_on_creation_for_testing", + "metal_use_combined_depth_stencil_format_for_stencil8"}, + {"lazy_clear_resource_on_first_use"}), OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}, {"lazy_clear_resource_on_first_use"}), OpenGLESBackend({"nonzero_clear_resources_on_creation_for_testing"}, diff --git a/webgpu-cts/expectations.txt b/webgpu-cts/expectations.txt index a959ef04e8..4e3a118ca4 100644 --- a/webgpu-cts/expectations.txt +++ b/webgpu-cts/expectations.txt @@ -350,7 +350,6 @@ crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero:uninitialized_texture_is_zero:dimension="2d";readMethod="CopyToBuffer";format="depth32float-stencil8" [ Failure ] crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero:uninitialized_texture_is_zero:dimension="2d";readMethod="CopyToBuffer";format="stencil8" [ Failure ] crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero:uninitialized_texture_is_zero:dimension="2d";readMethod="CopyToTexture";format="depth16unorm" [ Failure ] -crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero:uninitialized_texture_is_zero:dimension="2d";readMethod="CopyToTexture";format="stencil8" [ Failure ] crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero:uninitialized_texture_is_zero:dimension="2d";readMethod="DepthTest";format="depth16unorm" [ Failure ] crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero:uninitialized_texture_is_zero:dimension="2d";readMethod="StencilTest";format="stencil8" [ Failure ]