gallium: add PIPE_FORMAT_ETC1_RGB8
authorChia-I Wu <olv@lunarg.com>
Mon, 28 Nov 2011 16:10:37 +0000 (00:10 +0800)
committerChia-I Wu <olv@lunarg.com>
Fri, 2 Dec 2011 00:43:46 +0000 (08:43 +0800)
The format is defined by GL_OES_compressed_ETC1_RGB8_texture.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/Makefile.sources
src/gallium/auxiliary/util/u_format.csv
src/gallium/auxiliary/util/u_format.h
src/gallium/auxiliary/util/u_format_etc.c [new file with mode: 0644]
src/gallium/auxiliary/util/u_format_etc.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 5c65533308c942b3e4d55503c31fb4361698c22d..d40b95451f098070c1d40a4e7f4d4e004ea2e783 100644 (file)
@@ -103,6 +103,7 @@ C_SOURCES := \
        util/u_format_latc.c \
        util/u_format_s3tc.c \
        util/u_format_rgtc.c \
+       util/u_format_etc.c \
        util/u_format_tests.c \
        util/u_format_yuv.c \
        util/u_format_zs.c \
index 4b6fc75361d6d741e4f70702f3c6c3c6d8bbbfc4..345cc9d47c4be6aee5b3c79998c9d975bd0ebd0b 100644 (file)
@@ -158,6 +158,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.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
 PIPE_FORMAT_DXT1_RGBA             , s3tc, 4, 4, x64 ,     ,     ,     , xyzw, rgb
@@ -178,6 +179,8 @@ PIPE_FORMAT_LATC1_SNORM           , rgtc, 4, 4, x64,      ,     ,     , xxx1, rg
 PIPE_FORMAT_LATC2_UNORM           , rgtc, 4, 4, x128,     ,     ,     , xxxy, rgb
 PIPE_FORMAT_LATC2_SNORM           , rgtc, 4, 4, x128,     ,     ,     , xxxy, rgb
 
+PIPE_FORMAT_ETC1_RGB8             ,  etc, 4, 4, x64,      ,     ,     , xyz1, rgb
+
 # Straightforward D3D10-like formats (also used for 
 # vertex buffer element description)
 # 
index 99ee6767e83d06004e65c14e10fff9910d394ee7..9694c9034d2bff0fcf7337c6c3047113769e45f7 100644 (file)
@@ -69,10 +69,15 @@ enum util_format_layout {
     */
    UTIL_FORMAT_LAYOUT_RGTC = 5,
 
+   /**
+    * Ericsson Texture Compression
+    */
+   UTIL_FORMAT_LAYOUT_ETC = 6,
+
    /**
     * Everything else that doesn't fit in any of the above layouts.
     */
-   UTIL_FORMAT_LAYOUT_OTHER = 6
+   UTIL_FORMAT_LAYOUT_OTHER = 7
 };
 
 
