[Mesa-dev] [PATCH] st/program: fix compute shader nir references

Marek Olšák maraeo at gmail.com
Mon Oct 30 16:19:14 UTC 2017


Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek

On Mon, Oct 30, 2017 at 3:36 PM, Rob Clark <robdclark at gmail.com> wrote:
> In case the IR is NIR, the driver takes reference to the nir_shader.
> Also, because there are no variants, we need to clone the shader,
> instead of sharing the reference with gl_program, which would result
> in a double free in _mesa_delete_program().
>
> Signed-off-by: Rob Clark <robdclark at gmail.com>
> ---
>  src/mesa/state_tracker/st_program.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
> index 335d45ba282..382dd49f980 100644
> --- a/src/mesa/state_tracker/st_program.c
> +++ b/src/mesa/state_tracker/st_program.c
> @@ -360,7 +360,18 @@ st_release_cp_variants(struct st_context *st, struct st_compute_program *stcp)
>     *variants = NULL;
>
>     if (stcp->tgsi.prog) {
> -      ureg_free_tokens(stcp->tgsi.prog);
> +      switch (stcp->tgsi.ir_type) {
> +      case PIPE_SHADER_IR_TGSI:
> +         ureg_free_tokens(stcp->tgsi.prog);
> +         break;
> +      case PIPE_SHADER_IR_NIR:
> +         /* pipe driver took ownership of prog */
> +         break;
> +      case PIPE_SHADER_IR_LLVM:
> +      case PIPE_SHADER_IR_NATIVE:
> +         /* ??? */
> +         break;
> +      }
>        stcp->tgsi.prog = NULL;
>     }
>  }
> @@ -1775,7 +1786,7 @@ st_translate_compute_program(struct st_context *st,
>        st_finalize_nir(st, &stcp->Base, nir);
>
>        stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR;
> -      stcp->tgsi.prog = nir;
> +      stcp->tgsi.prog = nir_shader_clone(NULL, nir);
>
>        return true;
>     }
> --
> 2.13.6
>


More information about the mesa-dev mailing list