1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-12 04:08:52 +01:00

[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.
This commit is contained in:
Philip Rebohle 2019-01-17 22:22:23 +01:00
parent 8cc4497f11
commit 95815a075b
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
8 changed files with 72 additions and 39 deletions

View File

@ -45,12 +45,13 @@ namespace dxvk {
// some games like to put random/uninitialized numbers here, but // some games like to put random/uninitialized numbers here, but
// we do not need to enable it in case the parameters are both 0. // 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.depthBiasEnable = desc.DepthBias != 0 || desc.SlopeScaledDepthBias != 0.0f;
m_state.depthBiasConstant = static_cast<float>(desc.DepthBias);
m_state.depthBiasClamp = desc.DepthBiasClamp;
m_state.depthBiasSlope = desc.SlopeScaledDepthBias;
m_state.depthClipEnable = desc.DepthClipEnable; m_state.depthClipEnable = desc.DepthClipEnable;
m_state.sampleCount = VkSampleCountFlags(desc.ForcedSampleCount); 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) if (desc.AntialiasedLineEnable)
Logger::err("D3D11RasterizerState: Antialiased lines not supported"); Logger::err("D3D11RasterizerState: Antialiased lines not supported");
} }
@ -110,6 +111,9 @@ namespace dxvk {
void D3D11RasterizerState::BindToContext(const Rc<DxvkContext>& ctx) { void D3D11RasterizerState::BindToContext(const Rc<DxvkContext>& ctx) {
ctx->setRasterizerState(m_state); ctx->setRasterizerState(m_state);
if (m_state.depthBiasEnable)
ctx->setDepthBias(m_depthBias);
} }

View File

@ -54,6 +54,7 @@ namespace dxvk {
D3D11Device* const m_device; D3D11Device* const m_device;
D3D11_RASTERIZER_DESC1 m_desc; D3D11_RASTERIZER_DESC1 m_desc;
DxvkRasterizerState m_state; DxvkRasterizerState m_state;
DxvkDepthBias m_depthBias;
D3D10RasterizerState m_d3d10; D3D10RasterizerState m_d3d10;
}; };

View File

