mesa: move the NullBufferObj from GLcontext to gl_shared_state
authorBrian Paul <brianp@vmware.com>
Thu, 7 May 2009 19:30:39 +0000 (13:30 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 7 May 2009 20:34:09 +0000 (14:34 -0600)
Since shared array objects may point to the null/default buffer object,
the null/default buffer object should be part of the shared state.

13 files changed:
src/mesa/main/arrayobj.c
src/mesa/main/bufferobj.c
src/mesa/main/context.c
src/mesa/main/mtypes.h
src/mesa/main/pixel.c
src/mesa/main/pixelstore.c
src/mesa/main/shared.c
src/mesa/swrast/s_imaging.c
src/mesa/vbo/vbo_context.c
src/mesa/vbo/vbo_exec_api.c
src/mesa/vbo/vbo_rebase.c
src/mesa/vbo/vbo_split_copy.c
src/mesa/vbo/vbo_split_inplace.c

index b04095fd16b6fb9514bbe2289103a1ff12a11623..2646c12ccc1554240f526028f64f13a532925c24 100644 (file)
@@ -112,7 +112,8 @@ init_array(GLcontext *ctx,
    array->Normalized = GL_FALSE;
 #if FEATURE_ARB_vertex_buffer_object
    /* Vertex array buffers */
-   array->BufferObj = ctx->Array.NullBufferObj;
+   _mesa_reference_buffer_object(ctx, &array->BufferObj,
+                                 ctx->Shared->NullBufferObj);
 #endif
 }
 
@@ -180,7 +181,7 @@ _mesa_remove_array_object( GLcontext *ctx, struct gl_array_object *obj )
 static void
 unbind_buffer_object( GLcontext *ctx, struct gl_buffer_object *bufObj )
 {
-   if (bufObj != ctx->Array.NullBufferObj) {
+   if (bufObj != ctx->Shared->NullBufferObj) {
       _mesa_reference_buffer_object(ctx, &bufObj, NULL);
    }
 }
index a983376251825f35e485ae452234892e340b5b1c..1f2070ef4735548fe71ed1ecb25c8c8176fc6940 100644 (file)
@@ -424,16 +424,8 @@ _mesa_buffer_unmap( GLcontext *ctx, GLenum target,
 void
 _mesa_init_buffer_objects( GLcontext *ctx )
 {
-   /* Allocate the default buffer object and set refcount so high that
-    * it never gets deleted.
-    * XXX with recent/improved refcounting this may not longer be needed.
-    */
-   ctx->Array.NullBufferObj = _mesa_new_buffer_object(ctx, 0, 0);
-   if (ctx->Array.NullBufferObj)
-      ctx->Array.NullBufferObj->RefCount = 1000;
-
-   ctx->Array.ArrayBufferObj = ctx->Array.NullBufferObj;
-   ctx->Array.ElementArrayBufferObj = ctx->Array.NullBufferObj;
+   ctx->Array.ArrayBufferObj = ctx->Shared->NullBufferObj;
+   ctx->Array.ElementArrayBufferObj = ctx->Shared->NullBufferObj;
 }
 
 
@@ -477,7 +469,7 @@ bind_buffer_object(GLcontext *ctx, GLenum target, GLuint buffer)
       /* The spec says there's not a buffer object named 0, but we use
        * one internally because it simplifies things.
        */
-      newBufObj = ctx->Array.NullBufferObj;
+      newBufObj = ctx->Shared->NullBufferObj;
    }
    else {
       /* non-default buffer object */
@@ -744,7 +736,7 @@ unbind(GLcontext *ctx,
        struct gl_buffer_object *obj)
 {
    if (*ptr == obj) {
-      _mesa_reference_buffer_object(ctx, ptr, ctx->Array.NullBufferObj);
+      _mesa_reference_buffer_object(ctx, ptr, ctx->Shared->NullBufferObj);
    }
 }
 
index d780f91f048b95dbb296aa8f2dddb10ab0296b96..1a290f251adbf7600f8c44ae84436c281575eef4 100644 (file)
@@ -1005,9 +1005,6 @@ _mesa_free_context_data( GLcontext *ctx )
    _mesa_free_query_data(ctx);
 #endif
 
-#if FEATURE_ARB_vertex_buffer_object
-   _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj);
-#endif
    _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
 
    /* free dispatch tables */
index affb000b8c48012a20a77ef159240379e03ea2ac..3debbe9f2de1650b9c110dd45c50a7cf0ec5d95a 100644 (file)
@@ -1593,7 +1593,6 @@ struct gl_array_attrib
    GLbitfield NewState;                /**< mask of _NEW_ARRAY_* values */
 
 #if FEATURE_ARB_vertex_buffer_object
-   struct gl_buffer_object *NullBufferObj;
    struct gl_buffer_object *ArrayBufferObj;
    struct gl_buffer_object *ElementArrayBufferObj;
 #endif
@@ -2064,6 +2063,8 @@ struct gl_shared_state
    GLuint TextureStateStamp;           /**< state notification for shared tex */
    /*@}*/
 
+   /** Default buffer object for vertex arrays that aren't in VBOs */
+   struct gl_buffer_object *NullBufferObj;
 
    /**
     * \name Vertex/fragment programs
index 57ae9c721a823e42b0aefac04f045eca947773fc..d9f3e476e81e0f52f7bfc0c9a97a45a37c92558b 100644 (file)
@@ -170,7 +170,7 @@ _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
          return;
       }
       /* restore */
-      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+      ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
       buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
                                               GL_READ_ONLY_ARB,
                                               ctx->Unpack.BufferObj);
@@ -229,7 +229,7 @@ _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
          return;
       }
       /* restore */
