gallium: add basic support for BPTC formats
authorIlia Mirkin <imirkin@alum.mit.edu>
Tue, 22 Jul 2014 23:58:00 +0000 (19:58 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Tue, 12 Aug 2014 23:21:04 +0000 (19:21 -0400)
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/Makefile.sources
src/gallium/auxiliary/util/u_format.c
src/gallium/auxiliary/util/u_format.csv
src/gallium/auxiliary/util/u_format.h
src/gallium/auxiliary/util/u_format_bptc.c [new file with mode: 0644]
src/gallium/auxiliary/util/u_format_bptc.h [new file with mode: 0644]
src/gallium/auxiliary/util/u_format_pack.py
src/gallium/auxiliary/util/u_format_table.py
src/gallium/include/pipe/p_format.h

index 3eae9e52526c0fe03e558e27d000adb40f2f7e52..9bfaa0eabfc56817c61ca5beafb0fc7a57afe3a7 100644 (file)
@@ -113,6 +113,7 @@ C_SOURCES := \
        util/u_format_s3tc.c \
        util/u_format_rgtc.c \
        util/u_format_etc.c \
+       util/u_format_bptc.c \
        util/u_format_tests.c \
        util/u_format_yuv.c \
        util/u_format_zs.c \
index a53ed6f297b6b2c1e2eff225e50f2751091a6850..d53dd7884f0157ca83c1522fc1e5ffd6eda3b7ba 100644 (file)
@@ -496,6 +496,10 @@ util_format_fits_8unorm(const struct util_format_description *format_desc)
           format_desc->format == PIPE_FORMAT_LATC2_SNORM)
          return FALSE;
       return TRUE;
+   case UTIL_FORMAT_LAYOUT_BPTC:
+      if (format_desc->format == PIPE_FORMAT_BPTC_RGBA_UNORM)
+         return TRUE;
+      return FALSE;
 
    case UTIL_FORMAT_LAYOUT_PLAIN:
       /*
index 8aa5c364de976f53375d90fbbc15ccb3f8525213..17034049deae74c8e2c973ae213f7db611505bf0 100644 (file)
@@ -160,6 +160,7 @@ PIPE_FORMAT_R8G8Bx_SNORM          , other,      1,  1, sn8 , sn8 ,     ,     , x
 # - http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt
 # - http://www.opengl.org/registry/specs/ARB/texture_compression_rgtc.txt
 # - http://www.opengl.org/registry/specs/EXT/texture_compression_latc.txt
+# - http://www.opengl.org/registry/specs/ARB/texture_compression_bptc.txt
 # - http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
 # - http://msdn.microsoft.com/en-us/library/bb694531.aspx
 PIPE_FORMAT_DXT1_RGB              , s3tc, 4, 4, x64 ,     ,     ,     , xyz1, rgb
@@ -183,6 +184,11 @@ PIPE_FORMAT_LATC2_SNORM           , rgtc, 4, 4, x128,     ,     ,     , xxxy, rg
 
 PIPE_FORMAT_ETC1_RGB8             ,  etc, 4, 4, x64,      ,     ,     , xyz1, rgb
 
+PIPE_FORMAT_BPTC_RGBA_UNORM       , bptc, 4, 4, x128,     ,     ,     , xyzw, rgb
+PIPE_FORMAT_BPTC_SRGBA            , bptc, 4, 4, x128,     ,     ,     , xyzw, srgb
+PIPE_FORMAT_BPTC_RGB_FLOAT        , bptc, 4, 4, x128,     ,     ,     , xyz1, rgb
+PIPE_FORMAT_BPTC_RGB_UFLOAT       , bptc, 4, 4, x128,     ,     ,     , xyz1, rgb
+
 # Straightforward D3D10-like formats (also used for 
 # vertex buffer element description)
 # 
index 2e2bf0240dd5ec46bdd81a21965919d3a4a01f75..df31400af900971f529dca90b13c0edda2c35309 100644 (file)
@@ -78,10 +78,15 @@ enum util_format_layout {
     */
    UTIL_FORMAT_LAYOUT_ETC = 6,
 
+   /**
+    * BC6/7 Texture Compression
+    */
+   UTIL_FORMAT_LAYOUT_BPTC = 7,
+
    /**
     * Everything else that doesn't fit in any of the above layouts.
     */
-   UTIL_FORMAT_LAYOUT_OTHER = 7
+   UTIL_FORMAT_LAYOUT_OTHER = 8
 };
 
 
@@ -475,6 +480,7 @@ util_format_is_compressed(enum pipe_format format)
    case UTIL_FORMAT_LAYOUT_S3TC:
    case UTIL_FORMAT_LAYOUT_RGTC:
    case UTIL_FORMAT_LAYOUT_ETC:
+   case UTIL_FORMAT_LAYOUT_BPTC:
       /* XXX add other formats in the future */
       return TRUE;
    default:
