Enable Dual Source Blending Backend Enums And Tests

Enables dual source blending functionality for D3D, Vk, Metal and GL
backends. Also adds tests.

Bug: dawn:1709
Change-Id: I6ca5114d70d5647061968dc83aa812b254719696
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/144760
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Brandon1 Jones <brandon1.jones@intel.com>
diff --git a/docs/dawn/features/dual_source_blending.md b/docs/dawn/features/dual_source_blending.md
index 916537a..79f6a53 100644
--- a/docs/dawn/features/dual_source_blending.md
+++ b/docs/dawn/features/dual_source_blending.md
@@ -1,5 +1,33 @@
 # Dual Source Blending
 
-The `dual-source-blending` feature adds additional blend factors and the WGSL @index attribute to allow a fragment shader to output two colors to the same output buffer.
+The `dual-source-blending` feature adds additional blend factors and the WGSL @index attribute to allow a fragment shader to blend two color outputs into a single output buffer.
 
-TODO(dawn:1709): Add details about how to use this feature.
+This feature adds the following `wgpu::BlendFactors`:
+- `Src1`
+- `OneMinusSrc1`
+- `Src1Alpha`
+- `OneMinusSrc1Alpha`
+
+This feature introduces the @index WGSL attribute. This attribute is added to a fragment output at @location(0) to denote the blending source index. You must use `enable chromium_internal_dual_source_blending` in a shader to use the @index attribute.
+
+Example Fragment Shader:
+```
+    enable chromium_internal_dual_source_blending;
+
+    struct FragOut {
+        @location(0) @index(0) color : vec4<f32>,
+        @location(0) @index(1) blend : vec4<f32>,
+    }
+
+    @fragment fn main() -> FragOut {
+        var output : FragOut;
+        output.color = {1.0, 1.0, 1.0, 1.0};
+        output.blend = {0.5, 0.5, 0.5, 0.5};
+        return output;
+    }
+```
+
+### Restrictions:
+    - Dual source blending must occur on color attachment 0.
+    - Dual source blending makes it invalid to render to multiple render targets.
+
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index 9cb597f..f6f3a44 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -1418,6 +1418,9 @@
     if (IsToggleEnabled(Toggle::AllowUnsafeAPIs)) {
         mWGSLExtensionAllowList.insert("chromium_disable_uniformity_analysis");
     }
