Merge pull request #37795 from Chaosus/shader_fix_const_order2
Fix shader constant sorting
This commit is contained in:
commit
0bf6a86db4
@ -404,18 +404,19 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener
|
|||||||
|
|
||||||
// constants
|
// 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++) {
|
||||||
|
const SL::ShaderNode::Constant &cnode = snode->vconstants[i];
|
||||||
String gcode;
|
String gcode;
|
||||||
gcode += "const ";
|
gcode += "const ";
|
||||||
gcode += _prestr(E->get().precision);
|
gcode += _prestr(cnode.precision);
|
||||||
if (E->get().type == SL::TYPE_STRUCT) {
|
if (cnode.type == SL::TYPE_STRUCT) {
|
||||||
gcode += _mkid(E->get().type_str);
|
gcode += _mkid(cnode.type_str);
|
||||||
} else {
|
} else {
|
||||||
gcode += _typestr(E->get().type);
|
gcode += _typestr(cnode.type);
|
||||||
}
|
}
|
||||||
gcode += " " + _mkid(E->key());
|
gcode += " " + _mkid(String(cnode.name));
|
||||||
gcode += "=";
|
gcode += "=";
|
||||||
gcode += _dump_node_code(E->get().initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
gcode += _dump_node_code(cnode.initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
||||||
gcode += ";\n";
|
gcode += ";\n";
|
||||||
vertex_global += gcode;
|
vertex_global += gcode;
|
||||||
fragment_global += gcode;
|
fragment_global += gcode;
|
||||||
|
@ -650,18 +650,19 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map<StringName, SL::ShaderNode::Constant>::Element *E = pnode->constants.front(); E; E = E->next()) {
|
for (int i = 0; i < pnode->vconstants.size(); i++) {
|
||||||
|
const SL::ShaderNode::Constant &cnode = pnode->vconstants[i];
|
||||||
String gcode;
|
String gcode;
|
||||||
gcode += "const ";
|
gcode += "const ";
|
||||||
gcode += _prestr(E->get().precision);
|
gcode += _prestr(cnode.precision);
|
||||||
if (E->get().type == SL::TYPE_STRUCT) {
|
if (cnode.type == SL::TYPE_STRUCT) {
|
||||||
gcode += _mkid(E->get().type_str);
|
gcode += _mkid(cnode.type_str);
|
||||||
} else {
|
} else {
|
||||||
gcode += _typestr(E->get().type);
|
gcode += _typestr(cnode.type);
|
||||||
}
|
}
|
||||||
gcode += " " + _mkid(E->key());
|
gcode += " " + _mkid(String(cnode.name));
|
||||||
gcode += "=";
|
gcode += "=";
|
||||||
gcode += _dump_node_code(E->get().initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
gcode += _dump_node_code(cnode.initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
||||||
gcode += ";\n";
|
gcode += ";\n";
|
||||||
r_gen_code.vertex_global += gcode;
|
r_gen_code.vertex_global += gcode;
|
||||||
r_gen_code.fragment_global += gcode;
|
r_gen_code.fragment_global += gcode;
|
||||||
|
@ -6334,6 +6334,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ShaderNode::Constant constant;
|
ShaderNode::Constant constant;
|
||||||
|
constant.name = name;
|
||||||
constant.type = is_struct ? TYPE_STRUCT : type;
|
constant.type = is_struct ? TYPE_STRUCT : type;
|
||||||
constant.type_str = struct_name;
|
constant.type_str = struct_name;
|
||||||
constant.precision = precision;
|
constant.precision = precision;
|
||||||
@ -6373,6 +6374,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
|
|||||||
}
|
}
|
||||||
|
|
||||||
shader->constants[name] = constant;
|
shader->constants[name] = constant;
|
||||||
|
shader->vconstants.push_back(constant);
|
||||||
|
|
||||||
if (tk.type == TK_COMMA) {
|
if (tk.type == TK_COMMA) {
|
||||||
tk = _get_token();
|
tk = _get_token();
|
||||||
if (tk.type != TK_IDENTIFIER) {
|
if (tk.type != TK_IDENTIFIER) {
|
||||||
|
@ -607,6 +607,7 @@ public:
|
|||||||
struct ShaderNode : public Node {
|
struct ShaderNode : public Node {
|
||||||
|
|
||||||
struct Constant {
|
struct Constant {
|
||||||
|
StringName name;
|
||||||
DataType type;
|
DataType type;
|
||||||
StringName type_str;
|
StringName type_str;
|
||||||
DataPrecision precision;
|
DataPrecision precision;
|
||||||
@ -698,6 +699,7 @@ public:
|
|||||||
Vector<StringName> render_modes;
|
Vector<StringName> render_modes;
|
||||||
|
|
||||||
Vector<Function> functions;
|
Vector<Function> functions;
|
||||||
|
Vector<Constant> vconstants;
|
||||||
Vector<Struct> vstructs;
|
Vector<Struct> vstructs;
|
||||||
|
|
||||||
ShaderNode() :
|
ShaderNode() :
|
||||||
|
Loading…
Reference in New Issue
Block a user