@@ -911,6 +917,8 @@ util_format_srgb(enum pipe_format format)
       return PIPE_FORMAT_DXT5_SRGBA;
    case PIPE_FORMAT_B5G6R5_UNORM:
       return PIPE_FORMAT_B5G6R5_SRGB;
+   case PIPE_FORMAT_BPTC_RGBA_UNORM:
+      return PIPE_FORMAT_BPTC_SRGBA;
    default:
       return PIPE_FORMAT_NONE;
    }
@@ -956,6 +964,8 @@ util_format_linear(enum pipe_format format)
       return PIPE_FORMAT_DXT5_RGBA;
    case PIPE_FORMAT_B5G6R5_SRGB:
       return PIPE_FORMAT_B5G6R5_UNORM;
+   case PIPE_FORMAT_BPTC_SRGBA:
+      return PIPE_FORMAT_BPTC_RGBA_UNORM;
    default:
       return format;
    }
diff --git a/src/gallium/auxiliary/util/u_format_bptc.c b/src/gallium/auxiliary/util/u_format_bptc.c
new file mode 100644 (file)
index 0000000..196220e
--- /dev/null
@@ -0,0 +1,26 @@
+#include "u_format.h"
+#include "u_format_bptc.h"
+
+#define fake(format) \
+void \
+util_format_##format##_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) {assert(0);} \
+\
+void \
+util_format_##format##_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) {assert(0);} \
+\
+void \
+util_format_##format##_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) {assert(0);} \
+\
+void \
+util_format_##format##_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) {assert(0);} \
+\
+void \
+util_format_##format##_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) {assert(0);} \
+\
+void \
+util_format_##format##_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) {assert(0);}
+
+fake(bptc_rgba_unorm)
+fake(bptc_srgba)
+fake(bptc_rgb_float)
+fake(bptc_rgb_ufloat)
diff --git a/src/gallium/auxiliary/util/u_format_bptc.h b/src/gallium/auxiliary/util/u_format_bptc.h
new file mode 100644 (file)
index 0000000..f67d071
--- /dev/null
@@ -0,0 +1,109 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Red Hat Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ **************************************************************************/
+
+#ifndef U_FORMAT_BPTC_H_
+#define U_FORMAT_BPTC_H_
+
+void
+util_format_bptc_rgba_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
+
+void
+util_format_bptc_rgba_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgba_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgba_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
+
+
+
+void
+util_format_bptc_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
+
+void
+util_format_bptc_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
+
+
+
+void
+util_format_bptc_rgb_float_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
+
+void
+util_format_bptc_rgb_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_float_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
+
+
+void
+util_format_bptc_rgb_ufloat_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
+
+void
+util_format_bptc_rgb_ufloat_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_ufloat_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_ufloat_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_ufloat_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_bptc_rgb_ufloat_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
+
+
+#endif
index a553e2346a9582ded81c87dc505b67d9af497c9e..6ccf04c29e7754a778d3ed3193c4a3ca91c6bc7b 100644 (file)
@@ -659,7 +659,7 @@ def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix):
 
 
 def is_format_hand_written(format):
-    return format.layout in ('s3tc', 'rgtc', 'etc', 'subsampled', 'other') or format.colorspace == ZS
+    return format.layout in ('s3tc', 'rgtc', 'etc', 'bptc', 'subsampled', 'other') or format.colorspace == ZS
 
 
 def generate(formats):
index 81fd3996f5d9a6357bcd10ada94567421c8185da..ad582e4f54c44cccac2c3d872ad511781fb2400c 100755 (executable)
@@ -90,6 +90,7 @@ def write_format_table(formats):
     print '#include "u_format_rgtc.h"'
     print '#include "u_format_latc.h"'
     print '#include "u_format_etc.h"'
+    print '#include "u_format_bptc.h"'
     print
     
     u_format_pack.generate(formats)
@@ -141,7 +142,7 @@ def write_format_table(formats):
         if format.colorspace != ZS and not format.is_pure_color():
             print "   &util_format_%s_unpack_rgba_8unorm," % format.short_name() 
             print "   &util_format_%s_pack_rgba_8unorm," % format.short_name() 
-            if format.layout == 's3tc' or format.layout == 'rgtc':
+            if format.layout == 's3tc' or format.layout == 'rgtc' or format.layout == 'bptc':
                 print "   &util_format_%s_fetch_rgba_8unorm," % format.short_name()
             else:
                 print "   NULL, /* fetch_rgba_8unorm */" 
index a7fdcd0f4a7660735f670e906e994c9661e38b02..1b048840ff8977cca413a8d07fae76c5dd395034 100644 (file)
@@ -344,6 +344,11 @@ enum pipe_format {
 
    PIPE_FORMAT_B5G6R5_SRGB             = 254,
 
+   PIPE_FORMAT_BPTC_RGBA_UNORM         = 255,
+   PIPE_FORMAT_BPTC_SRGBA              = 256,
+   PIPE_FORMAT_BPTC_RGB_FLOAT          = 257,
+   PIPE_FORMAT_BPTC_RGB_UFLOAT         = 258,
+
    PIPE_FORMAT_COUNT
 };