Merge pull request #40010 from Chaosus/shader_func_arg_const_qual
Added const qualifier support for function arguments in shaders
This commit is contained in:
commit
77e4794721
4 changed files with 30 additions and 1 deletions
|
@ -247,6 +247,9 @@ void ShaderCompilerGLES2::_dump_function_deps(SL::ShaderNode *p_node, const Stri
|
|||
for (int i = 0; i < fnode->arguments.size(); i++) {
|
||||
if (i > 0)
|
||||
header += ", ";
|
||||
if (fnode->arguments[i].is_const) {
|
||||
header += "const ";
|
||||
}
|
||||
if (fnode->arguments[i].type == SL::TYPE_STRUCT) {
|
||||
header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].type_str) + " " + _mkid(fnode->arguments[i].name);
|
||||
} else {
|
||||
|
|
|
@ -399,6 +399,9 @@ void ShaderCompilerRD::_dump_function_deps(const SL::ShaderNode *p_node, const S
|
|||
if (i > 0) {
|
||||
header += ", ";
|
||||
}
|
||||
if (fnode->arguments[i].is_const) {
|
||||
header += "const ";
|
||||
}
|
||||
if (fnode->arguments[i].type == SL::TYPE_STRUCT) {
|
||||
header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].type_str) + " " + _mkid(fnode->arguments[i].name);
|
||||
} else {
|
||||
|
|
|
@ -982,6 +982,9 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea
|
|||
if (r_struct_name) {
|
||||
*r_struct_name = function->arguments[i].type_str;
|
||||
}
|
||||
if (r_is_const) {
|
||||
*r_is_const = function->arguments[i].is_const;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3553,7 +3556,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
|||
for (int i = 0; i < call_function->arguments.size(); i++) {
|
||||
int argidx = i + 1;
|
||||
if (argidx < func->arguments.size()) {
|
||||
if (call_function->arguments[i].qualifier == ArgumentQualifier::ARGUMENT_QUALIFIER_OUT || call_function->arguments[i].qualifier == ArgumentQualifier::ARGUMENT_QUALIFIER_INOUT) {
|
||||
if (call_function->arguments[i].is_const || call_function->arguments[i].qualifier == ArgumentQualifier::ARGUMENT_QUALIFIER_OUT || call_function->arguments[i].qualifier == ArgumentQualifier::ARGUMENT_QUALIFIER_INOUT) {
|
||||
bool error = false;
|
||||
Node *n = func->arguments[argidx];
|
||||
if (n->type == Node::TYPE_CONSTANT || n->type == Node::TYPE_OPERATOR) {
|
||||
|
@ -6780,15 +6783,29 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
|
|||
break;
|
||||
}
|
||||
|
||||
bool is_const = false;
|
||||
if (tk.type == TK_CONST) {
|
||||
is_const = true;
|
||||
tk = _get_token();
|
||||
}
|
||||
|
||||
ArgumentQualifier qualifier = ARGUMENT_QUALIFIER_IN;
|
||||
|
||||
if (tk.type == TK_ARG_IN) {
|
||||
qualifier = ARGUMENT_QUALIFIER_IN;
|
||||
tk = _get_token();
|
||||
} else if (tk.type == TK_ARG_OUT) {
|
||||
if (is_const) {
|
||||
_set_error("'out' qualifier cannot be used within a function parameter declared with 'const'.");
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
qualifier = ARGUMENT_QUALIFIER_OUT;
|
||||
tk = _get_token();
|
||||
} else if (tk.type == TK_ARG_INOUT) {
|
||||
if (is_const) {
|
||||
_set_error("'inout' qualifier cannot be used within a function parameter declared with 'const'.");
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
qualifier = ARGUMENT_QUALIFIER_INOUT;
|
||||
tk = _get_token();
|
||||
}
|
||||
|
@ -6877,6 +6894,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
|
|||
arg.tex_builtin_check = false;
|
||||
arg.tex_argument_filter = FILTER_DEFAULT;
|
||||
arg.tex_argument_repeat = REPEAT_DEFAULT;
|
||||
arg.is_const = is_const;
|
||||
|
||||
func_node->arguments.push_back(arg);
|
||||
|
||||
|
@ -7273,6 +7291,10 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
|||
calltip += CharType(0xFFFF);
|
||||
}
|
||||
|
||||
if (shader->functions[i].function->arguments[j].is_const) {
|
||||
calltip += "const ";
|
||||
}
|
||||
|
||||
if (shader->functions[i].function->arguments[j].qualifier != ArgumentQualifier::ARGUMENT_QUALIFIER_IN) {
|
||||
if (shader->functions[i].function->arguments[j].qualifier == ArgumentQualifier::ARGUMENT_QUALIFIER_OUT) {
|
||||
calltip += "out ";
|
||||
|
|
|
@ -554,6 +554,7 @@ public:
|
|||
TextureRepeat tex_argument_repeat;
|
||||
bool tex_builtin_check;
|
||||
StringName tex_builtin;
|
||||
bool is_const;
|
||||
|
||||
Map<StringName, Set<int>> tex_argument_connect;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue