mesa: modify _mesa_copy_linked_program_data() to take gl_linked_shader
authorTimothy Arceri <timothy.arceri@collabora.com>
Wed, 19 Oct 2016 03:49:48 +0000 (14:49 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Wed, 26 Oct 2016 03:29:36 +0000 (14:29 +1100)
This allows us to do some small tidy ups, but will also allow us to call
a new function that copies values to a shared shader info from here.

In order to make this change this function now requires
_mesa_reference_program() to have previously been called.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/drivers/dri/i965/brw_link.cpp
src/mesa/main/shaderapi.c
src/mesa/main/shaderapi.h
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 5ea97736fa8d19dcf5b6248a93c50b702207a88d..f0e504d99abeee0989fde901a1e2e9dfb7bbb818 100644 (file)
@@ -226,9 +226,12 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
                                 0);
       if (!prog)
         return false;
+
+      _mesa_reference_program(ctx, &shader->Program, prog);
+
       prog->Parameters = _mesa_new_parameter_list();
 
-      _mesa_copy_linked_program_data((gl_shader_stage) stage, shProg, prog);
+      _mesa_copy_linked_program_data(shProg, shader);
 
       process_glsl_ir(brw, shProg, shader);
 
@@ -261,8 +264,6 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
       prog->ShadowSamplers = shader->shadow_samplers;
       _mesa_update_shader_textures_used(shProg, prog);
 
-      _mesa_reference_program(ctx, &shader->Program, prog);
-
       brw_add_texrect_params(prog);
 
       prog->nir = brw_create_nir(brw, shProg, prog, (gl_shader_stage) stage,
index 1af1c3f57948caf7c520de0fd6dd3da6de9d7518..358969b082cc4c99af63b991398330e5ebc10aee 100644 (file)
@@ -2152,14 +2152,20 @@ _mesa_use_shader_program(struct gl_context *ctx, GLenum type,
 
 /**
  * Copy program-specific data generated by linking from the gl_shader_program
- * object to a specific gl_program object.
+ * object to the gl_program object referred to by the gl_linked_shader.
+ *
+ * This function expects _mesa_reference_program() to have been previously
+ * called setting the gl_linked_shaders program reference.
  */
 void
-_mesa_copy_linked_program_data(gl_shader_stage type,
-                               const struct gl_shader_program *src,
-                               struct gl_program *dst)
+_mesa_copy_linked_program_data(const struct gl_shader_program *src,
+                               struct gl_linked_shader *dst_sh)
 {
-   switch (type) {
+   assert(dst_sh->Program);
+
+   struct gl_program *dst = dst_sh->Program;
+
+   switch (dst_sh->Stage) {
    case MESA_SHADER_VERTEX:
       dst->ClipDistanceArraySize = src->Vert.ClipDistanceArraySize;
       dst->CullDistanceArraySize = src->Vert.CullDistanceArraySize;
@@ -2167,34 +2173,29 @@ _mesa_copy_linked_program_data(gl_shader_stage type,
    case MESA_SHADER_TESS_CTRL: {
       struct gl_tess_ctrl_program *dst_tcp =
          (struct gl_tess_ctrl_program *) dst;
-      dst_tcp->VerticesOut = src->_LinkedShaders[MESA_SHADER_TESS_CTRL]->
-         info.TessCtrl.VerticesOut;
+      dst_tcp->VerticesOut = dst_sh->info.TessCtrl.VerticesOut;
       break;
    }
    case MESA_SHADER_TESS_EVAL: {
       struct gl_tess_eval_program *dst_tep =
          (struct gl_tess_eval_program *) dst;
-      struct gl_linked_shader *tes_sh =
-         src->_LinkedShaders[MESA_SHADER_TESS_EVAL];
 
-      dst_tep->PrimitiveMode = tes_sh->info.TessEval.PrimitiveMode;
-      dst_tep->Spacing = tes_sh->info.TessEval.Spacing;
-      dst_tep->VertexOrder = tes_sh->info.TessEval.VertexOrder;
-      dst_tep->PointMode = tes_sh->info.TessEval.PointMode;
+      dst_tep->PrimitiveMode = dst_sh->info.TessEval.PrimitiveMode;
+      dst_tep->Spacing = dst_sh->info.TessEval.Spacing;
+      dst_tep->VertexOrder = dst_sh->info.TessEval.VertexOrder;
+      dst_tep->PointMode = dst_sh->info.TessEval.PointMode;
       dst->ClipDistanceArraySize = src->TessEval.ClipDistanceArraySize;
       dst->CullDistanceArraySize = src->TessEval.CullDistanceArraySize;
       break;
    }
    case MESA_SHADER_GEOMETRY: {
       struct gl_geometry_program *dst_gp = (struct gl_geometry_program *) dst;
-      struct gl_linked_shader *geom_sh =
-         src->_LinkedShaders[MESA_SHADER_GEOMETRY];
 
       dst_gp->VerticesIn = src->Geom.VerticesIn;
-      dst_gp->VerticesOut = geom_sh->info.Geom.VerticesOut;
-      dst_gp->Invocations = geom_sh->info.Geom.Invocations;
-      dst_gp->InputType = geom_sh->info.Geom.InputType;
-      dst_gp->OutputType = geom_sh->info.Geom.OutputType;
+      dst_gp->VerticesOut = dst_sh->info.Geom.VerticesOut;
+      dst_gp->Invocations = dst_sh->info.Geom.Invocations;
+      dst_gp->InputType = dst_sh->info.Geom.InputType;
+      dst_gp->OutputType = dst_sh->info.Geom.OutputType;
       dst->ClipDistanceArraySize = src->Geom.ClipDistanceArraySize;
       dst->CullDistanceArraySize = src->Geom.CullDistanceArraySize;
       dst_gp->UsesEndPrimitive = src->Geom.UsesEndPrimitive;
index 4297bfa3d65765119699c7205beface209630b09..50929f4483e7d20e1c92cc2c216fe9955b4d0d91 100644 (file)
@@ -218,9 +218,8 @@ _mesa_use_shader_program(struct gl_context *ctx, GLenum type,
                          struct gl_pipeline_object *shTarget);
 
 extern void
-_mesa_copy_linked_program_data(gl_shader_stage type,
-                               const struct gl_shader_program *src,
-                               struct gl_program *dst);
+_mesa_copy_linked_program_data(const struct gl_shader_program *src,
+                               struct gl_linked_shader *dst_sh);
 
 extern bool
 _mesa_validate_shader_target(const struct gl_context *ctx, GLenum type);
index bd65df2b22e7c59a39e30bdced712056cba7b85b..00ee3e34bfcc3ff0ed4956ac7cbb8501ada7e597 100644 (file)
@@ -3028,7 +3028,7 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       linked_prog = get_mesa_program(ctx, prog, prog->_LinkedShaders[i]);
 
       if (linked_prog) {
-         _mesa_copy_linked_program_data((gl_shader_stage) i, prog, linked_prog);
+         _mesa_copy_linked_program_data(prog, prog->_LinkedShaders[i]);
 
          if (!ctx->Driver.ProgramStringNotify(ctx,
                                               _mesa_shader_stage_to_program(i),
index f43460ba67ad142c2511bbe25440cdb827de19a4..97fef082c0458d08422dabfdb6283db50aeacd1c 100644 (file)
@@ -378,9 +378,11 @@ st_nir_get_mesa_program(struct gl_context *ctx,
    if (!prog)
       return NULL;
 
+   _mesa_reference_program(ctx, &shader->Program, prog);
+
    prog->Parameters = _mesa_new_parameter_list();
 
-   _mesa_copy_linked_program_data(shader->Stage, shader_program, prog);
+   _mesa_copy_linked_program_data(shader_program, shader);
    _mesa_generate_parameters_list_for_uniforms(shader_program, shader,
                                                prog->Parameters);
 
@@ -426,8 +428,6 @@ st_nir_get_mesa_program(struct gl_context *ctx,
    prog->ExternalSamplersUsed = gl_external_samplers(shader);
    _mesa_update_shader_textures_used(shader_program, prog);
 
-   _mesa_reference_program(ctx, &shader->Program, prog);
-
    /* Avoid reallocation of the program parameter list, because the uniform
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
index f3764623d5041a60d0703b10ffb71d8cd932aeef..b2bd21524885ecb9b65d48abedb84b23f433570f 100644 (file)
@@ -6379,6 +6379,9 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    prog = ctx->Driver.NewProgram(ctx, target, shader_program->Name);
    if (!prog)
       return NULL;
+
+   _mesa_reference_program(ctx, &shader->Program, prog);
+
    prog->Parameters = _mesa_new_parameter_list();
    v = new glsl_to_tgsi_visitor();
    v->ctx = ctx;
@@ -6394,7 +6397,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    v->have_fma = pscreen->get_shader_param(pscreen, ptarget,
                                            PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED);
 
-   _mesa_copy_linked_program_data(shader->Stage, shader_program, prog);
+   _mesa_copy_linked_program_data(shader_program, shader);
    _mesa_generate_parameters_list_for_uniforms(shader_program, shader,
                                                prog->Parameters);
 
@@ -6486,8 +6489,6 @@ get_mesa_program_tgsi(struct gl_context *ctx,
                                                           wposTransformState);
    }
 
-   _mesa_reference_program(ctx, &shader->Program, prog);
-
    /* Avoid reallocation of the program parameter list, because the uniform
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.