2 * Copyright (c) 2021 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * This test was designed to exercise as many of the Mesa Gallium draw
24 * module's vertex pipeline stages as possible, particularly those which
25 * allocate extra vertex attributes.
27 * It does not yet check for correctness, and is instead meant to be used with
28 * memory debuggers to trap buffer overflows.
31 * Jose Fonseca <jfonseca@vmware.com>
34 #include "piglit-util-gl.h"
36 static const GLint W
= 800;
37 static const GLint H
= 600;
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 30;
43 config
.window_width
= W
;
44 config
.window_height
= H
;
46 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
47 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
49 PIGLIT_GL_TEST_CONFIG_END
56 "flat out vec4 fs_color0;\n"
57 "flat out vec4 fs_color1;\n"
58 "flat out vec4 fs_generic0;\n"
59 "uniform vec4 CS[6];\n"
62 " position = A0.xxxx * CS[0];\n"
63 " position += A0.yyyy * CS[1];\n"
64 " position += A0.zzzz * CS[2];\n"
65 " position += A0.wwww * CS[3];\n"
66 " gl_ClipDistance[0] = dot(position, CS[4]);\n"
67 " gl_ClipDistance[1] = dot(position, CS[5]);\n"
68 " gl_Position = position;\n"
70 " fs_color1 = vec4(0, 0, 0, 0);\n"
71 " fs_generic0 = vec4(0, 0, 0, 1);\n"
78 "#extension GL_EXT_gpu_shader4 : require\n"
79 "flat in vec4 fs_color0;\n"
80 "out vec4 fragColor0;\n"
82 " fragColor0.r = gl_PrimitiveID / 12.0;\n"
83 " fragColor0.g = gl_FrontFacing ? 1.0 : 0.0;\n"
84 " fragColor0.b = fs_color0.b;\n"
85 " fragColor0.a = 1.0;\n"
91 { 0.90533f
, 3.223402e-08f
, -2.673027e-08f
, -2.670354e-08f
},
92 { -2.417551e-08f
, 1.207107f
, 5.346054e-08f
, 5.340707e-08f
},
93 { 4.835103e-08f
, -1.289361e-07f
, 0.5005005f
, 0.5f
},
94 { 0.0f
, 0.0f
, 2.902903f
, 3.0f
},
95 { 0.0f
, 0.0f
, 0.0f
, 0.0f
},
96 { 0.0f
, 0.0f
, 0.0f
, 0.0f
},
99 typedef struct Vertex
{
106 { { -1.0f
, -1.0f
, -1.0f
}, 0xffffffffU
},
107 { { -1.0f
, -1.0f
, 1.0f
}, 0xffffff00U
},
108 { { -1.0f
, 1.0f
, -1.0f
}, 0xffff00ffU
},
109 { { -1.0f
, 1.0f
, 1.0f
}, 0xffff0000U
},
110 { { 1.0f
, -1.0f
, -1.0f
}, 0xff00ffffU
},
111 { { 1.0f
, -1.0f
, 1.0f
}, 0xff00ff00U
},
112 { { 1.0f
, 1.0f
, -1.0f
}, 0xff0000ffU
},
113 { { 1.0f
, 1.0f
, 1.0f
}, 0xff000000U
},
116 static const GLushort
134 { 0x80, 0x80, 0x80, 0x80 },
135 { 0x00, 0x00, 0x00, 0x00 },
136 { 0x00, 0x00, 0x00, 0x00 },
137 { 0x00, 0x00, 0x00, 0x00 },
138 { 0x00, 0x00, 0x00, 0x00 },
139 { 0x00, 0x00, 0x00, 0x00 },
140 { 0x00, 0x00, 0x00, 0x00 },
141 { 0x00, 0x00, 0x00, 0x00 },
142 { 0x80, 0x80, 0x80, 0x80 },
143 { 0x00, 0x00, 0x00, 0x00 },
144 { 0x00, 0x00, 0x00, 0x00 },
145 { 0x00, 0x00, 0x00, 0x00 },
146 { 0x00, 0x00, 0x00, 0x00 },
147 { 0x00, 0x00, 0x00, 0x00 },
148 { 0x00, 0x00, 0x00, 0x00 },
149 { 0x00, 0x00, 0x00, 0x00 },
150 { 0x80, 0x80, 0x80, 0x80 },
151 { 0x00, 0x00, 0x00, 0x00 },
152 { 0x00, 0x00, 0x00, 0x00 },
153 { 0x00, 0x00, 0x00, 0x00 },
154 { 0x00, 0x00, 0x00, 0x00 },
155 { 0x00, 0x00, 0x00, 0x00 },
156 { 0x00, 0x00, 0x00, 0x00 },
157 { 0x00, 0x00, 0x00, 0x00 },
158 { 0x80, 0x80, 0x80, 0x80 },
159 { 0x00, 0x00, 0x00, 0x00 },
160 { 0x00, 0x00, 0x00, 0x00 },
161 { 0x00, 0x00, 0x00, 0x00 },
162 { 0x00, 0x00, 0x00, 0x00 },
163 { 0x00, 0x00, 0x00, 0x00 },
164 { 0x00, 0x00, 0x00, 0x00 },
165 { 0x00, 0x00, 0x00, 0x00 },
168 enum piglit_result
piglit_display(void)
170 GLuint program
= glCreateProgram();
171 GLuint vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
,
173 GLuint fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
,
175 glAttachShader(program
, vs
);
177 glAttachShader(program
, fs
);
179 glBindAttribLocation(program
, 0, "A0");
180 glBindAttribLocation(program
, 1, "A1");
181 glBindFragDataLocation(program
, 0, "fragColor0");
182 glLinkProgram(program
);
183 glDetachShader(program
, fs
);
184 glDetachShader(program
, vs
);
185 if (!piglit_link_check_status(program
)) {
186 glDeleteProgram(program
);
187 piglit_report_result(PIGLIT_FAIL
);
189 glUseProgram(program
);
190 GLint l0
= glGetUniformLocation(program
, "CS[0]");
192 glUniform4fv(l0
, ARRAY_SIZE(uniforms
), uniforms
[0]);
194 glViewport(0, 0, W
, H
);
195 glDepthRange(0.0, 1.0);
196 glEnable(GL_SCISSOR_TEST
);
197 glScissor(0, 0, W
, H
);
198 glDisable(GL_DEPTH_TEST
);
199 glDepthFunc(GL_LESS
);
200 glEnable(GL_CLIP_DISTANCE0
);
201 glEnable(GL_CLIP_DISTANCE1
);
202 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
206 /* Smooth points for front faces.
208 glPolygonMode(GL_FRONT
, GL_POINT
);
209 glEnable(GL_POINT_SMOOTH
);
212 glEnable(GL_POLYGON_STIPPLE
);
213 glPolygonStipple(stipple
[0]);
216 /* Smooth lines for back faces.
218 glPolygonMode(GL_BACK
, GL_LINE
);
219 glEnable(GL_LINE_SMOOTH
);
221 glEnable(GL_LINE_STIPPLE
);
222 glLineStipple(3, 0xfafa);
225 glGenVertexArrays(1, &vao
);
226 glBindVertexArray(vao
);
228 glCreateBuffers(1, &vb
);
229 glBindBuffer(GL_ARRAY_BUFFER
, vb
);
230 glBufferData(GL_ARRAY_BUFFER
, sizeof vertices
, vertices
, GL_STATIC_DRAW
);
232 glCreateBuffers(1, &ib
);
233 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, ib
);
234 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, sizeof indices
, indices
, GL_STATIC_DRAW
);
235 glVertexAttribPointer(0, 3, GL_FLOAT
, GL_FALSE
, sizeof(Vertex
),
236 (const void *)offsetof(Vertex
, position
));
237 glVertexAttribPointer(1, GL_BGRA
, GL_UNSIGNED_BYTE
, GL_TRUE
, sizeof(Vertex
),
238 (const void *)offsetof(Vertex
, color
));
239 glEnableVertexAttribArray(0);
240 glEnableVertexAttribArray(1);
242 glValidateProgram(program
);
243 GLint status
= GL_FALSE
;
244 glGetProgramiv(program
, GL_VALIDATE_STATUS
, &status
);
245 if (status
!= GL_TRUE
) {
246 piglit_report_result(PIGLIT_FAIL
);
249 glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
250 glClear(GL_COLOR_BUFFER_BIT
);
252 glDrawElementsBaseVertex(GL_TRIANGLES
, ARRAY_SIZE(indices
),
253 GL_UNSIGNED_SHORT
, NULL
, 0);
255 piglit_present_results();
257 glBindVertexArray(0);
259 glDeleteBuffers(1, &vb
);
260 glDeleteBuffers(1, &ib
);
261 glDeleteVertexArrays(1, &vao
);
262 glDeleteProgram(program
);
267 void piglit_init(int argc
, char **argv
)
269 piglit_require_extension("GL_EXT_gpu_shader4");