Prevent shuffling custom shader functions (shader cache requires determinism)
This commit is contained in:
parent
4c4cb12e38
commit
73793ab89c
4 changed files with 16 additions and 14 deletions
|
@ -229,17 +229,18 @@ void ShaderCompilerGLES2::_dump_function_deps(const SL::ShaderNode *p_node, cons
|
||||||
|
|
||||||
ERR_FAIL_COND(fidx == -1);
|
ERR_FAIL_COND(fidx == -1);
|
||||||
|
|
||||||
for (Set<StringName>::Element *E = p_node->functions[fidx].uses_function.front(); E; E = E->next()) {
|
for (int ufidx = 0; ufidx < p_node->functions[fidx].uses_function.size(); ufidx++) {
|
||||||
if (r_added.has(E->get())) {
|
StringName function_name = p_node->functions[fidx].uses_function[ufidx];
|
||||||
|
if (r_added.has(function_name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_dump_function_deps(p_node, E->get(), p_func_code, r_to_add, r_added);
|
_dump_function_deps(p_node, function_name, p_func_code, r_to_add, r_added);
|
||||||
|
|
||||||
SL::FunctionNode *fnode = nullptr;
|
SL::FunctionNode *fnode = nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < p_node->functions.size(); i++) {
|
for (int i = 0; i < p_node->functions.size(); i++) {
|
||||||
if (p_node->functions[i].name == E->get()) {
|
if (p_node->functions[i].name == function_name) {
|
||||||
fnode = p_node->functions[i].function;
|
fnode = p_node->functions[i].function;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -272,9 +273,9 @@ void ShaderCompilerGLES2::_dump_function_deps(const SL::ShaderNode *p_node, cons
|
||||||
|
|
||||||
header += ")\n";
|
header += ")\n";
|
||||||
r_to_add += header.as_string();
|
r_to_add += header.as_string();
|
||||||
r_to_add += p_func_code[E->get()];
|
r_to_add += p_func_code[function_name];
|
||||||
|
|
||||||
r_added.insert(E->get());
|
r_added.insert(function_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -354,17 +354,18 @@ void ShaderCompilerGLES3::_dump_function_deps(const SL::ShaderNode *p_node, cons
|
||||||
|
|
||||||
ERR_FAIL_COND(fidx == -1);
|
ERR_FAIL_COND(fidx == -1);
|
||||||
|
|
||||||
for (Set<StringName>::Element *E = p_node->functions[fidx].uses_function.front(); E; E = E->next()) {
|
for (int ufidx = 0; ufidx < p_node->functions[fidx].uses_function.size(); ufidx++) {
|
||||||
if (added.has(E->get())) {
|
StringName function_name = p_node->functions[fidx].uses_function[ufidx];
|
||||||
|
if (added.has(function_name)) {
|
||||||
continue; //was added already
|
continue; //was added already
|
||||||
}
|
}
|
||||||
|
|
||||||
_dump_function_deps(p_node, E->get(), p_func_code, r_to_add, added);
|
_dump_function_deps(p_node, function_name, p_func_code, r_to_add, added);
|
||||||
|
|
||||||
SL::FunctionNode *fnode = nullptr;
|
SL::FunctionNode *fnode = nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < p_node->functions.size(); i++) {
|
for (int i = 0; i < p_node->functions.size(); i++) {
|
||||||
if (p_node->functions[i].name == E->get()) {
|
if (p_node->functions[i].name == function_name) {
|
||||||
fnode = p_node->functions[i].function;
|
fnode = p_node->functions[i].function;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -396,9 +397,9 @@ void ShaderCompilerGLES3::_dump_function_deps(const SL::ShaderNode *p_node, cons
|
||||||
|
|
||||||
header += ")\n";
|
header += ")\n";
|
||||||
r_to_add += header;
|
r_to_add += header;
|
||||||
r_to_add += p_func_code[E->get()];
|
r_to_add += p_func_code[function_name];
|
||||||
|
|
||||||
added.insert(E->get());
|
added.insert(function_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3405,7 +3405,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||||
//add to current function as dependency
|
//add to current function as dependency
|
||||||
for (int j = 0; j < shader->functions.size(); j++) {
|
for (int j = 0; j < shader->functions.size(); j++) {
|
||||||
if (shader->functions[j].name == current_function) {
|
if (shader->functions[j].name == current_function) {
|
||||||
shader->functions.write[j].uses_function.insert(name);
|
shader->functions.write[j].uses_function.push_back(name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -602,7 +602,7 @@ public:
|
||||||
struct Function {
|
struct Function {
|
||||||
StringName name;
|
StringName name;
|
||||||
FunctionNode *function;
|
FunctionNode *function;
|
||||||
Set<StringName> uses_function;
|
Vector<StringName> uses_function;
|
||||||
bool callable;
|
bool callable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue