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:
Rémi Verschelde 2020-07-01 15:28:58 +02:00 committed by GitHub
commit 77e4794721
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View file

@ -247,6 +247,9 @@ void ShaderCompilerGLES2::_dump_function_deps(SL::ShaderNode *p_node, const Stri
for (int i = 0; i < fnode->arguments.size(); i++) { for (int i = 0; i < fnode->arguments.size(); i++) {
if (i > 0) if (i > 0)
header += ", "; header += ", ";
if (fnode->arguments[i].is_const) {
header += "const ";
}
if (fnode->arguments[i].type == SL::TYPE_STRUCT) { 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); header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].type_str) + " " + _mkid(fnode->arguments[i].name);
} else { } else {

View file

@ -399,6 +399,9 @@ void ShaderCompilerRD::_dump_function_deps(const SL::ShaderNode *p_node, const S
if (i > 0) { if (i > 0) {
header += ", "; header += ", ";
} }
if (fnode->arguments[i].is_const) {
header += "const ";
}
if (fnode->arguments[i].type == SL::TYPE_STRUCT) { 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); header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].type_str) + " " + _mkid(fnode->arguments[i].name);
} else { } else {

View file

@ -982,6 +982,9 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea
if (r_struct_name) { if (r_struct_name) {
*r_struct_name = function->arguments[i].type_str; *r_struct_name = function->arguments[i].type_str;
} }
if (r_is_const) {
*r_is_const = function->arguments[i].is_const;
}
return true; 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++) { for (int i = 0; i < call_function->arguments.size(); i++) {
int argidx = i + 1; int argidx = i + 1;
if (argidx < func->arguments.size()) { 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; bool error = false;
Node *n = func->arguments[argidx]; Node *n = func->arguments[argidx];
if (n->type == Node::TYPE_CONSTANT || n->type == Node::TYPE_OPERATOR) { 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; break;
} }
bool is_const = false;
if (tk.type == TK_CONST) {
is_const = true;
tk = _get_token();
}
ArgumentQualifier qualifier = ARGUMENT_QUALIFIER_IN; ArgumentQualifier qualifier = ARGUMENT_QUALIFIER_IN;
if (tk.type == TK_ARG_IN) { if (tk.type == TK_ARG_IN) {
qualifier = ARGUMENT_QUALIFIER_IN; qualifier = ARGUMENT_QUALIFIER_IN;
tk = _get_token(); tk = _get_token();
} else if (tk.type == TK_ARG_OUT) { } 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; qualifier = ARGUMENT_QUALIFIER_OUT;
tk = _get_token(); tk = _get_token();
} else if (tk.type == TK_ARG_INOUT) { } 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; qualifier = ARGUMENT_QUALIFIER_INOUT;
tk = _get_token(); tk = _get_token();
} }
@ -6877,6 +6894,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
arg.tex_builtin_check = false; arg.tex_builtin_check = false;
arg.tex_argument_filter = FILTER_DEFAULT; arg.tex_argument_filter = FILTER_DEFAULT;
arg.tex_argument_repeat = REPEAT_DEFAULT; arg.tex_argument_repeat = REPEAT_DEFAULT;
arg.is_const = is_const;
func_node->arguments.push_back(arg); func_node->arguments.push_back(arg);
@ -7273,6 +7291,10 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
calltip += CharType(0xFFFF); 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_IN) {
if (shader->functions[i].function->arguments[j].qualifier == ArgumentQualifier::ARGUMENT_QUALIFIER_OUT) { if (shader->functions[i].function->arguments[j].qualifier == ArgumentQualifier::ARGUMENT_QUALIFIER_OUT) {
calltip += "out "; calltip += "out ";

View file

@ -554,6 +554,7 @@ public:
TextureRepeat tex_argument_repeat; TextureRepeat tex_argument_repeat;
bool tex_builtin_check; bool tex_builtin_check;
StringName tex_builtin; StringName tex_builtin;
bool is_const;
Map<StringName, Set<int>> tex_argument_connect; Map<StringName, Set<int>> tex_argument_connect;
}; };