2 * Copyright (C) 2016 Samuel Pitoiset
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
26 * Test cases in which the ARB_compute_variable_group_size API is expected to
30 #include "piglit-util-gl.h"
31 #include "piglit-shader.h"
33 static struct piglit_gl_test_config
*piglit_config
;
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 piglit_config
= &config
;
38 config
.supports_gl_compat_version
= 33;
39 config
.supports_gl_core_version
= 33;
40 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
44 static const char *variable_work_group_size_shader
=
46 "#extension GL_ARB_compute_shader: enable\n"
47 "#extension GL_ARB_compute_variable_group_size: enable\n"
49 "layout(local_size_variable) in;\n"
55 static const char *fixed_work_group_size_shader
=
57 "#extension GL_ARB_compute_shader: enable\n"
59 "layout(local_size_x = 1) in;\n"
65 static enum piglit_result
66 use_variable_work_group_size_normal(void *data
)
68 /* The ARB_compute_variable_group_size spec says:
70 * An INVALID_OPERATION error is generated by DispatchCompute or
71 * DispatchComputeIndirect if the active program for the compute
72 * shader stage has a variable work group size.
74 GLint prog
= piglit_build_simple_program_multiple_shaders(
75 GL_COMPUTE_SHADER
, variable_work_group_size_shader
, 0);
77 glDispatchCompute(1, 1, 1);
78 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
83 static enum piglit_result
84 use_variable_work_group_size_indirect(void *data
)
86 /* The ARB_compute_variable_group_size spec says:
88 * An INVALID_OPERATION error is generated by DispatchCompute or
89 * DispatchComputeIndirect if the active program for the compute
90 * shader stage has a variable work group size.
92 GLuint indirect_buf
[3] = { 1, 1, 1 };
93 GLuint indirect_bo
= 0;
96 glGenBuffers(1, &indirect_bo
);
97 if (!piglit_check_gl_error(GL_NO_ERROR
))
100 glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER
, indirect_bo
);
101 glBufferData(GL_DISPATCH_INDIRECT_BUFFER
, sizeof(indirect_buf
),
102 indirect_buf
, GL_STREAM_READ
);
104 prog
= piglit_build_simple_program_multiple_shaders(
105 GL_COMPUTE_SHADER
, variable_work_group_size_shader
, 0);
108 glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER
, indirect_bo
);
109 glDispatchComputeIndirect(0);
110 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
113 glDeleteBuffers(1, &indirect_bo
);
117 static enum piglit_result
118 use_fixed_work_group_size(void *data
)
120 /* The ARB_compute_variable_group_size spec says:
122 * An INVALID_OPERATION error is generated by
123 * DispatchComputeGroupSizeARB if the active program for the
124 * compute shader stage has a fixed work group size.
126 GLint prog
= piglit_build_simple_program_multiple_shaders(
127 GL_COMPUTE_SHADER
, fixed_work_group_size_shader
, 0);
129 glDispatchComputeGroupSizeARB(1, 1, 1, 1, 1, 1);
130 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
135 static enum piglit_result
136 use_invalid_work_group_count_values(void *data
)
140 /* The ARB_compute_variable_group_size spec says:
142 * An INVALID_VALUE error is generated if any of num_groups_x,
143 * num_groups_y and num_groups_z are greater than or equal to the
144 * maximum work group count for the corresponding dimension.
146 prog
= piglit_build_simple_program_multiple_shaders(
147 GL_COMPUTE_SHADER
, variable_work_group_size_shader
, 0);
150 /* Use values greater than the maximum work group count. */
151 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT
, 0, &v
[0]);
152 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT
, 1, &v
[1]);
153 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT
, 2, &v
[2]);
155 glDispatchComputeGroupSizeARB(v
[0] + 1, v
[1] + 1, v
[2] + 1, 1, 1, 1);
156 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
161 static enum piglit_result
162 use_invalid_variable_work_group_size_values(void *data
)
164 /* The ARB_compute_variable_group_size spec says:
166 * An INVALID_VALUE error is generated by
167 * DispatchComputeGroupSizeARB if any of <group_size_x>,
168 * <group_size_y>, or <group_size_z> is less than or equal to zero
169 * or greater than the maximum local work group size for compute
170 * shaders with variable group size
171 * (MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB) in the corresponding
176 prog
= piglit_build_simple_program_multiple_shaders(
177 GL_COMPUTE_SHADER
, variable_work_group_size_shader
, 0);
180 /* Use values equal to zero (because "less than" is a spec bug). */
181 glDispatchComputeGroupSizeARB(1, 1, 1, 0, 0, 0);
182 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
185 /* Use values greater than the maximum local work group size. */
186 glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB
, 0, &v
[0]);
187 glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB
, 1, &v
[1]);
188 glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB
, 2, &v
[2]);
189 glDispatchComputeGroupSizeARB(1, 1, 1, v
[0] + 1, v
[1] + 1, v
[0] + 1);
190 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
195 static enum piglit_result
196 use_invalid_variable_group_invocations_values(void *data
)
198 /* The ARB_compute_variable_group_size spec says:
200 * An INVALID_VALUE error is generated by
201 * DispatchComputeGroupSizeARB if the product of <group_size_x>,
202 * <group_size_y>, and <group_size_z> exceeds the
203 * implementation-dependent maximum local work group invocation
204 * count for compute shaders with variable group size
205 * (MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB).
209 prog
= piglit_build_simple_program_multiple_shaders(
210 GL_COMPUTE_SHADER
, variable_work_group_size_shader
, 0);
213 glGetIntegerv(GL_MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB
, &v
);
214 glDispatchComputeGroupSizeARB(1, 1, 1, v
, v
, v
);
215 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
220 static const struct piglit_subtest subtests
[] = {
222 "Use a variable work group size with DispatchCompute",
223 "use_variable_work_group_size_normal",
224 use_variable_work_group_size_normal
,
228 "Use a variable work group size with DispatchComputeIndirect",
229 "use_variable_work_group_size_indirect",
230 use_variable_work_group_size_indirect
,
235 "Use a fixed work group size with DispatchComputeGroupSizeARB",
236 "use_fixed_work_group_size",
237 use_fixed_work_group_size
,
241 "Use invalid work group count values",
242 "use_invalid_work_group_count_values",
243 use_invalid_work_group_count_values
,
247 "Use invalid variable work group size values",
248 "use_invalid_variable_work_group_size_values",
249 use_invalid_variable_work_group_size_values
,
253 "Use invalid variable group invocations values",
254 "use_invalid_variable_group_invocations_values",
255 use_invalid_variable_group_invocations_values
,
273 piglit_init(int argc
, char **argv
)
275 enum piglit_result result
;
277 piglit_require_extension("GL_ARB_compute_variable_group_size");
278 result
= piglit_run_selected_subtests(subtests
,
279 piglit_config
->selected_subtests
,
280 piglit_config
->num_selected_subtests
,
282 piglit_report_result(result
);