[Bf-blender-cvs] [20d9cd3a1fb] master: GPU: Add GPU_vertbuf_discard and GPU_BATCH_UNUSED

Clément Foucault noreply at git.blender.org
Tue May 14 11:01:38 CEST 2019


Commit: 20d9cd3a1fbd763dbe002e9baf2e3ba7fbb66f2f
Author: Clément Foucault
Date:   Mon May 13 17:27:35 2019 +0200
Branches: master
https://developer.blender.org/rB20d9cd3a1fbd763dbe002e9baf2e3ba7fbb66f2f

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.

===================================================================

M	source/blender/gpu/GPU_batch.h
M	source/blender/gpu/GPU_vertex_buffer.h
M	source/blender/gpu/intern/gpu_batch.c
M	source/blender/gpu/intern/gpu_vertex_buffer.c

===================================================================

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);
 }



More information about the Bf-blender-cvs mailing list