[Mesa-dev] [PATCH 03/14] st/glsl: move nir linking loop to new function st_link_nir()

Timothy Arceri tarceri at itsqueeze.com
Tue Nov 21 03:37:24 UTC 2017


This will allow us to refactor linking and include some nir link
time optimisations.
---
 src/mesa/state_tracker/st_glsl_to_nir.cpp  | 25 +++++++++++++++++++++++++
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 26 +++++++++++++-------------
 src/mesa/state_tracker/st_nir.h            |  7 +++----
 3 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index d0375dd3aa..8b66f8277a 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -501,11 +501,36 @@ st_nir_get_mesa_program(struct gl_context *ctx,
       break;
    default:
       assert(!"should not be reached");
       return NULL;
    }
 
 
    return prog;
 }
 
+bool
+st_link_nir(struct gl_context *ctx,
+            struct gl_shader_program *shader_program)
+{
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      struct gl_linked_shader *shader = shader_program->_LinkedShaders[i];
+      if (shader == NULL)
+         continue;
+
+      struct gl_program *linked_prog =
+         st_nir_get_mesa_program(ctx, shader_program, shader);
+
+      if (linked_prog) {
+         if (!ctx->Driver.ProgramStringNotify(ctx,
+                                              _mesa_shader_stage_to_program(i),
+                                              linked_prog)) {
+            _mesa_reference_program(ctx, &shader->Program, NULL);
+            return false;
+         }
+      }
+   }
+
+   return true;
+}
+
 } /* extern "C" */
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 0772b73627..4fc1533e28 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6894,39 +6894,46 @@ GLboolean
 st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 {
    /* Return early if we are loading the shader from on-disk cache */
    if (st_load_tgsi_from_disk_cache(ctx, prog)) {
       return GL_TRUE;
    }
 
    struct pipe_screen *pscreen = ctx->st->pipe->screen;
    assert(prog->data->LinkStatus);
 
+   bool use_nir = false;
    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
       if (prog->_LinkedShaders[i] == NULL)
          continue;
 
       struct gl_linked_shader *shader = prog->_LinkedShaders[i];
       exec_list *ir = shader->ir;
       gl_shader_stage stage = shader->Stage;
       const struct gl_shader_compiler_options *options =
             &ctx->Const.ShaderCompilerOptions[stage];
       enum pipe_shader_type ptarget = pipe_shader_type_from_mesa(stage);
       bool have_dround = pscreen->get_shader_param(pscreen, ptarget,
                                                    PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED);
       bool have_dfrexp = pscreen->get_shader_param(pscreen, ptarget,
                                                    PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED);
       bool have_ldexp = pscreen->get_shader_param(pscreen, ptarget,
                                                   PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED);
       unsigned if_threshold = pscreen->get_shader_param(pscreen, ptarget,
                                                         PIPE_SHADER_CAP_LOWER_IF_THRESHOLD);
 
+      enum pipe_shader_ir preferred_ir = (enum pipe_shader_ir)
+         pscreen->get_shader_param(pscreen, ptarget,
+                                   PIPE_SHADER_CAP_PREFERRED_IR);
+      if (preferred_ir == PIPE_SHADER_IR_NIR)
+         use_nir = true;
+
       /* If there are forms of indirect addressing that the driver
        * cannot handle, perform the lowering pass.
        */
       if (options->EmitNoIndirectInput || options->EmitNoIndirectOutput ||
           options->EmitNoIndirectTemp || options->EmitNoIndirectUniform) {
          lower_variable_index_to_cond_assign(stage, ir,
                                              options->EmitNoIndirectInput,
                                              options->EmitNoIndirectOutput,
                                              options->EmitNoIndirectTemp,
                                              options->EmitNoIndirectUniform);
@@ -7016,38 +7023,31 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
             progress |= lower_if_to_cond_assign((gl_shader_stage)i, ir,
                                                 options->MaxIfDepth, if_threshold);
          } while (progress);
       }
 
       validate_ir_tree(ir);
    }
 
    build_program_resource_list(ctx, prog);
 
+   if (use_nir)
+      return st_link_nir(ctx, prog);
+
    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
       struct gl_linked_shader *shader = prog->_LinkedShaders[i];
       if (shader == NULL)
          continue;
 
-      enum pipe_shader_type ptarget =
-         pipe_shader_type_from_mesa(shader->Stage);
-      enum pipe_shader_ir preferred_ir = (enum pipe_shader_ir)
-         pscreen->get_shader_param(pscreen, ptarget,
-                                   PIPE_SHADER_CAP_PREFERRED_IR);
-
-      struct gl_program *linked_prog = NULL;
-      if (preferred_ir == PIPE_SHADER_IR_NIR) {
-         linked_prog = st_nir_get_mesa_program(ctx, prog, shader);
-      } else {
-         linked_prog = get_mesa_program_tgsi(ctx, prog, shader);
-         st_set_prog_affected_state_flags(linked_prog);
-      }
+      struct gl_program *linked_prog =
+         get_mesa_program_tgsi(ctx, prog, shader);
+      st_set_prog_affected_state_flags(linked_prog);
 
       if (linked_prog) {
          if (!ctx->Driver.ProgramStringNotify(ctx,
                                               _mesa_shader_stage_to_program(i),
                                               linked_prog)) {
             _mesa_reference_program(ctx, &shader->Program, NULL);
             return GL_FALSE;
          }
       }
    }
diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h
index 9302a7c786..c65e753f9b 100644
--- a/src/mesa/state_tracker/st_nir.h
+++ b/src/mesa/state_tracker/st_nir.h
@@ -38,20 +38,19 @@ 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 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);
+bool
+st_link_nir(struct gl_context *ctx,
+            struct gl_shader_program *shader_program);
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* ST_NIR_H */
-- 
2.14.3



More information about the mesa-dev mailing list