[Bf-blender-cvs] [a80c381ec52] temp_bmesh_multires: Sculpt Dyntopo: PBVH draw fixes

Joseph Eagar noreply at git.blender.org
Sun Aug 8 07:30:55 CEST 2021


Commit: a80c381ec52d162945c3344cc1668b1c89a13128
Author: Joseph Eagar
Date:   Sat Aug 7 22:28:00 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBa80c381ec52d162945c3344cc1668b1c89a13128

Sculpt Dyntopo: PBVH draw fixes

* The PBVH draw subsystem is now told whether any viewports
  have drawtype >= OB_MATERIAL before anything in any windows
  are drawn.  There are no alternatives given the design
  constraints of sculpting, where simply uploading data to the GPU
  quickly becomes a bottleneck.

* Fixed flat vcol shading mode.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/draw/intern/draw_manager.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
M	source/blender/windowmanager/intern/wm_draw.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 21f8d9903d8..97d3c77fb50 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -349,8 +349,7 @@ 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,
-                      bool active_vcol_only);
+                      void *user_data);
 
 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 32de1d786e6..abadab127a8 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1045,7 +1045,6 @@ 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,
@@ -1401,7 +1400,6 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
                                         pbvh->face_sets_color_seed,
                                         pbvh->face_sets_color_default,
                                         data->flat_vcol_shading,
-                                        data->active_vcol_only,
                                         node->tri_buffers[i].mat_nr);
         }
         break;
@@ -1456,8 +1454,7 @@ void pbvh_update_free_all_draw_buffers(PBVH *pbvh, PBVHNode *node)
   }
 }
 
-static void pbvh_update_draw_buffers(
-    PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag, bool active_vcol_only)
+static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag)
 {
   if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
     /* Free buffers uses OpenGL, so not in parallel. */
@@ -1489,13 +1486,11 @@ static void pbvh_update_draw_buffers(
     ldata = pbvh->ldata;
   }
 
-  GPU_pbvh_update_attribute_names(vdata, ldata, active_vcol_only);
+  GPU_pbvh_update_attribute_names(vdata, ldata, GPU_pbvh_need_full_render_get());
 
   /* Parallel creation and update of draw buffers. */
-  PBVHUpdateData data = {.pbvh = pbvh,
-                         .nodes = nodes,
-                         .flat_vcol_shading = pbvh->flat_vcol_shading,
-                         .active_vcol_only = active_vcol_only};
+  PBVHUpdateData data = {
+      .pbvh = pbvh, .nodes = nodes, .flat_vcol_shading = pbvh->flat_vcol_shading};
 
   TaskParallelSettings settings;
   BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -2926,8 +2921,7 @@ 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,
-                      bool active_vcol_only)
+                      void *user_data)
 {
   PBVHNode **nodes;
   int totnode;
@@ -2950,7 +2944,28 @@ 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, active_vcol_only);
+    // check that need_full_render is set to GPU_pbvh_need_full_render_get(),
+    // but only if nodes need updating
+
+    if (pbvh->type == PBVH_BMESH && pbvh->need_full_render != GPU_pbvh_need_full_render_get()) {
+      // update all nodes
+      MEM_SAFE_FREE(nodes);
+
+      printf("Rebuilding PBVH draw buffers...\n");
+
+      for (int i = 0; i < pbvh->totnode; i++) {
+        PBVHNode *node = pbvh->nodes + i;
+
+        node->flag |= PBVH_UpdateDrawBuffers | PBVH_RebuildDrawBuffers;
+      }
+
+      pbvh->need_full_render = GPU_pbvh_need_full_render_get();
+      BKE_pbvh_draw_cb(
+          pbvh, update_only_visible, update_frustum, draw_frustum, draw_fn, user_data);
+      return;
+    }
+
+    pbvh_update_draw_buffers(pbvh, nodes, totnode, update_flag);
   }
   MEM_SAFE_FREE(nodes);
 
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index bce00b79c8c..f06c95b1755 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -205,6 +205,7 @@ struct PBVH {
   struct SubdivCCG *subdiv_ccg;
 
   bool flat_vcol_shading;
+  bool need_full_render;  // used by pbvh drawing for PBVH_BMESH
 };
 
 /* pbvh.c */
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 027ab8ce32b..1881ad56696 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -29,6 +29,7 @@
 #include "BLI_string.h"
 #include "BLI_task.h"
 #include "BLI_threads.h"
