Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix completion of functions with struct param/return type in shaders #92464

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions servers/rendering/shader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ void ShaderCompiler::_dump_function_deps(const SL::ShaderNode *p_node, const Str
}
header += _constr(fnode->arguments[i].is_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);
header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].struct_name) + " " + _mkid(fnode->arguments[i].name);
} else {
header += _qualstr(fnode->arguments[i].qualifier) + _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
}
Expand Down Expand Up @@ -743,7 +743,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
gcode += _constr(true);
gcode += _prestr(cnode.precision, ShaderLanguage::is_float_type(cnode.type));
if (cnode.type == SL::TYPE_STRUCT) {
gcode += _mkid(cnode.type_str);
gcode += _mkid(cnode.struct_name);
} else {
gcode += _typestr(cnode.type);
}
Expand Down
28 changes: 18 additions & 10 deletions servers/rendering/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea
*r_data_type = function->arguments[i].type;
}
if (r_struct_name) {
*r_struct_name = function->arguments[i].type_str;
*r_struct_name = function->arguments[i].struct_name;
}
if (r_array_size) {
*r_array_size = function->arguments[i].array_size;
Expand Down Expand Up @@ -1442,7 +1442,7 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea
*r_array_size = shader->constants[p_identifier].array_size;
}
if (r_struct_name) {
*r_struct_name = shader->constants[p_identifier].type_str;
*r_struct_name = shader->constants[p_identifier].struct_name;
}
if (r_constant_value) {
if (shader->constants[p_identifier].initializer && shader->constants[p_identifier].initializer->values.size() == 1) {
Expand Down Expand Up @@ -3432,7 +3432,7 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const FunctionI
}
String func_arg_name;
if (pfunc->arguments[j].type == TYPE_STRUCT) {
func_arg_name = pfunc->arguments[j].type_str;
func_arg_name = pfunc->arguments[j].struct_name;
} else {
func_arg_name = get_datatype_name(pfunc->arguments[j].type);
}
Expand All @@ -3455,10 +3455,10 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const FunctionI
for (int j = 0; j < args.size(); j++) {
if (get_scalar_type(args[j]) == args[j] && p_func->arguments[j + 1]->type == Node::NODE_TYPE_CONSTANT && args3[j] == 0 && convert_constant(static_cast<ConstantNode *>(p_func->arguments[j + 1]), pfunc->arguments[j].type)) {
//all good, but it needs implicit conversion later
} else if (args[j] != pfunc->arguments[j].type || (args[j] == TYPE_STRUCT && args2[j] != pfunc->arguments[j].type_str) || args3[j] != pfunc->arguments[j].array_size) {
} else if (args[j] != pfunc->arguments[j].type || (args[j] == TYPE_STRUCT && args2[j] != pfunc->arguments[j].struct_name) || args3[j] != pfunc->arguments[j].array_size) {
String func_arg_name;
if (pfunc->arguments[j].type == TYPE_STRUCT) {
func_arg_name = pfunc->arguments[j].type_str;
func_arg_name = pfunc->arguments[j].struct_name;
} else {
func_arg_name = get_datatype_name(pfunc->arguments[j].type);
}
Expand Down Expand Up @@ -9228,7 +9228,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
ShaderNode::Constant constant;
constant.name = name;
constant.type = is_struct ? TYPE_STRUCT : type;
constant.type_str = struct_name;
constant.struct_name = struct_name;
constant.precision = precision;
constant.initializer = nullptr;
constant.array_size = array_size;
Expand Down Expand Up @@ -9407,7 +9407,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f

expr->datatype = constant.type;

expr->struct_name = constant.type_str;
expr->struct_name = constant.struct_name;

expr->array_size = constant.array_size;

Expand Down Expand Up @@ -9748,7 +9748,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
FunctionNode::Argument arg;
arg.type = param_type;
arg.name = param_name;
arg.type_str = param_struct_name;
arg.struct_name = param_struct_name;
arg.precision = param_precision;
arg.qualifier = param_qualifier;
arg.tex_argument_check = false;
Expand Down Expand Up @@ -10371,7 +10371,11 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_
if (shader->vfunctions[i].name == completion_function) {
String calltip;

calltip += get_datatype_name(shader->vfunctions[i].function->return_type);
if (shader->vfunctions[i].function->return_type == TYPE_STRUCT) {
calltip += String(shader->vfunctions[i].function->return_struct_name);
} else {
calltip += get_datatype_name(shader->vfunctions[i].function->return_type);
}

if (shader->vfunctions[i].function->return_array_size > 0) {
calltip += "[";
Expand Down Expand Up @@ -10406,7 +10410,11 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_
}
}

calltip += get_datatype_name(shader->vfunctions[i].function->arguments[j].type);
if (shader->vfunctions[i].function->arguments[j].type == TYPE_STRUCT) {
calltip += String(shader->vfunctions[i].function->arguments[j].struct_name);
} else {
calltip += get_datatype_name(shader->vfunctions[i].function->arguments[j].type);
}
calltip += " ";
calltip += shader->vfunctions[i].function->arguments[j].name;

Expand Down
4 changes: 2 additions & 2 deletions servers/rendering/shader_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ class ShaderLanguage {
ArgumentQualifier qualifier;
StringName name;
DataType type;
StringName type_str;
StringName struct_name;
DataPrecision precision;
//for passing textures as arguments
bool tex_argument_check;
Expand Down Expand Up @@ -618,7 +618,7 @@ class ShaderLanguage {
struct Constant {
StringName name;
DataType type;
StringName type_str;
StringName struct_name;
DataPrecision precision;
ConstantNode *initializer = nullptr;
int array_size;
Expand Down
Loading