mesa: hook up memoryobject tex(ture)storage api
authorAndres Rodriguez <andresx7@gmail.com>
Wed, 12 Jul 2017 22:45:11 +0000 (18:45 -0400)
committerTimothy Arceri <tarceri@itsqueeze.com>
Sun, 6 Aug 2017 02:42:06 +0000 (12:42 +1000)
V2 (Timothy Arceri):
 - formating fixes

V3 (Timothy):
 - error check memory == 0 before lookup

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/mesa/main/dd.h
src/mesa/main/externalobjects.c
src/mesa/main/texstorage.c
src/mesa/main/texstorage.h

index 6d6bdecb4dd99f6a698c5d29a4cf498ecc8e3b94..fbe70cdfab755716a255c899717fcf15af2b0000 100644 (file)
@@ -1087,6 +1087,16 @@ struct dd_function_table {
     */
    void (*DeleteMemoryObject)(struct gl_context *ctx,
                               struct gl_memory_object *memObj);
+
+   /**
+    * Set the given memory object as the texture's storage.
+    */
+   GLboolean (*SetTextureStorageForMemoryObject)(struct gl_context *ctx,
+                                                 struct gl_texture_object *tex_obj,
+                                                 struct gl_memory_object *mem_obj,
+                                                 GLsizei levels, GLsizei width,
+                                                 GLsizei height, GLsizei depth,
+                                                 GLuint64 offset);
    /*@}*/
 
    /**
index 9241fe1fe6ab47358036394d559b2f010aaedaf6..3843c9492e912aeafc47774e8fbc812469e63078 100644 (file)
 #include "macros.h"
 #include "mtypes.h"
 #include "externalobjects.h"
+#include "teximage.h"
+#include "texobj.h"
+#include "glformats.h"
+#include "texstorage.h"
 
 /**
  * Allocate and initialize a new memory object.  But don't put it into the
@@ -228,6 +232,100 @@ invalid_pname:
                "glGetMemoryObjectParameterivEXT(pname=0x%x)", pname);
 }
 
+static struct gl_memory_object *
+lookup_memory_object_err(struct gl_context *ctx, unsigned memory,
+                         const char* func)
+{
+   if (memory == 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(memory=0)", func);
+      return NULL;
+   }
+
+   struct gl_memory_object *memObj = _mesa_lookup_memory_object(ctx, memory);
+   if (!memObj)
+      return NULL;
+
+   if (!memObj->Immutable) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no associated memory)",
+                  func);
+      return NULL;
+   }
+
+   return memObj;
+}
+
+/**
+ * Helper used by _mesa_TexStorageMem1/2/3DEXT().
+ */
+static void
+texstorage_memory(GLuint dims, GLenum target, GLsizei levels,
+                  GLenum internalFormat, GLsizei width, GLsizei height,
+                  GLsizei depth, GLuint memory, GLuint64 offset,
+                  const char *func)
+{
+   struct gl_texture_object *texObj;
+   struct gl_memory_object *memObj;
+
+   GET_CURRENT_CONTEXT(ctx);
+
+   texObj = _mesa_get_current_tex_object(ctx, target);
+   if (!texObj)
+      return;
+
+   memObj = lookup_memory_object_err(ctx, memory, func);
+   if (!memObj)
+      return;
+
+   _mesa_texture_storage_memory(ctx, dims, texObj, memObj, target,
+                                levels, internalFormat,
+                                width, height, depth, offset, false);
+}
+
+static void
+texstorage_memory_ms(GLuint dims, GLenum target, GLsizei samples,
+                     GLenum internalFormat, GLsizei width, GLsizei height,
+                     GLsizei depth, GLboolean fixedSampleLocations,
+                     GLuint memory, GLuint64 offset)
+{
+
+}
+
+/**
+ * Helper used by _mesa_TextureStorageMem1/2/3DEXT().
+ */
+static void
+texturestorage_memory(GLuint dims, GLuint texture, GLsizei levels,
+                      GLenum internalFormat, GLsizei width, GLsizei height,
+                      GLsizei depth, GLuint memory, GLuint64 offset,
+                      const char *func)
+{
+   struct gl_texture_object *texObj;
+   struct gl_memory_object *memObj;
+
+   GET_CURRENT_CONTEXT(ctx);
+
+   texObj = _mesa_lookup_texture(ctx, texture);
+   if (!texObj)
+      return;
+
+   memObj = lookup_memory_object_err(ctx, memory, func);
+   if (!memObj)
+      return;
+
+   _mesa_texture_storage_memory(ctx, dims, texObj, memObj, texObj->Target,
+                                levels, internalFormat,
+                                width, height, depth, offset, true);
+}
+
+static void
+texturestorage_memory_ms(GLuint dims, GLuint texture, GLsizei samples,
+                         GLenum internalFormat, GLsizei width, GLsizei height,
+                         GLsizei depth, GLboolean fixedSampleLocations,
+                         GLuint memory, GLuint64 offset)
+{
+
+}
+
 void GLAPIENTRY
 _mesa_TexStorageMem2DEXT(GLenum target,
                          GLsizei levels,
@@ -237,7 +335,8 @@ _mesa_TexStorageMem2DEXT(GLenum target,
                          GLuint memory,
                          GLuint64 offset)
 {
-
+   texstorage_memory(2, target, levels, internalFormat, width, height, 1,
+                     memory, offset, "glTexStorageMem2DEXT");
 }
 
 void GLAPIENTRY
@@ -250,7 +349,8 @@ _mesa_TexStorageMem2DMultisampleEXT(GLenum target,
                                     GLuint memory,
                                     GLuint64 offset)
 {
-
+   texstorage_memory_ms(2, target, samples, internalFormat, width, height, 1,
+                        fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -263,7 +363,8 @@ _mesa_TexStorageMem3DEXT(GLenum target,
                          GLuint memory,
                          GLuint64 offset)
 {
-
+   texstorage_memory(3, target, levels, internalFormat, width, height, depth,
+                     memory, offset, "glTexStorageMem3DEXT");
 }
 
 void GLAPIENTRY
@@ -277,7 +378,8 @@ _mesa_TexStorageMem3DMultisampleEXT(GLenum target,
                                     GLuint memory,
                                     GLuint64 offset)
 {
-
+   texstorage_memory_ms(3, target, samples, internalFormat, width, height,
+                        depth, fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -289,7 +391,8 @@ _mesa_TextureStorageMem2DEXT(GLuint texture,
                              GLuint memory,
                              GLuint64 offset)
 {
-
+   texturestorage_memory(2, texture, levels, internalFormat, width, height, 1,
+                         memory, offset, "glTexureStorageMem2DEXT");
 }
 
 void GLAPIENTRY
@@ -302,7 +405,8 @@ _mesa_TextureStorageMem2DMultisampleEXT(GLuint texture,
                                         GLuint memory,
                                         GLuint64 offset)
 {
-
+   texturestorage_memory_ms(2, texture, samples, internalFormat, width, height,
+                            1, fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -315,7 +419,8 @@ _mesa_TextureStorageMem3DEXT(GLuint texture,
                              GLuint memory,
                              GLuint64 offset)
 {
-
+   texturestorage_memory(3, texture, levels, internalFormat, width, height,
+                         depth, memory, offset, "glTextureStorageMem3DEXT");
 }
 
 void GLAPIENTRY
@@ -329,7 +434,8 @@ _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,
                                         GLuint memory,
                                         GLuint64 offset)
 {
-
+   texturestorage_memory_ms(3, texture, samples, internalFormat, width, height,
+                            depth, fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -340,7 +446,8 @@ _mesa_TexStorageMem1DEXT(GLenum target,
                          GLuint memory,
                          GLuint64 offset)
 {
-
+   texstorage_memory(1, target, levels, internalFormat, width, 1, 1, memory,
+                     offset, "glTexStorageMem1DEXT");
 }
 
 void GLAPIENTRY
@@ -351,7 +458,8 @@ _mesa_TextureStorageMem1DEXT(GLuint texture,
                              GLuint memory,
                              GLuint64 offset)
 {
-
+   texturestorage_memory(1, texture, levels, internalFormat, width, 1, 1,
+                         memory, offset, "glTextureStorageMem1DEXT");
 }
 
 void GLAPIENTRY
index 7a61a4f47862d37372c96ab4ba5de14ea7cfea63..e0930abe3f8cba330fb9a9e7f347fab185c2bfc9 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 */
       }
@@ -454,18 +458,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 +498,8 @@ 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);
 }
 
 
@@ -494,8 +510,8 @@ texture_storage_no_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, true);
+   texture_storage(ctx, dims, texObj, NULL, target, levels, internalformat,
+                   width, height, depth, dsa, 0, true);
 }
 
 
@@ -784,3 +800,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);
+}
index 66b77be4e14289eadd96228ffcc6e6118da52a1f..f184dfd86eb8081d745e2599a8d0f33e753b5978 100644 (file)
@@ -137,4 +137,13 @@ _mesa_AllocTextureStorage_sw(struct gl_context *ctx,
                              GLsizei levels, GLsizei width,
                              GLsizei height, GLsizei depth);
 
+extern 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);
+
 #endif /* TEXSTORAGE_H */