[Mesa-dev] [PATCH V2 1/3] allow builtin functions to require parameters to be shader inputs
Chris Forbes
chrisf at ijw.co.nz
Mon Nov 11 23:45:02 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.
V2: Don't abuse ir_var_mode_shader_in for this; make a new flag.
Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
src/glsl/ast_function.cpp | 18 ++++++++++++++++++
src/glsl/ir.h | 6 ++++++
src/glsl/ir_clone.cpp | 1 +
3 files changed, 25 insertions(+)
diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 2707522..8730e71 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->must_be_shader_input) {
+ 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) {
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 2f06fb9..7b905ef 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -600,6 +600,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
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index b0f173a..3d5ea50 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -69,6 +69,7 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
var->depth_layout = this->depth_layout;
var->assigned = this->assigned;
var->used = this->used;
+ var->must_be_shader_input = this->must_be_shader_input;
var->num_state_slots = this->num_state_slots;
if (this->state_slots) {
--
1.8.4.2
More information about the mesa-dev
mailing list