From b0231403fe73ae2eee39a9433545d6b396520cd4 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 13 Oct 2019 22:40:41 +0200 Subject: [PATCH] [d3d11] Don't use a state object for default rasterizer state --- src/d3d11/d3d11_context.cpp | 50 ++++++++++++++++++++++++------------- src/d3d11/d3d11_context.h | 4 ++- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 71183b40..3c52df87 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -25,18 +25,15 @@ namespace dxvk { // to the application, but we'll use them to apply state. Com defaultBlendState; Com defaultDepthStencilState; - Com defaultRasterizerState; if (FAILED(m_parent->CreateBlendState (nullptr, &defaultBlendState)) - || FAILED(m_parent->CreateDepthStencilState(nullptr, &defaultDepthStencilState)) - || FAILED(m_parent->CreateRasterizerState (nullptr, &defaultRasterizerState))) + || FAILED(m_parent->CreateDepthStencilState(nullptr, &defaultDepthStencilState))) 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()); - m_defaultRasterizerState = static_cast (defaultRasterizerState.ptr()); } @@ -3275,16 +3272,20 @@ namespace dxvk { void D3D11DeviceContext::ApplyRasterizerState() { - auto rsState = m_state.rs.state.prvRef(); + if (m_state.rs.state != nullptr) { + EmitCs([ + cRasterizerState = m_state.rs.state.prvRef() + ] (DxvkContext* ctx) { + cRasterizerState->BindToContext(ctx); + }); + } else { + EmitCs([] (DxvkContext* ctx) { + DxvkRasterizerState rsState; + InitDefaultRasterizerState(&rsState); - if (unlikely(rsState == nullptr)) - rsState = m_defaultRasterizerState.prvRef(); - - EmitCs([ - cRasterizerState = std::move(rsState) - ] (DxvkContext* ctx) { - cRasterizerState->BindToContext(ctx); - }); + ctx->setRasterizerState(rsState); + }); + } } @@ -3778,8 +3779,7 @@ namespace dxvk { void D3D11DeviceContext::ResetState() { EmitCs([ cBlendState = m_defaultBlendState.prvRef(), - cDepthStencilState = m_defaultDepthStencilState.prvRef(), - cRasterizerState = m_defaultRasterizerState.prvRef() + cDepthStencilState = m_defaultDepthStencilState.prvRef() ] (DxvkContext* ctx) { // Reset render targets ctx->bindRenderTargets(DxvkRenderTargets()); @@ -3787,15 +3787,18 @@ namespace dxvk { // Reset vertex input state ctx->setInputLayout(0, nullptr, 0, nullptr); + // Reset render states DxvkInputAssemblyState iaState; InitDefaultPrimitiveTopology(&iaState); - ctx->setInputAssemblyState(iaState); + DxvkRasterizerState rsState; + InitDefaultRasterizerState(&rsState); + + ctx->setInputAssemblyState(iaState); + ctx->setRasterizerState(rsState); - // Reset render states cBlendState->BindToContext(ctx, D3D11_DEFAULT_SAMPLE_MASK); cDepthStencilState->BindToContext(ctx); - cRasterizerState->BindToContext(ctx); // Reset dynamic states ctx->setBlendConstants(DxvkBlendConstants { 1.0f, 1.0f, 1.0f, 1.0f }); @@ -4267,4 +4270,15 @@ namespace dxvk { pIaState->patchVertexCount = 0; } + + void D3D11DeviceContext::InitDefaultRasterizerState( + DxvkRasterizerState* pRsState) { + pRsState->polygonMode = VK_POLYGON_MODE_FILL; + pRsState->cullMode = VK_CULL_MODE_BACK_BIT; + pRsState->frontFace = VK_FRONT_FACE_CLOCKWISE; + pRsState->depthClipEnable = VK_TRUE; + pRsState->depthBiasEnable = VK_FALSE; + pRsState->sampleCount = 0; + } + } diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 56e7e84c..9c5c82f7 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -719,7 +719,6 @@ namespace dxvk { Com m_defaultBlendState; Com m_defaultDepthStencilState; - Com m_defaultRasterizerState; D3D11ContextState m_state; D3D11CmdData* m_cmdData; @@ -907,6 +906,9 @@ namespace dxvk { static void InitDefaultPrimitiveTopology( DxvkInputAssemblyState* pIaState); + static void InitDefaultRasterizerState( + DxvkRasterizerState* pRsState); + template const D3D11CommonShader* GetCommonShader(T* pShader) const { return pShader != nullptr ? pShader->GetCommonShader() : nullptr;