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

Timothy Arceri tarceri at itsqueeze.com
Fri Aug 4 01:54:06 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 | 50 +++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/mtypes.h          |  4 +++-
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 6bc07a5015..c0c97f645c 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);
@@ -161,29 +162,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)
@@ -373,19 +422,20 @@ _mesa_ImportMemoryFdEXT(GLuint memory,
       _mesa_error(ctx, GL_INVALID_VALUE, "glImportMemoryFdEXT(handleType=%u)",
                   handleType);
       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 b5ec6168a1..3f83c0c427 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -4639,21 +4639,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