st/glsl_to_nir: generate NIR earlier
authorTimothy Arceri <tarceri@itsqueeze.com>
Wed, 1 Nov 2017 06:28:09 +0000 (17:28 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 8 Nov 2017 06:33:14 +0000 (17:33 +1100)
We want to use nir_shader_gather_info() the GLSL IR version might
be including varyings that NIR later eliminates. To do this we
need to generate NIR before we we start using the in/out bitmasks.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_program.c

index bbef830a2e652411d251c0583740c025de95612d..d59e47258445bcbbc74796c97cb3884f2ca490c0 100644 (file)
@@ -407,6 +407,7 @@ st_nir_get_mesa_program(struct gl_context *ctx,
                         struct gl_shader_program *shader_program,
                         struct gl_linked_shader *shader)
 {
+   struct st_context *st = st_context(ctx);
    struct gl_program *prog;
 
    validate_ir_tree(shader->ir);
@@ -462,6 +463,11 @@ st_nir_get_mesa_program(struct gl_context *ctx,
       return NULL;
    }
 
+   struct st_common_program *st_comm_prog = (struct st_common_program *)prog;
+   nir_shader *nir = st_glsl_to_nir(st, prog, shader_program, shader->Stage);
+   st_comm_prog->tgsi.type = PIPE_SHADER_IR_NIR;
+   st_comm_prog->tgsi.ir.nir = nir;
+
    return prog;
 }
 
index 25a849bb1833199598421fdcbf1bb600d507b928..e3649a8b7cca03b433ec870b0f9df0d4e2090ee7 100644 (file)
@@ -447,12 +447,6 @@ st_translate_vertex_program(struct st_context *st,
    }
 
    if (stvp->shader_program) {
-      nir_shader *nir = st_glsl_to_nir(st, &stvp->Base, stvp->shader_program,
-                                       MESA_SHADER_VERTEX);
-
-      stvp->tgsi.type = PIPE_SHADER_IR_NIR;
-      stvp->tgsi.ir.nir = nir;
-
       struct gl_program *prog = stvp->shader_program->last_vert_prog;
       if (prog) {
          st_translate_stream_output_info2(prog->sh.LinkedTransformFeedback,
@@ -895,15 +889,9 @@ st_translate_fragment_program(struct st_context *st,
       }
    }
 
-   if (stfp->shader_program) {
-      nir_shader *nir = st_glsl_to_nir(st, &stfp->Base, stfp->shader_program,
-                                       MESA_SHADER_FRAGMENT);
-
-      stfp->tgsi.type = PIPE_SHADER_IR_NIR;
-      stfp->tgsi.ir.nir = nir;
-
+   /* We have already compiler to NIR so just return */
+   if (stfp->shader_program)
       return true;
-   }
 
    ureg = ureg_create_with_screen(PIPE_SHADER_FRAGMENT, st->pipe->screen);
    if (ureg == NULL)
@@ -1681,15 +1669,9 @@ st_translate_tessctrl_program(struct st_context *st,
 {
    struct ureg_program *ureg;
 
-   if (sttcp->shader_program) {
-      nir_shader *nir = st_glsl_to_nir(st, &sttcp->Base, sttcp->shader_program,
-                                       MESA_SHADER_TESS_EVAL);
-
-      sttcp->tgsi.type = PIPE_SHADER_IR_NIR;
-      sttcp->tgsi.ir.nir = nir;
-
+   /* We have already compiler to NIR so just return */
+   if (sttcp->shader_program)
       return true;
-   }
 
    ureg = ureg_create_with_screen(PIPE_SHADER_TESS_CTRL, st->pipe->screen);
    if (ureg == NULL)
@@ -1716,15 +1698,9 @@ st_translate_tesseval_program(struct st_context *st,
 {
    struct ureg_program *ureg;
 
-   if (sttep->shader_program) {
-      nir_shader *nir = st_glsl_to_nir(st, &sttep->Base, sttep->shader_program,
-                                       MESA_SHADER_TESS_EVAL);
-
-      sttep->tgsi.type = PIPE_SHADER_IR_NIR;
-      sttep->tgsi.ir.nir = nir;
-
+   /* We have already compiler to NIR so just return */
+   if (sttep->shader_program)
       return true;
-   }
 
    ureg = ureg_create_with_screen(PIPE_SHADER_TESS_EVAL, st->pipe->screen);
    if (ureg == NULL)
@@ -1770,14 +1746,9 @@ st_translate_compute_program(struct st_context *st,
    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, stcp->shader_program, nir);
-
-      stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR;
-      stcp->tgsi.prog = nir;
+      st_finalize_nir(st, &stcp->Base, stcp->shader_program,
+                      (struct nir_shader *) stcp->tgsi.prog);
 
       return true;
    }