2 * Copyright © 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 pipeline_stats_comp.c
26 * This test verifies that the vertex shader related tokens of
27 * ARB_pipeline_statistics_query() work as expected. OpenGL 4.4
28 * Specification, Core Profile.
30 * When BeginQuery is called with a target of
31 * COMPUTE_SHADER_INVOCATIONS_ARB, the compute shader invocations
32 * count maintained by the GL is set to zero. When a compute shader
33 * invocations query is active, the counter is incremented every time
34 * the compute shader is invoked (see chapter 19).
38 #include "piglit-util-gl.h"
39 #include "pipestat_help.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config
.supports_gl_core_version
= 32;
43 config
.supports_gl_compat_version
= 32;
44 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
45 PIGLIT_GL_TEST_CONFIG_END
47 #define NUM_ATOMIC_COUNTERS 1
49 static GLuint atomics_bo
= 0;
51 static int sizes
[] = {
52 1, 2, 3, 4, 5, 7, 8, 9, 15, 16, 17, 31, 32, 33, 63, 64, 65,
53 127, 128, 129, 255, 256, 257, 511, 512, 513, 1023, 1024
56 static struct query queries
[] = {
58 .query
= GL_COMPUTE_SHADER_INVOCATIONS_ARB
,
59 .min
= 0 /* Adjusted by confirm_size */},
62 static const char *compute_shader_template
=
64 "#extension GL_ARB_compute_shader: enable\n"
65 "#extension GL_ARB_shader_atomic_counters: require\n"
67 "layout(binding = 0) uniform atomic_uint atc;\n"
69 "layout(local_size_x = %d, local_size_y = %d, local_size_z = %d) in;\n"
73 " atomicCounterIncrement(atc);\n"
78 dispatch_size(uint32_t x
, uint32_t y
, uint32_t z
)
81 GLuint shader
= glCreateShader(GL_COMPUTE_SHADER
);
83 static GLint prog
= 0;
86 glDeleteProgram(prog
);
89 (void)!asprintf(&compute_shader
, compute_shader_template
, x
, y
, z
);
91 glShaderSource(shader
, 1,
92 (const GLchar
**) &compute_shader
,
95 glCompileShader(shader
);
97 glGetShaderiv(shader
, GL_COMPILE_STATUS
, &ok
);
100 prog
= glCreateProgram();
102 glAttachShader(prog
, shader
);
106 glGetProgramiv(prog
, GL_LINK_STATUS
, &ok
);
111 glMemoryBarrier(GL_ALL_BARRIER_BITS
);
112 glDispatchCompute(1, 1, 1);
113 glMemoryBarrier(GL_ALL_BARRIER_BITS
);
118 test_all_sizes_for_query(void)
123 for (zi
= 0; zi
< ARRAY_SIZE(sizes
); zi
++) {
127 for (yi
= 0; yi
< ARRAY_SIZE(sizes
); yi
++) {
131 for (xi
= 0; xi
< ARRAY_SIZE(sizes
); xi
++) {
133 if ((x
* y
* z
) > 1024)
135 dispatch_size(x
, y
, z
);
137 /* Adjust the expected count. This
138 * will be verified after we
140 queries
[0].min
+= x
* y
* z
;
155 piglit_init(int argc
, char **argv
)
157 enum piglit_result result
;
160 piglit_require_extension("GL_ARB_compute_shader");
161 piglit_require_extension("GL_ARB_shader_atomic_counters");
163 do_query_init(queries
, ARRAY_SIZE(queries
));
165 atomics_buf
= calloc(NUM_ATOMIC_COUNTERS
, sizeof(GLuint
));
166 glGenBuffers(1, &atomics_bo
);
167 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER
, 0, atomics_bo
);
168 glBufferData(GL_ATOMIC_COUNTER_BUFFER
,
169 sizeof(GLuint
) * NUM_ATOMIC_COUNTERS
,
170 atomics_buf
, GL_STATIC_DRAW
);
173 result
= do_query_func(queries
, ARRAY_SIZE(queries
),
174 test_all_sizes_for_query
);
176 piglit_report_result(result
);