D3D11: Support ReadWrite storage texture access

Bug: dawn:1972
Test: dawn_end2end_tests
Change-Id: Ic917344d9ad7d357a52c443a180c4a11560c9815
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/147440
Reviewed-by: Peng Huang <penghuang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp b/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp
index 238bf56..4c3deaf 100644
--- a/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp
+++ b/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp
@@ -188,12 +188,22 @@
                     }
 
                     case BindingInfoType::StorageTexture: {
-                        ASSERT(bindingInfo.storageTexture.access ==
-                               wgpu::StorageTextureAccess::WriteOnly);
-                        ComPtr<ID3D11UnorderedAccessView> d3d11UAV;
-                        TextureView* view = ToBackend(group->GetBindingAsTextureView(bindingIndex));
-                        DAWN_TRY_ASSIGN(d3d11UAV, view->CreateD3D11UnorderedAccessView());
-                        d3d11UAVs.insert(d3d11UAVs.begin(), std::move(d3d11UAV));
+                        switch (bindingInfo.storageTexture.access) {
+                            case wgpu::StorageTextureAccess::WriteOnly:
+                            case wgpu::StorageTextureAccess::ReadWrite: {
+                                ComPtr<ID3D11UnorderedAccessView> d3d11UAV;
+                                TextureView* view =
+                                    ToBackend(group->GetBindingAsTextureView(bindingIndex));
+                                DAWN_TRY_ASSIGN(d3d11UAV, view->CreateD3D11UnorderedAccessView());
+                                d3d11UAVs.insert(d3d11UAVs.begin(), std::move(d3d11UAV));
+                                break;
+                            }
+                            // TODO(dawn:1972): Support ReadOnly storage texture access
+                            case wgpu::StorageTextureAccess::ReadOnly:
+                            default:
+                                UNREACHABLE();
+                                break;
+                        }
                         break;
                     }
                     case BindingInfoType::Texture:
@@ -371,13 +381,22 @@
             }
 
             case BindingInfoType::StorageTexture: {
-                ASSERT(bindingInfo.storageTexture.access == wgpu::StorageTextureAccess::WriteOnly);
-                if (bindingVisibility & wgpu::ShaderStage::Compute) {
-                    ComPtr<ID3D11UnorderedAccessView> d3d11UAV;
-                    TextureView* view = ToBackend(group->GetBindingAsTextureView(bindingIndex));
-                    DAWN_TRY_ASSIGN(d3d11UAV, view->CreateD3D11UnorderedAccessView());
-                    deviceContext1->CSSetUnorderedAccessViews(bindingSlot, 1,
-                                                              d3d11UAV.GetAddressOf(), nullptr);
+                TextureView* view = ToBackend(group->GetBindingAsTextureView(bindingIndex));
+                switch (bindingInfo.storageTexture.access) {
+                    case wgpu::StorageTextureAccess::WriteOnly:
+                    case wgpu::StorageTextureAccess::ReadWrite: {
+                        ComPtr<ID3D11UnorderedAccessView> d3d11UAV;
+                        DAWN_TRY_ASSIGN(d3d11UAV, view->CreateD3D11UnorderedAccessView());
+                        if (bindingVisibility & wgpu::ShaderStage::Compute) {
+                            deviceContext1->CSSetUnorderedAccessViews(
+                                bindingSlot, 1, d3d11UAV.GetAddressOf(), nullptr);
+                        }
+                        break;
+                    }
+                    // TODO(dawn:1972): Support ReadOnly storage texture access
+                    case wgpu::StorageTextureAccess::ReadOnly:
+                    default:
+                        UNREACHABLE();
                 }
                 break;
             }
@@ -485,15 +504,25 @@
             }
 
             case BindingInfoType::StorageTexture: {
-                ASSERT(bindingInfo.storageTexture.access == wgpu::StorageTextureAccess::WriteOnly);
-                ID3D11UnorderedAccessView* nullUAV = nullptr;
-                if (bindingVisibility & wgpu::ShaderStage::Fragment) {
-                    deviceContext1->OMSetRenderTargetsAndUnorderedAccessViews(
-                        D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, bindingSlot,
-                        1, &nullUAV, nullptr);
-                }
-                if (bindingVisibility & wgpu::ShaderStage::Compute) {
-                    deviceContext1->CSSetUnorderedAccessViews(bindingSlot, 1, &nullUAV, nullptr);
+                switch (bindingInfo.storageTexture.access) {
+                    case wgpu::StorageTextureAccess::WriteOnly:
+                    case wgpu::StorageTextureAccess::ReadWrite: {
+                        ID3D11UnorderedAccessView* nullUAV = nullptr;
+                        if (bindingVisibility & wgpu::ShaderStage::Fragment) {
+                            deviceContext1->OMSetRenderTargetsAndUnorderedAccessViews(
+                                D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr,
+                                bindingSlot, 1, &nullUAV, nullptr);
+                        }
+                        if (bindingVisibility & wgpu::ShaderStage::Compute) {
+                            deviceContext1->CSSetUnorderedAccessViews(bindingSlot, 1, &nullUAV,
+                                                                      nullptr);
+                        }
+                        break;
+                    }
+                    // TODO(dawn:1972): Support ReadOnly storage texture access
+                    case wgpu::StorageTextureAccess::ReadOnly:
+                    default:
+                        UNREACHABLE();
                 }
                 break;
             }
diff --git a/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp b/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp
index c00e423..b7358b4 100644
--- a/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp
+++ b/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp
@@ -75,6 +75,9 @@
                     break;
 
                 case BindingInfoType::StorageTexture:
+                    // TODO(dawn:1972): Support ReadOnly storage texture access.
+                    ASSERT(bindingInfo.storageTexture.access !=
+                           wgpu::StorageTextureAccess::ReadOnly);
                     mIndexInfo[group][bindingIndex] = --unorderedAccessViewIndex;
                     mUAVBindGroups.set(group);
                     break;
diff --git a/src/dawn/tests/end2end/StorageTextureTests.cpp b/src/dawn/tests/end2end/StorageTextureTests.cpp
index faa5b03..186a4a9 100644
--- a/src/dawn/tests/end2end/StorageTextureTests.cpp
+++ b/src/dawn/tests/end2end/StorageTextureTests.cpp
@@ -1152,8 +1152,9 @@
                               expectedData.size() * sizeof(uint32_t));
 }
 
-// TODO(dawn:1972): Support ReadWrite storage texture access on D3D11 and OpenGL backends
+// TODO(dawn:1972): Support ReadWrite storage texture access on OpenGL
 DAWN_INSTANTIATE_TEST(ReadWriteStorageTextureTests,
+                      D3D11Backend(),
                       D3D12Backend(),
                       MetalBackend(),
                       VulkanBackend());