1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-28 02:19:26 +01:00

[dxvk,d3d9,d3d11] Refactor logic op state object

This commit is contained in:
Philip Rebohle 2025-03-22 15:57:20 +01:00
parent abb5db346c
commit 4a5c50b2de
7 changed files with 53 additions and 29 deletions

View File

@ -27,8 +27,8 @@ namespace dxvk {
if (desc.IndependentBlendEnable && desc.RenderTarget[0].LogicOpEnable)
Logger::warn("D3D11: Per-target logic ops not supported");
m_loState.enableLogicOp = desc.RenderTarget[0].LogicOpEnable;
m_loState.logicOp = DecodeLogicOp(desc.RenderTarget[0].LogicOp);
m_loState.setLogicOp(desc.RenderTarget[0].LogicOpEnable,
DecodeLogicOp(desc.RenderTarget[0].LogicOp));
}
@ -96,9 +96,6 @@ namespace dxvk {
// blend mode array will be identical
for (uint32_t i = 0; i < m_blendModes.size(); i++)
ctx->setBlendMode(i, m_blendModes.at(i));
// Set up logic op state as well
ctx->setLogicOpState(m_loState);
}

View File

@ -38,6 +38,10 @@ namespace dxvk {
return msState;
}
DxvkLogicOpState GetLoState() const {
return m_loState;
}
void BindToContext(
DxvkContext* ctx) const;
@ -57,10 +61,10 @@ namespace dxvk {
std::array<DxvkBlendMode, 8> m_blendModes;
DxvkMultisampleState m_msState = { };
DxvkLogicOpState m_loState;
DxvkLogicOpState m_loState = { };
D3D10BlendState m_d3d10;
static DxvkBlendMode DecodeBlendMode(
const D3D11_RENDER_TARGET_BLEND_DESC1& BlendDesc);

View File

@ -3371,25 +3371,26 @@ namespace dxvk {
if (m_state.om.cbState != nullptr) {
EmitCs([
cBlendState = m_state.om.cbState,
cMsState = m_state.om.cbState->GetMsState(m_state.om.sampleMask)
cMsState = m_state.om.cbState->GetMsState(m_state.om.sampleMask),
cLoState = m_state.om.cbState->GetLoState()
] (DxvkContext* ctx) {
cBlendState->BindToContext(ctx);
ctx->setMultisampleState(cMsState);
ctx->setLogicOpState(cLoState);
});
} else {
EmitCs([
cSampleMask = m_state.om.sampleMask
] (DxvkContext* ctx) {
DxvkBlendMode cbState;
DxvkLogicOpState loState;
InitDefaultBlendState(&cbState, &loState);
InitDefaultBlendState(&cbState);
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
ctx->setBlendMode(i, cbState);
ctx->setLogicOpState(loState);
ctx->setMultisampleState(InitDefaultMultisampleState(cSampleMask));
ctx->setLogicOpState(InitDefaultLogicOpState());
});
}
}
@ -4730,13 +4731,12 @@ namespace dxvk {
InitDefaultRasterizerState(&rsState);
DxvkBlendMode cbState;
DxvkLogicOpState loState;
InitDefaultBlendState(&cbState, &loState);
InitDefaultBlendState(&cbState);
ctx->setInputAssemblyState(iaState);
ctx->setDepthStencilState(InitDefaultDepthStencilState());
ctx->setRasterizerState(rsState);
ctx->setLogicOpState(loState);
ctx->setLogicOpState(InitDefaultLogicOpState());
ctx->setMultisampleState(InitDefaultMultisampleState(D3D11_DEFAULT_SAMPLE_MASK));
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
@ -5821,10 +5821,17 @@ namespace dxvk {
}
template<typename ContextType>
DxvkLogicOpState D3D11CommonContext<ContextType>::InitDefaultLogicOpState() {
DxvkLogicOpState loState = { };
loState.setLogicOp(false, VK_LOGIC_OP_NO_OP);
return loState;
}
template<typename ContextType>
void D3D11CommonContext<ContextType>::InitDefaultBlendState(
DxvkBlendMode* pCbState,
DxvkLogicOpState* pLoState) {
DxvkBlendMode* pCbState) {
pCbState->enableBlending = VK_FALSE;
pCbState->colorSrcFactor = VK_BLEND_FACTOR_ONE;
pCbState->colorDstFactor = VK_BLEND_FACTOR_ZERO;
@ -5834,9 +5841,6 @@ namespace dxvk {
pCbState->alphaBlendOp = VK_BLEND_OP_ADD;
pCbState->writeMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT
| VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
pLoState->enableLogicOp = VK_FALSE;
pLoState->logicOp = VK_LOGIC_OP_NO_OP;
}
// Explicitly instantiate here

View File

@ -1154,9 +1154,10 @@ namespace dxvk {
static DxvkMultisampleState InitDefaultMultisampleState(
UINT SampleMask);
static DxvkLogicOpState InitDefaultLogicOpState();
static void InitDefaultBlendState(
DxvkBlendMode* pCbState,
DxvkLogicOpState* pLoState);
DxvkBlendMode* pCbState);
template<bool AllowFlush = true, typename Cmd>
void EmitCs(Cmd&& command) {

View File

@ -82,9 +82,7 @@ namespace dxvk {
ctx->beginRecording(cDevice->createCommandList());
// Disable logic op once and for all.
DxvkLogicOpState loState;
loState.enableLogicOp = VK_FALSE;
loState.logicOp = VK_LOGIC_OP_CLEAR;
DxvkLogicOpState loState = { };
ctx->setLogicOpState(loState);
});

View File

@ -312,9 +312,29 @@ namespace dxvk {
* \brief Logic op state
* Defines a logic op.
*/
struct DxvkLogicOpState {
VkBool32 enableLogicOp;
VkLogicOp logicOp;
class DxvkLogicOpState {
public:
bool logicOpEnable() const {
return m_logicOpEnable;
}
VkLogicOp logicOp() const {
return VkLogicOp(m_logicOp);
}
void setLogicOp(bool enable, VkLogicOp op) {
m_logicOpEnable = enable;
m_logicOp = uint8_t(op);
}
private:
uint8_t m_logicOpEnable : 1;
uint8_t m_logicOp : 4;
uint8_t m_reserved : 3;
};

View File

@ -2925,8 +2925,8 @@ namespace dxvk {
void DxvkContext::setLogicOpState(const DxvkLogicOpState& lo) {
m_state.gp.state.om = DxvkOmInfo(
lo.enableLogicOp,
lo.logicOp,
lo.logicOpEnable(),
lo.logicOp(),
m_state.gp.state.om.feedbackLoop());
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);