#include "varray.h"
#include "main/dispatch.h"
#include "util/bitscan.h"
+#include "util/u_atomic.h"
const GLubyte
/* Unreference the old array object */
struct gl_vertex_array_object *oldObj = *ptr;
- assert(oldObj->RefCount > 0);
- oldObj->RefCount--;
+ bool deleteFlag;
+ if (oldObj->SharedAndImmutable) {
+ deleteFlag = p_atomic_dec_zero(&oldObj->RefCount);
+ } else {
+ assert(oldObj->RefCount > 0);
+ oldObj->RefCount--;
+ deleteFlag = (oldObj->RefCount == 0);
+ }
- if (oldObj->RefCount == 0)
+ if (deleteFlag)
_mesa_delete_vao(ctx, oldObj);
*ptr = NULL;
if (vao) {
/* reference new array object */
- assert(vao->RefCount > 0);
+ if (vao->SharedAndImmutable) {
+ p_atomic_inc(&vao->RefCount);
+ } else {
+ assert(vao->RefCount > 0);
+ vao->RefCount++;
+ }
- vao->RefCount++;
*ptr = vao;
}
}
vao->Name = name;
vao->RefCount = 1;
+ vao->SharedAndImmutable = false;
/* Init the individual arrays */
for (i = 0; i < ARRAY_SIZE(vao->VertexAttrib); i++) {
{
GLbitfield arrays = vao->NewArrays;
+ /* Make sure we do not run into problems with shared objects */
+ assert(!vao->SharedAndImmutable || vao->NewArrays == 0);
+
while (arrays) {
const int attrib = u_bit_scan(&arrays);
struct gl_vertex_array *array = &vao->_VertexArray[attrib];
}
+void
+_mesa_set_vao_immutable(struct gl_context *ctx,
+ struct gl_vertex_array_object *vao)
+{
+ _mesa_update_vao_derived_arrays(ctx, vao);
+ vao->NewArrays = 0;
+ vao->SharedAndImmutable = true;
+}
+
+
bool
_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao)
{
_mesa_update_vao_derived_arrays(struct gl_context *ctx,
struct gl_vertex_array_object *vao);
+
+/**
+ * Mark the vao as shared and immutable, do remaining updates.
+ */
+extern void
+_mesa_set_vao_immutable(struct gl_context *ctx,
+ struct gl_vertex_array_object *vao);
+
+
/* Returns true if all varying arrays reside in vbos */
extern bool
_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);