summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2018-02-03 15:22:33 +0100
committerMathias Fröhlich <[email protected]>2018-02-23 05:34:11 +0100
commit2f351408467a1d2e46927b8df0d3047b67ae2623 (patch)
tree4f3ba35429173ef3521bc7d2530a7ec9021ddc50 /src/mesa/main
parent8a3a4b6fae75905088ce4fcb42fc50cb09763a10 (diff)
mesa: Use atomics for shared VAO reference counts.
VAOs will be used in the next change as immutable object across multiple contexts. Only reference counting may write concurrently on the VAO. So, make the reference count thread safe for those and only those VAO objects. v3: Use bool/true/false for gl_vertex_array_object::SharedAndImmutable. Signed-off-by: Mathias Fröhlich <[email protected]> Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/arrayobj.c35
-rw-r--r--src/mesa/main/arrayobj.h9
-rw-r--r--src/mesa/main/mtypes.h7
3 files changed, 46 insertions, 5 deletions
diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index cf9c5d7ecc7..2526404fda3 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -53,6 +53,7 @@
#include "varray.h"
#include "main/dispatch.h"
#include "util/bitscan.h"
+#include "util/u_atomic.h"
const GLubyte
@@ -331,10 +332,16 @@ _mesa_reference_vao_(struct gl_context *ctx,
/* 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;
@@ -343,9 +350,13 @@ _mesa_reference_vao_(struct gl_context *ctx,
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;
}
}
@@ -407,6 +418,7 @@ _mesa_initialize_vao(struct gl_context *ctx,
vao->Name = name;
vao->RefCount = 1;
+ vao->SharedAndImmutable = false;
/* Init the individual arrays */
for (i = 0; i < ARRAY_SIZE(vao->VertexAttrib); i++) {
@@ -452,6 +464,9 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
{
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];
@@ -465,6 +480,16 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
}
+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)
{
diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
index 5de74505bb8..8da5c9ffe01 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -81,6 +81,15 @@ extern void
_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);
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index bdecd422a9a..15f39cbacc3 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1608,6 +1608,13 @@ struct gl_vertex_array_object
GLboolean EverBound;
/**
+ * Marked to true if the object is shared between contexts and immutable.
+ * Then reference counting is done using atomics and thread safe.
+ * Is used for dlist VAOs.
+ */
+ bool SharedAndImmutable;
+
+ /**
* Derived vertex attribute arrays
*
* This is a legacy data structure created from gl_array_attributes and