[Bf-blender-cvs] [215c3460171] temp_bmesh_multires: Only send all vcol layers to gpu (for pbvh drawing) in a material draw mode.

Joseph Eagar noreply at git.blender.org
Fri Mar 26 01:39:11 CET 2021


Commit: 215c3460171499a29e088b0e4bda883b5b664827
Author: Joseph Eagar
Date:   Thu Mar 25 17:38:27 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB215c3460171499a29e088b0e4bda883b5b664827

Only send all vcol layers to gpu (for pbvh drawing) in a material
draw mode.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 8a55d09bfe1..46076baccd3 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -308,7 +308,8 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
                       PBVHFrustumPlanes *update_frustum,
                       PBVHFrustumPlanes *draw_frustum,
                       void (*draw_fn)(void *user_data, struct GPU_PBVH_Buffers *buffers),
-                      void *user_data);
+                      void *user_data,
+                      bool active_vcol_only);
 
 void BKE_pbvh_draw_debug_cb(
     PBVH *pbvh,
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 9e345e7354e..9ee8bc43de4 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1021,6 +1021,7 @@ typedef struct PBVHUpdateData {
   int flag;
   bool show_sculpt_face_sets;
   bool flat_vcol_shading;
+  bool active_vcol_only;
 } PBVHUpdateData;
 
 static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
@@ -1337,7 +1338,8 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
                                       pbvh->cd_vert_node_offset,
                                       pbvh->face_sets_color_seed,
                                       pbvh->face_sets_color_default,
-                                      data->flat_vcol_shading);
+                                      data->flat_vcol_shading,
+                                      data->active_vcol_only);
         break;
     }
   }
@@ -1360,7 +1362,8 @@ void BKE_pbvh_set_flat_vcol_shading(PBVH *pbvh, bool value)
   pbvh->flat_vcol_shading = value;
 }
 
-static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag)
+static void pbvh_update_draw_buffers(
+    PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag, bool active_vcol_only)
 {
   if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
     /* Free buffers uses OpenGL, so not in parallel. */
@@ -1402,8 +1405,10 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
   GPU_pbvh_update_attribute_names(vdata, ldata);
 
   /* Parallel creation and update of draw buffers. */
-  PBVHUpdateData data = {
-      .pbvh = pbvh, .nodes = nodes, .flat_vcol_shading = pbvh->flat_vcol_shading};
+  PBVHUpdateData data = {.pbvh = pbvh,
+                         .nodes = nodes,
+                         .flat_vcol_shading = pbvh->flat_vcol_shading,
+                         .active_vcol_only = active_vcol_only};
 
   TaskParallelSettings settings;
   BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -1467,8 +1472,7 @@ void BKE_pbvh_update_origcolor_bmesh(PBVH *pbvh, PBVHNode *node)
     return;
   }
 
-  BKE_pbvh_vertex_iter_begin(pbvh, node, vd, PBVH_ITER_ALL)
-  {
+  BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_ALL) {
     MDynTopoVert *mv = BKE_PBVH_DYNVERT(pbvh->cd_dyn_vert, vd.bm_vert);
     float *c2 = BM_ELEM_CD_GET_VOID_P(vd.bm_vert, pbvh->cd_vcol_offset);
 
@@ -1485,8 +1489,7 @@ void BKE_pbvh_update_origco_bmesh(PBVH *pbvh, PBVHNode *node)
     return;
   }
 
-  BKE_pbvh_vertex_iter_begin(pbvh, node, vd, PBVH_ITER_ALL)
-  {
+  BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_ALL) {
     MDynTopoVert *mv = BKE_PBVH_DYNVERT(pbvh->cd_dyn_vert, vd.bm_vert);
 
     copy_v3_v3(mv->origco, vd.bm_vert->co);
@@ -2811,7 +2814,8 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
                       PBVHFrustumPlanes *update_frustum,
                       PBVHFrustumPlanes *draw_frustum,
                       void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers),
