diff --git a/src/dxvk/dxvk_cmdlist.h b/src/dxvk/dxvk_cmdlist.h index bd4edd57..ca8e5d44 100644 --- a/src/dxvk/dxvk_cmdlist.h +++ b/src/dxvk/dxvk_cmdlist.h @@ -824,6 +824,12 @@ namespace dxvk { } + void cmdSetDepthBias2( + const VkDepthBiasInfoEXT *depthBiasInfo) { + m_vkd->vkCmdSetDepthBias2EXT(m_cmd.execBuffer, depthBiasInfo); + } + + void cmdSetDepthBounds( float minDepthBounds, float maxDepthBounds) { diff --git a/src/dxvk/dxvk_constant_state.h b/src/dxvk/dxvk_constant_state.h index 46d3d2af..f6fea430 100644 --- a/src/dxvk/dxvk_constant_state.h +++ b/src/dxvk/dxvk_constant_state.h @@ -29,26 +29,47 @@ namespace dxvk { }; + /** + * \brief Depth bias representation + * + * Stores depth bias representation info. + */ + struct DxvkDepthBiasRepresentation { + VkDepthBiasRepresentationEXT depthBiasRepresentation; + VkBool32 depthBiasExact; + + bool operator == (const DxvkDepthBiasRepresentation& other) const { + return depthBiasRepresentation == other.depthBiasRepresentation + && depthBiasExact == other.depthBiasExact; + } + + bool operator != (const DxvkDepthBiasRepresentation& other) const { + return depthBiasRepresentation != other.depthBiasRepresentation + || depthBiasExact != other.depthBiasExact; + } + }; + + /** * \brief Depth bias * * Stores depth bias values. */ struct DxvkDepthBias { - float depthBiasConstant; - float depthBiasSlope; - float depthBiasClamp; + float depthBiasConstant; + float depthBiasSlope; + float depthBiasClamp; bool operator == (const DxvkDepthBias& other) const { - return depthBiasConstant == other.depthBiasConstant - && depthBiasSlope == other.depthBiasSlope - && depthBiasClamp == other.depthBiasClamp; + 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; + return depthBiasConstant != other.depthBiasConstant + || depthBiasSlope != other.depthBiasSlope + || depthBiasClamp != other.depthBiasClamp; } }; diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index ad9739c2..c8d5c7cd 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -2442,6 +2442,15 @@ namespace dxvk { } + void DxvkContext::setDepthBiasRepresentation( + DxvkDepthBiasRepresentation depthBiasRepresentation) { + if (m_state.dyn.depthBiasRepresentation != depthBiasRepresentation) { + m_state.dyn.depthBiasRepresentation = depthBiasRepresentation; + m_flags.set(DxvkContextFlag::GpDirtyDepthBias); + } + } + + void DxvkContext::setDepthBounds( DxvkDepthBounds depthBounds) { if (m_state.dyn.depthBounds != depthBounds) { @@ -5784,10 +5793,24 @@ namespace dxvk { DxvkContextFlag::GpDynamicDepthBias)) { m_flags.clr(DxvkContextFlag::GpDirtyDepthBias); - m_cmd->cmdSetDepthBias( - m_state.dyn.depthBias.depthBiasConstant, - m_state.dyn.depthBias.depthBiasClamp, - m_state.dyn.depthBias.depthBiasSlope); + if (m_device->features().extDepthBiasControl.depthBiasControl) { + VkDepthBiasRepresentationInfoEXT depthBiasRepresentation = { VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT }; + depthBiasRepresentation.depthBiasRepresentation = m_state.dyn.depthBiasRepresentation.depthBiasRepresentation; + depthBiasRepresentation.depthBiasExact = m_state.dyn.depthBiasRepresentation.depthBiasExact; + + VkDepthBiasInfoEXT depthBiasInfo = { VK_STRUCTURE_TYPE_DEPTH_BIAS_INFO_EXT }; + depthBiasInfo.pNext = &depthBiasRepresentation; + depthBiasInfo.depthBiasConstantFactor = m_state.dyn.depthBias.depthBiasConstant; + depthBiasInfo.depthBiasClamp = m_state.dyn.depthBias.depthBiasClamp; + depthBiasInfo.depthBiasSlopeFactor = m_state.dyn.depthBias.depthBiasSlope; + + m_cmd->cmdSetDepthBias2(&depthBiasInfo); + } else { + m_cmd->cmdSetDepthBias( + m_state.dyn.depthBias.depthBiasConstant, + m_state.dyn.depthBias.depthBiasClamp, + m_state.dyn.depthBias.depthBiasSlope); + } } if (m_flags.all(DxvkContextFlag::GpDirtyDepthBounds, diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index fac872c9..93ed91e3 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -1141,6 +1141,14 @@ namespace dxvk { */ void setDepthBias( DxvkDepthBias depthBias); + + /** + * \brief Sets depth bias representation + * + * \param [in] depthBiasRepresentation Depth bias representation + */ + void setDepthBiasRepresentation( + DxvkDepthBiasRepresentation depthBiasRepresentation); /** * \brief Sets depth bounds diff --git a/src/dxvk/dxvk_context_state.h b/src/dxvk/dxvk_context_state.h index 5c2218e8..34018f0e 100644 --- a/src/dxvk/dxvk_context_state.h +++ b/src/dxvk/dxvk_context_state.h @@ -150,12 +150,13 @@ namespace dxvk { struct DxvkDynamicState { - DxvkBlendConstants blendConstants = { 0.0f, 0.0f, 0.0f, 0.0f }; - DxvkDepthBias depthBias = { 0.0f, 0.0f, 0.0f }; - DxvkDepthBounds depthBounds = { false, 0.0f, 1.0f }; - uint32_t stencilReference = 0; - VkCullModeFlags cullMode = VK_CULL_MODE_BACK_BIT; - VkFrontFace frontFace = VK_FRONT_FACE_CLOCKWISE; + DxvkBlendConstants blendConstants = { 0.0f, 0.0f, 0.0f, 0.0f }; + DxvkDepthBias depthBias = { 0.0f, 0.0f, 0.0f }; + DxvkDepthBiasRepresentation depthBiasRepresentation = { VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, false }; + DxvkDepthBounds depthBounds = { false, 0.0f, 1.0f }; + uint32_t stencilReference = 0; + VkCullModeFlags cullMode = VK_CULL_MODE_BACK_BIT; + VkFrontFace frontFace = VK_FRONT_FACE_CLOCKWISE; };