diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm index 7177fff222..6bf8f0749a 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.mm +++ b/src/dawn_native/metal/RenderPipelineMTL.mm @@ -353,10 +353,16 @@ namespace dawn_native { namespace metal { } if (HasDepthStencilAttachment()) { - // TODO(kainino@chromium.org): Handle depth-only and stencil-only formats. wgpu::TextureFormat depthStencilFormat = GetDepthStencilFormat(); - descriptorMTL.depthAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat); - descriptorMTL.stencilAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat); + const Format& internalFormat = GetDevice()->GetValidInternalFormat(depthStencilFormat); + MTLPixelFormat metalFormat = MetalPixelFormat(depthStencilFormat); + + if (internalFormat.HasDepth()) { + descriptorMTL.depthAttachmentPixelFormat = metalFormat; + } + if (internalFormat.HasStencil()) { + descriptorMTL.stencilAttachmentPixelFormat = metalFormat; + } } const ShaderModuleBase::FragmentOutputBaseTypes& fragmentOutputBaseTypes = diff --git a/src/tests/end2end/DepthStencilStateTests.cpp b/src/tests/end2end/DepthStencilStateTests.cpp index 3385db6adb..7625f421cb 100644 --- a/src/tests/end2end/DepthStencilStateTests.cpp +++ b/src/tests/end2end/DepthStencilStateTests.cpp @@ -681,6 +681,25 @@ TEST_P(DepthStencilStateTest, StencilDepthPass) { 2); // Replace the stencil on stencil pass, depth pass, so it should be 2 } +// Test that creating a render pipeline works with for all depth and combined formats +TEST_P(DepthStencilStateTest, CreatePipelineWithAllFormats) { + constexpr wgpu::TextureFormat kDepthStencilFormats[] = { + wgpu::TextureFormat::Depth32Float, + wgpu::TextureFormat::Depth24PlusStencil8, + wgpu::TextureFormat::Depth24Plus, + }; + + for (wgpu::TextureFormat depthStencilFormat : kDepthStencilFormats) { + utils::ComboRenderPipelineDescriptor descriptor(device); + descriptor.vertexStage.module = vsModule; + descriptor.cFragmentStage.module = fsModule; + descriptor.cDepthStencilState.format = depthStencilFormat; + descriptor.depthStencilState = &descriptor.cDepthStencilState; + + device.CreateRenderPipeline(&descriptor); + } +} + DAWN_INSTANTIATE_TEST(DepthStencilStateTest, D3D12Backend(), MetalBackend(),