d3d11: Fix alpha factor
Use explicit alpha factors for the alpha channel.
Bug: dawn:1893
Bug: dawn:1705
Change-Id: Ie7784bf83f4cf58c0c802a7ef4222a7926ed5702
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/139581
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Peng Huang <penghuang@chromium.org>
diff --git a/src/dawn/native/d3d11/RenderPipelineD3D11.cpp b/src/dawn/native/d3d11/RenderPipelineD3D11.cpp
index d3b8f6f..d879d1b 100644
--- a/src/dawn/native/d3d11/RenderPipelineD3D11.cpp
+++ b/src/dawn/native/d3d11/RenderPipelineD3D11.cpp
@@ -106,6 +106,26 @@
}
}
+// When a blend factor is defined for the alpha channel, any of the factors that don't
+// explicitly state that they apply to alpha should be treated as their explicitly-alpha
+// equivalents. See: https://github.com/gpuweb/gpuweb/issues/65
+D3D11_BLEND D3DBlendAlphaFactor(wgpu::BlendFactor factor) {
+ switch (factor) {
+ case wgpu::BlendFactor::Src:
+ return D3D11_BLEND_SRC_ALPHA;
+ case wgpu::BlendFactor::OneMinusSrc:
+ return D3D11_BLEND_INV_SRC_ALPHA;
+ case wgpu::BlendFactor::Dst:
+ return D3D11_BLEND_DEST_ALPHA;
+ case wgpu::BlendFactor::OneMinusDst:
+ return D3D11_BLEND_INV_DEST_ALPHA;
+
+ // Other blend factors translate to the same D3D11 enum as the color blend factors.
+ default:
+ return D3DBlendFactor(factor);
+ }
+}
+
D3D11_BLEND_OP D3DBlendOperation(wgpu::BlendOperation blendOperation) {
switch (blendOperation) {
case wgpu::BlendOperation::Add:
@@ -330,8 +350,8 @@
}
rtBlendDesc.DestBlend = D3DBlendFactor(descriptor->blend->color.dstFactor);
rtBlendDesc.BlendOp = D3DBlendOperation(descriptor->blend->color.operation);
- rtBlendDesc.SrcBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.srcFactor);
- rtBlendDesc.DestBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.dstFactor);
+ rtBlendDesc.SrcBlendAlpha = D3DBlendAlphaFactor(descriptor->blend->alpha.srcFactor);
+ rtBlendDesc.DestBlendAlpha = D3DBlendAlphaFactor(descriptor->blend->alpha.dstFactor);
rtBlendDesc.BlendOpAlpha = D3DBlendOperation(descriptor->blend->alpha.operation);
}
rtBlendDesc.RenderTargetWriteMask = D3DColorWriteMask(descriptor->writeMask);