[Mesa-dev] [PATCH 1/5] mesa: add GL_AMD_compressed_ATC_texture support

Ilia Mirkin imirkin at alum.mit.edu
Sun Mar 1 19:08:10 PST 2015


Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 src/mapi/glapi/gen/es_EXT.xml |  6 ++++++
 src/mesa/main/extensions.c    |  1 +
 src/mesa/main/format_info.py  |  2 ++
 src/mesa/main/formats.c       | 11 +++++++++++
 src/mesa/main/formats.csv     |  5 +++++
 src/mesa/main/formats.h       |  5 +++++
 src/mesa/main/glformats.c     |  8 ++++++++
 src/mesa/main/glformats.h     |  5 +++++
 src/mesa/main/mtypes.h        |  1 +
 src/mesa/main/texcompress.c   | 39 ++++++++++++++++++++++++++++++++++++++-
 src/mesa/main/teximage.c      | 15 +++++++++++++++
 src/mesa/swrast/s_texfetch.c  |  6 +++++-
 12 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/src/mapi/glapi/gen/es_EXT.xml b/src/mapi/glapi/gen/es_EXT.xml
index 3a2adeb..e691ae1 100644
--- a/src/mapi/glapi/gen/es_EXT.xml
+++ b/src/mapi/glapi/gen/es_EXT.xml
@@ -602,6 +602,12 @@
     <enum name="HALF_FLOAT_OES"                           value="0x8D61"/>
 </category>
 
