1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
|
/*
* Copyright © 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/** @file max-counters.c
*
* Test that using more than the maximum number of suported atomic
* counters, buffers or bindings fails with a linking error.
*/
#include "common.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_core_version = 31;
config.window_width = 1;
config.window_height = 1;
config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
config.khr_no_error_support = PIGLIT_NO_ERRORS;
PIGLIT_GL_TEST_CONFIG_END
static char *
iterate_template(const char *template, unsigned n)
{
char *ss;
int i, ret;
ss = strdup("");
assert(ss);
for (i = 0; i < n; ++i) {
char *s, *tmp = ss;
ret = asprintf(&s, template, i);
assert(ret >= 0);
ret = asprintf(&ss, "%s%s", tmp, s);
assert(ret >= 0);
free(tmp);
free(s);
}
return ss;
}
/**
* Generate source code by substituting the first occurrence of "%s"
* in \a src_template with \a n copies of \a decl_template and the
* second occurrence of "%s" with \a n copies of \a insn_template.
*/
static char *
generate_source(const char *src_template,
const char *decl_template, const char *insn_template,
unsigned n)
{
char *decls = iterate_template(decl_template, n);
char *insns = iterate_template(insn_template, n);
char *src;
int ret;
ret = asprintf(&src, src_template, decls, insns);
assert(ret);
free(decls);
free(insns);
return src;
}
static bool
run_test_vertex_max_counters(unsigned num_counters)
{
/* Generate a shader with 'num_counters' counters. */
char *vs_source = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"%s\n"
"\n"
"in vec4 position;\n"
"flat out ivec4 vcolor;\n"
"\n"
"void main() {\n"
" uint y = 0u;\n"
" %s\n"
" vcolor.x = int(y);\n"
" gl_Position = position;\n"
"}\n",
"layout(binding=0) uniform atomic_uint x%d;\n",
" y += atomicCounterDecrement(x%d);\n",
num_counters);
GLuint prog = glCreateProgram();
bool ret = atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
atomic_counters_link(prog);
glDeleteProgram(prog);
free(vs_source);
return ret;
}
static bool
run_test_fragment_max_counters(unsigned num_counters)
{
/* Generate a shader with 'num_counters' counters. */
char *fs_source = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"%s\n"
"\n"
"out ivec4 fcolor;\n"
"\n"
"void main() {\n"
" uint y = 0u;\n"
" %s\n"
" fcolor.x = int(y);\n"
"}\n",
"layout(binding=0) uniform atomic_uint x%d;\n",
" y += atomicCounterDecrement(x%d);\n",
num_counters);
GLuint prog = glCreateProgram();
bool ret = atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
atomic_counters_link(prog);
glDeleteProgram(prog);
free(fs_source);
return ret;
}
static bool
run_test_combined_max_counters(unsigned num_fragment_counters,
unsigned num_vertex_counters)
{
/* Generate a shader with 'num_fragment_counters' counters. */
char *fs_source = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"%s\n"
"\n"
"flat in ivec4 vcolor;\n"
"out ivec4 fcolor;\n"
"\n"
"void main() {\n"
" uint y = uint(vcolor.x);\n"
" %s\n"
" fcolor.x = int(y);\n"
"}\n",
"layout(binding=0) uniform atomic_uint fx%d;\n",
" y += atomicCounterDecrement(fx%d);\n",
num_fragment_counters);
/* Generate a shader with 'num_vertex_counters' counters. */
char *vs_source = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"%s\n"
"\n"
"in vec4 position;\n"
"flat out ivec4 vcolor;\n"
"\n"
"void main() {\n"
" uint y = 0u;\n"
" %s\n"
" vcolor.x = int(y);\n"
" gl_Position = position;\n"
"}\n",
"layout(binding=1) uniform atomic_uint vx%d;\n",
" y += atomicCounterDecrement(vx%d);\n",
num_vertex_counters);
GLuint prog = glCreateProgram();
bool ret = atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
atomic_counters_link(prog);
glDeleteProgram(prog);
free(fs_source);
free(vs_source);
return ret;
}
static bool
run_test_fragment_max_buffers(unsigned num_buffers)
{
/* Generate a shader with 'num_buffers' buffers. */
char *src = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"#define PASTE(A,B) A ## B\n"
"#define Y(I) PASTE(y, I)\n"
"\n"
"out ivec4 fcolor;\n"
"\n"
"%s"
"\n"
"void main() {\n"
" uint x = 0u;\n"
" %s\n"
" fcolor.x = int(x);\n"
"}\n",
"#define I %d\n"
"layout(binding=I, offset=0) uniform atomic_uint Y(I);\n"
"#undef I\n",
" x += atomicCounterDecrement(y%d);\n",
num_buffers);
GLuint prog = glCreateProgram();
bool ret = atomic_counters_compile(prog, GL_FRAGMENT_SHADER, src) &&
atomic_counters_link(prog);
glDeleteProgram(prog);
free(src);
return ret;
}
static bool
run_test_vertex_max_buffers(unsigned num_buffers)
{
/* Generate a shader with 'num_buffers' buffers. */
char *src = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"#define PASTE(A,B) A ## B\n"
"#define X(I) PASTE(x, I)\n"
"\n"
"in vec4 position;\n"
"flat out ivec4 vcolor;\n"
"\n"
"%s"
"\n"
"void main() {\n"
" uint x = 0u;\n"
" %s\n"
" vcolor.x = int(x);\n"
" gl_Position = position;\n"
"}\n",
"#define I %d\n"
"layout(binding=I, offset=0) uniform atomic_uint X(I);\n"
"#undef I\n",
" x += atomicCounterDecrement(x%d);\n",
num_buffers);
GLuint prog = glCreateProgram();
bool ret = atomic_counters_compile(prog, GL_VERTEX_SHADER, src) &&
atomic_counters_link(prog);
glDeleteProgram(prog);
free(src);
return ret;
}
static bool
run_test_combined_max_buffers(unsigned num_fragment_buffers,
unsigned num_vertex_buffers)
{
/* Generate a shader with 'num_fragment_buffers' buffers. */
char *fs_source = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"#define PASTE(A,B) A ## B\n"
"#define Y(I) PASTE(y, I)\n"
"\n"
"out ivec4 fcolor;\n"
"\n"
"%s"
"\n"
"void main() {\n"
" uint x = 0u;\n"
" %s\n"
" fcolor.x = int(x);\n"
"}\n",
"#define I %d\n"
"layout(binding=I, offset=0) uniform atomic_uint Y(I);\n"
"#undef I\n",
" x += atomicCounterDecrement(y%d);\n",
num_fragment_buffers);
/* Generate a shader with 'num_vertex_buffers' buffers. */
char *vs_source = generate_source(
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"#define PASTE(A,B) A ## B\n"
"#define X(I) PASTE(x, I)\n"
"\n"
"in vec4 position;\n"
"flat out ivec4 vcolor;\n"
"\n"
"%s"
"\n"
"void main() {\n"
" uint x = 0u;\n"
" %s\n"
" vcolor.x = int(x);\n"
" gl_Position = position;\n"
"}\n",
"#define I %d\n"
"layout(binding=I, offset=4) uniform atomic_uint X(I);\n"
"#undef I\n",
" x += atomicCounterDecrement(x%d);\n",
num_vertex_buffers);
GLuint prog = glCreateProgram();
bool ret =
atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
atomic_counters_link(prog);
glDeleteProgram(prog);
free(fs_source);
free(vs_source);
return ret;
}
static bool
run_test_fragment_max_bindings(unsigned binding)
{
const char *src_template = "#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"layout(binding=%d) uniform atomic_uint x;"
"\n"
"void main() {\n"
"}\n";
char *src;
GLuint prog = glCreateProgram();
int ret;
ret = asprintf(&src, src_template, binding);
assert(ret);
ret = atomic_counters_compile(prog, GL_FRAGMENT_SHADER, src);
glDeleteProgram(prog);
free(src);
return ret;
}
static bool
run_test_vertex_max_bindings(unsigned binding)
{
const char *src_template = "#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"in vec4 position;\n"
"layout(binding=%d) uniform atomic_uint x;"
"\n"
"void main() {\n"
" gl_Position = position;\n"
"}\n";
char *src;
GLuint prog = glCreateProgram();
int ret;
ret = asprintf(&src, src_template, binding);
assert(ret);
ret = atomic_counters_compile(prog, GL_VERTEX_SHADER, src);
glDeleteProgram(prog);
free(src);
return ret;
}
void
piglit_init(int argc, char **argv)
{
enum piglit_result status = PIGLIT_PASS;
struct atomic_counters_limits ls = atomic_counters_get_limits();
piglit_require_gl_version(31);
piglit_require_extension("GL_ARB_shader_atomic_counters");
printf("Max combined: %d\n", ls.combined_counters);
printf("Max VS: %d\n", ls.vertex_counters);
printf("Max FS: %d\n", ls.fragment_counters);
atomic_counters_subtest(&status, GL_VERTEX_SHADER,
"Vertex shader test above maximum "
"number of atomic counters",
!run_test_vertex_max_counters,
ls.vertex_counters + 1);
atomic_counters_subtest(&status, GL_FRAGMENT_SHADER,
"Fragment shader test above maximum "
"number of atomic counters",
!run_test_fragment_max_counters,
ls.fragment_counters + 1);
if (ls.vertex_counters + ls.fragment_counters > ls.combined_counters) {
atomic_counters_subtest(&status, GL_NONE,
"Combined test above maximum number "
"of atomic counters",
!run_test_combined_max_counters,
ls.fragment_counters,
ls.combined_counters
- ls.fragment_counters + 1);
} else {
piglit_report_subtest_result(
PIGLIT_SKIP, "Combined test above maximum number "
"of atomic counters");
}
atomic_counters_subtest(&status, GL_FRAGMENT_SHADER,
"Fragment shader test under maximum "
"number of atomic counter buffers",
run_test_fragment_max_buffers,
ls.fragment_buffers);
atomic_counters_subtest(&status, GL_FRAGMENT_SHADER,
"Fragment shader test above maximum "
"number of atomic counter buffers",
!run_test_fragment_max_buffers,
ls.fragment_buffers + 1);
atomic_counters_subtest(&status, GL_VERTEX_SHADER,
"Vertex shader test under maximum "
"number of atomic counter buffers",
run_test_vertex_max_buffers,
ls.vertex_buffers);
atomic_counters_subtest(&status, GL_VERTEX_SHADER,
"Vertex shader test above maximum "
"number of atomic counter buffers",
!run_test_vertex_max_buffers,
ls.vertex_buffers + 1);
const int combined_test_max_vs_bufs =
MIN2(ls.vertex_buffers, ls.combined_buffers - ls.fragment_buffers);
if (combined_test_max_vs_bufs > 0) {
atomic_counters_subtest(&status, GL_NONE,
"Combined test under maximum "
"number of atomic counter buffers",
run_test_combined_max_buffers,
ls.fragment_buffers,
combined_test_max_vs_bufs);
} else {
piglit_report_subtest_result(
PIGLIT_SKIP, "Combined test under maximum "
"number of atomic counter buffers");
}
if (combined_test_max_vs_bufs < ls.vertex_buffers) {
atomic_counters_subtest(&status, GL_NONE,
"Combined test above maximum "
"number of atomic counter buffers",
!run_test_combined_max_buffers,
ls.fragment_buffers,
combined_test_max_vs_bufs + 1);
} else {
piglit_report_subtest_result(
PIGLIT_SKIP, "Combined test above maximum "
"number of atomic counter buffers");
}
atomic_counters_subtest(&status, GL_FRAGMENT_SHADER,
"Fragment shader test above maximum "
"number of atomic counter bindings",
!run_test_fragment_max_bindings,
ls.bindings + 1);
atomic_counters_subtest(&status, GL_VERTEX_SHADER,
"Vertex shader test above maximum "
"number of atomic counter bindings",
!run_test_vertex_max_bindings,
ls.bindings + 1);
piglit_report_result(status);
}
enum piglit_result
piglit_display(void)
{
return PIGLIT_PASS;
}
|