1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
|
/*
* Copyright © 2011 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/**
* \file internal-format-query.c
* Check that only general-purpose fmts are listed by COMPRESSED_TEXTURE_FORMATS
*
* From page 117 (page 129 of the PDF) of the OpenGL 1.3 spec says:
*
* "The set of specific compressed internal formats supported by the
* renderer can be obtained by querying the value of COMPRESSED TEXTURE
* FORMATS. The only values returned by this query are those corresponding
* to formats suitable for general-purpose usage. The renderer will not
* enumerate formats with restrictions that need to be specifically
* understood prior to use."
*
* All texture compression extensions have taken this to mean only linear RGB
* and linear RGBA formats should be exposed.
*/
#include "piglit-util-gl.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_compat_version = 10;
config.window_width = 10;
config.window_height = 10;
config.window_visual = PIGLIT_GL_VISUAL_RGB;
PIGLIT_GL_TEST_CONFIG_END
/**
* Set of formats for a particular extension
*
* Each array of "good" formats and "bad" formats is terminated by a sentinel
* with \c format set to zero.
*
* \note
* The arrays are sized for the largest set from any extension. They may need
* to be expanded in the future.
*/
struct format_list {
/**
* Formats that are part of the extension and should be exposed.
*/
GLenum good[11];
/**
* Formats that are part of the extension but should not be exposed.
*/
GLenum bad[29];
};
/**
* Formats belonging to GL_ARB_texture_comrpession_bptc
*
* The extension spec says nothing about whether or not these must be
* advertised via GL_COMPRESSED_TEXTURE_FORMATS. The OpenGL 4.2 spec also
* requires these formats, but it says that GL_NUM_COMPRESSED_TEXTURE_FORMATS
* must be at least 0. NVIDIA's driver does not expose them, so we'll
* classify them as optional.
*/
static const struct format_list bptc_formats = {
{
GL_COMPRESSED_RGBA_BPTC_UNORM_ARB,
GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB,
GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB,
GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB,
0,
},
{
0,
}
};
/**
* Formats belonging to GL_ARB_texture_comrpession_rgtc
*/
static const struct format_list rgtc_formats = {
{
0,
},
{
GL_COMPRESSED_RED_RGTC1,
GL_COMPRESSED_SIGNED_RED_RGTC1,
GL_COMPRESSED_RG_RGTC2,
GL_COMPRESSED_SIGNED_RG_RGTC2,
0,
}
};
/**
* Formats belonging to GL_3DFX_texture_comrpession_FXT1
*/
static const struct format_list fxt1_formats = {
{
GL_COMPRESSED_RGB_FXT1_3DFX,
GL_COMPRESSED_RGBA_FXT1_3DFX,
0,
},
{
0,
}
};
/**
* Formats belonging to GL_ATI_texture_comrpession_3dc
*/
static const struct format_list ati_3dc_formats = {
{
0,
},
{
GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI,
0,
}
};
/**
* Formats belonging to GL_EXT_texture_comrpession_latc
*/
static const struct format_list latc_formats = {
{
0,
},
{
GL_COMPRESSED_LUMINANCE_LATC1_EXT,
GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT,
GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT,
GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT,
0,
}
};
/**
* Formats belonging to GL_EXT_texture_comrpession_s3tc
*/
static const struct format_list s3tc_formats = {
{
GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
0,
},
{
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
0,
}
};
/**
* Formats belonging to GL_EXT_texture_sRGB
*
* These should only be exported if GL_EXT_texture_compression_s3tc is also
* supported.
*/
static const struct format_list srgb_formats = {
{
0,
},
{
GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,
GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
0,
}
};
/**
* Formats belonging to GL_OES_comrpessed_paletted_texture
*/
static const struct format_list paletted_formats = {
{
GL_PALETTE4_RGB8_OES,
GL_PALETTE4_RGBA8_OES,
GL_PALETTE4_R5_G6_B5_OES,
GL_PALETTE4_RGBA4_OES,
GL_PALETTE4_RGB5_A1_OES,
GL_PALETTE8_RGB8_OES,
GL_PALETTE8_RGBA8_OES,
GL_PALETTE8_R5_G6_B5_OES,
GL_PALETTE8_RGBA4_OES,
GL_PALETTE8_RGB5_A1_OES,
0,
},
{
0,
}
};
/**
* Format belonging to GL_OES_compressed_ETC1_RGB8_texture.
*
* The GL_OES_compressed_ETC1_RGB8_texture spec says:
*
* "New State
*
* The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
* COMPRESSED_TEXTURE_FORMATS include ETC1_RGB8_OES."
*/
static const struct format_list etc1_formats = {
{
GL_ETC1_RGB8_OES,
0,
},
{
0,
}
};
/**
* Formats belonging to OpenGL ES 3.0
*
* These formats are dragged into desktop OpenGL via GL_ARB_ES3_compatibility
* or OpenGL 4.3. The extension spec says nothing about whether or not these
* must be advertised via GL_COMPRESSED_TEXTURE_FORMATS. The OpenGL 4.3 spec
* requires these formats, but it says that GL_NUM_COMPRESSED_TEXTURE_FORMATS
* must be at least 0. NVIDIA's driver exposes them, so we'll classify them
* as optional.
*/
static const struct format_list etc2_formats = {
{
GL_COMPRESSED_RGB8_ETC2,
GL_COMPRESSED_SRGB8_ETC2,
GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
GL_COMPRESSED_RGBA8_ETC2_EAC,
GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
GL_COMPRESSED_R11_EAC,
GL_COMPRESSED_SIGNED_R11_EAC,
GL_COMPRESSED_RG11_EAC,
GL_COMPRESSED_SIGNED_RG11_EAC,
0,
},
{
0,
}
};
/**
* Formats belonging to GL_KHR_texture_compression_astc_ldr
*/
static const struct format_list astc_formats = {
{
0,
},
{
GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
GL_COMPRESSED_RGBA_ASTC_5x5_KHR,
GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
GL_COMPRESSED_RGBA_ASTC_6x6_KHR,
GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
GL_COMPRESSED_RGBA_ASTC_8x6_KHR,
GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
GL_COMPRESSED_RGBA_ASTC_10x5_KHR,
GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
GL_COMPRESSED_RGBA_ASTC_10x8_KHR,
GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
GL_COMPRESSED_RGBA_ASTC_12x10_KHR,
GL_COMPRESSED_RGBA_ASTC_12x12_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
0,
}
};
/**
* List of all known compression methods to test
*
* The dummy first element is because this list is used by \c main to replace
* the \c argv vector when no command line parameters are supplied.
*/
const char *all_formats[] = {
"argv[0]",
"bptc",
"s3tc",
"fxt1",
"latc",
"3dc",
"rgtc",
"srgb",
"paletted",
"etc1",
"etc2",
"astc",
};
enum piglit_result
piglit_display(void)
{
return PIGLIT_FAIL;
}
static bool
reject_bad(const GLenum *bad, GLenum *compressed_formats,
GLint num_compressed_formats, bool check_errors)
{
bool pass = true;
unsigned i;
unsigned j;
for (i = 0; bad[i] != 0; i++) {
for (j = 0; j < num_compressed_formats; j++) {
if (compressed_formats[j] == 0)
continue;
if (compressed_formats[j] == bad[i])
break;
}
if (j != num_compressed_formats) {
if (check_errors) {
fprintf(stderr,
"%s should not be available.\n",
piglit_get_gl_enum_name(
bad[i]));
pass = false;
}
/* Replace formats that have been processed with
* zero. This allows detection of values that don't
* belong to any compression extension.
*/
compressed_formats[j] = 0;
}
}
return pass;
}
static bool
try_formats(const struct format_list *t, GLenum *compressed_formats,
GLint num_compressed_formats, bool check_errors, bool supported,
bool optional)
{
bool pass = true;
if (!supported) {
pass = reject_bad(t->good, compressed_formats,
num_compressed_formats, check_errors)
&& pass;
} else {
unsigned i;
unsigned j;
for (i = 0; t->good[i] != 0; i++) {
for (j = 0; j < num_compressed_formats; j++) {
if (compressed_formats[j] == 0)
continue;
if (compressed_formats[j] == t->good[i])
break;
}
if (j == num_compressed_formats) {
if (check_errors && !optional) {
fprintf(stderr,
"%s should be available.\n",
piglit_get_gl_enum_name(
t->good[i]));
pass = false;
}
} else {
/* Replace formats that have been processed
* with zero. This allows detection of values
* that don't belong to any compression
* extension.
*/
compressed_formats[j] = 0;
}
}
}
pass = reject_bad(t->bad, compressed_formats, num_compressed_formats,
check_errors)
&& pass;
return pass;
}
static bool
test_hint(void)
{
GLint hint = 0;
glGetIntegerv(GL_TEXTURE_COMPRESSION_HINT, &hint);
if (hint != GL_DONT_CARE) {
printf("Unexpected default GL_TEXTURE_COMPRESSION_HINT"
" value: %s\n", piglit_get_gl_enum_name(hint));
return false;
}
glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
glGetIntegerv(GL_TEXTURE_COMPRESSION_HINT, &hint);
if (hint != GL_NICEST) {
printf("Unexpected GL_TEXTURE_COMPRESSION_HINT"
" value: %s\n", piglit_get_gl_enum_name(hint));
return false;
}
return true;
}
void
piglit_init(int argc, char **argv)
{
GLint num_compressed_formats;
GLenum *compressed_formats = NULL;
unsigned i;
bool pass = true;
bool log_header = true;
bool do_all = false;
bool check_errors = true;
piglit_require_extension("GL_ARB_texture_compression");
glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
&num_compressed_formats);
if (num_compressed_formats == 0) {
printf("No compressed formats supported.\n");
} else {
compressed_formats = calloc(num_compressed_formats,
sizeof(GLenum));
glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS,
(GLint *) compressed_formats);
printf("Driver reported the following compressed formats:\n");
for (i = 0; i < num_compressed_formats; i++) {
printf(" 0x%04x: %s\n",
compressed_formats[i],
piglit_get_gl_enum_name(compressed_formats[i]));
}
printf("\n");
fflush(stdout);
}
/* First scan the list of formats looking for zeros. We use that as
* magic flag later in the test.
*/
for (i = 0; i < num_compressed_formats; i++) {
if (compressed_formats[i] == 0) {
fprintf(stderr,
"Invalid value 0x0000 in format list.\n");
piglit_report_result(PIGLIT_FAIL);
}
}
/* The "unknown" flag instructs the test to just check for values that
* don't belong to any compression extension supported by this
* implementation.
*/
if (argc > 1 && strcmp("unknown", argv[1]) == 0) {
check_errors = false;
argv++;
argc--;
}
if (argc == 1) {
argv = (char **) all_formats; /* cast away const */
argc = ARRAY_SIZE(all_formats);
do_all = true;
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "bptc") == 0) {
pass = try_formats(&bptc_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_ARB_texture_compression_bptc"),
true)
&& pass;
} else if (strcmp(argv[i], "s3tc") == 0) {
pass = try_formats(&s3tc_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_EXT_texture_compression_s3tc"),
false)
&& pass;
} else if (strcmp(argv[i], "fxt1") == 0) {
pass = try_formats(&fxt1_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_3DFX_texture_compression_FXT1"),
false)
&& pass;
} else if (strcmp(argv[i], "latc") == 0) {
pass = try_formats(&latc_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_EXT_texture_compression_latc"),
false)
&& pass;
} else if (strcmp(argv[i], "3dc") == 0) {
pass = try_formats(&ati_3dc_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_ATI_texture_compression_3dc"),
false)
&& pass;
} else if (strcmp(argv[i], "rgtc") == 0) {
pass = try_formats(&rgtc_formats,
compressed_formats,
num_compressed_formats,
check_errors,
(piglit_is_extension_supported("GL_ARB_texture_compression_rgtc")
|| piglit_is_extension_supported("GL_EXT_texture_compression_rgtc")),
false)
&& pass;
} else if (strcmp(argv[i], "srgb") == 0) {
pass = try_formats(&srgb_formats,
compressed_formats,
num_compressed_formats,
check_errors,
(piglit_is_extension_supported("GL_EXT_texture_sRGB")
&& piglit_is_extension_supported("GL_EXT_texture_compression_s3tc")),
false)
&& pass;
} else if (strcmp(argv[i], "paletted") == 0) {
pass = try_formats(&paletted_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_OES_compressed_paletted_texture"),
false)
&& pass;
} else if (strcmp(argv[i], "etc1") == 0) {
pass = try_formats(&etc1_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_OES_compressed_ETC1_RGB8_texture"),
false)
&& pass;
} else if (strcmp(argv[i], "etc2") == 0) {
pass = try_formats(&etc2_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_ARB_ES3_compatibility"),
true)
&& pass;
} else if (strcmp(argv[i], "astc") == 0) {
pass = try_formats(&astc_formats,
compressed_formats,
num_compressed_formats,
check_errors,
piglit_is_extension_supported("GL_KHR_texture_compression_astc_ldr"),
false)
&& pass;
} else {
fprintf(stderr,
"Unrecognized selection `%s'\n", argv[i]);
piglit_report_result(PIGLIT_FAIL);
}
}
/* After all of the known formats have been processed, the entire
* format array should be zeroed out. Any non-zero values are either
* errors or formats from unknown extensions... meaning that the test
* may need to be updated.
*/
if (do_all) {
for (i = 0; i < num_compressed_formats; i++) {
if (compressed_formats[i] != 0) {
if (log_header) {
fprintf(stderr,
"Unrecognized compressed "
"texture formats:\n");
log_header = false;
}
fprintf(stderr, " 0x%04x: %s\n",
compressed_formats[i],
piglit_get_gl_enum_name(compressed_formats[i]));
pass = false;
}
}
}
pass = test_hint() && pass;
piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
|