framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / arb_arrays_of_arrays / max-binding.c
blob9d9bd2d471913b28aadca3b4eb518697d1757d55
1 /*
2 * Copyright © 2015 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 max-binding.c
26 * Test that using more than the maximum number of suported interface block,
27 * sampler, or atomic bindings fails with a compile error.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_core_version = 32;
36 config.window_width = 1;
37 config.window_height = 1;
38 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
40 PIGLIT_GL_TEST_CONFIG_END
42 static bool
43 generate_and_compile_shader(GLuint stage, const char *src_template,
44 unsigned binding)
46 char *src;
47 int ret;
49 ret = asprintf(&src, src_template, binding);
50 assert(ret);
52 ret = piglit_compile_shader_text_nothrow(stage, src, true);
54 free(src);
55 return ret;
58 static bool
59 run_test_sampler_max_bindings(unsigned binding)
61 const char *src_template = "#version 150\n"
62 "#extension GL_ARB_arrays_of_arrays : enable\n"
63 "#extension GL_ARB_shading_language_420pack : enable\n"
64 "layout(binding=%d) uniform sampler2D sampler[2][2];\n"
65 "in vec2 coord;"
66 "\n"
67 "void main() {\n"
68 " gl_FragColor = texture2D(sampler[1][1], coord) + texture2D(sampler[0][1], coord);"
69 "}\n";
70 return generate_and_compile_shader(GL_FRAGMENT_SHADER, src_template,
71 binding);
74 static bool
75 run_test_interface_max_bindings(unsigned binding)
77 const char *src_template = "#version 150\n"
78 "#extension GL_ARB_arrays_of_arrays : enable\n"
79 "#extension GL_ARB_shading_language_420pack : enable\n"
80 "layout(binding=%d) uniform ArraysOfArraysBlock\n"
81 "{\n"
82 " float a;"
83 "} i[2][2];\n"
84 "void main() {\n"
85 " gl_Position = vec4(i[0][0].a, i[0][1].a, i[1][0].a, i[1][1].a);"
86 "}\n";
87 return generate_and_compile_shader(GL_VERTEX_SHADER, src_template,
88 binding);
91 static bool
92 run_test_ac_fragment_max_bindings(unsigned binding)
94 const char *src_template = "#version 150\n"
95 "#extension GL_ARB_shader_atomic_counters : enable\n"
96 "#extension GL_ARB_arrays_of_arrays : enable\n"
97 "\n"
98 "layout(binding=%d) uniform atomic_uint x[2][2];"
99 "\n"
100 "void main() {\n"
101 "}\n";
102 return generate_and_compile_shader(GL_FRAGMENT_SHADER, src_template,
103 binding);
106 static bool
107 run_test_ac_vertex_max_bindings(unsigned binding)
109 const char *src_template = "#version 150\n"
110 "#extension GL_ARB_shader_atomic_counters : enable\n"
111 "#extension GL_ARB_arrays_of_arrays : enable\n"
112 "\n"
113 "in vec4 position;\n"
114 "layout(binding=%d) uniform atomic_uint x[2][2];"
115 "\n"
116 "void main() {\n"
117 " gl_Position = position;\n"
118 "}\n";
119 return generate_and_compile_shader(GL_VERTEX_SHADER, src_template,
120 binding);
123 static void
124 subtest_fail(enum piglit_result *status, char *name)
126 piglit_report_subtest_result(PIGLIT_FAIL, "%s", name);
127 *status = PIGLIT_FAIL;
130 void
131 piglit_init(int argc, char **argv)
133 enum piglit_result status = PIGLIT_PASS;
134 int max_ab_binding;
135 int max_samp_binding;
136 int max_ifc_blk_binding;
138 /* assume the templates use this number of elements */
139 int array_elements = 4;
141 if (piglit_is_extension_supported("GL_ARB_shader_atomic_counters")) {
142 glGetIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS,
143 &max_ab_binding);
145 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
146 &max_samp_binding);
147 glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_ifc_blk_binding);
149 /* require 3.2 for interface block support */
150 piglit_require_gl_version(32);
151 piglit_require_extension("GL_ARB_arrays_of_arrays");
152 piglit_require_extension("GL_ARB_shading_language_420pack");
154 /* text above max limit */
155 if(run_test_interface_max_bindings(max_ifc_blk_binding-(array_elements-1)))
156 subtest_fail(&status, "Test interface block binding above "
157 "maximum number of uniform "
158 "buffer bindings");
160 /* test max boundary */
161 if(!run_test_interface_max_bindings(max_ifc_blk_binding-array_elements))
162 subtest_fail(&status, "Test interface block binding on "
163 "boundary of maximum number of uniform "
164 "buffer bindings");
166 /* text above max limit */
167 if(run_test_sampler_max_bindings(max_samp_binding-(array_elements-1)))
168 subtest_fail(&status, "Test sampler binding above "
169 "maximum number of texture "
170 "unit bindings");
172 /* test max boundary */
173 if(!run_test_sampler_max_bindings(max_samp_binding-array_elements))
174 subtest_fail(&status, "Test sampler binding on boundary "
175 "of maximum number of texure "
176 "unit bindings");
178 if (piglit_is_extension_supported("GL_ARB_shader_atomic_counters")) {
179 /* text above max limit */
180 if(run_test_ac_fragment_max_bindings(max_ab_binding))
181 subtest_fail(&status, "Fragment shader test above "
182 "maximum number of atomic "
183 "counter bindings");
185 if(run_test_ac_vertex_max_bindings(max_ab_binding))
186 subtest_fail(&status, "Vertex shader test above "
187 "maximum number of atomic "
188 "counter bindings");
189 /* test max boundary */
190 if(!run_test_ac_fragment_max_bindings(max_ab_binding-1))
191 subtest_fail(&status, "Fragment shader test boundary "
192 "of maximum number of atomic "
193 "counter bindings");
195 if(!run_test_ac_vertex_max_bindings(max_ab_binding-1))
196 subtest_fail(&status, "Vertex shader test boundary "
197 "of maximum number of atomic "
198 "counter bindings");
201 piglit_report_result(status);
204 enum piglit_result
205 piglit_display(void)
207 return PIGLIT_PASS;