mesa: don't ever set NullBufferObj in gl_vertex_array_binding
authorMarek Olšák <marek.olsak@amd.com>
Sun, 22 Mar 2020 01:36:28 +0000 (21:36 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 6 Apr 2020 14:28:53 +0000 (10:28 -0400)
This improves performance by 5% in the game "torcs", FPS: 98.83 -> 103.73

It does a lot of glPush/PopClientAttrib, which exacerbates the overhead
of setting NullBufferObj.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4466>

src/mesa/drivers/dri/nouveau/nouveau_array.c
src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c
src/mesa/main/api_arrayelt.c
src/mesa/main/arrayobj.c
src/mesa/main/bufferobj.c
src/mesa/main/draw.c
src/mesa/main/get.c
src/mesa/main/varray.c
src/mesa/tnl/t_split_copy.c
src/mesa/vbo/vbo_context.c
src/mesa/vbo/vbo_exec_api.c

index b77932f9c9c8fef929c4975138bbd7726d66354d..114e98d9fa2190349ab10024384e2997f933abd9 100644 (file)
@@ -109,26 +109,29 @@ nouveau_init_array(struct nouveau_array *a, int attr, int stride,
        a->type = type;
        a->buf = NULL;
 
-       if (obj) {
-               if (nouveau_bufferobj_hw(obj)) {
-                       struct nouveau_bufferobj *nbo =
-                               to_nouveau_bufferobj(obj);
+       if (nouveau_bufferobj_hw(obj)) {
+               struct nouveau_bufferobj *nbo =
+                       to_nouveau_bufferobj(obj);
 
-                       nouveau_bo_ref(nbo->bo, &a->bo);
-                       a->offset = (intptr_t)ptr;
+               nouveau_bo_ref(nbo->bo, &a->bo);
+               a->offset = (intptr_t)ptr;
 
-                       if (map) {
-                               nouveau_bo_map(a->bo, NOUVEAU_BO_RD, client);
-                               a->buf = a->bo->map + a->offset;
-                       }
+               if (map) {
+                       nouveau_bo_map(a->bo, NOUVEAU_BO_RD, client);
+                       a->buf = a->bo->map + a->offset;
+               }
 
-               } else {
-                       nouveau_bo_ref(NULL, &a->bo);
-                       a->offset = 0;
+       } else {
+               nouveau_bo_ref(NULL, &a->bo);
+               a->offset = 0;
 
-                       if (map)
+               if (map) {
+                       if (obj) {
                                a->buf = ADD_POINTERS(
                                        nouveau_bufferobj_sys(obj), ptr);
+                       } else {
+                               a->buf = ptr;
+                       }
                }
        }
 
index f516bd3e4ab8519c4c5a77d21e365440d0deea87..d7e6c34c1e24514ad04e397fad3c3092224fe88c 100644 (file)
@@ -343,8 +343,13 @@ vbo_bind_vertices(struct gl_context *ctx, const struct tnl_vertex_array *arrays,
 
                } else {
                        int n = max_index - min_index + 1;
-                       char *sp = (char *)ADD_POINTERS(
+                       const char *sp;
+                        if (obj) {
+                           sp = (char *)ADD_POINTERS(
                                nouveau_bufferobj_sys(obj), p) + delta;
+                        } else {
+                           sp = p + delta;
+                        }
                        char *dp  = nouveau_get_scratch(ctx, n * a->stride,
                                                        &bo[i], &offset[i]);
 
index 022a1285c26577f65eb0f14d71df44b547e668d3..0dae3ef7740fc2fdba7416c5e09212ab39814bd6 100644 (file)
@@ -1413,11 +1413,14 @@ attrib_src(const struct gl_vertex_array_object *vao,
 {
    const struct gl_vertex_buffer_binding *binding =
       &vao->BufferBinding[array->BufferBindingIndex];
-   const GLubyte *src
-      = ADD_POINTERS(binding->BufferObj->Mappings[MAP_INTERNAL].Pointer,
-                     _mesa_vertex_attrib_address(array, binding))
-      + elt * binding->Stride;
-   return src;
+   const GLubyte *src = _mesa_vertex_attrib_address(array, binding);
+
+   if (_mesa_is_bufferobj(binding->BufferObj)) {
+      src = ADD_POINTERS(binding->BufferObj->Mappings[MAP_INTERNAL].Pointer,
+                         src);
+   }
+
+   return src + elt * binding->Stride;
 }
 
 
index 2c2c164123d62307d2ea4538c3afb0748e8a13f9..c05627b05b98bc5bf823977b1041b54b8127ea09 100644 (file)
@@ -398,12 +398,6 @@ _mesa_initialize_vao(struct gl_context *ctx,
    vao->Name = name;
    _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj,
                                  ctx->Shared->NullBufferObj);
-
-   /* Vertex array buffers */
-   for (unsigned i = 0; i < ARRAY_SIZE(vao->BufferBinding); i++) {
-      _mesa_reference_buffer_object(ctx, &vao->BufferBinding[i].BufferObj,
-                                    ctx->Shared->NullBufferObj);
-   }
 }
 
 
index 881a9d3e00e0488434c15f761f97981ff5bd0894..9c4630bca12c5daa57c0da39bfba6b69631d33bf 100644 (file)
@@ -1171,7 +1171,7 @@ unbind(struct gl_context *ctx,
        struct gl_buffer_object *obj)
 {
    if (vao->BufferBinding[index].BufferObj == obj) {
-      _mesa_bind_vertex_buffer(ctx, vao, index, ctx->Shared->NullBufferObj,
+      _mesa_bind_vertex_buffer(ctx, vao, index, NULL,
                                vao->BufferBinding[index].Offset,
                                vao->BufferBinding[index].Stride);
    }
index e856d9c5ef36f30ae1ac81440b011d733b5f0805..5bb254e00d2621191b064096518ecca22afca963 100644 (file)
@@ -90,7 +90,7 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
                          array->Format.Type, array->Format.Size,
                          binding->Stride);
                   printf("  Address/offset %p in Buffer Object %u\n",
-                         array->Ptr, bo->Name);
+                         array->Ptr, bo ? bo->Name : 0);
                   f[k] = 1.0F;  /* XXX replace the bad value! */
                }
                /*assert(!IS_INF_OR_NAN(f[k])); */
@@ -255,7 +255,7 @@ print_draw_arrays(struct gl_context *ctx,
              "ptr %p  Bufobj %u\n",
              gl_vert_attrib_name((gl_vert_attrib) i),
              array->Format.Size, binding->Stride,
-             array->Ptr, bufObj->Name);
+             array->Ptr, bufObj ? bufObj->Name : 0);
 
       if (_mesa_is_bufferobj(bufObj)) {
          GLubyte *p = bufObj->Mappings[MAP_INTERNAL].Pointer;
index 8325786a396e08df8b20deeb114c57664b58c8dc..cbfe9c8b309b3b77e07b46a439923e5e619e2d22 100644 (file)
@@ -690,7 +690,7 @@ static const int extra_EXT_disjoint_timer_query[] = {
 static void
 find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
 {
-   struct gl_buffer_object **buffer_obj;
+   struct gl_buffer_object **buffer_obj, *buf;
    struct gl_array_attributes *array;
    GLuint unit, *p;
 
@@ -1006,14 +1006,14 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
    case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
       buffer_obj = (struct gl_buffer_object **)
          ((char *) ctx->Array.VAO + d->offset);
-      v->value_int = (*buffer_obj)->Name;
+      v->value_int = (*buffer_obj) ? (*buffer_obj)->Name : 0;
       break;
    case GL_ARRAY_BUFFER_BINDING_ARB:
       v->value_int = ctx->Array.ArrayBufferObj->Name;
       break;
    case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
-      v->value_int =
-         ctx->Array.VAO->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj->Name;
+      buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj;
+      v->value_int = buf ? buf->Name : 0;
       break;
    case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
       v->value_int = ctx->Array.VAO->IndexBufferObj->Name;
@@ -1079,7 +1079,8 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
          ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
       break;
    case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
-      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_POINT_SIZE].BufferObj->Name;
+      buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_POINT_SIZE].BufferObj;
+      v->value_int = buf ? buf->Name : 0;
       break;
 
    case GL_FOG_COLOR:
@@ -2394,6 +2395,7 @@ static enum value_type
 find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
 {
    GET_CURRENT_CONTEXT(ctx);
+   struct gl_buffer_object *buf;
 
    switch (pname) {
 
@@ -2642,7 +2644,8 @@ find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
          goto invalid_enum;
       if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
          goto invalid_value;
-      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
+      buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj;
+      v->value_int = buf ? buf->Name : 0;
       return TYPE_INT;
 
    /* ARB_shader_image_load_store */
index df63e556a36d8ff1775eb16525d59b987f123a22..ec5e71917613b12fcf8616c09e2cc7f7f56ff770 100644 (file)
@@ -204,6 +204,8 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
    assert(!vao->SharedAndImmutable);
    struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
 
+   assert(vbo != ctx->Shared->NullBufferObj);
+
    if (ctx->Const.VertexBufferOffsetIsInt32 && (int)offset < 0 &&
        _mesa_is_bufferobj(vbo)) {
       /* The offset will be interpreted as a signed int, so make sure
@@ -899,6 +901,10 @@ update_array(struct gl_context *ctx,
    assert((vao->NewArrays | ~vao->Enabled) & VERT_BIT(attrib));
    array->Ptr = ptr;
 
+   /* TODO: remove this hack by not using NullBufferObj in callers */
+   if (obj == ctx->Shared->NullBufferObj)
+      obj = NULL;
+
    /* Update the vertex buffer binding */
    GLsizei effectiveStride = stride != 0 ?
       stride : array->Format._ElementSize;
@@ -932,7 +938,7 @@ _lookup_vao_and_vbo_dsa(struct gl_context *ctx,
          return false;
       }
    } else {
-      *vbo = ctx->Shared->NullBufferObj;
+      *vbo = NULL;
    }
 
    return true;
@@ -2065,6 +2071,7 @@ get_vertex_array_attrib(struct gl_context *ctx,
                         const char *caller)
 {
    const struct gl_array_attributes *array;
+   struct gl_buffer_object *buf;
 
    if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
@@ -2087,7 +2094,8 @@ get_vertex_array_attrib(struct gl_context *ctx,
    case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
       return array->Format.Normalized;
    case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
-      return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name;
+      buf = vao->BufferBinding[array->BufferBindingIndex].BufferObj;
+      return buf ? buf->Name : 0;
    case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
       if ((_mesa_is_desktop_gl(ctx)
            && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
@@ -2329,6 +2337,7 @@ _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_vertex_array_object *vao;
+   struct gl_buffer_object *buf;
 
    /* The ARB_direct_state_access specification says:
     *
@@ -2376,7 +2385,8 @@ _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
       params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
       break;
    case GL_VERTEX_BINDING_BUFFER:
-      params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
+      buf = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj;
+      params[0] = buf ? buf->Name : 0;
       break;
    default:
       params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
@@ -2895,9 +2905,11 @@ vertex_array_vertex_buffer(struct gl_context *ctx,
                            GLsizei stride, bool no_error, const char *func)
 {
    struct gl_buffer_object *vbo;
-   if (buffer ==
-       vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
-      vbo = vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
+   struct gl_buffer_object *current_buf =
+      vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
+
+   if (current_buf && buffer == current_buf->Name) {
+      vbo = current_buf;
    } else if (buffer != 0) {
       vbo = _mesa_lookup_bufferobj(ctx, buffer);
 
@@ -2923,7 +2935,7 @@ vertex_array_vertex_buffer(struct gl_context *ctx,
        *    "If <buffer> is zero, any buffer object attached to this
        *     bindpoint is detached."
        */
-      vbo = ctx->Shared->NullBufferObj;
+      vbo = NULL;
    }
 
    _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
@@ -3090,11 +3102,9 @@ vertex_array_vertex_buffers(struct gl_context *ctx,
        *     associated with the binding points are set to default values,
        *     ignoring <offsets> and <strides>."
        */
-      struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
-
       for (i = 0; i < count; i++)
          _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
-                                  vbo, 0, 16);
+                                  NULL, 0, 16);
 
       return;
    }
@@ -3156,15 +3166,21 @@ vertex_array_vertex_buffers(struct gl_context *ctx,
          struct gl_vertex_buffer_binding *binding =
             &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
 
-         if (buffers[i] == binding->BufferObj->Name)
+         if (buffers[i] == 0)
+            vbo = NULL;
+         else if (binding->BufferObj && binding->BufferObj->Name == buffers[i])
             vbo = binding->BufferObj;
-         else
+         else {
             vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
+            if (!vbo)
+               continue;
 
-         if (!vbo)
-            continue;
+            /* TODO: remove this hack */
+            if (vbo == ctx->Shared->NullBufferObj)
+               vbo = NULL;
+         }
       } else {
-         vbo = ctx->Shared->NullBufferObj;
+         vbo = NULL;
       }
 
       _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
@@ -3783,8 +3799,8 @@ _mesa_print_arrays(struct gl_context *ctx)
               gl_vert_attrib_name((gl_vert_attrib)i),
               array->Ptr, _mesa_enum_to_string(array->Format.Type),
               array->Format.Size,
-              array->Format._ElementSize, binding->Stride, bo->Name,
-              (unsigned long) bo->Size);
+              array->Format._ElementSize, binding->Stride, bo ? bo->Name : 0,
+              (unsigned long) bo ? bo->Size : 0);
    }
 }
 
@@ -3903,6 +3919,7 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_vertex_array_object* vao;
+   struct gl_buffer_object *buf;
    void* ptr;
 
    vao = _mesa_lookup_vao_err(ctx, vaobj, true,
@@ -3932,7 +3949,8 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
          *param = vao->VertexAttrib[VERT_ATTRIB_POS].Stride;
          break;
       case GL_VERTEX_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_POS].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_POS].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       case GL_COLOR_ARRAY_SIZE:
          *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Format.Size;
@@ -3944,13 +3962,15 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
          *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Stride;
          break;
       case GL_COLOR_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_COLOR0].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_COLOR0].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       case GL_EDGE_FLAG_ARRAY_STRIDE:
          *param = vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Stride;
          break;
       case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_EDGEFLAG].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_EDGEFLAG].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       case GL_INDEX_ARRAY_TYPE:
          *param = vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Format.Type;
