From e4aa5f78897b9ccf7814ef76d041bc37daa46b83 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 11 Apr 2022 17:33:58 -0700 Subject: [PATCH] nir: Skip fround_even on already-integral values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just like the other make-the-float-an-integer opcodes. Noticed in a gallium nine shader run through TGSI-to-NIR, where the array index had been floored by the user, but got implicitly rounded by DX9 array indexing. Reviewed-by: Marek Olšák Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 35f445afd5e..830a5377199 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -357,13 +357,6 @@ 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'), @@ -1385,6 +1378,8 @@ optimizations.extend([ (('ffloor', 'a(is_integral)'), a), (('fceil', 'a(is_integral)'), a), (('ftrunc', 'a(is_integral)'), a), + (('fround_even', 'a(is_integral)'), a), + # fract(x) = x - floor(x), so fract(NaN) = NaN (('~ffract', 'a(is_integral)'), 0.0), (('fabs', 'a(is_not_negative)'), a), @@ -2612,6 +2607,15 @@ late_optimizations = [ (('~flrp', ('fadd(is_used_once)', a, b), ('fadd(is_used_once)', a, c), d), ('fadd', ('flrp', b, c, d), a)), + # Approximate handling of fround_even for DX9 addressing from gallium nine on + # DX9-class hardware with no proper fround support. This is in + # late_optimizations so that the is_integral() opts in the main pass get a + # chance to eliminate the fround_even first. + (('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'), + # A similar operation could apply to any ffma(#a, b, #(-a/2)), but this # particular operation is common for expanding values stored in a texture # from [0,1] to [-1,1].