Mesa (master): linker: Demote user-defined varyings in the VS-only case

Ian Romanick idr at kemper.freedesktop.org
Tue Aug 17 22:02:57 UTC 2010


Module: Mesa
Branch: master
Commit: 40e114b5dc60c5e196a86e33c2436b099ed9f392
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=40e114b5dc60c5e196a86e33c2436b099ed9f392

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Aug 17 14:55:50 2010 -0700

linker: Demote user-defined varyings in the VS-only case

Fixes piglit test case glsl-vs-ff-frag and bugzilla #29623.

---

 src/glsl/linker.cpp |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 22cdd76..4172e41 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1104,6 +1104,28 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index
 }
 
 
+/**
+ * Demote shader outputs that are not read to being just plain global variables
+ */
+void
+demote_unread_shader_outputs(gl_shader *sh)
+{
+   foreach_list(node, sh->ir) {
+      ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+      if ((var == NULL) || (var->mode != ir_var_out))
+	 continue;
+
+      /* An 'out' variable is only really a shader output if its value is read
+       * by the following stage.
+       */
+      if (var->location == -1) {
+	 var->mode = ir_var_auto;
+      }
+   }
+}
+
+
 void
 assign_varying_locations(struct gl_shader_program *prog,
 			 gl_shader *producer, gl_shader *consumer)
@@ -1152,19 +1174,7 @@ assign_varying_locations(struct gl_shader_program *prog,
       input_index++;
    }
 
-   foreach_list(node, producer->ir) {
-      ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
-      if ((var == NULL) || (var->mode != ir_var_out))
-	 continue;
-
-      /* An 'out' variable is only really a shader output if its value is read
-       * by the following stage.
-       */
-      if (var->location == -1) {
-	 var->mode = ir_var_auto;
-      }
-   }
+   demote_unread_shader_outputs(producer);
 
    foreach_list(node, consumer->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
@@ -1320,7 +1330,7 @@ link_shaders(struct gl_shader_program *prog)
 
    assign_uniform_locations(prog);
 
-   if (prog->_LinkedShaders[0]->Type == GL_VERTEX_SHADER)
+   if (prog->_LinkedShaders[0]->Type == GL_VERTEX_SHADER) {
       /* FINISHME: The value of the max_attribute_index parameter is
        * FINISHME: implementation dependent based on the value of
        * FINISHME: GL_MAX_VERTEX_ATTRIBS.  GL_MAX_VERTEX_ATTRIBS must be
@@ -1329,6 +1339,10 @@ link_shaders(struct gl_shader_program *prog)
       if (!assign_attribute_locations(prog, 16))
 	 goto done;
 
+      if (prog->_NumLinkedShaders == 1)
+	 demote_unread_shader_outputs(prog->_LinkedShaders[0]);
+   }
+
    for (unsigned i = 1; i < prog->_NumLinkedShaders; i++)
       assign_varying_locations(prog,
 			       prog->_LinkedShaders[i - 1],




More information about the mesa-commit mailing list