1# Reproduces the bug in Mesa issue 3150. 2# 3# The geometry shader takes in points and outputs three squares as 4# triangle strip primitives. The middle square is conditionally 5# emitted depending on a vertex attribute. On V3D, this makes the 6# offset for the vertex data of the final square non-uniform across 7# the lanes and needs special handling. 8[require] 9GL ES >= 3.1 10GLSL ES >= 3.1 11GL_OES_geometry_shader 12 13[vertex shader] 14#version 310 es 15 16layout(location = 0) in vec2 pos; 17layout(location = 1) in float middle; 18 19out float middle_g; 20 21void 22main() 23{ 24 gl_Position = vec4(pos, 0.0, 1.0); 25 middle_g = middle; 26} 27 28[geometry shader] 29#version 310 es 30#extension GL_OES_geometry_shader : require 31 32layout(points) in; 33layout(triangle_strip, max_vertices = 12) out; 34 35in float middle_g[]; 36 37void 38emit_square(vec2 pos) 39{ 40 /* Emit a square centered at pos whose width is ¼ of the 41 * framebuffer and whose height is ⅓. 42 */ 43 for (float y = -1.0; y <= 1.0; y += 2.0) { 44 for (float x = -1.0; x <= 1.0; x += 2.0) { 45 gl_Position = vec4(pos.x + x * 2.0 / 8.0, 46 pos.y + y * 2.0 / 6.0, 47 0.0, 48 1.0); 49 EmitVertex(); 50 } 51 } 52 53 EndPrimitive(); 54} 55 56void 57main() 58{ 59 /* Top square */ 60 emit_square(vec2(gl_in[0].gl_Position.x, 1.0 - 2.0 / 6.0)); 61 62 /* Optionally emit the middle square */ 63 if (middle_g[0] > 0.5) 64 emit_square(vec2(gl_in[0].gl_Position.x, 0.0)); 65 66 /* Bottom square */ 67 emit_square(vec2(gl_in[0].gl_Position.x, 2.0 / 6.0 - 1.0)); 68} 69 70[fragment shader] 71#version 310 es 72 73layout(location = 0) mediump out vec4 color_out; 74 75void 76main() 77{ 78 color_out = vec4(0.0, 1.0, 0.0, 1.0); 79} 80 81[vertex data] 82pos/float/2 middle/float/1 83-0.75 0.0 1.0 84-0.25 0.0 1.0 85# Don’t draw the middle section for the points on the right-hand side 860.25 0.0 0.0 870.75 0.0 0.0 88 89[test] 90clear color 0.0 0.0 1.0 1.0 91clear 92 93draw arrays GL_POINTS 0 4 94 95# Top third should all be green 96relative probe rect rgb (0.0, 0.0, 1.0, 0.32) (0.0, 1.0, 0.0) 97 98# Middle section should be half green half blue 99relative probe rect rgb (0.0, 0.34, 0.5, 0.31) (0.0, 1.0, 0.0) 100relative probe rect rgb (0.5, 0.34, 0.5, 0.31) (0.0, 0.0, 1.0) 101 102# Bottom third should be all green 103relative probe rect rgb (0.0, 0.67, 1.0, 0.31) (0.0, 1.0, 0.0) 104