1 /**************************************************************************
3 * Copyright 2009-2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include "util/u_half.h"
34 #include "util/format/u_format.h"
35 #include "util/format/u_format_tests.h"
36 #include "util/format/u_format_s3tc.h"
40 compare_float(float x
, float y
)
47 if (error
> FLT_EPSILON
) {
56 print_packed(const struct util_format_description
*format_desc
,
58 const uint8_t *packed
,
65 for (i
= 0; i
< format_desc
->block
.bits
/8; ++i
) {
66 printf("%s%02x", sep
, packed
[i
]);
75 print_unpacked_rgba_doubl(const struct util_format_description
*format_desc
,
77 const double unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4],
84 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
85 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
86 printf("%s{%f, %f, %f, %f}", sep
, unpacked
[i
][j
][0], unpacked
[i
][j
][1], unpacked
[i
][j
][2], unpacked
[i
][j
][3]);
97 print_unpacked_rgba_float(const struct util_format_description
*format_desc
,
99 float unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4],
103 const char *sep
= "";
105 printf("%s", prefix
);
106 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
107 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
108 printf("%s{%f, %f, %f, %f}", sep
, unpacked
[i
][j
][0], unpacked
[i
][j
][1], unpacked
[i
][j
][2], unpacked
[i
][j
][3]);
113 printf("%s", suffix
);
119 print_unpacked_rgba_8unorm(const struct util_format_description
*format_desc
,
121 uint8_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4],
125 const char *sep
= "";
127 printf("%s", prefix
);
128 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
129 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
130 printf("%s{0x%02x, 0x%02x, 0x%02x, 0x%02x}", sep
, unpacked
[i
][j
][0], unpacked
[i
][j
][1], unpacked
[i
][j
][2], unpacked
[i
][j
][3]);
134 printf("%s", suffix
);
140 print_unpacked_z_float(const struct util_format_description
*format_desc
,
142 float unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
],
146 const char *sep
= "";
148 printf("%s", prefix
);
149 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
150 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
151 printf("%s%f", sep
, unpacked
[i
][j
]);
156 printf("%s", suffix
);
162 print_unpacked_z_32unorm(const struct util_format_description
*format_desc
,
164 uint32_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
],
168 const char *sep
= "";
170 printf("%s", prefix
);
171 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
172 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
173 printf("%s0x%08x", sep
, unpacked
[i
][j
]);
177 printf("%s", suffix
);
183 print_unpacked_s_8uint(const struct util_format_description
*format_desc
,
185 uint8_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
],
189 const char *sep
= "";
191 printf("%s", prefix
);
192 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
193 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
194 printf("%s0x%02x", sep
, unpacked
[i
][j
]);
198 printf("%s", suffix
);
204 test_format_fetch_rgba_float(const struct util_format_description
*format_desc
,
205 const struct util_format_test_case
*test
)
207 const struct util_format_unpack_description
*unpack
=
208 util_format_unpack_description(format_desc
->format
);
209 float unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4] = { { { 0 } } };
214 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
215 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
216 unpack
->fetch_rgba_float(unpacked
[i
][j
], test
->packed
, j
, i
);
217 for (k
= 0; k
< 4; ++k
) {
218 if (!compare_float(test
->unpacked
[i
][j
][k
], unpacked
[i
][j
][k
])) {
225 /* Ignore S3TC errors */
226 if (format_desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
231 print_unpacked_rgba_float(format_desc
, "FAILED: ", unpacked
, " obtained\n");
232 print_unpacked_rgba_doubl(format_desc
, " ", test
->unpacked
, " expected\n");
240 test_format_unpack_rgba(const struct util_format_description
*format_desc
,
241 const struct util_format_test_case
*test
)
243 const struct util_format_unpack_description
*unpack
=
244 util_format_unpack_description(format_desc
->format
);
245 float unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4] = { { { 0 } } };
249 unpack
->unpack_rgba(&unpacked
[0][0][0], sizeof unpacked
[0],
251 format_desc
->block
.width
, format_desc
->block
.height
);
254 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
255 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
256 for (k
= 0; k
< 4; ++k
) {
257 if (!compare_float(test
->unpacked
[i
][j
][k
], unpacked
[i
][j
][k
])) {
264 /* Ignore S3TC errors */
265 if (format_desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
270 print_unpacked_rgba_float(format_desc
, "FAILED: ", unpacked
, " obtained\n");
271 print_unpacked_rgba_doubl(format_desc
, " ", test
->unpacked
, " expected\n");
279 test_format_pack_rgba_float(const struct util_format_description
*format_desc
,
280 const struct util_format_test_case
*test
)
282 const struct util_format_pack_description
*pack
=
283 util_format_pack_description(format_desc
->format
);
284 float unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4];
285 uint8_t packed
[UTIL_FORMAT_MAX_PACKED_BYTES
];
289 if (test
->format
== PIPE_FORMAT_DXT1_RGBA
) {
291 * Skip S3TC as packed representation is not canonical.
293 * TODO: Do a round trip conversion.
298 memset(packed
, 0, sizeof packed
);
299 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
300 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
301 for (k
= 0; k
< 4; ++k
) {
302 unpacked
[i
][j
][k
] = (float) test
->unpacked
[i
][j
][k
];
307 pack
->pack_rgba_float(packed
, 0,
308 &unpacked
[0][0][0], sizeof unpacked
[0],
309 format_desc
->block
.width
, format_desc
->block
.height
);
312 for (i
= 0; i
< format_desc
->block
.bits
/8; ++i
) {
313 if ((test
->packed
[i
] & test
->mask
[i
]) != (packed
[i
] & test
->mask
[i
]))
318 if (util_is_double_nan(test
->unpacked
[0][0][0]))
321 /* Ignore S3TC errors */
322 if (format_desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
327 print_packed(format_desc
, "FAILED: ", packed
, " obtained\n");
328 print_packed(format_desc
, " ", test
->packed
, " expected\n");
336 convert_float_to_8unorm(uint8_t *dst
, const double *src
)
339 boolean accurate
= TRUE
;
341 for (i
= 0; i
< UTIL_FORMAT_MAX_UNPACKED_HEIGHT
*UTIL_FORMAT_MAX_UNPACKED_WIDTH
*4; ++i
) {
346 else if (src
[i
] > 1.0) {
351 dst
[i
] = src
[i
] * 255.0;
360 test_format_unpack_rgba_8unorm(const struct util_format_description
*format_desc
,
361 const struct util_format_test_case
*test
)
363 const struct util_format_unpack_description
*unpack
=
364 util_format_unpack_description(format_desc
->format
);
365 uint8_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4] = { { { 0 } } };
366 uint8_t expected
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4] = { { { 0 } } };
370 if (util_format_is_pure_integer(format_desc
->format
))
373 unpack
->unpack_rgba_8unorm(&unpacked
[0][0][0], sizeof unpacked
[0],
375 format_desc
->block
.width
, format_desc
->block
.height
);
377 convert_float_to_8unorm(&expected
[0][0][0], &test
->unpacked
[0][0][0]);
380 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
381 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
382 for (k
= 0; k
< 4; ++k
) {
383 if (expected
[i
][j
][k
] != unpacked
[i
][j
][k
]) {
391 if (util_is_double_nan(test
->unpacked
[0][0][0]))
395 print_unpacked_rgba_8unorm(format_desc
, "FAILED: ", unpacked
, " obtained\n");
396 print_unpacked_rgba_8unorm(format_desc
, " ", expected
, " expected\n");
404 test_format_pack_rgba_8unorm(const struct util_format_description
*format_desc
,
405 const struct util_format_test_case
*test
)
407 const struct util_format_pack_description
*pack
=
408 util_format_pack_description(format_desc
->format
);
409 uint8_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
][4];
410 uint8_t packed
[UTIL_FORMAT_MAX_PACKED_BYTES
];
414 if (test
->format
== PIPE_FORMAT_DXT1_RGBA
) {
416 * Skip S3TC as packed representation is not canonical.
418 * TODO: Do a round trip conversion.
423 if (!convert_float_to_8unorm(&unpacked
[0][0][0], &test
->unpacked
[0][0][0])) {
425 * Skip test cases which cannot be represented by four unorm bytes.
430 memset(packed
, 0, sizeof packed
);
432 pack
->pack_rgba_8unorm(packed
, 0,
433 &unpacked
[0][0][0], sizeof unpacked
[0],
434 format_desc
->block
.width
, format_desc
->block
.height
);
437 for (i
= 0; i
< format_desc
->block
.bits
/8; ++i
)
438 if ((test
->packed
[i
] & test
->mask
[i
]) != (packed
[i
] & test
->mask
[i
]))
442 if (util_is_double_nan(test
->unpacked
[0][0][0]))
445 /* Ignore failure cases due to unorm8 format */
446 if (test
->unpacked
[0][0][0] > 1.0f
|| test
->unpacked
[0][0][0] < 0.0f
)
449 /* Multiple of 255 */
450 if ((test
->unpacked
[0][0][0] * 255.0) != (int)(test
->unpacked
[0][0][0] * 255.0))
453 /* Ignore S3TC errors */
454 if (format_desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
459 print_packed(format_desc
, "FAILED: ", packed
, " obtained\n");
460 print_packed(format_desc
, " ", test
->packed
, " expected\n");
468 test_format_unpack_z_float(const struct util_format_description
*format_desc
,
469 const struct util_format_test_case
*test
)
471 const struct util_format_unpack_description
*unpack
=
472 util_format_unpack_description(format_desc
->format
);
473 float unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
] = { { 0 } };
477 unpack
->unpack_z_float(&unpacked
[0][0], sizeof unpacked
[0],
479 format_desc
->block
.width
, format_desc
->block
.height
);
482 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
483 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
484 if (!compare_float(test
->unpacked
[i
][j
][0], unpacked
[i
][j
])) {
491 print_unpacked_z_float(format_desc
, "FAILED: ", unpacked
, " obtained\n");
492 print_unpacked_rgba_doubl(format_desc
, " ", test
->unpacked
, " expected\n");
500 test_format_pack_z_float(const struct util_format_description
*format_desc
,
501 const struct util_format_test_case
*test
)
503 const struct util_format_pack_description
*pack
=
504 util_format_pack_description(format_desc
->format
);
505 float unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
];
506 uint8_t packed
[UTIL_FORMAT_MAX_PACKED_BYTES
];
510 memset(packed
, 0, sizeof packed
);
511 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
512 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
513 unpacked
[i
][j
] = (float) test
->unpacked
[i
][j
][0];
514 if (test
->unpacked
[i
][j
][1]) {
520 pack
->pack_z_float(packed
, 0,
521 &unpacked
[0][0], sizeof unpacked
[0],
522 format_desc
->block
.width
, format_desc
->block
.height
);
525 for (i
= 0; i
< format_desc
->block
.bits
/8; ++i
)
526 if ((test
->packed
[i
] & test
->mask
[i
]) != (packed
[i
] & test
->mask
[i
]))
530 print_packed(format_desc
, "FAILED: ", packed
, " obtained\n");
531 print_packed(format_desc
, " ", test
->packed
, " expected\n");
539 test_format_unpack_z_32unorm(const struct util_format_description
*format_desc
,
540 const struct util_format_test_case
*test
)
542 const struct util_format_unpack_description
*unpack
=
543 util_format_unpack_description(format_desc
->format
);
544 uint32_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
] = { { 0 } };
545 uint32_t expected
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
] = { { 0 } };
549 unpack
->unpack_z_32unorm(&unpacked
[0][0], sizeof unpacked
[0],
551 format_desc
->block
.width
, format_desc
->block
.height
);
553 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
554 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
555 expected
[i
][j
] = test
->unpacked
[i
][j
][0] * 0xffffffff;
560 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
561 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
562 if (expected
[i
][j
] != unpacked
[i
][j
]) {
569 print_unpacked_z_32unorm(format_desc
, "FAILED: ", unpacked
, " obtained\n");
570 print_unpacked_z_32unorm(format_desc
, " ", expected
, " expected\n");
578 test_format_pack_z_32unorm(const struct util_format_description
*format_desc
,
579 const struct util_format_test_case
*test
)
581 const struct util_format_pack_description
*pack
=
582 util_format_pack_description(format_desc
->format
);
583 uint32_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
];
584 uint8_t packed
[UTIL_FORMAT_MAX_PACKED_BYTES
];
588 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
589 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
590 unpacked
[i
][j
] = test
->unpacked
[i
][j
][0] * 0xffffffff;
591 if (test
->unpacked
[i
][j
][1]) {
597 memset(packed
, 0, sizeof packed
);
599 pack
->pack_z_32unorm(packed
, 0,
600 &unpacked
[0][0], sizeof unpacked
[0],
601 format_desc
->block
.width
, format_desc
->block
.height
);
604 for (i
= 0; i
< format_desc
->block
.bits
/8; ++i
)
605 if ((test
->packed
[i
] & test
->mask
[i
]) != (packed
[i
] & test
->mask
[i
]))
609 print_packed(format_desc
, "FAILED: ", packed
, " obtained\n");
610 print_packed(format_desc
, " ", test
->packed
, " expected\n");
618 test_format_unpack_s_8uint(const struct util_format_description
*format_desc
,
619 const struct util_format_test_case
*test
)
621 const struct util_format_unpack_description
*unpack
=
622 util_format_unpack_description(format_desc
->format
);
623 uint8_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
] = { { 0 } };
624 uint8_t expected
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
] = { { 0 } };
628 unpack
->unpack_s_8uint(&unpacked
[0][0], sizeof unpacked
[0],
630 format_desc
->block
.width
, format_desc
->block
.height
);
632 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
633 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
634 expected
[i
][j
] = test
->unpacked
[i
][j
][1];
639 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
640 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
641 if (expected
[i
][j
] != unpacked
[i
][j
]) {
648 print_unpacked_s_8uint(format_desc
, "FAILED: ", unpacked
, " obtained\n");
649 print_unpacked_s_8uint(format_desc
, " ", expected
, " expected\n");
657 test_format_pack_s_8uint(const struct util_format_description
*format_desc
,
658 const struct util_format_test_case
*test
)
660 const struct util_format_pack_description
*pack
=
661 util_format_pack_description(format_desc
->format
);
662 uint8_t unpacked
[UTIL_FORMAT_MAX_UNPACKED_HEIGHT
][UTIL_FORMAT_MAX_UNPACKED_WIDTH
];
663 uint8_t packed
[UTIL_FORMAT_MAX_PACKED_BYTES
];
667 for (i
= 0; i
< format_desc
->block
.height
; ++i
) {
668 for (j
= 0; j
< format_desc
->block
.width
; ++j
) {
669 unpacked
[i
][j
] = test
->unpacked
[i
][j
][1];
670 if (test
->unpacked
[i
][j
][0]) {
676 memset(packed
, 0, sizeof packed
);
678 pack
->pack_s_8uint(packed
, 0,
679 &unpacked
[0][0], sizeof unpacked
[0],
680 format_desc
->block
.width
, format_desc
->block
.height
);
683 for (i
= 0; i
< format_desc
->block
.bits
/8; ++i
)
684 if ((test
->packed
[i
] & test
->mask
[i
]) != (packed
[i
] & test
->mask
[i
]))
688 print_packed(format_desc
, "FAILED: ", packed
, " obtained\n");
689 print_packed(format_desc
, " ", test
->packed
, " expected\n");
696 /* Touch-test that the unorm/snorm flags are set up right by codegen. */
698 test_format_norm_flags(const struct util_format_description
*format_desc
)
700 boolean success
= TRUE
;
702 #define FORMAT_CASE(format, unorm, snorm) \
704 success = (format_desc->is_unorm == unorm && \
705 format_desc->is_snorm == snorm); \
708 switch (format_desc
->format
) {
709 FORMAT_CASE(PIPE_FORMAT_R8G8B8A8_UNORM
, TRUE
, FALSE
);
710 FORMAT_CASE(PIPE_FORMAT_R8G8B8A8_SRGB
, TRUE
, FALSE
);
711 FORMAT_CASE(PIPE_FORMAT_R8G8B8A8_SNORM
, FALSE
, TRUE
);
712 FORMAT_CASE(PIPE_FORMAT_R32_FLOAT
, FALSE
, FALSE
);
713 FORMAT_CASE(PIPE_FORMAT_X8Z24_UNORM
, TRUE
, FALSE
);
714 FORMAT_CASE(PIPE_FORMAT_S8X24_UINT
, FALSE
, FALSE
);
715 FORMAT_CASE(PIPE_FORMAT_DXT1_RGB
, TRUE
, FALSE
);
716 FORMAT_CASE(PIPE_FORMAT_ETC2_RGB8
, TRUE
, FALSE
);
717 FORMAT_CASE(PIPE_FORMAT_ETC2_R11_SNORM
, FALSE
, TRUE
);
718 FORMAT_CASE(PIPE_FORMAT_ASTC_4x4
, TRUE
, FALSE
);
719 FORMAT_CASE(PIPE_FORMAT_BPTC_RGBA_UNORM
, TRUE
, FALSE
);
720 FORMAT_CASE(PIPE_FORMAT_BPTC_RGB_FLOAT
, FALSE
, FALSE
);
722 success
= !(format_desc
->is_unorm
&& format_desc
->is_snorm
);
728 printf("FAILED: %s (unorm %s, snorm %s)\n",
729 format_desc
->short_name
,
730 format_desc
->is_unorm
? "yes" : "no",
731 format_desc
->is_snorm
? "yes" : "no");
738 (*test_func_t
)(const struct util_format_description
*format_desc
,
739 const struct util_format_test_case
*test
);
743 test_one_func(const struct util_format_description
*format_desc
,
748 boolean success
= TRUE
;
750 printf("Testing util_format_%s_%s ...\n",
751 format_desc
->short_name
, suffix
);
754 for (i
= 0; i
< util_format_nr_test_cases
; ++i
) {
755 const struct util_format_test_case
*test
= &util_format_test_cases
[i
];
757 if (test
->format
== format_desc
->format
) {
758 if (!func(format_desc
, &util_format_test_cases
[i
])) {
768 test_format_metadata(const struct util_format_description
*format_desc
,
769 boolean (*func
)(const struct util_format_description
*format_desc
),
772 boolean success
= TRUE
;
774 printf("Testing util_format_%s_%s ...\n", format_desc
->short_name
, suffix
);
777 if (!func(format_desc
)) {
787 enum pipe_format format
;
788 boolean success
= TRUE
;
790 for (format
= 1; format
< PIPE_FORMAT_COUNT
; ++format
) {
791 const struct util_format_description
*format_desc
;
793 format_desc
= util_format_description(format
);
798 assert(format_desc
->block
.bits
<= UTIL_FORMAT_MAX_PACKED_BYTES
* 8);
799 assert(format_desc
->block
.height
<= UTIL_FORMAT_MAX_UNPACKED_HEIGHT
);
800 assert(format_desc
->block
.width
<= UTIL_FORMAT_MAX_UNPACKED_WIDTH
);
802 # define TEST_ONE_PACK_FUNC(name) \
803 if (util_format_pack_description(format)->name) { \
804 if (!test_one_func(format_desc, &test_format_##name, #name)) { \
809 # define TEST_ONE_UNPACK_FUNC(name) \
810 if (util_format_unpack_description(format)->name) { \
811 if (!test_one_func(format_desc, &test_format_##name, #name)) { \
816 # define TEST_FORMAT_METADATA(name) \
817 if (!test_format_metadata(format_desc, &test_format_##name, #name)) { \
821 TEST_ONE_UNPACK_FUNC(fetch_rgba_float);
822 TEST_ONE_PACK_FUNC(pack_rgba_float
);
823 TEST_ONE_UNPACK_FUNC(unpack_rgba
);
824 TEST_ONE_PACK_FUNC(pack_rgba_8unorm
);
825 TEST_ONE_UNPACK_FUNC(unpack_rgba_8unorm
);
827 TEST_ONE_UNPACK_FUNC(unpack_z_32unorm
);
828 TEST_ONE_PACK_FUNC(pack_z_32unorm
);
829 TEST_ONE_UNPACK_FUNC(unpack_z_float
);
830 TEST_ONE_PACK_FUNC(pack_z_float
);
831 TEST_ONE_UNPACK_FUNC(unpack_s_8uint
);
832 TEST_ONE_PACK_FUNC(pack_s_8uint
);
834 TEST_FORMAT_METADATA(norm_flags
);
836 # undef TEST_ONE_FUNC
837 # undef TEST_ONE_FORMAT
844 int main(int argc
, char **argv
)
848 success
= test_all();
850 return success
? 0 : 1;