glsl: reduce geometry shader complexity

output 1 strip of 2 triangles instead of 2 strips of 1 triangle.

Potentially it would reduce the geometry shader overhead. And it
might avoid a middle line in sprite in some AMD GPU/driver/OS
bad combination
This commit is contained in:
Gregory Hainaut 2017-07-02 22:37:24 +02:00
parent 38010432ee
commit c5d35d434c
1 changed files with 15 additions and 50 deletions

View File

@ -99,7 +99,7 @@ struct vertex
vec4 c; vec4 c;
}; };
void out_vertex(in vertex v) void out_vertex(in vec4 position, in vertex v)
{ {
GSout.t_float = v.t_float; GSout.t_float = v.t_float;
GSout.t_int = v.t_int; GSout.t_int = v.t_int;
@ -110,6 +110,7 @@ void out_vertex(in vertex v)
#else #else
GSout.fc = GSin[1].fc; GSout.fc = GSin[1].fc;
#endif #endif
gl_Position = position;
gl_PrimitiveID = gl_PrimitiveIDIn; gl_PrimitiveID = gl_PrimitiveIDIn;
EmitVertex(); EmitVertex();
} }
@ -119,7 +120,7 @@ layout(points) in;
#else #else
layout(lines) in; layout(lines) in;
#endif #endif
layout(triangle_strip, max_vertices = 6) out; layout(triangle_strip, max_vertices = 4) out;
#if GS_POINT == 1 #if GS_POINT == 1
@ -136,26 +137,14 @@ void gs_main()
lb_p.x = lt_p.x; lb_p.x = lt_p.x;
rt_p.y = lt_p.y; rt_p.y = lt_p.y;
// Triangle 1 out_vertex(lt_p, point);
gl_Position = lt_p;
out_vertex(point);
gl_Position = lb_p; out_vertex(lb_p, point);
out_vertex(point);
gl_Position = rt_p; out_vertex(rt_p, point);
out_vertex(point);
EndPrimitive();
// Triangle 2 out_vertex(rb_p, point);
gl_Position = lb_p;
out_vertex(point);
gl_Position = rt_p;
out_vertex(point);
gl_Position = rb_p;
out_vertex(point);
EndPrimitive(); EndPrimitive();
} }
@ -177,26 +166,14 @@ void gs_main()
vec4 lb_p = gl_in[0].gl_Position + vec4(line_width, 0.0f, 0.0f); vec4 lb_p = gl_in[0].gl_Position + vec4(line_width, 0.0f, 0.0f);
vec4 rb_p = gl_in[1].gl_Position + vec4(line_width, 0.0f, 0.0f); vec4 rb_p = gl_in[1].gl_Position + vec4(line_width, 0.0f, 0.0f);
// Triangle 1 out_vertex(lt_p, left);
gl_Position = lt_p;
out_vertex(left);
gl_Position = lb_p; out_vertex(lb_p, left);
out_vertex(left);
gl_Position = rt_p; out_vertex(rt_p, right);
out_vertex(right);
EndPrimitive();
// Triangle 2 out_vertex(rb_p, right);
gl_Position = lb_p;
out_vertex(left);
gl_Position = rt_p;
out_vertex(right);
gl_Position = rb_p;
out_vertex(right);
EndPrimitive(); EndPrimitive();
} }
@ -234,26 +211,14 @@ void gs_main()
rt.t_int.y = lt.t_int.y; rt.t_int.y = lt.t_int.y;
rt.t_int.w = lt.t_int.w; rt.t_int.w = lt.t_int.w;
// Triangle 1 out_vertex(lt_p, lt);
gl_Position = lt_p;
out_vertex(lt);
gl_Position = lb_p; out_vertex(lb_p, lb);
out_vertex(lb);
gl_Position = rt_p; out_vertex(rt_p, rt);
out_vertex(rt);
EndPrimitive();
// Triangle 2 out_vertex(rb_p, rb);
gl_Position = lb_p;
out_vertex(lb);
gl_Position = rt_p;
out_vertex(rt);
gl_Position = rb_p;
out_vertex(rb);
EndPrimitive(); EndPrimitive();
} }