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
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
26 * Verify that minimum value requirements for implementation limits
27 * are satisfied. Equivalent to query1 minmax, but testing against
28 * GetInternalformati64v too.
33 #include <inttypes.h> /* for PRIu64 macro */
35 #define ERROR_HEADER(data) test_data_get_testing64(data) ? \
36 fprintf(stderr, "64 bit query: ") : \
37 fprintf(stderr, "32 bit query: ");
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 10;
42 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
43 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
45 PIGLIT_GL_TEST_CONFIG_END
47 /* These are all the formats that are required to be color-renderable
48 * by the OpenGL 3.0 spec.
50 * But note that GL_ALPHA8 was removed on 3.1 and beyond on core, or
51 * if ARB_compatibility is missing, so we need to take that into
54 static const GLenum valid_formats
[] = {
72 static const GLenum valid_integer_formats
[] = {
93 static const GLenum valid_depth_formats
[] = {
96 GL_DEPTH_COMPONENT32F
,
99 static const GLenum valid_targets_with_tms
[] = {
101 GL_TEXTURE_2D_MULTISAMPLE
,
102 GL_TEXTURE_2D_MULTISAMPLE_ARRAY
,
112 real_try(GLenum target
, GLenum format
, GLint max_samples
,
113 const char *max_samples_name
,
114 test_data
*data_counts
,
115 test_data
*data_samples
)
118 int buffer_size_in_elements
= 0;
122 test_data_set_params_size(data_counts
, 1);
123 test_data_execute(data_counts
, target
, format
,
124 GL_NUM_SAMPLE_COUNTS
);
126 buffer_size_in_elements
= test_data_value_at_index(data_counts
, 0);
127 pass
= piglit_check_gl_error(0)
130 /* The GL_ARB_internalformat_query spec says:
132 * "Add new table 6.X Internalformat-specific
133 * Implementation Dependent Values after 6.52"
136 * Get Value Type Get Command Value
137 * --------- ---- ----------- -------
138 * SAMPLES 0*xZ+ GetInternalformativ fn1
139 * NUM_SAMPLE_COUNTS Z+ GetInternalformativ 1
141 * fn1: see section 6.X."
143 if (buffer_size_in_elements
< 1) {
144 ERROR_HEADER(data_counts
);
146 "GL_NUM_SAMPLE_COUNTS is %d for %s/%s\n",
147 buffer_size_in_elements
,
148 piglit_get_gl_enum_name(target
),
149 piglit_get_gl_enum_name(format
));
153 test_data_set_params_size(data_samples
, buffer_size_in_elements
);
157 test_data_execute(data_samples
, target
,
159 pass
= piglit_check_gl_error(0)
162 /* The GL_ARB_internalformat_query spec says:
164 * "- SAMPLES: The sample counts supported for this
165 * <format> and <target> are written into <params>, in
166 * descending order. Only positive values are
169 * We take "positive" to mean greater than zero. Zero isn't a
170 * valid sample count for multisampling. It's the special
171 * value used to request non-multisampling.
174 for (i
= 0; i
< test_data_get_params_size(data_samples
); i
++) {
175 if (test_data_value_at_index(data_samples
, i
) <= 0) {
176 ERROR_HEADER(data_samples
);
178 "Invalid sample count [%u] = %" PRIi64
" returned "
179 "for %s/%s (num sample counts = %i)\n",
180 i
, test_data_value_at_index(data_samples
, i
),
181 piglit_get_gl_enum_name(target
),
182 piglit_get_gl_enum_name(format
),
183 buffer_size_in_elements
);
187 if (previous
== test_data_value_at_index(data_samples
, i
)) {
188 ERROR_HEADER(data_samples
);
190 "Duplicate values [%u] = [%u] = %" PRIi64
" returned "
191 "for %s/%s (num sample counts = %i)\n",
192 i
- 1, i
, test_data_value_at_index(data_samples
, i
),
193 piglit_get_gl_enum_name(target
),
194 piglit_get_gl_enum_name(format
),
195 buffer_size_in_elements
);
199 if (previous
< test_data_value_at_index(data_samples
, i
)) {
200 ERROR_HEADER(data_samples
);
202 "Values not in descending order "
203 "([%u] = %d) < ([%u] = %" PRIi64
") returned "
204 "for %s/%s (num sample counts = %i)\n",
206 i
, test_data_value_at_index(data_samples
, i
),
207 piglit_get_gl_enum_name(target
),
208 piglit_get_gl_enum_name(format
),
209 buffer_size_in_elements
);
213 previous
= test_data_value_at_index(data_samples
, i
);
216 /* The GL_ARB_internalformat_query spec says:
218 * "The maximum value in SAMPLES is guaranteed to be at
219 * least the lowest of the following:
221 * - The value of GetIntegerv(MAX_INTEGER_SAMPLES), if
222 * <internalformat> is a signed or unsigned integer format.
223 * - The value of GetIntegerv(MAX_DEPTH_TEXTURE_SAMPLES), if
224 * <internalformat> is a depth/stencil-renderable format and
225 * <target> is TEXTURE_2D_MULTISAMPLE or
226 * TEXTURE_2D_MULTISAMPLE_ARRAY.
227 * - The value of GetIntegerv(MAX_COLOR_TEXTURE_SAMPLES), if
228 * <internalformat> is a color-renderable format and <target>
229 * is TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY.
230 * - The value of GetIntegerv(MAX_SAMPLES)."
232 * Separate tests will verify the values for GL_MAX_*_SAMPLES.
234 if (test_data_value_at_index(data_samples
, 0) < max_samples
) {
235 ERROR_HEADER(data_samples
);
237 "GL_SAMPLES (%" PRIi64
") smaller than %s (%d) "
239 test_data_value_at_index(data_samples
, 0),
242 piglit_get_gl_enum_name(target
),
243 piglit_get_gl_enum_name(format
));
252 * This is a wrapping method that handles the need to test using
253 * GetInternalformativ and GetInternalformati64v. This way piglit_init
254 * is basically the same that query1 counterpart, and real_try is just
255 * try() at query1, but using the test_data structs. Also helps on the
259 try(GLenum target
, GLenum format
, GLint max_samples
,
260 const char *max_samples_name
)
262 /* real params_size will be set at real_try() */
263 test_data
*data_counts
= test_data_new(0, 0);
264 test_data
*data_samples
= test_data_new(0, 0);
268 for (testing64
= 0; testing64
<= 1; testing64
++) {
269 test_data_set_testing64(data_counts
, testing64
);
270 test_data_set_testing64(data_samples
, testing64
);
272 result
= real_try(target
, format
, max_samples
, max_samples_name
,
273 data_counts
, data_samples
);
276 test_data_clear(&data_counts
);
277 test_data_clear(&data_samples
);
283 piglit_init(int argc
, char **argv
)
287 const bool tms_supported
=
288 piglit_is_extension_supported("GL_ARB_texture_multisample");
290 GLint valid_formats_size
= ARRAY_SIZE(valid_formats
);
292 piglit_require_extension("GL_ARB_framebuffer_object");
293 piglit_require_extension("GL_ARB_internalformat_query2");
294 initialize_valid_internalformats();
296 /* Need GL 3 or extensions to support the valid_formats[] above */
297 if (piglit_get_gl_version() < 30) {
298 piglit_require_extension("GL_ARB_texture_rg");
299 piglit_require_extension("GL_ARB_texture_float");
302 /* GL_ALPHA8 was removed on OpenGL 3.1 core, or if
303 * ARB_compatibility is missing, so on that case we skip that
306 if (piglit_get_gl_version() >= 31 &&
307 (piglit_is_core_profile
||
308 !piglit_is_extension_supported("GL_ARB_compatibility")))
309 valid_formats_size
= valid_formats_size
- 1;
311 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
312 for (i
= 0; i
< valid_formats_size
; i
++) {
313 pass
= try(GL_RENDERBUFFER
,
320 if (!tms_supported
) {
321 for (i
= 0; i
< ARRAY_SIZE(valid_depth_formats
); i
++) {
322 pass
= try(GL_RENDERBUFFER
,
323 valid_depth_formats
[i
],
329 /* The OpenGL 3.1 spec says:
331 * "The error INVALID_OPERATION may be generated if
332 * internalformat is a signed or unsigned integer format,
333 * samples is greater than one, and the implementation
334 * does not support multisampled integer renderbuffers
335 * (see “Required Renderbuffer Formats” below)."
337 * In OpenGL 3.2 or ARB_texture_multisample the query
338 * GL_MAX_INTEGER_SAMPLES is used to determine the
339 * maximum number of samples for integer buffers.
340 * This is checked in the other code path.
342 for (i
= 0; i
< ARRAY_SIZE(valid_integer_formats
); i
++) {
343 pass
= try(GL_RENDERBUFFER
,
344 valid_integer_formats
[i
],
350 for (i
= 0; i
< ARRAY_SIZE(valid_targets_with_tms
); i
++) {
351 const char *max_samples_name
;
354 if (valid_targets_with_tms
[i
] == GL_RENDERBUFFER
) {
355 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
356 max_samples_name
= "GL_MAX_SAMPLES";
358 glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES
,
360 max_samples_name
= "GL_MAX_COLOR_TEXTURE_SAMPLES";
363 for (j
= 0; j
< valid_formats_size
; j
++) {
364 pass
= try(valid_targets_with_tms
[i
],
371 if (valid_targets_with_tms
[i
] == GL_RENDERBUFFER
) {
372 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
373 max_samples_name
= "GL_MAX_SAMPLES";
375 glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES
,
377 max_samples_name
= "GL_MAX_DEPTH_TEXTURE_SAMPLES";
380 for (j
= 0; j
< ARRAY_SIZE(valid_depth_formats
); j
++) {
381 pass
= try(valid_targets_with_tms
[i
],
382 valid_depth_formats
[j
],
388 glGetIntegerv(GL_MAX_INTEGER_SAMPLES
, &max_samples
);
389 max_samples_name
= "GL_MAX_INTEGER_SAMPLES";
391 for (j
= 0; j
< ARRAY_SIZE(valid_integer_formats
); j
++) {
392 pass
= try(valid_targets_with_tms
[i
],
393 valid_integer_formats
[j
],
401 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);