+#include "BLI_utildefines.h"
 
 #include "BLF_api.h"
 
@@ -64,6 +65,7 @@
 #include "ED_space_api.h"
 #include "ED_view3d.h"
 
+#include "GPU_buffers.h"
 #include "GPU_capabilities.h"
 #include "GPU_framebuffer.h"
 #include "GPU_immediate.h"
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 9929a902b74..1baee2088e0 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -924,7 +924,6 @@ 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])
@@ -1092,8 +1091,7 @@ static void drw_sculpt_generate_calls(DRWSculptCallbackData *scd)
                    &update_frustum,
                    &draw_frustum,
                    (void (*)(void *, GPU_PBVH_Buffers *))sculpt_draw_cb,
-                   scd,
-                   scd->active_vcol_only);
+                   scd);
 
   if (SCULPT_DEBUG_BUFFERS) {
     int debug_node_nr = 0;
@@ -1113,8 +1111,7 @@ void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup, Object *ob, bool use_wire
                                .num_shading_groups = 1,
                                .use_wire = use_wire,
                                .use_mats = false,
-                               .use_mask = use_mask,
-                               .active_vcol_only = true};
+                               .use_mask = use_mask};
   drw_sculpt_generate_calls(&scd);
 }
 
@@ -1127,8 +1124,8 @@ void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups,
                                .num_shading_groups = num_shgroups,
                                .use_wire = false,
                                .use_mats = true,
-                               .use_mask = false,
-                               .active_vcol_only = false};
+                               .use_mask = false};
+
   drw_sculpt_generate_calls(&scd);
 }
 
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index e8fc189e7e0..cf0ba4b16bf 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -87,11 +87,9 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                   const struct MPropCol *vtcol,
                                   const int update_flags);
 
-/** if active_vcol_only is true, only the active (not render!) layer will
-    be uploaded to GPU*/
 void GPU_pbvh_update_attribute_names(struct CustomData *vdata,
                                      struct CustomData *ldata,
-                                     bool active_vcol_only);
+                                     bool need_full_render);
 
 void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                    struct BMesh *bm,
@@ -104,7 +102,6 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                    int face_sets_color_seed,
                                    int face_sets_color_default,
                                    bool flat_vcol,
-                                   bool active_vcol_only,
                                    short mat_nr);
 
 void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
@@ -132,6 +129,12 @@ short GPU_pbvh_buffers_material_index_get(GPU_PBVH_Buffers *buffers);
 bool GPU_pbvh_buffers_has_overlays(GPU_PBVH_Buffers *buffers);
 float *GPU_pbvh_get_extra_matrix(GPU_PBVH_Buffers *buffers);
 
+/** if need_full_render is false, only the active (not render!) vcol layer will
+    be uploaded to GPU*/
+
+void GPU_pbvh_need_full_render_set(bool state);
+bool GPU_pbvh_need_full_render_get(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index b265b6590ee..d6968dbc158 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -154,6 +154,9 @@ static struct {
   int vertex_attrs_len;
   int loop_attrs_len;
 #endif
+
+  bool active_vcol_only;
+  bool need_full_render;
 } g_vbo_id = {{0}};
 
 #ifdef NEW_ATTR_SYSTEM
@@ -1218,8 +1221,21 @@ static int gpu_pbvh_bmesh_make_vcol_offs(CustomData *vdata,
   return count;
 }
 
-void GPU_pbvh_update_attribute_names(CustomData *vdata, CustomData *ldata, bool active_only)
+void GPU_pbvh_need_full_render_set(bool state)
+{
+  g_vbo_id.need_full_render = state;
+  g_vbo_id.active_vcol_only = !state;
+}
+
+bool GPU_pbvh_need_full_render_get()
+{
+  return g_vbo_id.need_full_render;
+}
+
+void GPU_pbvh_update_attribute_names(CustomData *vdata, CustomData *ldata, bool need_full_render)
 {
+  const bool active_only = !need_full_render;
+
   GPU_vertformat_clear(&g_vbo_id.format);
 
   // g_vbo_id.loop_attrs = build_cd_layers(vdata, )
@@ -1288,7 +1304,6 @@ void GPU_pbvh_update_attribute_names(CustomData *vdata, CustomData *ldata, bool
 
 #ifndef NEW_ATTR_SYSTEM
     if (vdata && CustomData_has_layer(vdata, CD_PROP_COLOR)) {
-      const int cd_vcol_index = CustomData_get_layer_index(vdata, CD_P

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list