d3d11: specify planeSlice for creating SRV and RTV

Bug: chromium:324422644
Change-Id: Ib0212afab394716914c466a4c286390733906a73
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/174660
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/d3d11/TextureD3D11.cpp b/src/dawn/native/d3d11/TextureD3D11.cpp
index bae63ef..ba3dbb7 100644
--- a/src/dawn/native/d3d11/TextureD3D11.cpp
+++ b/src/dawn/native/d3d11/TextureD3D11.cpp
@@ -406,18 +406,20 @@
 }
 
 ResultOrError<ComPtr<ID3D11RenderTargetView>> Texture::CreateD3D11RenderTargetView(
-    const Format& format,
+    wgpu::TextureFormat format,
     uint32_t mipLevel,
     uint32_t baseSlice,
-    uint32_t sliceCount) const {
-    D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
-    rtvDesc.Format = d3d::DXGITextureFormat(format.format);
+    uint32_t sliceCount,
+    uint32_t planeSlice) const {
+    D3D11_RENDER_TARGET_VIEW_DESC1 rtvDesc;
+    rtvDesc.Format = d3d::DXGITextureFormat(format);
     if (IsMultisampledTexture()) {
         DAWN_ASSERT(GetDimension() == wgpu::TextureDimension::e2D);
         DAWN_ASSERT(GetNumMipLevels() == 1);
         DAWN_ASSERT(mipLevel == 0);
         DAWN_ASSERT(baseSlice == 0);
         DAWN_ASSERT(sliceCount == 1);
+        DAWN_ASSERT(planeSlice == 0);
         rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
     } else {
         switch (GetDimension()) {
@@ -434,6 +436,7 @@
                 rtvDesc.Texture2DArray.MipSlice = mipLevel;
                 rtvDesc.Texture2DArray.FirstArraySlice = baseSlice;
                 rtvDesc.Texture2DArray.ArraySize = sliceCount;
+                rtvDesc.Texture2DArray.PlaneSlice = planeSlice;
                 break;
             case wgpu::TextureDimension::e3D:
                 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
@@ -448,13 +451,13 @@
         }
     }
 
-    ComPtr<ID3D11RenderTargetView> rtv;
+    ComPtr<ID3D11RenderTargetView1> rtv;
     DAWN_TRY(CheckHRESULT(ToBackend(GetDevice())
-                              ->GetD3D11Device()
-                              ->CreateRenderTargetView(GetD3D11Resource(), &rtvDesc, &rtv),
+                              ->GetD3D11Device5()
+                              ->CreateRenderTargetView1(GetD3D11Resource(), &rtvDesc, &rtv),
                           "CreateRenderTargetView"));
 
-    return rtv;
+    return {std::move(rtv)};
 }
 
 ResultOrError<ComPtr<ID3D11DepthStencilView>> Texture::CreateD3D11DepthStencilView(
@@ -551,7 +554,6 @@
     clearRange.aspects = range.aspects;
     clearRange.layerCount = 1u;
     clearRange.levelCount = 1u;
-
     for (clearRange.baseArrayLayer = range.baseArrayLayer;
          clearRange.baseArrayLayer < range.baseArrayLayer + range.layerCount;
          ++clearRange.baseArrayLayer) {
@@ -571,19 +573,25 @@
                 commandContext->ClearDepthStencilView(
                     d3d11DSV.Get(), clearFlags, d3d11ClearValue.depth, d3d11ClearValue.stencil);
             } else {
-                ComPtr<ID3D11RenderTargetView> d3d11RTV;
-                // For the subresources of 3d textures, clearRange.baseArrayLayer must be 0 and
-                // clearRange.layerCount must be 1, the sliceCount is the depthOrArrayLayers of the
-                // subresource virtual size, which must be 1 for 2d textures. When clearing RTV, we
-                // can use the 'layer' as baseSlice and the 'depthOrArrayLayers' as sliceCount to
-                // create RTV without checking the dimension.
-                DAWN_TRY_ASSIGN(d3d11RTV,
-                                CreateD3D11RenderTargetView(
-                                    GetFormat(), clearRange.baseMipLevel, clearRange.baseArrayLayer,
-                                    GetMipLevelSingleSubresourceVirtualSize(clearRange.baseMipLevel,
-                                                                            clearRange.aspects)
-                                        .depthOrArrayLayers));
-                commandContext->ClearRenderTargetView(d3d11RTV.Get(), d3d11ClearValue.color);
+                for (auto aspect : IterateEnumMask(clearRange.aspects)) {
+                    wgpu::TextureFormat format = GetFormat().IsMultiPlanar()
+                                                     ? GetFormat().GetAspectInfo(aspect).format
+                                                     : GetFormat().format;
+                    ComPtr<ID3D11RenderTargetView> d3d11RTV;
+                    // For the subresources of 3d textures, clearRange.baseArrayLayer must be 0 and
+                    // clearRange.layerCount must be 1, the sliceCount is the depthOrArrayLayers of
+                    // the subresource virtual size, which must be 1 for 2d textures. When clearing
+                    // RTV, we can use the 'layer' as baseSlice and the 'depthOrArrayLayers' as
+                    // sliceCount to create RTV without checking the dimension.
+                    DAWN_TRY_ASSIGN(d3d11RTV,
+                                    CreateD3D11RenderTargetView(
+                                        format, clearRange.baseMipLevel, clearRange.baseArrayLayer,
+                                        GetMipLevelSingleSubresourceVirtualSize(
+                                            clearRange.baseMipLevel, clearRange.aspects)
+                                            .depthOrArrayLayers,
+                                        GetAspectIndex(aspect)));
+                    commandContext->ClearRenderTargetView(d3d11RTV.Get(), d3d11ClearValue.color);
+                }
             }
         }
     }
