st/glsl_to_nir: create set_st_program() helper
authorTimothy Arceri <tarceri@itsqueeze.com>
Mon, 13 Nov 2017 22:03:45 +0000 (09:03 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Sun, 3 Dec 2017 22:10:30 +0000 (09:10 +1100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/state_tracker/st_glsl_to_nir.cpp

index 8b66f8277a85b09f6f765133853a9f2bbfc4e963..bb0ba0701236d230ae4a2f9a0178f03e16cc4c0c 100644 (file)
@@ -435,44 +435,17 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
       NIR_PASS_V(nir, nir_lower_samplers, shader_program);
 }
 
-struct gl_program *
-st_nir_get_mesa_program(struct gl_context *ctx,
-                        struct gl_shader_program *shader_program,
-                        struct gl_linked_shader *shader)
+static void
+set_st_program(struct gl_program *prog,
+               struct gl_shader_program *shader_program,
+               nir_shader *nir)
 {
-   struct st_context *st = st_context(ctx);
-   struct gl_program *prog;
-
-   validate_ir_tree(shader->ir);
-
-   prog = shader->Program;
-
-   prog->Parameters = _mesa_new_parameter_list();
-
-   _mesa_copy_linked_program_data(shader_program, shader);
-   _mesa_generate_parameters_list_for_uniforms(ctx, shader_program, shader,
-                                               prog->Parameters);
-
-   if (ctx->_Shader->Flags & GLSL_DUMP) {
-      _mesa_log("\n");
-      _mesa_log("GLSL IR for linked %s program %d:\n",
-             _mesa_shader_stage_to_string(shader->Stage),
-             shader_program->Name);
-      _mesa_print_ir(_mesa_get_log_file(), shader->ir, NULL);
-      _mesa_log("\n\n");
-   }
-
-   prog->ExternalSamplersUsed = gl_external_samplers(prog);
-   _mesa_update_shader_textures_used(shader_program, prog);
-
    struct st_vertex_program *stvp;
    struct st_common_program *stp;
    struct st_fragment_program *stfp;
    struct st_compute_program *stcp;
 
-   nir_shader *nir = st_glsl_to_nir(st, prog, shader_program, shader->Stage);
-
-   switch (shader->Stage) {
+   switch (prog->info.stage) {
    case MESA_SHADER_VERTEX:
       stvp = (struct st_vertex_program *)prog;
       stvp->shader_program = shader_program;
@@ -500,10 +473,43 @@ st_nir_get_mesa_program(struct gl_context *ctx,
       stcp->tgsi.prog = nir_shader_clone(NULL, nir);
       break;
    default:
-      assert(!"should not be reached");
-      return NULL;
+      unreachable("unknown shader stage");
    }
+}
+
+struct gl_program *
+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);
+
+   prog = shader->Program;
+
+   prog->Parameters = _mesa_new_parameter_list();
+
+   _mesa_copy_linked_program_data(shader_program, shader);
+   _mesa_generate_parameters_list_for_uniforms(ctx, shader_program, shader,
+                                               prog->Parameters);
+
+   if (ctx->_Shader->Flags & GLSL_DUMP) {
+      _mesa_log("\n");
+      _mesa_log("GLSL IR for linked %s program %d:\n",
+             _mesa_shader_stage_to_string(shader->Stage),
+             shader_program->Name);
+      _mesa_print_ir(_mesa_get_log_file(), shader->ir, NULL);
+      _mesa_log("\n\n");
+   }
+
+   prog->ExternalSamplersUsed = gl_external_samplers(prog);
+   _mesa_update_shader_textures_used(shader_program, prog);
+
+   nir_shader *nir = st_glsl_to_nir(st, prog, shader_program, shader->Stage);
 
+   set_st_program(prog, shader_program, nir);
 
    return prog;
 }