diff --git a/src/gallium/drivers/r300/compiler/r300_nir.c b/src/gallium/drivers/r300/compiler/r300_nir.c index e879458ec72..afaaf40a7af 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir.c +++ b/src/gallium/drivers/r300/compiler/r300_nir.c @@ -137,12 +137,12 @@ remove_clip_vertex(nir_builder *b, nir_instr *instr, UNUSED void *_) return false; } -static void -r300_optimize_nir(struct nir_shader *s, struct pipe_screen *screen) +void +r300_optimize_nir(struct nir_shader *s, struct r300_screen *screen) { - bool is_r500 = r300_screen(screen)->caps.is_r500; + bool is_r500 = screen->caps.is_r500; - if (s->info.stage == MESA_SHADER_VERTEX && r300_screen(screen)->caps.has_tcl) { + if (s->info.stage == MESA_SHADER_VERTEX && 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)) { @@ -260,28 +260,3 @@ r300_check_control_flow(nir_shader *s) return NULL; } - -char * -r300_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *s) -{ - r300_optimize_nir(s, pscreen); - - /* st_program.c's parameter list optimization requires that future nir - * variants don't reallocate the uniform storage, so we have to remove - * uniforms that occupy storage. But we don't want to remove samplers, - * because they're needed for YUV variant lowering. - */ - nir_remove_dead_derefs(s); - nir_foreach_uniform_variable_safe (var, s) { - if (var->data.mode == nir_var_uniform && - (glsl_type_get_image_count(var->type) || glsl_type_get_sampler_count(var->type))) - continue; - - exec_node_remove(&var->node); - } - nir_validate_shader(s, "after uniform var removal"); - - nir_sweep(s); - - return NULL; -} diff --git a/src/gallium/drivers/r300/compiler/r300_nir.h b/src/gallium/drivers/r300/compiler/r300_nir.h index 302602279e6..cd971ac796e 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir.h +++ b/src/gallium/drivers/r300/compiler/r300_nir.h @@ -10,6 +10,7 @@ #include "compiler/nir/nir.h" #include "pipe/p_screen.h" +#include "r300_screen.h" static inline bool is_ubo_or_input(UNUSED struct hash_table *ht, const nir_alu_instr *instr, unsigned src, @@ -133,7 +134,7 @@ bool r300_is_only_used_as_float(const nir_alu_instr *instr); char *r300_check_control_flow(nir_shader *s); -char *r300_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *nir); +void r300_optimize_nir(struct nir_shader *s, struct r300_screen *screen); extern bool r300_transform_vs_trig_input(struct nir_shader *shader); diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index f2ae281ecd4..a90a2e20663 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -20,7 +20,6 @@ #include "r300_screen_buffer.h" #include "r300_state_inlines.h" #include "r300_public.h" -#include "compiler/r300_nir.h" #include "draw/draw_context.h" @@ -711,7 +710,6 @@ struct pipe_screen* r300_screen_create(struct radeon_winsys *rws, r300screen->screen.get_name = r300_get_name; r300screen->screen.get_vendor = r300_get_vendor; r300screen->screen.get_compiler_options = r300_get_compiler_options; - r300screen->screen.finalize_nir = r300_finalize_nir; r300screen->screen.get_device_vendor = r300_get_device_vendor; r300screen->screen.get_disk_shader_cache = r300_get_disk_shader_cache; r300screen->screen.get_screen_fd = r300_screen_get_fd; diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 76d98bedaac..1154fa77158 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1033,6 +1033,8 @@ static void* r300_create_fs_state(struct pipe_context* pipe, fs->state = *shader; if (fs->state.type == PIPE_SHADER_IR_NIR) { + r300_optimize_nir(shader->ir.nir, r300->screen); + /* R300/R400 can not do any kind of control flow, so abort early here. */ if (!r300->screen->caps.is_r500) { char *msg = r300_check_control_flow(shader->ir.nir); @@ -1949,6 +1951,8 @@ static void* r300_create_vs_state(struct pipe_context* pipe, vs->state = *shader; if (vs->state.type == PIPE_SHADER_IR_NIR) { + r300_optimize_nir(shader->ir.nir, r300->screen); + /* R300/R400 can not do any kind of control flow, so abort early here. */ if (!r300->screen->caps.is_r500 && r300->screen->caps.has_tcl) { char *msg = r300_check_control_flow(shader->ir.nir);