1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-11 19:24:11 +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,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<float>(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<DxvkContext>& ctx) {
ctx->setRasterizerState(m_state);
if (m_state.depthBiasEnable)
ctx->setDepthBias(m_depthBias);
}

View File

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

View File

@ -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;

View File

@ -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;
};

View File

@ -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);
}
}

View File

@ -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

View File

@ -75,13 +75,6 @@ namespace dxvk {
};
struct DxvkDynamicDepthState {
float depthBiasConstant = 0.0f;
float depthBiasClamp = 0.0f;
float depthBiasSlope = 0.0f;
};
struct DxvkOutputMergerState {
std::array<VkClearValue, MaxNumRenderTargets + 1> clearValues = { };
@ -124,6 +117,11 @@ namespace dxvk {
DxvkComputePipelineStateInfo state;
Rc<DxvkComputePipeline> 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;

View File

@ -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;