From a60a60fe29850ef8a5dc291ed70741eeb95d9e0b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 8 Mar 2021 16:05:57 +0200 Subject: [PATCH] Resolve functions after inlining expressions This fixes a bug introduced in c1d3a1d. --- source/glsl/compiler.cpp | 2 +- tests/glsl/keep_used_function.glsl | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/glsl/keep_used_function.glsl 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)); +} +*/ -- 2.43.0