[Mesa-dev] [PATCH 06/19] mesa: hook up memoryobject tex(ture)storage api

Andres Rodriguez andresx7 at gmail.com
Fri Jun 30 23:02:59 UTC 2017


Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
---
 src/mesa/main/dd.h              |  9 ++++
 src/mesa/main/externalobjects.c | 93 ++++++++++++++++++++++++++++++++++++-----
 src/mesa/main/texstorage.c      | 76 ++++++++++++++++++++++++---------
 src/mesa/main/texstorage.h      | 13 +++++-
 4 files changed, 160 insertions(+), 31 deletions(-)

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 97ef5b8..ec7a195 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -1087,6 +1087,15 @@ struct dd_function_table {
     */
    void (*DeleteMemoryObject)(struct gl_context *ctx,
                               struct gl_memory_object *mem_obj);
+
+   /**
+    * 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);
    /*@}*/
 
    /**
diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index edcb5bf..d083ad9 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -24,6 +24,10 @@
 #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
@@ -229,6 +233,75 @@ invalid_pname:
                pname);
 }
 
+/**
+ * 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)
+{
+   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 = _mesa_lookup_memory_object(ctx, memory);
+   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)
+{
+   struct gl_texture_object *texObj;
+   struct gl_memory_object *memObj;
+
+   GET_CURRENT_CONTEXT(ctx);
+
+   texObj = _mesa_lookup_texture(ctx, texture);
+   if (!texObj)
+      return;
+
+   memObj = _mesa_lookup_memory_object(ctx, memory);
+   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,
@@ -238,7 +311,7 @@ _mesa_TexStorageMem2DEXT(GLenum target,
                          GLuint memory,
                          GLuint64 offset)
 {
-
+   texstorage_memory(2, target, levels, internalFormat, width, height, 1, memory, offset);
 }
 
 void GLAPIENTRY
@@ -251,7 +324,7 @@ _mesa_TexStorageMem2DMultisampleEXT(GLenum target,
                                     GLuint memory,
                                     GLuint64 offset)
 {
-
+   texstorage_memory_ms(2, target, samples, internalFormat, width, height, 1, fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -264,7 +337,7 @@ _mesa_TexStorageMem3DEXT(GLenum target,
                          GLuint memory,
                          GLuint64 offset)
 {
-
+   texstorage_memory(3, target, levels, internalFormat, width, height, depth, memory, offset);
 }
 
 void GLAPIENTRY
@@ -278,7 +351,7 @@ _mesa_TexStorageMem3DMultisampleEXT(GLenum target,
                                     GLuint memory,
                                     GLuint64 offset)
 {
-
+   texstorage_memory_ms(3, target, samples, internalFormat, width, height, depth, fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -299,7 +372,7 @@ _mesa_TextureStorageMem2DEXT(GLuint texture,
                              GLuint memory,
                              GLuint64 offset)
 {
-
+   texturestorage_memory(2, texture, levels, internalFormat, width, height, 1, memory, offset);
 }
 
 void GLAPIENTRY
@@ -312,7 +385,7 @@ _mesa_TextureStorageMem2DMultisampleEXT(GLuint texture,
                                         GLuint memory,
                                         GLuint64 offset)
 {
-
+   texturestorage_memory_ms(2, texture, samples, internalFormat, width, height, 1, fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -325,7 +398,7 @@ _mesa_TextureStorageMem3DEXT(GLuint texture,
                              GLuint memory,
                              GLuint64 offset)
 {
-
+   texturestorage_memory(3, texture, levels, internalFormat, width, height, depth, memory, offset);
 }
 
 void GLAPIENTRY
@@ -339,7 +412,7 @@ _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,
                                         GLuint memory,
                                         GLuint64 offset)
 {
-
+   texturestorage_memory_ms(3, texture, samples, internalFormat, width, height, depth, fixedSampleLocations, memory, offset);
 }
 
 void GLAPIENTRY
@@ -359,7 +432,7 @@ _mesa_TexStorageMem1DEXT(GLenum target,
                          GLuint memory,
                          GLuint64 offset)
 {
-
+   texstorage_memory(1, target, levels, internalFormat, width, 1, 1, memory, offset);
 }
 
 void GLAPIENTRY
@@ -370,7 +443,7 @@ _mesa_TextureStorageMem1DEXT(GLuint texture,
                              GLuint memory,
                              GLuint64 offset)
 {
-
+   texturestorage_memory(1, texture, levels, internalFormat, width, 1, 1, memory, offset);
 }
 
 void GLAPIENTRY
diff --git a/src/mesa/main/texstorage.c b/src/mesa/main/texstorage.c
index 958c7b7..6ba1a2c 100644
--- a/src/mesa/main/texstorage.c
+++ b/src/mesa/main/texstorage.c
@@ -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,17 +391,20 @@ tex_storage_error_check(struct gl_context *ctx,
 void
 _mesa_texture_storage(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, bool dsa)
+                      GLsizei height, GLsizei depth,
+                      GLuint64 offset, bool dsa)
 {
    GLboolean sizeOK, dimensionsOK;
    mesa_format texFormat;
-   const char* suffix = dsa ? "ture" : "";
+   const char* suffix = dsa ? (memObj ? "tureMem" : "ture") :
+                              (memObj ? "Mem" : "");
 
    assert(texObj);
 
-   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 */
    }
@@ -449,18 +454,30 @@ _mesa_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);
@@ -509,8 +526,9 @@ texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
    if (!texObj)
       return;
 
-   _mesa_texture_storage(ctx, dims, texObj, target, levels,
-                         internalformat, width, height, depth, false);
+   _mesa_texture_storage(ctx, dims, texObj, NULL, target, levels,
+                         internalformat, width, height, depth,
+                         0, false);
 }
 
 
@@ -553,8 +571,9 @@ texturestorage(GLuint dims, GLuint texture, GLsizei levels,
       return;
    }
 
-   _mesa_texture_storage(ctx, dims, texObj, texObj->Target,
-                         levels, internalformat, width, height, depth, true);
+   _mesa_texture_storage(ctx, dims, texObj, NULL, texObj->Target,
+                         levels, internalformat, width, height, depth,
+                         0, true);
 }
 
 
@@ -673,3 +692,20 @@ _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);
+
+   _mesa_texture_storage(ctx, dims, texObj, memObj, target, levels,
+                         internalformat, width, height, depth,
+                         offset, dsa);
+}
diff --git a/src/mesa/main/texstorage.h b/src/mesa/main/texstorage.h
index e80a9ff..2aa5867 100644
--- a/src/mesa/main/texstorage.h
+++ b/src/mesa/main/texstorage.h
@@ -34,9 +34,11 @@
 extern void
 _mesa_texture_storage(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, bool dsa);
+                      GLsizei height, GLsizei depth,
+                      GLuint64 offset, bool dsa);
 
 /**
  * Texture width, height and depth check shared with the
@@ -120,4 +122,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 */
-- 
2.9.3



More information about the mesa-dev mailing list