[Mesa-dev] [PATCH 1/2] st/glsl_to_nir: pass gl_shader_program to st_finalize_nir()

Timothy Arceri tarceri at itsqueeze.com
Wed Nov 1 05:20:36 UTC 2017


---
 src/mesa/state_tracker/st_glsl_to_nir.cpp | 24 ++----------------------
 src/mesa/state_tracker/st_nir.h           |  4 +++-
 src/mesa/state_tracker/st_program.c       | 10 ++++++----
 3 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index e9a8d6414e..5b37d2cd63 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -313,21 +313,22 @@ sort_varyings(struct exec_list *var_list)
       exec_node_remove(&var->node);
       insert_sorted(&new_list, var);
    }
    exec_list_move_nodes_to(&new_list, var_list);
 }
 
 /* Second half of preparing nir from glsl, which happens after shader
  * variant lowering.
  */
 void
-st_finalize_nir(struct st_context *st, struct gl_program *prog, nir_shader *nir)
+st_finalize_nir(struct st_context *st, struct gl_program *prog,
+                struct gl_shader_program *shader_program, nir_shader *nir)
 {
    struct pipe_screen *screen = st->pipe->screen;
 
    NIR_PASS_V(nir, nir_split_var_copies);
    NIR_PASS_V(nir, nir_lower_var_copies);
    NIR_PASS_V(nir, nir_lower_io_types);
 
    if (nir->info.stage == MESA_SHADER_VERTEX) {
       /* Needs special handling so drvloc matches the vbo state: */
       st_nir_assign_vs_in_locations(prog, nir);
@@ -347,41 +348,20 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, nir_shader *nir)
       st_nir_fixup_varying_slots(st, &nir->inputs);
       nir_assign_var_locations(&nir->outputs,
                                &nir->num_outputs,
                                type_size);
    } else if (nir->info.stage == MESA_SHADER_COMPUTE) {
        /* TODO? */
    } else {
       unreachable("invalid shader type for tgsi bypass\n");
    }
 
-   struct gl_shader_program *shader_program;
-   switch (nir->info.stage) {
-   case MESA_SHADER_VERTEX:
-      shader_program = ((struct st_vertex_program *)prog)->shader_program;
-      break;
-   case MESA_SHADER_GEOMETRY:
-   case MESA_SHADER_TESS_CTRL:
-   case MESA_SHADER_TESS_EVAL:
-      shader_program = ((struct st_common_program *)prog)->shader_program;
-      break;
-   case MESA_SHADER_FRAGMENT:
-      shader_program = ((struct st_fragment_program *)prog)->shader_program;
-      break;
-   case MESA_SHADER_COMPUTE:
-      shader_program = ((struct st_compute_program *)prog)->shader_program;
-      break;
-   default:
-      assert(!"should not be reached");
-      return;
-   }
-
    NIR_PASS_V(nir, nir_lower_atomics_to_ssbo,
          st->ctx->Const.Program[nir->info.stage].MaxAtomicBuffers);
 
    st_nir_assign_uniform_locations(prog, shader_program,
                                    &nir->uniforms, &nir->num_uniforms);
 
    NIR_PASS_V(nir, nir_lower_system_values);
 
    if (screen->get_param(screen, PIPE_CAP_NIR_SAMPLERS_AS_DEREF))
       NIR_PASS_V(nir, nir_lower_samplers_as_deref, shader_program);
diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h
index 28d375c6fd..9302a7c786 100644
--- a/src/mesa/state_tracker/st_nir.h
+++ b/src/mesa/state_tracker/st_nir.h
@@ -34,21 +34,23 @@ extern "C" {
 struct nir_shader;
 
 void st_nir_lower_builtin(struct nir_shader *shader);
 void st_nir_lower_tex_src_plane(struct nir_shader *shader, unsigned free_slots,
                                 unsigned lower_2plane, unsigned lower_3plane);
 
 struct nir_shader * st_glsl_to_nir(struct st_context *st, struct gl_program *prog,
                                    struct gl_shader_program *shader_program,
                                    gl_shader_stage stage);
 
-void st_finalize_nir(struct st_context *st, struct gl_program *prog, struct nir_shader *nir);
+void st_finalize_nir(struct st_context *st, struct gl_program *prog,
+                     struct gl_shader_program *shader_program,
+                     struct nir_shader *nir);
 
 struct gl_program *
 st_nir_get_mesa_program(struct gl_context *ctx,
                         struct gl_shader_program *shader_program,
                         struct gl_linked_shader *shader);
 
 #ifdef __cplusplus
 }
 #endif
 
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 335d45ba28..25a849bb18 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -555,21 +555,22 @@ st_create_vp_variant(struct st_context *st,
    if (stvp->tgsi.type == PIPE_SHADER_IR_NIR) {
       vpv->tgsi.type = PIPE_SHADER_IR_NIR;
       vpv->tgsi.ir.nir = nir_shader_clone(NULL, stvp->tgsi.ir.nir);
       if (key->clamp_color)
          NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_clamp_color_outputs);
       if (key->passthrough_edgeflags) {
          NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_passthrough_edgeflags);
          vpv->num_inputs++;
       }
 
