rhi: Add depth bias and slope scaled depth bias
Beware of the API terminology: GL 'factor' = 'slope scaled depth bias', GL 'units' = '(constant) depth bias'. Task-number: QTBUG-81843 Change-Id: I03e3618d007cbf7100add0de4950a6163d788cc7 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
parent
7e82d49cc5
commit
19510abbff
@ -1155,6 +1155,12 @@ public:
|
||||
float lineWidth() const { return m_lineWidth; }
|
||||
void setLineWidth(float width) { m_lineWidth = width; }
|
||||
|
||||
int depthBias() const { return m_depthBias; }
|
||||
void setDepthBias(int bias) { m_depthBias = bias; }
|
||||
|
||||
float slopeScaledDepthBias() const { return m_slopeScaledDepthBias; }
|
||||
void setSlopeScaledDepthBias(float bias) { m_slopeScaledDepthBias = bias; }
|
||||
|
||||
void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; }
|
||||
template<typename InputIterator>
|
||||
void setShaderStages(InputIterator first, InputIterator last)
|
||||
@ -1193,6 +1199,8 @@ protected:
|
||||
quint32 m_stencilWriteMask = 0xFF;
|
||||
int m_sampleCount = 1;
|
||||
float m_lineWidth = 1.0f;
|
||||
int m_depthBias = 0;
|
||||
float m_slopeScaledDepthBias = 0.0f;
|
||||
QVarLengthArray<QRhiShaderStage, 4> m_shaderStages;
|
||||
QRhiVertexInputLayout m_vertexInputLayout;
|
||||
QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr;
|
||||
|
@ -3467,6 +3467,8 @@ bool QD3D11GraphicsPipeline::build()
|
||||
rastDesc.FillMode = D3D11_FILL_SOLID;
|
||||
rastDesc.CullMode = toD3DCullMode(m_cullMode);
|
||||
rastDesc.FrontCounterClockwise = m_frontFace == CCW;
|
||||
rastDesc.DepthBias = m_depthBias;
|
||||
rastDesc.SlopeScaledDepthBias = m_slopeScaledDepthBias;
|
||||
rastDesc.DepthClipEnable = true;
|
||||
rastDesc.ScissorEnable = m_flags.testFlag(UsesScissor);
|
||||
rastDesc.MultisampleEnable = rhiD->effectiveSampleCount(m_sampleCount).Count > 1;
|
||||
|
@ -2386,7 +2386,14 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps)
|
||||
f->glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
if (psD->topology() == QRhiGraphicsPipeline::Lines || psD->topology() == QRhiGraphicsPipeline::LineStrip)
|
||||
if (psD->m_depthBias != 0 || !qFuzzyIsNull(psD->m_slopeScaledDepthBias)) {
|
||||
f->glPolygonOffset(psD->m_slopeScaledDepthBias, psD->m_depthBias);
|
||||
f->glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
} else {
|
||||
f->glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
|
||||
if (psD->m_topology == QRhiGraphicsPipeline::Lines || psD->m_topology == QRhiGraphicsPipeline::LineStrip)
|
||||
f->glLineWidth(psD->m_lineWidth);
|
||||
|
||||
f->glUseProgram(psD->program);
|
||||
|
@ -298,6 +298,8 @@ struct QMetalGraphicsPipelineData
|
||||
MTLPrimitiveType primitiveType;
|
||||
MTLWinding winding;
|
||||
MTLCullMode cullMode;
|
||||
float depthBias;
|
||||
float slopeScaledDepthBias;
|
||||
QMetalShader vs;
|
||||
QMetalShader fs;
|
||||
};
|
||||
@ -956,6 +958,14 @@ void QRhiMetal::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline
|
||||
[cbD->d->currentRenderPassEncoder setFrontFacingWinding: psD->d->winding];
|
||||
cbD->currentFrontFaceWinding = int(psD->d->winding);
|
||||
}
|
||||
if (!qFuzzyCompare(psD->d->depthBias, cbD->currentDepthBiasValues.first)
|
||||
|| !qFuzzyCompare(psD->d->slopeScaledDepthBias, cbD->currentDepthBiasValues.second))
|
||||
{
|
||||
[cbD->d->currentRenderPassEncoder setDepthBias: psD->d->depthBias
|
||||
slopeScale: psD->d->slopeScaledDepthBias
|
||||
clamp: 0.0f];
|
||||
cbD->currentDepthBiasValues = { psD->d->depthBias, psD->d->slopeScaledDepthBias };
|
||||
}
|
||||
}
|
||||
|
||||
psD->lastActiveFrameSlot = currentFrameSlot;
|
||||
@ -3454,6 +3464,8 @@ bool QMetalGraphicsPipeline::build()
|
||||
d->primitiveType = toMetalPrimitiveType(m_topology);
|
||||
d->winding = m_frontFace == CCW ? MTLWindingCounterClockwise : MTLWindingClockwise;
|
||||
d->cullMode = toMetalCullMode(m_cullMode);
|
||||
d->depthBias = float(m_depthBias);
|
||||
d->slopeScaledDepthBias = m_slopeScaledDepthBias;
|
||||
|
||||
lastActiveFrameSlot = -1;
|
||||
generation += 1;
|
||||
@ -3602,6 +3614,7 @@ void QMetalCommandBuffer::resetPerPassCachedState()
|
||||
currentIndexFormat = QRhiCommandBuffer::IndexUInt16;
|
||||
currentCullMode = -1;
|
||||
currentFrontFaceWinding = -1;
|
||||
currentDepthBiasValues = { 0.0f, 0.0f };
|
||||
|
||||
d->currentFirstVertexBinding = -1;
|
||||
d->currentVertexInputsBuffers.clear();
|
||||
|
@ -288,6 +288,7 @@ struct QMetalCommandBuffer : public QRhiCommandBuffer
|
||||
QRhiCommandBuffer::IndexFormat currentIndexFormat;
|
||||
int currentCullMode;
|
||||
int currentFrontFaceWinding;
|
||||
QPair<float, float> currentDepthBiasValues;
|
||||
|
||||
const QRhiNativeHandles *nativeHandles();
|
||||
void resetState();
|
||||
|
@ -6208,6 +6208,11 @@ bool QVkGraphicsPipeline::build()
|
||||
rastInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
||||
rastInfo.cullMode = toVkCullMode(m_cullMode);
|
||||
rastInfo.frontFace = toVkFrontFace(m_frontFace);
|
||||
if (m_depthBias != 0 || !qFuzzyIsNull(m_slopeScaledDepthBias)) {
|
||||
rastInfo.depthBiasEnable = true;
|
||||
rastInfo.depthBiasConstantFactor = float(m_depthBias);
|
||||
rastInfo.depthBiasSlopeFactor = m_slopeScaledDepthBias;
|
||||
}
|
||||
rastInfo.lineWidth = rhiD->hasWideLines ? m_lineWidth : 1.0f;
|
||||
pipelineInfo.pRasterizationState = &rastInfo;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user