@ -574,9 +574,7 @@ namespace dxvk {
m_rsState.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; m_rsState.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
m_rsState.depthClipEnable = VK_FALSE; m_rsState.depthClipEnable = VK_FALSE;
m_rsState.depthBiasEnable = VK_FALSE; m_rsState.depthBiasEnable = VK_FALSE;
m_rsState.depthBiasConstant = 0.0f; m_rsState.sampleCount = VK_SAMPLE_COUNT_1_BIT;
m_rsState.depthBiasClamp = 0.0f;
m_rsState.depthBiasSlope = 0.0f;
m_msState.sampleMask = 0xffffffff; m_msState.sampleMask = 0xffffffff;
m_msState.enableAlphaToCoverage = VK_FALSE; m_msState.enableAlphaToCoverage = VK_FALSE;

View File

@ -29,6 +29,30 @@ namespace dxvk {
}; };
/**
* \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;
}
};
/** /**
* \brief Input assembly state * \brief Input assembly state
* *
@ -55,9 +79,6 @@ namespace dxvk {
VkFrontFace frontFace; VkFrontFace frontFace;
VkBool32 depthClipEnable; VkBool32 depthClipEnable;
VkBool32 depthBiasEnable; VkBool32 depthBiasEnable;
float depthBiasConstant;
float depthBiasClamp;
float depthBiasSlope;
VkSampleCountFlags sampleCount; VkSampleCountFlags sampleCount;
}; };

View File

@ -1592,7 +1592,7 @@ namespace dxvk {
void DxvkContext::setBlendConstants( void DxvkContext::setBlendConstants(
const DxvkBlendConstants& blendConstants) { DxvkBlendConstants blendConstants) {
if (m_state.om.blendConstants != blendConstants) { if (m_state.om.blendConstants != blendConstants) {
m_state.om.blendConstants = blendConstants; m_state.om.blendConstants = blendConstants;
m_flags.set(DxvkContextFlag::GpDirtyBlendConstants); 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( void DxvkContext::setStencilReference(
const uint32_t reference) { uint32_t reference) {
if (m_state.om.stencilReference != reference) { if (m_state.om.stencilReference != reference) {
m_state.om.stencilReference = reference; m_state.om.stencilReference = reference;
m_flags.set(DxvkContextFlag::GpDirtyStencilRef); m_flags.set(DxvkContextFlag::GpDirtyStencilRef);
@ -1659,13 +1668,7 @@ namespace dxvk {
m_state.gp.state.rsFrontFace = rs.frontFace; m_state.gp.state.rsFrontFace = rs.frontFace;
m_state.gp.state.rsSampleCount = rs.sampleCount; m_state.gp.state.rsSampleCount = rs.sampleCount;
m_state.ds.depthBiasConstant = rs.depthBiasConstant; m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
m_state.ds.depthBiasClamp = rs.depthBiasClamp;
m_state.ds.depthBiasSlope = rs.depthBiasSlope;
m_flags.set(
DxvkContextFlag::GpDirtyPipelineState,
DxvkContextFlag::GpDirtyDepthBias);
} }
@ -3053,9 +3056,9 @@ namespace dxvk {
m_flags.clr(DxvkContextFlag::GpDirtyDepthBias); m_flags.clr(DxvkContextFlag::GpDirtyDepthBias);
m_cmd->cmdSetDepthBias( m_cmd->cmdSetDepthBias(
m_state.ds.depthBiasConstant, m_state.dyn.depthBias.depthBiasConstant,
m_state.ds.depthBiasClamp, m_state.dyn.depthBias.depthBiasClamp,
m_state.ds.depthBiasSlope); m_state.dyn.depthBias.depthBiasSlope);
} }
} }

View File

@ -674,7 +674,17 @@ namespace dxvk {
* \param [in] blendConstants Blend constants * \param [in] blendConstants Blend constants
*/ */
void setBlendConstants( 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 * \brief Sets stencil reference
@ -683,7 +693,7 @@ namespace dxvk {
* \param [in] reference Reference value * \param [in] reference Reference value
*/ */
void setStencilReference( void setStencilReference(
const uint32_t reference); uint32_t reference);
/** /**
* \brief Sets input assembly state * \brief Sets input assembly state

View File

@ -75,13 +75,6 @@ namespace dxvk {
}; };
struct DxvkDynamicDepthState {
float depthBiasConstant = 0.0f;
float depthBiasClamp = 0.0f;
float depthBiasSlope = 0.0f;
};
struct DxvkOutputMergerState { struct DxvkOutputMergerState {
std::array<VkClearValue, MaxNumRenderTargets + 1> clearValues = { }; std::array<VkClearValue, MaxNumRenderTargets + 1> clearValues = { };
@ -126,6 +119,11 @@ namespace dxvk {
}; };
struct DxvkDynamicState {
DxvkDepthBias depthBias = { 0.0f, 0.0f, 0.0f };
};
/** /**
* \brief Pipeline state * \brief Pipeline state
* *
@ -136,9 +134,9 @@ namespace dxvk {
DxvkIndirectDrawState id; DxvkIndirectDrawState id;
DxvkVertexInputState vi; DxvkVertexInputState vi;
DxvkViewportState vp; DxvkViewportState vp;
DxvkDynamicDepthState ds;
DxvkOutputMergerState om; DxvkOutputMergerState om;
DxvkXfbState xfb; DxvkXfbState xfb;
DxvkDynamicState dyn;
DxvkGraphicsPipelineState gp; DxvkGraphicsPipelineState gp;
DxvkComputePipelineState cp; DxvkComputePipelineState cp;

View File

@ -16,14 +16,12 @@ namespace dxvk::hud {
m_hudFramerate (config.elements), m_hudFramerate (config.elements),
m_hudStats (config.elements) { m_hudStats (config.elements) {
// Set up constant state // Set up constant state
m_rsState.polygonMode = VK_POLYGON_MODE_FILL; m_rsState.polygonMode = VK_POLYGON_MODE_FILL;
m_rsState.cullMode = VK_CULL_MODE_BACK_BIT; m_rsState.cullMode = VK_CULL_MODE_BACK_BIT;
m_rsState.frontFace = VK_FRONT_FACE_CLOCKWISE; m_rsState.frontFace = VK_FRONT_FACE_CLOCKWISE;
m_rsState.depthClipEnable = VK_FALSE; m_rsState.depthClipEnable = VK_FALSE;
m_rsState.depthBiasEnable = VK_FALSE; m_rsState.depthBiasEnable = VK_FALSE;
m_rsState.depthBiasConstant = 0.0f; m_rsState.sampleCount = VK_SAMPLE_COUNT_1_BIT;
m_rsState.depthBiasClamp = 0.0f;
m_rsState.depthBiasSlope = 0.0f;
m_blendMode.enableBlending = VK_TRUE; m_blendMode.enableBlending = VK_TRUE;
m_blendMode.colorSrcFactor = VK_BLEND_FACTOR_ONE; m_blendMode.colorSrcFactor = VK_BLEND_FACTOR_ONE;