mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-03 04:24:11 +01:00
[d3d11] Don't use a state object for default depth-stencil state
This commit is contained in:
parent
b0231403fe
commit
c30fd8fb97
@ -24,16 +24,13 @@ namespace dxvk {
|
|||||||
// Create default state objects. We won't ever return them
|
// Create default state objects. We won't ever return them
|
||||||
// to the application, but we'll use them to apply state.
|
// to the application, but we'll use them to apply state.
|
||||||
Com<ID3D11BlendState> defaultBlendState;
|
Com<ID3D11BlendState> defaultBlendState;
|
||||||
Com<ID3D11DepthStencilState> defaultDepthStencilState;
|
|
||||||
|
|
||||||
if (FAILED(m_parent->CreateBlendState (nullptr, &defaultBlendState))
|
if (FAILED(m_parent->CreateBlendState (nullptr, &defaultBlendState)))
|
||||||
|| FAILED(m_parent->CreateDepthStencilState(nullptr, &defaultDepthStencilState)))
|
|
||||||
throw DxvkError("D3D11DeviceContext: Failed to create default state objects");
|
throw DxvkError("D3D11DeviceContext: Failed to create default state objects");
|
||||||
|
|
||||||
// Apply default state to the context. This is required
|
// Apply default state to the context. This is required
|
||||||
// in order to initialize the DXVK contex properly.
|
// in order to initialize the DXVK contex properly.
|
||||||
m_defaultBlendState = static_cast<D3D11BlendState*> (defaultBlendState.ptr());
|
m_defaultBlendState = static_cast<D3D11BlendState*> (defaultBlendState.ptr());
|
||||||
m_defaultDepthStencilState = static_cast<D3D11DepthStencilState*>(defaultDepthStencilState.ptr());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3249,16 +3246,20 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
void D3D11DeviceContext::ApplyDepthStencilState() {
|
void D3D11DeviceContext::ApplyDepthStencilState() {
|
||||||
auto dsState = m_state.om.dsState.prvRef();
|
if (m_state.om.dsState != nullptr) {
|
||||||
|
EmitCs([
|
||||||
|
cDepthStencilState = m_state.om.dsState.prvRef()
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
cDepthStencilState->BindToContext(ctx);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
EmitCs([] (DxvkContext* ctx) {
|
||||||
|
DxvkDepthStencilState dsState;
|
||||||
|
InitDefaultDepthStencilState(&dsState);
|
||||||
|
|
||||||
if (unlikely(dsState == nullptr))
|
ctx->setDepthStencilState(dsState);
|
||||||
dsState = m_defaultDepthStencilState.prvRef();
|
});
|
||||||
|
}
|
||||||
EmitCs([
|
|
||||||
cDepthStencilState = std::move(dsState)
|
|
||||||
] (DxvkContext* ctx) {
|
|
||||||
cDepthStencilState->BindToContext(ctx);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3778,8 +3779,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
void D3D11DeviceContext::ResetState() {
|
void D3D11DeviceContext::ResetState() {
|
||||||
EmitCs([
|
EmitCs([
|
||||||
cBlendState = m_defaultBlendState.prvRef(),
|
cBlendState = m_defaultBlendState.prvRef()
|
||||||
cDepthStencilState = m_defaultDepthStencilState.prvRef()
|
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) {
|
||||||
// Reset render targets
|
// Reset render targets
|
||||||
ctx->bindRenderTargets(DxvkRenderTargets());
|
ctx->bindRenderTargets(DxvkRenderTargets());
|
||||||
@ -3791,14 +3791,17 @@ namespace dxvk {
|
|||||||
DxvkInputAssemblyState iaState;
|
DxvkInputAssemblyState iaState;
|
||||||
InitDefaultPrimitiveTopology(&iaState);
|
InitDefaultPrimitiveTopology(&iaState);
|
||||||
|
|
||||||
|
DxvkDepthStencilState dsState;
|
||||||
|
InitDefaultDepthStencilState(&dsState);
|
||||||
|
|
||||||
DxvkRasterizerState rsState;
|
DxvkRasterizerState rsState;
|
||||||
InitDefaultRasterizerState(&rsState);
|
InitDefaultRasterizerState(&rsState);
|
||||||
|
|
||||||
ctx->setInputAssemblyState(iaState);
|
ctx->setInputAssemblyState(iaState);
|
||||||
|
ctx->setDepthStencilState(dsState);
|
||||||
ctx->setRasterizerState(rsState);
|
ctx->setRasterizerState(rsState);
|
||||||
|
|
||||||
cBlendState->BindToContext(ctx, D3D11_DEFAULT_SAMPLE_MASK);
|
cBlendState->BindToContext(ctx, D3D11_DEFAULT_SAMPLE_MASK);
|
||||||
cDepthStencilState->BindToContext(ctx);
|
|
||||||
|
|
||||||
// Reset dynamic states
|
// Reset dynamic states
|
||||||
ctx->setBlendConstants(DxvkBlendConstants { 1.0f, 1.0f, 1.0f, 1.0f });
|
ctx->setBlendConstants(DxvkBlendConstants { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
@ -4281,4 +4284,24 @@ namespace dxvk {
|
|||||||
pRsState->sampleCount = 0;
|
pRsState->sampleCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D11DeviceContext::InitDefaultDepthStencilState(
|
||||||
|
DxvkDepthStencilState* pDsState) {
|
||||||
|
VkStencilOpState stencilOp;
|
||||||
|
stencilOp.failOp = VK_STENCIL_OP_KEEP;
|
||||||
|
stencilOp.passOp = VK_STENCIL_OP_KEEP;
|
||||||
|
stencilOp.depthFailOp = VK_STENCIL_OP_KEEP;
|
||||||
|
stencilOp.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||||
|
stencilOp.compareMask = D3D11_DEFAULT_STENCIL_READ_MASK;
|
||||||
|
stencilOp.writeMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
|
||||||
|
stencilOp.reference = 0;
|
||||||
|
|
||||||
|
pDsState->enableDepthTest = VK_TRUE;
|
||||||
|
pDsState->enableDepthWrite = VK_TRUE;
|
||||||
|
pDsState->enableStencilTest = VK_FALSE;
|
||||||
|
pDsState->depthCompareOp = VK_COMPARE_OP_LESS;
|
||||||
|
pDsState->stencilOpFront = stencilOp;
|
||||||
|
pDsState->stencilOpBack = stencilOp;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -718,7 +718,6 @@ namespace dxvk {
|
|||||||
DxvkCsChunkRef m_csChunk;
|
DxvkCsChunkRef m_csChunk;
|
||||||
|
|
||||||
Com<D3D11BlendState> m_defaultBlendState;
|
Com<D3D11BlendState> m_defaultBlendState;
|
||||||
Com<D3D11DepthStencilState> m_defaultDepthStencilState;
|
|
||||||
|
|
||||||
D3D11ContextState m_state;
|
D3D11ContextState m_state;
|
||||||
D3D11CmdData* m_cmdData;
|
D3D11CmdData* m_cmdData;
|
||||||
@ -909,6 +908,9 @@ namespace dxvk {
|
|||||||
static void InitDefaultRasterizerState(
|
static void InitDefaultRasterizerState(
|
||||||
DxvkRasterizerState* pRsState);
|
DxvkRasterizerState* pRsState);
|
||||||
|
|
||||||
|
static void InitDefaultDepthStencilState(
|
||||||
|
DxvkDepthStencilState* pDsState);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const D3D11CommonShader* GetCommonShader(T* pShader) const {
|
const D3D11CommonShader* GetCommonShader(T* pShader) const {
|
||||||
return pShader != nullptr ? pShader->GetCommonShader() : nullptr;
|
return pShader != nullptr ? pShader->GetCommonShader() : nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user