Backport latest varying fixes to 3.x

This commit is contained in:
Yuri Roubinsky 2021-07-22 08:43:12 +03:00
parent 40b57319e2
commit 1e128c80c6

View file

@ -2180,6 +2180,11 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
}
StringName var_name = static_cast<const VariableNode *>(p_func->arguments[arg_idx + 1])->name;
if (shader->varyings.has(var_name)) {
_set_error(vformat("Varyings cannot be passed for '%s' parameter!", "out"));
return false;
}
const BlockNode *b = p_block;
bool valid = false;
while (b) {
@ -2776,8 +2781,8 @@ bool ShaderLanguage::_is_operator_assign(Operator p_op) const {
}
bool ShaderLanguage::_validate_varying_assign(ShaderNode::Varying &p_varying, String *r_message) {
if (current_function == String("light")) {
*r_message = RTR("Varying may not be assigned in the 'light' function.");
if (current_function != String("vertex") && current_function != String("fragment")) {
*r_message = vformat(RTR("Varying may not be assigned in the '%s' function."), current_function);
return false;
}
switch (p_varying.stage) {
@ -2788,12 +2793,15 @@ bool ShaderLanguage::_validate_varying_assign(ShaderNode::Varying &p_varying, St
p_varying.stage = ShaderNode::Varying::STAGE_FRAGMENT;
}
break;
case ShaderNode::Varying::STAGE_VERTEX_TO_FRAGMENT:
case ShaderNode::Varying::STAGE_VERTEX_TO_LIGHT:
case ShaderNode::Varying::STAGE_VERTEX:
if (current_function == String("fragment")) {
*r_message = RTR("Varyings which assigned in 'vertex' function may not be reassigned in 'fragment' or 'light'.");
return false;
}
break;
case ShaderNode::Varying::STAGE_FRAGMENT_TO_LIGHT:
case ShaderNode::Varying::STAGE_FRAGMENT:
if (current_function == String("vertex")) {
*r_message = RTR("Varyings which assigned in 'fragment' function may not be reassigned in 'vertex' or 'light'.");
@ -3429,6 +3437,10 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
} else if (shader->uniforms.has(varname)) {
error = true;
} else {
if (shader->varyings.has(varname)) {
_set_error(vformat("Varyings cannot be passed for '%s' parameter!", _get_qualifier_str(call_function->arguments[i].qualifier)));
return nullptr;
}
if (p_builtin_types.has(varname)) {
BuiltInInfo info = p_builtin_types[varname];
if (info.constant) {
@ -6335,14 +6347,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
tk = _get_token();
}
for (Map<StringName, ShaderNode::Varying>::Element *E = shader->varyings.front(); E; E = E->next()) {
if (E->get().stage == ShaderNode::Varying::STAGE_VERTEX || E->get().stage == ShaderNode::Varying::STAGE_FRAGMENT) {
_set_tkpos(E->get().tkpos);
_set_error(RTR("Varying must only be used in two different stages, which can be 'vertex' 'fragment' and 'light'"));
return ERR_PARSE_ERROR;
}
}
return OK;
}