glsl/mesa: stop duplicating geom and tcs layout values
authorTimothy Arceri <timothy.arceri@collabora.com>
Wed, 22 Jun 2016 02:41:28 +0000 (12:41 +1000)
committerTimothy Arceri <t_arceri@yahoo.com.au>
Thu, 23 Jun 2016 01:01:46 +0000 (11:01 +1000)
We already store these in gl_shader and gl_program here we
remove it from gl_shader_program and just use the values
from gl_shader.

This will allow us to keep the shader cache restore code as
simple as it can be while making it somewhat clearer where these
values originate from.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
src/compiler/glsl/glsl_to_nir.cpp
src/compiler/glsl/linker.cpp
src/mesa/drivers/dri/i965/brw_tcs.c
src/mesa/main/api_validate.c
src/mesa/main/mtypes.h
src/mesa/main/shaderapi.c
src/mesa/main/shaderobj.c

index daf237eee6b9003e05d7e6d90bac7244e54a799a..16d0c1d54d2ae1d8181dcba7c06dcb1bde4b5f5e 100644 (file)
@@ -166,7 +166,7 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
 
    switch (stage) {
    case MESA_SHADER_TESS_CTRL:
-      shader->info.tcs.vertices_out = shader_prog->TessCtrl.VerticesOut;
+      shader->info.tcs.vertices_out = sh->TessCtrl.VerticesOut;
       break;
 
    case MESA_SHADER_GEOMETRY:
index bf70f29039f22bf75ed8f6e00a4c40608e4d0790..c7cf56eaa0b3cfde22a0d1a51b746fb947760619 100644 (file)
@@ -857,7 +857,7 @@ validate_geometry_shader_executable(struct gl_shader_program *prog,
    if (shader == NULL)
       return;
 
-   unsigned num_vertices = vertices_per_prim(prog->Geom.InputType);
+   unsigned num_vertices = vertices_per_prim(shader->Geom.InputType);
    prog->Geom.VerticesIn = num_vertices;
 
    analyze_clip_cull_usage(prog, shader, ctx,
@@ -873,9 +873,11 @@ static void
 validate_geometry_shader_emissions(struct gl_context *ctx,
                                    struct gl_shader_program *prog)
 {
-   if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY] != NULL) {
+   struct gl_shader *sh = prog->_LinkedShaders[MESA_SHADER_GEOMETRY];
+
+   if (sh != NULL) {
       find_emit_vertex_visitor emit_vertex(ctx->Const.MaxVertexStreams - 1);
-      emit_vertex.run(prog->_LinkedShaders[MESA_SHADER_GEOMETRY]->ir);
+      emit_vertex.run(sh->ir);
       if (emit_vertex.error()) {
          linker_error(prog, "Invalid call %s(%d). Accepted values for the "
                       "stream parameter are in the range [0, %d].\n",
@@ -910,7 +912,7 @@ validate_geometry_shader_emissions(struct gl_context *ctx,
        * EmitStreamVertex() or EmitEndPrimitive() are called with a non-zero
        * stream.
        */
-      if (prog->Geom.UsesStreams && prog->Geom.OutputType != GL_POINTS) {
+      if (prog->Geom.UsesStreams && sh->Geom.OutputType != GL_POINTS) {
          linker_error(prog, "EmitStreamVertex(n) and EndStreamPrimitive(n) "
                       "with n>0 requires point output\n");
       }
@@ -1793,7 +1795,6 @@ link_tcs_out_layout_qualifiers(struct gl_shader_program *prog,
                   "vertices out layout qualifier\n");
       return;
    }
-   prog->TessCtrl.VerticesOut = linked_shader->TessCtrl.VerticesOut;
 }
 
 
@@ -2055,26 +2056,21 @@ link_gs_inout_layout_qualifiers(struct gl_shader_program *prog,
                   "geometry shader didn't declare primitive input type\n");
       return;
    }
-   prog->Geom.InputType = linked_shader->Geom.InputType;
 
    if (linked_shader->Geom.OutputType == PRIM_UNKNOWN) {
       linker_error(prog,
                   "geometry shader didn't declare primitive output type\n");
       return;
    }
-   prog->Geom.OutputType = linked_shader->Geom.OutputType;
 
    if (linked_shader->Geom.VerticesOut == -1) {
       linker_error(prog,
                   "geometry shader didn't declare max_vertices\n");
       return;
    }
-   prog->Geom.VerticesOut = linked_shader->Geom.VerticesOut;
 
    if (linked_shader->Geom.Invocations == 0)
       linked_shader->Geom.Invocations = 1;
-
-   prog->Geom.Invocations = linked_shader->Geom.Invocations;
 }
 
 
@@ -2349,7 +2345,7 @@ link_intrastage_shaders(void *mem_ctx,
 
    /* Set the size of geometry shader input arrays */
    if (linked->Stage == MESA_SHADER_GEOMETRY) {
-      unsigned num_vertices = vertices_per_prim(prog->Geom.InputType);
+      unsigned num_vertices = vertices_per_prim(linked->Geom.InputType);
       geom_array_resize_visitor input_resize_visitor(num_vertices, prog);
       foreach_in_list(ir_instruction, ir, linked->ir) {
          ir->accept(&input_resize_visitor);
index 548dc75276c17245027b041ea676f5e9bd6eeedd..d488715cac342d5ac3ee40fcf6bcbeda1010cb49 100644 (file)
@@ -390,8 +390,10 @@ brw_tcs_precompile(struct gl_context *ctx,
    brw_setup_tex_for_precompile(brw, &key.tex, prog);
 
    /* Guess that the input and output patches have the same dimensionality. */
-   if (brw->gen < 8)
-      key.input_vertices = shader_prog->TessCtrl.VerticesOut;
+   if (brw->gen < 8) {
+      key.input_vertices = shader_prog->
+         _LinkedShaders[MESA_SHADER_TESS_CTRL]->TessCtrl.VerticesOut;
+   }
 
    key.tes_primitive_mode = brw->tess_eval_program ?
       brw->tess_eval_program->PrimitiveMode : GL_TRIANGLES;
index ab34d99834c3e233551bf6bb5c966b61cec0ae4c..8efbf50c09234943a37dd0e36159d87f367f4f40 100644 (file)
@@ -200,7 +200,8 @@ _mesa_valid_prim_mode(struct gl_context *ctx, GLenum mode, const char *name)
    */
    if (ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]) {
       const GLenum geom_mode =
-         ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]->Geom.InputType;
+         ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]->
+            _LinkedShaders[MESA_SHADER_GEOMETRY]->Geom.InputType;
       struct gl_shader_program *tes =
          ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
       GLenum mode_before_gs = mode;
@@ -305,7 +306,8 @@ _mesa_valid_prim_mode(struct gl_context *ctx, GLenum mode, const char *name)
       GLboolean pass = GL_TRUE;
 
       if(ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]) {
-         switch (ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]->Geom.OutputType) {
+         switch (ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]->
+                    _LinkedShaders[MESA_SHADER_GEOMETRY]->Geom.OutputType) {
          case GL_POINTS:
             pass = ctx->TransformFeedback.Mode == GL_POINTS;
             break;
index 99fa779a8074d829679b60fe7791c6f265898b7f..73ae55d83ebed71b84f47a56f3709e2b72b5842f 100644 (file)
@@ -2711,17 +2711,6 @@ struct gl_shader_program
    /** Post-link gl_FragDepth layout for ARB_conservative_depth. */
    enum gl_frag_depth_layout FragDepthLayout;
 
-   /**
-    * Tessellation Control shader state from layout qualifiers.
-    */
-   struct {
-      /**
-       * 0 - vertices not declared in shader, or
-       * 1 .. GL_MAX_PATCH_VERTICES
-       */
-      GLint VerticesOut;
-   } TessCtrl;
-
    /**
     * Tessellation Evaluation shader state from layout qualifiers.
     */
@@ -2742,14 +2731,7 @@ struct gl_shader_program
     */
    struct {
       GLint VerticesIn;
-      GLint VerticesOut;
-      /**
-       * 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS
-       */
-      GLint Invocations;
-      GLenum InputType;  /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
-                              GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
-      GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
+
       /**
        * True if gl_ClipDistance is written to.  Copied into
        * gl_geometry_program by _mesa_copy_linked_program_data().
index b65c0dc6c377b05175d22a978b8ec59ad9add1a2..07250cd768c9d68d56b6f8fbdb4d7ea0d70d3ab3 100644 (file)
@@ -731,26 +731,34 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
    case GL_GEOMETRY_VERTICES_OUT:
       if (!has_core_gs)
          break;
-      if (check_gs_query(ctx, shProg))
-         *params = shProg->Geom.VerticesOut;
+      if (check_gs_query(ctx, shProg)) {
+         *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
+            Geom.VerticesOut;
+      }
       return;
    case GL_GEOMETRY_SHADER_INVOCATIONS:
       if (!has_core_gs || !ctx->Extensions.ARB_gpu_shader5)
          break;
-      if (check_gs_query(ctx, shProg))
-         *params = shProg->Geom.Invocations;
+      if (check_gs_query(ctx, shProg)) {
+         *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
+            Geom.Invocations;
+      }
       return;
    case GL_GEOMETRY_INPUT_TYPE:
       if (!has_core_gs)
          break;
-      if (check_gs_query(ctx, shProg))
-         *params = shProg->Geom.InputType;
+      if (check_gs_query(ctx, shProg)) {
+         *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
+            Geom.InputType;
+      }
       return;
    case GL_GEOMETRY_OUTPUT_TYPE:
       if (!has_core_gs)
          break;
-      if (check_gs_query(ctx, shProg))
-         *params = shProg->Geom.OutputType;
+      if (check_gs_query(ctx, shProg)) {
+         *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
+            Geom.OutputType;
+      }
       return;
    case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: {
       unsigned i;
@@ -825,8 +833,10 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
    case GL_TESS_CONTROL_OUTPUT_VERTICES:
       if (!has_tess)
          break;
-      if (check_tcs_query(ctx, shProg))
-         *params = shProg->TessCtrl.VerticesOut;
+      if (check_tcs_query(ctx, shProg)) {
+         *params = shProg->_LinkedShaders[MESA_SHADER_TESS_CTRL]->
+            TessCtrl.VerticesOut;
+      }
       return;
    case GL_TESS_GEN_MODE:
       if (!has_tess)
@@ -2159,7 +2169,8 @@ _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->TessCtrl.VerticesOut;
+      dst_tcp->VerticesOut =
+         src->_LinkedShaders[MESA_SHADER_TESS_CTRL]->TessCtrl.VerticesOut;
       break;
    }
    case MESA_SHADER_TESS_EVAL: {
@@ -2177,11 +2188,13 @@ _mesa_copy_linked_program_data(gl_shader_stage type,
    }
    case MESA_SHADER_GEOMETRY: {
       struct gl_geometry_program *dst_gp = (struct gl_geometry_program *) dst;
+      struct gl_shader *geom_sh = src->_LinkedShaders[MESA_SHADER_GEOMETRY];
+
       dst_gp->VerticesIn = src->Geom.VerticesIn;
-      dst_gp->VerticesOut = src->Geom.VerticesOut;
-      dst_gp->Invocations = src->Geom.Invocations;
-      dst_gp->InputType = src->Geom.InputType;
-      dst_gp->OutputType = src->Geom.OutputType;
+      dst_gp->VerticesOut = geom_sh->Geom.VerticesOut;
+      dst_gp->Invocations = geom_sh->Geom.Invocations;
+      dst_gp->InputType = geom_sh->Geom.InputType;
+      dst_gp->OutputType = geom_sh->Geom.OutputType;
       dst->ClipDistanceArraySize = src->Geom.ClipDistanceArraySize;
       dst->CullDistanceArraySize = src->Geom.CullDistanceArraySize;
       dst_gp->UsesEndPrimitive = src->Geom.UsesEndPrimitive;
index 8283555740b5137eeb5c6b5273ccc5bf03a4c5c7..f3d5c2ee5badc1df2974137a4d0e0ac151005e18 100644 (file)
@@ -92,6 +92,9 @@ void
 _mesa_init_shader(struct gl_context *ctx, struct gl_shader *shader)
 {
    shader->RefCount = 1;
+   shader->Geom.VerticesOut = -1;
+   shader->Geom.InputType = GL_TRIANGLES;
+   shader->Geom.OutputType = GL_TRIANGLE_STRIP;
 }
 
 /**
@@ -230,9 +233,6 @@ init_shader_program(struct gl_shader_program *prog)
    prog->FragDataBindings = string_to_uint_map_ctor();
    prog->FragDataIndexBindings = string_to_uint_map_ctor();
 
-   prog->Geom.VerticesOut = -1;
-   prog->Geom.InputType = GL_TRIANGLES;
-   prog->Geom.OutputType = GL_TRIANGLE_STRIP;
    prog->Geom.UsesEndPrimitive = false;
    prog->Geom.UsesStreams = false;