@@ -3959,7 +3979,8 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
          *param = vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Stride;
          break;
       case GL_INDEX_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_COLOR_INDEX].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_COLOR_INDEX].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       case GL_NORMAL_ARRAY_TYPE:
          *param = vao->VertexAttrib[VERT_ATTRIB_NORMAL].Format.Type;
@@ -3968,7 +3989,8 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
          *param = vao->VertexAttrib[VERT_ATTRIB_NORMAL].Stride;
          break;
       case GL_NORMAL_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_NORMAL].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_NORMAL].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       case GL_TEXTURE_COORD_ARRAY_SIZE:
          *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Format.Size;
@@ -3980,7 +4002,8 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
          *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Stride;
          break;
       case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       case GL_FOG_COORD_ARRAY_TYPE:
          *param = vao->VertexAttrib[VERT_ATTRIB_FOG].Format.Type;
@@ -3989,7 +4012,8 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
          *param = vao->VertexAttrib[VERT_ATTRIB_FOG].Stride;
          break;
       case GL_FOG_COORD_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_FOG].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_FOG].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       case GL_SECONDARY_COLOR_ARRAY_SIZE:
          *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Format.Size;
@@ -4001,7 +4025,8 @@ _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
          *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Stride;
          break;
       case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_COLOR1].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_COLOR1].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
 
       /* Tokens using IsEnabled */
