diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c b/src/gallium/auxiliary/draw/draw_vs_exec.c index 95e2e96693c..12904f995de 100644 --- a/src/gallium/auxiliary/draw/draw_vs_exec.c +++ b/src/gallium/auxiliary/draw/draw_vs_exec.c @@ -227,7 +227,6 @@ draw_create_vs_exec(struct draw_context *draw, if (state->type == PIPE_SHADER_IR_NIR) { vs->base.state.type = PIPE_SHADER_IR_TGSI; vs->base.state.tokens = nir_to_tgsi(state->ir.nir, draw->pipe->screen); - ralloc_free(state->ir.nir); } else { assert(state->type == PIPE_SHADER_IR_TGSI); vs->base.state.type = state->type; diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c index 5b3760ea059..9384406d7ca 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.c +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c @@ -2539,8 +2539,8 @@ ntt_fix_nir_options(struct nir_shader *s) !options->lower_rotate || !options->lower_uniforms_to_ubo || !options->lower_vector_cmp) { - struct nir_shader_compiler_options *new_options = - mem_dup(s->options, sizeof(*s->options)); + nir_shader_compiler_options *new_options = ralloc(s, nir_shader_compiler_options); + *new_options = *s->options; new_options->lower_extract_byte = true; new_options->lower_extract_word = true; @@ -2555,6 +2555,13 @@ ntt_fix_nir_options(struct nir_shader *s) } } +/** + * Translates the NIR shader to TGSI. + * + * This requires some lowering of the NIR shader to prepare it for translation. + * We take ownership of the NIR shader passed, returning a reference to the new + * TGSI tokens instead. If you need to keep the NIR, then pass us a clone. + */ const void * nir_to_tgsi(struct nir_shader *s, struct pipe_screen *screen) @@ -2688,11 +2695,7 @@ nir_to_tgsi(struct nir_shader *s, ureg_destroy(c->ureg); ralloc_free(c); - - if (s->options != original_options) { - free((void*)s->options); - s->options = original_options; - } + ralloc_free(s); return tgsi_tokens; } diff --git a/src/gallium/drivers/softpipe/sp_state_shader.c b/src/gallium/drivers/softpipe/sp_state_shader.c index 9fa2fdc061a..3a7b083e5a6 100644 --- a/src/gallium/drivers/softpipe/sp_state_shader.c +++ b/src/gallium/drivers/softpipe/sp_state_shader.c @@ -143,15 +143,10 @@ softpipe_create_shader_state(struct pipe_context *pipe, bool debug) { if (templ->type == PIPE_SHADER_IR_NIR) { - shader->tokens = nir_to_tgsi(templ->ir.nir, pipe->screen); - - /* Note: Printing the final NIR after nir-to-tgsi transformed and - * optimized it - */ if (debug) nir_print_shader(templ->ir.nir, stderr); - ralloc_free(templ->ir.nir); + shader->tokens = nir_to_tgsi(templ->ir.nir, pipe->screen); } else { assert(templ->type == PIPE_SHADER_IR_TGSI); /* we need to keep a local copy of the tokens */ @@ -433,7 +428,6 @@ softpipe_create_compute_state(struct pipe_context *pipe, nir_print_shader(s, stderr); state->tokens = (void *)nir_to_tgsi(s, pipe->screen); - ralloc_free(s); } else { assert(templ->ir_type == PIPE_SHADER_IR_TGSI); /* we need to keep a local copy of the tokens */ diff --git a/src/mesa/state_tracker/st_nir_builtins.c b/src/mesa/state_tracker/st_nir_builtins.c index cdeb5a0cd88..a5279dbc2af 100644 --- a/src/mesa/state_tracker/st_nir_builtins.c +++ b/src/mesa/state_tracker/st_nir_builtins.c @@ -79,7 +79,6 @@ st_nir_finish_builtin_shader(struct st_context *st, screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_PREFERRED_IR)) { state.type = PIPE_SHADER_IR_TGSI; state.tokens = nir_to_tgsi(nir, screen); - ralloc_free(nir); } struct pipe_shader_state *shader; diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 7b8d27cf101..07bb8d8436e 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -730,6 +730,7 @@ st_create_vp_variant(struct st_context *st, nir_print_shader(state.ir.nir, stderr); /* If the driver wants TGSI, then translate before handing off. */ + if (st->pipe->screen->get_shader_param(st->pipe->screen, PIPE_SHADER_VERTEX, PIPE_SHADER_CAP_PREFERRED_IR) != @@ -737,7 +738,6 @@ st_create_vp_variant(struct st_context *st, nir_shader *s = state.ir.nir; state.tokens = nir_to_tgsi(s, st->pipe->screen); state.type = PIPE_SHADER_IR_TGSI; - ralloc_free(s); } if (key->is_draw_shader) @@ -1348,7 +1348,6 @@ st_create_fp_variant(struct st_context *st, nir_shader *s = state.ir.nir; state.tokens = nir_to_tgsi(s, st->pipe->screen); state.type = PIPE_SHADER_IR_TGSI; - ralloc_free(s); } variant->base.driver_shader = pipe->create_fs_state(pipe, &state);