mesa: add ASTC 2D LDR decoder
[mesa.git] / src / mesa / main / texstorage.c
index 8545b06136e8406bad4c3b9cfbbb067ee267203d..9cb8b900651e1adadc7479a46e31a46908f0f9f0 100644 (file)
@@ -304,12 +304,14 @@ _mesa_AllocTextureStorage_sw(struct gl_context *ctx,
 static GLboolean
 tex_storage_error_check(struct gl_context *ctx,
                         struct gl_texture_object *texObj,
+                        struct gl_memory_object *memObj,
                         GLuint dims, GLenum target,
                         GLsizei levels, GLenum internalformat,
                         GLsizei width, GLsizei height, GLsizei depth,
                         bool dsa)
 {
-   const char* suffix = dsa ? "ture" : "";
+   const char* suffix = dsa ? (memObj ? "tureMem" : "ture") :
+                              (memObj ? "Mem" : "");
 
    /* Legal format checking has been moved to texstorage and texturestorage in
     * order to allow meta functions to use legacy formats. */
@@ -389,18 +391,20 @@ tex_storage_error_check(struct gl_context *ctx,
 static ALWAYS_INLINE void
 texture_storage(struct gl_context *ctx, GLuint dims,
                 struct gl_texture_object *texObj,
-                GLenum target, GLsizei levels,
-                GLenum internalformat, GLsizei width,
-                GLsizei height, GLsizei depth, bool dsa, bool no_error)
+                struct gl_memory_object *memObj, GLenum target,
+                GLsizei levels, GLenum internalformat, GLsizei width,
+                GLsizei height, GLsizei depth, GLuint64 offset, bool dsa,
+                bool no_error)
 {
    GLboolean sizeOK = GL_TRUE, dimensionsOK = GL_TRUE;
    mesa_format texFormat;
-   const char* suffix = dsa ? "ture" : "";
+   const char* suffix = dsa ? (memObj ? "tureMem" : "ture") :
+                              (memObj ? "Mem" : "");
 
    assert(texObj);
 
    if (!no_error) {
-      if (tex_storage_error_check(ctx, texObj, dims, target, levels,
+      if (tex_storage_error_check(ctx, texObj, memObj, dims, target, levels,
                                   internalformat, width, height, depth, dsa)) {
          return; /* error was recorded */
       }
@@ -441,6 +445,7 @@ texture_storage(struct gl_context *ctx, GLuint dims,
             _mesa_error(ctx, GL_OUT_OF_MEMORY,
                         "glTex%sStorage%uD(texture too large)",
                         suffix, dims);
+            return;
          }
       }
 
@@ -454,18 +459,30 @@ texture_storage(struct gl_context *ctx, GLuint dims,
          return;
       }
 
-      /* Do actual texture memory allocation */
-      if (!ctx->Driver.AllocTextureStorage(ctx, texObj, levels,
-                                           width, height, depth)) {
-         /* Reset the texture images' info to zeros.
-          * Strictly speaking, we probably don't have to do this since
-          * generating GL_OUT_OF_MEMORY can leave things in an undefined
-          * state but this puts things in a consistent state.
-          */
-         clear_texture_fields(ctx, texObj);
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex%sStorage%uD",
-                     suffix, dims);
-         return;
+      /* Setup the backing memory */
+      if (memObj) {
+         if (!ctx->Driver.SetTextureStorageForMemoryObject(ctx, texObj, memObj,
+                                                           levels,
+                                                           width, height, depth,
+                                                           offset)) {
+
+            clear_texture_fields(ctx, texObj);
+            return;
+         }
+      }
+      else {
+         if (!ctx->Driver.AllocTextureStorage(ctx, texObj, levels,
+                                              width, height, depth)) {
+            /* Reset the texture images' info to zeros.
+             * Strictly speaking, we probably don't have to do this since
+             * generating GL_OUT_OF_MEMORY can leave things in an undefined
+             * state but this puts things in a consistent state.
+             */
+            clear_texture_fields(ctx, texObj);
+            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex%sStorage%uD",
+                        suffix, dims);
+            return;
+         }
       }
 
       _mesa_set_texture_view_state(ctx, texObj, target, levels);
@@ -482,8 +499,20 @@ texture_storage_error(struct gl_context *ctx, GLuint dims,
                       GLenum internalformat, GLsizei width,
                       GLsizei height, GLsizei depth, bool dsa)
 {
-   texture_storage(ctx, dims, texObj, target, levels, internalformat, width,
-                   height, depth, dsa, false);
+   texture_storage(ctx, dims, texObj, NULL, target, levels, internalformat,
+                   width, height, depth, dsa, 0, false);
+}
+
+
+static void
+texture_storage_no_error(struct gl_context *ctx, GLuint dims,
+                         struct gl_texture_object *texObj,
+                         GLenum target, GLsizei levels,
+                         GLenum internalformat, GLsizei width,
+                         GLsizei height, GLsizei depth, bool dsa)
+{
+   texture_storage(ctx, dims, texObj, NULL, target, levels, internalformat,
+                   width, height, depth, dsa, 0, true);
 }
 
 
@@ -491,8 +520,9 @@ texture_storage_error(struct gl_context *ctx, GLuint dims,
  * Helper used by _mesa_TexStorage1/2/3D().
  */
 static void
-texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
-           GLsizei width, GLsizei height, GLsizei depth, const char *caller)
+texstorage_error(GLuint dims, GLenum target, GLsizei levels,
+                 GLenum internalformat, GLsizei width, GLsizei height,
+                 GLsizei depth, const char *caller)
 {
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
@@ -530,13 +560,26 @@ texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
 }
 
 
+static void
+texstorage_no_error(GLuint dims, GLenum target, GLsizei levels,
+                    GLenum internalformat, GLsizei width, GLsizei height,
+                    GLsizei depth)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   struct gl_texture_object *texObj = _mesa_get_current_tex_object(ctx, target);
+   texture_storage_no_error(ctx, dims, texObj, target, levels,
+                            internalformat, width, height, depth, false);
+}
+
+
 /**
  * Helper used by _mesa_TextureStorage1/2/3D().
  */
 static void
-texturestorage(GLuint dims, GLuint texture, GLsizei levels,
-               GLenum internalformat, GLsizei width, GLsizei height,
-               GLsizei depth, const char *caller)
+texturestorage_error(GLuint dims, GLuint texture, GLsizei levels,
+                     GLenum internalformat, GLsizei width, GLsizei height,
+                     GLsizei depth, const char *caller)
 {
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
@@ -563,7 +606,7 @@ texturestorage(GLuint dims, GLuint texture, GLsizei levels,
     * can receive unsized formats.
     */
    if (!legal_texobj_target(ctx, dims, texObj->Target)) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
+      _mesa_error(ctx, GL_INVALID_OPERATION,
                   "%s(illegal target=%s)", caller,
                   _mesa_enum_to_string(texObj->Target));
       return;
@@ -574,12 +617,42 @@ texturestorage(GLuint dims, GLuint texture, GLsizei levels,
 }
 
 
+static void
+texturestorage_no_error(GLuint dims, GLuint texture, GLsizei levels,
+                        GLenum internalformat, GLsizei width, GLsizei height,
+                        GLsizei depth)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   struct gl_texture_object *texObj = _mesa_lookup_texture(ctx, texture);
+   texture_storage_no_error(ctx, dims, texObj, texObj->Target,
+                            levels, internalformat, width, height, depth, true);
+}
+
+
+void GLAPIENTRY
+_mesa_TexStorage1D_no_error(GLenum target, GLsizei levels,
+                            GLenum internalformat, GLsizei width)
+{
+   texstorage_no_error(1, target, levels, internalformat, width, 1, 1);
+}
+
+
 void GLAPIENTRY
 _mesa_TexStorage1D(GLenum target, GLsizei levels, GLenum internalformat,
                    GLsizei width)
 {
-   texstorage(1, target, levels, internalformat, width, 1, 1,
-              "glTexStorage1D");
+   texstorage_error(1, target, levels, internalformat, width, 1, 1,
+                    "glTexStorage1D");
+}
+
+
+void GLAPIENTRY
+_mesa_TexStorage2D_no_error(GLenum target, GLsizei levels,
+                            GLenum internalformat, GLsizei width,
+                            GLsizei height)
+{
+   texstorage_no_error(2, target, levels, internalformat, width, height, 1);
 }
 
 
@@ -587,8 +660,17 @@ void GLAPIENTRY
 _mesa_TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat,
                    GLsizei width, GLsizei height)
 {
-   texstorage(2, target, levels, internalformat, width, height, 1,
-              "glTexStorage2D");
+   texstorage_error(2, target, levels, internalformat, width, height, 1,
+                    "glTexStorage2D");
+}
+
+
+void GLAPIENTRY
+_mesa_TexStorage3D_no_error(GLenum target, GLsizei levels,
+                            GLenum internalformat, GLsizei width,
+                            GLsizei height, GLsizei depth)
+{
+   texstorage_no_error(3, target, levels, internalformat, width, height, depth);
 }
 
 
@@ -596,8 +678,16 @@ void GLAPIENTRY
 _mesa_TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat,
                    GLsizei width, GLsizei height, GLsizei depth)
 {
-   texstorage(3, target, levels, internalformat, width, height, depth,
-              "glTexStorage3D");
+   texstorage_error(3, target, levels, internalformat, width, height, depth,
+                    "glTexStorage3D");
+}
+
+
+void GLAPIENTRY
+_mesa_TextureStorage1D_no_error(GLuint texture, GLsizei levels,
+                                GLenum internalformat, GLsizei width)
+{
+   texturestorage_no_error(1, texture, levels, internalformat, width, 1, 1);
 }
 
 
@@ -605,8 +695,17 @@ void GLAPIENTRY
 _mesa_TextureStorage1D(GLuint texture, GLsizei levels, GLenum internalformat,
                        GLsizei width)
 {
-   texturestorage(1, texture, levels, internalformat, width, 1, 1,
-                  "glTextureStorage1D");
+   texturestorage_error(1, texture, levels, internalformat, width, 1, 1,
+                        "glTextureStorage1D");
+}
+
+
+void GLAPIENTRY
+_mesa_TextureStorage2D_no_error(GLuint texture, GLsizei levels,
+                                GLenum internalformat,
+                                GLsizei width, GLsizei height)
+{
+   texturestorage_no_error(2, texture, levels, internalformat, width, height, 1);
 }
 
 
@@ -615,8 +714,18 @@ _mesa_TextureStorage2D(GLuint texture, GLsizei levels,
                        GLenum internalformat,
                        GLsizei width, GLsizei height)
 {
-   texturestorage(2, texture, levels, internalformat, width, height, 1,
-                  "glTextureStorage2D");
+   texturestorage_error(2, texture, levels, internalformat, width, height, 1,
+                        "glTextureStorage2D");
+}
+
+
+void GLAPIENTRY
+_mesa_TextureStorage3D_no_error(GLuint texture, GLsizei levels,
+                                GLenum internalformat, GLsizei width,
+                                GLsizei height, GLsizei depth)
+{
+   texturestorage_no_error(3, texture, levels, internalformat, width, height,
+                           depth);
 }
 
 
@@ -624,8 +733,8 @@ void GLAPIENTRY
 _mesa_TextureStorage3D(GLuint texture, GLsizei levels, GLenum internalformat,
                        GLsizei width, GLsizei height, GLsizei depth)
 {
-   texturestorage(3, texture, levels, internalformat, width, height, depth,
-                  "glTextureStorage3D");
+   texturestorage_error(3, texture, levels, internalformat, width, height, depth,
+                        "glTextureStorage3D");
 }
 
 
@@ -692,3 +801,19 @@ _mesa_TextureStorage3DEXT(GLuint texture, GLenum target, GLsizei levels,
    _mesa_error(ctx, GL_INVALID_OPERATION,
                "glTextureStorage3DEXT not supported");
 }
+
+
+void
+_mesa_texture_storage_memory(struct gl_context *ctx, GLuint dims,
+                             struct gl_texture_object *texObj,
+                             struct gl_memory_object *memObj,
+                             GLenum target, GLsizei levels,
+                             GLenum internalformat, GLsizei width,
+                             GLsizei height, GLsizei depth,
+                             GLuint64 offset, bool dsa)
+{
+   assert(memObj);
+
+   texture_storage(ctx, dims, texObj, memObj, target, levels, internalformat,
+                   width, height, depth, offset, dsa, false);
+}