nir: Add lowering for fround_even on r300.

When we put NIR in the compiler stack for r300, indirect addressing broke
for gallium nine.  DX's array indirects round the float value, so the DX
shader gets mapped to a TGSI "ARR ADDR[0] src.x" instruction.  Translating
that to NIR maps to r0[f2i32(fround(src.x))].  While we might hope that in
translation back using nir-to-tgsi after optimization we would recognize
the construct and emit ARR again, that's going to be error prone (think
"what if src.x is in a NIR register?") so we need a fallback plan.  r300
will be able to handle this lowering, so get it in place first to fix the
regression.

Fixes: #6297
Fixes: 7d2ea9b0ed ("r300: Request NIR shaders from mesa/st and use NIR-to-TGSI.")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15870>
This commit is contained in:
Emma Anholt
2022-04-11 16:28:05 -07:00
parent c60fea8c22
commit 6947016b46
3 changed files with 20 additions and 0 deletions

View File

@@ -3286,6 +3286,14 @@ typedef struct nir_shader_compiler_options {
bool lower_ftrunc;
/** Lowers fround_even to ffract+feq+csel.
*
* Not correct in that it doesn't correctly handle the "_even" part of the
* rounding, but good enough for DX9 array indexing handling on DX9-class
* hardware.
*/
bool lower_fround_even;
bool lower_ldexp;
bool lower_pack_half_2x16;

View File

@@ -356,6 +356,14 @@ optimizations.extend([
(('~flrp', a, 0.0, c), ('fadd', ('fmul', ('fneg', a), c), a)),
(('ftrunc', a), ('bcsel', ('flt', a, 0.0), ('fneg', ('ffloor', ('fabs', a))), ('ffloor', ('fabs', a))), 'options->lower_ftrunc'),
# Approximate handling of fround_even for DX9 addressing from gallium nine on
# DX9-class hardware with no proper fround support.
(('fround_even', a), ('bcsel',
('feq', ('ffract', a), 0.5),
('fadd', ('ffloor', ('fadd', a, 0.5)), 1.0),
('ffloor', ('fadd', a, 0.5))), 'options->lower_fround_even'),
(('ffloor', a), ('fsub', a, ('ffract', a)), 'options->lower_ffloor'),
(('fadd', a, ('fneg', ('ffract', a))), ('ffloor', a), '!options->lower_ffloor'),
(('ffract', a), ('fsub', a, ('ffloor', a)), 'options->lower_ffract'),