2 * Copyright © 2013 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 default-partition.c
26 * Test that the following is met:
28 * "Unlike other user-defined uniforms declared at global scope,
29 * [atomic counters] take NO storage from the default partition,
30 * they have NO location [...]"
32 * (from the ARB_shader_atomic_counters specification)
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_core_version
= 31;
41 config
.window_width
= 1;
42 config
.window_height
= 1;
43 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
44 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
46 PIGLIT_GL_TEST_CONFIG_END
49 run_test(unsigned max_uniforms
)
51 const char *fs_template
= "#version 140\n"
52 "#extension GL_ARB_shader_atomic_counters : enable\n"
57 "layout(binding=0) uniform atomic_uint x;\n"
58 "uniform uint y[N];\n"
62 " uint z = atomicCounter(x);\n"
64 " for (i = 0; i < N; ++i)\n"
67 " fcolor.x = int(z);\n"
70 GLuint prog
= glCreateProgram();
73 ret
= asprintf(&fs_source
, fs_template
, max_uniforms
);
76 /* This should fail to link if 'x' ended up being accounted in
77 * the default uniform partition because 'y[]' uses up the
78 * whole available uniform space. */
79 atomic_counters_compile(prog
, GL_FRAGMENT_SHADER
, fs_source
);
81 if (!piglit_check_gl_error(GL_NO_ERROR
))
84 glGetProgramiv(prog
, GL_ACTIVE_UNIFORMS
, &n
);
86 printf("Unexpected number of active uniforms %d.\n", n
);
90 if (glGetUniformLocation(prog
, "x") != -1) {
91 printf("Atomic counter unexpectedly reported to have a"
97 glDeleteProgram(prog
);
102 piglit_init(int argc
, char **argv
)
104 struct atomic_counters_limits ls
= atomic_counters_get_limits();
105 enum piglit_result status
= PIGLIT_PASS
;
107 piglit_require_gl_version(31);
108 piglit_require_extension("GL_ARB_shader_atomic_counters");
110 atomic_counters_subtest(&status
, GL_FRAGMENT_SHADER
,
111 "Atomic counter location",
112 run_test
, ls
.uniform_components
);
114 piglit_report_result(status
);