Fix depth-only render pipeline creation on Metal.

Bug:

Change-Id: I6e07d2a0164386f7fe2fe1776cf8228066e23959
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/16700
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2020-03-20 09:04:00 +00:00 committed by Commit Bot service account
parent 7c24b6b2ff
commit 69c5dd70e7
2 changed files with 28 additions and 3 deletions

View File

@ -353,10 +353,16 @@ namespace dawn_native { namespace metal {
} }
if (HasDepthStencilAttachment()) { if (HasDepthStencilAttachment()) {
// TODO(kainino@chromium.org): Handle depth-only and stencil-only formats.
wgpu::TextureFormat depthStencilFormat = GetDepthStencilFormat(); wgpu::TextureFormat depthStencilFormat = GetDepthStencilFormat();
descriptorMTL.depthAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat); const Format& internalFormat = GetDevice()->GetValidInternalFormat(depthStencilFormat);
descriptorMTL.stencilAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat); MTLPixelFormat metalFormat = MetalPixelFormat(depthStencilFormat);
if (internalFormat.HasDepth()) {
descriptorMTL.depthAttachmentPixelFormat = metalFormat;
}
if (internalFormat.HasStencil()) {
descriptorMTL.stencilAttachmentPixelFormat = metalFormat;
}
} }
const ShaderModuleBase::FragmentOutputBaseTypes& fragmentOutputBaseTypes = const ShaderModuleBase::FragmentOutputBaseTypes& fragmentOutputBaseTypes =

View File

@ -681,6 +681,25 @@ TEST_P(DepthStencilStateTest, StencilDepthPass) {
2); // Replace the stencil on stencil pass, depth pass, so it should be 2 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, DAWN_INSTANTIATE_TEST(DepthStencilStateTest,
D3D12Backend(), D3D12Backend(),
MetalBackend(), MetalBackend(),