-      st_finalize_nir(st, &stvp->Base, vpv->tgsi.ir.nir);
+      st_finalize_nir(st, &stvp->Base, stvp->shader_program,
+                      vpv->tgsi.ir.nir);
 
       vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi);
       /* driver takes ownership of IR: */
       vpv->tgsi.ir.nir = NULL;
       return vpv;
    }
 
    vpv->tgsi.tokens = tgsi_dup_tokens(stvp->tgsi.tokens);
 
    /* Emulate features. */
@@ -1081,21 +1082,21 @@ st_create_fp_variant(struct st_context *st,
          NIR_PASS_V(tgsi.ir.nir, nir_lower_drawpixels, &options);
       }
 
       if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
          nir_lower_tex_options options = {0};
          options.lower_y_uv_external = key->external.lower_nv12;
          options.lower_y_u_v_external = key->external.lower_iyuv;
          NIR_PASS_V(tgsi.ir.nir, nir_lower_tex, &options);
       }
 
-      st_finalize_nir(st, &stfp->Base, tgsi.ir.nir);
+      st_finalize_nir(st, &stfp->Base, stfp->shader_program, tgsi.ir.nir);
 
       if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
          /* This pass needs to happen *after* nir_lower_sampler */
          NIR_PASS_V(tgsi.ir.nir, st_nir_lower_tex_src_plane,
                     ~stfp->Base.SamplersUsed,
                     key->external.lower_nv12,
                     key->external.lower_iyuv);
       }
 
       variant->driver_shader = pipe->create_fs_state(pipe, &tgsi);
@@ -1631,21 +1632,22 @@ st_get_basic_variant(struct st_context *st,
    }
 
    if (!v) {
       /* create new */
       v = CALLOC_STRUCT(st_basic_variant);
       if (v) {
 
 	 if (prog->tgsi.type == PIPE_SHADER_IR_NIR) {
 	    tgsi.type = PIPE_SHADER_IR_NIR;
 	    tgsi.ir.nir = nir_shader_clone(NULL, prog->tgsi.ir.nir);
-	    st_finalize_nir(st, &prog->Base, tgsi.ir.nir);
+	    st_finalize_nir(st, &prog->Base, prog->shader_program,
+                            tgsi.ir.nir);
 	 } else
 	    tgsi = prog->tgsi;
          /* fill in new variant */
          switch (pipe_shader) {
          case PIPE_SHADER_TESS_CTRL:
             v->driver_shader = pipe->create_tcs_state(pipe, &tgsi);
             break;
          case PIPE_SHADER_TESS_EVAL:
             v->driver_shader = pipe->create_tes_state(pipe, &tgsi);
             break;
@@ -1765,21 +1767,21 @@ st_translate_compute_program(struct st_context *st,
                              struct st_compute_program *stcp)
 {
    struct ureg_program *ureg;
    struct pipe_shader_state prog;
 
    if (stcp->shader_program) {
       nir_shader *nir = st_glsl_to_nir(st, &stcp->Base, stcp->shader_program,
                                        MESA_SHADER_COMPUTE);
 
       /* no compute variants: */
-      st_finalize_nir(st, &stcp->Base, nir);
+      st_finalize_nir(st, &stcp->Base, stcp->shader_program, nir);
 
       stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR;
       stcp->tgsi.prog = nir;
 
       return true;
    }
 
    ureg = ureg_create_with_screen(PIPE_SHADER_COMPUTE, st->pipe->screen);
    if (ureg == NULL)
       return false;
-- 
2.14.3



More information about the mesa-dev mailing list