]> git.tdb.fi Git - libs/gl.git/commitdiff
Count EmitVertex as referencing all active outputs
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Mar 2021 11:05:41 +0000 (13:05 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Mar 2021 13:33:38 +0000 (15:33 +0200)
source/glsl/optimize.cpp
tests/glsl/conditional_multiple_emitvertex.glsl [new file with mode: 0644]

index 080bfd7c2705001a40fdf8b97abeb9401c4821bd..441a73a072e8df7740c27b62f9d3c5cc1f9596b2 100644 (file)
@@ -728,6 +728,13 @@ void UnusedVariableRemover::visit(FunctionCall &call)
        /* Treat function calls as having side effects so expression statements
        consisting of nothing but a function call won't be optimized away. */
        r_side_effects = true;
+
+       if(stage->type==Stage::GEOMETRY && call.name=="EmitVertex")
+       {
+               for(map<Statement *, VariableInfo>::const_iterator i=variables.begin(); i!=variables.end(); ++i)
+                       if(i->second.output)
+                               referenced(i->first, call);
+       }
 }
 
 void UnusedVariableRemover::record_assignment(const Assignment::Target &target, Node &node)
diff --git a/tests/glsl/conditional_multiple_emitvertex.glsl b/tests/glsl/conditional_multiple_emitvertex.glsl
new file mode 100644 (file)
index 0000000..09bf25d
--- /dev/null
@@ -0,0 +1,76 @@
+uniform bool flag;
+uniform sampler2D tex;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+void main()
+{
+       out vec2 texcoord = position.xy*0.5+0.5;
+       gl_Position = position;
+}
+
+#pragma MSP stage(geometry)
+layout(triangles) in;
+layout(triangles, max_vertices=3) out;
+void main()
+{
+       passthrough[0];
+       if(flag)
+               EmitVertex();
+       passthrough[1];
+       if(flag)
+               EmitVertex();
+       passthrough[2];
+       if(flag)
+               EmitVertex();
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       frag_color = texture(tex, texcoord);
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+out vec2 texcoord;
+void main()
+{
+       texcoord = position.xy*0.5+0.5;
+       gl_Position = position;
+}
+*/
+
+/* Expected output: geometry
+uniform bool flag;
+layout(triangles) in;
+layout(triangles, max_vertices=3) out;
+in vec2 texcoord[];
+out vec2 _gs_out_texcoord;
+void main()
+{
+       gl_Position = gl_in[0].gl_Position;
+       _gs_out_texcoord = texcoord[0];
+       if(flag)
+               EmitVertex();
+       gl_Position = gl_in[1].gl_Position;
+       _gs_out_texcoord = texcoord[1];
+       if(flag)
+               EmitVertex();
+       gl_Position = gl_in[2].gl_Position;
+       _gs_out_texcoord = texcoord[2];
+       if(flag)
+               EmitVertex();
+}
+*/
+
+/* Expected output: fragment
+uniform sampler2D tex;
+layout(location=0) out vec4 frag_color;
+in vec2 _gs_out_texcoord;
+void main()
+{
+       frag_color = texture(tex, _gs_out_texcoord);
+}
+*/