From ec1a00f507354b00e526f2c48bed1fae4dccf1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 12 Nov 2024 14:42:56 -0500 Subject: [PATCH] r300: don't lower sin/cos in finalize_nir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit finalize_nir requires that calling it multiple times on the same shader doesn't break it. RV530 shader-db: total instructions in shared programs: 132915 -> 132851 (-0.05%) instructions in affected programs: 2016 -> 1952 (-3.17%) helped: 16 HURT: 0 total temps in shared programs: 18238 -> 18232 (-0.03%) temps in affected programs: 42 -> 36 (-14.29%) helped: 6 HURT: 0 total cycles in shared programs: 197510 -> 197446 (-0.03%) cycles in affected programs: 2102 -> 2038 (-3.04%) helped: 16 HURT: 0 Reviewed-by: Pavel Ondračka Reviewed-by: Filip Gawin Part-of: --- src/gallium/drivers/r300/compiler/nir_to_rc.c | 20 ++++++++ src/gallium/drivers/r300/compiler/r300_nir.c | 48 ++++++------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/gallium/drivers/r300/compiler/nir_to_rc.c b/src/gallium/drivers/r300/compiler/nir_to_rc.c index b3de9a3253c..445987b7070 100644 --- a/src/gallium/drivers/r300/compiler/nir_to_rc.c +++ b/src/gallium/drivers/r300/compiler/nir_to_rc.c @@ -2257,6 +2257,26 @@ nir_to_rc(struct nir_shader *s, struct pipe_screen *screen) c->screen = screen; c->lower_fabs = !is_r500 && s->info.stage == MESA_SHADER_VERTEX; + if (s->info.stage == MESA_SHADER_FRAGMENT) { + if (is_r500) { + NIR_PASS_V(s, r300_transform_fs_trig_input); + } + } else if (r300_screen(screen)->caps.has_tcl) { + if (is_r500) { + /* Only nine should set both NTT shader name and + * use_legacy_math_rules and D3D9 already mandates + * the proper range for the trigonometric inputs. + */ + if (!s->info.use_legacy_math_rules || !(s->info.name && !strcmp("TTN", s->info.name))) { + NIR_PASS_V(s, r300_transform_vs_trig_input); + } + } else { + if (r300_screen(screen)->caps.is_r400) { + NIR_PASS_V(s, r300_transform_vs_trig_input); + } + } + } + /* Lower array indexing on FS inputs. Since we don't set * ureg->supports_any_inout_decl_range, the TGSI input decls will be split to * elements by ureg, and so dynamically indexing them would be invalid. diff --git a/src/gallium/drivers/r300/compiler/r300_nir.c b/src/gallium/drivers/r300/compiler/r300_nir.c index 8a79f1e1d74..31bde7911e6 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir.c +++ b/src/gallium/drivers/r300/compiler/r300_nir.c @@ -143,44 +143,24 @@ r300_optimize_nir(struct nir_shader *s, struct pipe_screen *screen) bool is_r500 = r300_screen(screen)->caps.is_r500; bool progress; - if (s->info.stage == MESA_SHADER_FRAGMENT) { - if (is_r500) { - NIR_PASS_V(s, r300_transform_fs_trig_input); - } - } else { - if (r300_screen(screen)->caps.has_tcl) { - if (r300_screen(screen)->caps.is_r500) { - /* Only nine should set both NTT shader name and - * use_legacy_math_rules and D3D9 already mandates - * the proper range for the trigonometric inputs. - */ - if (!s->info.use_legacy_math_rules || !(s->info.name && !strcmp("TTN", s->info.name))) { - NIR_PASS_V(s, r300_transform_vs_trig_input); - } - } else { - if (r300_screen(screen)->caps.is_r400) { - NIR_PASS_V(s, r300_transform_vs_trig_input); + if (s->info.stage == MESA_SHADER_VERTEX && r300_screen(screen)->caps.has_tcl) { + /* There is no HW support for gl_ClipVertex, so we just remove it early. */ + if (nir_shader_instructions_pass(s, remove_clip_vertex, + nir_metadata_control_flow, NULL)) { + unsigned clip_vertex_location = 0; + nir_foreach_variable_with_modes(var, s, nir_var_shader_out) { + if (var->data.location == VARYING_SLOT_CLIP_VERTEX) { + clip_vertex_location = var->data.driver_location; } } - - /* There is no HW support for gl_ClipVertex, so we just remove it early. */ - if (nir_shader_instructions_pass(s, remove_clip_vertex, - nir_metadata_control_flow, NULL)) { - unsigned clip_vertex_location = 0; - nir_foreach_variable_with_modes(var, s, nir_var_shader_out) { - if (var->data.location == VARYING_SLOT_CLIP_VERTEX) { - clip_vertex_location = var->data.driver_location; - } + nir_foreach_variable_with_modes(var, s, nir_var_shader_out) { + if (var->data.driver_location > clip_vertex_location) { + var->data.driver_location--; } - nir_foreach_variable_with_modes(var, s, nir_var_shader_out) { - if (var->data.driver_location > clip_vertex_location) { - var->data.driver_location--; - } - } - NIR_PASS_V(s, nir_remove_dead_variables, nir_var_shader_out, NULL); - fprintf(stderr, "r300: no HW support for clip vertex, expect misrendering.\n"); - fprintf(stderr, "r300: software emulation can be enabled with RADEON_DEBUG=notcl.\n"); } + NIR_PASS_V(s, nir_remove_dead_variables, nir_var_shader_out, NULL); + fprintf(stderr, "r300: no HW support for clip vertex, expect misrendering.\n"); + fprintf(stderr, "r300: software emulation can be enabled with RADEON_DEBUG=notcl.\n"); } }