mesa: add support for memory object parameters
authorAndres Rodriguez <andresx7@gmail.com>
Wed, 12 Jul 2017 22:45:08 +0000 (18:45 -0400)
committerTimothy Arceri <tarceri@itsqueeze.com>
Sun, 6 Aug 2017 02:42:06 +0000 (12:42 +1000)
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@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/mesa/main/externalobjects.c
src/mesa/main/mtypes.h

index 6c5b07d110ebc380bdf23189bda2960d4f132b99..9241fe1fe6ab47358036394d559b2f010aaedaf6 100644 (file)
@@ -73,6 +73,7 @@ _mesa_initialize_memory_object(struct gl_context *ctx,
 {
    memset(obj, 0, sizeof(struct gl_memory_object));
    obj->Name = name;
+   obj->Dedicated = GL_FALSE;
 }
 
 void GLAPIENTRY
@@ -168,7 +169,34 @@ _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
@@ -176,7 +204,28 @@ _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
@@ -380,6 +429,7 @@ _mesa_ImportMemoryFdEXT(GLuint memory,
       return;
 
    ctx->Driver.ImportMemoryObjectFd(ctx, memObj, size, fd);
+   memObj->Immutable = GL_TRUE;
 }
 
 void GLAPIENTRY
index 8ef1183785c3c2ac4650780dfb4b3167dd118e34..1c48d2313683c157b816d5c6086af9d4f657f66c 100644 (file)
@@ -4646,7 +4646,9 @@ struct gl_image_handle_object
 
 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 */
 };
 
 /**