framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / arb_internalformat_query2 / minmax.c
blobb07dcb2ea8fc1ce0a3576a8c0ab7fbf00e21d867
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 /**
25 * \file minmax.c
26 * Verify that minimum value requirements for implementation limits
27 * are satisfied. Equivalent to query1 minmax, but testing against
28 * GetInternalformati64v too.
31 #include <limits.h>
32 #include "common.h"
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
52 * account.
54 static const GLenum valid_formats[] = {
55 GL_RGBA32F,
56 GL_RGBA16,
57 GL_RGBA16F,
58 GL_RGBA8,
59 GL_SRGB8_ALPHA8,
60 GL_R11F_G11F_B10F,
61 GL_RG32F,
62 GL_RG16,
63 GL_RG16F,
64 GL_RG8,
65 GL_R32F,
66 GL_R16,
67 GL_R16F,
68 GL_R8,
69 GL_ALPHA8,
72 static const GLenum valid_integer_formats[] = {
73 GL_RGBA32I,
74 GL_RGBA32UI,
75 GL_RGBA16I,
76 GL_RGBA16UI,
77 GL_RGBA8I,
78 GL_RGBA8UI,
79 GL_RG32I,
80 GL_RG32UI,
81 GL_RG16I,
82 GL_RG16UI,
83 GL_RG8I,
84 GL_RG8UI,
85 GL_R32I,
86 GL_R32UI,
87 GL_R16I,
88 GL_R16UI,
89 GL_R8I,
90 GL_R8UI,
93 static const GLenum valid_depth_formats[] = {
94 GL_DEPTH_COMPONENT16,
95 GL_DEPTH_COMPONENT24,
96 GL_DEPTH_COMPONENT32F,
99 static const GLenum valid_targets_with_tms[] = {
100 GL_RENDERBUFFER,
101 GL_TEXTURE_2D_MULTISAMPLE,
102 GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
105 enum piglit_result
106 piglit_display(void)
108 return PIGLIT_FAIL;
111 static bool
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)
117 bool pass = true;
118 int buffer_size_in_elements = 0;
119 unsigned i;
120 GLint previous;
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)
128 && pass;
130 /* The GL_ARB_internalformat_query spec says:
132 * "Add new table 6.X Internalformat-specific
133 * Implementation Dependent Values after 6.52"
135 * Minimum
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);
145 fprintf(stderr,
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));
150 return false;
153 test_data_set_params_size(data_samples, buffer_size_in_elements);
155 /* Try GL_SAMPLES
157 test_data_execute(data_samples, target,
158 format, GL_SAMPLES);
159 pass = piglit_check_gl_error(0)
160 && pass;
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
167 * returned."
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.
173 previous = INT_MAX;
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);
177 fprintf(stderr,
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);
184 pass = false;
187 if (previous == test_data_value_at_index(data_samples, i)) {
188 ERROR_HEADER(data_samples);
189 fprintf(stderr,
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);
196 pass = false;
199 if (previous < test_data_value_at_index(data_samples, i)) {
200 ERROR_HEADER(data_samples);
201 fprintf(stderr,
202 "Values not in descending order "
203 "([%u] = %d) < ([%u] = %" PRIi64 ") returned "
204 "for %s/%s (num sample counts = %i)\n",
205 i - 1, previous,
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);
210 pass = false;
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);
236 fprintf(stderr,
237 "GL_SAMPLES (%" PRIi64 ") smaller than %s (%d) "
238 "for %s/%s\n",
239 test_data_value_at_index(data_samples, 0),
240 max_samples_name,
241 max_samples,
242 piglit_get_gl_enum_name(target),
243 piglit_get_gl_enum_name(format));
244 pass = false;
247 return pass;
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
256 * indentation.
258 static bool
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);
265 bool result;
266 int testing64;
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);
279 return result;
282 void
283 piglit_init(int argc, char **argv)
285 bool pass = true;
286 unsigned i;
287 const bool tms_supported =
288 piglit_is_extension_supported("GL_ARB_texture_multisample");
289 GLint max_samples;
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
304 * format
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,
314 valid_formats[i],
315 max_samples,
316 "GL_MAX_SAMPLES")
317 && pass;
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],
324 max_samples,
325 "GL_MAX_SAMPLES")
326 && pass;
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],
346 "one")
347 && pass;
349 } else {
350 for (i = 0; i < ARRAY_SIZE(valid_targets_with_tms); i++) {
351 const char *max_samples_name;
352 unsigned j;
354 if (valid_targets_with_tms[i] == GL_RENDERBUFFER) {
355 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
356 max_samples_name = "GL_MAX_SAMPLES";
357 } else {
358 glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES,
359 &max_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],
365 valid_formats[j],
366 max_samples,
367 max_samples_name)
368 && pass;
371 if (valid_targets_with_tms[i] == GL_RENDERBUFFER) {
372 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
373 max_samples_name = "GL_MAX_SAMPLES";
374 } else {
375 glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES,
376 &max_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],
383 max_samples,
384 max_samples_name)
385 && pass;
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],
394 max_samples,
395 max_samples_name)
396 && pass;
401 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);