[Mesa-dev] [PATCH v2 05/12] mesa: Add the format enums for BPTC-compressed images

Neil Roberts neil at linux.intel.com
Wed Aug 6 09:27:50 PDT 2014


This adds the following four Mesa image format enums which correspond to the
four BPTC compressed texture formats:

 MESA_FORMAT_BPTC_RGBA_UNORM
 MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
 MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
 MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT

It also updates the format information functions to handle these and the
corresponding GL enums.

v2: Also modify _mesa_get_format_color_encoding, _mesa_get_srgb_format_linear
    and _mesa_get_uncompressed_format
---
 src/mesa/main/formats.c      | 20 ++++++++++++++++++++
 src/mesa/main/formats.csv    |  6 ++++++
 src/mesa/main/formats.h      |  6 ++++++
 src/mesa/main/glformats.c    | 10 ++++++++++
 src/mesa/main/texcompress.c  | 24 ++++++++++++++++++++++++
 src/mesa/main/texformat.c    |  8 ++++++++
 src/mesa/main/teximage.c     | 14 ++++++++++++++
 src/mesa/swrast/s_texfetch.c | 24 ++++++++++++++++++++++++
 8 files changed, 112 insertions(+)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index f03425e..a5e06ce 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -369,6 +369,7 @@ _mesa_get_format_color_encoding(mesa_format format)
    case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
    case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
    case MESA_FORMAT_B8G8R8X8_SRGB:
+   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
       return GL_SRGB;
    default:
       return GL_LINEAR;
@@ -426,6 +427,9 @@ _mesa_get_srgb_format_linear(mesa_format format)
    case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
       format = MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
       break;
+   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
+      format = MESA_FORMAT_BPTC_RGBA_UNORM;
+      break;
    case MESA_FORMAT_B8G8R8X8_SRGB:
       format = MESA_FORMAT_B8G8R8X8_UNORM;
       break;
@@ -491,6 +495,12 @@ _mesa_get_uncompressed_format(mesa_format format)
    case MESA_FORMAT_ETC2_RG11_EAC:
    case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
       return MESA_FORMAT_R16G16_UNORM;
+   case MESA_FORMAT_BPTC_RGBA_UNORM:
+   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
+      return MESA_FORMAT_A8B8G8R8_UNORM;
+   case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
+   case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
+      return MESA_FORMAT_RGB_FLOAT32;
    default:
 #ifdef DEBUG
       assert(!_mesa_is_format_compressed(format));
@@ -968,6 +978,10 @@ _mesa_format_to_type_and_comps(mesa_format format,
    case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
    case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
    case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
+   case MESA_FORMAT_BPTC_RGBA_UNORM:
+   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
+   case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
+   case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
       /* XXX generate error instead? */
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 0;
@@ -1524,6 +1538,12 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
    case MESA_FORMAT_RGBA_DXT5:
       return GL_FALSE;
 
+   case MESA_FORMAT_BPTC_RGBA_UNORM:
+   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
+   case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
+   case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
+      return GL_FALSE;
+
    case MESA_FORMAT_RGBA_FLOAT32:
       return format == GL_RGBA && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_RGBA_FLOAT16:
diff --git a/src/mesa/main/formats.csv b/src/mesa/main/formats.csv
index 5abb706..fdd4341 100644
--- a/src/mesa/main/formats.csv
+++ b/src/mesa/main/formats.csv
@@ -280,3 +280,9 @@ MESA_FORMAT_ETC2_SIGNED_R11_EAC           , etc2  , 4, 4, x64 ,     ,     ,
 MESA_FORMAT_ETC2_SIGNED_RG11_EAC          , etc2  , 4, 4, x128,     ,     ,     , xyzw, rgb
 MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1 , etc2  , 4, 4, x64 ,     ,     ,     , xyzw, rgb
 MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, etc2  , 4, 4, x128,     ,     ,     , xyzw, srgb
+
+# BPTC compressed formats
+MESA_FORMAT_BPTC_RGBA_UNORM               , bptc  , 4, 4, x128,     ,     ,     , xyzw, rgb
+MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM         , bptc  , 4, 4, x128,     ,     ,     , xyzw, srgb
+MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT         , bptc  , 4, 4, x128,     ,     ,     , xyz1, rgb
+MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT       , bptc  , 4, 4, x128,     ,     ,     , xyz1, rgb
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 457c8ab..83a7367 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -427,6 +427,12 @@ typedef enum
    MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1,
    MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1,
 
+   /* BPTC compressed formats */
+   MESA_FORMAT_BPTC_RGBA_UNORM,
+   MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM,
+   MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT,
+   MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT,
+
    MESA_FORMAT_COUNT
 } mesa_format;
 
diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
index 0fb25ba..00478f9 100644
--- a/src/mesa/main/glformats.c
+++ b/src/mesa/main/glformats.c
@@ -787,6 +787,10 @@ _mesa_is_color_format(GLenum format)
       case GL_COMPRESSED_SIGNED_RG11_EAC:
       case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
       case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+      case GL_COMPRESSED_RGBA_BPTC_UNORM:
+      case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
+      case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
+      case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
       /* generic integer formats */
       case GL_RED_INTEGER_EXT:
       case GL_GREEN_INTEGER_EXT:
@@ -1040,6 +1044,12 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
    case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
    case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
       return _mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility;
+   case GL_COMPRESSED_RGBA_BPTC_UNORM:
+   case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
+   case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
+   case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
+      return _mesa_is_desktop_gl(ctx) &&
+         ctx->Extensions.ARB_texture_compression_bptc;
    case GL_PALETTE4_RGB8_OES:
    case GL_PALETTE4_RGBA8_OES:
    case GL_PALETTE4_R5_G6_B5_OES:
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index fb3ea02..53c0ea0 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -235,6 +235,12 @@ _mesa_gl_compressed_format_base_format(GLenum format)
  * GL_EXT_texture_compression_latc.  At the very least, Catalyst 11.6 does not
  * expose the 3dc formats through this mechanism.
  *
+ * The spec for GL_ARB_texture_compression_bptc doesn't mention whether it
+ * should be included in GL_COMPRESSED_TEXTURE_FORMATS. However as it takes a
+ * very long time to compress the textures in this format it's probably not
+ * very useful as a general format where the GL will have to compress it on
+ * the fly.
+ *
  * \param ctx  the GL context
  * \param formats  the resulting format list (may be NULL).
  *
@@ -434,6 +440,15 @@ _mesa_glenum_to_compressed_format(GLenum format)
    case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
       return MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
 
+   case GL_COMPRESSED_RGBA_BPTC_UNORM:
+      return MESA_FORMAT_BPTC_RGBA_UNORM;
+   case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
+      return MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM;
+   case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
+      return MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT;
+   case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
+      return MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT;
+
    default:
       return MESA_FORMAT_NONE;
    }
@@ -515,6 +530,15 @@ _mesa_compressed_format_to_glenum(struct gl_context *ctx, mesa_format mesaFormat
    case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
       return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
 
+   case MESA_FORMAT_BPTC_RGBA_UNORM:
+      return GL_COMPRESSED_RGBA_BPTC_UNORM;
+   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
+      return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
+   case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
+      return GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
+   case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
+      return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
+
    default:
       _mesa_problem(ctx, "Unexpected mesa texture format in"
                     " _mesa_compressed_format_to_glenum()");
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index c61a748..6d3b805 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -345,6 +345,14 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
       return MESA_FORMAT_SRGBA_DXT3;
    case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
       return MESA_FORMAT_SRGBA_DXT5;
+   case GL_COMPRESSED_RGBA_BPTC_UNORM:
+      return MESA_FORMAT_BPTC_RGBA_UNORM;
+   case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
+      return MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM;
+   case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
+      return MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT;
+   case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
+      return MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT;
 
    case GL_ALPHA16F_ARB:
       RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT16);
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index bb050b1..5f8edff 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -520,6 +520,20 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
       }
    }
 
+   if (_mesa_is_desktop_gl(ctx) &&
+       ctx->Extensions.ARB_texture_compression_bptc) {
+      switch (internalFormat) {
+      case GL_COMPRESSED_RGBA_BPTC_UNORM:
+      case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
+         return GL_RGBA;
+      case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
+      case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
+         return GL_RGB;
+      default:
+         ; /* fallthrough */
+      }
+   }
+
    if (ctx->API == API_OPENGLES) {
       switch (internalFormat) {
       case GL_PALETTE4_RGB8_OES:
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index aef0232..38d71ca 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -512,6 +512,30 @@ texfetch_funcs[] =
       fetch_compressed,
       fetch_compressed,
       fetch_compressed
+   },
+   {
+      MESA_FORMAT_BPTC_RGBA_UNORM,
+      fetch_compressed,
+      fetch_compressed,
+      fetch_compressed
+   },
+   {
+      MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM,
+      fetch_compressed,
+      fetch_compressed,
+      fetch_compressed
+   },
+   {
+      MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT,
+      fetch_compressed,
+      fetch_compressed,
+      fetch_compressed
+   },
+   {
+      MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT,
+      fetch_compressed,
+      fetch_compressed,
+      fetch_compressed
    }
 };
 
-- 
1.9.3



More information about the mesa-dev mailing list