tests: Updated tests to properly handle NaN for half floats.
authorJames Benton <jbenton@vmware.com>
Tue, 12 Jun 2012 11:12:16 +0000 (12:12 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 29 Jun 2012 11:20:59 +0000 (12:20 +0100)
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/util/u_format_tests.c
src/gallium/drivers/llvmpipe/lp_test_format.c
src/gallium/tests/unit/u_format_test.c
src/gallium/tests/unit/u_half_test.c

index afbd06247905744e07defd501f2bccfeeb9b9cde..bd7a290c46ec1d7e71826aea628fc1903a4459e3 100644 (file)
@@ -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)},
 
index 6aca66dc700fed8326f467bb1137eaec9332fc70..daf6ded29c731b04417d77006ff064523a7e9cd3 100644 (file)
@@ -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
        */
index b0e44766bd90dae85383fbf4385eccc60109345b..2d89e7ed45bfd80811681e10a6387792342acda2 100644 (file)
@@ -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");
index 00bda7f50a6cd0c9b7cbfc688aac2111f3a3697b..a53a043bfdeca4f3c0328ab7e02365b4f60a5507 100644 (file)
@@ -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;
 }