]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't make the result variable of an inlined builtin function a builtin
authorMikko Rasa <tdb@tdb.fi>
Sat, 23 Dec 2023 16:16:25 +0000 (18:16 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 23 Dec 2023 16:22:05 +0000 (18:22 +0200)
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.

source/glsl/optimize.cpp
tests/glsl/inline_builtin.glsl [new file with mode: 0644]

index 6b2f1a0348ec1f8eaa8b380fc543c5a4a7f48e75..51377594272734db5a5de7d233a3fc033c2a8dab 100644 (file)
@@ -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<VariableDeclaration> var = make_unique<VariableDeclaration>();
-               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 (file)
index 0000000..eb2747e
--- /dev/null
@@ -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;
+}
+*/