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 <lokokung@google.com>
Kokoro: Austin Eng <enga@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2023-01-17 19:06:12 +00:00 committed by Dawn LUCI CQ
parent 330bc25322
commit 1177c970d6
15 changed files with 132 additions and 56 deletions

View File

@ -326,6 +326,11 @@ static constexpr ToggleEnumAndInfoList kToggleNameAndInfoList = {{
"resources. This toggle is enabled by default on D3D12 backends using Intel Gen9.5 and Gen11 " "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.", "GPUs due to a driver issue on Intel D3D12 driver.",
"https://crbug.com/1237175"}}, "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, {Toggle::DisallowDeprecatedAPIs,
{"disallow_deprecated_apis", {"disallow_deprecated_apis",
"Disallow all deprecated paths by changing the deprecation warnings to validation error for " "Disallow all deprecated paths by changing the deprecation warnings to validation error for "

View File

@ -82,6 +82,7 @@ enum class Toggle {
MetalUseMockBlitEncoderForWriteTimestamp, MetalUseMockBlitEncoderForWriteTimestamp,
VulkanSplitCommandBufferOnDepthStencilComputeSampleAfterRenderPass, VulkanSplitCommandBufferOnDepthStencilComputeSampleAfterRenderPass,
D3D12Allocate2DTexturewithCopyDstAsCommittedResource, D3D12Allocate2DTexturewithCopyDstAsCommittedResource,
MetalUseCombinedDepthStencilFormatForStencil8,
DisallowDeprecatedAPIs, DisallowDeprecatedAPIs,
// Unresolved issues. // Unresolved issues.

View File

@ -658,7 +658,7 @@ void RecordCopyBufferToTexture(CommandRecordingContext* commandContext,
TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit( TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit(
texture, mipLevel, origin, copySize, bufferSize, offset, bytesPerRow, rowsPerImage, aspect); 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) { for (const auto& copyInfo : splitCopies) {
uint64_t bufferOffset = copyInfo.bufferOffset; uint64_t bufferOffset = copyInfo.bufferOffset;
@ -881,8 +881,7 @@ MaybeError CommandBuffer::FillCommands(CommandRecordingContext* commandContext)
dst.bytesPerRow, dst.rowsPerImage, src.aspect); dst.bytesPerRow, dst.rowsPerImage, src.aspect);
for (const auto& copyInfo : splitCopies) { for (const auto& copyInfo : splitCopies) {
MTLBlitOption blitOption = MTLBlitOption blitOption = texture->ComputeMTLBlitOption(src.aspect);
ComputeMTLBlitOption(texture->GetFormat(), src.aspect);
uint64_t bufferOffset = copyInfo.bufferOffset; uint64_t bufferOffset = copyInfo.bufferOffset;
switch (texture->GetDimension()) { switch (texture->GetDimension()) {

View File

@ -269,6 +269,9 @@ void Device::InitTogglesFromDriver() {
ForceSetToggle(Toggle::NoWorkaroundIndirectBaseVertexNotApplied, true); ForceSetToggle(Toggle::NoWorkaroundIndirectBaseVertexNotApplied, true);
} }
} }
if (gpu_info::IsAMD(vendorId) || gpu_info::IsIntel(vendorId)) {
SetToggle(Toggle::MetalUseCombinedDepthStencilFormatForStencil8, true);
}
#endif #endif
} }

View File

@ -364,7 +364,7 @@ MaybeError RenderPipeline::Initialize() {
const auto& fragmentOutputsWritten = fragmentStage.metadata->fragmentOutputsWritten; const auto& fragmentOutputsWritten = fragmentStage.metadata->fragmentOutputsWritten;
for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) { for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) {
descriptorMTL.colorAttachments[static_cast<uint8_t>(i)].pixelFormat = descriptorMTL.colorAttachments[static_cast<uint8_t>(i)].pixelFormat =
MetalPixelFormat(GetColorAttachmentFormat(i)); MetalPixelFormat(GetDevice(), GetColorAttachmentFormat(i));
const ColorTargetState* descriptor = GetColorTargetState(i); const ColorTargetState* descriptor = GetColorTargetState(i);
ComputeBlendDesc(descriptorMTL.colorAttachments[static_cast<uint8_t>(i)], descriptor, ComputeBlendDesc(descriptorMTL.colorAttachments[static_cast<uint8_t>(i)], descriptor,
fragmentOutputsWritten[i]); fragmentOutputsWritten[i]);
@ -374,7 +374,7 @@ MaybeError RenderPipeline::Initialize() {
if (HasDepthStencilAttachment()) { if (HasDepthStencilAttachment()) {
wgpu::TextureFormat depthStencilFormat = GetDepthStencilFormat(); wgpu::TextureFormat depthStencilFormat = GetDepthStencilFormat();
const Format& internalFormat = GetDevice()->GetValidInternalFormat(depthStencilFormat); const Format& internalFormat = GetDevice()->GetValidInternalFormat(depthStencilFormat);
MTLPixelFormat metalFormat = MetalPixelFormat(depthStencilFormat); MTLPixelFormat metalFormat = MetalPixelFormat(GetDevice(), depthStencilFormat);
if (internalFormat.HasDepth()) { if (internalFormat.HasDepth()) {
descriptorMTL.depthAttachmentPixelFormat = metalFormat; descriptorMTL.depthAttachmentPixelFormat = metalFormat;

View File

@ -106,7 +106,7 @@ MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
[*mLayer setFramebufferOnly:(GetUsage() == wgpu::TextureUsage::RenderAttachment)]; [*mLayer setFramebufferOnly:(GetUsage() == wgpu::TextureUsage::RenderAttachment)];
[*mLayer setDevice:ToBackend(GetDevice())->GetMTLDevice()]; [*mLayer setDevice:ToBackend(GetDevice())->GetMTLDevice()];
[*mLayer setPixelFormat:MetalPixelFormat(GetFormat())]; [*mLayer setPixelFormat:MetalPixelFormat(GetDevice(), GetFormat())];
#if DAWN_PLATFORM_IS(MACOS) #if DAWN_PLATFORM_IS(MACOS)
if (@available(macos 10.13, *)) { if (@available(macos 10.13, *)) {

View File

@ -32,7 +32,7 @@ class CommandRecordingContext;
class Device; class Device;
struct MTLSharedEventAndSignalValue; struct MTLSharedEventAndSignalValue;
MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format); MTLPixelFormat MetalPixelFormat(const DeviceBase* device, wgpu::TextureFormat format);
MaybeError ValidateIOSurfaceCanBeWrapped(const DeviceBase* device, MaybeError ValidateIOSurfaceCanBeWrapped(const DeviceBase* device,
const TextureDescriptor* descriptor, const TextureDescriptor* descriptor,
IOSurfaceRef ioSurface); IOSurfaceRef ioSurface);
@ -55,6 +55,7 @@ class Texture final : public TextureBase {
IOSurfaceRef GetIOSurface(); IOSurfaceRef GetIOSurface();
NSPRef<id<MTLTexture>> CreateFormatView(wgpu::TextureFormat format); NSPRef<id<MTLTexture>> CreateFormatView(wgpu::TextureFormat format);
MTLBlitOption ComputeMTLBlitOption(Aspect aspect) const;
void EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext, void EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext,
const SubresourceRange& range); const SubresourceRange& range);

View File

@ -221,7 +221,7 @@ MTLStorageMode kIOSurfaceStorageMode = MTLStorageModePrivate;
#endif #endif
} // namespace } // namespace
MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format) { MTLPixelFormat MetalPixelFormat(const DeviceBase* device, wgpu::TextureFormat format) {
switch (format) { switch (format) {
case wgpu::TextureFormat::R8Unorm: case wgpu::TextureFormat::R8Unorm:
return MTLPixelFormatR8Unorm; return MTLPixelFormatR8Unorm;
@ -315,6 +315,9 @@ MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format) {
UNREACHABLE(); UNREACHABLE();
} }
case wgpu::TextureFormat::Stencil8: case wgpu::TextureFormat::Stencil8:
if (device->IsToggleEnabled(Toggle::MetalUseCombinedDepthStencilFormatForStencil8)) {
return MTLPixelFormatDepth32Float_Stencil8;
}
return MTLPixelFormatStencil8; return MTLPixelFormatStencil8;
#if DAWN_PLATFORM_IS(MACOS) #if DAWN_PLATFORM_IS(MACOS)
@ -644,7 +647,13 @@ NSRef<MTLTextureDescriptor> Texture::CreateMetalTextureDescriptor() const {
// between linear space and sRGB. For example, creating bgra8Unorm texture view on // between linear space and sRGB. For example, creating bgra8Unorm texture view on
// rgba8Unorm texture or creating rgba8Unorm_srgb texture view on rgab8Unorm texture. // rgba8Unorm texture or creating rgba8Unorm_srgb texture view on rgab8Unorm texture.
mtlDesc.usage = MetalTextureUsage(GetFormat(), GetInternalUsage()); 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.mipmapLevelCount = GetNumMipLevels();
mtlDesc.storageMode = MTLStorageModePrivate; mtlDesc.storageMode = MTLStorageModePrivate;
@ -817,10 +826,10 @@ NSPRef<id<MTLTexture>> Texture::CreateFormatView(wgpu::TextureFormat format) {
return mMtlTexture; return mMtlTexture;
} }
ASSERT(AllowFormatReinterpretationWithoutFlag(MetalPixelFormat(GetFormat().format), ASSERT(AllowFormatReinterpretationWithoutFlag(MetalPixelFormat(GetDevice(), GetFormat().format),
MetalPixelFormat(format))); MetalPixelFormat(GetDevice(), format)));
return AcquireNSPRef( return AcquireNSPRef(
[mMtlTexture.Get() newTextureViewWithPixelFormat:MetalPixelFormat(format)]); [mMtlTexture.Get() newTextureViewWithPixelFormat:MetalPixelFormat(GetDevice(), format)]);
} }
MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
@ -995,7 +1004,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
continue; continue;
} }
MTLBlitOption blitOption = ComputeMTLBlitOption(GetFormat(), aspect); MTLBlitOption blitOption = ComputeMTLBlitOption(aspect);
[commandContext->EnsureBlit() [commandContext->EnsureBlit()
copyFromBuffer:uploadBuffer copyFromBuffer:uploadBuffer
sourceOffset:uploadHandle.startOffset sourceOffset:uploadHandle.startOffset
@ -1020,6 +1029,26 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
return {}; 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, void Texture::EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext,
const SubresourceRange& range) { const SubresourceRange& range) {
if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) { if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
@ -1042,6 +1071,7 @@ ResultOrError<Ref<TextureView>> TextureView::Create(TextureBase* texture,
} }
MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) {
DeviceBase* device = GetDevice();
Texture* texture = ToBackend(GetTexture()); Texture* texture = ToBackend(GetTexture());
// Texture could be destroyed by the time we make a view. // Texture could be destroyed by the time we make a view.
@ -1051,7 +1081,15 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) {
id<MTLTexture> mtlTexture = texture->GetMTLTexture(); id<MTLTexture> 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; mMtlTextureView = mtlTexture;
} else if (texture->GetFormat().IsMultiPlanar()) { } else if (texture->GetFormat().IsMultiPlanar()) {
NSRef<MTLTextureDescriptor> mtlDescRef = AcquireNSRef([MTLTextureDescriptor new]); NSRef<MTLTextureDescriptor> mtlDescRef = AcquireNSRef([MTLTextureDescriptor new]);
@ -1059,7 +1097,7 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) {
mtlDesc.sampleCount = texture->GetSampleCount(); mtlDesc.sampleCount = texture->GetSampleCount();
mtlDesc.usage = MetalTextureUsage(texture->GetFormat(), texture->GetInternalUsage()); mtlDesc.usage = MetalTextureUsage(texture->GetFormat(), texture->GetInternalUsage());
mtlDesc.pixelFormat = MetalPixelFormat(descriptor->format); mtlDesc.pixelFormat = MetalPixelFormat(device, descriptor->format);
mtlDesc.mipmapLevelCount = texture->GetNumMipLevels(); mtlDesc.mipmapLevelCount = texture->GetNumMipLevels();
mtlDesc.storageMode = kIOSurfaceStorageMode; 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."); return DAWN_INTERNAL_ERROR("Failed to create MTLTexture view for external texture.");
} }
} else { } else {
MTLPixelFormat viewFormat = MetalPixelFormat(descriptor->format); MTLPixelFormat viewFormat = MetalPixelFormat(device, descriptor->format);
MTLPixelFormat textureFormat = MetalPixelFormat(GetTexture()->GetFormat().format); MTLPixelFormat textureFormat = MetalPixelFormat(device, GetTexture()->GetFormat().format);
if (descriptor->aspect == wgpu::TextureAspect::StencilOnly &&
textureFormat != MTLPixelFormatStencil8) { Aspect aspect = SelectFormatAspects(GetFormat(), descriptor->aspect);
if (aspect == Aspect::Stencil && textureFormat != MTLPixelFormatStencil8) {
if (@available(macOS 10.12, iOS 10.0, *)) { if (@available(macOS 10.12, iOS 10.0, *)) {
if (textureFormat == MTLPixelFormatDepth32Float_Stencil8) { if (textureFormat == MTLPixelFormatDepth32Float_Stencil8) {
viewFormat = MTLPixelFormatX32_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 // TODO(enga): Add a workaround to back combined depth/stencil textures
// with Sampled usage using two separate textures. // with Sampled usage using two separate textures.
// Or, consider always using the workaround for D32S8. // Or, consider always using the workaround for D32S8.
GetDevice()->ConsumedError( device->ConsumedError(
DAWN_DEVICE_LOST_ERROR("Cannot create stencil-only texture view of " DAWN_DEVICE_LOST_ERROR("Cannot create stencil-only texture view of "
"combined depth/stencil format.")); "combined depth/stencil format."));
} }

View File

@ -79,8 +79,6 @@ void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext
const TextureCopy& dst, const TextureCopy& dst,
const Extent3D& size); const Extent3D& size);
MTLBlitOption ComputeMTLBlitOption(const Format& format, Aspect aspect);
// Allow use MTLStoreActionStoreAndMultismapleResolve because the logic in the backend is // 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 // 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). // are not on macOS 10.12 (i.e. the EmulateStoreAndMSAAResolve toggle is on).

View File

@ -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, MaybeError EncodeMetalRenderPass(Device* device,
CommandRecordingContext* commandContext, CommandRecordingContext* commandContext,
MTLRenderPassDescriptor* mtlRenderPass, MTLRenderPassDescriptor* mtlRenderPass,

View File

@ -899,13 +899,13 @@ DAWN_INSTANTIATE_TEST_P(DepthCopyFromBufferTests,
std::vector<wgpu::TextureFormat>(kValidDepthCopyFromBufferFormats.begin(), std::vector<wgpu::TextureFormat>(kValidDepthCopyFromBufferFormats.begin(),
kValidDepthCopyFromBufferFormats.end())); kValidDepthCopyFromBufferFormats.end()));
DAWN_INSTANTIATE_TEST_P(StencilCopyTests, DAWN_INSTANTIATE_TEST_P(
{D3D12Backend(), StencilCopyTests,
D3D12Backend({"d3d12_use_temp_buffer_in_depth_stencil_texture_and_buffer_" {D3D12Backend(),
"copy_with_non_zero_buffer_offset"}), D3D12Backend({"d3d12_use_temp_buffer_in_depth_stencil_texture_and_buffer_"
MetalBackend(), OpenGLBackend(), OpenGLESBackend(), "copy_with_non_zero_buffer_offset"}),
// Test with the vulkan_use_s8 toggle forced on and off. MetalBackend(), MetalBackend({"metal_use_combined_depth_stencil_format_for_stencil8"}),
VulkanBackend({"vulkan_use_s8"}, {}), OpenGLBackend(), OpenGLESBackend(),
VulkanBackend({}, {"vulkan_use_s8"})}, // Test with the vulkan_use_s8 toggle forced on and off.
std::vector<wgpu::TextureFormat>(utils::kStencilFormats.begin(), VulkanBackend({"vulkan_use_s8"}, {}), VulkanBackend({}, {"vulkan_use_s8"})},
utils::kStencilFormats.end())); std::vector<wgpu::TextureFormat>(utils::kStencilFormats.begin(), utils::kStencilFormats.end()));

View File

@ -285,7 +285,9 @@ TEST_P(StencilClearValueOverflowTest, StencilClearValueOverFlowUint16) {
DAWN_INSTANTIATE_TEST_P(StencilClearValueOverflowTest, DAWN_INSTANTIATE_TEST_P(StencilClearValueOverflowTest,
{D3D12Backend(), D3D12Backend({}, {"use_d3d12_render_pass"}), {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::Depth24PlusStencil8,
wgpu::TextureFormat::Depth32FloatStencil8, wgpu::TextureFormat::Stencil8}, wgpu::TextureFormat::Depth32FloatStencil8, wgpu::TextureFormat::Stencil8},
{Check::CopyStencil, Check::StencilTest}); {Check::CopyStencil, Check::StencilTest});

View File

@ -934,7 +934,8 @@ DAWN_INSTANTIATE_TEST_P(DepthSamplingTest,
utils::kDepthFormats.end())); utils::kDepthFormats.end()));
DAWN_INSTANTIATE_TEST_P(StencilSamplingTest, DAWN_INSTANTIATE_TEST_P(StencilSamplingTest,
{D3D12Backend(), MetalBackend(), OpenGLBackend(), OpenGLESBackend(), {D3D12Backend(), MetalBackend(),
VulkanBackend()}, MetalBackend({"metal_use_combined_depth_stencil_format_for_stencil8"}),
OpenGLBackend(), OpenGLESBackend(), VulkanBackend()},
std::vector<wgpu::TextureFormat>(utils::kStencilFormats.begin(), std::vector<wgpu::TextureFormat>(utils::kStencilFormats.begin(),
utils::kStencilFormats.end())); utils::kStencilFormats.end()));

View File

@ -108,6 +108,12 @@ class NonzeroTextureCreationTests : public DawnTestWithParams<Params> {
DAWN_TEST_UNSUPPORTED_IF(GetParam().mFormat == wgpu::TextureFormat::BC1RGBAUnorm && DAWN_TEST_UNSUPPORTED_IF(GetParam().mFormat == wgpu::TextureFormat::BC1RGBAUnorm &&
(IsOpenGL() || IsOpenGLES())); (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; wgpu::TextureDescriptor descriptor;
descriptor.dimension = GetParam().mDimension; descriptor.dimension = GetParam().mDimension;
descriptor.size.width = kSize; descriptor.size.width = kSize;
@ -190,6 +196,14 @@ class NonzeroTextureCreationTests : public DawnTestWithParams<Params> {
} }
break; break;
} }
case wgpu::TextureFormat::Stencil8: {
uint32_t texelCount = mipSize * mipSize * depthOrArrayLayers;
std::vector<uint8_t> expectedStencil(texelCount, 1);
EXPECT_TEXTURE_EQ(expectedStencil.data(), texture, {0, 0, 0},
{mipSize, mipSize, depthOrArrayLayers}, mip,
wgpu::TextureAspect::StencilOnly);
break;
}
case wgpu::TextureFormat::BC1RGBAUnorm: { case wgpu::TextureFormat::BC1RGBAUnorm: {
// Set buffer with dirty data so we know it is cleared by the lazy cleared // Set buffer with dirty data so we know it is cleared by the lazy cleared
// texture copy // texture copy
@ -241,6 +255,7 @@ class NonzeroNonrenderableTextureCreationTests : public NonzeroTextureCreationTe
class NonzeroCompressedTextureCreationTests : public NonzeroTextureCreationTests {}; class NonzeroCompressedTextureCreationTests : public NonzeroTextureCreationTests {};
class NonzeroDepthTextureCreationTests : public NonzeroTextureCreationTests {}; class NonzeroDepthTextureCreationTests : public NonzeroTextureCreationTests {};
class NonzeroDepthStencilTextureCreationTests : public NonzeroTextureCreationTests {}; class NonzeroDepthStencilTextureCreationTests : public NonzeroTextureCreationTests {};
class NonzeroStencilTextureCreationTests : public NonzeroTextureCreationTests {};
class NonzeroMultisampledTextureCreationTests : public NonzeroTextureCreationTests {}; class NonzeroMultisampledTextureCreationTests : public NonzeroTextureCreationTests {};
} // anonymous namespace } // anonymous namespace
@ -270,6 +285,11 @@ TEST_P(NonzeroDepthStencilTextureCreationTests, TextureCreationClears) {
Run(); 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 that texture clears to a non-zero value because toggle is enabled.
TEST_P(NonzeroMultisampledTextureCreationTests, TextureCreationClears) { TEST_P(NonzeroMultisampledTextureCreationTests, TextureCreationClears) {
Run(); Run();
@ -352,7 +372,7 @@ DAWN_INSTANTIATE_TEST_P(NonzeroDepthTextureCreationTests,
VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}, VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"},
{"lazy_clear_resource_on_first_use"})}, {"lazy_clear_resource_on_first_use"})},
{wgpu::TextureFormat::Depth32Float}, {wgpu::TextureFormat::Depth32Float},
{wgpu::TextureAspect::DepthOnly}, {wgpu::TextureAspect::All, wgpu::TextureAspect::DepthOnly},
{wgpu::TextureUsage(wgpu::TextureUsage::RenderAttachment | {wgpu::TextureUsage(wgpu::TextureUsage::RenderAttachment |
wgpu::TextureUsage::CopySrc), wgpu::TextureUsage::CopySrc),
wgpu::TextureUsage::CopySrc}, wgpu::TextureUsage::CopySrc},
@ -387,12 +407,39 @@ DAWN_INSTANTIATE_TEST_P(
{1u} // sample count {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( DAWN_INSTANTIATE_TEST_P(
NonzeroMultisampledTextureCreationTests, NonzeroMultisampledTextureCreationTests,
{D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}, {D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
{"lazy_clear_resource_on_first_use"}), {"lazy_clear_resource_on_first_use"}),
MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}, MetalBackend({"nonzero_clear_resources_on_creation_for_testing"},
{"lazy_clear_resource_on_first_use"}), {"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"}, OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"},
{"lazy_clear_resource_on_first_use"}), {"lazy_clear_resource_on_first_use"}),
OpenGLESBackend({"nonzero_clear_resources_on_creation_for_testing"}, OpenGLESBackend({"nonzero_clear_resources_on_creation_for_testing"},

View File

@ -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="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="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="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="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 ] crbug.com/dawn/1389 [ monterey ] webgpu:api,operation,resource_init,texture_zero:uninitialized_texture_is_zero:dimension="2d";readMethod="StencilTest";format="stencil8" [ Failure ]