diff --git a/src/gallium/auxiliary/util/u_format_etc.c b/src/gallium/auxiliary/util/u_format_etc.c
new file mode 100644 (file)
index 0000000..7500e1e
--- /dev/null
@@ -0,0 +1,104 @@
+#include "pipe/p_compiler.h"
+#include "util/u_debug.h"
+#include "util/u_math.h"
+#include "u_format_etc.h"
+
+/* define etc1_parse_block and etc. */
+#define UINT8_TYPE uint8_t
+#define TAG(x) x
+#include "../../../mesa/main/texcompress_etc_tmp.h"
+#undef TAG
+#undef UINT8_TYPE
+
+void
+util_format_etc1_rgb8_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
+{
+   const unsigned bw = 4, bh = 4, bs = 8, comps = 4;
+   struct etc1_block block;
+   unsigned x, y, i, j;
+
+   for (y = 0; y < height; y += bh) {
+      const uint8_t *src = src_row;
+
+      for (x = 0; x < width; x+= bw) {
+         etc1_parse_block(&block, src);
+
+         for (j = 0; j < bh; j++) {
+            uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps;
+            for (i = 0; i < bw; i++) {
+               etc1_fetch_texel(&block, i, j, dst);
+               dst[3] = 255;
+               dst += comps;
+            }
+         }
+
+         src += bs;
+      }
+
+      src_row += src_stride;
+   }
+}
+
+void
+util_format_etc1_rgb8_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_etc1_rgb8_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
+{
+   const unsigned bw = 4, bh = 4, bs = 8, comps = 4;
+   struct etc1_block block;
+   unsigned x, y, i, j;
+
+   for (y = 0; y < height; y += bh) {
+      const uint8_t *src = src_row;
+
+      for (x = 0; x < width; x+= bw) {
+         etc1_parse_block(&block, src);
+
+         for (j = 0; j < bh; j++) {
+            float *dst = dst_row + (y + j) * dst_stride / sizeof(*dst_row) + x * comps;
+            uint8_t tmp[3];
+
+            for (i = 0; i < bw; i++) {
+               etc1_fetch_texel(&block, i, j, tmp);
+               dst[0] = ubyte_to_float(tmp[0]);
+               dst[1] = ubyte_to_float(tmp[1]);
+               dst[2] = ubyte_to_float(tmp[2]);
+               dst[3] = 1.0f;
+               dst += comps;
+            }
+         }
+
+         src += bs;
+      }
+
+      src_row += src_stride;
+   }
+}
+
+void
+util_format_etc1_rgb8_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_etc1_rgb8_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
+{
+   const unsigned bw = 4, bh = 4;
+   struct etc1_block block;
+   uint8_t tmp[3];
+
+   assert(i < bw && j < bh);
+
+   etc1_parse_block(&block, src);
+   etc1_fetch_texel(&block, i, j, tmp);
+
+   dst[0] = ubyte_to_float(tmp[0]);
+   dst[1] = ubyte_to_float(tmp[1]);
+   dst[2] = ubyte_to_float(tmp[2]);
+   dst[3] = 1.0f;
+}
diff --git a/src/gallium/auxiliary/util/u_format_etc.h b/src/gallium/auxiliary/util/u_format_etc.h
new file mode 100644 (file)
index 0000000..30c3dcb
--- /dev/null
@@ -0,0 +1,46 @@
+/**************************************************************************
+ *
+ * Copyright 2011 LunarG, 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_ETC1_H_
+#define U_FORMAT_ETC1_H_
+
+void
+util_format_etc1_rgb8_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_etc1_rgb8_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_etc1_rgb8_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_etc1_rgb8_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_etc1_rgb8_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
+
+#endif /* U_FORMAT_ETC1_H_ */
index 14a5049449a2cc22d4e01d5b76a190a0cf2e624e..fff409fb75d2188f47d367c9fc061d0fdf7fae20 100644 (file)
@@ -658,7 +658,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', 'subsampled', 'other') or format.colorspace == ZS
+    return format.layout in ('s3tc', 'rgtc', 'etc', 'subsampled', 'other') or format.colorspace == ZS
 
 
 def generate(formats):
index 703d99959f53721917f079f61585fbe4674f218b..07beb38723be56c8a29d57255e983e9246d7497c 100755 (executable)
@@ -89,6 +89,7 @@ def write_format_table(formats):
     print '#include "u_format_s3tc.h"'
     print '#include "u_format_rgtc.h"'
     print '#include "u_format_latc.h"'
+    print '#include "u_format_etc.h"'
     print
     
     u_format_pack.generate(formats)
index f229a5ad545ff181497ebbbf3f5f70db0b11f70e..c05629b616e113b0ca595f5312c0643ddd029ae2 100644 (file)
@@ -312,6 +312,9 @@ enum pipe_format {
    PIPE_FORMAT_L32A32_SINT             = 224,
 
    PIPE_FORMAT_B10G10R10A2_UINT        = 225, 
+
+   PIPE_FORMAT_ETC1_RGB8               = 226,
+
    PIPE_FORMAT_COUNT
 };