-      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+      ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
       buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
                                               GL_READ_ONLY_ARB,
                                               ctx->Unpack.BufferObj);
@@ -303,7 +303,7 @@ _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
          return;
       }
       /* restore */
-      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+      ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
       buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
                                               GL_READ_ONLY_ARB,
                                               ctx->Unpack.BufferObj);
@@ -371,7 +371,7 @@ _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
          return;
       }
       /* restore */
-      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+      ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
       buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
                                               GL_WRITE_ONLY_ARB,
                                               ctx->Pack.BufferObj);
@@ -432,7 +432,7 @@ _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
          return;
       }
       /* restore */
-      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+      ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
       buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
                                               GL_WRITE_ONLY_ARB,
                                               ctx->Pack.BufferObj);
@@ -494,7 +494,7 @@ _mesa_GetPixelMapusv( GLenum map, GLushort *values )
          return;
       }
       /* restore */
-      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+      ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
       buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
                                               GL_WRITE_ONLY_ARB,
                                               ctx->Pack.BufferObj);
index ff1a6344cc946f5540630c81373754a7a0c67dcb..6a641f83f27fea499748db7b4d1388e245fba0fd 100644 (file)
@@ -245,7 +245,8 @@ _mesa_init_pixelstore( GLcontext *ctx )
    ctx->Pack.ClientStorage = GL_FALSE;
    ctx->Pack.Invert = GL_FALSE;
 #if FEATURE_EXT_pixel_buffer_object
-   ctx->Pack.BufferObj = ctx->Array.NullBufferObj;
+   _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj,
+                                 ctx->Shared->NullBufferObj);
 #endif
    ctx->Unpack.Alignment = 4;
    ctx->Unpack.RowLength = 0;
@@ -258,7 +259,8 @@ _mesa_init_pixelstore( GLcontext *ctx )
    ctx->Unpack.ClientStorage = GL_FALSE;
    ctx->Unpack.Invert = GL_FALSE;
 #if FEATURE_EXT_pixel_buffer_object
