Mesa (master): tests: Updated tests to properly handle NaN for half floats.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Fri Jun 29 11:24:28 UTC 2012


Module: Mesa
Branch: master
Commit: c8d3481cdb12a10e02b23d65c73017ce5925cde7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c8d3481cdb12a10e02b23d65c73017ce5925cde7

Author: James Benton <jbenton at vmware.com>
Date:   Tue Jun 12 12:12:16 2012 +0100

tests: Updated tests to properly handle NaN for half floats.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

---

 src/gallium/auxiliary/util/u_format_tests.c   |    6 ++++--
 src/gallium/drivers/llvmpipe/lp_test_format.c |    6 ++++++
 src/gallium/tests/unit/u_format_test.c        |   23 ++++++++++++++++++++++-
 src/gallium/tests/unit/u_half_test.c          |   15 +++++++++------
 4 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format_tests.c b/src/gallium/auxiliary/util/u_format_tests.c
index afbd062..bd7a290 100644
--- a/src/gallium/auxiliary/util/u_format_tests.c
+++ b/src/gallium/auxiliary/util/u_format_tests.c
@@ -905,8 +905,10 @@ util_format_test_cases[] =
    {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), UNPACKED_1x1(        INF, 0.0, 0.0, 1.0)},
    {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), UNPACKED_1x1(       -INF, 0.0, 0.0, 1.0)},
 
-   {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x8000), UNPACKED_1x1(  0.0, 0.0, 0.0, 1.0)},
-   {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(  0.0, 0.0, 0.0, 1.0)},
+   /* Zero, ignore sign */
+   {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0x7fff), PACKED_1x16(0x8000), UNPACKED_1x1( -0.0, 0.0, 0.0, 1.0)},
+   {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0x7fff), PACKED_1x16(0x0000), UNPACKED_1x1(  0.0, 0.0, 0.0, 1.0)},
+
    {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x3c00), UNPACKED_1x1(  1.0, 0.0, 0.0, 1.0)},
    {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0xbc00), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)},
 
diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c
index 6aca66d..daf6ded 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_format.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_format.c
@@ -262,8 +262,13 @@ test_format_unorm8(struct gallivm_state *gallivm,
                match = TRUE;
                for(k = 0; k < 4; ++k) {
                   int error = float_to_ubyte(test->unpacked[i][j][k]) - unpacked[k];
+
+                  if (util_is_double_nan(test->unpacked[i][j][k]))
+                     continue;
+
                   if (error < 0)
                      error = -error;
+
                   if (error > 1)
                      match = FALSE;
                }
@@ -337,6 +342,7 @@ test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp)
          continue;
       }
 
+
       /*
        * TODO: test more
        */
diff --git a/src/gallium/tests/unit/u_format_test.c b/src/gallium/tests/unit/u_format_test.c
index b0e4476..2d89e7e 100644
--- a/src/gallium/tests/unit/u_format_test.c
+++ b/src/gallium/tests/unit/u_format_test.c
@@ -293,9 +293,14 @@ test_format_pack_rgba_float(const struct util_format_description *format_desc,
                            format_desc->block.width, format_desc->block.height);
 
    success = TRUE;
-   for (i = 0; i < format_desc->block.bits/8; ++i)
+   for (i = 0; i < format_desc->block.bits/8; ++i) {
       if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
          success = FALSE;
+   }
+
+   /* Ignore NaN */
+   if (util_is_double_nan(test->unpacked[0][0][0]))
+      success = TRUE;
 
    if (!success) {
       print_packed(format_desc, "FAILED: ", packed, " obtained\n");
@@ -356,6 +361,10 @@ test_format_unpack_rgba_8unorm(const struct util_format_description *format_desc
       }
    }
 
+   /* Ignore NaN */
+   if (util_is_double_nan(test->unpacked[0][0][0]))
+      success = TRUE;
+
    if (!success) {
       print_unpacked_rgba_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
       print_unpacked_rgba_8unorm(format_desc, "        ", expected, " expected\n");
@@ -401,6 +410,18 @@ test_format_pack_rgba_8unorm(const struct util_format_description *format_desc,
       if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
          success = FALSE;
 
+   /* Ignore NaN */
+   if (util_is_double_nan(test->unpacked[0][0][0]))
+      success = TRUE;
+
+   /* Ignore failure cases due to unorm8 format */
+   if (test->unpacked[0][0][0] > 1.0f || test->unpacked[0][0][0] < 0.0f)
+      success = TRUE;
+
+   /* Multiple of 255 */
+   if ((test->unpacked[0][0][0] * 255.0) != (int)(test->unpacked[0][0][0] * 255.0))
+      success = TRUE;
+
    if (!success) {
       print_packed(format_desc, "FAILED: ", packed, " obtained\n");
       print_packed(format_desc, "        ", test->packed, " expected\n");
diff --git a/src/gallium/tests/unit/u_half_test.c b/src/gallium/tests/unit/u_half_test.c
index 00bda7f..a53a043 100644
--- a/src/gallium/tests/unit/u_half_test.c
+++ b/src/gallium/tests/unit/u_half_test.c
@@ -10,17 +10,19 @@ main(int argc, char **argv)
 {
    unsigned i;
    unsigned roundtrip_fails = 0;
+
    for(i = 0; i < 1 << 16; ++i)
    {
       uint16_t h = (uint16_t) i;
       union fi f;
       uint16_t rh;
-      f.ui = util_half_to_floatui(h);
-      rh = util_floatui_to_half(f.ui);
-      if(h != rh)
-      {
-	 printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh);
-	 ++roundtrip_fails;
+
+      f.f = util_half_to_float(h);
+      rh = util_float_to_half(f.f);
+
+      if (h != rh && !(util_is_half_nan(h) && util_is_half_nan(rh))) {
+         printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh);
+         ++roundtrip_fails;
       }
    }
 
@@ -28,5 +30,6 @@ main(int argc, char **argv)
       printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails);
    else
       printf("Success!\n");
+
    return 0;
 }




More information about the mesa-commit mailing list