[Mesa-dev] [PATCH 15/21] main: Add entry point for UnmapNamedBuffer.

Laura Ekstrand laura at jlekstrand.net
Wed Jan 21 17:40:28 PST 2015


---
 src/mapi/glapi/gen/ARB_direct_state_access.xml |  5 ++
 src/mesa/main/bufferobj.c                      | 87 ++++++++++----------------
 src/mesa/main/bufferobj.h                      |  7 +++
 src/mesa/main/tests/dispatch_sanity.cpp        |  1 +
 4 files changed, 47 insertions(+), 53 deletions(-)

diff --git a/src/mapi/glapi/gen/ARB_direct_state_access.xml b/src/mapi/glapi/gen/ARB_direct_state_access.xml
index 7727f0d..f2b17c8 100644
--- a/src/mapi/glapi/gen/ARB_direct_state_access.xml
+++ b/src/mapi/glapi/gen/ARB_direct_state_access.xml
@@ -75,6 +75,11 @@
       <param name="access" type="GLbitfield" />
    </function>
 
+   <function name="UnmapNamedBuffer" offset="assign">
+      <return type="GLboolean" />
+      <param name="buffer" type="GLuint" />
+   </function>
+
   <!-- Texture object functions -->
 
    <function name="CreateTextures" offset="assign">
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 16c0faa..087d31e 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -49,10 +49,6 @@
 #include "dispatch.h"
 
 
-/* Debug flags */
-/*#define VBO_DEBUG*/
-/*#define BOUNDS_CHECK*/
-
 
 /**
  * Used as a placeholder for buffer objects between glGenBuffers() and
@@ -736,15 +732,15 @@ _mesa_buffer_flush_mapped_range( struct gl_context *ctx,
 
 
 /**
- * Default callback for \c dd_function_table::MapBuffer().
+ * Default callback for \c dd_function_table::UnmapBuffer().
  *
  * The input parameters will have been already tested for errors.
  *
  * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
  */
 static GLboolean
-_mesa_buffer_unmap(struct gl_context *ctx, struct gl_buffer_object *bufObj,
-                   gl_map_buffer_index index)
+_mesa_UnmapBuffer_sw(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+                     gl_map_buffer_index index)
 {
    (void) ctx;
    /* XXX we might assert here that bufObj->Pointer is non-null */
@@ -1110,7 +1106,7 @@ _mesa_init_buffer_object_functions(struct dd_function_table *driver)
    driver->BufferData = _mesa_BufferData_sw;
    driver->BufferSubData = _mesa_BufferSubData_sw;
    driver->GetBufferSubData = _mesa_buffer_get_subdata;
-   driver->UnmapBuffer = _mesa_buffer_unmap;
+   driver->UnmapBuffer = _mesa_UnmapBuffer_sw;
 
    /* GL_ARB_clear_buffer_object */
    driver->ClearBufferSubData = _mesa_ClearBufferSubData_sw;
@@ -1794,59 +1790,19 @@ _mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
 }
 
 
-GLboolean GLAPIENTRY
-_mesa_UnmapBuffer(GLenum target)
+GLboolean
+_mesa_unmap_buffer(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+                   const char *func)
 {
-   GET_CURRENT_CONTEXT(ctx);
-   struct gl_buffer_object *bufObj;
    GLboolean status = GL_TRUE;
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
 
-   bufObj = get_buffer(ctx, "glUnmapBufferARB", target, GL_INVALID_OPERATION);
-   if (!bufObj)
-      return GL_FALSE;
-
    if (!_mesa_bufferobj_mapped(bufObj, MAP_USER)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB");
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "%s(buffer is already unmapped)", func);
       return GL_FALSE;
    }
 