-   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+   _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj,
+                                 ctx->Shared->NullBufferObj);
 #endif
 
    /*
@@ -278,6 +280,7 @@ _mesa_init_pixelstore( GLcontext *ctx )
    ctx->DefaultPacking.ClientStorage = GL_FALSE;
    ctx->DefaultPacking.Invert = GL_FALSE;
 #if FEATURE_EXT_pixel_buffer_object
-   ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+   _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj,
+                                 ctx->Shared->NullBufferObj);
 #endif
 }
index ae8dd2a83643abf79ec173c014d24c1e6a87177e..759883743dae4b3be18c7eac6d795dc3699286d1 100644 (file)
@@ -33,6 +33,7 @@
 #include "mtypes.h"
 #include "hash.h"
 #include "arrayobj.h"
+#include "bufferobj.h"
 #include "shared.h"
 #include "shader/program.h"
 #include "shader/shader_api.h"
@@ -92,6 +93,13 @@ _mesa_alloc_shared_state(GLcontext *ctx)
    shared->BufferObjects = _mesa_NewHashTable();
 #endif
 
+   /* Allocate the default buffer object and set refcount so high that
+    * it never gets deleted.
+    * XXX with recent/improved refcounting this may not longer be needed.
+    */
+   shared->NullBufferObj = _mesa_new_buffer_object(ctx, 0, 0);
+   shared->NullBufferObj->RefCount = 1000;
+
    shared->ArrayObjects = _mesa_NewHashTable();
 
    /* Create default texture objects */
@@ -341,6 +349,10 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
    _mesa_DeleteHashTable(shared->RenderBuffers);
 #endif
 
+#if FEATURE_ARB_vertex_buffer_object
+   _mesa_delete_buffer_object(ctx, shared->NullBufferObj);
+#endif
+
    /*
     * Free texture objects (after FBOs since some textures might have
     * been bound to FBOs).
index d6be3aa022e977fb9838bcef1848d11f9d8a3eb6..3578b713f61b7061fe0d0232bae504b864efe781 100644 (file)
@@ -60,7 +60,7 @@ _swrast_CopyColorTable( GLcontext *ctx,
 
    /* save PBO binding */
    bufferSave = ctx->Unpack.BufferObj;
-   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+   ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
 
    _mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
 
@@ -94,7 +94,7 @@ _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
 
    /* save PBO binding */
    bufferSave = ctx->Unpack.BufferObj;
-   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+   ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
 
    _mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
 
@@ -126,7 +126,7 @@ _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
 
    /* save PBO binding */
    bufferSave = ctx->Unpack.BufferObj;
-   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+   ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
 
    /* store as convolution filter */
    _mesa_ConvolutionFilter1D(target, internalFormat, width,
@@ -178,12 +178,12 @@ _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
    ctx->Unpack.SkipImages = 0;
    ctx->Unpack.SwapBytes = GL_FALSE;
    ctx->Unpack.LsbFirst = GL_FALSE;
-   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+   ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
    ctx->NewState |= _NEW_PACKUNPACK;
 
    /* save PBO binding */
    bufferSave = ctx->Unpack.BufferObj;
-   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+   ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
 
    _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
                              GL_RGBA, CHAN_TYPE, rgba);
index ca8190fd059fc637b014302efc8e5f976a8dc9bb..f193a4bf1e093f2daf747e7cf309241fe2ae7cfe 100644 (file)
@@ -28,6 +28,7 @@
 #include "main/imports.h"
 #include "main/mtypes.h"
 #include "main/api_arrayelt.h"
+#include "main/bufferobj.h"
 #include "math/m_eval.h"
 #include "vbo.h"
 #include "vbo_context.h"
@@ -81,7 +82,8 @@ static void init_legacy_currval(GLcontext *ctx)
       cl->Type = GL_FLOAT;
       cl->Format = GL_RGBA;
       cl->Ptr = (const void *)ctx->Current.Attrib[i];
-      cl->BufferObj = ctx->Array.NullBufferObj;
+      _mesa_reference_buffer_object(ctx, &cl->BufferObj,
+                                    ctx->Shared->NullBufferObj);
    }
 }
 
@@ -106,7 +108,8 @@ static void init_generic_currval(GLcontext *ctx)
       cl->Stride = 0;
       cl->StrideB = 0;
       cl->Enabled = 1;
