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 <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp
index d6d1e3a..d9cf9b7 100644
--- a/src/dawn_native/d3d12/TextureD3D12.cpp
+++ b/src/dawn_native/d3d12/TextureD3D12.cpp
@@ -939,11 +939,9 @@
     }
 
     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 2ed61e3..3774b8f 100644
--- a/src/dawn_native/metal/CommandBufferMTL.mm
+++ b/src/dawn_native/metal/CommandBufferMTL.mm
@@ -102,13 +102,14 @@
             if (renderPass->attachmentState->HasDepthStencilAttachment()) {
                 auto& attachmentInfo = renderPass->depthStencilAttachment;
 
-                // TODO(jiawei.shao@intel.com): support rendering into a layer of a texture.
                 id<MTLTexture> 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 @@
 
                 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 4266865..fa08ff0 100644
--- a/src/tests/end2end/SubresourceOutputAttachmentTests.cpp
+++ b/src/tests/end2end/SubresourceOutputAttachmentTests.cpp
@@ -155,8 +155,9 @@
     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());