mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-28 02:19:26 +01:00
[dxvk,d3d9,d3d11] Normalize blend state in front-end
This commit is contained in:
parent
a1106db71f
commit
8de7397816
@ -182,6 +182,8 @@ namespace dxvk {
|
||||
DecodeBlendFactor(BlendDesc.DestBlendAlpha, true),
|
||||
DecodeBlendOp(BlendDesc.BlendOpAlpha));
|
||||
mode.setWriteMask(BlendDesc.RenderTargetWriteMask);
|
||||
|
||||
mode.normalize();
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
@ -6882,6 +6882,8 @@ namespace dxvk {
|
||||
NormalizeFactor(mode.alphaDstFactor()), mode.alphaBlendOp());
|
||||
}
|
||||
|
||||
mode.normalize();
|
||||
|
||||
ctx->setBlendMode(i, mode);
|
||||
}
|
||||
});
|
||||
|
@ -65,4 +65,56 @@ namespace dxvk {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DxvkBlendMode::normalize() {
|
||||
constexpr VkColorComponentFlags colorMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT;
|
||||
constexpr VkColorComponentFlags alphaMask = VK_COLOR_COMPONENT_A_BIT;
|
||||
|
||||
VkColorComponentFlags newWriteMask = writeMask();
|
||||
|
||||
if (!newWriteMask)
|
||||
setBlendEnable(false);
|
||||
|
||||
if (blendEnable()) {
|
||||
// If alpha or color are effectively not modified given the blend
|
||||
// function, set the corresponding part of the write mask to 0.
|
||||
if (colorBlendOp() == VK_BLEND_OP_ADD
|
||||
&& colorSrcFactor() == VK_BLEND_FACTOR_ZERO
|
||||
&& colorDstFactor() == VK_BLEND_FACTOR_ONE)
|
||||
newWriteMask &= ~colorMask;
|
||||
|
||||
if (alphaBlendOp() == VK_BLEND_OP_ADD
|
||||
&& alphaSrcFactor() == VK_BLEND_FACTOR_ZERO
|
||||
&& alphaDstFactor() == VK_BLEND_FACTOR_ONE)
|
||||
newWriteMask &= ~alphaMask;
|
||||
|
||||
// Check whether blending is equivalent to passing through
|
||||
// the source data as if blending was disabled.
|
||||
bool needsBlending = false;
|
||||
|
||||
if (newWriteMask & colorMask) {
|
||||
needsBlending |= colorSrcFactor() != VK_BLEND_FACTOR_ONE
|
||||
|| colorDstFactor() != VK_BLEND_FACTOR_ZERO
|
||||
|| colorBlendOp() != VK_BLEND_OP_ADD;
|
||||
}
|
||||
|
||||
if (newWriteMask & alphaMask) {
|
||||
needsBlending |= alphaSrcFactor() != VK_BLEND_FACTOR_ONE
|
||||
|| alphaDstFactor() != VK_BLEND_FACTOR_ZERO
|
||||
|| alphaBlendOp() != VK_BLEND_OP_ADD;
|
||||
}
|
||||
|
||||
if (!needsBlending)
|
||||
setBlendEnable(false);
|
||||
}
|
||||
|
||||
if (!blendEnable() || !(newWriteMask & colorMask))
|
||||
setColorOp(VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD);
|
||||
|
||||
if (!blendEnable() || !(newWriteMask & alphaMask))
|
||||
setAlphaOp(VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD);
|
||||
|
||||
setWriteMask(newWriteMask);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -400,6 +400,8 @@ namespace dxvk {
|
||||
m_writeMask = writeMask;
|
||||
}
|
||||
|
||||
void normalize();
|
||||
|
||||
private:
|
||||
|
||||
uint32_t m_enableBlending : 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user