@@ -4089,6 +4114,7 @@ _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj, GLuint index, GLenum pname, GLin
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_vertex_array_object* vao;
+   struct gl_buffer_object *buf;
 
    vao = _mesa_lookup_vao_err(ctx, vaobj, true,
                               "glGetVertexArrayIntegeri_vEXT");
@@ -4120,7 +4146,8 @@ _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj, GLuint index, GLenum pname, GLin
          *param = vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Stride;
          break;
       case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
-         *param = vao->BufferBinding[VERT_ATTRIB_TEX(index)].BufferObj->Name;
+         buf = vao->BufferBinding[VERT_ATTRIB_TEX(index)].BufferObj;
+         *param = buf ? buf->Name : 0;
          break;
       default:
          *param = get_vertex_array_attrib(ctx, vao, index, pname, "glGetVertexArrayIntegeri_vEXT");
index 57ff5bf0e038371b1112e74adb05aab300928ef1..5b300e935538e113921a311816f35b670debc51b 100644 (file)
@@ -455,13 +455,17 @@ replay_init(struct copy_context *copy)
          copy->varying[j].size = attrib->Format._ElementSize;
          copy->vertex_size += attrib->Format._ElementSize;
 
-         if (_mesa_is_bufferobj(vbo) &&
-             !_mesa_bufferobj_mapped(vbo, MAP_INTERNAL))
-            ctx->Driver.MapBufferRange(ctx, 0, vbo->Size, GL_MAP_READ_BIT, vbo,
-                                       MAP_INTERNAL);
+         if (_mesa_is_bufferobj(vbo)) {
+            if (!_mesa_bufferobj_mapped(vbo, MAP_INTERNAL)) {
+               ctx->Driver.MapBufferRange(ctx, 0, vbo->Size, GL_MAP_READ_BIT, vbo,
+                                          MAP_INTERNAL);
+            }
 
-         copy->varying[j].src_ptr =
-               ADD_POINTERS(vbo->Mappings[MAP_INTERNAL].Pointer, ptr);
+            copy->varying[j].src_ptr =
+                  ADD_POINTERS(vbo->Mappings[MAP_INTERNAL].Pointer, ptr);
+         } else {
+            copy->varying[j].src_ptr = ptr;
+         }
 
          copy->dstarray[i].VertexAttrib = &copy->varying[j].dstattribs;
          copy->dstarray[i].BufferBinding = &copy->varying[j].dstbinding;
