Vulkan: apply each material's depth bias, like OpenGL (#7939)

Squad logos are drawn with a material depth bias of 1 so they sit on top
of the hull. Under Vulkan the bias was written to the dynamic state but
the pipeline was built with depth bias disabled, so it never applied.
applyMaterial now calls vulkan_zbias with the material's bias before
building the pipeline config, the same way opengl_tnl_set_material calls
gr_zbias.

vulkan_zbias also passed its two values in the wrong order:
glPolygonOffset takes (slope factor, constant units) while
setDepthBias here takes (constant, slope).

Co-authored-by: Dustinspace217 <[email protected]>
This commit is contained in:
dustinspace217andDustinspace217 authored and GitHub committed 2026-11-04 18:20:24 +01:00
1 parent b7e7949413
commit 259a58de60
3 files changed
+5 -7

No files matched your search

+2 -4
View File
@@ -1283,6 +1283,7 @@ bool VulkanDrawManager::applyMaterial(material* mat, primitive_type prim_type, v
// Like opengl_tnl_set_material(), every material draw sets the texture addressing (e.g. MR_FORCE_CLAMP skyboxes)
setTextureAddressing(mat->get_texture_addressing());
vulkan_zbias(mat->get_depth_bias());
// Build pipeline configuration from material
PipelineConfig config = buildPipelineConfig(mat, prim_type);
@@ -1483,9 +1484,6 @@ bool VulkanDrawManager::applyMaterial(material* mat, primitive_type prim_type, v
stateTracker->setStencilMode(GR_STENCIL_NONE);
}
// Set depth bias if needed
stateTracker->setDepthBias(static_cast<float>(mat->get_depth_bias()), 0.0f);
return true;
}
@@ -1543,7 +1541,7 @@ void VulkanDrawManager::draw(primitive_type prim_type, int first_vertex, int ver
m_frameStats.totalVertices += vertex_count;
// Flush any dirty dynamic state (viewport, scissor, depth bias, stencil ref)
// before issuing the draw command. applyMaterial sets these AFTER bindPipeline,
// before issuing the draw command. applyMaterial sets some of these AFTER bindPipeline,
// so they may be dirty even when the pipeline didn't change.
stateTracker->applyDynamicState();
+2 -2
View File
@@ -351,9 +351,9 @@ void vulkan_zbias(int bias)
if (bias) {
drawManager->setDepthBiasEnabled(true);
if (bias < 0) {
stateTracker->setDepthBias(1.0f, static_cast<float>(-bias));
stateTracker->setDepthBias(static_cast<float>(-bias), 1.0f);
} else {
stateTracker->setDepthBias(0.0f, static_cast<float>(-bias));
stateTracker->setDepthBias(static_cast<float>(-bias), 0.0f);
}
} else {
drawManager->setDepthBiasEnabled(false);
+1 -1
View File
@@ -293,7 +293,7 @@ class VulkanStateTracker {
*
* Must be called before every draw command to ensure dirty dynamic state
* (viewport, scissor, depth bias, stencil ref, line width) is flushed.
* applyMaterial() sets depth bias/stencil AFTER bindPipeline(), so if
* applyMaterial() sets the stencil reference AFTER bindPipeline(), so if
* the pipeline didn't change, those changes would be lost without this.
*/
void applyDynamicState();