[Bf-blender-cvs] [520a7ca2f38] tmp-batch-cache-cleanup: Mesh Batch Cache: Refactor start

Clément Foucault noreply at git.blender.org
Mon Jul 22 12:52:48 CEST 2019


Commit: 520a7ca2f3821ac9555c33de28f2c92607a5cc04
Author: Clément Foucault
Date:   Thu Jul 11 14:34:36 2019 +0200
Branches: tmp-batch-cache-cleanup
https://developer.blender.org/rB520a7ca2f3821ac9555c33de28f2c92607a5cc04

Mesh Batch Cache: Refactor start

- Put placeholders vbos/ibos
- Restructure the buffers cache : One cache for final mesh and one for the
  edit mesh cage.

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

M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/modes/edit_mesh_mode.c

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

diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 4dc58972ce6..ea0b8f406dd 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -143,7 +143,7 @@ struct GPUBatch *DRW_mesh_batch_cache_get_surface_weights(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_triangles(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_vertices(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_edges(struct Mesh *me);
-struct GPUBatch *DRW_mesh_batch_cache_get_edit_lnors(struct Mesh *me);
+struct GPUBatch *DRW_mesh_batch_cache_get_edit_vnors(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_facedots(struct Mesh *me);
 /* edit-mesh selection */
 struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(struct Mesh *me);
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 306031809d1..f244cf40e79 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -1969,7 +1969,7 @@ typedef enum DRWBatchFlag {
   MBC_EDIT_TRIANGLES = (1 << 2),
   MBC_EDIT_VERTICES = (1 << 3),
   MBC_EDIT_EDGES = (1 << 4),
-  MBC_EDIT_LNOR = (1 << 5),
+  MBC_EDIT_VNOR = (1 << 5),
   MBC_EDIT_FACEDOTS = (1 << 6),
   MBC_EDIT_MESH_ANALYSIS = (1 << 7),
   MBC_EDITUV_FACES_STRECH_AREA = (1 << 8),
@@ -1996,69 +1996,61 @@ typedef enum DRWBatchFlag {
   (MBC_EDITUV_FACES_STRECH_AREA | MBC_EDITUV_FACES_STRECH_ANGLE | MBC_EDITUV_FACES | \
    MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS)
 
-typedef struct MeshBatchCache {
-  /* In order buffers: All verts only specified once
-   * or once per loop. To be used with a GPUIndexBuf. */
-  struct {
-    /* Vertex data. */
-    GPUVertBuf *pos_nor;
-    GPUVertBuf *weights;
-    /* Loop data. */
-    GPUVertBuf *loop_pos_nor;
-    GPUVertBuf *loop_uv_tan;
-    GPUVertBuf *loop_vcol;
-    GPUVertBuf *loop_edge_fac;
-    GPUVertBuf *loop_orco;
-  } ordered;
-
-  /* Edit Mesh Data:
-   * Edit cage can be different from final mesh so vertex count
-   * might differ. */
+#define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc) \
+  for (MeshBufferCache *mbc = &batch_cache->final; \
+       mbc == &batch_cache->final || mbc == &batch_cache->cage; \
+       mbc = (mbc == &batch_cache->final) ? &batch_cache->cage : NULL)
+
+typedef struct MeshBufferCache {
+  /* Every VBO below contains at least enough
+   * data for every loops in the mesh (except facedots).
+   * For some VBOs, it extends to (in this exact order) :
+   * loops + loose_edges*2 + loose_verts */
   struct {
-    /* TODO(fclem): Reuse ordered.loop_pos_nor and maybe even
-     * ordered.loop_uv_tan when cage match final mesh. */
-    GPUVertBuf *loop_pos_nor;
-    GPUVertBuf *loop_data;
-    GPUVertBuf *loop_lnor;
+    GPUVertBuf *pos_nor;  /* extend */
+    GPUVertBuf *edge_fac; /* extend */
+    GPUVertBuf *weights;  /* extend */
+    GPUVertBuf *uv_tan;
+    GPUVertBuf *vcol;
+    GPUVertBuf *orco;
+    /* Only for edit mode. */
+    GPUVertBuf *vnor; /* extend */
+    GPUVertBuf *data; /* extend */
+    GPUVertBuf *data_edituv;
+    GPUVertBuf *stretch_area;
+    GPUVertBuf *stretch_angle;
+    GPUVertBuf *mesh_analysis;
     GPUVertBuf *facedots_pos_nor_data;
-    GPUVertBuf *loop_mesh_analysis;
-    /* UV data without modifier applied.
-     * Vertex count is always the one of the cage. */
-    GPUVertBuf *loop_uv;
-    GPUVertBuf *loop_uv_data;
-    GPUVertBuf *loop_stretch_angle;
-    GPUVertBuf *loop_stretch_area;
     GPUVertBuf *facedots_uv;
-    GPUVertBuf *facedots_uv_data;
+    GPUVertBuf *facedots_data_edituv;
     /* Selection */
-    GPUVertBuf *loop_vert_idx;
-    GPUVertBuf *loop_edge_idx;
-    GPUVertBuf *loop_face_idx;
+    GPUVertBuf *vert_idx; /* extend */
+    GPUVertBuf *edge_idx; /* extend */
+    GPUVertBuf *face_idx;
     GPUVertBuf *facedots_idx;
-  } edit;
-
+  } vbo;
   /* Index Buffers:
    * Only need to be updated when topology changes. */
   struct {
-    /* Indices to verts. */
-    GPUIndexBuf *surf_tris;
-    GPUIndexBuf *edges_lines;
-    GPUIndexBuf *edges_adj_lines;
-    GPUIndexBuf *loose_edges_lines;
     /* Indices to vloops. */
-    GPUIndexBuf *loops_tris;
-    GPUIndexBuf *loops_lines;
-    GPUIndexBuf *loops_lines_paint_mask;
-    GPUIndexBuf *loops_line_strips;
-    /* Edit mode. */
-    GPUIndexBuf *edit_loops_points; /* verts */
-    GPUIndexBuf *edit_loops_lines;  /* edges */
-    GPUIndexBuf *edit_loops_tris;   /* faces */
-    /* Edit UVs */
-    GPUIndexBuf *edituv_loops_points;      /* verts */
-    GPUIndexBuf *edituv_loops_line_strips; /* edges */
-    GPUIndexBuf *edituv_loops_tri_fans;    /* faces */
+    GPUIndexBuf *tris; /* Ordered per material. */
+    GPUIndexBuf *lines;
+    GPUIndexBuf *points;
+    GPUIndexBuf *facedots;
+    /* 3D overlays. */
+    GPUIndexBuf *lines_loose;      /* only loose edges. */
+    GPUIndexBuf *lines_paint_mask; /* no loose edges. */
+    GPUIndexBuf *lines_adjacency;
+    /* Uv overlays. (visibility can differ from 3D view) */
+    GPUIndexBuf *edituv_tris;
+    GPUIndexBuf *edituv_line_strips;
+    GPUIndexBuf *edituv_points;
+    GPUIndexBuf *edituv_facedots;
   } ibo;
+} MeshBufferCache;
+
+typedef struct MeshBatchCache {
+  MeshBufferCache final, cage;
 
   struct {
     /* Surfaces / Render */
@@ -2068,7 +2060,7 @@ typedef struct MeshBatchCache {
     GPUBatch *edit_triangles;
     GPUBatch *edit_vertices;
     GPUBatch *edit_edges;
-    GPUBatch *edit_lnor;
+    GPUBatch *edit_vnor;
     GPUBatch *edit_facedots;
     GPUBatch *edit_mesh_analysis;
     /* Edit UVs */
@@ -2093,8 +2085,7 @@ typedef struct MeshBatchCache {
     GPUBatch *wire_loops_uvs; /* Same as wire_loops but only has uvs. */
   } batch;
 
-  GPUIndexBuf **surf_per_mat_tris;
-  GPUBatch **surf_per_mat;
+  GPUBatch **surface_per_mat;
 
   /* arrays of bool uniform names (and value) that will be use to
    * set srgb conversion for auto attributes.*/
@@ -2178,9 +2169,7 @@ static void mesh_batch_cache_init(Mesh *me)
   }
 
   cache->mat_len = mesh_render_mat_len_get(me);
-  cache->surf_per_mat_tris = MEM_callocN(sizeof(*cache->surf_per_mat_tris) * cache->mat_len,
-                                         __func__);
-  cache->surf_per_mat = MEM_callocN(sizeof(*cache->surf_per_mat) * cache->mat_len, __func__);
+  cache->surface_per_mat = MEM_callocN(sizeof(*cache->surface_per_mat) * cache->mat_len, __func__);
 
   cache->is_dirty = false;
   cache->batch_ready = 0;
@@ -2206,8 +2195,11 @@ static void mesh_batch_cache_check_vertex_group(MeshBatchCache *cache,
                                                 const struct DRW_MeshWeightState *wstate)
 {
   if (!drw_mesh_weight_state_compare(&cache->weight_state, wstate)) {
+    FOREACH_MESH_BUFFER_CACHE(cache, mbufcache)
+    {
+      GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.weights);
+    }
     GPU_BATCH_CLEAR_SAFE(cache->batch.surface_weights);
-    GPU_VERTBUF_DISCARD_SAFE(cache->ordered.weights);
 
     cache->batch_ready &= ~MBC_SURFACE_WEIGHTS;
 
@@ -2217,23 +2209,20 @@ static void mesh_batch_cache_check_vertex_group(MeshBatchCache *cache,
 
 static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache)
 {
-  GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_pos_nor);
-  GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_uv_tan);
-  GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_vcol);
-  GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_orco);
-
-  if (cache->surf_per_mat_tris) {
-    for (int i = 0; i < cache->mat_len; i++) {
-      GPU_INDEXBUF_DISCARD_SAFE(cache->surf_per_mat_tris[i]);
-    }
+  FOREACH_MESH_BUFFER_CACHE(cache, mbufcache)
+  {
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.pos_nor);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.uv_tan);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.vcol);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.orco);
   }
-  MEM_SAFE_FREE(cache->surf_per_mat_tris);
-  if (cache->surf_per_mat) {
+
+  if (cache->surface_per_mat) {
     for (int i = 0; i < cache->mat_len; i++) {
-      GPU_BATCH_DISCARD_SAFE(cache->surf_per_mat[i]);
+      GPU_BATCH_DISCARD_SAFE(cache->surface_per_mat[i]);
     }
   }
-  MEM_SAFE_FREE(cache->surf_per_mat);
+  MEM_SAFE_FREE(cache->surface_per_mat);
 
   cache->batch_ready &= ~MBC_SURF_PER_MAT;
 
@@ -2247,15 +2236,18 @@ static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache)
 
 static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache)
 {
-  GPU_VERTBUF_DISCARD_SAFE(cache->edit.loop_stretch_angle);
-  GPU_VERTBUF_DISCARD_SAFE(cache->edit.loop_stretch_area);
-  GPU_VERTBUF_DISCARD_SAFE(cache->edit.loop_uv);
-  GPU_VERTBUF_DISCARD_SAFE(cache->edit.loop_uv_data);
-  GPU_VERTBUF_DISCARD_SAFE(cache->edit.facedots_uv);
-  GPU_VERTBUF_DISCARD_SAFE(cache->edit.facedots_uv_data);
-  GPU_INDEXBUF_DISCARD_SAFE(cache->ibo.edituv_loops_tri_fans);
-  GPU_INDEXBUF_DISCARD_SAFE(cache->ibo.edituv_loops_line_strips);
-  GPU_INDEXBUF_DISCARD_SAFE(cache->ibo.edituv_loops_points);
+  FOREACH_MESH_BUFFER_CACHE(cache, mbufcache)
+  {
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.stretch_angle);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.stretch_area);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.uv_tan);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.data_edituv);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.facedots_uv);
+    GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.facedots_data_edituv);
+    GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_tris);
+    GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_line_strips);
+    GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_points);
+  }
   GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_strech_area);
   GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_strech_angle);
   GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces);
@@ -2274,8 +2266,11 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
   }
   switch (mode) {
     case BKE_MESH_BATCH_DIRTY_SELECT:
-      GPU_VERTBUF_DISCARD_SAFE(cache->edit.loop_data);
-      GPU_VERTBUF_DISCARD_SAFE(cache->edit.facedots_pos_nor_data);
+      FOREACH_MESH_BUFFER_CACHE(cache, mbufcache)
+      {
+        GPU_VERTBUF_DISCARD_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list