[Mesa-dev] [PATCH 5/5] st/mesa/glsl: change xfb_program field to last_vert_prog

Timothy Arceri timothy.arceri at collabora.com
Fri Dec 30 22:31:01 UTC 2016


By making it more generic and we can short circuit a bunch of code
paths.

The new field will also be used in coming changes for more clean-ups.

This change also fixes a regression caused by 700bc94dcebf425

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=99231
---
 src/compiler/glsl/link_varyings.cpp        |  5 +++-
 src/compiler/glsl/linker.cpp               | 47 +++++++++++++++---------------
 src/mesa/drivers/dri/i965/brw_ff_gs.c      |  2 +-
 src/mesa/drivers/dri/i965/gen6_sol.c       |  6 ++--
 src/mesa/main/mtypes.h                     |  2 +-
 src/mesa/main/shader_query.cpp             |  2 +-
 src/mesa/main/transformfeedback.c          |  5 +++-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  5 +++-
 src/mesa/state_tracker/st_program.c        | 10 +++++--
 9 files changed, 48 insertions(+), 36 deletions(-)

diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index e1a29b0..147a7c3 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -1074,6 +1074,9 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
                      unsigned num_tfeedback_decls,
                      tfeedback_decl *tfeedback_decls, bool has_xfb_qualifiers)
 {
+   if (!prog->last_vert_prog)
+      return true;
+
    /* Make sure MaxTransformFeedbackBuffers is less than 32 so the bitmask for
     * tracking the number of buffers doesn't overflow.
     */
@@ -1082,7 +1085,7 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
    bool separate_attribs_mode =
       prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS;
 
-   struct gl_program *xfb_prog = prog->xfb_program;
+   struct gl_program *xfb_prog = prog->last_vert_prog;
    xfb_prog->sh.LinkedTransformFeedback =
       rzalloc(xfb_prog, struct gl_transform_feedback_info);
 
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index f4f918a..40002eb 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4244,27 +4244,29 @@ build_program_resource_list(struct gl_context *ctx,
                                 output_stage, GL_PROGRAM_OUTPUT))
       return;
 
-   struct gl_transform_feedback_info *linked_xfb =
-      shProg->xfb_program->sh.LinkedTransformFeedback;
-
-   /* Add transform feedback varyings. */
-   if (linked_xfb->NumVarying > 0) {
-      for (int i = 0; i < linked_xfb->NumVarying; i++) {
-         if (!add_program_resource(shProg, resource_set,
-                                   GL_TRANSFORM_FEEDBACK_VARYING,
-                                   &linked_xfb->Varyings[i], 0))
-         return;
+   if (shProg->last_vert_prog) {
+      struct gl_transform_feedback_info *linked_xfb =
+         shProg->last_vert_prog->sh.LinkedTransformFeedback;
+
+      /* Add transform feedback varyings. */
+      if (linked_xfb->NumVarying > 0) {
+         for (int i = 0; i < linked_xfb->NumVarying; i++) {
+            if (!add_program_resource(shProg, resource_set,
+                                      GL_TRANSFORM_FEEDBACK_VARYING,
+                                      &linked_xfb->Varyings[i], 0))
+            return;
+         }
       }
-   }
 
-   /* Add transform feedback buffers. */
-   for (unsigned i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) {
-      if ((linked_xfb->ActiveBuffers >> i) & 1) {
-         linked_xfb->Buffers[i].Binding = i;
-         if (!add_program_resource(shProg, resource_set,
-                                   GL_TRANSFORM_FEEDBACK_BUFFER,
-                                   &linked_xfb->Buffers[i], 0))
-         return;
+      /* Add transform feedback buffers. */
+      for (unsigned i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) {
+         if ((linked_xfb->ActiveBuffers >> i) & 1) {
+            linked_xfb->Buffers[i].Binding = i;
+            if (!add_program_resource(shProg, resource_set,
+                                      GL_TRANSFORM_FEEDBACK_BUFFER,
+                                      &linked_xfb->Buffers[i], 0))
+            return;
+         }
       }
    }
 
@@ -4590,15 +4592,12 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
       varying_names = prog->TransformFeedback.VaryingNames;
    }
 
-   /* Find the program used for xfb. Even if we don't use xfb we still want to
-    * set this so we can fill the default values for program interface query.
-    */
-   prog->xfb_program = prog->_LinkedShaders[last]->Program;
+   prog->last_vert_prog = NULL;
    for (int i = MESA_SHADER_GEOMETRY; i >= MESA_SHADER_VERTEX; i--) {
       if (prog->_LinkedShaders[i] == NULL)
          continue;
 
-      prog->xfb_program = prog->_LinkedShaders[i]->Program;
+      prog->last_vert_prog = prog->_LinkedShaders[i]->Program;
       break;
    }
 
diff --git a/src/mesa/drivers/dri/i965/brw_ff_gs.c b/src/mesa/drivers/dri/i965/brw_ff_gs.c
index 4934af3..ec32d0b 100644
--- a/src/mesa/drivers/dri/i965/brw_ff_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_ff_gs.c
@@ -198,7 +198,7 @@ brw_ff_gs_populate_key(struct brw_context *brw,
          const struct gl_shader_program *shaderprog =
             ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
          const struct gl_transform_feedback_info *linked_xfb_info =
-            shaderprog->xfb_program->sh.LinkedTransformFeedback;
+            shaderprog->last_vert_prog->sh.LinkedTransformFeedback;
          int i;
 
          /* Make sure that the VUE slots won't overflow the unsigned chars in
diff --git a/src/mesa/drivers/dri/i965/gen6_sol.c b/src/mesa/drivers/dri/i965/gen6_sol.c
index 656d042..f56f2f9 100644
--- a/src/mesa/drivers/dri/i965/gen6_sol.c
+++ b/src/mesa/drivers/dri/i965/gen6_sol.c
@@ -116,7 +116,7 @@ brw_gs_upload_binding_table(struct brw_context *brw)
       if (shaderprog) {
          /* Skip making a binding table if we don't have anything to put in it */
          const struct gl_transform_feedback_info *linked_xfb_info =
-            shaderprog->xfb_program->sh.LinkedTransformFeedback;
+            shaderprog->last_vert_prog->sh.LinkedTransformFeedback;
          need_binding_table = linked_xfb_info->NumOutputs > 0;
       }
       if (!need_binding_table) {
@@ -145,7 +145,7 @@ brw_gs_upload_binding_table(struct brw_context *brw)
          /* Skip making a binding table if we don't have anything to put in it */
          struct brw_stage_prog_data *prog_data = brw->gs.base.prog_data;
          const struct gl_transform_feedback_info *linked_xfb_info =
-            shaderprog->xfb_program->sh.LinkedTransformFeedback;
+            shaderprog->last_vert_prog->sh.LinkedTransformFeedback;
          need_binding_table = linked_xfb_info->NumOutputs > 0 ||
                               prog_data->binding_table.size_bytes > 0;
       }
@@ -241,7 +241,7 @@ brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
       shaderprog =
          ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
    }
-   linked_xfb_info = shaderprog->xfb_program->sh.LinkedTransformFeedback;
+   linked_xfb_info = shaderprog->last_vert_prog->sh.LinkedTransformFeedback;
 
    /* Compute the maximum number of vertices that we can write without
     * overflowing any of the buffers currently being used for feedback.
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 89e183f..cc5aaae 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2752,7 +2752,7 @@ struct gl_shader_program
       GLchar **VaryingNames;  /**< Array [NumVarying] of char * */
    } TransformFeedback;
 
