From: Mikko Rasa Date: Sat, 23 Dec 2023 16:16:25 +0000 (+0200) Subject: Don't make the result variable of an inlined builtin function a builtin X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=8ae3a11fd1feb6f490b5e5b229c4891abc1e4a0d;p=libs%2Fgl.git Don't make the result variable of an inlined builtin function a builtin A few builtin function overloads are actually defined in the builtins module and can be inlined. However the GLSL formatter skips any builtin statements, which caused the variable to go missing. --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 6b2f1a03..51377594 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -235,7 +235,7 @@ void InlineContentInjector::visit(Return &ret) // Create a new variable to hold the return value of the inlined function. r_result_name = get_unused_variable_name(staging_block, "_return"); unique_ptr var = make_unique(); - var->source = ret.source; + var->source = (ret.source==BUILTIN_SOURCE ? GENERATED_SOURCE : ret.source); var->line = ret.line; var->type = source_func->return_type; var->name = r_result_name; diff --git a/tests/glsl/inline_builtin.glsl b/tests/glsl/inline_builtin.glsl new file mode 100644 index 00000000..eb2747e9 --- /dev/null +++ b/tests/glsl/inline_builtin.glsl @@ -0,0 +1,21 @@ +#pragma MSP stage(vertex) +layout(location=0) in vec4 pos1; +layout(location=1) in vec4 pos2; +layout(location=2) in float weight; +void main() +{ + vec4 p = mix(pos1, pos2, weight); + gl_Position = p+p; +} + +/* Expected output: vertex +layout(location=0) in vec4 pos1; +layout(location=1) in vec4 pos2; +layout(location=2) in float weight; +void main() +{ + vec4 _return = mix(pos1, pos2, vec4(weight)); + gl_Position = _return+_return; + gl_Position.z = gl_Position.z*2.0-gl_Position.w; +} +*/