}
static bool
-should_replace_variable(ir_variable *sig_param, ir_rvalue *param) {
+should_replace_variable(ir_variable *sig_param, ir_rvalue *param,
+ bool is_builtin) {
+
+ if (sig_param->data.mode != ir_var_function_in &&
+ sig_param->data.mode != ir_var_const_in)
+ return false;
+
+ /* SSBO and shared vars might be passed to a built-in such as an atomic
+ * memory function, where copying these to a temp before passing to the
+ * atomic function is not valid so we must replace these instead. Also,
+ * shader inputs for interpolateAt funtions also need to be replaced.
+ *
+ * Our builtins should always use temps and not the inputs themselves to
+ * store temporay values so just checking is_builtin rather than string
+ * comparing the function name for e.g atomic* should always be safe.
+ */
+ if (is_builtin)
+ return true;
+
/* For opaque types, we want the inlined variable references
* referencing the passed in variable, since that will have
* the location information, which an assignment of an opaque
* variable wouldn't.
*/
- return sig_param->type->contains_opaque() &&
- param->is_dereference() &&
- sig_param->data.mode == ir_var_function_in;
+ return sig_param->type->contains_opaque();
}
void
ir_rvalue *param = (ir_rvalue *) actual_node;
/* Generate a new variable for the parameter. */
- if (should_replace_variable(sig_param, param)) {
+ if (should_replace_variable(sig_param, param,
+ this->callee->is_builtin())) {
/* Actual replacement happens below */
parameters[i] = NULL;
} else {
ir_rvalue *const param = (ir_rvalue *) actual_node;
ir_variable *sig_param = (ir_variable *) formal_node;
- if (should_replace_variable(sig_param, param)) {
+ if (should_replace_variable(sig_param, param,
+ this->callee->is_builtin())) {
do_variable_replacement(&new_instructions, sig_param, param);
}
}
color2 = y + 1;
}
""",
- r'assign \(x\) \(var_ref x@2\) \(expression float f162f'),
+ r'assign \(x\) \(var_ref compiler_temp@2\) \(expression uint bitcast_f2u \(expression float f162f'),
Test("ldexp",
"""
#version 310 es
color *= carry;
}
""",
- r'expression uint \+ \(var_ref x\) \(var_ref y'),
+ r'expression uint \+ \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref x\) \) \(constant uint16_t \(2\)\) \) \) \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref y'),
Test("usubBorrow",
"""
#version 310 es
color *= borrow;
}
""",
- r'expression uint \- \(var_ref x\) \(var_ref y'),
+ r'expression uint \- \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref x\) \) \(constant uint16_t \(2\)\) \) \) \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref y'),
Test("imulExtended",
"""
#version 310 es