@@ -532,7 +536,7 @@ replay_init(struct copy_context *copy)
       dstattr->Format = srcattr->Format;
       dstattr->Ptr = copy->dstbuf + offset;
       dstbind->Stride = copy->vertex_size;
-      dstbind->BufferObj = ctx->Shared->NullBufferObj;
+      dstbind->BufferObj = NULL;
       dst->BufferBinding = dstbind;
       dst->VertexAttrib = dstattr;
 
index ac8f9973f98f19b33b6749d38c5d1e7755510b4c..ad23655e6f0a9f0113b1e8fe546be0b3d0c5f958 100644 (file)
@@ -168,8 +168,7 @@ _vbo_CreateContext(struct gl_context *ctx, bool use_buffer_objects)
    vbo->binding.Offset = 0;
    vbo->binding.Stride = 0;
    vbo->binding.InstanceDivisor = 0;
-   _mesa_reference_buffer_object(ctx, &vbo->binding.BufferObj,
-                                 ctx->Shared->NullBufferObj);
+
    init_legacy_currval(ctx);
    init_generic_currval(ctx);
    init_mat_currval(ctx);
@@ -202,7 +201,6 @@ _vbo_DestroyContext(struct gl_context *ctx)
    struct vbo_context *vbo = vbo_context(ctx);
 
    if (vbo) {
-
       _mesa_reference_buffer_object(ctx, &vbo->binding.BufferObj, NULL);
 
       vbo_exec_destroy(ctx);
index 53269f18d3bebf9ffde96068321f2e3f0b4602ac..74be1c574a8eba55520030e103c583f06793404d 100644 (file)
@@ -1013,10 +1013,7 @@ vbo_exec_vtx_init(struct vbo_exec_context *exec, bool use_buffer_objects)
       assert(exec->vtx.buffer_ptr);
    } else {
       /* Use allocated memory for immediate mode. */
-      _mesa_reference_buffer_object(ctx,
-                                    &exec->vtx.bufferobj,
-                                    ctx->Shared->NullBufferObj);
-
+      exec->vtx.bufferobj = NULL;
       exec->vtx.buffer_map =
          _mesa_align_malloc(ctx->Const.glBeginEndBufferSize, 64);
       exec->vtx.buffer_ptr = exec->vtx.buffer_map;
@@ -1039,9 +1036,9 @@ vbo_exec_vtx_destroy(struct vbo_exec_context *exec)
    /* True VBOs should already be unmapped
     */
    if (exec->vtx.buffer_map) {
-      assert(exec->vtx.bufferobj->Name == 0 ||
+      assert(!exec->vtx.bufferobj ||
              exec->vtx.bufferobj->Name == IMM_BUFFER_NAME);
-      if (exec->vtx.bufferobj->Name == 0) {
+      if (!exec->vtx.bufferobj) {
          _mesa_align_free(exec->vtx.buffer_map);
          exec->vtx.buffer_map = NULL;
          exec->vtx.buffer_ptr = NULL;
@@ -1050,7 +1047,8 @@ vbo_exec_vtx_destroy(struct vbo_exec_context *exec)
 
    /* Free the vertex buffer.  Unmap first if needed.
     */
-   if (_mesa_bufferobj_mapped(exec->vtx.bufferobj, MAP_INTERNAL)) {
+   if (exec->vtx.bufferobj &&
+       _mesa_bufferobj_mapped(exec->vtx.bufferobj, MAP_INTERNAL)) {
       ctx->Driver.UnmapBuffer(ctx, exec->vtx.bufferobj, MAP_INTERNAL);
    }
    _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);