diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 3c52df87..8950a19f 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -24,16 +24,13 @@ namespace dxvk { // Create default state objects. We won't ever return them // to the application, but we'll use them to apply state. Com defaultBlendState; - Com defaultDepthStencilState; - if (FAILED(m_parent->CreateBlendState (nullptr, &defaultBlendState)) - || FAILED(m_parent->CreateDepthStencilState(nullptr, &defaultDepthStencilState))) + if (FAILED(m_parent->CreateBlendState (nullptr, &defaultBlendState))) throw DxvkError("D3D11DeviceContext: Failed to create default state objects"); // Apply default state to the context. This is required // in order to initialize the DXVK contex properly. m_defaultBlendState = static_cast (defaultBlendState.ptr()); - m_defaultDepthStencilState = static_cast(defaultDepthStencilState.ptr()); } @@ -3249,16 +3246,20 @@ namespace dxvk { 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)) - dsState = m_defaultDepthStencilState.prvRef(); - - EmitCs([ - cDepthStencilState = std::move(dsState) - ] (DxvkContext* ctx) { - cDepthStencilState->BindToContext(ctx); - }); + ctx->setDepthStencilState(dsState); + }); + } } @@ -3778,8 +3779,7 @@ namespace dxvk { void D3D11DeviceContext::ResetState() { EmitCs([ - cBlendState = m_defaultBlendState.prvRef(), - cDepthStencilState = m_defaultDepthStencilState.prvRef() + cBlendState = m_defaultBlendState.prvRef() ] (DxvkContext* ctx) { // Reset render targets ctx->bindRenderTargets(DxvkRenderTargets()); @@ -3791,14 +3791,17 @@ namespace dxvk { DxvkInputAssemblyState iaState; InitDefaultPrimitiveTopology(&iaState); + DxvkDepthStencilState dsState; + InitDefaultDepthStencilState(&dsState); + DxvkRasterizerState rsState; InitDefaultRasterizerState(&rsState); ctx->setInputAssemblyState(iaState); + ctx->setDepthStencilState(dsState); ctx->setRasterizerState(rsState); cBlendState->BindToContext(ctx, D3D11_DEFAULT_SAMPLE_MASK); - cDepthStencilState->BindToContext(ctx); // Reset dynamic states ctx->setBlendConstants(DxvkBlendConstants { 1.0f, 1.0f, 1.0f, 1.0f }); @@ -4281,4 +4284,24 @@ namespace dxvk { 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; + } + } diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 9c5c82f7..ee348956 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -718,7 +718,6 @@ namespace dxvk { DxvkCsChunkRef m_csChunk; Com m_defaultBlendState; - Com m_defaultDepthStencilState; D3D11ContextState m_state; D3D11CmdData* m_cmdData; @@ -909,6 +908,9 @@ namespace dxvk { static void InitDefaultRasterizerState( DxvkRasterizerState* pRsState); + static void InitDefaultDepthStencilState( + DxvkDepthStencilState* pDsState); + template const D3D11CommonShader* GetCommonShader(T* pShader) const { return pShader != nullptr ? pShader->GetCommonShader() : nullptr;