1 /* Copyright © 2011-2012 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 /** @file minmax-test.c
25 * Helpers for performing minimuTest for the minimum maximum values in section 6.2 "State Tables"
32 #include "piglit-util-gl.h"
33 #include "minmax-test.h"
35 bool piglit_minmax_pass
= true;
37 void piglit_print_minmax_header(void)
39 printf("%-50s %8s %8s\n", "token", "minimum", "value");
43 piglit_report_int(const char *name
, GLint limit
, GLint val
, bool pass
)
46 printf("%-50s %8d %8d\n", name
, limit
, val
);
48 fprintf(stderr
, "%-50s %8d %8d (ERROR)\n",
50 piglit_minmax_pass
= false;
55 piglit_report_uint(const char *name
, GLuint limit
, GLuint val
, bool pass
)
58 printf("%-50s %8u %8u", name
, limit
, val
);
61 piglit_minmax_pass
= false;
67 piglit_report_int64(const char *name
, GLint64 limit
, GLint64 val
, bool pass
)
69 printf("%-50s %8"PRId64
" %8"PRId64
, name
, limit
, val
);
72 piglit_minmax_pass
= false;
78 piglit_report_uint64(const char *name
, GLuint64 limit
, GLuint64 val
, bool pass
)
80 printf("%-50s %8"PRIu64
" %8"PRIu64
, name
, limit
, val
);
83 piglit_minmax_pass
= false;
89 piglit_report_float(const char *name
, GLfloat limit
, GLfloat val
, bool pass
)
92 printf("%-50s %8.1f %8.1f\n", name
, limit
, val
);
94 fprintf(stderr
, "%-50s %8f %8f (ERROR)\n",
96 piglit_minmax_pass
= false;
100 #define SENTINEL 0xDEADBEEF
103 piglit_test_int(GLenum token
, GLint limit
, bool max
)
105 const char *name
= piglit_get_gl_enum_name(token
);
106 GLint val
= SENTINEL
;
109 glGetIntegerv(token
, &val
);
111 pass
= piglit_check_gl_error(GL_NO_ERROR
);
113 piglit_report_int(name
, limit
, val
,
115 val
!= (GLint
)SENTINEL
&&
116 ((max
&& val
<= limit
) ||
117 (!max
&& val
>= limit
)));
121 piglit_test_int_v(GLenum token
, GLuint index
, GLint limit
, bool max
)
125 (void)!asprintf(&name
, "%s[%d]", piglit_get_gl_enum_name(token
), index
);
127 glGetIntegeri_v(token
, index
, &val
);
129 piglit_report_int(name
, limit
, val
,
130 (max
&& val
<= limit
) ||
131 (!max
&& val
>= limit
));
137 piglit_test_uint(GLenum token
, GLuint limit
, bool max
)
139 const char *name
= piglit_get_gl_enum_name(token
);
140 GLuint val
= SENTINEL
;
143 glGetIntegerv(token
, (GLint
*) &val
);
145 pass
= piglit_check_gl_error(GL_NO_ERROR
);
147 piglit_report_uint(name
, limit
, val
,
150 ((max
&& val
<= limit
) ||
151 (!max
&& val
>= limit
)));
155 piglit_test_int64(GLenum token
, GLint64 limit
, bool max
)
157 const char *name
= piglit_get_gl_enum_name(token
);
158 GLint64 val
= SENTINEL
;
161 glGetInteger64v(token
, &val
);
163 pass
= piglit_check_gl_error(GL_NO_ERROR
);
165 piglit_report_int64(name
, limit
, val
,
168 ((max
&& val
<= limit
) ||
169 (!max
&& val
>= limit
)));
173 piglit_test_uint64(GLenum token
, GLuint64 limit
, bool max
)
175 const char *name
= piglit_get_gl_enum_name(token
);
176 GLuint64 val
= SENTINEL
;
179 /* To obtain GLuint64 values, we must use glGetInteger64v.
180 * Justification is found in the GL_ARB_sync spec:
182 * 30) What is the type of the timeout interval?
184 * RESOLVED: GLuint64. [...] Consequently the type of <timeout>
185 * has been changed to 'GLuint64' and a corresponding
186 * 'GetInteger64v' query taking 'GLint64' added (by symmetry
187 * with GetInteger, where unsigned quantities are queries with
188 * a function taking a pointer to a signed integer - the pointer
189 * conversion is harmless).
192 glGetInteger64v(token
, (GLint64
*) &val
);
194 pass
= piglit_check_gl_error(GL_NO_ERROR
);
196 piglit_report_uint64(name
, limit
, val
,
199 ((max
&& val
<= limit
) ||
200 (!max
&& val
>= limit
)));
203 void piglit_test_min_int_v(GLenum token
, GLuint index
, GLint min
)
205 piglit_test_int_v(token
, index
, min
, false);
208 void piglit_test_max_int_v(GLenum token
, GLuint index
, GLint max
)
210 piglit_test_int_v(token
, index
, max
, true);
213 void piglit_test_min_int(GLenum token
, GLint min
)
215 piglit_test_int(token
, min
, false);
218 void piglit_test_max_int(GLenum token
, GLint max
)
220 piglit_test_int(token
, max
, true);
223 void piglit_test_min_uint(GLenum token
, GLuint min
)
225 piglit_test_uint(token
, min
, false);
228 void piglit_test_max_uint(GLenum token
, GLuint max
)
230 piglit_test_uint(token
, max
, true);
233 void piglit_test_min_int64(GLenum token
, GLint64 min
)
235 piglit_test_int64(token
, min
, false);
238 void piglit_test_max_int64(GLenum token
, GLint64 max
)
240 piglit_test_int64(token
, max
, true);
243 void piglit_test_min_uint64(GLenum token
, GLuint64 min
)
245 piglit_test_uint64(token
, min
, false);
248 void piglit_test_max_uint64(GLenum token
, GLuint64 max
)
250 piglit_test_uint64(token
, max
, true);
254 piglit_test_float(GLenum token
, GLfloat limit
, bool max
)
256 const char *name
= piglit_get_gl_enum_name(token
);
257 GLfloat val
= SENTINEL
;
260 glGetFloatv(token
, &val
);
262 pass
= piglit_check_gl_error(GL_NO_ERROR
);
264 piglit_report_float(name
, limit
, val
,
266 val
!= (GLfloat
)SENTINEL
&&
267 ((max
&& val
<= limit
) ||
268 (!max
&& val
>= limit
)));
271 void piglit_test_min_float(GLenum token
, GLfloat min
)
273 piglit_test_float(token
, min
, false);
276 void piglit_test_max_float(GLenum token
, GLfloat max
)
278 piglit_test_float(token
, max
, true);
281 /** Tests that the range referenced by the token covers at least low-high. */
282 void piglit_test_range_float(GLenum token
, GLfloat low
, GLfloat high
)
284 const char *name
= piglit_get_gl_enum_name(token
);
286 GLfloat vals
[2] = {SENTINEL
, SENTINEL
};
289 glGetFloatv(token
, vals
);
291 pass
= piglit_check_gl_error(GL_NO_ERROR
);
293 (void)!asprintf(&temp
, "%s[0]", name
);
294 piglit_report_float(temp
, low
, vals
[0], pass
&& vals
[0] <= low
);
297 (void)!asprintf(&temp
, "%s[1]", name
);
298 piglit_report_float(temp
, high
, vals
[1], pass
&& vals
[1] >= high
);
302 void piglit_test_min_viewport_dimensions(void)
305 GLint dims
[2] = {9999, 9999};
307 if (piglit_get_gl_version() < 30) {
310 * "The maximum viewport dimensions must be
311 * greater than or equal to the larger of the
312 * visible dimensions of the display being
313 * rendered to (if a display exists), and the
314 * largest renderbuffer image which can be
315 * successfully created and attached to a
316 * framebuffer object (see chapter 4). INVALID
317 * VALUE is generated if either w or h is
320 * We're only looking at RB limits here.
323 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE
, &rb_size
);
330 * "The maximum viewport dimensions must be
331 * greater than or equal to the visible
332 * dimensions of the display being rendered to."
334 * Surely the screen is at least 1024x768, right?
340 glGetIntegerv(GL_MAX_VIEWPORT_DIMS
, dims
);
342 piglit_report_int("GL_MAX_VIEWPORT_DIMS[0]", min_w
, dims
[0],
344 piglit_report_int("GL_MAX_VIEWPORT_DIMS[1]", min_h
, dims
[1],
349 piglit_test_oq_bits()
351 GLint dims
[2] = {9999, 9999};
352 GLint minbits
, oqbits
= 9999;
354 /* From the GL 2.1 specification:
356 * "The number of query counter bits may be zero, in which
357 * case the counter contains no useful
358 * information. Otherwise, the minimum number of bits
359 * allowed is a function of the implementation’s maximum
360 * viewport dimensions (MAX_VIEWPORT_DIMS). In this case,
361 * the counter must be able to represent at least two
362 * overdraws for every pixel in the viewport The formula
363 * to compute the allowable minimum value (where n is the
364 * minimum number of bits) is:
366 * n = min{32, log2(maxViewportWidth ∗ maxViewportHeight * 2}"
369 glGetIntegerv(GL_MAX_VIEWPORT_DIMS
, dims
);
370 minbits
= log2((float)dims
[0] * dims
[1] * 2);
374 glGetQueryiv(GL_SAMPLES_PASSED
, GL_QUERY_COUNTER_BITS
, &oqbits
);
375 if (oqbits
== 0 || oqbits
>= minbits
) {
376 printf("%-50s 0 / %2d %8d\n",
377 "GL_QUERY_COUNTER_BITS(GL_SAMPLES_PASSED)",
381 "%-50s 0 / %2d %8d\n",
382 "GL_QUERY_COUNTER_BITS(GL_SAMPLES_PASSED)",
384 piglit_minmax_pass
= false;
389 piglit_test_tf_bits(GLenum target
)
394 if (target
== GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
)
395 name
= "GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN bits";
397 name
= "GL_PRIMITIVES_GENERATED bits";
399 /* From the GL 3.0 specification, page 329:
401 * "If pname is QUERY_COUNTER_BITS, the
402 * implementation-dependent number of query counter bits
403 * may be zero, in which case the counter contains no
404 * useful information.
406 * For primitive queries (PRIMITIVES GENERATED and
407 * TRANSFORM FEEDBACK PRIMITIVES WRITTEN) if the number
408 * of bits is non-zero, the minimum number of bits
412 glGetQueryiv(target
, GL_QUERY_COUNTER_BITS
, &bits
);
413 if (bits
== 0 || bits
>= 32) {
414 printf("%-50s %8s %8d\n", name
, "0 / 32", bits
);
416 fprintf(stderr
, "%-50s %8s %8d (ERROR)\n",
417 name
, "0 / 32", bits
);
418 piglit_minmax_pass
= false;