gallium/util: add util_format_is_supported to check for pack/unpack
authorLuca Barbieri <luca@luca-barbieri.com>
Fri, 2 Apr 2010 03:23:32 +0000 (05:23 +0200)
committerLuca Barbieri <luca@luca-barbieri.com>
Fri, 2 Apr 2010 04:16:30 +0000 (06:16 +0200)
This improves the code by making it more readable, and removes
special knowledge of S3TC and other formats from softpipe.

progs/gallium/unit/u_format_test.c
src/gallium/auxiliary/util/u_format.h
src/gallium/auxiliary/util/u_format_s3tc.c
src/gallium/auxiliary/util/u_format_table.py
src/gallium/drivers/softpipe/sp_screen.c

index dcdbf6548ded59fc4b3e4ed61ed9bddece078726..9883e1e41ca74d703bbef60301d4d279b4b3fe52 100644 (file)
@@ -354,10 +354,8 @@ test_one(test_func_t func, const char *suffix)
 
       format_desc = util_format_description(test->format);
 
-      if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC &&
-          !util_format_s3tc_enabled) {
+      if (!util_format_is_supported(test->format))
          skip = TRUE;
-      }
 
       if (test->format != last_format) {
          printf("%s util_format_%s_%s ...\n",
index f7daa6d923666d9efc215f365fd202f75753a2c4..fc550405d8740b84aab2565c4d95c09fa63e2797 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "pipe/p_format.h"
 #include "util/u_debug.h"
-#include "util/u_inline_init.h"
+#include "util/u_format_s3tc.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -168,6 +168,13 @@ struct util_format_description
     */
    unsigned is_mixed:1;
 
+   /**
+    * Whether the pack/unpack functions actually work.
+    *
+    * Call util_format_is_supported instead of using this directly.
+    */
+   unsigned is_supported:1;
+
    /**
     * Input channel description.
     *
@@ -507,6 +514,20 @@ util_format_get_nr_components(enum pipe_format format)
  * Format access functions.
  */
 
+static INLINE boolean
+util_format_is_supported(enum pipe_format format)
+{
+   const struct util_format_description *desc = util_format_description(format);
+
+   if(!desc)
+      return FALSE;
+
+   if(desc->layout == UTIL_FORMAT_LAYOUT_S3TC)
+      util_format_s3tc_init();
+
+   return desc->is_supported;
+}
+
 void
 util_format_read_4f(enum pipe_format format,
                     float *dst, unsigned dst_stride, 
index 8a5e6f0c43744452ed52d4bbfa2fa45c55dae2ea..c1c844e420e7b1bcde7bac6ae5da5444d2d608b6 100644 (file)
@@ -86,7 +86,6 @@ void util_format_dxtn_pack_stub( int src_comps,
    util_format_dxtn_pack_stub(src_comps, width, height, src, dst_format, dst, dst_stride);
 }
 
-boolean util_format_s3tc_enabled = FALSE;
 boolean util_format_s3tc_inited = FALSE;
 
 util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub;
@@ -141,12 +140,23 @@ util_format_s3tc_do_init(void)
          !is_nop(util_format_dxt5_rgba_fetch) &&
          !is_nop(util_format_dxtn_pack)) {
          debug_printf("software DXTn compression/decompression available");
-         util_format_s3tc_enabled = TRUE;
       } else
          debug_printf("couldn't reference all symbols in "
-            DXTN_LIBNAME ", software DXTn compression/decompression "
-            "unavailable");
+                 DXTN_LIBNAME ", software DXTn compression/decompression "
+                 "unavailable or partially available");
    }
+
+#define DO(n, a, A) \
+  ((struct util_format_description *)util_format_description(PIPE_FORMAT_DXT##n##_SRGB##A))->is_supported = \
+         ((struct util_format_description *)util_format_description(PIPE_FORMAT_DXT##n##_RGB##A))->is_supported = \
+               !is_nop(util_format_dxt##n##_rgb##a##_fetch);
+
+  DO(1,,);
+  DO(1,a,A);
+  DO(3,a,A);
+  DO(5,a,A);
+
+#undef DO
 }
 
 
index 94a4331b15fd253c1b776325c882a8735c8b2bd7..2c0c9bffeed95195134433245070d939b381179d 100755 (executable)
@@ -92,7 +92,7 @@ def write_format_table(formats):
     u_format_pack.generate(formats)
     
     for format in formats:
-        print 'const struct util_format_description'
+        print 'struct util_format_description'
         print 'util_format_%s_description = {' % (format.short_name(),)
         print "   %s," % (format.name,)
         print "   \"%s\"," % (format.name,)
@@ -103,6 +103,7 @@ def write_format_table(formats):
         print "   %s,\t/* is_array */" % (bool_map(format.is_array()),)
         print "   %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),)
         print "   %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),)
+        print "   %s,\t/* is_supported */" % ("TRUE" if u_format_pack.is_format_supported(format) else "FALSE",)
         print "   {"
         for i in range(4):
             channel = format.channels[i]
index 26a4bba57469dbe04befa388b177321ceaec34e1..df527f5cb152b8bf5cd0ac42162881948402926c 100644 (file)
@@ -156,25 +156,9 @@ softpipe_is_format_supported( struct pipe_screen *screen,
           target == PIPE_TEXTURE_3D ||
           target == PIPE_TEXTURE_CUBE);
 
-   switch(format) {
-   case PIPE_FORMAT_YUYV:
-   case PIPE_FORMAT_UYVY:
+   if(!util_format_is_supported(format))
       return FALSE;
 
-   case PIPE_FORMAT_DXT1_RGB:
-   case PIPE_FORMAT_DXT1_RGBA:
-   case PIPE_FORMAT_DXT3_RGBA:
-   case PIPE_FORMAT_DXT5_RGBA:
-      return util_format_s3tc_enabled;
-
-   case PIPE_FORMAT_Z32_FLOAT:
-   case PIPE_FORMAT_NONE:
-      return FALSE;
-
-   default:
-      break;
-   }
-
    if(tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
                    PIPE_TEXTURE_USAGE_SCANOUT |
                    PIPE_TEXTURE_USAGE_SHARED)) {
@@ -182,8 +166,6 @@ softpipe_is_format_supported( struct pipe_screen *screen,
          return FALSE;
    }
 
-   /* XXX: this is often a lie.  Pull in logic from llvmpipe to fix.
-    */
    return TRUE;
 }