+    if (mEnabledFeatures.IsEnabled(Feature::DualSourceBlending)) {
+        mWGSLExtensionAllowList.insert("chromium_internal_dual_source_blending");
+    }
 }
 
 WGSLExtensionSet DeviceBase::GetWGSLExtensionAllowList() const {
diff --git a/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp b/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp
index 9da8f24..b453fb0 100644
--- a/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp
+++ b/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp
@@ -139,6 +139,7 @@
     EnableFeature(Feature::SurfaceCapabilities);
     EnableFeature(Feature::D3D11MultithreadProtected);
     EnableFeature(Feature::MSAARenderToSingleSampled);
+    EnableFeature(Feature::DualSourceBlending);
 
     // To import multi planar textures, we need to at least tier 2 support.
     if (mDeviceInfo.supportsSharedResourceCapabilityTier2) {
diff --git a/src/dawn/native/d3d11/RenderPipelineD3D11.cpp b/src/dawn/native/d3d11/RenderPipelineD3D11.cpp
index 9b8badf..2122046 100644
--- a/src/dawn/native/d3d11/RenderPipelineD3D11.cpp
+++ b/src/dawn/native/d3d11/RenderPipelineD3D11.cpp
@@ -102,9 +102,13 @@
         case wgpu::BlendFactor::OneMinusConstant:
             return D3D11_BLEND_INV_BLEND_FACTOR;
         case wgpu::BlendFactor::Src1:
+            return D3D11_BLEND_SRC1_COLOR;
         case wgpu::BlendFactor::OneMinusSrc1:
+            return D3D11_BLEND_INV_SRC1_COLOR;
         case wgpu::BlendFactor::Src1Alpha:
+            return D3D11_BLEND_SRC1_ALPHA;
         case wgpu::BlendFactor::OneMinusSrc1Alpha:
+            return D3D11_BLEND_INV_SRC1_ALPHA;
         default:
             UNREACHABLE();
     }
@@ -123,6 +127,10 @@
             return D3D11_BLEND_DEST_ALPHA;
         case wgpu::BlendFactor::OneMinusDst:
             return D3D11_BLEND_INV_DEST_ALPHA;
+        case wgpu::BlendFactor::Src1:
+            return D3D11_BLEND_SRC1_ALPHA;
+        case wgpu::BlendFactor::OneMinusSrc1:
+            return D3D11_BLEND_INV_SRC1_ALPHA;
 
         // Other blend factors translate to the same D3D11 enum as the color blend factors.
         default:
diff --git a/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp b/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
index 3681230..e4c8244 100644
--- a/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
@@ -125,6 +125,7 @@
     EnableFeature(Feature::DepthClipControl);
     EnableFeature(Feature::SurfaceCapabilities);
     EnableFeature(Feature::Float32Filterable);
+    EnableFeature(Feature::DualSourceBlending);
 
     if (AreTimestampQueriesSupported()) {
         EnableFeature(Feature::TimestampQuery);
diff --git a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp
index 9b10ecc..0751f8b 100644
--- a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp
+++ b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp
@@ -115,10 +115,13 @@
         case wgpu::BlendFactor::OneMinusConstant:
             return D3D12_BLEND_INV_BLEND_FACTOR;
         case wgpu::BlendFactor::Src1:
+            return D3D12_BLEND_SRC1_COLOR;
         case wgpu::BlendFactor::OneMinusSrc1:
+            return D3D12_BLEND_INV_SRC1_COLOR;
         case wgpu::BlendFactor::Src1Alpha:
+            return D3D12_BLEND_SRC1_ALPHA;
         case wgpu::BlendFactor::OneMinusSrc1Alpha:
-            UNREACHABLE();
+            return D3D12_BLEND_INV_SRC1_ALPHA;
     }
 }
 
@@ -135,6 +138,10 @@
             return D3D12_BLEND_DEST_ALPHA;
         case wgpu::BlendFactor::OneMinusDst:
             return D3D12_BLEND_INV_DEST_ALPHA;
+        case wgpu::BlendFactor::Src1:
+            return D3D12_BLEND_SRC1_ALPHA;
+        case wgpu::BlendFactor::OneMinusSrc1:
+            return D3D12_BLEND_INV_SRC1_ALPHA;
 
         // Other blend factors translate to the same D3D12 enum as the color blend factors.
         default:
diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm
index 0404c24..a80e825 100644
--- a/src/dawn/native/metal/BackendMTL.mm
+++ b/src/dawn/native/metal/BackendMTL.mm
@@ -531,6 +531,7 @@
         EnableFeature(Feature::BGRA8UnormStorage);
         EnableFeature(Feature::SurfaceCapabilities);
         EnableFeature(Feature::MSAARenderToSingleSampled);
+        EnableFeature(Feature::DualSourceBlending);
 
         // SIMD-scoped permute operations is supported by GPU family Metal3, Apple6, Apple7, Apple8,
         // and Mac2.
diff --git a/src/dawn/native/metal/RenderPipelineMTL.mm b/src/dawn/native/metal/RenderPipelineMTL.mm
index 24308a7..ea80598 100644
--- a/src/dawn/native/metal/RenderPipelineMTL.mm
+++ b/src/dawn/native/metal/RenderPipelineMTL.mm
@@ -162,10 +162,13 @@
         case wgpu::BlendFactor::OneMinusConstant:
             return alpha ? MTLBlendFactorOneMinusBlendAlpha : MTLBlendFactorOneMinusBlendColor;
         case wgpu::BlendFactor::Src1:
+            return MTLBlendFactorSource1Color;
         case wgpu::BlendFactor::OneMinusSrc1:
+            return MTLBlendFactorOneMinusSource1Color;
         case wgpu::BlendFactor::Src1Alpha:
+            return MTLBlendFactorSource1Alpha;
         case wgpu::BlendFactor::OneMinusSrc1Alpha:
