mesa: Add the format enums for BPTC-compressed images
authorNeil Roberts <neil@linux.intel.com>
Thu, 17 Jul 2014 13:18:27 +0000 (14:18 +0100)
committerNeil Roberts <neil@linux.intel.com>
Tue, 12 Aug 2014 17:23:50 +0000 (18:23 +0100)
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

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/main/formats.c
src/mesa/main/formats.csv
src/mesa/main/formats.h
src/mesa/main/glformats.c
src/mesa/main/texcompress.c
src/mesa/main/texformat.c
src/mesa/main/teximage.c
src/mesa/swrast/s_texfetch.c

index a4ddbd669633155788abec9cccb15756223c083b..db22a45c46d2e9108a98309212f8002298ab1890 100644 (file)
@@ -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;
@@ -451,6 +452,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;
@@ -516,6 +520,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));
@@ -993,6 +1003,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;
@@ -1549,6 +1563,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:
index eade6facd6047084c67fe8e568fbe43c7b3168e4..4d542b7c6eb1aa3652e4270d0fa5a8652392fdd6 100644 (file)
@@ -280,3 +280,9 @@ MESA_FORMAT_ETC2_SIGNED_R11_EAC           , etc2  , 4, 4, x64 ,     ,     ,
 MESA_FORMAT_ETC2_SIGNED_RG11_EAC          , etc2  , 4, 4, x128,     ,     ,     , xy01, rgb
 MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1 , etc2  , 4, 4, x64 ,     ,     ,     , xyzw, rgb
 MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, etc2  , 4, 4, x64 ,     ,     ,     , 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
index 8166b964c7fe35f450df125ef3c060327dfe4d18..d6253bf862f9c755adf70ac632790d484e9f9b8c 100644 (file)
@@ -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;
 
index 0fb25ba0ff3af8b3f483c2c8348b5a78594b10b9..00478f989a68c6e9c451cfbc3b3e60e644c78f29 100644 (file)
@@ -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:
index fb3ea025b39b2e4f8972d1e833779854dc784f25..53c0ea0220643800808b8b598eda18c495edce89 100644 (file)
@@ -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()");
index c61a74859aac2cc3a02cb339be88d0a59a9ad6bd..6d3b80556618b386592c8f2f0e2eb15c23f078b1 100644 (file)
@@ -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);
index bb050b1882a340b3ed19926794b9a8a04bc46f6b..5f8edff87c699847a1b64331ee393ccaab37364e 100644 (file)
@@ -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:
index aef02321764a61ec5879dbe7f7f0d324d5e5647f..38d71caa38b873468397c56e4ed3c6beca6d83cb 100644 (file)
@@ -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
    }
 };