[Bf-blender-cvs] [7bfe70f2ba0] master: Mesh Batch Cache: Speedup: Use flags to early remove unecessary checks

Clément Foucault noreply at git.blender.org
Wed May 8 17:59:20 CEST 2019


Commit: 7bfe70f2ba09f6311cb4f1170398d522480bb274
Author: Clément Foucault
Date:   Wed May 8 00:12:24 2019 +0200
Branches: master
https://developer.blender.org/rB7bfe70f2ba09f6311cb4f1170398d522480bb274

Mesh Batch Cache: Speedup: Use flags to early remove unecessary checks

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

M	source/blender/draw/intern/draw_cache_impl_mesh.c

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

diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index f2b79b0d0e1..02ebe16fb37 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -1894,6 +1894,39 @@ static void drw_mesh_weight_state_extract(Object *ob,
 /** \name Mesh GPUBatch Cache
  * \{ */
 
+typedef enum DRWBatchFlag {
+  MBC_SURFACE = (1 << 0),
+  MBC_SURFACE_WEIGHTS = (1 << 1),
+  MBC_EDIT_TRIANGLES = (1 << 2),
+  MBC_EDIT_VERTICES = (1 << 3),
+  MBC_EDIT_EDGES = (1 << 4),
+  MBC_EDIT_LNOR = (1 << 5),
+  MBC_EDIT_FACEDOTS = (1 << 6),
+  MBC_EDIT_MESH_ANALYSIS = (1 << 7),
+  MBC_EDITUV_FACES_STRECH_AREA = (1 << 8),
+  MBC_EDITUV_FACES_STRECH_ANGLE = (1 << 9),
+  MBC_EDITUV_FACES = (1 << 10),
+  MBC_EDITUV_EDGES = (1 << 11),
+  MBC_EDITUV_VERTS = (1 << 12),
+  MBC_EDITUV_FACEDOTS = (1 << 13),
+  MBC_EDIT_SELECTION_VERTS = (1 << 14),
+  MBC_EDIT_SELECTION_EDGES = (1 << 15),
+  MBC_EDIT_SELECTION_FACES = (1 << 16),
+  MBC_EDIT_SELECTION_FACEDOTS = (1 << 17),
+  MBC_ALL_VERTS = (1 << 18),
+  MBC_ALL_EDGES = (1 << 19),
+  MBC_LOOSE_EDGES = (1 << 20),
+  MBC_EDGE_DETECTION = (1 << 21),
+  MBC_WIRE_EDGES = (1 << 22),
+  MBC_WIRE_LOOPS = (1 << 23),
+  MBC_WIRE_LOOPS_UVS = (1 << 24),
+  MBC_SURF_PER_MAT = (1 << 25),
+} DRWBatchFlag;
+
+#define MBC_EDITUV \
+  (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. */
@@ -1999,6 +2032,9 @@ typedef struct MeshBatchCache {
   int *auto_layer_is_srgb;
   int auto_layer_len;
 
+  DRWBatchFlag batch_requested;
+  DRWBatchFlag batch_ready;
+
   /* settings to determine if cache is invalid */
   bool is_maybe_dirty;
   bool is_dirty; /* Instantly invalidates cache, skipping mesh check */
@@ -2016,13 +2052,15 @@ typedef struct MeshBatchCache {
 
   int lastmatch;
 
-  /* XXX, only keep for as long as sculpt mode uses shaded drawing. */
-  bool is_sculpt_points_tag;
-
   /* Valid only if edge_detection is up to date. */
   bool is_manifold;
 } MeshBatchCache;
 
+BLI_INLINE void mesh_batch_cache_add_request(MeshBatchCache *cache, DRWBatchFlag new_flag)
+{
+  atomic_fetch_and_or_uint32((uint32_t *)(&cache->batch_requested), *(uint32_t *)&new_flag);
+}
+
 /* GPUBatch cache management. */
 
 static bool mesh_batch_cache_valid(Mesh *me)
@@ -2115,6 +2153,8 @@ static void mesh_batch_cache_check_vertex_group(MeshBatchCache *cache,
     GPU_BATCH_CLEAR_SAFE(cache->batch.surface_weights);
     GPU_VERTBUF_DISCARD_SAFE(cache->ordered.weights);
 
+    cache->batch_ready &= ~MBC_SURFACE_WEIGHTS;
+
     drw_mesh_weight_state_clear(&cache->weight_state);
   }
 }
@@ -2139,6 +2179,8 @@ static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache)
   }
   MEM_SAFE_FREE(cache->surf_per_mat);
 
+  cache->batch_ready &= ~MBC_SURF_PER_MAT;
+
   MEM_SAFE_FREE(cache->auto_layer_names);
   MEM_SAFE_FREE(cache->auto_layer_is_srgb);
 
@@ -2164,6 +2206,8 @@ static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache)
   GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_edges);
   GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_verts);
   GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_facedots);
+
+  cache->batch_ready &= ~MBC_EDITUV;
 }
 
 void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