@@ -1231,7 +1239,7 @@
     }
 
     Device* device = ToBackend(GetDevice());
-    D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
+    D3D11_SHADER_RESOURCE_VIEW_DESC1 srvDesc;
     srvDesc.Format = d3d::DXGITextureFormat(GetFormat().format);
 
     const Format& textureFormat = GetTexture()->GetFormat();
@@ -1333,6 +1341,7 @@
                 srvDesc.Texture2DArray.FirstArraySlice = GetBaseArrayLayer();
                 srvDesc.Texture2DArray.MipLevels = GetLevelCount();
                 srvDesc.Texture2DArray.MostDetailedMip = GetBaseMipLevel();
+                srvDesc.Texture2DArray.PlaneSlice = GetAspectIndex(GetAspects());
                 break;
             case wgpu::TextureViewDimension::Cube:
             case wgpu::TextureViewDimension::CubeArray:
@@ -1356,10 +1365,11 @@
         }
     }
 
-    DAWN_TRY(CheckHRESULT(
-        device->GetD3D11Device()->CreateShaderResourceView(
-            ToBackend(GetTexture())->GetD3D11Resource(), &srvDesc, &mD3d11SharedResourceView),
-        "CreateShaderResourceView"));
+    ComPtr<ID3D11ShaderResourceView1> srv;
+    DAWN_TRY(CheckHRESULT(device->GetD3D11Device5()->CreateShaderResourceView1(
+                              ToBackend(GetTexture())->GetD3D11Resource(), &srvDesc, &srv),
+                          "CreateShaderResourceView1"));
+    mD3d11SharedResourceView = std::move(srv);
     return mD3d11SharedResourceView.Get();
 }
 
@@ -1379,11 +1389,11 @@
     // 2d RTVs, which value is set to 0. For 3d RTVs, the baseArrayLayer must be 0. So here we can
     // simply use baseArrayLayer + depthSlice to specify the slice in RTVs without checking the
     // view's dimension.
-    DAWN_TRY_ASSIGN(
-        mD3d11RenderTargetViews[depthSlice],
-        ToBackend(GetTexture())
-            ->CreateD3D11RenderTargetView(GetFormat(), GetBaseMipLevel(),
-                                          GetBaseArrayLayer() + depthSlice, GetLayerCount()));
+    DAWN_TRY_ASSIGN(mD3d11RenderTargetViews[depthSlice],
+                    ToBackend(GetTexture())
+                        ->CreateD3D11RenderTargetView(
+                            GetFormat().format, GetBaseMipLevel(), GetBaseArrayLayer() + depthSlice,
+                            GetLayerCount(), GetAspectIndex(GetAspects())));
     return mD3d11RenderTargetViews[depthSlice].Get();
 }
 
diff --git a/src/dawn/native/d3d11/TextureD3D11.h b/src/dawn/native/d3d11/TextureD3D11.h
index 0d0f5b0..99854fc 100644
--- a/src/dawn/native/d3d11/TextureD3D11.h
+++ b/src/dawn/native/d3d11/TextureD3D11.h
@@ -76,10 +76,11 @@
     ID3D11Resource* GetD3D11Resource() const;
 
     ResultOrError<ComPtr<ID3D11RenderTargetView>> CreateD3D11RenderTargetView(
-        const Format& format,
+        wgpu::TextureFormat format,
         uint32_t mipLevel,
         uint32_t baseSlice,
-        uint32_t sliceCount) const;
+        uint32_t sliceCount,
+        uint32_t planeSlice) const;
     ResultOrError<ComPtr<ID3D11DepthStencilView>> CreateD3D11DepthStencilView(
         const SubresourceRange& singleLevelRange,
         bool depthReadOnly,