ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_draw_indirect / vertexid.c
blobbba2b026e0937d43dee93ea263ced5bf326bb6fe
1 /* Copyright © 2014 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
23 /** @file vertexid.c
24 * Test indirect renderinger with gl_VertexID
26 * When rendering with glDrawArraysIndirect, the value of gl_VertexID observed
27 * in the shader should start with the value of 'first' and increment from
28 * there.
30 * When rendering with glDrawElementsIndirect, the value of gl_VertexID
31 * observed in the shader should be the value retrieved from the index buffer
32 * plus the value of basevertex.
34 * Run the program with no parameters to use glDrawArraysIndirect, or run the
35 * program with "elements" parameter to use glDrawElementsIndirect.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config.supports_gl_core_version = 31;
43 config.supports_gl_compat_version = 31;
45 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
46 config.khr_no_error_support = PIGLIT_NO_ERRORS;
48 PIGLIT_GL_TEST_CONFIG_END
50 static const float green[] = { 0, 1, 0, 1 };
51 static const float blue[] = { 0, 0, 1, 1 };
52 static const float gold[] = { 1, 1, 0, 1 };
53 static const float magenta[] = { 1, 0, 1, 1 };
55 typedef struct {
56 GLuint count;
57 GLuint primCount;
58 GLuint first;
59 GLuint reservedMustBeZero;
60 } DrawArraysIndirectCommand;
62 typedef struct {
63 GLuint count;
64 GLuint primCount;
65 GLuint firstIndex;
66 GLint baseVertex;
67 GLuint reservedMustBeZero;
68 } DrawElementsIndirectCommand;
70 static const DrawArraysIndirectCommand arrays_commands[] = {
71 { 4, 1, 4, 0 },
72 { 4, 1, 8, 0 },
73 { 4, 1, 12, 0 },
74 { 4, 1, 16, 0 },
77 static const DrawElementsIndirectCommand elements_commands[ARRAY_SIZE(arrays_commands)] = {
78 { 4, 1, 0, 4, 0 },
79 { 4, 1, 0, 8, 0 },
80 { 4, 1, 0, 12, 0 },
81 { 4, 1, 0, 16, 0 },
84 static bool use_arrays = true;
86 enum piglit_result
87 piglit_display(void)
89 bool pass = true;
90 unsigned i;
92 glViewport(0, 0, piglit_width, piglit_height);
93 glClearColor(0.2, 0.2, 0.2, 0.2);
94 glClear(GL_COLOR_BUFFER_BIT);
96 for (i = 0; i < ARRAY_SIZE(arrays_commands); i++) {
97 if (use_arrays) {
98 glDrawArraysIndirect(GL_TRIANGLE_FAN,
99 (void *)(sizeof(arrays_commands[0]) * i));
100 } else {
101 glDrawElementsIndirect(GL_TRIANGLE_FAN,
102 GL_UNSIGNED_INT,
103 (void *)(sizeof(elements_commands[0]) * i));
107 pass = piglit_probe_rect_rgba(0, 0,
108 piglit_width / 2, piglit_height /2,
109 green)
110 && pass;
111 pass = piglit_probe_rect_rgba(piglit_width / 2, 0,
112 piglit_width / 2, piglit_height / 2,
113 blue)
114 && pass;
115 pass = piglit_probe_rect_rgba(0, piglit_height /2,
116 piglit_width / 2, piglit_height / 2,
117 gold)
118 && pass;
119 pass = piglit_probe_rect_rgba(piglit_width / 2, piglit_height /2,
120 piglit_width / 2, piglit_height / 2,
121 magenta)
122 && pass;
124 piglit_present_results();
126 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
129 void
130 piglit_init(int argc, char **argv)
132 static const GLuint indices[] = { 0, 1, 2, 3 };
133 static const GLfloat verts[] = {
134 /* These vertices should never be accessed due to the way
135 * glDrawArraysIndirect and glDrawElementsIndirect are called.
137 -0.5, -0.5,
138 0.5, -0.5,
139 0.5, 0.5,
140 -0.5, 0.5,
142 -1.0, -1.0,
143 0.0, -1.0,
144 0.0, 0.0,
145 -1.0, 0.0,
147 0.0, -1.0,
148 1.0, -1.0,
149 1.0, 0.0,
150 0.0, 0.0,
152 -1.0, 0.0,
153 0.0, 0.0,
154 0.0, 1.0,
155 -1.0, 1.0,
157 0.0, 0.0,
158 1.0, 0.0,
159 1.0, 1.0,
160 0.0, 1.0,
163 GLuint prog = piglit_build_simple_program(
164 "#version 140\n"
165 "\n"
166 "in vec4 piglit_vertex;\n"
167 "out vec3 c;\n"
168 "\n"
169 "const vec3 colors[] = vec3[](\n"
170 " vec3(1, 0, 0),\n"
171 " vec3(1, 0, 0),\n"
172 " vec3(1, 0, 0),\n"
173 " vec3(1, 0, 0),\n"
174 "\n"
175 " vec3(0, 1, 0),\n"
176 " vec3(0, 1, 0),\n"
177 " vec3(0, 1, 0),\n"
178 " vec3(0, 1, 0),\n"
179 "\n"
180 " vec3(0, 0, 1),\n"
181 " vec3(0, 0, 1),\n"
182 " vec3(0, 0, 1),\n"
183 " vec3(0, 0, 1),\n"
184 "\n"
185 " vec3(1, 1, 0),\n"
186 " vec3(1, 1, 0),\n"
187 " vec3(1, 1, 0),\n"
188 " vec3(1, 1, 0),\n"
189 "\n"
190 " vec3(1, 0, 1),\n"
191 " vec3(1, 0, 1),\n"
192 " vec3(1, 0, 1),\n"
193 " vec3(1, 0, 1)\n"
194 ");\n"
195 "void main() {\n"
196 " c = colors[gl_VertexID];\n"
197 " gl_Position = piglit_vertex;\n"
198 "}\n",
200 "#version 140\n"
201 "in vec3 c;\n"
202 "out vec4 fragcolor;\n"
203 "\n"
204 "void main() {\n"
205 " fragcolor = vec4(c, 1);\n"
206 "}\n");
208 GLuint vao;
209 GLuint buf[3];
211 piglit_require_extension("GL_ARB_draw_indirect");
213 use_arrays = (argc < 2 || strcmp(argv[1], "elements") != 0);
214 printf("Using glDraw%sIndirect...\n",
215 use_arrays ? "Arrays" : "Elements");
217 glUseProgram(prog);
219 glGenVertexArrays(1, &vao);
220 glBindVertexArray(vao);
222 glGenBuffers(ARRAY_SIZE(buf), buf);
223 glBindBuffer(GL_ARRAY_BUFFER, buf[0]);
224 glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts,
225 GL_STATIC_DRAW);
227 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf[1]);
228 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,
229 GL_STATIC_DRAW);
231 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void *) 0);
232 glEnableVertexAttribArray(0);
234 if (use_arrays) {
235 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf[2]);
236 glBufferData(GL_DRAW_INDIRECT_BUFFER,
237 sizeof(arrays_commands),
238 arrays_commands,
239 GL_STATIC_DRAW);
240 } else {
241 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf[2]);
242 glBufferData(GL_DRAW_INDIRECT_BUFFER,
243 sizeof(elements_commands),
244 elements_commands,
245 GL_STATIC_DRAW);