ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_atomic_counters / unused-result.c
blob83dd43f1809cf71304b2ba1757efadceee41abbd
1 /*
2 * Copyright © 2013-2014 Intel Corporation
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /** @file unused-result.c
26 * Tests that the atomic built-in functions have the expected effects
27 * on the buffer, even if the result of the atomic op is unused within
28 * the shader.
31 #include "common.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_core_version = 31;
37 config.window_width = 1;
38 config.window_height = 1;
39 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
40 config.khr_no_error_support = PIGLIT_NO_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
44 static bool
45 run_test_vertex(void)
47 const char *fs_source = "#version 140\n"
48 "out ivec4 fcolor;\n"
49 "void main() {\n"
50 " fcolor = ivec4(0);\n"
51 "}\n";
52 const char *vs_source = "#version 140\n"
53 "#extension GL_ARB_shader_atomic_counters : enable\n"
54 "\n"
55 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
56 "in vec4 piglit_vertex;\n"
57 "\n"
58 "void main() {\n"
59 " atomicCounterIncrement(x);\n"
60 " gl_Position = piglit_vertex;\n"
61 "}\n";
62 const uint32_t start_buffer[] = { 0x0 };
63 const uint32_t expected_buffer[] = { 0x1 };
64 const uint32_t expected_color[] = { 0x0, 0x0, 0x0, 0x0 };
65 GLuint prog = glCreateProgram();
66 bool ret =
67 atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
68 atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
69 atomic_counters_draw_point(prog, 1, start_buffer) &&
70 piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
71 atomic_counters_probe_buffer(0, 1, expected_buffer);
73 glDeleteProgram(prog);
74 return ret;
77 static bool
78 run_test_fragment(void)
80 const char *fs_source = "#version 140\n"
81 "#extension GL_ARB_shader_atomic_counters : enable\n"
82 "\n"
83 "out ivec4 fcolor;\n"
84 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
85 "\n"
86 "void main() {\n"
87 " atomicCounterIncrement(x);\n"
89 " fcolor = ivec4(0);\n"
90 "}\n";
91 const char *vs_source = "#version 140\n"
92 "#extension GL_ARB_shader_atomic_counters : enable\n"
93 "\n"
94 "in vec4 piglit_vertex;\n"
95 "\n"
96 "void main() {\n"
97 " gl_Position = piglit_vertex;\n"
98 "}\n";
99 const uint32_t start_buffer[] = { 0x0 };
100 const uint32_t expected_buffer[] = { 0x1 };
101 const uint32_t expected_color[] = { 0x0, 0x0, 0x0, 0x0 };
102 GLuint prog = glCreateProgram();
103 bool ret =
104 atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
105 atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
106 atomic_counters_draw_point(prog, 1, start_buffer) &&
107 piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
108 atomic_counters_probe_buffer(0, 1, expected_buffer);
110 glDeleteProgram(prog);
111 return ret;
114 static bool
115 run_test_geometry(void)
117 const char *fs_source = "#version 140\n"
118 "out ivec4 fcolor;\n"
119 "void main() {\n"
120 " fcolor = ivec4(0);\n"
121 "}\n";
122 const char *gs_source = "#version 150\n"
123 "#extension GL_ARB_shader_atomic_counters : enable\n"
124 "\n"
125 "layout(points) in;\n"
126 "layout(points, max_vertices=1) out;\n"
127 "\n"
128 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
129 "\n"
130 "void main() {\n"
131 " gl_Position = gl_in[0].gl_Position;\n"
132 " atomicCounterIncrement(x);\n"
133 " EmitVertex();\n"
134 "}\n";
135 const char *vs_source = "#version 140\n"
136 "\n"
137 "in vec4 piglit_vertex;\n"
138 "\n"
139 "void main() {\n"
140 " gl_Position = piglit_vertex;\n"
141 "}\n";
142 const uint32_t start_buffer[] = { 0x0 };
143 const uint32_t expected_buffer[] = { 0x1 };
144 const uint32_t expected_color[] = { 0x0, 0x0, 0x0, 0x0 };
145 GLuint prog = glCreateProgram();
146 bool ret =
147 atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
148 atomic_counters_compile(prog, GL_GEOMETRY_SHADER, gs_source) &&
149 atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
150 atomic_counters_draw_point(prog, 1, start_buffer) &&
151 piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
152 atomic_counters_probe_buffer(0, 1, expected_buffer);
154 glDeleteProgram(prog);
155 return ret;
158 static bool
159 run_test_tess_control(void)
161 const char *fs_source = "#version 140\n"
162 "out ivec4 fg;\n"
163 "void main() {\n"
164 " fg = ivec4(0);\n"
165 "}\n";
166 const char *tes_source = "#version 150\n"
167 "#extension GL_ARB_tessellation_shader : enable\n"
168 "\n"
169 "layout(triangles, point_mode) in;\n"
170 "\n"
171 "\n"
172 "void main() {\n"
173 " gl_Position = gl_in[0].gl_Position * gl_TessCoord.x +\n"
174 " gl_in[1].gl_Position * gl_TessCoord.y +\n"
175 " gl_in[2].gl_Position * gl_TessCoord.z;\n"
176 " \n"
177 "}\n";
178 const char *tcs_source = "#version 150\n"
179 "#extension GL_ARB_tessellation_shader : enable\n"
180 "#extension GL_ARB_shader_atomic_counters : enable\n"
181 "\n"
182 "layout(vertices=3) out;\n"
183 "\n"
184 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
185 "\n"
186 "void main() {\n"
187 " if (gl_InvocationID == 0) {\n"
188 " gl_TessLevelInner[0] = 1;\n"
189 " \n"
190 " gl_TessLevelOuter[0] = 1;\n"
191 " gl_TessLevelOuter[1] = 1;\n"
192 " gl_TessLevelOuter[2] = 1;\n"
193 " \n"
194 " atomicCounterIncrement(x);\n"
195 " }\n"
196 " \n"
197 " gl_out[gl_InvocationID].gl_Position =\n"
198 " gl_in[gl_InvocationID].gl_Position;\n"
199 "}\n";
200 const char *vs_source = "#version 140\n"
201 "\n"
202 "in vec4 piglit_vertex;\n"
203 "\n"
204 "void main() {\n"
205 " gl_Position = piglit_vertex;\n"
206 "}\n";
207 const uint32_t start_buffer[] = { 0x0 };
208 const uint32_t expected_buffer[] = { 0x1 };
209 const uint32_t expected_color[] = { 0x0, 0x0, 0x0, 0x0 };
210 GLuint prog = glCreateProgram();
211 bool ret =
212 atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
213 atomic_counters_compile(prog, GL_TESS_EVALUATION_SHADER,
214 tes_source) &&
215 atomic_counters_compile(prog, GL_TESS_CONTROL_SHADER,
216 tcs_source) &&
217 atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
218 atomic_counters_draw_patch(prog, 1, start_buffer) &&
219 piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
220 atomic_counters_probe_buffer(0, 1, expected_buffer);
222 glDeleteProgram(prog);
223 return ret;
226 static bool
227 run_test_tess_evaluation(void)
229 const char *fs_source = "#version 140\n"
230 "out ivec4 fg;\n"
231 "void main() {\n"
232 " fg = ivec4(0);\n"
233 "}\n";
234 const char *tes_source = "#version 150\n"
235 "#extension GL_ARB_shader_atomic_counters : enable\n"
236 "#extension GL_ARB_tessellation_shader : enable\n"
237 "\n"
238 "layout(triangles, point_mode) in;\n"
239 "\n"
240 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
241 "\n"
242 "void main() {\n"
243 " gl_Position = gl_in[0].gl_Position * gl_TessCoord.x +\n"
244 " gl_in[1].gl_Position * gl_TessCoord.y +\n"
245 " gl_in[2].gl_Position * gl_TessCoord.z;\n"
246 " \n"
247 " if (gl_TessCoord.z == 1.0) {\n"
248 " atomicCounterIncrement(x);\n"
249 " }\n"
250 "}\n";
251 const char *tcs_source = "#version 150\n"
252 "#extension GL_ARB_tessellation_shader : enable\n"
253 "\n"
254 "layout(vertices=3) out;\n"
255 "\n"
256 "void main() {\n"
257 " if (gl_InvocationID == 0) {\n"
258 " gl_TessLevelInner[0] = 1;\n"
259 " \n"
260 " gl_TessLevelOuter[0] = 1;\n"
261 " gl_TessLevelOuter[1] = 1;\n"
262 " gl_TessLevelOuter[2] = 1;\n"
263 " }\n"
264 " \n"
265 " gl_out[gl_InvocationID].gl_Position =\n"
266 " gl_in[gl_InvocationID].gl_Position;\n"
267 "}\n";
268 const char *vs_source = "#version 140\n"
269 "\n"
270 "in vec4 piglit_vertex;\n"
271 "\n"
272 "void main() {\n"
273 " gl_Position = piglit_vertex;\n"
274 "}\n";
275 const uint32_t start_buffer[] = { 0x0 };
276 const uint32_t expected_buffer[] = { 0x1 };
277 const uint32_t expected_color[] = { 0x0, 0x0, 0x0, 0x0 };
278 GLuint prog = glCreateProgram();
279 bool ret =
280 atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
281 atomic_counters_compile(prog, GL_TESS_EVALUATION_SHADER,
282 tes_source) &&
283 atomic_counters_compile(prog, GL_TESS_CONTROL_SHADER,
284 tcs_source) &&
285 atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
286 atomic_counters_draw_patch(prog, 1, start_buffer) &&
287 piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
288 atomic_counters_probe_buffer(0, 1, expected_buffer);
290 glDeleteProgram(prog);
291 return ret;
294 void
295 piglit_init(int argc, char **argv)
297 GLuint fb, rb, buffer;
298 enum piglit_result status = PIGLIT_PASS;
300 piglit_require_extension("GL_ARB_shader_atomic_counters");
302 glGenFramebuffers(1, &fb);
303 glGenRenderbuffers(1, &rb);
305 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb);
306 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
307 glBindRenderbuffer(GL_RENDERBUFFER, rb);
309 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32UI, 1, 1);
310 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
311 GL_RENDERBUFFER, rb);
313 glGenBuffers(1, &buffer);
314 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, buffer);
316 atomic_counters_subtest(&status, GL_FRAGMENT_SHADER,
317 "Fragment shader atomic built-in semantics",
318 run_test_fragment);
320 atomic_counters_subtest(&status, GL_VERTEX_SHADER,
321 "Vertex shader atomic built-in semantics",
322 run_test_vertex);
324 atomic_counters_subtest(&status, GL_GEOMETRY_SHADER,
325 "Geometry shader atomic built-in semantics",
326 run_test_geometry);
328 atomic_counters_subtest(&status, GL_TESS_CONTROL_SHADER,
329 "Tessellation control shader atomic built-in "
330 "semantics",
331 run_test_tess_control);
333 atomic_counters_subtest(&status, GL_TESS_EVALUATION_SHADER,
334 "Tessellation evaluation shader atomic built-in "
335 "semantics",
336 run_test_tess_evaluation);
338 piglit_report_result(status);
341 enum piglit_result
342 piglit_display(void)
344 /* UNREACHED */
345 return PIGLIT_FAIL;