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
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
37 piglit_fail(const char *fmt
, ...)
43 piglit_report_result(PIGLIT_FAIL
);
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
,
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
);
64 piglit_init(int argc
, char **argv
)
66 piglit_require_extension("GL_AMD_framebuffer_multisample_advanced");
69 int num_modes
, *modes
;
70 glGetIntegerv(GL_NUM_SUPPORTED_MULTISAMPLE_MODES_AMD
, &num_modes
);
71 piglit_check_gl_error(GL_NO_ERROR
);
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
++) {
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
)
110 if (!found_max_color
)
111 piglit_fail("Mode with GL_MAX_COLOR_FRAMEBUFFER_SAMPLES_AMD and ..._STORAGE_SAMPLES_AMD not listed\n");
113 piglit_fail("Modes with GL_MAX_DEPTH_STENCIL_FRAMEBUFFER_SAMPLES_AMD not listed");
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
;
154 glGenRenderbuffers(1, &cb
);
155 glBindRenderbuffer(GL_RENDERBUFFER
, cb
);
156 glRenderbufferStorageMultisampleAdvancedAMD(GL_RENDERBUFFER
, modes
[i
*3], modes
[i
*3+1],
158 piglit_check_gl_error(GL_NO_ERROR
);
159 validate_current_renderbuffer("color", modes
[i
*3], modes
[i
*3+1]);
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]);
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],
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]) {
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
);