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

Author: Chris Forbes <[email protected]>
Date:   Sun Nov 10 21:19:31 2013 +1300

allow builtin functions to require parameters to be shader inputs

The new interpolateAt* builtins have strange restrictions on the
<interpolant> parameter.

- It must be a shader input, or an element of a shader input array.
- It must not include a swizzle.

V2: Don't abuse ir_var_mode_shader_in for this; make a new flag.

Signed-off-by: Chris Forbes <[email protected]>
Reviewed-by: Ilia Mirkin <[email protected]>

---

 src/glsl/ast_function.cpp |   18 ++++++++++++++++++
 src/glsl/ir.h             |    6 ++++++
 2 files changed, 24 insertions(+)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index cdb34cc..631b793 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -178,6 +178,24 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
         return false;
       }
 
+      /* Verify that shader_in parameters are shader inputs */
+      if (formal->data.must_be_shader_input) {
+         ir_variable *var = actual->variable_referenced();
+         if (var && var->data.mode != ir_var_shader_in) {
+            _mesa_glsl_error(&loc, state,
+                             "parameter `%s` must be a shader input",
+                             formal->name);
+            return false;
+         }
+
+         if (actual->ir_type == ir_type_swizzle) {
+            _mesa_glsl_error(&loc, state,
+                             "parameter `%s` must not be swizzled",
+                             formal->name);
+            return false;
+         }
+      }
+
       /* Verify that 'out' and 'inout' actual parameters are lvalues. */
       if (formal->data.mode == ir_var_function_out
           || formal->data.mode == ir_var_function_inout) {
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index d5239d4..fa93efd 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -678,6 +678,12 @@ public:
       unsigned from_named_ifc_block_array:1;
 
       /**
+       * Non-zero if the variable must be a shader input. This is useful for
+       * constraints on function parameters.
+       */
+      unsigned must_be_shader_input:1;
+
+      /**
        * \brief Layout qualifier for gl_FragDepth.
        *
        * This is not equal to \c ir_depth_layout_none if and only if this

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to