From: Mikko Rasa Date: Mon, 8 Mar 2021 14:05:57 +0000 (+0200) Subject: Resolve functions after inlining expressions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a60a60fe29850ef8a5dc291ed70741eeb95d9e0b;p=libs%2Fgl.git Resolve functions after inlining expressions This fixes a bug introduced in c1d3a1d. --- diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index ccfbe691..e46e5401 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -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 index 00000000..419f3f2c --- /dev/null +++ b/tests/glsl/keep_used_function.glsl @@ -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)); +} +*/