1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Allow shader arrays to be passed as parameters and return value

This commit is contained in:
Yuri Roubinsky
2021-05-21 19:16:23 +03:00
parent 234a101eb3
commit 5874b7a29c
3 changed files with 942 additions and 425 deletions

View File

@@ -391,10 +391,21 @@ void ShaderCompilerRD::_dump_function_deps(const SL::ShaderNode *p_node, const S
String header;
if (fnode->return_type == SL::TYPE_STRUCT) {
header = _mkid(fnode->return_struct_name) + " " + _mkid(fnode->name) + "(";
header = _mkid(fnode->return_struct_name);
} else {
header = _typestr(fnode->return_type) + " " + _mkid(fnode->name) + "(";
header = _typestr(fnode->return_type);
}
if (fnode->return_array_size > 0) {
header += "[";
header += itos(fnode->return_array_size);
header += "]";
}
header += " ";
header += _mkid(fnode->name);
header += "(";
for (int i = 0; i < fnode->arguments.size(); i++) {
if (i > 0) {
header += ", ";
@@ -407,6 +418,11 @@ void ShaderCompilerRD::_dump_function_deps(const SL::ShaderNode *p_node, const S
} else {
header += _qualstr(fnode->arguments[i].qualifier) + _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
}
if (fnode->arguments[i].array_size > 0) {
header += "[";
header += itos(fnode->arguments[i].array_size);
header += "]";
}
}
header += ")\n";
@@ -959,25 +975,30 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
declaration += itos(adnode->declarations[i].size);
}
declaration += "]";
int sz = adnode->declarations[i].initializer.size();
if (sz > 0) {
if (adnode->declarations[i].single_expression) {
declaration += "=";
if (adnode->datatype == SL::TYPE_STRUCT) {
declaration += _mkid(adnode->struct_name);
} else {
declaration += _typestr(adnode->datatype);
}
declaration += "[";
declaration += itos(sz);
declaration += "]";
declaration += "(";
for (int j = 0; j < sz; j++) {
declaration += _dump_node_code(adnode->declarations[i].initializer[j], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
if (j != sz - 1) {
declaration += ", ";
declaration += _dump_node_code(adnode->declarations[i].initializer[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
} else {
int sz = adnode->declarations[i].initializer.size();
if (sz > 0) {
declaration += "=";
if (adnode->datatype == SL::TYPE_STRUCT) {
declaration += _mkid(adnode->struct_name);
} else {
declaration += _typestr(adnode->datatype);
}
declaration += "[";
declaration += itos(sz);
declaration += "]";
declaration += "(";
for (int j = 0; j < sz; j++) {
declaration += _dump_node_code(adnode->declarations[i].initializer[j], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
if (j != sz - 1) {
declaration += ", ";
}
}
declaration += ")";
}
declaration += ")";
}
}
@@ -988,7 +1009,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
bool use_fragment_varying = false;
if (!(p_actions.entry_point_stages.has(current_func_name) && p_actions.entry_point_stages[current_func_name] == STAGE_VERTEX)) {
if (anode->assign_expression != nullptr) {
if (anode->assign_expression != nullptr && shader->varyings.has(anode->name)) {
use_fragment_varying = true;
} else {
if (p_assigning) {