+<category name="GL_AMD_compressed_ATC_texture" number="40">
+    <enum name="ATC_RGB_AMD"                              value="0x8C92"/>
+    <enum name="ATC_RGBA_EXPLICIT_ALPHA_AMD"              value="0x8C93"/>
+    <enum name="ATC_RGBA_INTERPOLATED_ALPHA_AMD"          value="0x87EE"/>
+</category>
+
 <!-- 41. GL_EXT_texture_filter_anisotropic -->
 
 <category name="GL_EXT_texture_type_2_10_10_10_REV" number="42">
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index f212015..913de1a 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -335,6 +335,7 @@ static const struct extension extension_table[] = {
 
    /* Vendor extensions */
    { "GL_3DFX_texture_compression_FXT1",           o(TDFX_texture_compression_FXT1),           GL,             1999 },
+   { "GL_AMD_compressed_ATC_texture",              o(AMD_compressed_ATC_texture),                   ES1 | ES2, 2007 },
    { "GL_AMD_conservative_depth",                  o(ARB_conservative_depth),                  GL,             2009 },
    { "GL_AMD_draw_buffers_blend",                  o(ARB_draw_buffers_blend),                  GL,             2009 },
    { "GL_AMD_performance_monitor",                 o(AMD_performance_monitor),                 GL,             2007 },
diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py
index 3bae57e..0c6fccf 100644
--- a/src/mesa/main/format_info.py
+++ b/src/mesa/main/format_info.py
@@ -130,6 +130,8 @@ def get_channel_bits(fmat, chan_name):
       elif fmat.layout == 'bptc':
          bits = 16 if fmat.name.endswith('_FLOAT') else 8
          return bits if fmat.has_channel(chan_name) else 0
+      elif fmat.layout == 'atc':
+         return 8 if fmat.has_channel(chan_name) else 0
       else:
          assert False
    else:
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index df852f3..cf363b3 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -712,11 +712,14 @@ _mesa_get_uncompressed_format(mesa_format format)
    case MESA_FORMAT_ETC1_RGB8:
    case MESA_FORMAT_ETC2_RGB8:
    case MESA_FORMAT_ETC2_SRGB8:
+   case MESA_FORMAT_ATC_RGB:
       return MESA_FORMAT_BGR_UNORM8;
    case MESA_FORMAT_ETC2_RGBA8_EAC:
    case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
    case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
    case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
+   case MESA_FORMAT_ATC_RGBA_EXPLICIT:
+   case MESA_FORMAT_ATC_RGBA_INTERPOLATED:
       return MESA_FORMAT_A8B8G8R8_UNORM;
    case MESA_FORMAT_ETC2_R11_EAC:
    case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
@@ -1242,6 +1245,9 @@ _mesa_format_to_type_and_comps(mesa_format format,
    case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
    case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
    case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
+   case MESA_FORMAT_ATC_RGB:
+   case MESA_FORMAT_ATC_RGBA_EXPLICIT:
+   case MESA_FORMAT_ATC_RGBA_INTERPOLATED:
       /* XXX generate error instead? */
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 0;
@@ -2079,6 +2085,11 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
    case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
       return GL_FALSE;
 
+   case MESA_FORMAT_ATC_RGB:
+   case MESA_FORMAT_ATC_RGBA_EXPLICIT:
+   case MESA_FORMAT_ATC_RGBA_INTERPOLATED:
+      return GL_FALSE;
+
    case MESA_FORMAT_A_SNORM8:
       return format == GL_ALPHA && type == GL_BYTE;
    case MESA_FORMAT_L_SNORM8:
diff --git a/src/mesa/main/formats.csv b/src/mesa/main/formats.csv
index e159e7d..1d669af 100644
--- a/src/mesa/main/formats.csv
+++ b/src/mesa/main/formats.csv
@@ -301,3 +301,8 @@ MESA_FORMAT_BPTC_RGBA_UNORM               , bptc  , 4, 4, x128,     ,     ,
 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
+
+# ATC compressed formats
+MESA_FORMAT_ATC_RGB                       ,  atc  , 4, 4, x64 ,     ,     ,     , xyz1, rgb
+MESA_FORMAT_ATC_RGBA_EXPLICIT             ,  atc  , 4, 4, x128,     ,     ,     , xyzw, rgb
+MESA_FORMAT_ATC_RGBA_INTERPOLATED         ,  atc  , 4, 4, x128,     ,     ,     , xyzw, rgb
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 7e451ca..4909cad 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -575,6 +575,11 @@ typedef enum
    MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT,
    MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT,
 
+   /* ATC compressed formats */
+   MESA_FORMAT_ATC_RGB,
+   MESA_FORMAT_ATC_RGBA_EXPLICIT,
+   MESA_FORMAT_ATC_RGBA_INTERPOLATED,
+
    MESA_FORMAT_COUNT
 } mesa_format;
 
diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
index 4e05229..e30c427 100644
--- a/src/mesa/main/glformats.c
+++ b/src/mesa/main/glformats.c
@@ -1003,6 +1003,9 @@ _mesa_is_color_format(GLenum format)
       case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
       case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
       case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
+      case GL_ATC_RGB_AMD:
+      case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
+      case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
       /* generic integer formats */
       case GL_RED_INTEGER_EXT:
       case GL_GREEN_INTEGER_EXT:
@@ -1262,6 +1265,11 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
    case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
       return _mesa_is_desktop_gl(ctx) &&
          ctx->Extensions.ARB_texture_compression_bptc;
+   case GL_ATC_RGB_AMD:
+   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
+   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
+      return _mesa_is_gles(ctx)
+         && ctx->Extensions.AMD_compressed_ATC_texture;
    case GL_PALETTE4_RGB8_OES:
    case GL_PALETTE4_RGBA8_OES:
    case GL_PALETTE4_R5_G6_B5_OES:
diff --git a/src/mesa/main/glformats.h b/src/mesa/main/glformats.h
index e1ecd64..295fb83 100644
--- a/src/mesa/main/glformats.h
+++ b/src/mesa/main/glformats.h
@@ -30,11 +30,16 @@
 
 #include <GL/gl.h>
 
+#define GL_ATC_RGB_AMD                     0x8C92
+#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD     0x8C93
+#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
+
 extern void
 _mesa_compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte *map);
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 6e99773..24d98ef 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3855,6 +3855,7 @@ struct gl_extensions
    GLboolean EXT_vertex_array_bgra;
    GLboolean OES_standard_derivatives;
    /* vendor extensions */
+   GLboolean AMD_compressed_ATC_texture;
    GLboolean AMD_performance_monitor;
    GLboolean AMD_pinned_memory;
    GLboolean AMD_seamless_cubemap_per_texture;
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index 00234d4..1c1a4f5 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -30,6 +30,7 @@
  */
 
 
+#include "glformats.h"
 #include "glheader.h"
 #include "imports.h"
 #include "colormac.h"
@@ -44,7 +45,6 @@
 #include "texcompress_etc.h"
 #include "texcompress_bptc.h"
 
