st/glsl: move nir linking loop to new function st_link_nir()
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 9 Nov 2017 06:32:08 +0000 (17:32 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Sun, 3 Dec 2017 22:10:30 +0000 (09:10 +1100)
This will allow us to refactor linking and include some nir link
time optimisations.

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

index d0375dd3aa70b4a216a17b9da0356451720c3613..8b66f8277a85b09f6f765133853a9f2bbfc4e963 100644 (file)
@@ -508,4 +508,29 @@ st_nir_get_mesa_program(struct gl_context *ctx,
    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" */
index fa51fef343be7bb41e64b7a299cd18d65c6f3954..8eeae86dabb3fa4450c47fa96e09a1e8b69c19db 100644 (file)
@@ -6901,6 +6901,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
    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;
@@ -6920,6 +6921,12 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       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.
        */
@@ -7023,24 +7030,17 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 
    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,
index 9302a7c786b2061c3a4b2d85158861abb1d60e36..c65e753f9b4db0927e80f820e33b0b042e295057 100644 (file)
@@ -45,10 +45,9 @@ 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
 }