Fix completion of functions with struct param/return type in shaders
This commit is contained in:
parent
b7feebefab
commit
246a760323
|
@ -362,7 +362,7 @@ void ShaderCompiler::_dump_function_deps(const SL::ShaderNode *p_node, const Str
|
||||||
}
|
}
|
||||||
header += _constr(fnode->arguments[i].is_const);
|
header += _constr(fnode->arguments[i].is_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].struct_name) + " " + _mkid(fnode->arguments[i].name);
|
||||||
} else {
|
} else {
|
||||||
header += _qualstr(fnode->arguments[i].qualifier) + _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
|
header += _qualstr(fnode->arguments[i].qualifier) + _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
|
||||||
}
|
}
|
||||||
|
@ -743,7 +743,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
|
||||||
gcode += _constr(true);
|
gcode += _constr(true);
|
||||||
gcode += _prestr(cnode.precision, ShaderLanguage::is_float_type(cnode.type));
|
gcode += _prestr(cnode.precision, ShaderLanguage::is_float_type(cnode.type));
|
||||||
if (cnode.type == SL::TYPE_STRUCT) {
|
if (cnode.type == SL::TYPE_STRUCT) {
|
||||||
gcode += _mkid(cnode.type_str);
|
gcode += _mkid(cnode.struct_name);
|
||||||
} else {
|
} else {
|
||||||
gcode += _typestr(cnode.type);
|
gcode += _typestr(cnode.type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1389,7 +1389,7 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea
|
||||||
*r_data_type = function->arguments[i].type;
|
*r_data_type = function->arguments[i].type;
|
||||||
}
|
}
|
||||||
if (r_struct_name) {
|
if (r_struct_name) {
|
||||||
*r_struct_name = function->arguments[i].type_str;
|
*r_struct_name = function->arguments[i].struct_name;
|
||||||
}
|
}
|
||||||
if (r_array_size) {
|
if (r_array_size) {
|
||||||
*r_array_size = function->arguments[i].array_size;
|
*r_array_size = function->arguments[i].array_size;
|
||||||
|
@ -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;
|
*r_array_size = shader->constants[p_identifier].array_size;
|
||||||
}
|
}
|
||||||
if (r_struct_name) {
|
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 (r_constant_value) {
|
||||||
if (shader->constants[p_identifier].initializer && shader->constants[p_identifier].initializer->values.size() == 1) {
|
if (shader->constants[p_identifier].initializer && shader->constants[p_identifier].initializer->values.size() == 1) {
|
||||||
|
@ -3432,7 +3432,7 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const FunctionI
|
||||||
}
|
}
|
||||||
String func_arg_name;
|
String func_arg_name;
|
||||||
if (pfunc->arguments[j].type == TYPE_STRUCT) {
|
if (pfunc->arguments[j].type == TYPE_STRUCT) {
|
||||||
func_arg_name = pfunc->arguments[j].type_str;
|
func_arg_name = pfunc->arguments[j].struct_name;
|
||||||
} else {
|
} else {
|
||||||
func_arg_name = get_datatype_name(pfunc->arguments[j].type);
|
func_arg_name = get_datatype_name(pfunc->arguments[j].type);
|
||||||
}
|
}
|
||||||
|
@ -3455,10 +3455,10 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const FunctionI
|
||||||
for (int j = 0; j < args.size(); j++) {
|
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)) {
|
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
|
//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;
|
String func_arg_name;
|
||||||
if (pfunc->arguments[j].type == TYPE_STRUCT) {
|
if (pfunc->arguments[j].type == TYPE_STRUCT) {
|
||||||
func_arg_name = pfunc->arguments[j].type_str;
|
func_arg_name = pfunc->arguments[j].struct_name;
|
||||||
} else {
|
} else {
|
||||||
func_arg_name = get_datatype_name(pfunc->arguments[j].type);
|
func_arg_name = get_datatype_name(pfunc->arguments[j].type);
|
||||||
}
|
}
|
||||||
|
@ -9228,7 +9228,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
|
||||||
ShaderNode::Constant constant;
|
ShaderNode::Constant constant;
|
||||||
constant.name = name;
|
constant.name = name;
|
||||||
constant.type = is_struct ? TYPE_STRUCT : type;
|
constant.type = is_struct ? TYPE_STRUCT : type;
|
||||||
constant.type_str = struct_name;
|
constant.struct_name = struct_name;
|
||||||
constant.precision = precision;
|
constant.precision = precision;
|
||||||
constant.initializer = nullptr;
|
constant.initializer = nullptr;
|
||||||
constant.array_size = array_size;
|
constant.array_size = array_size;
|
||||||
|
@ -9407,7 +9407,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
|
||||||
|
|
||||||
expr->datatype = constant.type;
|
expr->datatype = constant.type;
|
||||||
|
|
||||||
expr->struct_name = constant.type_str;
|
expr->struct_name = constant.struct_name;
|
||||||
|
|
||||||
expr->array_size = constant.array_size;
|
expr->array_size = constant.array_size;
|
||||||
|
|
||||||
|
@ -9748,7 +9748,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
|
||||||
FunctionNode::Argument arg;
|
FunctionNode::Argument arg;
|
||||||
arg.type = param_type;
|
arg.type = param_type;
|
||||||
arg.name = param_name;
|
arg.name = param_name;
|
||||||
arg.type_str = param_struct_name;
|
arg.struct_name = param_struct_name;
|
||||||
arg.precision = param_precision;
|
arg.precision = param_precision;
|
||||||
arg.qualifier = param_qualifier;
|
arg.qualifier = param_qualifier;
|
||||||
arg.tex_argument_check = false;
|
arg.tex_argument_check = false;
|
||||||
|
@ -10371,7 +10371,11 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_
|
||||||
if (shader->vfunctions[i].name == completion_function) {
|
if (shader->vfunctions[i].name == completion_function) {
|
||||||
String calltip;
|
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) {
|
if (shader->vfunctions[i].function->return_array_size > 0) {
|
||||||
calltip += "[";
|
calltip += "[";
|
||||||
|
@ -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 += " ";
|
||||||
calltip += shader->vfunctions[i].function->arguments[j].name;
|
calltip += shader->vfunctions[i].function->arguments[j].name;
|
||||||
|
|
||||||
|
|
|
@ -583,7 +583,7 @@ public:
|
||||||
ArgumentQualifier qualifier;
|
ArgumentQualifier qualifier;
|
||||||
StringName name;
|
StringName name;
|
||||||
DataType type;
|
DataType type;
|
||||||
StringName type_str;
|
StringName struct_name;
|
||||||
DataPrecision precision;
|
DataPrecision precision;
|
||||||
//for passing textures as arguments
|
//for passing textures as arguments
|
||||||
bool tex_argument_check;
|
bool tex_argument_check;
|
||||||
|
@ -618,7 +618,7 @@ public:
|
||||||
struct Constant {
|
struct Constant {
|
||||||
StringName name;
|
StringName name;
|
||||||
DataType type;
|
DataType type;
|
||||||
StringName type_str;
|
StringName struct_name;
|
||||||
DataPrecision precision;
|
DataPrecision precision;
|
||||||
ConstantNode *initializer = nullptr;
|
ConstantNode *initializer = nullptr;
|
||||||
int array_size;
|
int array_size;
|
||||||
|
|
Loading…
Reference in New Issue