From 68bcc0ef5d2954372c93cb8b2801316cdcd79f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 21 Jun 2025 11:21:09 -0400 Subject: [PATCH] radeonsi: add a workaround for gfx10.3-11 corruption with R9G9B9E5_FLOAT Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/drivers/radeonsi/si_state.c | 26 +++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index 78109b6c8a4..9bbec335e62 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -222,8 +222,30 @@ static void si_emit_cb_render_state(struct si_context *sctx, unsigned index) break; case V_028C70_COLOR_5_9_9_9: - if (spi_format == V_028714_SPI_SHADER_FP16_ABGR) - sx_ps_downconvert |= V_028754_SX_RT_EXPORT_9_9_9_E5 << (i * 4); + /* This only executes on GFX10.3+. */ + if (spi_format == V_028714_SPI_SHADER_FP16_ABGR) { + if (sctx->gfx_level >= GFX12) { + sx_ps_downconvert |= V_028754_SX_RT_EXPORT_9_9_9_E5 << (i * 4); + } else { + /* GFX10.3-11 have a bug where R9G9B9E5 is broken with RB+ when the color mask is not + * full or empty. + * + * If A is missing in the color mask, add it. If it's the only bit set, remove it. + */ + if (colormask == BITFIELD_MASK(3)) + cb_target_mask |= BITFIELD_BIT(3) << (i * 4); + else if (colormask == BITFIELD_BIT(3)) + cb_target_mask &= ~(BITFIELD_BIT(3) << (i * 4)); + + colormask = (cb_target_mask >> (i * 4)) & 0xf; + + /* Don't enable RB+ if the color mask is not full or empty, which is done by not + * setting SX_PS_DOWNCONVERT for that MRT. + */ + if (colormask == 0xf || colormask == 0) + sx_ps_downconvert |= V_028754_SX_RT_EXPORT_9_9_9_E5 << (i * 4); + } + } break; } }