mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-18 02:52:10 +01:00
[dxvk] Refactored blend state
This commit is contained in:
parent
6a9743ead7
commit
b49815657e
@ -51,11 +51,26 @@ namespace dxvk {
|
||||
m_defaultMsState.minSampleShading = 0.0f;
|
||||
m_context->setMultisampleState(m_defaultMsState);
|
||||
|
||||
m_defaultCbState = new DxvkBlendState(
|
||||
VK_FALSE, VK_LOGIC_OP_CLEAR, 0, nullptr);
|
||||
DxvkLogicOpState loState;
|
||||
loState.enableLogicOp = VK_FALSE;
|
||||
loState.logicOp = VK_LOGIC_OP_CLEAR;
|
||||
m_context->setLogicOpState(loState);
|
||||
|
||||
m_defaultBlendMode.enableBlending = VK_FALSE;
|
||||
m_defaultBlendMode.colorSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
m_defaultBlendMode.colorDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
m_defaultBlendMode.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
m_defaultBlendMode.alphaSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
m_defaultBlendMode.alphaDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
m_defaultBlendMode.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
m_defaultBlendMode.writeMask = VK_COLOR_COMPONENT_R_BIT
|
||||
| VK_COLOR_COMPONENT_G_BIT
|
||||
| VK_COLOR_COMPONENT_B_BIT
|
||||
| VK_COLOR_COMPONENT_A_BIT;
|
||||
|
||||
for (uint32_t i = 0; i < DxvkLimits::MaxNumRenderTargets; i++)
|
||||
m_context->setBlendMode(i, m_defaultBlendMode);
|
||||
|
||||
m_context->setDepthStencilState(m_defaultDsState);
|
||||
m_context->setBlendState(m_defaultCbState);
|
||||
}
|
||||
|
||||
|
||||
|
@ -550,7 +550,7 @@ namespace dxvk {
|
||||
DxvkRasterizerState m_defaultRsState;
|
||||
DxvkDepthStencilState m_defaultDsState;
|
||||
DxvkMultisampleState m_defaultMsState;
|
||||
Rc<DxvkBlendState> m_defaultCbState;
|
||||
DxvkBlendMode m_defaultBlendMode;
|
||||
|
||||
D3D11ContextState m_state;
|
||||
|
||||
|
@ -92,33 +92,36 @@ namespace dxvk {
|
||||
stencilOp.reference = 0;
|
||||
|
||||
DxvkDepthStencilState dsState;
|
||||
dsState.enableDepthTest = VK_FALSE;
|
||||
dsState.enableDepthWrite = VK_FALSE;
|
||||
dsState.enableDepthBounds = VK_FALSE;
|
||||
dsState.enableStencilTest = VK_FALSE;
|
||||
dsState.depthCompareOp = VK_COMPARE_OP_ALWAYS;
|
||||
dsState.stencilOpFront = stencilOp;
|
||||
dsState.stencilOpBack = stencilOp;
|
||||
dsState.depthBoundsMin = 0.0f;
|
||||
dsState.depthBoundsMax = 1.0f;
|
||||
dsState.enableDepthTest = VK_FALSE;
|
||||
dsState.enableDepthWrite = VK_FALSE;
|
||||
dsState.enableDepthBounds = VK_FALSE;
|
||||
dsState.enableStencilTest = VK_FALSE;
|
||||
dsState.depthCompareOp = VK_COMPARE_OP_ALWAYS;
|
||||
dsState.stencilOpFront = stencilOp;
|
||||
dsState.stencilOpBack = stencilOp;
|
||||
dsState.depthBoundsMin = 0.0f;
|
||||
dsState.depthBoundsMax = 1.0f;
|
||||
|
||||
VkPipelineColorBlendAttachmentState blendAttachment;
|
||||
blendAttachment.blendEnable = VK_FALSE;
|
||||
blendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
blendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
blendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
blendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
blendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
blendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
blendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT
|
||||
| VK_COLOR_COMPONENT_G_BIT
|
||||
| VK_COLOR_COMPONENT_B_BIT
|
||||
| VK_COLOR_COMPONENT_A_BIT;
|
||||
DxvkLogicOpState loState;
|
||||
loState.enableLogicOp = VK_FALSE;
|
||||
loState.logicOp = VK_LOGIC_OP_NO_OP;
|
||||
m_context->setLogicOpState(loState);
|
||||
|
||||
m_context->setBlendState(
|
||||
new DxvkBlendState(
|
||||
VK_FALSE, VK_LOGIC_OP_NO_OP,
|
||||
1, &blendAttachment));
|
||||
DxvkBlendMode blendMode;
|
||||
blendMode.enableBlending = VK_FALSE;
|
||||
blendMode.colorSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
blendMode.colorDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
blendMode.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
blendMode.alphaSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
blendMode.alphaDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
blendMode.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
blendMode.writeMask = VK_COLOR_COMPONENT_R_BIT
|
||||
| VK_COLOR_COMPONENT_G_BIT
|
||||
| VK_COLOR_COMPONENT_B_BIT
|
||||
| VK_COLOR_COMPONENT_A_BIT;
|
||||
|
||||
for (uint32_t i = 0; i < DxvkLimits::MaxNumRenderTargets; i++)
|
||||
m_context->setBlendMode(i, blendMode);
|
||||
|
||||
m_context->bindShader(
|
||||
VK_SHADER_STAGE_VERTEX_BIT,
|
||||
|
@ -1,44 +0,0 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "dxvk_constant_state.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
DxvkBlendState::DxvkBlendState(
|
||||
VkBool32 enableLogicOp,
|
||||
VkLogicOp logicOp,
|
||||
uint32_t attachmentCount,
|
||||
const VkPipelineColorBlendAttachmentState* attachmentState) {
|
||||
// Copy the provided blend states into the array
|
||||
for (uint32_t i = 0; i < attachmentCount; i++)
|
||||
m_attachments.at(i) = attachmentState[i];
|
||||
|
||||
// Use default values for the remaining attachments
|
||||
for (uint32_t i = attachmentCount; i < m_attachments.size(); i++) {
|
||||
m_attachments.at(i).blendEnable = VK_FALSE;
|
||||
m_attachments.at(i).srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
m_attachments.at(i).dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
m_attachments.at(i).colorBlendOp = VK_BLEND_OP_ADD;
|
||||
m_attachments.at(i).srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
m_attachments.at(i).dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
m_attachments.at(i).alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
m_attachments.at(i).colorWriteMask =
|
||||
VK_COLOR_COMPONENT_R_BIT
|
||||
| VK_COLOR_COMPONENT_G_BIT
|
||||
| VK_COLOR_COMPONENT_B_BIT
|
||||
| VK_COLOR_COMPONENT_A_BIT;
|
||||
}
|
||||
|
||||
m_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||
m_info.pNext = nullptr;
|
||||
m_info.flags = 0;
|
||||
m_info.logicOpEnable = enableLogicOp;
|
||||
m_info.logicOp = logicOp;
|
||||
m_info.attachmentCount = m_attachments.size();
|
||||
m_info.pAttachments = m_attachments.data();
|
||||
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
m_info.blendConstants[i] = 0.0f;
|
||||
}
|
||||
|
||||
}
|
@ -90,14 +90,14 @@ namespace dxvk {
|
||||
* Blend modes can be set separately for each attachment.
|
||||
*/
|
||||
struct DxvkBlendMode {
|
||||
VkBool32 blendEnable;
|
||||
VkBlendFactor srcColorBlendFactor;
|
||||
VkBlendFactor dstColorBlendFactor;
|
||||
VkBool32 enableBlending;
|
||||
VkBlendFactor colorSrcFactor;
|
||||
VkBlendFactor colorDstFactor;
|
||||
VkBlendOp colorBlendOp;
|
||||
VkBlendFactor srcAlphaBlendFactor;
|
||||
VkBlendFactor dstAlphaBlendFactor;
|
||||
VkBlendFactor alphaSrcFactor;
|
||||
VkBlendFactor alphaDstFactor;
|
||||
VkBlendOp alphaBlendOp;
|
||||
VkColorComponentFlags colorWriteMask;
|
||||
VkColorComponentFlags writeMask;
|
||||
};
|
||||
|
||||
|
||||
@ -141,9 +141,4 @@ namespace dxvk {
|
||||
std::array<DxvkVertexBinding, DxvkLimits::MaxNumVertexBindings> bindings;
|
||||
};
|
||||
|
||||
|
||||
struct DxvkConstantStateObjects {
|
||||
Rc<DxvkBlendState> blendState;
|
||||
};
|
||||
|
||||
}
|
@ -561,15 +561,25 @@ namespace dxvk {
|
||||
gpState.dsDepthBoundsMin = m_state.ds.depthBoundsMin;
|
||||
gpState.dsDepthBoundsMax = m_state.ds.depthBoundsMax;
|
||||
|
||||
const auto& om = m_state.co.blendState->info();
|
||||
gpState.omEnableLogicOp = om.logicOpEnable;
|
||||
gpState.omLogicOp = om.logicOp;
|
||||
gpState.omEnableLogicOp = m_state.lo.enableLogicOp;
|
||||
gpState.omLogicOp = m_state.lo.logicOp;
|
||||
gpState.omRenderPass = m_state.om.framebuffer->renderPass();
|
||||
|
||||
const auto& rt = m_state.om.framebuffer->renderTargets();
|
||||
|
||||
for (uint32_t i = 0; i < DxvkLimits::MaxNumRenderTargets; i++) {
|
||||
if (rt.getColorTarget(i) != nullptr)
|
||||
gpState.omBlendAttachments[i] = om.pAttachments[i];
|
||||
if (rt.getColorTarget(i) != nullptr) {
|
||||
const DxvkBlendMode& mode = m_state.om.blendModes.at(i);
|
||||
|
||||
gpState.omBlendAttachments[i].blendEnable = mode.enableBlending;
|
||||
gpState.omBlendAttachments[i].srcColorBlendFactor = mode.colorSrcFactor;
|
||||
gpState.omBlendAttachments[i].dstColorBlendFactor = mode.colorDstFactor;
|
||||
gpState.omBlendAttachments[i].colorBlendOp = mode.colorBlendOp;
|
||||
gpState.omBlendAttachments[i].srcAlphaBlendFactor = mode.alphaSrcFactor;
|
||||
gpState.omBlendAttachments[i].dstAlphaBlendFactor = mode.alphaDstFactor;
|
||||
gpState.omBlendAttachments[i].alphaBlendOp = mode.alphaBlendOp;
|
||||
gpState.omBlendAttachments[i].colorWriteMask = mode.writeMask;
|
||||
}
|
||||
}
|
||||
|
||||
m_cmd->cmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
|
@ -93,15 +93,13 @@ namespace dxvk {
|
||||
struct DxvkContextState {
|
||||
DxvkInputAssemblyState ia;
|
||||
DxvkInputLayout il;
|
||||
DxvkVertexInputState vi;
|
||||
DxvkViewportState vp;
|
||||
DxvkRasterizerState rs;
|
||||
DxvkMultisampleState ms;
|
||||
DxvkDepthStencilState ds;
|
||||
DxvkLogicOpState lo;
|
||||
|
||||
DxvkVertexInputState vi;
|
||||
DxvkViewportState vp;
|
||||
DxvkOutputMergerState om;
|
||||
DxvkConstantStateObjects co;
|
||||
|
||||
DxvkGraphicsPipelineState gp;
|
||||
DxvkComputePipelineState cp;
|
||||
|
@ -4,7 +4,6 @@ dxvk_src = files([
|
||||
'dxvk_buffer.cpp',
|
||||
'dxvk_cmdlist.cpp',
|
||||
'dxvk_compute.cpp',
|
||||
'dxvk_constant_state.cpp',
|
||||
'dxvk_context.cpp',
|
||||
'dxvk_data.cpp',
|
||||
'dxvk_descriptor.cpp',
|
||||
|
@ -120,10 +120,26 @@ public:
|
||||
dsState.depthBoundsMax = 1.0f;
|
||||
m_dxvkContext->setDepthStencilState(dsState);
|
||||
|
||||
m_dxvkContext->setBlendState(
|
||||
new DxvkBlendState(
|
||||
VK_FALSE, VK_LOGIC_OP_COPY,
|
||||
0, nullptr));
|
||||
DxvkLogicOpState loState;
|
||||
loState.enableLogicOp = VK_FALSE;
|
||||
loState.logicOp = VK_LOGIC_OP_NO_OP;
|
||||
m_dxvkContext->setLogicOpState(loState);
|
||||
|
||||
DxvkBlendMode blendMode;
|
||||
blendMode.enableBlending = VK_FALSE;
|
||||
blendMode.colorSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
blendMode.colorDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
blendMode.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
blendMode.alphaSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
blendMode.alphaDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
blendMode.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
blendMode.writeMask = VK_COLOR_COMPONENT_R_BIT
|
||||
| VK_COLOR_COMPONENT_G_BIT
|
||||
| VK_COLOR_COMPONENT_B_BIT
|
||||
| VK_COLOR_COMPONENT_A_BIT;
|
||||
|
||||
for (uint32_t i = 0; i < DxvkLimits::MaxNumRenderTargets; i++)
|
||||
m_dxvkContext->setBlendMode(i, blendMode);
|
||||
|
||||
m_dxvkVertexShader = m_dxvkDevice->createShader(
|
||||
VK_SHADER_STAGE_VERTEX_BIT, 0, nullptr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user