Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-08-10 02:35:59 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-08-13 15:20:23 +0300
commit00a3c297d254ee7acb375206d7ed0cf6f0ef9ef9 (patch)
treec914853b8b11672952b9fad4c4c0bf61c4d7fbbe /source
parent93165cbf478af8f5297a729fa05d387d6070b02d (diff)
GPUVertBuf: Add handle refcount
A handle refcount is here to avoid freeing of the GPUVertBuf datablock if it is still referenced somewhere else. This does not prevent deleting the actual data. This is to avoid too much zombie data usage. This is in order to avoid most hacks inside `draw_instance_data.c`.
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/GPU_vertex_buffer.h6
-rw-r--r--source/blender/gpu/intern/gpu_vertex_buffer.cc19
2 files changed, 24 insertions, 1 deletions
diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index 757255496e0..bd1019bb1f5 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -59,6 +59,8 @@ typedef struct GPUVertBuf {
uint32_t vbo_id;
/** Usage hint for GL optimisation. */
GPUUsageType usage;
+ /** This counter will only avoid freeing the GPUVertBuf, not the data. */
+ char handle_refcount;
/** Data has been touched and need to be reuploaded to GPU. */
bool dirty;
uchar *data; /* NULL indicates data in VRAM (unmapped) */
@@ -73,6 +75,10 @@ GPUVertBuf *GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageTyp
void GPU_vertbuf_clear(GPUVertBuf *verts);
void GPU_vertbuf_discard(GPUVertBuf *);
+/* Avoid GPUVertBuf datablock being free but not its data. */
+void GPU_vertbuf_handle_ref_add(GPUVertBuf *verts);
+void GPU_vertbuf_handle_ref_remove(GPUVertBuf *verts);
+
void GPU_vertbuf_init(GPUVertBuf *, GPUUsageType);
void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsageType);
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.cc b/source/blender/gpu/intern/gpu_vertex_buffer.cc
index 67ad8835b6a..debf9835c90 100644
--- a/source/blender/gpu/intern/gpu_vertex_buffer.cc
+++ b/source/blender/gpu/intern/gpu_vertex_buffer.cc
@@ -77,6 +77,7 @@ void GPU_vertbuf_init(GPUVertBuf *verts, GPUUsageType usage)
memset(verts, 0, sizeof(GPUVertBuf));
verts->usage = usage;
verts->dirty = true;
+ verts->handle_refcount = 1;
}
void GPU_vertbuf_init_with_format_ex(GPUVertBuf *verts,
@@ -137,7 +138,23 @@ void GPU_vertbuf_clear(GPUVertBuf *verts)
void GPU_vertbuf_discard(GPUVertBuf *verts)
{
GPU_vertbuf_clear(verts);
- MEM_freeN(verts);
+ GPU_vertbuf_handle_ref_remove(verts);
+}
+
+void GPU_vertbuf_handle_ref_add(GPUVertBuf *verts)
+{
+ verts->handle_refcount++;
+}
+
+void GPU_vertbuf_handle_ref_remove(GPUVertBuf *verts)
+{
+ BLI_assert(verts->handle_refcount > 0);
+ verts->handle_refcount--;
+ if (verts->handle_refcount == 0) {
+ /* Should already have been cleared. */
+ BLI_assert(verts->vbo_id == 0 && verts->data == NULL);
+ MEM_freeN(verts);
+ }
}
uint GPU_vertbuf_size_get(const GPUVertBuf *verts)