-   struct gl_program *xfb_program;
+   struct gl_program *last_vert_prog;
 
    /** Post-link gl_FragDepth layout for ARB_conservative_depth. */
    enum gl_frag_depth_layout FragDepthLayout;
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 0f4b282..603e259 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -1042,7 +1042,7 @@ get_buffer_property(struct gl_shader_program *shProg,
          return 1;
       case GL_ACTIVE_VARIABLES:
          struct gl_transform_feedback_info *linked_xfb =
-            shProg->xfb_program->sh.LinkedTransformFeedback;
+            shProg->last_vert_prog->sh.LinkedTransformFeedback;
          for (int i = 0; i < linked_xfb->NumVarying; i++) {
             unsigned index = linked_xfb->Varyings[i].BufferIndex;
             struct gl_program_resource *buf_res =
diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
index 771223a..efb7963 100644
--- a/src/mesa/main/transformfeedback.c
+++ b/src/mesa/main/transformfeedback.c
@@ -65,9 +65,12 @@ bool
 _mesa_transform_feedback_is_using_program(struct gl_context *ctx,
                                           struct gl_shader_program *shProg)
 {
+   if (!shProg->last_vert_prog)
+      return false;
+
    struct using_program_tuple callback_data;
    callback_data.found = false;
-   callback_data.prog = shProg->xfb_program;
+   callback_data.prog = shProg->last_vert_prog;
 
    _mesa_HashWalk(ctx->TransformFeedback.Objects,
                   active_xfb_object_references_program, &callback_data);
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 9599296..ee967d5 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6918,8 +6918,11 @@ st_translate_stream_output_info(glsl_to_tgsi_visitor *glsl_to_tgsi,
                                 const GLuint outputMapping[],
                                 struct pipe_stream_output_info *so)
 {
+   if (!glsl_to_tgsi->shader_program->last_vert_prog)
+      return;
+
    struct gl_transform_feedback_info *info =
-      glsl_to_tgsi->shader_program->xfb_program->sh.LinkedTransformFeedback;
+      glsl_to_tgsi->shader_program->last_vert_prog->sh.LinkedTransformFeedback;
    st_translate_stream_output_info2(info, outputMapping, so);
 }
 
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index e9dd584..1e687ed 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -390,9 +390,13 @@ st_translate_vertex_program(struct st_context *st,
       stvp->tgsi.type = PIPE_SHADER_IR_NIR;
       stvp->tgsi.ir.nir = nir;
 
-      st_translate_stream_output_info2(stvp->shader_program->xfb_program->sh.LinkedTransformFeedback,
-                                       stvp->result_to_output,
-                                       &stvp->tgsi.stream_output);
+      struct gl_program *prog = stvp->shader_program->last_vert_prog;
+      if (prog) {
+         st_translate_stream_output_info2(prog->sh.LinkedTransformFeedback,
+                                          stvp->result_to_output,
+                                          &stvp->tgsi.stream_output);
+      }
+
       return true;
    }
 
-- 
2.9.3



More information about the mesa-dev mailing list