From e76de6e7ba324194716b8a40d83353a4c1dc824c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 14 Mar 2021 19:13:02 +0200 Subject: [PATCH] Fix some bugs with name conflicts in function inlining One of these is a regression from b89239e, but the other has been around for longer. --- source/glsl/optimize.cpp | 3 ++ .../function_inline_multi_name_conflict.glsl | 30 +++++++++++++++++++ tests/glsl/multiple_function_inline.glsl | 24 +++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tests/glsl/function_inline_multi_name_conflict.glsl create mode 100644 tests/glsl/multiple_function_inline.glsl diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index c4118dee..2a9bfb17 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -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 set_remap(remap_names, 1); SetForScope 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 index 00000000..6740b944 --- /dev/null +++ b/tests/glsl/function_inline_multi_name_conflict.glsl @@ -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 index 00000000..aedfa93f --- /dev/null +++ b/tests/glsl/multiple_function_inline.glsl @@ -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; +} +*/ -- 2.43.0