[dawn][d3d] Support BGLArraySize in D3D11 and D3D12

D3D11 didn't require any backend changes, while D3D12 needed a fix to
the merging of the D3D12_DESCRIPTOR_RANGE1 to merge as soon as there is
one range (and not two as the code previously required).

Bug: 411554199, 411573959, 425328998
Change-Id: I720d2cd249105a39867f33129b4bead90e9d9cfa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/238554
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp b/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp
index c763c05..d6bd42c 100644
--- a/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp
+++ b/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp
@@ -201,9 +201,9 @@
         // Try to join this range with the previous one, if the current range is a continuation
         // of the previous. This is possible because the binding infos in the base type are
         // sorted.
-        if (descriptorRanges.size() >= 2) {
+        if (!descriptorRanges.empty()) {
             D3D12_DESCRIPTOR_RANGE1& previous = descriptorRanges.back();
-            if (previous.RangeType == range.RangeType &&
+            if (previous.RangeType == range.RangeType && previous.Flags == range.Flags &&
                 previous.BaseShaderRegister + previous.NumDescriptors == range.BaseShaderRegister) {
                 previous.NumDescriptors += range.NumDescriptors;
                 continue;
diff --git a/src/dawn/tests/end2end/BindingArrayTests.cpp b/src/dawn/tests/end2end/BindingArrayTests.cpp
index f2c97ff..dbb344d 100644
--- a/src/dawn/tests/end2end/BindingArrayTests.cpp
+++ b/src/dawn/tests/end2end/BindingArrayTests.cpp
@@ -34,6 +34,15 @@
 
 class SizedBindingArrayTests : public DawnTest {
   public:
+    void SetUp() override {
+        DawnTest::SetUp();
+
+        // TODO(https://issues.chromium.org/411573959) Fails using WARP but not on real hardware.
+        // WARP 10.0.19031.4355 samples the wrong textures when indexing while WARP 1.0.12.0 fails
+        // pipeline creation.
+        DAWN_SUPPRESS_TEST_IF(IsD3D12() && IsWARP());
+    }
+
     wgpu::Texture MakeTestR8Texture(uint8_t value) {
         wgpu::TextureDescriptor desc;
         desc.size = {1, 1};
@@ -103,6 +112,14 @@
 
 // Test accessing a binding_array with dynamically uniform values.
 TEST_P(SizedBindingArrayTests, IndexingWithDynamicallyUniformValues) {
+    // Compat should disallow dynamically uniform indexing of binding_array of textures.
+    DAWN_TEST_UNSUPPORTED_IF(IsCompatibilityMode());
+
+    // TODO(https://issues.chromium.org/425328998): D3D11 exposes core when FXC cannot support
+    // core's uniform indexing of binding_array<texture*>. We should make D3D11 expose only compat
+    // by default.
+    DAWN_SUPPRESS_TEST_IF(IsD3D11());
+
     // Make the test pipeline
     wgpu::ShaderModule module = utils::CreateShaderModule(device, R"(
         @vertex fn vs() -> @builtin(position) vec4f {
@@ -459,7 +476,11 @@
     EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(3, 2, 1, 0), rp.color, 0, 0);
 }
 
-DAWN_INSTANTIATE_TEST(SizedBindingArrayTests, MetalBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(SizedBindingArrayTests,
+                      D3D11Backend({"use_tint_ir"}, {}),
+                      D3D12Backend({"use_tint_ir"}, {}),
+                      MetalBackend(),
+                      VulkanBackend());
 
 }  // anonymous namespace
 }  // namespace dawn