gallium/util: revert util_format_init addition
[mesa.git] / src / gallium / auxiliary / util / u_format.h
index 4d59b9927d3ced148daf3f6b233c5832388f1f54..2ac3abab23ae95eeb18129e71a17f11a67b103c7 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "pipe/p_format.h"
 #include "util/u_debug.h"
+#include "util/u_format_s3tc.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -167,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.
     *
@@ -189,6 +197,46 @@ struct util_format_description
     * Colorspace transformation.
     */
    enum util_format_colorspace colorspace;
+
+   /**
+    * Unpack pixel blocks to R8G8B8A8_UNORM.
+    */
+   void
+   (*unpack_8unorm)(uint8_t *dst, unsigned dst_stride,
+                    const uint8_t *src, unsigned src_stride,
+                    unsigned width, unsigned height);
+
+   /**
+    * Pack pixel blocks from R8G8B8A8_UNORM.
+    */
+   void
+   (*pack_8unorm)(uint8_t *dst, unsigned dst_stride,
+                  const uint8_t *src, unsigned src_stride,
+                  unsigned width, unsigned height);
+
+   /**
+    * Unpack pixel blocks to R32G32B32A32_FLOAT.
+    */
+   void
+   (*unpack_float)(float *dst, unsigned dst_stride,
+                   const uint8_t *src, unsigned src_stride,
+                   unsigned width, unsigned height);
+
+   /**
+    * Pack pixel blocks from R32G32B32A32_FLOAT.
+    */
+   void
+   (*pack_float)(uint8_t *dst, unsigned dst_stride,
+                 const float *src, unsigned src_stride,
+                 unsigned width, unsigned height);
+
+   /**
+    * Fetch a single pixel (i, j) from a block.
+    */
+   void
+   (*fetch_float)(float *dst,
+                  const uint8_t *src,
+                  unsigned i, unsigned j);
 };
 
 
@@ -209,8 +257,8 @@ util_format_name(enum pipe_format format)
 {
    const struct util_format_description *desc = util_format_description(format);
 
-   assert(format);
-   if (!format) {
+   assert(desc);
+   if (!desc) {
       return "???";
    }
 
@@ -222,8 +270,8 @@ util_format_is_s3tc(enum pipe_format format)
 {
    const struct util_format_description *desc = util_format_description(format);
 
-   assert(format);
-   if (!format) {
+   assert(desc);
+   if (!desc) {
       return FALSE;
    }
 
@@ -235,8 +283,8 @@ util_format_is_depth_or_stencil(enum pipe_format format)
 {
    const struct util_format_description *desc = util_format_description(format);
 
-   assert(format);
-   if (!format) {
+   assert(desc);
+   if (!desc) {
       return FALSE;
    }
 
@@ -248,8 +296,8 @@ util_format_is_depth_and_stencil(enum pipe_format format)
 {
    const struct util_format_description *desc = util_format_description(format);
 
-   assert(format);
-   if (!format) {
+   assert(desc);
+   if (!desc) {
       return FALSE;
    }
 
@@ -298,8 +346,8 @@ util_format_get_blocksizebits(enum pipe_format format)
 {
    const struct util_format_description *desc = util_format_description(format);
 
-   assert(format);
-   if (!format) {
+   assert(desc);
+   if (!desc) {
       return 0;
    }
 
@@ -324,8 +372,8 @@ util_format_get_blockwidth(enum pipe_format format)
 {
    const struct util_format_description *desc = util_format_description(format);
 
-   assert(format);
-   if (!format) {
+   assert(desc);
+   if (!desc) {
       return 1;
    }
 
@@ -337,8 +385,8 @@ util_format_get_blockheight(enum pipe_format format)
 {
    const struct util_format_description *desc = util_format_description(format);
 
-   assert(format);
-   if (!format) {
+   assert(desc);
+   if (!desc) {
       return 1;
    }
 
@@ -466,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,