From 50bb35b4b44b025633bb513ca9d9da4a509561dd Mon Sep 17 00:00:00 2001 From: Triang3l Date: Wed, 9 Jun 2021 20:46:24 +0300 Subject: [PATCH] [GPU] Polygon offset scale factor in xenos.h --- src/xenia/gpu/d3d12/d3d12_command_processor.cc | 7 ++++--- src/xenia/gpu/d3d12/pipeline_cache.cc | 5 +++-- src/xenia/gpu/draw_util.h | 2 +- src/xenia/gpu/xenos.h | 10 ++++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/xenia/gpu/d3d12/d3d12_command_processor.cc b/src/xenia/gpu/d3d12/d3d12_command_processor.cc index 74646a459..7259efc68 100644 --- a/src/xenia/gpu/d3d12/d3d12_command_processor.cc +++ b/src/xenia/gpu/d3d12/d3d12_command_processor.cc @@ -3241,9 +3241,10 @@ void D3D12CommandProcessor::UpdateSystemConstantValues( poly_offset_back_offset = poly_offset_front_offset; } } - // "slope computed in subpixels ([...] 1/16)" - R5xx Acceleration. - poly_offset_front_scale *= (1.0f / 16.0f) * resolution_scale; - poly_offset_back_scale *= (1.0f / 16.0f) * resolution_scale; + float poly_offset_scale_factor = + xenos::kPolygonOffsetScaleSubpixelUnit * resolution_scale; + poly_offset_front_scale *= poly_offset_scale_factor; + poly_offset_back_scale *= poly_offset_scale_factor; dirty |= system_constants_.edram_poly_offset_front_scale != poly_offset_front_scale; system_constants_.edram_poly_offset_front_scale = poly_offset_front_scale; diff --git a/src/xenia/gpu/d3d12/pipeline_cache.cc b/src/xenia/gpu/d3d12/pipeline_cache.cc index b28369d54..556c7cacf 100644 --- a/src/xenia/gpu/d3d12/pipeline_cache.cc +++ b/src/xenia/gpu/d3d12/pipeline_cache.cc @@ -36,6 +36,7 @@ #include "xenia/gpu/d3d12/d3d12_render_target_cache.h" #include "xenia/gpu/draw_util.h" #include "xenia/gpu/gpu_flags.h" +#include "xenia/gpu/xenos.h" #include "xenia/ui/d3d12/d3d12_util.h" DEFINE_bool(d3d12_dxbc_disasm, false, @@ -1456,7 +1457,7 @@ bool PipelineCache::GetCurrentStateDescription( } } if (!edram_rov_used) { - float poly_offset_host_scale = draw_util::GetD3D10PolygonOffsetScale( + float poly_offset_host_scale = draw_util::GetD3D10PolygonOffsetFactor( regs.Get().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 @@ -1467,7 +1468,7 @@ bool PipelineCache::GetCurrentStateDescription( (poly_offset < 0.0f ? -1 : 1); // "slope computed in subpixels ([...] 1/16)" - R5xx Acceleration. description_out.depth_bias_slope_scaled = - poly_offset_scale * (1.0f / 16.0f); + poly_offset_scale * xenos::kPolygonOffsetScaleSubpixelUnit; } if (tessellated && cvars::d3d12_tessellation_wireframe) { description_out.fill_mode_wireframe = 1; diff --git a/src/xenia/gpu/draw_util.h b/src/xenia/gpu/draw_util.h index 75d3d4053..d23d0d25a 100644 --- a/src/xenia/gpu/draw_util.h +++ b/src/xenia/gpu/draw_util.h @@ -106,7 +106,7 @@ inline reg::RB_DEPTHCONTROL GetDepthControlForCurrentEdramMode( return regs.Get(); } -constexpr float GetD3D10PolygonOffsetScale( +constexpr float GetD3D10PolygonOffsetFactor( xenos::DepthRenderTargetFormat depth_format, bool float24_as_0_to_0_5) { if (depth_format == xenos::DepthRenderTargetFormat::kD24S8) { return float(1 << 24); diff --git a/src/xenia/gpu/xenos.h b/src/xenia/gpu/xenos.h index 97d668513..98fd8741b 100644 --- a/src/xenia/gpu/xenos.h +++ b/src/xenia/gpu/xenos.h @@ -347,6 +347,16 @@ constexpr float UNorm24To32(uint32_t n24) { return float(n24 + (n24 >> 23)) * (1.0f / float(1 << 24)); } +// Scale for conversion of slope scales from PA_SU_POLY_OFFSET_FRONT/BACK_SCALE +// units to those used when the slope is computed from the difference between +// adjacent pixels, for conversion from the guest to common host APIs or to +// calculation using max(|ddx(z)|, |ddy(z)|). +// "slope computed in subpixels (1/12 or 1/16)" - R5xx Acceleration. +// But the correct scale for conversion of the slope scale from subpixels to +// pixels is likely 1/16 according to: +// https://github.com/mesa3d/mesa/blob/54ad9b444c8e73da498211870e785239ad3ff1aa/src/gallium/drivers/radeonsi/si_state.c#L946 +constexpr float kPolygonOffsetScaleSubpixelUnit = 1.0f / 16.0f; + constexpr uint32_t kColorRenderTargetFormatBits = 4; constexpr uint32_t kDepthRenderTargetFormatBits = 1; constexpr uint32_t kRenderTargetFormatBits =