Merge pull request #37462 from Chaosus/shader_fix_const_order

[3.2] Fix shader constant sorting
This commit is contained in:
Rémi Verschelde 2020-04-29 09:41:49 +02:00 committed by GitHub
commit f2150d1766
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 10 deletions

View file

@ -368,14 +368,14 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener
// constants
for (Map<StringName, SL::ShaderNode::Constant>::Element *E = snode->constants.front(); E; E = E->next()) {
for (int i = 0; i < snode->vconstants.size(); i++) {
String gcode;
gcode += "const ";
gcode += _prestr(E->get().precision);
gcode += _typestr(E->get().type);
gcode += " " + _mkid(E->key());
gcode += _prestr(snode->vconstants[i].precision);
gcode += _typestr(snode->vconstants[i].type);
gcode += " " + _mkid(String(snode->vconstants[i].name));
gcode += "=";
gcode += _dump_node_code(E->get().initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += _dump_node_code(snode->vconstants[i].initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += ";\n";
vertex_global += gcode;
fragment_global += gcode;

View file

@ -440,14 +440,14 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
r_gen_code.fragment_global += interp_mode + "in " + vcode;
}
for (Map<StringName, SL::ShaderNode::Constant>::Element *E = pnode->constants.front(); E; E = E->next()) {
for (int i = 0; i < pnode->vconstants.size(); i++) {
String gcode;
gcode += "const ";
gcode += _prestr(E->get().precision);
gcode += _typestr(E->get().type);
gcode += " " + _mkid(E->key());
gcode += _prestr(pnode->vconstants[i].precision);
gcode += _typestr(pnode->vconstants[i].type);
gcode += " " + _mkid(String(pnode->vconstants[i].name));
gcode += "=";
gcode += _dump_node_code(E->get().initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += _dump_node_code(pnode->vconstants[i].initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += ";\n";
r_gen_code.vertex_global += gcode;
r_gen_code.fragment_global += gcode;

View file

@ -5156,6 +5156,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
while (true) {
ShaderNode::Constant constant;
constant.name = name;
constant.type = type;
constant.precision = precision;
constant.initializer = NULL;
@ -5190,6 +5191,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
}
shader->constants[name] = constant;
shader->vconstants.push_back(constant);
if (tk.type == TK_COMMA) {
tk = _get_token();
if (tk.type != TK_IDENTIFIER) {

View file

@ -512,6 +512,7 @@ public:
struct ShaderNode : public Node {
struct Constant {
StringName name;
DataType type;
DataPrecision precision;
ConstantNode *initializer;
@ -577,6 +578,7 @@ public:
Vector<StringName> render_modes;
Vector<Function> functions;
Vector<Constant> vconstants;
ShaderNode() :
Node(TYPE_SHADER) {}