[Mesa-dev,14/27] mesa: hook up (Named)BufferStorageMem api

Submitted by Andres Rodriguez on July 12, 2017, 10:45 p.m.

Details

Message ID 20170712224532.1307-15-andresx7@gmail.com
State New
Headers show
Series "Initial support for EXT_external_objects v3" ( rev: 3 2 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Andres Rodriguez July 12, 2017, 10:45 p.m.
Include no_error variants as well.

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
---
 src/mapi/glapi/gen/EXT_external_objects.xml |  4 +-
 src/mesa/main/bufferobj.c                   | 80 +++++++++++++++++++++++------
 src/mesa/main/bufferobj.h                   | 16 +++++-
 src/mesa/main/externalobjects.c             | 18 -------
 src/mesa/main/externalobjects.h             | 12 -----
 5 files changed, 81 insertions(+), 49 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/mapi/glapi/gen/EXT_external_objects.xml b/src/mapi/glapi/gen/EXT_external_objects.xml
index 7c4fd6f..25e6879 100644
--- a/src/mapi/glapi/gen/EXT_external_objects.xml
+++ b/src/mapi/glapi/gen/EXT_external_objects.xml
@@ -108,7 +108,7 @@ 
         <param name="offset" type="GLuint64"/>
     </function>
 
-    <function name="BufferStorageMemEXT" es2="3.2">
+    <function name="BufferStorageMemEXT" es2="3.2" no_error="true">
         <param name="target" type="GLenum"/>
         <param name="size" type="GLsizeiptr"/>
         <param name="memory" type="GLuint"/>
@@ -159,7 +159,7 @@ 
         <param name="offset" type="GLuint64"/>
     </function>
 
-    <function name="NamedBufferStorageMemEXT" es2="3.2">
+    <function name="NamedBufferStorageMemEXT" es2="3.2" no_error="true">
         <param name="buffer" type="GLuint"/>
         <param name="size" type="GLsizeiptr"/>
         <param name="memory" type="GLuint"/>
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 419972e..13d16b1 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -39,6 +39,7 @@ 
 #include "imports.h"
 #include "context.h"
 #include "bufferobj.h"
+#include "externalobjects.h"
 #include "mtypes.h"
 #include "teximage.h"
 #include "glformats.h"
@@ -1596,9 +1597,12 @@  validate_buffer_storage(struct gl_context *ctx,
 
 static void
 buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
-               GLenum target, GLsizeiptr size, const GLvoid *data,
-               GLbitfield flags, const char *func)
+               struct gl_memory_object *memObj, GLenum target,
+               GLsizeiptr size, const GLvoid *data, GLbitfield flags,
+               GLuint64 offset, const char *func)
 {
+   GLboolean err;
+
    /* Unmap the existing buffer.  We'll replace it now.  Not an error. */
    _mesa_buffer_unmap_all_mappings(ctx, bufObj);
 
@@ -1608,9 +1612,18 @@  buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
    bufObj->Immutable = GL_TRUE;
    bufObj->MinMaxCacheDirty = true;
 
-   assert(ctx->Driver.BufferData);
-   if (!ctx->Driver.BufferData(ctx, target, size, data, GL_DYNAMIC_DRAW,
-                               flags, bufObj)) {
+   if (memObj) {
+      assert(ctx->Driver.BufferData);
+      err = ctx->Driver.BufferDataMem(ctx, target, size, memObj, offset,
+                                      GL_DYNAMIC_DRAW, bufObj);
+   }
+   else {
+      assert(ctx->Driver.BufferData);
+      err = ctx->Driver.BufferData(ctx, target, size, data, GL_DYNAMIC_DRAW,
+                                   flags, bufObj);
+   }
+
+   if (err) {
       if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {
          /* Even though the interaction between AMD_pinned_memory and
           * glBufferStorage is not described in the spec, Graham Sellers
@@ -1627,11 +1640,16 @@  buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
 
 static ALWAYS_INLINE void
 inlined_buffer_storage(GLenum target, GLuint buffer, GLsizeiptr size,
-                       const GLvoid *data, GLbitfield flags, bool dsa,
-                       bool no_error, const char *func)
+                       const GLvoid *data, GLbitfield flags,
+                       GLuint memory, GLuint64 offset,
+                       bool dsa, bool mem, bool no_error, const char *func)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
+   struct gl_memory_object *memObj = NULL;
+
+   if (mem)
+      memObj = _mesa_lookup_memory_object(ctx, memory);
 
    if (dsa) {
       if (no_error) {
@@ -1653,7 +1671,7 @@  inlined_buffer_storage(GLenum target, GLuint buffer, GLsizeiptr size,
    }
 
    if (no_error || validate_buffer_storage(ctx, bufObj, size, flags, func))
-      buffer_storage(ctx, bufObj, target, size, data, flags, func);
+      buffer_storage(ctx, bufObj, memObj, target, size, data, flags, offset, func);
 }
 
 
@@ -1661,8 +1679,8 @@  void GLAPIENTRY
 _mesa_BufferStorage_no_error(GLenum target, GLsizeiptr size,
                              const GLvoid *data, GLbitfield flags)
 {
-   inlined_buffer_storage(target, 0, size, data, flags, false, true,
-                          "glBufferStorage");
+   inlined_buffer_storage(target, 0, size, data, flags, GL_NONE, 0,
+                          false, false, true, "glBufferStorage");
 }
 
 
@@ -1670,10 +1688,25 @@  void GLAPIENTRY
 _mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
                     GLbitfield flags)
 {
-   inlined_buffer_storage(target, 0, size, data, flags, false, false,
-                          "glBufferStorage");
+   inlined_buffer_storage(target, 0, size, data, flags, GL_NONE, 0,
+                          false, false, false, "glBufferStorage");
 }
 
+void GLAPIENTRY
+_mesa_BufferStorageMemEXT_no_error(GLenum target, GLsizeiptr size,
+                                   GLuint memory, GLuint64 offset)
+{
+   inlined_buffer_storage(target, 0, size, NULL, 0, memory, offset,
+                          false, true, true, "glBufferStorageMemEXT");
+}
+
+void GLAPIENTRY
+_mesa_BufferStorageMemEXT(GLenum target, GLsizeiptr size,
+                          GLuint memory, GLuint64 offset)
+{
+   inlined_buffer_storage(target, 0, size, NULL, 0, memory, offset,
+                          false, true, false, "glBufferStorageMemEXT");
+}
 
 void GLAPIENTRY
 _mesa_NamedBufferStorage_no_error(GLuint buffer, GLsizeiptr size,
@@ -1682,8 +1715,8 @@  _mesa_NamedBufferStorage_no_error(GLuint buffer, GLsizeiptr size,
    /* In direct state access, buffer objects have an unspecified target
     * since they are not required to be bound.
     */
-   inlined_buffer_storage(GL_NONE, buffer, size, data, flags, true, true,
-                          "glNamedBufferStorage");
+   inlined_buffer_storage(GL_NONE, buffer, size, data, flags, GL_NONE, 0,
+                          true, false, true, "glNamedBufferStorage");
 }
 
 
@@ -1694,10 +1727,25 @@  _mesa_NamedBufferStorage(GLuint buffer, GLsizeiptr size, const GLvoid *data,
    /* In direct state access, buffer objects have an unspecified target
     * since they are not required to be bound.
     */
-   inlined_buffer_storage(GL_NONE, buffer, size, data, flags, true, false,
-                          "glNamedBufferStorage");
+   inlined_buffer_storage(GL_NONE, buffer, size, data, flags, GL_NONE, 0,
+                          true, false, false, "glNamedBufferStorage");
+}
+
+void GLAPIENTRY
+_mesa_NamedBufferStorageMemEXT_no_error(GLuint buffer, GLsizeiptr size,
+                                        GLuint memory, GLuint64 offset)
+{
+   inlined_buffer_storage(GL_NONE, buffer, size, GL_NONE, 0, memory, offset,
+                          true, true, true, "glNamedBufferStorageMemEXT");
 }
 
+void GLAPIENTRY
+_mesa_NamedBufferStorageMemEXT(GLuint buffer, GLsizeiptr size,
+                               GLuint memory, GLuint64 offset)
+{
+   inlined_buffer_storage(GL_NONE, buffer, size, GL_NONE, 0, memory, offset,
+                          true, true, false, "glNamedBufferStorageMemEXT");
+}
 
 void
 _mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index 662ceba..4454d67 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -151,6 +151,9 @@  _mesa_ClearBufferSubData_sw(struct gl_context *ctx,
                             const GLvoid *clearValue,
                             GLsizeiptr clearValueSize,
                             struct gl_buffer_object *bufObj);
+extern void
+_mesa_bufferstorage_mem(GLenum target, GLsizeiptr size,
+                        const GLvoid *data, GLbitfield flags);
 
 /*
  * API functions
@@ -185,13 +188,24 @@  _mesa_BufferStorage_no_error(GLenum target, GLsizeiptr size,
 void GLAPIENTRY
 _mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
                     GLbitfield flags);
-
+void GLAPIENTRY
+_mesa_BufferStorageMemEXT(GLenum target, GLsizeiptr size,
+                          GLuint memory, GLuint64 offset);
+void GLAPIENTRY
+_mesa_BufferStorageMemEXT_no_error(GLenum target, GLsizeiptr size,
+                                   GLuint memory, GLuint64 offset);
 void GLAPIENTRY
 _mesa_NamedBufferStorage_no_error(GLuint buffer, GLsizeiptr size,
                                   const GLvoid *data, GLbitfield flags);
 void GLAPIENTRY
 _mesa_NamedBufferStorage(GLuint buffer, GLsizeiptr size, const GLvoid *data,
                          GLbitfield flags);
+void GLAPIENTRY
+_mesa_NamedBufferStorageMemEXT(GLuint buffer, GLsizeiptr size,
+                               GLuint memory, GLuint64 offset);
+void GLAPIENTRY
+_mesa_NamedBufferStorageMemEXT_no_error(GLuint buffer, GLsizeiptr size,
+                                        GLuint memory, GLuint64 offset);
 
 void GLAPIENTRY
 _mesa_BufferData(GLenum target, GLsizeiptr size,
diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 0b4f5f5..919a81c 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -390,15 +390,6 @@  _mesa_TexStorageMem3DMultisampleEXT(GLenum target,
 }
 
 void GLAPIENTRY
-_mesa_BufferStorageMemEXT(GLenum target,
-                          GLsizeiptr size,
-                          GLuint memory,
-                          GLuint64 offset)
-{
-
-}
-
-void GLAPIENTRY
 _mesa_TextureStorageMem2DEXT(GLuint texture,
                              GLsizei levels,
                              GLenum internalFormat,
@@ -455,15 +446,6 @@  _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,
 }
 
 void GLAPIENTRY
-_mesa_NamedBufferStorageMemEXT(GLuint buffer,
-                               GLsizeiptr size,
-                               GLuint memory,
-                               GLuint64 offset)
-{
-
-}
-
-void GLAPIENTRY
 _mesa_TexStorageMem1DEXT(GLenum target,
                          GLsizei levels,
                          GLenum internalFormat,
diff --git a/src/mesa/main/externalobjects.h b/src/mesa/main/externalobjects.h
index 7c33bc1..0219a07 100644
--- a/src/mesa/main/externalobjects.h
+++ b/src/mesa/main/externalobjects.h
@@ -124,12 +124,6 @@  _mesa_TexStorageMem3DMultisampleEXT(GLenum target,
                                     GLuint64 offset);
 
 extern void GLAPIENTRY
-_mesa_BufferStorageMemEXT(GLenum target,
-                          GLsizeiptr size,
-                          GLuint memory,
-                          GLuint64 offset);
-
-extern void GLAPIENTRY
 _mesa_TextureStorageMem2DEXT(GLuint texture,
                              GLsizei levels,
                              GLenum internalFormat,
@@ -170,12 +164,6 @@  _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,
                                         GLuint64 offset);
 
 extern void GLAPIENTRY
-_mesa_NamedBufferStorageMemEXT(GLuint buffer,
-                               GLsizeiptr size,
-                               GLuint memory,
-                               GLuint64 offset);
-
-extern void GLAPIENTRY
 _mesa_TexStorageMem1DEXT(GLenum target,
                          GLsizei levels,
                          GLenum internalFormat,