[Mesa-dev] [PATCH 03/24] mesa: add support for memory object parameters

Timothy Arceri tarceri at itsqueeze.com
Thu Jul 27 13:08:28 UTC 2017


From: Andres Rodriguez <andresx7 at gmail.com>

V2 (Timothy Arceri):
 - fix copy and paste error with error message

V3 (Timothy Arceri):
 - drop the Protected field for now as its unused

Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
---
 src/mesa/main/externalobjects.c | 51 ++++++++++++++++++++++++++++++++++++++++-
 src/mesa/main/mtypes.h          |  4 +++-
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 4cbada3f4e..c3ee0d8115 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -66,20 +66,21 @@ _mesa_init_memory_object_functions(struct dd_function_table *driver)
 /**
  * Initialize a buffer object to default values.
  */
 void
 _mesa_initialize_memory_object(struct gl_context *ctx,
                                struct gl_memory_object *obj,
                                GLuint name)
 {
    memset(obj, 0, sizeof(struct gl_memory_object));
    obj->Name = name;
+   obj->Dedicated = GL_FALSE;
 }
 
 void GLAPIENTRY
 _mesa_DeleteMemoryObjectsEXT(GLsizei n, const GLuint *memoryObjects)
 {
    GET_CURRENT_CONTEXT(ctx);
 
    if (MESA_VERBOSE & (VERBOSE_API))
       _mesa_debug(ctx, "glDeleteMemoryObjectsEXT(%d, %p)\n", n, memoryObjects);
 
@@ -135,21 +136,20 @@ _mesa_CreateMemoryObjectsEXT(GLsizei n, GLuint *memoryObjects)
    }
 
    if (!memoryObjects)
       return;
 
    _mesa_HashLockMutex(ctx->Shared->MemoryObjects);
    GLuint first = _mesa_HashFindFreeKeyBlock(ctx->Shared->MemoryObjects, n);
    if (first) {
       for (GLsizei i = 0; i < n; i++) {
          struct gl_memory_object *memObj;
-
          memoryObjects[i] = first + i;
 
          /* allocate memory object */
          memObj = ctx->Driver.NewMemoryObject(ctx, memoryObjects[i]);
          if (!memObj) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s()", func);
             goto out_unlock;
          }
 
          /* insert into hash table */
@@ -161,29 +161,77 @@ _mesa_CreateMemoryObjectsEXT(GLsizei n, GLuint *memoryObjects)
 
 out_unlock:
    _mesa_HashUnlockMutex(ctx->Shared->MemoryObjects);
 }
 
 void GLAPIENTRY
 _mesa_MemoryObjectParameterivEXT(GLuint memoryObject,
                                  GLenum pname,
                                  const GLint *params)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_memory_object *memObj;
+
+   memObj = _mesa_lookup_memory_object(ctx, memoryObject);
+   if (!memObj)
+      return;
+
+   if (memObj->Immutable) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glMemoryObjectParameterivEXT(memoryObject is immutable");
+      return;
+   }
 
+   switch (pname) {
+   case GL_DEDICATED_MEMORY_OBJECT_EXT:
+      memObj->Dedicated = (GLboolean) params[0];
+      break;
+   case GL_PROTECTED_MEMORY_OBJECT_EXT:
+      /* EXT_protected_textures not supported */
+      goto invalid_pname;
+   default:
+      goto invalid_pname;
+   }
+   return;
+
+invalid_pname:
+   _mesa_error(ctx, GL_INVALID_ENUM,
+               "glMemoryObjectParameterivEXT(pname=0x%x)", pname);
 }
 
 void GLAPIENTRY
 _mesa_GetMemoryObjectParameterivEXT(GLuint memoryObject,
                                     GLenum pname,
                                     GLint *params)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_memory_object *memObj;
+
+   memObj = _mesa_lookup_memory_object(ctx, memoryObject);
+   if (!memObj)
+      return;
+
+   switch (pname) {
+      case GL_DEDICATED_MEMORY_OBJECT_EXT:
+         *params = (GLint) memObj->Dedicated;
+         break;
+      case GL_PROTECTED_MEMORY_OBJECT_EXT:
+         /* EXT_protected_textures not supported */
+         goto invalid_pname;
+      default:
+         goto invalid_pname;
+   }
+   return;
 
+invalid_pname:
+   _mesa_error(ctx, GL_INVALID_ENUM,
+               "glGetMemoryObjectParameterivEXT(pname=0x%x)", pname);
 }
 
 void GLAPIENTRY
 _mesa_TexStorageMem2DEXT(GLenum target,
                          GLsizei levels,
                          GLenum internalFormat,
                          GLsizei width,
                          GLsizei height,
                          GLuint memory,
                          GLuint64 offset)
@@ -375,19 +423,20 @@ _mesa_ImportMemoryFdEXT(GLuint memory,
    }
 
    if (memory == 0)
       return;
 
    struct gl_memory_object *memObj = _mesa_lookup_memory_object(ctx, memory);
    if (!memObj)
       return;
 
    ctx->Driver.ImportMemoryObjectFd(ctx, memObj, size, fd);
+   memObj->Immutable = GL_TRUE;
 }
 
 void GLAPIENTRY
 _mesa_ImportSemaphoreFdEXT(GLuint semaphore,
                            GLenum handleType,
                            GLint fd)
 {
 
 }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 642cd72d29..8cb9ae3d17 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -4640,21 +4640,23 @@ struct gl_texture_handle_object
 };
 
 struct gl_image_handle_object
 {
    struct gl_image_unit imgObj;
    GLuint64 handle;
 };
 
 struct gl_memory_object
 {
-   GLuint Name;          /**< hash table ID/name */
+   GLuint Name;            /**< hash table ID/name */
+   GLboolean Immutable;    /**< denotes mutability state of parameters */
+   GLboolean Dedicated;    /**< import memory from a dedicated allocation */
 };
 
 /**
  * Mesa rendering context.
  *
  * This is the central context data structure for Mesa.  Almost all
  * OpenGL state is contained in this structure.
  * Think of this as a base class from which device drivers will derive
  * sub classes.
  */
-- 
2.13.3



More information about the mesa-dev mailing list