@@ -2184,6 +2228,8 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
       GPU_BATCH_DISCARD_SAFE(cache->batch.edit_edges);
       GPU_BATCH_DISCARD_SAFE(cache->batch.edit_facedots);
       GPU_BATCH_DISCARD_SAFE(cache->batch.edit_mesh_analysis);
+      cache->batch_ready &= ~(MBC_EDIT_TRIANGLES | MBC_EDIT_VERTICES | MBC_EDIT_EDGES |
+                              MBC_EDIT_FACEDOTS | MBC_EDIT_MESH_ANALYSIS);
       /* Because visible UVs depends on edit mode selection, discard everything. */
       mesh_batch_cache_discard_uvedit(cache);
       break;
@@ -2198,6 +2244,7 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
           GPU_BATCH_DISCARD_SAFE(cache->surf_per_mat[i]);
         }
       }
+      cache->batch_ready &= ~(MBC_SURFACE | MBC_WIRE_LOOPS | MBC_SURF_PER_MAT);
       break;
     case BKE_MESH_BATCH_DIRTY_ALL:
       cache->is_dirty = true;
@@ -2221,6 +2268,7 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
       GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_edges);
       GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_verts);
       GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_facedots);
+      cache->batch_ready &= ~MBC_EDITUV;
       break;
     default:
       BLI_assert(0);
@@ -2255,6 +2303,8 @@ static void mesh_batch_cache_clear(Mesh *me)
 
   mesh_batch_cache_discard_uvedit(cache);
 
+  cache->batch_ready = 0;
+
   drw_mesh_weight_state_clear(&cache->weight_state);
 }
 
@@ -4233,36 +4283,42 @@ static void texpaint_request_active_vcol(MeshBatchCache *cache, Mesh *me)
 GPUBatch *DRW_mesh_batch_cache_get_all_verts(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_ALL_VERTS);
   return DRW_batch_request(&cache->batch.all_verts);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_all_edges(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_ALL_EDGES);
   return DRW_batch_request(&cache->batch.all_edges);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_surface(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_SURFACE);
   return DRW_batch_request(&cache->batch.surface);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_loose_edges(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_LOOSE_EDGES);
   return DRW_batch_request(&cache->batch.loose_edges);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_surface_weights(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_LOOSE_EDGES);
   return DRW_batch_request(&cache->batch.surface_weights);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_edge_detection(Mesh *me, bool *r_is_manifold)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDGE_DETECTION);
   /* Even if is_manifold is not correct (not updated),
    * the default (not manifold) is just the worst case. */
   if (r_is_manifold) {
@@ -4274,12 +4330,14 @@ GPUBatch *DRW_mesh_batch_cache_get_edge_detection(Mesh *me, bool *r_is_manifold)
 GPUBatch *DRW_mesh_batch_cache_get_wireframes_face(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_WIRE_EDGES);
   return DRW_batch_request(&cache->batch.wire_edges);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_MESH_ANALYSIS);
   return DRW_batch_request(&cache->batch.edit_mesh_analysis);
 }
 
@@ -4305,6 +4363,8 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me,
                                                &cache->auto_layer_len);
   }
 
+  mesh_batch_cache_add_request(cache, MBC_SURF_PER_MAT);
+
   if (auto_layer_names) {
     *auto_layer_names = cache->auto_layer_names;
     *auto_layer_is_srgb = cache->auto_layer_is_srgb;
@@ -4319,6 +4379,7 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me,
 GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_SURF_PER_MAT);
   texpaint_request_active_uv(cache, me);
   for (int i = 0; i < cache->mat_len; ++i) {
     DRW_batch_request(&cache->surf_per_mat[i]);
@@ -4330,6 +4391,7 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
   texpaint_request_active_uv(cache, me);
+  mesh_batch_cache_add_request(cache, MBC_SURFACE);
   return DRW_batch_request(&cache->batch.surface);
 }
 
@@ -4337,6 +4399,7 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
   texpaint_request_active_vcol(cache, me);
+  mesh_batch_cache_add_request(cache, MBC_SURFACE);
   return DRW_batch_request(&cache->batch.surface);
 }
 
@@ -4349,30 +4412,35 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Mesh *me)
 GPUBatch *DRW_mesh_batch_cache_get_edit_triangles(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_TRIANGLES);
   return DRW_batch_request(&cache->batch.edit_triangles);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_edit_edges(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_EDGES);
   return DRW_batch_request(&cache->batch.edit_edges);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_edit_vertices(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_VERTICES);
   return DRW_batch_request(&cache->batch.edit_vertices);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_edit_lnors(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_LNOR);
   return DRW_batch_request(&cache->batch.edit_lnor);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_edit_facedots(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_FACEDOTS);
   return DRW_batch_request(&cache->batch.edit_facedots);
 }
 
@@ -4385,24 +4453,28 @@ GPUBatch *DRW_mesh_batch_cache_get_edit_facedots(Mesh *me)
 GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_SELECTION_FACES);
   return DRW_batch_request(&cache->batch.edit_selection_faces);
 }
 
 GPUBatch *DRW_mesh_batch_cache_get_facedots_with_select_id(Mesh *me)
 {
   MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_EDIT_SELECTION_FACEDOTS);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list