diff --git a/src/gallium/auxiliary/driver_ddebug/dd_screen.c b/src/gallium/auxiliary/driver_ddebug/dd_screen.c index 8a1bbc39d71..735f9cf5a53 100644 --- a/src/gallium/auxiliary/driver_ddebug/dd_screen.c +++ b/src/gallium/auxiliary/driver_ddebug/dd_screen.c @@ -455,11 +455,12 @@ dd_screen_semaphore_create(struct pipe_screen *_screen) */ static void -dd_screen_finalize_nir(struct pipe_screen *_screen, struct nir_shader *nir) +dd_screen_finalize_nir(struct pipe_screen *_screen, struct nir_shader *nir, + bool optimize) { struct pipe_screen *screen = dd_screen(_screen)->screen; - screen->finalize_nir(screen, nir); + screen->finalize_nir(screen, nir, optimize); } static void diff --git a/src/gallium/auxiliary/driver_noop/noop_pipe.c b/src/gallium/auxiliary/driver_noop/noop_pipe.c index 79691bda13a..44fba86386c 100644 --- a/src/gallium/auxiliary/driver_noop/noop_pipe.c +++ b/src/gallium/auxiliary/driver_noop/noop_pipe.c @@ -578,11 +578,12 @@ static struct disk_cache *noop_get_disk_shader_cache(struct pipe_screen *pscreen return screen->get_disk_shader_cache(screen); } -static void noop_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *nir) +static void noop_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *nir, + bool optimize) { struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen; - screen->finalize_nir(screen, nir); + screen->finalize_nir(screen, nir, optimize); } static bool noop_check_resource_capability(struct pipe_screen *screen, diff --git a/src/gallium/auxiliary/driver_trace/tr_screen.c b/src/gallium/auxiliary/driver_trace/tr_screen.c index 4e4dd203221..7f41c0d2924 100644 --- a/src/gallium/auxiliary/driver_trace/tr_screen.c +++ b/src/gallium/auxiliary/driver_trace/tr_screen.c @@ -1070,11 +1070,12 @@ trace_screen_get_timestamp(struct pipe_screen *_screen) } static void -trace_screen_finalize_nir(struct pipe_screen *_screen, struct nir_shader *nir) +trace_screen_finalize_nir(struct pipe_screen *_screen, struct nir_shader *nir, + bool optimize) { struct pipe_screen *screen = trace_screen(_screen)->screen; - screen->finalize_nir(screen, nir); + screen->finalize_nir(screen, nir, optimize); } static void diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c index a98717225e8..c851d81c8fd 100644 --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c @@ -2564,7 +2564,7 @@ ttn_finalize_nir(struct ttn_compile *c, struct pipe_screen *screen) NIR_PASS(_, nir, nir_lower_samplers); if (screen->finalize_nir) { - screen->finalize_nir(screen, nir); + screen->finalize_nir(screen, nir, true); } else { ttn_optimize_nir(nir); } diff --git a/src/gallium/auxiliary/vl/vl_compositor_cs.c b/src/gallium/auxiliary/vl/vl_compositor_cs.c index 4ea4ff93ff5..ca50a410248 100644 --- a/src/gallium/auxiliary/vl/vl_compositor_cs.c +++ b/src/gallium/auxiliary/vl/vl_compositor_cs.c @@ -143,7 +143,7 @@ static nir_def *cs_create_shader(struct vl_compositor *c, struct cs_shader *s) static void *cs_create_shader_state(struct vl_compositor *c, struct cs_shader *s) { - c->pipe->screen->finalize_nir(c->pipe->screen, s->b.shader); + c->pipe->screen->finalize_nir(c->pipe->screen, s->b.shader, true); struct pipe_compute_state state = {0}; state.ir_type = PIPE_SHADER_IR_NIR; diff --git a/src/gallium/auxiliary/vl/vl_deint_filter_cs.c b/src/gallium/auxiliary/vl/vl_deint_filter_cs.c index 4291ccba614..aa94386ff29 100644 --- a/src/gallium/auxiliary/vl/vl_deint_filter_cs.c +++ b/src/gallium/auxiliary/vl/vl_deint_filter_cs.c @@ -126,7 +126,8 @@ create_deint_shader(struct vl_deint_filter *filter, unsigned field) } nir_pop_if(&b, if_curr_field); - filter->pipe->screen->finalize_nir(filter->pipe->screen, b.shader); + filter->pipe->screen->finalize_nir(filter->pipe->screen, b.shader, + true); struct pipe_compute_state state = { .ir_type = PIPE_SHADER_IR_NIR, diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c index 81bfa6b43d4..f550b62c1f6 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c @@ -481,7 +481,8 @@ ir3_fixup_shader_state(struct pipe_context *pctx, struct ir3_shader_key *key) } static void -ir3_screen_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *nir) +ir3_screen_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *nir, + bool optimize) { struct fd_screen *screen = fd_screen(pscreen); diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c index 909c3d612a4..31f24f642e7 100644 --- a/src/gallium/drivers/i915/i915_screen.c +++ b/src/gallium/drivers/i915/i915_screen.c @@ -225,7 +225,8 @@ i915_optimize_nir(struct nir_shader *s) } static void -i915_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *s) +i915_finalize_nir(struct pipe_screen *pscreen, struct nir_shader *s, + bool optimize) { if (s->info.stage == MESA_SHADER_FRAGMENT) i915_optimize_nir(s); diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index 4d728eb846b..57a2b77a516 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -3835,7 +3835,8 @@ iris_bind_cs_state(struct pipe_context *ctx, void *state) } static void -iris_finalize_nir(struct pipe_screen *_screen, struct nir_shader *nir) +iris_finalize_nir(struct pipe_screen *_screen, struct nir_shader *nir, + bool optimize) { struct iris_screen *screen = (struct iris_screen *)_screen; diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index f00c57e0728..b644e1d0c58 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -498,7 +498,7 @@ static const struct nir_shader_compiler_options gallivm_nir_options = { static void llvmpipe_finalize_nir(struct pipe_screen *screen, - struct nir_shader *nir) + struct nir_shader *nir, bool optimize) { lp_build_opt_nir(nir); } diff --git a/src/gallium/drivers/r600/r600_sfn.cpp b/src/gallium/drivers/r600/r600_sfn.cpp index 0fa85fbdbc3..b87569ed90e 100644 --- a/src/gallium/drivers/r600/r600_sfn.cpp +++ b/src/gallium/drivers/r600/r600_sfn.cpp @@ -25,7 +25,7 @@ #include void -r600_finalize_nir(pipe_screen *screen, struct nir_shader *nir) +r600_finalize_nir(pipe_screen *screen, struct nir_shader *nir, bool optimize) { auto rs = container_of(screen, r600_screen, b.b); r600_finalize_nir_common(nir, rs->b.gfx_level); diff --git a/src/gallium/drivers/r600/r600_sfn.h b/src/gallium/drivers/r600/r600_sfn.h index 097730b8a2c..17349813ca5 100644 --- a/src/gallium/drivers/r600/r600_sfn.h +++ b/src/gallium/drivers/r600/r600_sfn.h @@ -16,7 +16,7 @@ extern "C" { #endif void -r600_finalize_nir(struct pipe_screen *screen, struct nir_shader *nir); +r600_finalize_nir(struct pipe_screen *screen, struct nir_shader *nir, bool optimize); int r600_shader_from_nir(struct r600_context *rctx, diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h index 7534ef42e0e..4fd55b90eb6 100644 --- a/src/gallium/drivers/radeonsi/si_shader.h +++ b/src/gallium/drivers/radeonsi/si_shader.h @@ -923,7 +923,8 @@ void si_lower_mediump_io_option(struct nir_shader *nir); bool si_alu_to_scalar_packed_math_filter(const struct nir_instr *instr, const void *data); void si_nir_opts(struct si_screen *sscreen, struct nir_shader *nir, bool has_array_temps); void si_nir_late_opts(struct nir_shader *nir); -void si_finalize_nir(struct pipe_screen *screen, struct nir_shader *nir); +void si_finalize_nir(struct pipe_screen *screen, struct nir_shader *nir, + bool optimize); /* si_state_shaders.cpp */ unsigned si_shader_num_alloc_param_exports(struct si_shader *shader); diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c index 1b68e4b2828..63582dd265f 100644 --- a/src/gallium/drivers/radeonsi/si_shader_nir.c +++ b/src/gallium/drivers/radeonsi/si_shader_nir.c @@ -389,7 +389,8 @@ static void si_lower_nir(struct si_screen *sscreen, struct nir_shader *nir) NIR_PASS(_, nir, nir_lower_fp16_casts, nir_lower_fp16_split_fp64); } -void si_finalize_nir(struct pipe_screen *screen, struct nir_shader *nir) +void si_finalize_nir(struct pipe_screen *screen, struct nir_shader *nir, + bool optimize) { struct si_screen *sscreen = (struct si_screen *)screen; diff --git a/src/gallium/drivers/radeonsi/si_shaderlib_nir.c b/src/gallium/drivers/radeonsi/si_shaderlib_nir.c index 2335837fc62..ad8bea93113 100644 --- a/src/gallium/drivers/radeonsi/si_shaderlib_nir.c +++ b/src/gallium/drivers/radeonsi/si_shaderlib_nir.c @@ -27,7 +27,7 @@ void *si_create_shader_state(struct si_context *sctx, nir_shader *nir) blob_finish(&blob); } - sctx->b.screen->finalize_nir(sctx->b.screen, nir); + sctx->b.screen->finalize_nir(sctx->b.screen, nir, true); return pipe_shader_from_nir(&sctx->b, nir); } diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 9882ec7aaaf..7e79e6df30a 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -6373,7 +6373,7 @@ zink_shader_init(struct zink_screen *screen, struct zink_shader *zs) } void -zink_shader_finalize(struct pipe_screen *pscreen, struct nir_shader *nir) +zink_shader_finalize(struct pipe_screen *pscreen, struct nir_shader *nir, bool optimize) { struct zink_screen *screen = zink_screen(pscreen); diff --git a/src/gallium/drivers/zink/zink_compiler.h b/src/gallium/drivers/zink/zink_compiler.h index 5830046bef5..28112e2561a 100644 --- a/src/gallium/drivers/zink/zink_compiler.h +++ b/src/gallium/drivers/zink/zink_compiler.h @@ -74,7 +74,7 @@ void zink_shader_init(struct zink_screen *screen, struct zink_shader *zs); void -zink_shader_finalize(struct pipe_screen *pscreen, struct nir_shader *nir); +zink_shader_finalize(struct pipe_screen *pscreen, struct nir_shader *nir, bool optimize); void zink_shader_free(struct zink_screen *screen, struct zink_shader *shader); diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c b/src/gallium/frontends/lavapipe/lvp_pipeline.c index 71dea2949aa..1638fcfa962 100644 --- a/src/gallium/frontends/lavapipe/lvp_pipeline.c +++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c @@ -617,7 +617,7 @@ void * lvp_shader_compile(struct lvp_device *device, struct lvp_shader *shader, nir_shader *nir, bool locked) { const struct lvp_physical_device *pdev = lvp_device_physical(device); - pdev->pscreen->finalize_nir(pdev->pscreen, nir); + pdev->pscreen->finalize_nir(pdev->pscreen, nir, true); if (!locked) simple_mtx_lock(&device->queue.lock); diff --git a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs index c4a3063bea5..3527ba6ed69 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs @@ -511,7 +511,7 @@ impl PipeScreen { pub fn finalize_nir(&self, nir: &NirShader) -> bool { if let Some(func) = self.screen().finalize_nir { unsafe { - func(self.pipe(), nir.get_nir().cast()); + func(self.pipe(), nir.get_nir().cast(), true); } true } else { diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 9b1676b0889..79cf3c4f745 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -613,8 +613,11 @@ struct pipe_screen { * * gallium frontends should call this before passing shaders to drivers, * and ideally also before shader caching. + * + * \param optimize If false, the driver doesn't have to optimize NIR. */ - void (*finalize_nir)(struct pipe_screen *screen, struct nir_shader *nir); + void (*finalize_nir)(struct pipe_screen *screen, struct nir_shader *nir, + bool optimize); /*Separated memory/resource allocations interfaces for Vulkan */ diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 41cfa47e4a6..6f8198bda6e 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -370,7 +370,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog, st_finalize_nir(st, prog, shader_program, nir, true, false); if (screen->finalize_nir) - screen->finalize_nir(screen, nir); + screen->finalize_nir(screen, nir, false); } if (st->ctx->_Shader->Flags & GLSL_DUMP) { diff --git a/src/mesa/state_tracker/st_nir_builtins.c b/src/mesa/state_tracker/st_nir_builtins.c index dcd60098922..9dfea3a8651 100644 --- a/src/mesa/state_tracker/st_nir_builtins.c +++ b/src/mesa/state_tracker/st_nir_builtins.c @@ -69,7 +69,7 @@ st_nir_finish_builtin_nir(struct st_context *st, nir_shader *nir) } if (screen->finalize_nir) { - screen->finalize_nir(screen, nir); + screen->finalize_nir(screen, nir, true); } else { gl_nir_opts(nir); } diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 3b4d26dd074..8332f3fb049 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -400,7 +400,7 @@ st_prog_to_nir_postprocess(struct st_context *st, nir_shader *nir, st_finalize_nir(st, prog, NULL, nir, true, false); if (screen->finalize_nir) - screen->finalize_nir(screen, nir); + screen->finalize_nir(screen, nir, false); } nir_validate_shader(nir, "after st/glsl finalize_nir"); @@ -887,7 +887,7 @@ st_create_common_variant(struct st_context *st, if (finalize || !st->allow_st_finalize_nir_twice || key->is_draw_shader) { struct pipe_screen *screen = st->screen; if (!key->is_draw_shader && screen->finalize_nir) - screen->finalize_nir(screen, state.ir.nir); + screen->finalize_nir(screen, state.ir.nir, false); /* Clip lowering and edgeflags may have introduced new varyings, so * update the inputs_read/outputs_written. However, with @@ -1268,7 +1268,7 @@ st_create_fp_variant(struct st_context *st, struct pipe_screen *screen = st->screen; if (screen->finalize_nir) - screen->finalize_nir(screen, state.ir.nir); + screen->finalize_nir(screen, state.ir.nir, false); } variant->base.driver_shader = st_create_nir_shader(st, &state);