r300: optimize the load A0 pattern from wined3d

Shader-db

RV530:
total instructions in shared programs: 129701 -> 128733 (-0.75%)
instructions in affected programs: 7011 -> 6043 (-13.81%)
helped: 48
HURT: 0
total loops in shared programs: 15 -> 11 (-26.67%)
loops in affected programs: 4 -> 0
helped: 4
HURT: 0
total temps in shared programs: 16819 -> 16832 (0.08%)
temps in affected programs: 70 -> 83 (18.57%)
helped: 0
HURT: 13
total consts in shared programs: 90830 -> 90813 (-0.02%)
consts in affected programs: 4335 -> 4318 (-0.39%)
helped: 17
HURT: 0

RV370:
total instructions in shared programs: 82027 -> 81215 (-0.99%)
instructions in affected programs: 5456 -> 4644 (-14.88%)
helped: 39
HURT: 0
total temps in shared programs: 12262 -> 12273 (0.09%)
temps in affected programs: 64 -> 75 (17.19%)
helped: 0
HURT: 11
total consts in shared programs: 79119 -> 79104 (-0.02%)
consts in affected programs: 3825 -> 3810 (-0.39%)
helped: 15
HURT: 0
GAINED:5

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9157
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Filip Gawin <filip.gawin@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23560>
This commit is contained in:
Pavel Ondračka
2023-06-09 14:32:47 +02:00
committed by Marge Bot
parent 886a6aa5be
commit a1a981f6c1
3 changed files with 19 additions and 0 deletions
@@ -68,6 +68,8 @@ r300_optimize_nir(struct nir_shader *s, struct pipe_screen *screen)
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_algebraic);
if (s->info.stage == MESA_SHADER_VERTEX)
NIR_PASS(progress, s, r300_nir_fuse_fround_d3d9);
NIR_PASS(progress, s, nir_opt_constant_folding);
NIR_PASS(progress, s, nir_opt_remove_phis);
NIR_PASS(progress, s, nir_opt_conditional_discard);
@@ -32,4 +32,6 @@ extern bool r300_transform_vs_trig_input(struct nir_shader *shader);
extern bool r300_transform_fs_trig_input(struct nir_shader *shader);
extern bool r300_nir_fuse_fround_d3d9(struct nir_shader *shader);
#endif /* R300_NIR_H */
@@ -43,6 +43,19 @@ transform_trig_input_fs_r500 = [
(('fcos', 'a'), ('fcos', ('ffract', ('fmul', 'a', 1 / (2 * pi))))),
]
# The is a pattern produced by wined3d for A0 register load.
# The specific pattern wined3d emits looks like this
# A0.x = (int(floor(abs(R0.x) + 0.5) * sign(R0.x)));
# however we lower both sign and floor so here we check for the already lowered
# sequence.
r300_nir_fuse_fround_d3d9 = [
(('fmul', ('fadd', ('fadd', ('fabs', 'a') , 0.5),
('fneg', ('ffract', ('fadd', ('fabs', 'a') , 0.5)))),
('fadd', ('b2f', ('!flt', 0.0, 'a')),
('fneg', ('b2f', ('!flt', 'a', 0.0))))),
('fround_even', 'a'))
]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--import-path', required=True)
@@ -61,6 +74,8 @@ def main():
f.write(nir_algebraic.AlgebraicPass("r300_transform_fs_trig_input",
transform_trig_input_fs_r500).render())
f.write(nir_algebraic.AlgebraicPass("r300_nir_fuse_fround_d3d9",
r300_nir_fuse_fround_d3d9).render())
if __name__ == '__main__':
main()