From 95815a075bbc2cc137988ce7adcaceac375cb2c8 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 17 Jan 2019 22:22:23 +0100 Subject: [PATCH] [dxvk] Move depth bias out of rasterizer state While the previous model corresponded to D3D11, it does not reflect that the backend treats it the same way as e.g. blend constants. --- src/d3d11/d3d11_rasterizer.cpp | 10 +++++++--- src/d3d11/d3d11_rasterizer.h | 1 + src/d3d11/d3d11_swapchain.cpp | 4 +--- src/dxvk/dxvk_constant_state.h | 27 ++++++++++++++++++++++++--- src/dxvk/dxvk_context.cpp | 27 +++++++++++++++------------ src/dxvk/dxvk_context.h | 14 ++++++++++++-- src/dxvk/dxvk_context_state.h | 14 ++++++-------- src/dxvk/hud/dxvk_hud.cpp | 14 ++++++-------- 8 files changed, 72 insertions(+), 39 deletions(-) diff --git a/src/d3d11/d3d11_rasterizer.cpp b/src/d3d11/d3d11_rasterizer.cpp index faf28e25..3eacd3a5 100644 --- a/src/d3d11/d3d11_rasterizer.cpp +++ b/src/d3d11/d3d11_rasterizer.cpp @@ -45,11 +45,12 @@ namespace dxvk { // some games like to put random/uninitialized numbers here, but // we do not need to enable it in case the parameters are both 0. m_state.depthBiasEnable = desc.DepthBias != 0 || desc.SlopeScaledDepthBias != 0.0f; - m_state.depthBiasConstant = static_cast(desc.DepthBias); - m_state.depthBiasClamp = desc.DepthBiasClamp; - m_state.depthBiasSlope = desc.SlopeScaledDepthBias; m_state.depthClipEnable = desc.DepthClipEnable; m_state.sampleCount = VkSampleCountFlags(desc.ForcedSampleCount); + + m_depthBias.depthBiasConstant = float(desc.DepthBias); + m_depthBias.depthBiasSlope = desc.SlopeScaledDepthBias; + m_depthBias.depthBiasClamp = desc.DepthBiasClamp; if (desc.AntialiasedLineEnable) Logger::err("D3D11RasterizerState: Antialiased lines not supported"); @@ -110,6 +111,9 @@ namespace dxvk { void D3D11RasterizerState::BindToContext(const Rc& ctx) { ctx->setRasterizerState(m_state); + + if (m_state.depthBiasEnable) + ctx->setDepthBias(m_depthBias); } diff --git a/src/d3d11/d3d11_rasterizer.h b/src/d3d11/d3d11_rasterizer.h index a408550d..a2378d2c 100644 --- a/src/d3d11/d3d11_rasterizer.h +++ b/src/d3d11/d3d11_rasterizer.h @@ -54,6 +54,7 @@ namespace dxvk { D3D11Device* const m_device; D3D11_RASTERIZER_DESC1 m_desc; DxvkRasterizerState m_state; + DxvkDepthBias m_depthBias; D3D10RasterizerState m_d3d10; }; diff --git a/src/d3d11/d3d11_swapchain.cpp b/src/d3d11/d3d11_swapchain.cpp index 9201001d..4b4e0b76 100644 --- a/src/d3d11/d3d11_swapchain.cpp +++ b/src/d3d11/d3d11_swapchain.cpp @@ -574,9 +574,7 @@ namespace dxvk { m_rsState.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; m_rsState.depthClipEnable = VK_FALSE; m_rsState.depthBiasEnable = VK_FALSE; - m_rsState.depthBiasConstant = 0.0f; - m_rsState.depthBiasClamp = 0.0f; - m_rsState.depthBiasSlope = 0.0f; + m_rsState.sampleCount = VK_SAMPLE_COUNT_1_BIT; m_msState.sampleMask = 0xffffffff; m_msState.enableAlphaToCoverage = VK_FALSE; diff --git a/src/dxvk/dxvk_constant_state.h b/src/dxvk/dxvk_constant_state.h index 1d98c699..6446ce96 100644 --- a/src/dxvk/dxvk_constant_state.h +++ b/src/dxvk/dxvk_constant_state.h @@ -27,6 +27,30 @@ namespace dxvk { || this->b != other.b || this->a != other.a; } }; + + + /** + * \brief Depth bias + * + * Stores depth bias values. + */ + struct DxvkDepthBias { + float depthBiasConstant; + float depthBiasSlope; + float depthBiasClamp; + + bool operator == (const DxvkDepthBias& other) const { + return depthBiasConstant == other.depthBiasConstant + && depthBiasSlope == other.depthBiasSlope + && depthBiasClamp == other.depthBiasClamp; + } + + bool operator != (const DxvkDepthBias& other) const { + return depthBiasConstant != other.depthBiasConstant + || depthBiasSlope != other.depthBiasSlope + || depthBiasClamp != other.depthBiasClamp; + } + }; /** @@ -55,9 +79,6 @@ namespace dxvk { VkFrontFace frontFace; VkBool32 depthClipEnable; VkBool32 depthBiasEnable; - float depthBiasConstant; - float depthBiasClamp; - float depthBiasSlope; VkSampleCountFlags sampleCount; }; diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 92102ac4..63546e24 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1592,7 +1592,7 @@ namespace dxvk { void DxvkContext::setBlendConstants( - const DxvkBlendConstants& blendConstants) { + DxvkBlendConstants blendConstants) { if (m_state.om.blendConstants != blendConstants) { m_state.om.blendConstants = blendConstants; m_flags.set(DxvkContextFlag::GpDirtyBlendConstants); @@ -1600,8 +1600,17 @@ namespace dxvk { } + void DxvkContext::setDepthBias( + DxvkDepthBias depthBias) { + if (m_state.dyn.depthBias != depthBias) { + m_state.dyn.depthBias = depthBias; + m_flags.set(DxvkContextFlag::GpDirtyDepthBias); + } + } + + void DxvkContext::setStencilReference( - const uint32_t reference) { + uint32_t reference) { if (m_state.om.stencilReference != reference) { m_state.om.stencilReference = reference; m_flags.set(DxvkContextFlag::GpDirtyStencilRef); @@ -1659,13 +1668,7 @@ namespace dxvk { m_state.gp.state.rsFrontFace = rs.frontFace; m_state.gp.state.rsSampleCount = rs.sampleCount; - m_state.ds.depthBiasConstant = rs.depthBiasConstant; - m_state.ds.depthBiasClamp = rs.depthBiasClamp; - m_state.ds.depthBiasSlope = rs.depthBiasSlope; - - m_flags.set( - DxvkContextFlag::GpDirtyPipelineState, - DxvkContextFlag::GpDirtyDepthBias); + m_flags.set(DxvkContextFlag::GpDirtyPipelineState); } @@ -3053,9 +3056,9 @@ namespace dxvk { m_flags.clr(DxvkContextFlag::GpDirtyDepthBias); m_cmd->cmdSetDepthBias( - m_state.ds.depthBiasConstant, - m_state.ds.depthBiasClamp, - m_state.ds.depthBiasSlope); + m_state.dyn.depthBias.depthBiasConstant, + m_state.dyn.depthBias.depthBiasClamp, + m_state.dyn.depthBias.depthBiasSlope); } } diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index e0573555..ea356570 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -674,7 +674,17 @@ namespace dxvk { * \param [in] blendConstants Blend constants */ void setBlendConstants( - const DxvkBlendConstants& blendConstants); + DxvkBlendConstants blendConstants); + + /** + * \brief Sets depth bias + * + * Depth bias has to be enabled explicitly in + * the rasterizer state to have any effect. + * \param [in] depthBias Depth bias values + */ + void setDepthBias( + DxvkDepthBias depthBias); /** * \brief Sets stencil reference @@ -683,7 +693,7 @@ namespace dxvk { * \param [in] reference Reference value */ void setStencilReference( - const uint32_t reference); + uint32_t reference); /** * \brief Sets input assembly state diff --git a/src/dxvk/dxvk_context_state.h b/src/dxvk/dxvk_context_state.h index 3beca32f..ab548ec5 100644 --- a/src/dxvk/dxvk_context_state.h +++ b/src/dxvk/dxvk_context_state.h @@ -75,13 +75,6 @@ namespace dxvk { }; - struct DxvkDynamicDepthState { - float depthBiasConstant = 0.0f; - float depthBiasClamp = 0.0f; - float depthBiasSlope = 0.0f; - }; - - struct DxvkOutputMergerState { std::array clearValues = { }; @@ -124,6 +117,11 @@ namespace dxvk { DxvkComputePipelineStateInfo state; Rc pipeline; }; + + + struct DxvkDynamicState { + DxvkDepthBias depthBias = { 0.0f, 0.0f, 0.0f }; + }; /** @@ -136,9 +134,9 @@ namespace dxvk { DxvkIndirectDrawState id; DxvkVertexInputState vi; DxvkViewportState vp; - DxvkDynamicDepthState ds; DxvkOutputMergerState om; DxvkXfbState xfb; + DxvkDynamicState dyn; DxvkGraphicsPipelineState gp; DxvkComputePipelineState cp; diff --git a/src/dxvk/hud/dxvk_hud.cpp b/src/dxvk/hud/dxvk_hud.cpp index be422c16..c400917a 100644 --- a/src/dxvk/hud/dxvk_hud.cpp +++ b/src/dxvk/hud/dxvk_hud.cpp @@ -16,14 +16,12 @@ namespace dxvk::hud { m_hudFramerate (config.elements), m_hudStats (config.elements) { // Set up constant state - m_rsState.polygonMode = VK_POLYGON_MODE_FILL; - m_rsState.cullMode = VK_CULL_MODE_BACK_BIT; - m_rsState.frontFace = VK_FRONT_FACE_CLOCKWISE; - m_rsState.depthClipEnable = VK_FALSE; - m_rsState.depthBiasEnable = VK_FALSE; - m_rsState.depthBiasConstant = 0.0f; - m_rsState.depthBiasClamp = 0.0f; - m_rsState.depthBiasSlope = 0.0f; + m_rsState.polygonMode = VK_POLYGON_MODE_FILL; + m_rsState.cullMode = VK_CULL_MODE_BACK_BIT; + m_rsState.frontFace = VK_FRONT_FACE_CLOCKWISE; + m_rsState.depthClipEnable = VK_FALSE; + m_rsState.depthBiasEnable = VK_FALSE; + m_rsState.sampleCount = VK_SAMPLE_COUNT_1_BIT; m_blendMode.enableBlending = VK_TRUE; m_blendMode.colorSrcFactor = VK_BLEND_FACTOR_ONE;