mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-11 01:24:12 +01:00
[d3d11] RestoreState: Restore DS/OM/RS state objects
This commit is contained in:
parent
5befa3b745
commit
969b35c80c
@ -1729,34 +1729,14 @@ namespace dxvk {
|
|||||||
m_state.om.cbState = blendState;
|
m_state.om.cbState = blendState;
|
||||||
m_state.om.sampleMask = SampleMask;
|
m_state.om.sampleMask = SampleMask;
|
||||||
|
|
||||||
if (blendState == nullptr)
|
ApplyBlendState();
|
||||||
blendState = m_defaultBlendState;
|
|
||||||
|
|
||||||
EmitCs([
|
|
||||||
cBlendState = std::move(blendState),
|
|
||||||
cSampleMask = SampleMask
|
|
||||||
] (DxvkContext* ctx) {
|
|
||||||
cBlendState->BindToContext(ctx, cSampleMask);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BlendFactor != nullptr) {
|
if (BlendFactor != nullptr) {
|
||||||
bool updateBlendFactor = false;
|
for (uint32_t i = 0; i < 4; i++)
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 4; i++) {
|
|
||||||
updateBlendFactor |= m_state.om.blendFactor[i] != BlendFactor[i];
|
|
||||||
m_state.om.blendFactor[i] = BlendFactor[i];
|
m_state.om.blendFactor[i] = BlendFactor[i];
|
||||||
}
|
|
||||||
|
|
||||||
if (updateBlendFactor) {
|
ApplyBlendFactor();
|
||||||
EmitCs([
|
|
||||||
cBlendConstants = DxvkBlendConstants {
|
|
||||||
BlendFactor[0], BlendFactor[1],
|
|
||||||
BlendFactor[2], BlendFactor[3] }
|
|
||||||
] (DxvkContext* ctx) {
|
|
||||||
ctx->setBlendConstants(cBlendConstants);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1769,22 +1749,12 @@ namespace dxvk {
|
|||||||
|
|
||||||
if (m_state.om.dsState != depthStencilState) {
|
if (m_state.om.dsState != depthStencilState) {
|
||||||
m_state.om.dsState = depthStencilState;
|
m_state.om.dsState = depthStencilState;
|
||||||
|
ApplyDepthStencilState();
|
||||||
if (depthStencilState == nullptr)
|
|
||||||
depthStencilState = m_defaultDepthStencilState;
|
|
||||||
|
|
||||||
EmitCs([cDepthStencilState = std::move(depthStencilState)]
|
|
||||||
(DxvkContext* ctx) {
|
|
||||||
cDepthStencilState->BindToContext(ctx);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_state.om.stencilRef != StencilRef) {
|
if (m_state.om.stencilRef != StencilRef) {
|
||||||
m_state.om.stencilRef = StencilRef;
|
m_state.om.stencilRef = StencilRef;
|
||||||
|
ApplyStencilRef();
|
||||||
EmitCs([cStencilRef = StencilRef] (DxvkContext* ctx) {
|
|
||||||
ctx->setStencilReference(cStencilRef);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1852,18 +1822,11 @@ namespace dxvk {
|
|||||||
if (m_state.rs.state != rasterizerState) {
|
if (m_state.rs.state != rasterizerState) {
|
||||||
m_state.rs.state = rasterizerState;
|
m_state.rs.state = rasterizerState;
|
||||||
|
|
||||||
if (rasterizerState == nullptr)
|
// In D3D11, the rasterizer state defines whether the
|
||||||
rasterizerState = m_defaultRasterizerState;
|
// scissor test is enabled, so we have to update the
|
||||||
|
// scissor rectangles as well.
|
||||||
EmitCs([cRasterizerState = std::move(rasterizerState)]
|
ApplyRasterizerState();
|
||||||
(DxvkContext* ctx) {
|
ApplyViewportState();
|
||||||
cRasterizerState->BindToContext(ctx);
|
|
||||||
});
|
|
||||||
|
|
||||||
// In D3D11, the rasterizer state defines
|
|
||||||
// whether the scissor test is enabled, so
|
|
||||||
// we have to update the scissor rectangles.
|
|
||||||
this->ApplyViewportState();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1876,7 +1839,7 @@ namespace dxvk {
|
|||||||
for (uint32_t i = 0; i < NumViewports; i++)
|
for (uint32_t i = 0; i < NumViewports; i++)
|
||||||
m_state.rs.viewports.at(i) = pViewports[i];
|
m_state.rs.viewports.at(i) = pViewports[i];
|
||||||
|
|
||||||
this->ApplyViewportState();
|
ApplyViewportState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1893,7 +1856,7 @@ namespace dxvk {
|
|||||||
m_state.rs.state->GetDesc(&rsDesc);
|
m_state.rs.state->GetDesc(&rsDesc);
|
||||||
|
|
||||||
if (rsDesc.ScissorEnable)
|
if (rsDesc.ScissorEnable)
|
||||||
this->ApplyViewportState();
|
ApplyViewportState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2034,6 +1997,60 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D11DeviceContext::ApplyBlendState() {
|
||||||
|
EmitCs([
|
||||||
|
cBlendState = m_state.om.cbState != nullptr
|
||||||
|
? m_state.om.cbState
|
||||||
|
: m_defaultBlendState,
|
||||||
|
cSampleMask = m_state.om.sampleMask
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
cBlendState->BindToContext(ctx, cSampleMask);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D11DeviceContext::ApplyBlendFactor() {
|
||||||
|
EmitCs([
|
||||||
|
cBlendConstants = DxvkBlendConstants {
|
||||||
|
m_state.om.blendFactor[0], m_state.om.blendFactor[1],
|
||||||
|
m_state.om.blendFactor[2], m_state.om.blendFactor[3] }
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
ctx->setBlendConstants(cBlendConstants);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D11DeviceContext::ApplyDepthStencilState() {
|
||||||
|
EmitCs([
|
||||||
|
cDepthStencilState = m_state.om.dsState != nullptr
|
||||||
|
? m_state.om.dsState
|
||||||
|
: m_defaultDepthStencilState
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
cDepthStencilState->BindToContext(ctx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D11DeviceContext::ApplyStencilRef() {
|
||||||
|
EmitCs([
|
||||||
|
cStencilRef = m_state.om.stencilRef
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
ctx->setStencilReference(cStencilRef);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D11DeviceContext::ApplyRasterizerState() {
|
||||||
|
EmitCs([
|
||||||
|
cRasterizerState = m_state.rs.state != nullptr
|
||||||
|
? m_state.rs.state
|
||||||
|
: m_defaultRasterizerState
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
cRasterizerState->BindToContext(ctx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void D3D11DeviceContext::ApplyViewportState() {
|
void D3D11DeviceContext::ApplyViewportState() {
|
||||||
// We cannot set less than one viewport in Vulkan, and
|
// We cannot set less than one viewport in Vulkan, and
|
||||||
// rendering with no active viewport is illegal anyway.
|
// rendering with no active viewport is illegal anyway.
|
||||||
@ -2342,11 +2359,6 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
void D3D11DeviceContext::RestoreState() {
|
void D3D11DeviceContext::RestoreState() {
|
||||||
static bool s_errorShown = false;
|
|
||||||
|
|
||||||
if (!std::exchange(s_errorShown, true))
|
|
||||||
Logger::err("D3D11DeviceContext::RestoreState: Incomplete");
|
|
||||||
|
|
||||||
BindFramebuffer();
|
BindFramebuffer();
|
||||||
|
|
||||||
BindShader(m_state.vs.shader.ptr(), VK_SHADER_STAGE_VERTEX_BIT);
|
BindShader(m_state.vs.shader.ptr(), VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
@ -2358,6 +2370,11 @@ namespace dxvk {
|
|||||||
|
|
||||||
ApplyInputLayout();
|
ApplyInputLayout();
|
||||||
ApplyPrimitiveTopology();
|
ApplyPrimitiveTopology();
|
||||||
|
ApplyBlendState();
|
||||||
|
ApplyBlendFactor();
|
||||||
|
ApplyDepthStencilState();
|
||||||
|
ApplyStencilRef();
|
||||||
|
ApplyRasterizerState();
|
||||||
ApplyViewportState();
|
ApplyViewportState();
|
||||||
|
|
||||||
BindIndexBuffer(
|
BindIndexBuffer(
|
||||||
|
@ -531,6 +531,16 @@ namespace dxvk {
|
|||||||
|
|
||||||
void ApplyPrimitiveTopology();
|
void ApplyPrimitiveTopology();
|
||||||
|
|
||||||
|
void ApplyBlendState();
|
||||||
|
|
||||||
|
void ApplyBlendFactor();
|
||||||
|
|
||||||
|
void ApplyDepthStencilState();
|
||||||
|
|
||||||
|
void ApplyStencilRef();
|
||||||
|
|
||||||
|
void ApplyRasterizerState();
|
||||||
|
|
||||||
void ApplyViewportState();
|
void ApplyViewportState();
|
||||||
|
|
||||||
void BindFramebuffer();
|
void BindFramebuffer();
|
||||||
|
Loading…
Reference in New Issue
Block a user