]> git.tdb.fi Git - libs/gl.git/commitdiff
Resolve functions after inlining expressions
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Mar 2021 14:05:57 +0000 (16:05 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Mar 2021 15:28:21 +0000 (17:28 +0200)
This fixes a bug introduced in c1d3a1d.

source/glsl/compiler.cpp
tests/glsl/keep_used_function.glsl [new file with mode: 0644]

index ccfbe691195eefd91aa4314281db6afc1bb97c97..e46e5401a8fbe452e8175cc622545d7f52caf6f7 100644 (file)
@@ -312,7 +312,7 @@ Compiler::OptimizeResult Compiler::optimize(Stage &stage)
        }
        if(ExpressionInliner().apply(stage))
        {
-               resolve(stage, RESOLVE_VARIABLES|RESOLVE_EXPRESSIONS);
+               resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS|RESOLVE_EXPRESSIONS);
                any_inlined = true;
        }
 
diff --git a/tests/glsl/keep_used_function.glsl b/tests/glsl/keep_used_function.glsl
new file mode 100644 (file)
index 0000000..419f3f2
--- /dev/null
@@ -0,0 +1,26 @@
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in vec2 scale;
+float square(float arg)
+{
+       return arg*arg;
+}
+void main()
+{
+       float x_sq = square(scale.x);
+       float y_sq = square(scale.y);
+       gl_Position = position*sqrt(x_sq+y_sq);
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+layout(location=1) in vec2 scale;
+float square(float arg)
+{
+       return arg*arg;
+}
+void main()
+{
+       gl_Position = position*sqrt(square(scale.x)+square(scale.y));
+}
+*/