ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_compression / invalid-formats.c
blobcca35cc0f9c725b13afdb962be94727d407d6ba7
1 /*
2 * Copyright © 2011 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 internal-format-query.c
26 * Check that only general-purpose fmts are listed by COMPRESSED_TEXTURE_FORMATS
28 * From page 117 (page 129 of the PDF) of the OpenGL 1.3 spec says:
30 * "The set of specific compressed internal formats supported by the
31 * renderer can be obtained by querying the value of COMPRESSED TEXTURE
32 * FORMATS. The only values returned by this query are those corresponding
33 * to formats suitable for general-purpose usage. The renderer will not
34 * enumerate formats with restrictions that need to be specifically
35 * understood prior to use."
37 * All texture compression extensions have taken this to mean only linear RGB
38 * and linear RGBA formats should be exposed.
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 10;
46 config.window_width = 10;
47 config.window_height = 10;
48 config.window_visual = PIGLIT_GL_VISUAL_RGB;
50 PIGLIT_GL_TEST_CONFIG_END
52 /**
53 * Set of formats for a particular extension
55 * Each array of "good" formats and "bad" formats is terminated by a sentinel
56 * with \c format set to zero.
58 * \note
59 * The arrays are sized for the largest set from any extension. They may need
60 * to be expanded in the future.
62 struct format_list {
63 /**
64 * Formats that are part of the extension and should be exposed.
66 GLenum good[11];
68 /**
69 * Formats that are part of the extension but should not be exposed.
71 GLenum bad[29];
74 /**
75 * Formats belonging to GL_ARB_texture_comrpession_bptc
77 * The extension spec says nothing about whether or not these must be
78 * advertised via GL_COMPRESSED_TEXTURE_FORMATS. The OpenGL 4.2 spec also
79 * requires these formats, but it says that GL_NUM_COMPRESSED_TEXTURE_FORMATS
80 * must be at least 0. NVIDIA's driver does not expose them, so we'll
81 * classify them as optional.
83 static const struct format_list bptc_formats = {
85 GL_COMPRESSED_RGBA_BPTC_UNORM_ARB,
86 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB,
87 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB,
88 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB,
96 /**
97 * Formats belonging to GL_ARB_texture_comrpession_rgtc
99 static const struct format_list rgtc_formats = {
104 GL_COMPRESSED_RED_RGTC1,
105 GL_COMPRESSED_SIGNED_RED_RGTC1,
106 GL_COMPRESSED_RG_RGTC2,
107 GL_COMPRESSED_SIGNED_RG_RGTC2,
113 * Formats belonging to GL_3DFX_texture_comrpession_FXT1
115 static const struct format_list fxt1_formats = {
117 GL_COMPRESSED_RGB_FXT1_3DFX,
118 GL_COMPRESSED_RGBA_FXT1_3DFX,
127 * Formats belonging to GL_ATI_texture_comrpession_3dc
129 static const struct format_list ati_3dc_formats = {
134 GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI,
140 * Formats belonging to GL_EXT_texture_comrpession_latc
142 static const struct format_list latc_formats = {
147 GL_COMPRESSED_LUMINANCE_LATC1_EXT,
148 GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT,
149 GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT,
150 GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT,
156 * Formats belonging to GL_EXT_texture_comrpession_s3tc
158 static const struct format_list s3tc_formats = {
160 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
161 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
162 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
166 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
172 * Formats belonging to GL_EXT_texture_sRGB
174 * These should only be exported if GL_EXT_texture_compression_s3tc is also
175 * supported.
177 static const struct format_list srgb_formats = {
182 GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,
183 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
184 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
185 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
191 * Formats belonging to GL_OES_comrpessed_paletted_texture
193 static const struct format_list paletted_formats = {
195 GL_PALETTE4_RGB8_OES,
196 GL_PALETTE4_RGBA8_OES,
197 GL_PALETTE4_R5_G6_B5_OES,
198 GL_PALETTE4_RGBA4_OES,
199 GL_PALETTE4_RGB5_A1_OES,
200 GL_PALETTE8_RGB8_OES,
201 GL_PALETTE8_RGBA8_OES,
202 GL_PALETTE8_R5_G6_B5_OES,
203 GL_PALETTE8_RGBA4_OES,
204 GL_PALETTE8_RGB5_A1_OES,
213 * Format belonging to GL_OES_compressed_ETC1_RGB8_texture.
215 * The GL_OES_compressed_ETC1_RGB8_texture spec says:
217 * "New State
219 * The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
220 * COMPRESSED_TEXTURE_FORMATS include ETC1_RGB8_OES."
222 static const struct format_list etc1_formats = {
224 GL_ETC1_RGB8_OES,
233 * Formats belonging to OpenGL ES 3.0
235 * These formats are dragged into desktop OpenGL via GL_ARB_ES3_compatibility
236 * or OpenGL 4.3. The extension spec says nothing about whether or not these
237 * must be advertised via GL_COMPRESSED_TEXTURE_FORMATS. The OpenGL 4.3 spec
238 * requires these formats, but it says that GL_NUM_COMPRESSED_TEXTURE_FORMATS
239 * must be at least 0. NVIDIA's driver exposes them, so we'll classify them
240 * as optional.
242 static const struct format_list etc2_formats = {
244 GL_COMPRESSED_RGB8_ETC2,
245 GL_COMPRESSED_SRGB8_ETC2,
246 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
247 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
248 GL_COMPRESSED_RGBA8_ETC2_EAC,
249 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
250 GL_COMPRESSED_R11_EAC,
251 GL_COMPRESSED_SIGNED_R11_EAC,
252 GL_COMPRESSED_RG11_EAC,
253 GL_COMPRESSED_SIGNED_RG11_EAC,
262 * Formats belonging to GL_KHR_texture_compression_astc_ldr
264 static const struct format_list astc_formats = {
269 GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
270 GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
271 GL_COMPRESSED_RGBA_ASTC_5x5_KHR,
272 GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
273 GL_COMPRESSED_RGBA_ASTC_6x6_KHR,
274 GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
275 GL_COMPRESSED_RGBA_ASTC_8x6_KHR,
276 GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
277 GL_COMPRESSED_RGBA_ASTC_10x5_KHR,
278 GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
279 GL_COMPRESSED_RGBA_ASTC_10x8_KHR,
280 GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
281 GL_COMPRESSED_RGBA_ASTC_12x10_KHR,
282 GL_COMPRESSED_RGBA_ASTC_12x12_KHR,
283 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
284 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
285 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
286 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
287 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
288 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
289 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
290 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
291 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
292 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
293 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
294 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
295 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
296 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
302 * List of all known compression methods to test
304 * The dummy first element is because this list is used by \c main to replace
305 * the \c argv vector when no command line parameters are supplied.
307 const char *all_formats[] = {
308 "argv[0]",
309 "bptc",
310 "s3tc",
311 "fxt1",
312 "latc",
313 "3dc",
314 "rgtc",
315 "srgb",
316 "paletted",
317 "etc1",
318 "etc2",
319 "astc",
322 enum piglit_result
323 piglit_display(void)
325 return PIGLIT_FAIL;
328 static bool
329 reject_bad(const GLenum *bad, GLenum *compressed_formats,
330 GLint num_compressed_formats, bool check_errors)
332 bool pass = true;
333 unsigned i;
334 unsigned j;
336 for (i = 0; bad[i] != 0; i++) {
337 for (j = 0; j < num_compressed_formats; j++) {
338 if (compressed_formats[j] == 0)
339 continue;
341 if (compressed_formats[j] == bad[i])
342 break;
345 if (j != num_compressed_formats) {
346 if (check_errors) {
347 fprintf(stderr,
348 "%s should not be available.\n",
349 piglit_get_gl_enum_name(
350 bad[i]));
351 pass = false;
354 /* Replace formats that have been processed with
355 * zero. This allows detection of values that don't
356 * belong to any compression extension.
358 compressed_formats[j] = 0;
362 return pass;
365 static bool
366 try_formats(const struct format_list *t, GLenum *compressed_formats,
367 GLint num_compressed_formats, bool check_errors, bool supported,
368 bool optional)
370 bool pass = true;
372 if (!supported) {
373 pass = reject_bad(t->good, compressed_formats,
374 num_compressed_formats, check_errors)
375 && pass;
376 } else {
377 unsigned i;
378 unsigned j;
380 for (i = 0; t->good[i] != 0; i++) {
381 for (j = 0; j < num_compressed_formats; j++) {
382 if (compressed_formats[j] == 0)
383 continue;
385 if (compressed_formats[j] == t->good[i])
386 break;
389 if (j == num_compressed_formats) {
390 if (check_errors && !optional) {
391 fprintf(stderr,
392 "%s should be available.\n",
393 piglit_get_gl_enum_name(
394 t->good[i]));
395 pass = false;
397 } else {
398 /* Replace formats that have been processed
399 * with zero. This allows detection of values
400 * that don't belong to any compression
401 * extension.
403 compressed_formats[j] = 0;
408 pass = reject_bad(t->bad, compressed_formats, num_compressed_formats,
409 check_errors)
410 && pass;
412 return pass;
416 static bool
417 test_hint(void)
419 GLint hint = 0;
420 glGetIntegerv(GL_TEXTURE_COMPRESSION_HINT, &hint);
421 if (hint != GL_DONT_CARE) {
422 printf("Unexpected default GL_TEXTURE_COMPRESSION_HINT"
423 " value: %s\n", piglit_get_gl_enum_name(hint));
424 return false;
427 glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
428 glGetIntegerv(GL_TEXTURE_COMPRESSION_HINT, &hint);
429 if (hint != GL_NICEST) {
430 printf("Unexpected GL_TEXTURE_COMPRESSION_HINT"
431 " value: %s\n", piglit_get_gl_enum_name(hint));
432 return false;
435 return true;
439 void
440 piglit_init(int argc, char **argv)
442 GLint num_compressed_formats;
443 GLenum *compressed_formats = NULL;
444 unsigned i;
445 bool pass = true;
446 bool log_header = true;
447 bool do_all = false;
448 bool check_errors = true;
450 piglit_require_extension("GL_ARB_texture_compression");
452 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
453 &num_compressed_formats);
454 if (num_compressed_formats == 0) {
455 printf("No compressed formats supported.\n");
456 } else {
457 compressed_formats = calloc(num_compressed_formats,
458 sizeof(GLenum));
459 glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS,
460 (GLint *) compressed_formats);
462 printf("Driver reported the following compressed formats:\n");
463 for (i = 0; i < num_compressed_formats; i++) {
464 printf(" 0x%04x: %s\n",
465 compressed_formats[i],
466 piglit_get_gl_enum_name(compressed_formats[i]));
468 printf("\n");
469 fflush(stdout);
472 /* First scan the list of formats looking for zeros. We use that as
473 * magic flag later in the test.
475 for (i = 0; i < num_compressed_formats; i++) {
476 if (compressed_formats[i] == 0) {
477 fprintf(stderr,
478 "Invalid value 0x0000 in format list.\n");
479 piglit_report_result(PIGLIT_FAIL);
483 /* The "unknown" flag instructs the test to just check for values that
484 * don't belong to any compression extension supported by this
485 * implementation.
487 if (argc > 1 && strcmp("unknown", argv[1]) == 0) {
488 check_errors = false;
489 argv++;
490 argc--;
493 if (argc == 1) {
494 argv = (char **) all_formats; /* cast away const */
495 argc = ARRAY_SIZE(all_formats);
496 do_all = true;
499 for (i = 1; i < argc; i++) {
500 if (strcmp(argv[i], "bptc") == 0) {
501 pass = try_formats(&bptc_formats,
502 compressed_formats,
503 num_compressed_formats,
504 check_errors,
505 piglit_is_extension_supported("GL_ARB_texture_compression_bptc"),
506 true)
507 && pass;
508 } else if (strcmp(argv[i], "s3tc") == 0) {
509 pass = try_formats(&s3tc_formats,
510 compressed_formats,
511 num_compressed_formats,
512 check_errors,
513 piglit_is_extension_supported("GL_EXT_texture_compression_s3tc"),
514 false)
515 && pass;
516 } else if (strcmp(argv[i], "fxt1") == 0) {
517 pass = try_formats(&fxt1_formats,
518 compressed_formats,
519 num_compressed_formats,
520 check_errors,
521 piglit_is_extension_supported("GL_3DFX_texture_compression_FXT1"),
522 false)
523 && pass;
524 } else if (strcmp(argv[i], "latc") == 0) {
525 pass = try_formats(&latc_formats,
526 compressed_formats,
527 num_compressed_formats,
528 check_errors,
529 piglit_is_extension_supported("GL_EXT_texture_compression_latc"),
530 false)
531 && pass;
532 } else if (strcmp(argv[i], "3dc") == 0) {
533 pass = try_formats(&ati_3dc_formats,
534 compressed_formats,
535 num_compressed_formats,
536 check_errors,
537 piglit_is_extension_supported("GL_ATI_texture_compression_3dc"),
538 false)
539 && pass;
540 } else if (strcmp(argv[i], "rgtc") == 0) {
541 pass = try_formats(&rgtc_formats,
542 compressed_formats,
543 num_compressed_formats,
544 check_errors,
545 (piglit_is_extension_supported("GL_ARB_texture_compression_rgtc")
546 || piglit_is_extension_supported("GL_EXT_texture_compression_rgtc")),
547 false)
548 && pass;
549 } else if (strcmp(argv[i], "srgb") == 0) {
550 pass = try_formats(&srgb_formats,
551 compressed_formats,
552 num_compressed_formats,
553 check_errors,
554 (piglit_is_extension_supported("GL_EXT_texture_sRGB")
555 && piglit_is_extension_supported("GL_EXT_texture_compression_s3tc")),
556 false)
557 && pass;
558 } else if (strcmp(argv[i], "paletted") == 0) {
559 pass = try_formats(&paletted_formats,
560 compressed_formats,
561 num_compressed_formats,
562 check_errors,
563 piglit_is_extension_supported("GL_OES_compressed_paletted_texture"),
564 false)
565 && pass;
566 } else if (strcmp(argv[i], "etc1") == 0) {
567 pass = try_formats(&etc1_formats,
568 compressed_formats,
569 num_compressed_formats,
570 check_errors,
571 piglit_is_extension_supported("GL_OES_compressed_ETC1_RGB8_texture"),
572 false)
573 && pass;
574 } else if (strcmp(argv[i], "etc2") == 0) {
575 pass = try_formats(&etc2_formats,
576 compressed_formats,
577 num_compressed_formats,
578 check_errors,
579 piglit_is_extension_supported("GL_ARB_ES3_compatibility"),
580 true)
581 && pass;
582 } else if (strcmp(argv[i], "astc") == 0) {
583 pass = try_formats(&astc_formats,
584 compressed_formats,
585 num_compressed_formats,
586 check_errors,
587 piglit_is_extension_supported("GL_KHR_texture_compression_astc_ldr"),
588 false)
589 && pass;
590 } else {
591 fprintf(stderr,
592 "Unrecognized selection `%s'\n", argv[i]);
593 piglit_report_result(PIGLIT_FAIL);
597 /* After all of the known formats have been processed, the entire
598 * format array should be zeroed out. Any non-zero values are either
599 * errors or formats from unknown extensions... meaning that the test
600 * may need to be updated.
602 if (do_all) {
603 for (i = 0; i < num_compressed_formats; i++) {
604 if (compressed_formats[i] != 0) {
605 if (log_header) {
606 fprintf(stderr,
607 "Unrecognized compressed "
608 "texture formats:\n");
609 log_header = false;
612 fprintf(stderr, " 0x%04x: %s\n",
613 compressed_formats[i],
614 piglit_get_gl_enum_name(compressed_formats[i]));
615 pass = false;
620 pass = test_hint() && pass;
622 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);