1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 19:24:10 +01:00

[d3d11] Don't use a state object for default rasterizer state

This commit is contained in:
Philip Rebohle 2019-10-13 22:40:41 +02:00
parent a89c662984
commit b0231403fe
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 35 additions and 19 deletions

View File

@ -25,18 +25,15 @@ namespace dxvk {
// to the application, but we'll use them to apply state.
Com<ID3D11BlendState> defaultBlendState;
Com<ID3D11DepthStencilState> defaultDepthStencilState;
Com<ID3D11RasterizerState> 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<D3D11BlendState*> (defaultBlendState.ptr());
m_defaultDepthStencilState = static_cast<D3D11DepthStencilState*>(defaultDepthStencilState.ptr());
m_defaultRasterizerState = static_cast<D3D11RasterizerState*> (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;
}
}

View File

@ -719,7 +719,6 @@ namespace dxvk {
Com<D3D11BlendState> m_defaultBlendState;
Com<D3D11DepthStencilState> m_defaultDepthStencilState;
Com<D3D11RasterizerState> 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<typename T>
const D3D11CommonShader* GetCommonShader(T* pShader) const {
return pShader != nullptr ? pShader->GetCommonShader() : nullptr;