-                      void *user_data)
+                      void *user_data,
+                      bool active_vcol_only)
 {
   PBVHNode **nodes;
   int totnode;
@@ -2834,7 +2838,7 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
 
   /* Update draw buffers. */
   if (totnode != 0 && (update_flag & (PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers))) {
-    pbvh_update_draw_buffers(pbvh, nodes, totnode, update_flag);
+    pbvh_update_draw_buffers(pbvh, nodes, totnode, update_flag, active_vcol_only);
   }
   MEM_SAFE_FREE(nodes);
 
@@ -3265,8 +3269,7 @@ void BKE_pbvh_ensure_proxyarray_indexmap(PBVH *pbvh, PBVHNode *node, GHash *vert
   PBVHVertexIter vd;
 
   int i = 0;
-  BKE_pbvh_vertex_iter_begin(pbvh, node, vd, PBVH_ITER_UNIQUE)
-  {
+  BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_UNIQUE) {
     BLI_ghash_insert(gs, (void *)vd.vertex.i, (void *)i);
     i++;
   }
@@ -3305,8 +3308,7 @@ GHash *pbvh_build_vert_node_map(PBVH *pbvh, PBVHNode **nodes, int totnode, int m
       continue;
     }
 
-    BKE_pbvh_vertex_iter_begin(pbvh, node, vd, PBVH_ITER_UNIQUE)
-    {
+    BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_UNIQUE) {
       BLI_ghash_insert(vert_node_map, (void *)vd.vertex.i, (void *)(node - pbvh->nodes));
     }
     BKE_pbvh_vertex_iter_end;
@@ -3414,8 +3416,7 @@ void BKE_pbvh_ensure_proxyarray(SculptSession *ss,
   int i = 0;
 
 #  if 1
-  BKE_pbvh_vertex_iter_begin(pbvh, node, vd, PBVH_ITER_UNIQUE)
-  {
+  BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_UNIQUE) {
     void **val;
 
     if (!BLI_ghash_ensure_p(gs, (void *)vd.vertex.i, &val)) {
@@ -3431,8 +3432,7 @@ void BKE_pbvh_ensure_proxyarray(SculptSession *ss,
   }
 
   i = 0;
-  BKE_pbvh_vertex_iter_begin(pbvh, node, vd, PBVH_ITER_UNIQUE)
-  {
+  BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_UNIQUE) {
     if (i >= p->size) {
       printf("error!! %s\n", __func__);
       break;
@@ -3595,8 +3595,7 @@ static void pbvh_gather_proxyarray_exec(void *__restrict userdata,
 
   int mask = p->datamask;
 
-  BKE_pbvh_vertex_iter_begin(data->pbvh, node, vd, PBVH_ITER_UNIQUE)
-  {
+  BKE_pbvh_vertex_iter_begin (data->pbvh, node, vd, PBVH_ITER_UNIQUE) {
     if (mask & PV_CO) {
       copy_v3_v3(vd.co, p->co[i]);
     }
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 6bdc5305fed..c9827d71edf 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -888,6 +888,7 @@ typedef struct DRWSculptCallbackData {
   bool fast_mode; /* Set by draw manager. Do not init. */
 
   int debug_node_nr;
+  bool active_vcol_only;
 } DRWSculptCallbackData;
 
 #define SCULPT_DEBUG_COLOR(id) (sculpt_debug_colors[id % 9])
@@ -1041,7 +1042,7 @@ static void drw_sculpt_generate_calls(DRWSculptCallbackData *scd)
                    &update_frustum,
                    &draw_frustum,
                    (void (*)(void *, GPU_PBVH_Buffers *))sculpt_draw_cb,
-                   scd);
+                   scd, scd->active_vcol_only);
 
   if (SCULPT_DEBUG_BUFFERS) {
     int debug_node_nr = 0;
@@ -1063,6 +1064,7 @@ void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup, Object *ob, bool use_wire
       .use_wire = use_wire,
       .use_mats = false,
       .use_mask = use_mask,
+      .active_vcol_only = true
   };
   drw_sculpt_generate_calls(&scd);
 }
@@ -1078,6 +1080,7 @@ void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups,
       .use_wire = false,
       .use_mats = true,
       .use_mask = false,
+      .active_vcol_only = false
   };
   drw_sculpt_generate_calls(&scd);
 }
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 50262148eb1..c3fb989a923 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -97,7 +97,8 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                    const int cd_vert_node_offset,
                                    int face_sets_color_seed,
                                    int face_sets_color_default,
-                                   bool flat_vcol);
+                                   bool flat_vcol,
+                                   bool active_vcol_only);
 
 void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
                                   struct SubdivCCG *subdiv_ccg,
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 25accf2bf2f..dce0cec2ecb 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -979,14 +979,24 @@ void GPU_pbvh_update_attribute_names(CustomData *vdata, CustomData *ldata)
   }
 }
 
-static int gpu_pbvh_bmesh_make_vcol_offs(BMesh *bm, int r_cd_vcols[MAX_MCOL])
+static int gpu_pbvh_bmesh_make_vcol_offs(BMesh *bm, int r_cd_vcols[MAX_MCOL], bool active_only)
 {
+  if (active_only) {
+    int idx = CustomData_get_offset(&bm->vdata, CD_PROP_COLOR);
+    if (idx >= 0) {
+      r_cd_vcols[0] = idx;
+      return 1;
+    }
+
+    return 0;
+  }
+
   int count = 0;
   int tot = CustomData_number_of_layers(&bm->vdata, CD_PROP_COLOR);
 
   for (int i = 0; i < tot; i++) {
     int idx = CustomData_get_layer_index_n(&bm->vdata, CD_PROP_COLOR, i);
-    //idx = CustomData_get_active_layer_index(&bm->vdata, CD_PROP_COLOR);
+    // idx = CustomData_get_active_layer_index(&bm->vdata, CD_PROP_COLOR);
 
     if (idx < 0) {
       printf("eek, corruption in customdata!\n");
@@ -996,7 +1006,7 @@ static int gpu_pbvh_bmesh_make_vcol_offs(BMesh *bm, int r_cd_vcols[MAX_MCOL])
     CustomDataLayer *cl = bm->vdata.layers + idx;
 
     if (cl->flag & CD_FLAG_TEMPORARY) {
-      continue; //ignore original color layer
+      continue;  // ignore original color layer
     }
 
     r_cd_vcols[count++] = CustomData_get_n_offset(&bm->vdata, CD_PROP_COLOR, i);
@@ -1047,7 +1057,8 @@ static void GPU_pbvh_bmesh_buffers_update_flat_vcol(GPU_PBVH_Buffers *buffers,
                                                     const int update_flags,
                                                     const int cd_vert_node_offset,
                                                     int face_sets_color_seed,
-                                                    int face_sets_color_default)
+                                                    int face_sets_color_default,
+                                                    bool active_vcol_onl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list