]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix some bugs with name conflicts in function inlining
authorMikko Rasa <tdb@tdb.fi>
Sun, 14 Mar 2021 17:13:02 +0000 (19:13 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 14 Mar 2021 23:15:33 +0000 (01:15 +0200)
One of these is a regression from b89239e, but the other has been around
for longer.

source/glsl/optimize.cpp
tests/glsl/function_inline_multi_name_conflict.glsl [new file with mode: 0644]
tests/glsl/multiple_function_inline.glsl [new file with mode: 0644]

index c4118dee205d09f2f84c1e468001b6c6706de1c9..2a9bfb17273aa743c7dd7af8608065f7b66058a0 100644 (file)
@@ -90,6 +90,9 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta
                inlined.push_back(r_inlined_statement);
        }
 
+       // Insert the variables here to enable further inlinings to avoid conflicts.
+       tgt_blk.variables.insert(variable_map.begin(), variable_map.end());
+
        SetForScope<unsigned> set_remap(remap_names, 1);
        SetForScope<string> set_prefix(remap_prefix, target_func.name);
        variable_map.clear();
diff --git a/tests/glsl/function_inline_multi_name_conflict.glsl b/tests/glsl/function_inline_multi_name_conflict.glsl
new file mode 100644 (file)
index 0000000..6740b94
--- /dev/null
@@ -0,0 +1,30 @@
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in float scale;
+layout(location=2) in float size;
+float get_scale()
+{
+       float s = scale*2.0;
+       return s*s;
+}
+float get_size()
+{
+       float s = size*0.5;
+       return s*s;
+}
+void main()
+{
+       gl_Position = position*get_scale()*get_size();
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+layout(location=1) in float scale;
+layout(location=2) in float size;
+void main()
+{
+       float s = scale*2.0;
+       float _get_size_s = size*0.5;
+       gl_Position = position*s*s*_get_size_s*_get_size_s;
+}
+*/
diff --git a/tests/glsl/multiple_function_inline.glsl b/tests/glsl/multiple_function_inline.glsl
new file mode 100644 (file)
index 0000000..aedfa93
--- /dev/null
@@ -0,0 +1,24 @@
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in float scale;
+vec4 get_position()
+{
+       return position;
+}
+float get_scale()
+{
+       return scale;
+}
+void main()
+{
+       gl_Position = get_position()*get_scale();
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+layout(location=1) in float scale;
+void main()
+{
+       gl_Position = position*scale;
+}
+*/