summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorLuca Barbieri <[email protected]>2010-04-02 05:23:32 +0200
committerLuca Barbieri <[email protected]>2010-04-02 06:16:30 +0200
commit5126683e3b971ccfb51e50e560750ce44e86bae8 (patch)
treeccdb7104752d266653a1201a97e551bed94ecd23 /src/gallium/auxiliary
parent52e9b990a192a9329006d5f7dd2ac222effea5a5 (diff)
gallium/util: add util_format_is_supported to check for pack/unpack
This improves the code by making it more readable, and removes special knowledge of S3TC and other formats from softpipe.
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/util/u_format.h23
-rw-r--r--src/gallium/auxiliary/util/u_format_s3tc.c18
-rwxr-xr-xsrc/gallium/auxiliary/util/u_format_table.py3
3 files changed, 38 insertions, 6 deletions
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index f7daa6d9236..fc550405d87 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -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" {
@@ -169,6 +169,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.
*
* Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats.
@@ -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,
diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c b/src/gallium/auxiliary/util/u_format_s3tc.c
index 8a5e6f0c437..c1c844e420e 100644
--- a/src/gallium/auxiliary/util/u_format_s3tc.c
+++ b/src/gallium/auxiliary/util/u_format_s3tc.c
@@ -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
}
diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py
index 94a4331b15f..2c0c9bffeed 100755
--- a/src/gallium/auxiliary/util/u_format_table.py
+++ b/src/gallium/auxiliary/util/u_format_table.py
@@ -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]