-            UNREACHABLE();
+            return MTLBlendFactorOneMinusSource1Alpha;
     }
 }
 
diff --git a/src/dawn/native/opengl/PhysicalDeviceGL.cpp b/src/dawn/native/opengl/PhysicalDeviceGL.cpp
index 3eccb92..12f3c42 100644
--- a/src/dawn/native/opengl/PhysicalDeviceGL.cpp
+++ b/src/dawn/native/opengl/PhysicalDeviceGL.cpp
@@ -187,6 +187,12 @@
     if (mFunctions.IsGLExtensionSupported("GL_AMD_gpu_shader_half_float")) {
         EnableFeature(Feature::ShaderF16);
     }
+
+    // DualSourceBlending
+    if (mFunctions.IsGLExtensionSupported("GL_EXT_blend_func_extended") ||
+        mFunctions.IsAtLeastGL(3, 3)) {
+        EnableFeature(Feature::DualSourceBlending);
+    }
 }
 
 namespace {
diff --git a/src/dawn/native/opengl/RenderPipelineGL.cpp b/src/dawn/native/opengl/RenderPipelineGL.cpp
index 834fc62..879148c 100644
--- a/src/dawn/native/opengl/RenderPipelineGL.cpp
+++ b/src/dawn/native/opengl/RenderPipelineGL.cpp
@@ -86,9 +86,13 @@
         case wgpu::BlendFactor::OneMinusConstant:
             return alpha ? GL_ONE_MINUS_CONSTANT_ALPHA : GL_ONE_MINUS_CONSTANT_COLOR;
         case wgpu::BlendFactor::Src1:
+            return GL_SRC1_COLOR;
         case wgpu::BlendFactor::OneMinusSrc1:
+            return GL_ONE_MINUS_SRC1_COLOR;
         case wgpu::BlendFactor::Src1Alpha:
+            return GL_SRC1_ALPHA;
         case wgpu::BlendFactor::OneMinusSrc1Alpha:
+            return GL_ONE_MINUS_SRC1_ALPHA;
             UNREACHABLE();
     }
     UNREACHABLE();
diff --git a/src/dawn/native/vulkan/DeviceVk.cpp b/src/dawn/native/vulkan/DeviceVk.cpp
index 4b1c35b..cda3649 100644
--- a/src/dawn/native/vulkan/DeviceVk.cpp
+++ b/src/dawn/native/vulkan/DeviceVk.cpp
@@ -519,6 +519,10 @@
                           VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES);
     }
 
+    if (HasFeature(Feature::DualSourceBlending)) {
+        usedKnobs.features.dualSrcBlend = VK_TRUE;
+    }
+
     if (mDeviceInfo.HasExt(DeviceExt::Robustness2)) {
         ASSERT(usedKnobs.HasExt(DeviceExt::Robustness2));
 
diff --git a/src/dawn/native/vulkan/PhysicalDeviceVk.cpp b/src/dawn/native/vulkan/PhysicalDeviceVk.cpp
index 828575c..1ef89f4 100644
--- a/src/dawn/native/vulkan/PhysicalDeviceVk.cpp
+++ b/src/dawn/native/vulkan/PhysicalDeviceVk.cpp
@@ -216,6 +216,10 @@
         EnableFeature(Feature::IndirectFirstInstance);
     }
 
+    if (mDeviceInfo.features.dualSrcBlend == VK_TRUE) {
+        EnableFeature(Feature::DualSourceBlending);
+    }
+
     if (mDeviceInfo.HasExt(DeviceExt::ShaderFloat16Int8) &&
         mDeviceInfo.HasExt(DeviceExt::_16BitStorage) &&
         mDeviceInfo.shaderFloat16Int8Features.shaderFloat16 == VK_TRUE &&
diff --git a/src/dawn/native/vulkan/RenderPipelineVk.cpp b/src/dawn/native/vulkan/RenderPipelineVk.cpp
index d6713f9..128ecfe 100644
--- a/src/dawn/native/vulkan/RenderPipelineVk.cpp
+++ b/src/dawn/native/vulkan/RenderPipelineVk.cpp
@@ -195,10 +195,13 @@
         case wgpu::BlendFactor::OneMinusConstant:
             return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
         case wgpu::BlendFactor::Src1:
+            return VK_BLEND_FACTOR_SRC1_COLOR;
         case wgpu::BlendFactor::OneMinusSrc1:
+            return VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR;
         case wgpu::BlendFactor::Src1Alpha:
+            return VK_BLEND_FACTOR_SRC1_ALPHA;
         case wgpu::BlendFactor::OneMinusSrc1Alpha:
-            UNREACHABLE();
+            return VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA;
     }
     UNREACHABLE();
 }