-#ifdef BOUNDS_CHECK
-   if (bufObj->Access != GL_READ_ONLY_ARB) {
-      GLubyte *buf = (GLubyte *) bufObj->Pointer;
-      GLuint i;
-      /* check that last 100 bytes are still = magic value */
-      for (i = 0; i < 100; i++) {
-         GLuint pos = bufObj->Size - i - 1;
-         if (buf[pos] != 123) {
-            _mesa_warning(ctx, "Out of bounds buffer object write detected"
-                          " at position %d (value = %u)\n",
-                          pos, buf[pos]);
-         }
-      }
-   }
-#endif
-
-#ifdef VBO_DEBUG
-   if (bufObj->AccessFlags & GL_MAP_WRITE_BIT) {
-      GLuint i, unchanged = 0;
-      GLubyte *b = (GLubyte *) bufObj->Pointer;
-      GLint pos = -1;
-      /* check which bytes changed */
-      for (i = 0; i < bufObj->Size - 1; i++) {
-         if (b[i] == (i & 0xff) && b[i+1] == ((i+1) & 0xff)) {
-            unchanged++;
-            if (pos == -1)
-               pos = i;
-         }
-      }
-      if (unchanged) {
-         printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
-                      bufObj->Name, unchanged, bufObj->Size, pos);
-      }
-   }
-#endif
-
    status = ctx->Driver.UnmapBuffer(ctx, bufObj, MAP_USER);
    bufObj->Mappings[MAP_USER].AccessFlags = 0;
    ASSERT(bufObj->Mappings[MAP_USER].Pointer == NULL);
@@ -1856,6 +1812,31 @@ _mesa_UnmapBuffer(GLenum target)
    return status;
 }
 
+GLboolean GLAPIENTRY
+_mesa_UnmapBuffer(GLenum target)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_buffer_object *bufObj;
+
+   bufObj = get_buffer(ctx, "glUnmapBuffer", target, GL_INVALID_OPERATION);
+   if (!bufObj)
+      return GL_FALSE;
+
+   return _mesa_unmap_buffer(ctx, bufObj, "glUnmapBuffer");
+}
+
+GLboolean GLAPIENTRY
+_mesa_UnmapNamedBuffer(GLuint buffer)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_buffer_object *bufObj;
+
+   bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glUnmapNamedBuffer");
+   if (!bufObj)
+      return GL_FALSE;
+
+   return _mesa_unmap_buffer(ctx, bufObj, "glUnmapNamedBuffer");
+}
 
 void GLAPIENTRY
 _mesa_GetBufferParameteriv(GLenum target, GLenum pname, GLint *params)
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index b34162e..864c4be 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -177,6 +177,10 @@ _mesa_clear_buffer_sub_data(struct gl_context *ctx,
                             const GLvoid *data,
                             const char *func, bool subdata);
 
+extern GLboolean
+_mesa_unmap_buffer(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+                   const char *func);
+
 /*
  * API functions
  */
@@ -248,6 +252,9 @@ _mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
 GLboolean GLAPIENTRY
 _mesa_UnmapBuffer(GLenum target);
 
+GLboolean GLAPIENTRY
+_mesa_UnmapNamedBuffer(GLuint buffer);
+
 void GLAPIENTRY
 _mesa_GetBufferParameteriv(GLenum target, GLenum pname, GLint *params);
 
diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
index 5632ac0..05f6d07 100644
--- a/src/mesa/main/tests/dispatch_sanity.cpp
+++ b/src/mesa/main/tests/dispatch_sanity.cpp
@@ -964,6 +964,7 @@ const struct function gl_core_functions_possible[] = {
    { "glClearNamedBufferSubData", 45, -1 },
    { "glMapNamedBuffer", 45, -1 },
    { "glMapNamedBufferRange", 45, -1 },
+   { "glUnmapNamedBuffer", 45, -1 },
    { "glCreateTextures", 45, -1 },
    { "glTextureStorage1D", 45, -1 },
    { "glTextureStorage2D", 45, -1 },
-- 
2.1.0



More information about the mesa-dev mailing list