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
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
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
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
47 const char *fs_source
= "#version 140\n"
50 " fcolor = ivec4(0);\n"
52 const char *vs_source
= "#version 140\n"
53 "#extension GL_ARB_shader_atomic_counters : enable\n"
55 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
56 "in vec4 piglit_vertex;\n"
59 " atomicCounterIncrement(x);\n"
60 " gl_Position = piglit_vertex;\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();
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
);
78 run_test_fragment(void)
80 const char *fs_source
= "#version 140\n"
81 "#extension GL_ARB_shader_atomic_counters : enable\n"
84 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
87 " atomicCounterIncrement(x);\n"
89 " fcolor = ivec4(0);\n"
91 const char *vs_source
= "#version 140\n"
92 "#extension GL_ARB_shader_atomic_counters : enable\n"
94 "in vec4 piglit_vertex;\n"
97 " gl_Position = piglit_vertex;\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();
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
);
115 run_test_geometry(void)
117 const char *fs_source
= "#version 140\n"
118 "out ivec4 fcolor;\n"
120 " fcolor = ivec4(0);\n"
122 const char *gs_source
= "#version 150\n"
123 "#extension GL_ARB_shader_atomic_counters : enable\n"
125 "layout(points) in;\n"
126 "layout(points, max_vertices=1) out;\n"
128 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
131 " gl_Position = gl_in[0].gl_Position;\n"
132 " atomicCounterIncrement(x);\n"
135 const char *vs_source
= "#version 140\n"
137 "in vec4 piglit_vertex;\n"
140 " gl_Position = piglit_vertex;\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();
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
);
159 run_test_tess_control(void)
161 const char *fs_source
= "#version 140\n"
166 const char *tes_source
= "#version 150\n"
167 "#extension GL_ARB_tessellation_shader : enable\n"
169 "layout(triangles, point_mode) in;\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"
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"
182 "layout(vertices=3) out;\n"
184 "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
187 " if (gl_InvocationID == 0) {\n"
188 " gl_TessLevelInner[0] = 1;\n"
190 " gl_TessLevelOuter[0] = 1;\n"
191 " gl_TessLevelOuter[1] = 1;\n"
192 " gl_TessLevelOuter[2] = 1;\n"
194 " atomicCounterIncrement(x);\n"
197 " gl_out[gl_InvocationID].gl_Position =\n"
198 " gl_in[gl_InvocationID].gl_Position;\n"
200 const char *vs_source
= "#version 140\n"
202 "in vec4 piglit_vertex;\n"
205 " gl_Position = piglit_vertex;\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();
212 atomic_counters_compile(prog
, GL_FRAGMENT_SHADER
, fs_source
) &&
213 atomic_counters_compile(prog
, GL_TESS_EVALUATION_SHADER
,
215 atomic_counters_compile(prog
, GL_TESS_CONTROL_SHADER
,
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
);
227 run_test_tess_evaluation(void)
229 const char *fs_source
= "#version 140\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"
238 "layout(triangles, point_mode) in;\n"
240 "layout(binding = 0, offset = 0) uniform atomic_uint x;\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"
247 " if (gl_TessCoord.z == 1.0) {\n"
248 " atomicCounterIncrement(x);\n"
251 const char *tcs_source
= "#version 150\n"
252 "#extension GL_ARB_tessellation_shader : enable\n"
254 "layout(vertices=3) out;\n"
257 " if (gl_InvocationID == 0) {\n"
258 " gl_TessLevelInner[0] = 1;\n"
260 " gl_TessLevelOuter[0] = 1;\n"
261 " gl_TessLevelOuter[1] = 1;\n"
262 " gl_TessLevelOuter[2] = 1;\n"
265 " gl_out[gl_InvocationID].gl_Position =\n"
266 " gl_in[gl_InvocationID].gl_Position;\n"
268 const char *vs_source
= "#version 140\n"
270 "in vec4 piglit_vertex;\n"
273 " gl_Position = piglit_vertex;\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();
280 atomic_counters_compile(prog
, GL_FRAGMENT_SHADER
, fs_source
) &&
281 atomic_counters_compile(prog
, GL_TESS_EVALUATION_SHADER
,
283 atomic_counters_compile(prog
, GL_TESS_CONTROL_SHADER
,
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
);
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",
320 atomic_counters_subtest(&status
, GL_VERTEX_SHADER
,
321 "Vertex shader atomic built-in semantics",
324 atomic_counters_subtest(&status
, GL_GEOMETRY_SHADER
,
325 "Geometry shader atomic built-in semantics",
328 atomic_counters_subtest(&status
, GL_TESS_CONTROL_SHADER
,
329 "Tessellation control shader atomic built-in "
331 run_test_tess_control
);
333 atomic_counters_subtest(&status
, GL_TESS_EVALUATION_SHADER
,
334 "Tessellation evaluation shader atomic built-in "
336 run_test_tess_evaluation
);
338 piglit_report_result(status
);