diff --git a/src/dawn/tests/BUILD.gn b/src/dawn/tests/BUILD.gn
index cbc0c52..2c9f159 100644
--- a/src/dawn/tests/BUILD.gn
+++ b/src/dawn/tests/BUILD.gn
@@ -534,6 +534,7 @@
     "end2end/DrawIndexedTests.cpp",
     "end2end/DrawIndirectTests.cpp",
     "end2end/DrawTests.cpp",
+    "end2end/DualSourceBlendTests.cpp",
     "end2end/DynamicBufferOffsetTests.cpp",
     "end2end/EntryPointTests.cpp",
     "end2end/ExperimentalDP4aTests.cpp",
diff --git a/src/dawn/tests/end2end/DualSourceBlendTests.cpp b/src/dawn/tests/end2end/DualSourceBlendTests.cpp
new file mode 100644
index 0000000..8df7839
--- /dev/null
+++ b/src/dawn/tests/end2end/DualSourceBlendTests.cpp
@@ -0,0 +1,285 @@
+// Copyright 2023 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <algorithm>
+#include <array>
+#include <cmath>
+#include <utility>
+#include <vector>
+
+#include "dawn/common/Assert.h"
+#include "dawn/common/Constants.h"
+#include "dawn/tests/DawnTest.h"
+#include "dawn/utils/ComboRenderPipelineDescriptor.h"
+#include "dawn/utils/WGPUHelpers.h"
+
+namespace dawn {
+namespace {
+
+constexpr static unsigned int kRTSize = 1;
+
+class DualSourceBlendTests : public DawnTest {
+  protected:
+    void SetUp() override {
+        DawnTest::SetUp();
+        DAWN_TEST_UNSUPPORTED_IF(!device.HasFeature(wgpu::FeatureName::DualSourceBlending));
+
+        wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
+            device, {{0, wgpu::ShaderStage::Fragment, wgpu::BufferBindingType::Uniform}});
+        pipelineLayout = utils::MakePipelineLayout(device, {bindGroupLayout});
+
+        vsModule = utils::CreateShaderModule(device, R"(
+                @vertex
+                fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4f {
+                    var pos = array(
+                        vec2f(-1.0, -1.0),
+                        vec2f(3.0, -1.0),
+                        vec2f(-1.0, 3.0));
+                    return vec4f(pos[VertexIndex], 0.0, 1.0);
+                }
+            )");
+
+        renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
+        renderPass.renderPassInfo.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
+    }
+
+    std::vector<wgpu::FeatureName> GetRequiredFeatures() override {
+        std::vector<wgpu::FeatureName> requiredFeatures = {};
+        if (SupportsFeatures({wgpu::FeatureName::DualSourceBlending})) {
+            requiredFeatures.push_back(wgpu::FeatureName::DualSourceBlending);
+        }
+        return requiredFeatures;
+    }
+
+    struct TestParams {
+        wgpu::BlendFactor srcBlendFactor;
+        wgpu::BlendFactor dstBlendFactor;
+        utils::RGBA8 baseColor;
+        utils::RGBA8 testColorIndex0;
+        utils::RGBA8 testColorIndex1;
+    };
+
+    void RunTest(TestParams params, const utils::RGBA8& expectation) {
+        wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
+                enable chromium_internal_dual_source_blending;
+
+                struct TestData {
+                    color : vec4f,
+                    blend : vec4f
+                }
+
+                @group(0) @binding(0) var<uniform> testData : TestData;
+
+                struct FragOut {
+                  @location(0) @index(0) color : vec4<f32>,
+                  @location(0) @index(1) blend : vec4<f32>,
+                }
+
+                @fragment fn main() -> FragOut {
+                  var output : FragOut;
+                  output.color = testData.color;
+                  output.blend = testData.blend;
+                  return output;
+                }
+            )");
+
+        wgpu::BlendComponent blendComponent;
+        blendComponent.operation = wgpu::BlendOperation::Add;
+        blendComponent.srcFactor = params.srcBlendFactor;
+        blendComponent.dstFactor = params.dstBlendFactor;
+
+        wgpu::BlendState blend;
+        blend.color = blendComponent;
+        blend.alpha = blendComponent;
+
+        wgpu::ColorTargetState colorTargetState;
+        colorTargetState.blend = &blend;
+
+        utils::ComboRenderPipelineDescriptor baseDescriptor;
+        baseDescriptor.layout = pipelineLayout;
+        baseDescriptor.vertex.module = vsModule;
+        baseDescriptor.cFragment.module = fsModule;
+        baseDescriptor.cTargets[0].format = renderPass.colorFormat;
+
+        basePipeline = device.CreateRenderPipeline(&baseDescriptor);
+
+        utils::ComboRenderPipelineDescriptor testDescriptor;
+        testDescriptor.layout = pipelineLayout;
+        testDescriptor.vertex.module = vsModule;
+        testDescriptor.cFragment.module = fsModule;
+        testDescriptor.cTargets[0] = colorTargetState;
+        testDescriptor.cTargets[0].format = renderPass.colorFormat;
+
+        testPipeline = device.CreateRenderPipeline(&testDescriptor);
+
+        wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+        {
+            wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
+            // First use the base pipeline to draw a triangle with no blending
+            pass.SetPipeline(basePipeline);
+            wgpu::BindGroup baseColors = MakeBindGroupForColors(
+                std::array<utils::RGBA8, 2>({{params.baseColor, params.baseColor}}));
+            pass.SetBindGroup(0, baseColors);
+            pass.Draw(3);
+
+            // Then use the test pipeline to draw the test triangle with blending
+            pass.SetPipeline(testPipeline);
+            pass.SetBindGroup(
+                0, MakeBindGroupForColors({params.testColorIndex0, params.testColorIndex1}));
+            pass.Draw(3);
+            pass.End();
+        }
+
+        wgpu::CommandBuffer commands = encoder.Finish();
+        queue.Submit(1, &commands);
+
+        utils::RGBA8 expectationMinusOne = utils::RGBA8(expectation.r - 1, expectation.g - 1,
+                                                        expectation.b - 1, expectation.a - 1);
+        EXPECT_PIXEL_RGBA8_BETWEEN(expectation, expectationMinusOne, renderPass.color, kRTSize / 2,
+                                   kRTSize / 2);
+    }
+
+    // Create a bind group to set the colors as a uniform buffer
+    wgpu::BindGroup MakeBindGroupForColors(std::array<utils::RGBA8, 2> colors) {
+        std::array<float, 16> data;
+        for (unsigned int i = 0; i < 2; ++i) {
+            data[4 * i + 0] = static_cast<float>(colors[i].r) / 255.f;
+            data[4 * i + 1] = static_cast<float>(colors[i].g) / 255.f;
+            data[4 * i + 2] = static_cast<float>(colors[i].b) / 255.f;
+            data[4 * i + 3] = static_cast<float>(colors[i].a) / 255.f;
+        }
+
+        wgpu::Buffer buffer =
+            utils::CreateBufferFromData(device, &data, sizeof(data), wgpu::BufferUsage::Uniform);
+        return utils::MakeBindGroup(device, testPipeline.GetBindGroupLayout(0),
+                                    {{0, buffer, 0, sizeof(data)}});
+    }
+
+    wgpu::PipelineLayout pipelineLayout;
+    utils::BasicRenderPass renderPass;
+    wgpu::RenderPipeline basePipeline;
+    wgpu::RenderPipeline testPipeline;
+    wgpu::ShaderModule vsModule;
+};
+
+// Test that Src and Src1 BlendFactors work with dual source blending.
+TEST_P(DualSourceBlendTests, BlendFactorSrc1) {
+    // Test source blend factor with source index 0
+    TestParams params;
+    params.srcBlendFactor = wgpu::BlendFactor::Src;
+    params.dstBlendFactor = wgpu::BlendFactor::Zero;
+    params.baseColor = utils::RGBA8(100, 150, 200, 250);
+    params.testColorIndex0 = utils::RGBA8(100, 150, 200, 250);
+    params.testColorIndex1 = utils::RGBA8(32, 64, 96, 128);
+    RunTest(params, utils::RGBA8(39, 88, 157, 245));
+
+    // Test source blend factor with source index 1
+    params.srcBlendFactor = wgpu::BlendFactor::Src1;
+    RunTest(params, utils::RGBA8(13, 38, 75, 125));
+
+    // Test destination blend factor with source index 0
+    params.srcBlendFactor = wgpu::BlendFactor::Zero;
+    params.dstBlendFactor = wgpu::BlendFactor::Src;
+    RunTest(params, utils::RGBA8(39, 88, 157, 245));
+
+    // Test destination blend factor with source index 1
+    params.dstBlendFactor = wgpu::BlendFactor::Src1;
+    RunTest(params, utils::RGBA8(13, 38, 75, 125));
+}
+
+// Test that SrcAlpha and SrcAlpha1 BlendFactors work with dual source blending.
+TEST_P(DualSourceBlendTests, BlendFactorSrc1Alpha) {
+    // Test source blend factor with source alpha index 0
+    TestParams params;
+    params.srcBlendFactor = wgpu::BlendFactor::SrcAlpha;
+    params.dstBlendFactor = wgpu::BlendFactor::Zero;
+    params.baseColor = utils::RGBA8(100, 150, 200, 250);
+    params.testColorIndex0 = utils::RGBA8(100, 150, 200, 250);
+    params.testColorIndex1 = utils::RGBA8(32, 64, 96, 128);
+    RunTest(params, utils::RGBA8(98, 147, 196, 245));
+
+    // Test source blend factor with source alpha index 1
+    params.srcBlendFactor = wgpu::BlendFactor::Src1Alpha;
+    RunTest(params, utils::RGBA8(50, 75, 100, 125));
+
+    // Test destination blend factor with source alpha index 0
+    params.srcBlendFactor = wgpu::BlendFactor::Zero;
+    params.dstBlendFactor = wgpu::BlendFactor::SrcAlpha;
+    RunTest(params, utils::RGBA8(98, 147, 196, 245));
+
+    // Test destination blend factor with source alpha index 1
+    params.dstBlendFactor = wgpu::BlendFactor::Src1Alpha;
+    RunTest(params, utils::RGBA8(50, 75, 100, 125));
+}
+
+// Test that OneMinusSrc and OneMinusSrc1 BlendFactors work with dual source blending.
+TEST_P(DualSourceBlendTests, BlendFactorOneMinusSrc1) {
+    // Test source blend factor with one minus source index 0
+    TestParams params;
+    params.srcBlendFactor = wgpu::BlendFactor::OneMinusSrc;
+    params.dstBlendFactor = wgpu::BlendFactor::Zero;
+    params.baseColor = utils::RGBA8(100, 150, 200, 250);
+    params.testColorIndex0 = utils::RGBA8(100, 150, 200, 250);
+    params.testColorIndex1 = utils::RGBA8(32, 64, 96, 128);
+    RunTest(params, utils::RGBA8(61, 62, 43, 5));
+
+    // Test source blend factor with one minus source index 1
+    params.srcBlendFactor = wgpu::BlendFactor::OneMinusSrc1;
+    RunTest(params, utils::RGBA8(87, 112, 125, 125));
+
+    // Test destination blend factor with one minus source index 0
+    params.srcBlendFactor = wgpu::BlendFactor::Zero;
+    params.dstBlendFactor = wgpu::BlendFactor::OneMinusSrc;
+    RunTest(params, utils::RGBA8(61, 62, 43, 5));
+
+    // Test destination blend factor with one minus source index 1
+    params.dstBlendFactor = wgpu::BlendFactor::OneMinusSrc1;
+    RunTest(params, utils::RGBA8(87, 112, 125, 125));
+}
+
+// Test that OneMinusSrcAlpha and OneMinusSrc1Alpha BlendFactors work with dual source blending.
+TEST_P(DualSourceBlendTests, BlendFactorOneMinusSrc1Alpha) {
+    // Test source blend factor with one minus source alpha index 0
+    TestParams params;
+    params.srcBlendFactor = wgpu::BlendFactor::OneMinusSrcAlpha;
+    params.dstBlendFactor = wgpu::BlendFactor::Zero;
+    params.baseColor = utils::RGBA8(100, 150, 200, 250);
+    params.testColorIndex0 = utils::RGBA8(100, 150, 200, 96);
+    params.testColorIndex1 = utils::RGBA8(32, 64, 96, 160);
+    RunTest(params, utils::RGBA8(62, 94, 125, 60));
+
+    // Test source blend factor with one minus source alpha index 1
+    params.srcBlendFactor = wgpu::BlendFactor::OneMinusSrc1Alpha;
+    RunTest(params, utils::RGBA8(37, 56, 75, 36));
+
+    // Test destination blend factor with one minus source alpha index 0
+    params.srcBlendFactor = wgpu::BlendFactor::Zero;
+    params.dstBlendFactor = wgpu::BlendFactor::OneMinusSrcAlpha;
+    RunTest(params, utils::RGBA8(62, 94, 125, 156));
+
+    // Test destination blend factor with one minus source alpha index 1
+    params.dstBlendFactor = wgpu::BlendFactor::OneMinusSrc1Alpha;
+    RunTest(params, utils::RGBA8(37, 56, 75, 93));
+}
+
+DAWN_INSTANTIATE_TEST(DualSourceBlendTests,
+                      D3D11Backend(),
+                      D3D12Backend(),
+                      MetalBackend(),
+                      OpenGLBackend(),
+                      OpenGLESBackend(),
+                      VulkanBackend());
+
+}  // anonymous namespace
+}  // namespace dawn
diff --git a/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp b/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp
index c9b04ed..5d122b6 100644
--- a/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp
@@ -2361,5 +2361,40 @@
     }
 }
 
