summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2020-04-11 12:40:17 +0300
committerYuri Roubinsky <chaosus89@gmail.com>2020-04-11 12:40:17 +0300
commitbc30f541e60f7236b0463072d31cc5322d78ecd2 (patch)
treedb82e4ae0690506b1b246f561d92cbfa2ca80c5e
parent8806e7d5f3e65a06be1b0a58dc73442e58fdf469 (diff)
Fix shader constant sorting
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp15
-rw-r--r--servers/rendering/rasterizer_rd/shader_compiler_rd.cpp15
-rw-r--r--servers/rendering/shader_language.cpp3
-rw-r--r--servers/rendering/shader_language.h2
4 files changed, 21 insertions, 14 deletions
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index 699d6e1484..92c1ada850 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -404,18 +404,19 @@ 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++) {
+ const SL::ShaderNode::Constant &cnode = snode->vconstants[i];
String gcode;
gcode += "const ";
- gcode += _prestr(E->get().precision);
- if (E->get().type == SL::TYPE_STRUCT) {
- gcode += _mkid(E->get().type_str);
+ gcode += _prestr(cnode.precision);
+ if (cnode.type == SL::TYPE_STRUCT) {
+ gcode += _mkid(cnode.type_str);
} else {
- gcode += _typestr(E->get().type);
+ gcode += _typestr(cnode.type);
}
- gcode += " " + _mkid(E->key());
+ gcode += " " + _mkid(String(cnode.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(cnode.initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += ";\n";
vertex_global += gcode;
fragment_global += gcode;
diff --git a/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp b/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp
index 4a0b4f02b1..e9c541a68d 100644
--- a/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp
+++ b/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp
@@ -547,18 +547,19 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
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;
gcode += "const ";
- gcode += _prestr(E->get().precision);
- if (E->get().type == SL::TYPE_STRUCT) {
- gcode += _mkid(E->get().type_str);
+ gcode += _prestr(cnode.precision);
+ if (cnode.type == SL::TYPE_STRUCT) {
+ gcode += _mkid(cnode.type_str);
} else {
- gcode += _typestr(E->get().type);
+ gcode += _typestr(cnode.type);
}
- gcode += " " + _mkid(E->key());
+ gcode += " " + _mkid(String(cnode.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(cnode.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;
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp
index 76a81a4a1c..6b5fde5ab5 100644
--- a/servers/rendering/shader_language.cpp
+++ b/servers/rendering/shader_language.cpp
@@ -6219,6 +6219,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
while (true) {
ShaderNode::Constant constant;
+ constant.name = name;
constant.type = is_struct ? TYPE_STRUCT : type;
constant.type_str = struct_name;
constant.precision = precision;
@@ -6258,6 +6259,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) {
diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h
index beabae0dda..44333cad9e 100644
--- a/servers/rendering/shader_language.h
+++ b/servers/rendering/shader_language.h
@@ -599,6 +599,7 @@ public:
struct ShaderNode : public Node {
struct Constant {
+ StringName name;
DataType type;
StringName type_str;
DataPrecision precision;
@@ -681,6 +682,7 @@ public:
Vector<StringName> render_modes;
Vector<Function> functions;
+ Vector<Constant> vconstants;
Vector<Struct> vstructs;
ShaderNode() :