st/mesa: don't use redundant stp->state.ir.nir
authorMarek Olšák <marek.olsak@amd.com>
Thu, 21 Nov 2019 00:18:21 +0000 (19:18 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 26 Nov 2019 20:14:10 +0000 (15:14 -0500)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_shader_cache.c

index 27ad14518a1bbdd634497d1c3c0acdbee0b15d3c..9f41a7a3b0b9578de9c7143b0b753e3c9a1f6d77 100644 (file)
@@ -515,18 +515,6 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog,
    }
 }
 
-static void
-set_st_program(struct gl_program *prog,
-               struct gl_shader_program *shader_program,
-               nir_shader *nir)
-{
-   struct st_program *stp = (struct st_program *)prog;
-
-   stp->shader_program = shader_program;
-   stp->state.type = PIPE_SHADER_IR_NIR;
-   stp->state.ir.nir = nir;
-}
-
 static void
 st_nir_vectorize_io(nir_shader *producer, nir_shader *consumer)
 {
@@ -659,16 +647,19 @@ st_link_nir(struct gl_context *ctx,
       const nir_shader_compiler_options *options =
          st->ctx->Const.ShaderCompilerOptions[shader->Stage].NirOptions;
       struct gl_program *prog = shader->Program;
+      struct st_program *stp = (struct st_program *)prog;
+
       _mesa_copy_linked_program_data(shader_program, shader);
 
       assert(!prog->nir);
+      stp->shader_program = shader_program;
+      stp->state.type = PIPE_SHADER_IR_NIR;
 
       if (shader_program->data->spirv) {
          prog->Parameters = _mesa_new_parameter_list();
          /* Parameters will be filled during NIR linking. */
 
          prog->nir = _mesa_spirv_to_nir(ctx, shader_program, shader->Stage, options);
-         set_st_program(prog, shader_program, prog->nir);
       } else {
          validate_ir_tree(shader->ir);
 
@@ -689,7 +680,6 @@ st_link_nir(struct gl_context *ctx,
          _mesa_update_shader_textures_used(shader_program, prog);
 
          prog->nir = glsl_to_nir(st->ctx, shader_program, shader->Stage, options);
-         set_st_program(prog, shader_program, prog->nir);
          st_nir_preprocess(st, prog, shader_program, shader->Stage);
       }
 
index 12061ed91f1072d5710556f0f1af24be97bdb816..53781e6c01e2f8d3fa05964820f37ccc13d45993 100644 (file)
@@ -653,10 +653,9 @@ st_translate_vertex_program(struct st_context *st,
       nir_shader *nir =
          st_translate_prog_to_nir(st, &stp->Base, MESA_SHADER_VERTEX);
 
-      if (stp->state.ir.nir)
-         ralloc_free(stp->state.ir.nir);
+      if (stp->Base.nir)
+         ralloc_free(stp->Base.nir);
       stp->state.type = PIPE_SHADER_IR_NIR;
-      stp->state.ir.nir = nir;
       stp->Base.nir = nir;
       return true;
    }
@@ -690,7 +689,7 @@ st_create_vp_variant(struct st_context *st,
       bool finalize = false;
 
       state.type = PIPE_SHADER_IR_NIR;
-      state.ir.nir = nir_shader_clone(NULL, stvp->state.ir.nir);
+      state.ir.nir = nir_shader_clone(NULL, stvp->Base.nir);
       if (key->clamp_color) {
          NIR_PASS_V(state.ir.nir, nir_lower_clamp_color_outputs);
          finalize = true;
@@ -886,10 +885,9 @@ st_translate_fragment_program(struct st_context *st,
          nir_shader *nir =
             st_translate_prog_to_nir(st, &stfp->Base, MESA_SHADER_FRAGMENT);
 
-         if (stfp->state.ir.nir)
-            ralloc_free(stfp->state.ir.nir);
+         if (stfp->Base.nir)
+            ralloc_free(stfp->Base.nir);
          stfp->state.type = PIPE_SHADER_IR_NIR;
-         stfp->state.ir.nir = nir;
          stfp->Base.nir = nir;
          return true;
       }
@@ -1246,7 +1244,7 @@ st_create_fp_variant(struct st_context *st,
       bool finalize = false;
 
       state.type = PIPE_SHADER_IR_NIR;
-      state.ir.nir = nir_shader_clone(NULL, stfp->state.ir.nir);
+      state.ir.nir = nir_shader_clone(NULL, stfp->Base.nir);
 
       if (key->clamp_color) {
          NIR_PASS_V(state.ir.nir, nir_lower_clamp_color_outputs);
@@ -1770,7 +1768,7 @@ st_get_common_variant(struct st_context *st,
             bool finalize = false;
 
            state.type = PIPE_SHADER_IR_NIR;
-           state.ir.nir = nir_shader_clone(NULL, prog->state.ir.nir);
+           state.ir.nir = nir_shader_clone(NULL, prog->Base.nir);
 
             if (key->clamp_color) {
                NIR_PASS_V(state.ir.nir, nir_lower_clamp_color_outputs);
index 6543a532630b3ce1e61fdb140e4c1fd3b33d67d0..6145281573f7f4ab25c4e367bf7b0b6a61501dcc 100644 (file)
@@ -208,9 +208,8 @@ st_deserialise_ir_program(struct gl_context *ctx,
 
    if (nir) {
       stp->state.type = PIPE_SHADER_IR_NIR;
-      stp->state.ir.nir = nir_deserialize(NULL, options, &blob_reader);
       stp->shader_program = shProg;
-      prog->nir = stp->state.ir.nir;
+      prog->nir = nir_deserialize(NULL, options, &blob_reader);
    } else {
       read_tgsi_from_cache(&blob_reader, &stp->state.tokens);
    }