+// Test that rendering to multiple render targets while using dual source blending results in an
+// error.
+TEST_F(DualSourceBlendingFeatureTest, MultipleRenderTargetsNotAllowed) {
+    wgpu::SupportedLimits limits;
+    device.GetLimits(&limits);
+
+    for (uint32_t location = 1; location < limits.limits.maxColorAttachments; location++) {
+        std::ostringstream sstream;
+        sstream << R"(
+                enable chromium_internal_dual_source_blending;
+
+                struct TestData {
+                    color : vec4f,
+                    blend : vec4f
+                }
+
+                @group(0) @binding(0) var<uniform> testData : TestData;
+
+                struct FragOut {
+                    @location(0) @index(0) color : vec4<f32>,
+                    @location(0) @index(1) blend : vec4<f32>,
+                    @location()"
+                << location << R"("invalidOutput : vec4<f32>
+                }
+
+                @fragment fn main() -> FragOut {
+                    var output : FragOut;
+                    output.color = testData.color;
+                    output.blend = testData.blend;
+                    return output;)";
+
+        ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, sstream.str().c_str()));
+    }
+}
+
 }  // anonymous namespace
 }  // namespace dawn
diff --git a/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp b/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp
index 3b67479..885e6aa 100644
--- a/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp
@@ -789,12 +789,12 @@
     {"chromium_experimental_dp4a", true, "chromium-experimental-dp4a"},
     {"chromium_experimental_subgroups", true, "chromium-experimental-subgroups"},
     {"chromium_disable_uniformity_analysis", true, nullptr},
+    {"chromium_internal_dual_source_blending", true, "dual-source-blending"},
 
     // Currently the following WGSL extensions are not enabled under any situation.
     /*
     {"chromium_experimental_full_ptr_parameters", true, nullptr},
     {"chromium_experimental_push_constant", true, nullptr},
-    {"chromium_internal_dual_source_blending", true, nullptr},
     {"chromium_internal_relaxed_uniform_layout", true, nullptr},
     */
 };