[Mesa-dev] [PATCH 5/7] gallium: add PIPE_FORMAT_ETC1_RGB8

Chia-I Wu olvaffe at gmail.com
Wed Nov 30 23:40:59 PST 2011


On Wed, Nov 30, 2011 at 10:47 PM, Jose Fonseca <jfonseca at vmware.com> wrote:
> The "1" in "ETC1" suggests that there might be related formats in the future. So I think that the trailing "1" should be dropped from UTIL_FORMAT_LAYOUT_ETC1.
>
> Whether "1" should be also dropped from the source files names I can't say/care.
I will drop "1" from the enum.  I will also drop "1" from the file
names.  I do not have a good reason but my own preference for the
renames.  If "1" is desired in the file names, I am fine not renaming
them.

> Otherwise looks good to me. (*)
>
> Jose
>
> (*) Except the Mesa/Gallium format code duplication, which is mea culpa, as I keep not finding the time to do anything about it.
Yeah, I had to move the decoding routines to a header of their own so
that they can be shared..
> ----- Original Message -----
>> From: Chia-I Wu <olv at lunarg.com>
>>
>> The format is defined by GL_OES_compressed_ETC1_RGB8_texture.
>> ---
>>  src/gallium/auxiliary/Makefile.sources       |    1 +
>>  src/gallium/auxiliary/util/u_format.csv      |    3 +
>>  src/gallium/auxiliary/util/u_format.h        |    7 ++-
>>  src/gallium/auxiliary/util/u_format_etc1.c   |  104
>>  ++++++++++++++++++++++++++
>>  src/gallium/auxiliary/util/u_format_etc1.h   |   46 +++++++++++
>>  src/gallium/auxiliary/util/u_format_pack.py  |    2 +-
>>  src/gallium/auxiliary/util/u_format_table.py |    1 +
>>  src/gallium/include/pipe/p_format.h          |    3 +
>>  8 files changed, 165 insertions(+), 2 deletions(-)
>>  create mode 100644 src/gallium/auxiliary/util/u_format_etc1.c
>>  create mode 100644 src/gallium/auxiliary/util/u_format_etc1.h
>>
>> diff --git a/src/gallium/auxiliary/Makefile.sources
>> b/src/gallium/auxiliary/Makefile.sources
>> index 5c65533..80fd3c6 100644
>> --- a/src/gallium/auxiliary/Makefile.sources
>> +++ b/src/gallium/auxiliary/Makefile.sources
>> @@ -103,6 +103,7 @@ C_SOURCES := \
>>       util/u_format_latc.c \
>>       util/u_format_s3tc.c \
>>       util/u_format_rgtc.c \
>> +     util/u_format_etc1.c \
>>       util/u_format_tests.c \
>>       util/u_format_yuv.c \
>>       util/u_format_zs.c \
>> diff --git a/src/gallium/auxiliary/util/u_format.csv
>> b/src/gallium/auxiliary/util/u_format.csv
>> index 4b6fc75..14528cb 100644
>> --- a/src/gallium/auxiliary/util/u_format.csv
>> +++ b/src/gallium/auxiliary/util/u_format.csv
>> @@ -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             , etc1, 4, 4, x64,      ,     ,
>>     , xyz1, rgb
>> +
>>  # Straightforward D3D10-like formats (also used for
>>  # vertex buffer element description)
>>  #
>> diff --git a/src/gallium/auxiliary/util/u_format.h
>> b/src/gallium/auxiliary/util/u_format.h
>> index 99ee676..f133a45 100644
>> --- a/src/gallium/auxiliary/util/u_format.h
>> +++ b/src/gallium/auxiliary/util/u_format.h
>> @@ -70,9 +70,14 @@ enum util_format_layout {
>>     UTIL_FORMAT_LAYOUT_RGTC = 5,
>>
>>     /**
>> +    * Ericsson Texture Compression
>> +    */
>> +   UTIL_FORMAT_LAYOUT_ETC1 = 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_etc1.c
>> b/src/gallium/auxiliary/util/u_format_etc1.c
>> new file mode 100644
>> index 0000000..044ba12
>> --- /dev/null
>> +++ b/src/gallium/auxiliary/util/u_format_etc1.c
>> @@ -0,0 +1,104 @@
>> +#include "pipe/p_compiler.h"
>> +#include "util/u_debug.h"
>> +#include "util/u_math.h"
>> +#include "u_format_etc1.h"
>> +
>> +/* define etc1_parse_block and etc. */
>> +#define UINT8_TYPE uint8_t
>> +#define TAG(x) x
>> +#include "../../../mesa/main/texcompress_etc1_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_etc1.h
>> b/src/gallium/auxiliary/util/u_format_etc1.h
>> new file mode 100644
>> index 0000000..30c3dcb
>> --- /dev/null
>> +++ b/src/gallium/auxiliary/util/u_format_etc1.h
>> @@ -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_ */
>> diff --git a/src/gallium/auxiliary/util/u_format_pack.py
>> b/src/gallium/auxiliary/util/u_format_pack.py
>> index 14a5049..81b645c 100644
>> --- a/src/gallium/auxiliary/util/u_format_pack.py
>> +++ b/src/gallium/auxiliary/util/u_format_pack.py
>> @@ -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', 'etc1', 'subsampled',
>> 'other') or format.colorspace == ZS
>>
>>
>>  def generate(formats):
>> diff --git a/src/gallium/auxiliary/util/u_format_table.py
>> b/src/gallium/auxiliary/util/u_format_table.py
>> index 703d999..f877dc5 100755
>> --- a/src/gallium/auxiliary/util/u_format_table.py
>> +++ b/src/gallium/auxiliary/util/u_format_table.py
>> @@ -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_etc1.h"'
>>      print
>>
>>      u_format_pack.generate(formats)
>> diff --git a/src/gallium/include/pipe/p_format.h
>> b/src/gallium/include/pipe/p_format.h
>> index f229a5a..c05629b 100644
>> --- a/src/gallium/include/pipe/p_format.h
>> +++ b/src/gallium/include/pipe/p_format.h
>> @@ -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
>>  };
>>
>> --
>> 1.7.7.1
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>



-- 
olv at LunarG.com


More information about the mesa-dev mailing list