ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / arb_shader_atomic_counters / default-partition.c
blobf42093522b8ce78b66070f83dd382a97be830c71
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
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)
35 #include "common.h"
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
48 static bool
49 run_test(unsigned max_uniforms)
51 const char *fs_template = "#version 140\n"
52 "#extension GL_ARB_shader_atomic_counters : enable\n"
53 "\n"
54 "#define N %d\n"
55 "\n"
56 "out ivec4 fcolor;\n"
57 "layout(binding=0) uniform atomic_uint x;\n"
58 "uniform uint y[N];\n"
59 "\n"
60 "void main() {\n"
61 " int i;\n"
62 " uint z = atomicCounter(x);\n"
63 " \n"
64 " for (i = 0; i < N; ++i)\n"
65 " z += y[i];\n"
66 " \n"
67 " fcolor.x = int(z);\n"
68 "}\n";
69 char *fs_source;
70 GLuint prog = glCreateProgram();
71 int n = 0, ret;
73 ret = asprintf(&fs_source, fs_template, max_uniforms);
74 assert(ret > 0);
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);
80 glLinkProgram(prog);
81 if (!piglit_check_gl_error(GL_NO_ERROR))
82 return false;
84 glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, &n);
85 if (n != 2) {
86 printf("Unexpected number of active uniforms %d.\n", n);
87 return false;
90 if (glGetUniformLocation(prog, "x") != -1) {
91 printf("Atomic counter unexpectedly reported to have a"
92 " location.\n");
93 return false;
96 free(fs_source);
97 glDeleteProgram(prog);
98 return true;
101 void
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);
117 enum piglit_result
118 piglit_display(void)
120 return PIGLIT_PASS;