[Mesa-dev] [RFC PATCH 1/5] allow builtin functions to require parameters to be shader inputs

Chris Forbes chrisf at ijw.co.nz
Sun Nov 10 00:51:07 PST 2013


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.

Reuse ir_var_shader_in variable mode in a parameter list to express
this constraint.

Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
 src/glsl/ast_function.cpp | 19 +++++++++++++++++++
 src/glsl/ir_function.cpp  |  1 +
 2 files changed, 20 insertions(+)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 2707522..08fa631 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -131,6 +131,24 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
 	 return false;
       }
 
+      /* Verify that shader_in parameters are shader inputs */
+      if (formal->mode == ir_var_shader_in) {
+         ir_variable *var = actual->variable_referenced();
+         if (var && var->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->mode == ir_var_function_out
           || formal->mode == ir_var_function_inout) {
@@ -306,6 +324,7 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
       if (formal->type->is_numeric() || formal->type->is_boolean()) {
 	 switch (formal->mode) {
 	 case ir_var_const_in:
+         case ir_var_shader_in:
 	 case ir_var_function_in: {
 	    ir_rvalue *converted
 	       = convert_component(actual, formal->type);
diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp
index 53cf469..332210c 100644
--- a/src/glsl/ir_function.cpp
+++ b/src/glsl/ir_function.cpp
@@ -89,6 +89,7 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
 	 break;
 
       case ir_var_function_inout:
+      case ir_var_shader_in:
 	 /* Since there are no bi-directional automatic conversions (e.g.,
 	  * there is int -> float but no float -> int), inout parameters must
 	  * be exact matches.
-- 
1.8.4.2



More information about the mesa-dev mailing list