-      cl->BufferObj = ctx->Array.NullBufferObj;
+      _mesa_reference_buffer_object(ctx, &cl->BufferObj,
+                                    ctx->Shared->NullBufferObj);
    }
 }
 
@@ -150,7 +153,7 @@ static void init_mat_currval(GLcontext *ctx)
       cl->Stride = 0;
       cl->StrideB = 0;
       cl->Enabled = 1;
-      cl->BufferObj = ctx->Array.NullBufferObj;
+      cl->BufferObj = ctx->Shared->NullBufferObj;
    }
 }
 
index 5d35ec9c1114fc3b136e7c280dff1db5ed4dad31..6871ee5cab11c1ad63463b517705da83eb7ee20a 100644 (file)
@@ -671,7 +671,7 @@ void vbo_use_buffer_objects(GLcontext *ctx)
    GLsizei size = VBO_VERT_BUFFER_SIZE;
 
    /* Make sure this func is only used once */
-   assert(exec->vtx.bufferobj == ctx->Array.NullBufferObj);
+   assert(exec->vtx.bufferobj == ctx->Shared->NullBufferObj);
    if (exec->vtx.buffer_map) {
       _mesa_align_free(exec->vtx.buffer_map);
       exec->vtx.buffer_map = NULL;
@@ -697,7 +697,7 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
     */
    _mesa_reference_buffer_object(ctx,
                                  &exec->vtx.bufferobj,
-                                 ctx->Array.NullBufferObj);
+                                 ctx->Shared->NullBufferObj);
 
    ASSERT(!exec->vtx.buffer_map);
    exec->vtx.buffer_map = (GLfloat *)ALIGN_MALLOC(VBO_VERT_BUFFER_SIZE, 64);
index dae778e741ee02f91fba9f42eab0eb28cf8489e6..ea87dede64627566052a5de2c0a0d18ca55a11f3 100644 (file)
@@ -161,7 +161,7 @@ void vbo_rebase_prims( GLcontext *ctx,
                                 GL_ELEMENT_ARRAY_BUFFER,
                                 ib->obj);
 
-      tmp_ib.obj = ctx->Array.NullBufferObj;
+      tmp_ib.obj = ctx->Shared->NullBufferObj;
       tmp_ib.ptr = tmp_indices;
       tmp_ib.count = ib->count;
       tmp_ib.type = ib->type;
index 56a9fafac4317e7b1bd33e3e0f6a7fe9a1ff5f49..2f6a1998eaab2bf83783ec519b60f2c77953ffd2 100644 (file)
@@ -459,7 +459,7 @@ replay_init( struct copy_context *copy )
       dst->Ptr = copy->dstbuf + offset;
       dst->Enabled = GL_TRUE;
       dst->Normalized = src->Normalized; 
-      dst->BufferObj = ctx->Array.NullBufferObj;
+      dst->BufferObj = ctx->Shared->NullBufferObj;
       dst->_MaxElement = copy->dstbuf_size; /* may be less! */
 
       offset += copy->varying[i].size;
@@ -479,7 +479,7 @@ replay_init( struct copy_context *copy )
     */
    copy->dstib.count = 0;      /* duplicates dstelt_nr */
    copy->dstib.type = GL_UNSIGNED_INT;
-   copy->dstib.obj = ctx->Array.NullBufferObj;
+   copy->dstib.obj = ctx->Shared->NullBufferObj;
    copy->dstib.ptr = copy->dstelt;
 }
 
index fbc856e93b0f8b5aa308d781e8a628edf3f1dbb0..3ed6b34fbf079686654597de86b619db66dd492f 100644 (file)
@@ -221,7 +221,7 @@ static void split_prims( struct split_context *split)
 
         ib.count = count;
         ib.type = GL_UNSIGNED_INT;
-        ib.obj = split->ctx->Array.NullBufferObj;
+        ib.obj = split->ctx->Shared->NullBufferObj;
         ib.ptr = elts;
            
         tmpprim = *prim;