mesa: don't enable online compression for ASTC formats
authorNanley Chery <nanley.g.chery@intel.com>
Mon, 18 May 2015 23:30:30 +0000 (16:30 -0700)
committerNanley Chery <nanley.g.chery@intel.com>
Wed, 26 Aug 2015 21:36:42 +0000 (14:36 -0700)
In agreement with the ASTC spec, this makes calls to TexImage*D unsuccessful.
Implied by the spec, Generate[Texture]Mipmap and [Copy]Tex[Sub]Image*D calls
must be unsuccessful as well.

v2. actually force attempts to compress online to fail.
v3. indentation (Matt).
v4. update copytexture_error_check to account for CopyTexImage*D (Chad).

Reviewed-by: Chad Versace <chad.versace@intel.com>
Signed-off-by: Nanley Chery <nanley.g.chery@intel.com>
src/mesa/main/genmipmap.c
src/mesa/main/glformats.c
src/mesa/main/glformats.h
src/mesa/main/texcompress.c
src/mesa/main/teximage.c

index c18f9d5223f94d913164c1330ee6a5ad91b8c8ce..4ec8385ec2f70e7d0d191f61d688a49cf34cd5fd 100644 (file)
@@ -111,6 +111,7 @@ _mesa_generate_texture_mipmap(struct gl_context *ctx,
 
    if (_mesa_is_enum_format_integer(srcImage->InternalFormat) ||
        _mesa_is_depthstencil_format(srcImage->InternalFormat) ||
+       _mesa_is_astc_format(srcImage->InternalFormat) ||
        _mesa_is_stencil_format(srcImage->InternalFormat)) {
       _mesa_unlock_texture(ctx, texObj);
       _mesa_error(ctx, GL_INVALID_OPERATION,
index 3eb66dab7f85c3b0f09ab5bed26c225d5e3e4cb9..fd8336cf8e2961733446cc5d7d190b18ca1a4cd2 100644 (file)
@@ -820,6 +820,47 @@ _mesa_is_enum_format_signed_int(GLenum format)
    }
 }
 
+/**
+ * Test if the given format is an ASTC format.
+ */
+GLboolean
+_mesa_is_astc_format(GLenum internalFormat)
+{
+   switch (internalFormat) {
+   case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
+   case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
+      return true;
+   default:
+      return false;
+   }
+}
+
 
 /**
  * Test if the given format is an integer (non-normalized) format.
index 419955a60336b5c34a0e76a7cd1d96164d8f8f8a..aec905d23427f7591d289e4dcd9de8f8eb59e901 100644 (file)
@@ -56,6 +56,9 @@ _mesa_bytes_per_pixel( GLenum format, GLenum type );
 extern GLint
 _mesa_bytes_per_vertex_attrib(GLint comps, GLenum type);
 
+extern GLboolean
+_mesa_is_astc_format(GLenum internalFormat);
+
 extern GLboolean
 _mesa_is_type_unsigned(GLenum type);
 
index edfb03625c29cefdbcd4979129fd25044f4cb6f7..c028daa46e4dea7e5a183268ce953a301f71f34c 100644 (file)
@@ -229,6 +229,28 @@ _mesa_gl_compressed_format_base_format(GLenum format)
  *        what GL_NUM_COMPRESSED_TEXTURE_FORMATS and
  *        GL_COMPRESSED_TEXTURE_FORMATS return."
  *
+ * The KHR_texture_compression_astc_hdr spec says:
+ *
+ *    "Interactions with OpenGL 4.2
+ *
+ *        OpenGL 4.2 supports the feature that compressed textures can be
+ *        compressed online, by passing the compressed texture format enum as
+ *        the internal format when uploading a texture using TexImage1D,
+ *        TexImage2D or TexImage3D (see Section 3.9.3, Texture Image
+ *        Specification, subsection Encoding of Special Internal Formats).
+ *
+ *        Due to the complexity of the ASTC compression algorithm, it is not
+ *        usually suitable for online use, and therefore ASTC support will be
+ *        limited to pre-compressed textures only. Where on-device compression
+ *        is required, a domain-specific limited compressor will typically
+ *        be used, and this is therefore not suitable for implementation in
+ *        the driver.
+ *
+ *        In particular, the ASTC format specifiers will not be added to
+ *        Table 3.14, and thus will not be accepted by the TexImage*D
+ *        functions, and will not be returned by the (already deprecated)
+ *        COMPRESSED_TEXTURE_FORMATS query."
+ *
  * There is no formal spec for GL_ATI_texture_compression_3dc.  Since the
  * formats added by this extension are luminance-alpha formats, it is
  * reasonable to expect them to follow the same rules as
index 274ecad44e9fc424c671fc5ad59535063cac4f48..0a641cf2cad584f58626ce54741cdb7a82e10ca0 100644 (file)
@@ -1784,6 +1784,15 @@ compressedteximage_only_format(const struct gl_context *ctx, GLenum format)
    }
 }
 
+/**
+ * Return true if the format doesn't support online compression.
+ */
+static bool
+_mesa_format_no_online_compression(const struct gl_context *ctx, GLenum format)
+{
+   return _mesa_is_astc_format(format) ||
+          compressedteximage_only_format(ctx, format);
+}
 
 /* Writes to an GL error pointer if non-null and returns whether or not the
  * error is GL_NO_ERROR */
@@ -2328,7 +2337,7 @@ texture_error_check( struct gl_context *ctx,
                      "glTexImage%dD(target can't be compressed)", dimensions);
          return GL_TRUE;
       }
-      if (compressedteximage_only_format(ctx, internalFormat)) {
+      if (_mesa_format_no_online_compression(ctx, internalFormat)) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glTexImage%dD(no compression for format)", dimensions);
          return GL_TRUE;
@@ -2592,7 +2601,7 @@ texsubimage_error_check(struct gl_context *ctx, GLuint dimensions,
    }
 
    if (_mesa_is_format_compressed(texImage->TexFormat)) {
-      if (compressedteximage_only_format(ctx, texImage->InternalFormat)) {
+      if (_mesa_format_no_online_compression(ctx, texImage->InternalFormat)) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                "%s(no compression for format)", callerName);
          return GL_TRUE;
@@ -2850,7 +2859,7 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
                      "glCopyTexImage%dD(target can't be compressed)", dimensions);
          return GL_TRUE;
       }
-      if (compressedteximage_only_format(ctx, internalFormat)) {
+      if (_mesa_format_no_online_compression(ctx, internalFormat)) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                "glCopyTexImage%dD(no compression for format)", dimensions);
          return GL_TRUE;
@@ -2931,7 +2940,7 @@ copytexsubimage_error_check(struct gl_context *ctx, GLuint dimensions,
    }
 
    if (_mesa_is_format_compressed(texImage->TexFormat)) {
-      if (compressedteximage_only_format(ctx, texImage->InternalFormat)) {
+      if (_mesa_format_no_online_compression(ctx, texImage->InternalFormat)) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                "%s(no compression for format)", caller);
          return GL_TRUE;