From 09987b88f16920dbe195363805f341966b72335a Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 28 May 2020 08:51:23 +0000 Subject: [PATCH] Metal: Fix rendering to a layer of a depth/stencil texture Bug: dawn:430 Change-Id: Ice053a44a0720055fe02b2589153a04ffaa87e65 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22302 Commit-Queue: Corentin Wallez Reviewed-by: Corentin Wallez Reviewed-by: Jiawei Shao --- src/dawn_native/d3d12/TextureD3D12.cpp | 4 +--- src/dawn_native/metal/CommandBufferMTL.mm | 5 ++++- src/tests/end2end/SubresourceOutputAttachmentTests.cpp | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index d6d1e3a12b..d9cf9b7638 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -939,11 +939,9 @@ namespace dawn_native { namespace d3d12 { } D3D12_DEPTH_STENCIL_VIEW_DESC TextureView::GetDSVDescriptor() const { - // TODO(jiawei.shao@intel.com): support rendering into a layer of a texture. ASSERT(GetLevelCount() == 1); - uint32_t mipLevel = GetBaseMipLevel(); return ToBackend(GetTexture()) - ->GetDSVDescriptor(mipLevel, GetBaseArrayLayer(), GetLayerCount()); + ->GetDSVDescriptor(GetBaseMipLevel(), GetBaseArrayLayer(), GetLayerCount()); } D3D12_UNORDERED_ACCESS_VIEW_DESC TextureView::GetUAVDescriptor() const { diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index 2ed61e3e90..3774b8f826 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -102,13 +102,14 @@ namespace dawn_native { namespace metal { if (renderPass->attachmentState->HasDepthStencilAttachment()) { auto& attachmentInfo = renderPass->depthStencilAttachment; - // TODO(jiawei.shao@intel.com): support rendering into a layer of a texture. id texture = ToBackend(attachmentInfo.view->GetTexture())->GetMTLTexture(); const Format& format = attachmentInfo.view->GetTexture()->GetFormat(); if (format.HasDepth()) { descriptor.depthAttachment.texture = texture; + descriptor.depthAttachment.level = attachmentInfo.view->GetBaseMipLevel(); + descriptor.depthAttachment.slice = attachmentInfo.view->GetBaseArrayLayer(); switch (attachmentInfo.depthStoreOp) { case wgpu::StoreOp::Store: @@ -142,6 +143,8 @@ namespace dawn_native { namespace metal { if (format.HasStencil()) { descriptor.stencilAttachment.texture = texture; + descriptor.stencilAttachment.level = attachmentInfo.view->GetBaseMipLevel(); + descriptor.stencilAttachment.slice = attachmentInfo.view->GetBaseArrayLayer(); switch (attachmentInfo.stencilStoreOp) { case wgpu::StoreOp::Store: diff --git a/src/tests/end2end/SubresourceOutputAttachmentTests.cpp b/src/tests/end2end/SubresourceOutputAttachmentTests.cpp index 4266865101..fa08ff05d6 100644 --- a/src/tests/end2end/SubresourceOutputAttachmentTests.cpp +++ b/src/tests/end2end/SubresourceOutputAttachmentTests.cpp @@ -155,8 +155,9 @@ TEST_P(SubresourceOutputAttachmentTest, DISABLED_StencilTexture) { DoTest(Type::Stencil); } -// TODO(crbug.com/dawn/430): Implemented incorrectly on OpenGL and Metal. +// TODO(crbug.com/dawn/430): Not implemented on OpenGL DAWN_INSTANTIATE_TEST(SubresourceOutputAttachmentTest, D3D12Backend(), D3D12Backend({}, {"use_d3d12_render_pass"}), + MetalBackend(), VulkanBackend());