[GPU] Safer and more correct depth bias conversion

Float24-as-float32 depth bias is now in the increments of 8, because conversion of the depth to float24 directly in the pixel shaders may destroy the bias qualitatively otherwise if it's too small.
This commit is contained in:
Triang3l
2022-06-22 21:14:40 +03:00
parent a7885ae1a4
commit e9f129f67f
2 changed files with 109 additions and 32 deletions

View File

@@ -1435,16 +1435,8 @@ bool PipelineCache::GetCurrentStateDescription(
float polygon_offset, polygon_offset_scale;
draw_util::GetPreferredFacePolygonOffset(
regs, primitive_polygonal, polygon_offset_scale, polygon_offset);
float polygon_offset_host_scale = draw_util::GetD3D10PolygonOffsetFactor(
regs.Get<reg::RB_DEPTH_INFO>().depth_format, true);
// Using ceil here just in case a game wants the offset but passes a value
// that is too small - it's better to apply more offset than to make depth
// fighting worse or to disable the offset completely (Direct3D 12 takes an
// integer value).
description_out.depth_bias =
int32_t(
std::ceil(std::abs(polygon_offset * polygon_offset_host_scale))) *
(polygon_offset < 0.0f ? -1 : 1);
description_out.depth_bias = draw_util::GetD3D10IntegerPolygonOffset(
regs.Get<reg::RB_DEPTH_INFO>().depth_format, polygon_offset);
description_out.depth_bias_slope_scaled =
polygon_offset_scale * xenos::kPolygonOffsetScaleSubpixelUnit;
}