[Mesa-dev] [RFC 2/3] glsl link: annotate not_interstage attribute of the ir_var after link phase

Gregory Hainaut gregory.hainaut at gmail.com
Sat Oct 3 02:31:19 PDT 2015


Signed-off-by: Gregory Hainaut <gregory.hainaut at gmail.com>
---
 src/glsl/linker.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index fd69dbc..a4a8ab4 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -3378,6 +3378,51 @@ link_assign_subroutine_types(struct gl_shader_program *prog)
    }
 }
 
+static void
+set_interstage_io(struct gl_shader_program *prog)
+{
+   unsigned first, last;
+
+   /* In monolithic build, IO can be freely optimized */
+   if (!prog->SeparateShader)
+      return;
+
+   first = MESA_SHADER_STAGES;
+   last = 0;
+
+   /* Determine first and last stage. Excluding the compute stage */
+   for (unsigned i = 0; i < MESA_SHADER_COMPUTE; i++) {
+      if (!prog->_LinkedShaders[i])
+         continue;
+      if (first == MESA_SHADER_STAGES)
+         first = i;
+      last = i;
+   }
+
+   if (first == MESA_SHADER_STAGES)
+      return;
+
+   for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) {
+      gl_shader *sh = prog->_LinkedShaders[stage];
+      if (!sh)
+         continue;
+
+      if (first == last) {
+         /* Single shader program */
+         if (first != MESA_SHADER_VERTEX)
+            ir_set_not_interstage_io(sh->ir, ir_var_shader_in);
+         if (first != MESA_SHADER_FRAGMENT)
+            ir_set_not_interstage_io(sh->ir, ir_var_shader_out);
+      } else {
+         /* Multiple shaders program */
+         if (stage == first && stage != MESA_SHADER_VERTEX)
+            ir_set_not_interstage_io(sh->ir, ir_var_shader_in);
+         else if (stage == last && stage != MESA_SHADER_FRAGMENT)
+            ir_set_not_interstage_io(sh->ir, ir_var_shader_out);
+      }
+   }
+}
+
 void
 link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 {
@@ -3637,6 +3682,8 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
       }
    }
 
+   set_interstage_io(prog);
+
    if (!interstage_cross_validate_uniform_blocks(prog))
       goto done;
 
-- 
2.1.4



More information about the mesa-dev mailing list