-
 /**
  * Get the GL base format of a specified GL compressed texture format
  *
@@ -101,6 +101,7 @@ _mesa_gl_compressed_format_base_format(GLenum format)
    case GL_ETC1_RGB8_OES:
    case GL_COMPRESSED_RGB8_ETC2:
    case GL_COMPRESSED_SRGB8_ETC2:
+   case GL_ATC_RGB_AMD:
       return GL_RGB;
 
    case GL_COMPRESSED_RGBA:
@@ -118,6 +119,8 @@ _mesa_gl_compressed_format_base_format(GLenum format)
    case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
    case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
    case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
+   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
       return GL_RGBA;
 
    case GL_COMPRESSED_ALPHA:
@@ -326,6 +329,26 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
       }
    }
 
+   /* The GL_AMD_compressed_ATC_texture spec says:
+    *
+    *     "New State
+    *
+    *         The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
+    *         COMPRESSED_TEXTURE_FORMATS include ATC_RGB_AMD,
+    *         ATC_RGBA_EXPLICIT_ALPHA_AMD, and ATC_RGBA_INTERPOLATED_ALPHA_AMD."
+    */
+   if (_mesa_is_gles(ctx)
+       && ctx->Extensions.AMD_compressed_ATC_texture) {
+      if (formats) {
+         formats[n++] = GL_ATC_RGB_AMD;
+         formats[n++] = GL_ATC_RGBA_EXPLICIT_ALPHA_AMD;
+         formats[n++] = GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
+      }
+      else {
+         n += 3;
+      }
+   }
+
    if (ctx->API == API_OPENGLES) {
       if (formats) {
 	 formats[n++] = GL_PALETTE4_RGB8_OES;
@@ -450,6 +473,13 @@ _mesa_glenum_to_compressed_format(GLenum format)
    case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
       return MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT;
 
+   case GL_ATC_RGB_AMD:
+      return MESA_FORMAT_ATC_RGB;
+   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
+      return MESA_FORMAT_ATC_RGBA_EXPLICIT;
+   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
+      return MESA_FORMAT_ATC_RGBA_INTERPOLATED;
+
    default:
       return MESA_FORMAT_NONE;
    }
@@ -540,6 +570,13 @@ _mesa_compressed_format_to_glenum(struct gl_context *ctx, mesa_format mesaFormat
    case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
       return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
 
+   case MESA_FORMAT_ATC_RGB:
+      return GL_ATC_RGB_AMD;
+   case MESA_FORMAT_ATC_RGBA_EXPLICIT:
+      return GL_ATC_RGBA_EXPLICIT_ALPHA_AMD;
+   case MESA_FORMAT_ATC_RGBA_INTERPOLATED:
+      return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
+
    default:
       _mesa_problem(ctx, "Unexpected mesa texture format in"
                     " _mesa_compressed_format_to_glenum()");
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 6e45cc9..16f09ec 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -561,6 +561,18 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
       }
    }
 
+   if (_mesa_is_gles(ctx) && ctx->Extensions.AMD_compressed_ATC_texture) {
+      switch (internalFormat) {
+      case GL_ATC_RGB_AMD:
+         return GL_RGB;
+      case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
+      case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
+         return GL_RGBA;
+      default:
+         ; /* fallthrough */
+      }
+   }
+
    if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility) {
       switch (internalFormat) {
       case GL_COMPRESSED_RGB8_ETC2:
@@ -1778,6 +1790,9 @@ compressedteximage_only_format(const struct gl_context *ctx, GLenum format)
    case GL_PALETTE8_R5_G6_B5_OES:
    case GL_PALETTE8_RGBA4_OES:
    case GL_PALETTE8_RGB5_A1_OES:
+   case GL_ATC_RGB_AMD:
+   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
+   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
       return GL_TRUE;
    default:
       return GL_FALSE;
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index 242f8a4..01a8de9 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -552,7 +552,11 @@ texfetch_funcs[] =
       fetch_compressed,
       fetch_compressed,
       fetch_compressed
-   }
+   },
+
+   FETCH_NULL(ATC_RGB),
+   FETCH_NULL(ATC_RGBA_EXPLICIT),
+   FETCH_NULL(ATC_RGBA_INTERPOLATED),
 };
 
 
-- 
2.0.5



More information about the mesa-dev mailing list