mesa: add assertions for buffer reference counts
authorMarek Olšák <marek.olsak@amd.com>
Tue, 2 Mar 2021 05:56:29 +0000 (00:56 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 17 Mar 2021 22:43:01 +0000 (22:43 +0000)
Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9360>

src/mesa/main/bufferobj.c

index b2a36a3..6a8c80b 100644 (file)
@@ -514,6 +514,8 @@ _mesa_reference_buffer_object_(struct gl_context *ctx,
       /* Unreference the old buffer */
       struct gl_buffer_object *oldObj = *ptr;
 
+      assert(oldObj->RefCount >= 1);
+
       /* Count references only if the context doesn't own the buffer or if
        * ptr is a binding point shared by multiple contexts (such as a texture
        * buffer object being a buffer bound within a texture object).
@@ -1700,6 +1702,11 @@ delete_buffers(struct gl_context *ctx, GLsizei n, const GLuint *ids)
           */
          bufObj->DeletePending = GL_TRUE;
 
+         /* The GLuint ID holds one reference and the context that created
+          * the buffer holds the other one.
+          */
+         assert(p_atomic_read(&bufObj->RefCount) >= (bufObj->Ctx ? 2 : 1));
+
          if (bufObj->Ctx == ctx) {
             detach_ctx_from_buffer(ctx, bufObj);
          } else if (bufObj->Ctx) {