glsl: Convert TES gl_PatchVerticesIn into a constant when using a TCS.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 29 Jul 2015 01:16:37 +0000 (18:16 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 26 Oct 2015 23:37:07 +0000 (16:37 -0700)
When a TCS is present, the TES input gl_PatchVerticesIn is actually a
constant - it's simply the # of output vertices specified by the TCS
layout qualifiers.  So, we can replace the system value with a constant,
which may allow further optimization, and will likely be more efficient.

If the TCS is absent, we can't do this optimization.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/glsl/linker.cpp

index 424b92a1783b9a7bf4c5aab271a25ad695d2aa01..cfd8f81c86739d81136d7734770a8d9097513096 100644 (file)
@@ -2282,6 +2282,22 @@ resize_tes_inputs(struct gl_context *ctx,
    foreach_in_list(ir_instruction, ir, tes->ir) {
       ir->accept(&input_resize_visitor);
    }
+
+   if (tcs) {
+      /* Convert the gl_PatchVerticesIn system value into a constant, since
+       * the value is known at this point.
+       */
+      foreach_in_list(ir_instruction, ir, tes->ir) {
+         ir_variable *var = ir->as_variable();
+         if (var && var->data.mode == ir_var_system_value &&
+             var->data.location == SYSTEM_VALUE_VERTICES_IN) {
+            void *mem_ctx = ralloc_parent(var);
+            var->data.mode = ir_var_auto;
+            var->data.location = 0;
+            var->constant_value = new(mem_ctx) ir_constant(num_vertices);
+         }
+      }
+   }
 }
 
 /**