ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_atomic_counters / multiple-defs.c
blobb752fc2809c793f75af171094dff61a7115ae21b
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 multiple-defs.c
26 * Checks that atomic counters with the same name may be linked
27 * together if and only if their layout specifications are equivalent.
30 #include "common.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_core_version = 31;
36 config.window_width = 1;
37 config.window_height = 1;
38 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 PIGLIT_GL_TEST_CONFIG_END
43 const char *frag_src = "#version 140\n"
44 "#extension GL_ARB_shader_atomic_counters : enable\n"
45 "\n"
46 "flat in ivec4 vcolor;\n"
47 "out ivec4 fcolor;\n"
48 "\n"
49 "layout(binding=3, offset=4) uniform atomic_uint x0;\n"
50 "layout(binding=2, offset=0) uniform atomic_uint x1;\n"
51 "layout(binding=2) uniform atomic_uint x2;\n"
52 "\n"
53 "void main() {\n"
54 " fcolor.x = vcolor.x + int(atomicCounter(x0) +\n"
55 " atomicCounter(x1) + atomicCounter(x2));\n"
56 "}\n";
58 const char *vert_src_ok = "#version 140\n"
59 "#extension GL_ARB_shader_atomic_counters : enable\n"
60 "\n"
61 "in vec4 position;\n"
62 "flat out ivec4 vcolor;\n"
63 "\n"
64 "layout(binding=2) uniform atomic_uint x1;\n"
65 "layout(binding=2, offset=4) uniform atomic_uint x2;\n"
66 "layout(binding=3, offset=4) uniform atomic_uint x0;\n"
67 "\n"
68 "void main() {\n"
69 " vcolor.x = int(atomicCounter(x0) + atomicCounter(x1)\n"
70 " + atomicCounter(x2));\n"
71 " gl_Position = position;\n"
72 "}\n";
74 /* This should fail because 'x1' is redefined with a conflicting
75 * binding specification. */
76 const char *vert_src_fail_1 = "#version 140\n"
77 "#extension GL_ARB_shader_atomic_counters : enable\n"
78 "\n"
79 "in vec4 position;\n"
80 "flat out ivec4 vcolor;\n"
81 "\n"
82 "layout(binding=0) uniform atomic_uint x1;\n"
83 "layout(binding=2, offset=4) uniform atomic_uint x2;\n"
84 "layout(binding=3, offset=4) uniform atomic_uint x0;\n"
85 "\n"
86 "void main() {\n"
87 " vcolor.x = int(atomicCounter(x0) + atomicCounter(x1)\n"
88 " + atomicCounter(x2));\n"
89 " gl_Position = position;\n"
90 "}\n";
92 /* This should fail because 'x0' is redefined with a conflicting
93 * implicit offset specification. */
94 const char *vert_src_fail_2 = "#version 140\n"
95 "#extension GL_ARB_shader_atomic_counters : enable\n"
96 "\n"
97 "in vec4 position;\n"
98 "flat out ivec4 vcolor;\n"
99 "\n"
100 "layout(binding=2) uniform atomic_uint x1;\n"
101 "layout(binding=2, offset=4) uniform atomic_uint x2;\n"
102 "layout(binding=3) uniform atomic_uint x0;\n"
103 "\n"
104 "void main() {\n"
105 " vcolor.x = int(atomicCounter(x0) + atomicCounter(x1)\n"
106 " + atomicCounter(x2));\n"
107 " gl_Position = position;\n"
108 "}\n";
110 /* This should fail because 'x3' overlaps an already defined
111 * counter. */
112 const char *vert_src_fail_3 = "#version 140\n"
113 "#extension GL_ARB_shader_atomic_counters : enable\n"
114 "\n"
115 "in vec4 position;\n"
116 "flat out ivec4 vcolor;\n"
117 "\n"
118 "layout(binding=2) uniform atomic_uint x1;\n"
119 "layout(binding=2, offset=4) uniform atomic_uint x2;\n"
120 "layout(binding=3, offset=0) uniform atomic_uint x3[2];\n"
121 "\n"
122 "void main() {\n"
123 " vcolor.x = int(atomicCounter(x1) + atomicCounter(x2)\n"
124 " + atomicCounter(x3[0]));\n"
125 " gl_Position = position;\n"
126 "}\n";
128 /* This should fail because 'x3' has the same location specification
129 * as 'x0'. */
130 const char *vert_src_fail_4 = "#version 140\n"
131 "#extension GL_ARB_shader_atomic_counters : enable\n"
132 "\n"
133 "in vec4 position;\n"
134 "flat out ivec4 vcolor;\n"
135 "\n"
136 "layout(binding=2) uniform atomic_uint x1;\n"
137 "layout(binding=2, offset=4) uniform atomic_uint x2;\n"
138 "layout(binding=3, offset=4) uniform atomic_uint x3;\n"
139 "\n"
140 "void main() {\n"
141 " vcolor.x = int(atomicCounter(x1) + atomicCounter(x2)\n"
142 " + atomicCounter(x3));\n"
143 " gl_Position = position;\n"
144 "}\n";
146 bool
147 run_test(const char *fs_source, const char *vs_source)
149 GLuint prog = glCreateProgram();
150 bool ret =
151 atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
152 atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
153 atomic_counters_link(prog);
155 glDeleteProgram(prog);
156 return ret;
159 void
160 piglit_init(int argc, char **argv)
162 struct atomic_counters_limits ls = atomic_counters_get_limits();
163 enum piglit_result status = PIGLIT_PASS;
165 piglit_require_extension("GL_ARB_shader_atomic_counters");
167 if (ls.fragment_counters < 3 || ls.vertex_counters < 4) {
168 fprintf(stderr, "Insufficient number of supported atomic "
169 "counters.\n");
170 piglit_report_result(PIGLIT_SKIP);
173 if (ls.fragment_buffers < 2 || ls.vertex_buffers < 3) {
174 fprintf(stderr, "Insufficient number of supported atomic "
175 "buffers.\n");
176 piglit_report_result(PIGLIT_SKIP);
179 atomic_counters_subtest(&status, GL_NONE,
180 "Multiple atomic counter definitions "
181 "(compatible defs)",
182 run_test, frag_src, vert_src_ok);
184 atomic_counters_subtest(&status, GL_NONE,
185 "Multiple atomic counter definitions "
186 "(1: incompatible bindings)",
187 !run_test, frag_src, vert_src_fail_1);
189 atomic_counters_subtest(&status, GL_NONE,
190 "Multiple atomic counter definitions "
191 "(2: incompatible offsets)",
192 !run_test, frag_src, vert_src_fail_2);
194 atomic_counters_subtest(&status, GL_NONE,
195 "Multiple atomic counter definitions "
196 "(3: array overlap)",
197 !run_test, frag_src, vert_src_fail_3);
199 atomic_counters_subtest(&status, GL_NONE,
200 "Multiple atomic counter definitions "
201 "(4: conflicting locations)",
202 !run_test, frag_src, vert_src_fail_4);
204 piglit_report_result(status);
207 enum piglit_result
208 piglit_display(void)
210 return PIGLIT_PASS;