]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't try to access parameters with a pointer access instructior
authorMikko Rasa <tdb@tdb.fi>
Sun, 7 Nov 2021 14:01:06 +0000 (16:01 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Nov 2021 14:01:06 +0000 (16:01 +0200)
source/glsl/spirv.cpp
tests/glsl/parameter_composite_access.glsl [new file with mode: 0644]

index d8f24d20b7007342827423cfd3b7d3b5b85bee79..91182a65725f3cae26a509ed588492ba08cfb881 100644 (file)
@@ -518,8 +518,15 @@ void SpirVGenerator::visit(VariableReference &var)
        r_constant_result = false;
        if(composite_access)
        {
-               r_composite_base = var.declaration;
                r_expression_result_id = 0;
+               if(!assignment_source_id)
+               {
+                       auto i = variable_load_ids.find(var.declaration);
+                       if(i!=variable_load_ids.end())
+                               r_expression_result_id = i->second;
+               }
+               if(!r_expression_result_id)
+                       r_composite_base = var.declaration;
        }
        else if(assignment_source_id)
        {
diff --git a/tests/glsl/parameter_composite_access.glsl b/tests/glsl/parameter_composite_access.glsl
new file mode 100644 (file)
index 0000000..718fffd
--- /dev/null
@@ -0,0 +1,60 @@
+uniform Colors
+{
+       vec4 top_color;
+       vec4 bottom_color;
+};
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in vec3 normal;
+void main()
+{
+       gl_Position = position;
+       passthrough;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+vec4 get_color(vec3 n)
+{
+       if(n.z>=0)
+               return top_color;
+       else
+               return bottom_color;
+}
+void main()
+{
+       frag_color = get_color(normal);
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+layout(location=1) in vec3 normal;
+layout(location=0) out vec3 _vs_out_normal;
+void main()
+{
+       gl_Position = position;
+       _vs_out_normal = normal;
+}
+*/
+
+/* Expected output: fragment
+layout(binding=23) uniform Colors
+{
+       vec4 top_color;
+       vec4 bottom_color;
+};
+layout(location=0) out vec4 frag_color;
+vec4 get_color(vec3 n)
+{
+       if(n.z>=0.0)
+               return top_color;
+       else
+               return bottom_color;
+}
+layout(location=0) in vec3 _vs_out_normal;
+void main()
+{
+       frag_color = get_color(_vs_out_normal);
+}
+*/