mesa: Set default access flags based on the run-time API
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 18 Jan 2012 00:24:05 +0000 (16:24 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 19 Jan 2012 17:34:01 +0000 (09:34 -0800)
The default access flags for OpenGL ES (via GL_OES_map_buffer) and
desktop OpenGL are different.  The code previously tried to handle
this, but the decision was made at compile time.  Since the same
driver binary can be used for both OpenGL ES and desktop OpenGL, the
decision must be made at run-time.

This should fix bug #44433.  It appears that the test case does
various map and unmap operations and inspects the state of the buffer
object around each.  When it sees that GL_BUFFER_ACCESS does not match
its expectations, it fails.

NOTE: This is a candidate for release branches.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44433

src/mesa/drivers/dri/intel/intel_buffer_objects.c
src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
src/mesa/main/bufferobj.c
src/mesa/main/bufferobj.h
src/mesa/state_tracker/st_cb_bufferobjects.c

index 03dd179ee0b208b366ca52782c315bdb70fb0d86..600f01ca6f052a34cbfc1e3753628b3814e1f587 100644 (file)
@@ -72,7 +72,7 @@ intel_bufferobj_alloc(struct gl_context * ctx, GLuint name, GLenum target)
 {
    struct intel_buffer_object *obj = CALLOC_STRUCT(intel_buffer_object);
 
-   _mesa_initialize_buffer_object(&obj->Base, name, target);
+   _mesa_initialize_buffer_object(ctx, &obj->Base, name, target);
 
    obj->buffer = NULL;
 
index dc5b1528b071343b82900b96b4606bc0396aaa1a..f7ad895ac9af0e208fd18d2fb6fa03df640bbe5a 100644 (file)
@@ -56,7 +56,7 @@ nouveau_bufferobj_new(struct gl_context *ctx, GLuint buffer, GLenum target)
        if (!nbo)
                return NULL;
 
-       _mesa_initialize_buffer_object(&nbo->base, buffer, target);
+       _mesa_initialize_buffer_object(ctx, &nbo->base, buffer, target);
 
        return &nbo->base;
 }
index 7b59c0377f8dd73687952c5fd9b679ae4ad8506b..5abc52ba3f7ff4a136c04ea5c8004d67bf0602ba 100644 (file)
@@ -46,7 +46,7 @@ radeonNewBufferObject(struct gl_context * ctx,
 {
     struct radeon_buffer_object *obj = CALLOC_STRUCT(radeon_buffer_object);
 
-    _mesa_initialize_buffer_object(&obj->Base, name, target);
+    _mesa_initialize_buffer_object(ctx, &obj->Base, name, target);
 
     obj->bo = NULL;
 
index 5f8071f587f6e2f798f4eea95cae3eb500ca8f67..5b6db78d821611dc8aa4b4d6bcd047302584f616 100644 (file)
 /*#define BOUNDS_CHECK*/
 
 
-#if FEATURE_OES_mapbuffer
-#define DEFAULT_ACCESS GL_MAP_WRITE_BIT
-#else
-#define DEFAULT_ACCESS (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)
-#endif
-
-
 /**
  * Used as a placeholder for buffer objects between glGenBuffers() and
  * glBindBuffer() so that glIsBuffer() can work correctly.
@@ -122,6 +115,30 @@ get_buffer(struct gl_context *ctx, GLenum target)
 }
 
 
+static inline GLenum
+default_access_mode(const struct gl_context *ctx)
+{
+   /* Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
+    *
+    * Name           Type  Initial Value  Legal Values
+    * ...            ...   ...            ...
+    * BUFFER_ACCESS  enum  READ_WRITE     READ_ONLY, WRITE_ONLY
+    *                                     READ_WRITE
+    *
+    * However, table 6.8 in the GL_OES_mapbuffer extension says:
+    *
+    * Get Value         Type Get Command          Value          Description
+    * ---------         ---- -----------          -----          -----------
+    * BUFFER_ACCESS_OES Z1   GetBufferParameteriv WRITE_ONLY_OES buffer map flag
+    *
+    * The difference is because GL_OES_mapbuffer only supports mapping buffers
+    * write-only.
+    */
+   return (ctx->API == API_OPENGLES)
+      ? GL_MAP_WRITE_BIT : (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
+}
+
+
 /**
  * Convert a GLbitfield describing the mapped buffer access flags
  * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
@@ -213,7 +230,7 @@ _mesa_new_buffer_object( struct gl_context *ctx, GLuint name, GLenum target )
    (void) ctx;
 
    obj = MALLOC_STRUCT(gl_buffer_object);
-   _mesa_initialize_buffer_object(obj, name, target);
+   _mesa_initialize_buffer_object(ctx, obj, name, target);
    return obj;
 }
 
@@ -311,7 +328,8 @@ _mesa_reference_buffer_object_(struct gl_context *ctx,
  * Initialize a buffer object to default values.
  */
 void
-_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
+_mesa_initialize_buffer_object( struct gl_context *ctx,
+                               struct gl_buffer_object *obj,
                                GLuint name, GLenum target )
 {
    (void) target;
@@ -321,7 +339,7 @@ _mesa_initialize_buffer_object( struct gl_buffer_object *obj,
    obj->RefCount = 1;
    obj->Name = name;
    obj->Usage = GL_STATIC_DRAW_ARB;
-   obj->AccessFlags = DEFAULT_ACCESS;
+   obj->AccessFlags = default_access_mode(ctx);
 }
 
 
@@ -740,7 +758,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids)
          if (_mesa_bufferobj_mapped(bufObj)) {
             /* if mapped, unmap it now */
             ctx->Driver.UnmapBuffer(ctx, bufObj);
-            bufObj->AccessFlags = DEFAULT_ACCESS;
+            bufObj->AccessFlags = default_access_mode(ctx);
             bufObj->Pointer = NULL;
          }
 
@@ -900,7 +918,7 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size,
    if (_mesa_bufferobj_mapped(bufObj)) {
       /* Unmap the existing buffer.  We'll replace it now.  Not an error. */
       ctx->Driver.UnmapBuffer(ctx, bufObj);
-      bufObj->AccessFlags = DEFAULT_ACCESS;
+      bufObj->AccessFlags = default_access_mode(ctx);
       ASSERT(bufObj->Pointer == NULL);
    }  
 
@@ -1119,7 +1137,7 @@ _mesa_UnmapBufferARB(GLenum target)
 #endif
 
    status = ctx->Driver.UnmapBuffer( ctx, bufObj );
-   bufObj->AccessFlags = DEFAULT_ACCESS;
+   bufObj->AccessFlags = default_access_mode(ctx);
    ASSERT(bufObj->Pointer == NULL);
    ASSERT(bufObj->Offset == 0);
    ASSERT(bufObj->Length == 0);
index c0d5a641a46e1d8d3b97a01d202817db0ac56c7b..a7ce37928983178669e456816d98710eef711b21 100644 (file)
@@ -71,7 +71,8 @@ extern struct gl_buffer_object *
 _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer);
 
 extern void
-_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
+_mesa_initialize_buffer_object( struct gl_context *ctx,
+                               struct gl_buffer_object *obj,
                                GLuint name, GLenum target );
 
 extern void
index 6d95d57c1b36ddde16bd6543f5e43c7e36141702..6534a4347ab230494de395405652e9ea6a74acd7 100644 (file)
@@ -58,7 +58,7 @@ st_bufferobj_alloc(struct gl_context *ctx, GLuint name, GLenum target)
    if (!st_obj)
       return NULL;
 
-   _mesa_initialize_buffer_object(&st_obj->Base, name, target);
+   _mesa_initialize_buffer_object(ctx, &st_obj->Base, name, target);
 
    return &st_obj->Base;
 }