From 20d9cd3a1fbd763dbe002e9baf2e3ba7fbb66f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 13 May 2019 17:27:35 +0200 Subject: GPU: Add GPU_vertbuf_discard and GPU_BATCH_UNUSED GPU_vertbuf_discard to clear buffer containers in place. GPU_BATCH_UNUSED to tag batch that are cleared and not immediatly usable. --- source/blender/gpu/GPU_batch.h | 1 + source/blender/gpu/GPU_vertex_buffer.h | 1 + source/blender/gpu/intern/gpu_batch.c | 1 + source/blender/gpu/intern/gpu_vertex_buffer.c | 11 +++++++++-- 4 files changed, 12 insertions(+), 2 deletions(-) (limited to 'source/blender/gpu') diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h index 856148563f2..783bfb0b1f0 100644 --- a/source/blender/gpu/GPU_batch.h +++ b/source/blender/gpu/GPU_batch.h @@ -33,6 +33,7 @@ #include "GPU_shader.h" typedef enum { + GPU_BATCH_UNUSED, GPU_BATCH_READY_TO_FORMAT, GPU_BATCH_READY_TO_BUILD, GPU_BATCH_BUILDING, diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h index 6d88460964d..a5a5e3d4296 100644 --- a/source/blender/gpu/GPU_vertex_buffer.h +++ b/source/blender/gpu/GPU_vertex_buffer.h @@ -62,6 +62,7 @@ GPUVertBuf *GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageTyp #define GPU_vertbuf_create_with_format(format) \ GPU_vertbuf_create_with_format_ex(format, GPU_USAGE_STATIC) +void GPU_vertbuf_clear(GPUVertBuf *verts); void GPU_vertbuf_discard(GPUVertBuf *); void GPU_vertbuf_init(GPUVertBuf *, GPUUsageType); diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c index f179f9ef22c..010f57bf5f8 100644 --- a/source/blender/gpu/intern/gpu_batch.c +++ b/source/blender/gpu/intern/gpu_batch.c @@ -139,6 +139,7 @@ void GPU_batch_clear(GPUBatch *batch) } } GPU_batch_vao_cache_clear(batch); + batch->phase = GPU_BATCH_UNUSED; } void GPU_batch_discard(GPUBatch *batch) diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.c b/source/blender/gpu/intern/gpu_vertex_buffer.c index f9823c18723..2f854fe03ea 100644 --- a/source/blender/gpu/intern/gpu_vertex_buffer.c +++ b/source/blender/gpu/intern/gpu_vertex_buffer.c @@ -85,17 +85,24 @@ void GPU_vertbuf_init_with_format_ex(GPUVertBuf *verts, } } -void GPU_vertbuf_discard(GPUVertBuf *verts) +/** Same as discard but does not free. */ +void GPU_vertbuf_clear(GPUVertBuf *verts) { if (verts->vbo_id) { GPU_buf_free(verts->vbo_id); + verts->vbo_id = 0; #if VRAM_USAGE vbo_memory_usage -= GPU_vertbuf_size_get(verts); #endif } if (verts->data) { - MEM_freeN(verts->data); + MEM_SAFE_FREE(verts->data); } +} + +void GPU_vertbuf_discard(GPUVertBuf *verts) +{ + GPU_vertbuf_clear(verts); MEM_freeN(verts); } -- cgit v1.2.3