glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / amd_framebuffer_multisample_advanced / api.c
blob37deee5f2932c7d1aff81a5b1f011961d9472774
1 /*
2 * Copyright © 2018 Advanced Micro Devices, Inc.
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
21 * DEALINGS IN THE SOFTWARE.
25 #include "piglit-util-gl.h"
27 PIGLIT_GL_TEST_CONFIG_BEGIN
29 config.supports_gl_core_version = 32;
30 config.supports_gl_es_version = 30;
32 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
34 PIGLIT_GL_TEST_CONFIG_END
36 static void
37 piglit_fail(const char *fmt, ...)
39 va_list ap;
40 va_start(ap, fmt);
41 vprintf(fmt, ap);
42 va_end(ap);
43 piglit_report_result(PIGLIT_FAIL);
46 static void
47 validate_current_renderbuffer(const char *type, int input_samples, int input_storage_samples)
49 int samples, storage_samples;
51 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
52 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_STORAGE_SAMPLES_AMD,
53 &storage_samples);
54 piglit_check_gl_error(GL_NO_ERROR);
56 if (samples != input_samples ||
57 storage_samples != input_storage_samples) {
58 piglit_fail("Created %s buffer (samples = %u, storageSamples = %u), got (%u, %u)\n",
59 type, input_samples, input_storage_samples, samples, storage_samples);
63 void
64 piglit_init(int argc, char **argv)
66 piglit_require_extension("GL_AMD_framebuffer_multisample_advanced");
68 /* Check enums. */
69 int num_modes, *modes;
70 glGetIntegerv(GL_NUM_SUPPORTED_MULTISAMPLE_MODES_AMD, &num_modes);
71 piglit_check_gl_error(GL_NO_ERROR);
72 if (num_modes < 1)
73 piglit_fail("GL_NUM_SUPPORTED_MULTISAMPLED_MODES_AMD expected > 0, got %u\n", num_modes);
75 int max_color_samples, max_color_storage_samples, max_depthstencil_samples;
76 glGetIntegerv(GL_MAX_COLOR_FRAMEBUFFER_SAMPLES_AMD, &max_color_samples);
77 glGetIntegerv(GL_MAX_COLOR_FRAMEBUFFER_STORAGE_SAMPLES_AMD, &max_color_storage_samples);
78 glGetIntegerv(GL_MAX_DEPTH_STENCIL_FRAMEBUFFER_SAMPLES_AMD, &max_depthstencil_samples);
79 if (max_color_samples < 4 ||
80 max_color_storage_samples < 4 ||
81 max_depthstencil_samples < 4) {
82 piglit_fail("GL_MAX_xxx_SAMPLES_AMD expected >= 4, got %u,%u,%u\n",
83 max_color_samples, max_color_storage_samples,
84 max_depthstencil_samples);
86 if (max_color_samples < max_color_storage_samples)
87 piglit_fail("GL_MAX_COLOR_FRAMEBUFFER_SAMPLES_AMD < GL_MAX_COLOR_FRAMEBUFFER_STORAGE_SAMPLES_AMD\n");
89 modes = malloc(num_modes * 3 * 4);
90 glGetIntegerv(GL_SUPPORTED_MULTISAMPLE_MODES_AMD, modes);
91 piglit_check_gl_error(GL_NO_ERROR);
93 bool found_max_color = false, found_max_zs = false;
94 for (int i = 0; i < num_modes; i++) {
95 if (modes[i*3] < 2 ||
96 modes[i*3+1] < 1 ||
97 modes[i*3+2] < 1 ||
98 modes[i*3] < modes[i*3+1] ||
99 modes[i*3] < modes[i*3+2])
100 piglit_fail("GL_SUPPORTED_MULTISAMPLE_MODES_AMD invalid mode %u,%u,%u\n",
101 modes[i*3], modes[i*3+1], modes[i*3+2]);
103 if (modes[i*3] == max_color_samples &&
104 modes[i*3+1] == max_color_storage_samples)
105 found_max_color = true;
107 if (modes[i*3+2] == max_depthstencil_samples)
108 found_max_zs = true;
110 if (!found_max_color)
111 piglit_fail("Mode with GL_MAX_COLOR_FRAMEBUFFER_SAMPLES_AMD and ..._STORAGE_SAMPLES_AMD not listed\n");
112 if (!found_max_zs)
113 piglit_fail("Modes with GL_MAX_DEPTH_STENCIL_FRAMEBUFFER_SAMPLES_AMD not listed");
115 GLuint rb;
116 glGenRenderbuffers(1, &rb);
117 glBindRenderbuffer(GL_RENDERBUFFER, rb);
119 /* Check RenderbufferStorage errors. */
120 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, 1, -1, GL_RGBA8, 64, 64);
121 piglit_check_gl_error(GL_INVALID_VALUE);
123 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, max_color_samples + 1,
124 max_color_storage_samples, GL_RGBA8, 64, 64);
125 piglit_check_gl_error(GL_INVALID_OPERATION);
127 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, max_color_samples,
128 max_color_storage_samples + 1, GL_RGBA8, 64, 64);
129 piglit_check_gl_error(GL_INVALID_OPERATION);
131 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, 2, 3, GL_RGBA8, 64, 64);
132 piglit_check_gl_error(GL_INVALID_OPERATION);
134 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, 2, 3, GL_DEPTH_COMPONENT24, 64, 64);
135 piglit_check_gl_error(GL_INVALID_OPERATION);
137 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, 2, 3, GL_STENCIL_INDEX8, 64, 64);
138 piglit_check_gl_error(GL_INVALID_OPERATION);
140 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, 3, 2, GL_DEPTH_COMPONENT24, 64, 64);
141 piglit_check_gl_error(GL_INVALID_OPERATION);
143 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, 3, 2, GL_STENCIL_INDEX8, 64, 64);
144 piglit_check_gl_error(GL_INVALID_OPERATION);
145 glDeleteRenderbuffers(1, &rb);
147 /* Check that all modes can be allocated and are framebuffer complete. */
148 bool tested_zero_samples = false;
150 for (int i = 0; i < num_modes; i++) {
151 GLuint fb, cb, db, tmp;
153 /* Color */
154 glGenRenderbuffers(1, &cb);
155 glBindRenderbuffer(GL_RENDERBUFFER, cb);
156 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, modes[i*3], modes[i*3+1],
157 GL_RGBA8, 64, 64);
158 piglit_check_gl_error(GL_NO_ERROR);
159 validate_current_renderbuffer("color", modes[i*3], modes[i*3+1]);
161 /* Depth stencil */
162 glGenRenderbuffers(1, &db);
163 glBindRenderbuffer(GL_RENDERBUFFER, db);
164 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER, modes[i*3+2], modes[i*3+2],
165 GL_DEPTH24_STENCIL8, 64, 64);
166 piglit_check_gl_error(GL_NO_ERROR);
167 validate_current_renderbuffer("Z/S", modes[i*3+2], modes[i*3+2]);
169 /* Framebuffer */
170 glGenFramebuffers(1, &fb);
171 glBindFramebuffer(GL_FRAMEBUFFER, fb);
172 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
173 GL_RENDERBUFFER, cb);
174 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
175 GL_RENDERBUFFER, db);
177 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
178 piglit_fail("Incomplete framebuffer for listed mode %u,%u,%u\n",
179 modes[i*3], modes[i*3+1], modes[i*3+2]);
182 glDeleteRenderbuffers(1, &cb);
183 glDeleteRenderbuffers(1, &db);
184 glDeleteFramebuffers(1, &fb);
185 piglit_check_gl_error(GL_NO_ERROR);
187 /* Quickly test the other functions and check that
188 * GL_RENDERBUFFER_STORAGE_SAMPLES_AMD is correct.
190 glGenRenderbuffers(1, &tmp);
191 glBindRenderbuffer(GL_RENDERBUFFER, tmp); /* Bind-to-create. */
192 glBindRenderbuffer(GL_RENDERBUFFER, 0); /* Unbind before glNamed*. */
193 glNamedRenderbufferStorageMultisampleAdvancedAMD(tmp, modes[i*3], modes[i*3+1],
194 GL_RGBA8, 64, 64);
195 glBindRenderbuffer(GL_RENDERBUFFER, tmp);
196 piglit_check_gl_error(GL_NO_ERROR);
197 validate_current_renderbuffer("color(glNamed..Advanced)", modes[i*3], modes[i*3+1]);
198 glDeleteRenderbuffers(1, &tmp);
200 if (modes[i*3] == modes[i*3+1]) {
201 /* Standard MSAA. */
202 unsigned s = modes[i*3];
204 if (piglit_is_extension_supported("GL_ARB_direct_state_access")) {
205 glGenRenderbuffers(1, &tmp);
206 glBindRenderbuffer(GL_RENDERBUFFER, tmp); /* Bind-to-create. */
207 glBindRenderbuffer(GL_RENDERBUFFER, 0); /* Unbind before glNamed*. */
208 glNamedRenderbufferStorageMultisample(tmp, s, GL_RGBA8, 64, 64);
209 glBindRenderbuffer(GL_RENDERBUFFER, tmp);
210 piglit_check_gl_error(GL_NO_ERROR);
211 validate_current_renderbuffer("color(glNamed..Multisample)", s, s);
212 glDeleteRenderbuffers(1, &tmp);
214 if (!tested_zero_samples) {
215 glGenRenderbuffers(1, &tmp);
216 glBindRenderbuffer(GL_RENDERBUFFER, tmp); /* Bind-to-create. */
217 glBindRenderbuffer(GL_RENDERBUFFER, 0); /* Unbind before glNamed*. */
218 glNamedRenderbufferStorage(tmp, GL_RGBA8, 64, 64);
219 glBindRenderbuffer(GL_RENDERBUFFER, tmp);
220 piglit_check_gl_error(GL_NO_ERROR);
221 validate_current_renderbuffer("color(glNamed..Storage)", 0, 0);
222 glDeleteRenderbuffers(1, &tmp);
226 glGenRenderbuffers(1, &tmp);
227 glBindRenderbuffer(GL_RENDERBUFFER, tmp);
228 glRenderbufferStorageMultisample(GL_RENDERBUFFER, s, GL_RGBA8, 64, 64);
229 validate_current_renderbuffer("color(gl..Multisample)", s, s);
230 glDeleteRenderbuffers(1, &tmp);
232 if (!tested_zero_samples) {
233 glGenRenderbuffers(1, &tmp);
234 glBindRenderbuffer(GL_RENDERBUFFER, tmp);
235 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 64, 64);
236 piglit_check_gl_error(GL_NO_ERROR);
237 validate_current_renderbuffer("color(gl..Storage)", 0, 0);
238 glDeleteRenderbuffers(1, &tmp);
240 tested_zero_samples = true;
244 piglit_report_result(PIGLIT_PASS);
247 enum piglit_result
248 piglit_display(void)
250 return PIGLIT_FAIL;