[Bf-blender-cvs] [f52ed672894] sculpt-dev: Sculpt: fixed dyntopo speed issue
Joseph Eagar
noreply at git.blender.org
Fri Oct 1 06:31:33 CEST 2021
Commit: f52ed672894e30bf1d5478462d970cbf9fe0092e
Author: Joseph Eagar
Date: Thu Sep 30 21:30:15 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rBf52ed672894e30bf1d5478462d970cbf9fe0092e
Sculpt: fixed dyntopo speed issue
* PBVH_UpdateTopology is now properly cleared in all cases.
* BKE_curvemapping_cache.h no longer provides a global curve
cache, the brush system now allocates its own on startup.
===================================================================
M source/blender/blenkernel/BKE_brush_engine.h
M source/blender/blenkernel/BKE_curvemapping_cache.h
M source/blender/blenkernel/intern/brush.c
M source/blender/blenkernel/intern/brush_engine.c
M source/blender/blenkernel/intern/brush_engine_presets.c
M source/blender/blenkernel/intern/curvemapping_cache.c
M source/blender/blenkernel/intern/dyntopo.c
M source/blender/blenkernel/intern/pbvh_bmesh.c
M source/blender/bmesh/intern/bmesh_log.c
M source/blender/makesrna/intern/rna_brush_engine.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_brush_engine.h b/source/blender/blenkernel/BKE_brush_engine.h
index 3e04b014425..58cc33170cd 100644
--- a/source/blender/blenkernel/BKE_brush_engine.h
+++ b/source/blender/blenkernel/BKE_brush_engine.h
@@ -362,6 +362,9 @@ void BKE_brush_channelset_check_radius(BrushChannelSet *chset);
const char *BKE_brush_channel_category_get(BrushChannel *ch);
void BKE_brush_channel_category_set(BrushChannel *ch, const char *str);
+void BKE_brush_channel_system_init();
+void BKE_brush_channel_system_exit();
+
/*
set up static type checker for BRUSHSET_XXX macros
*/
diff --git a/source/blender/blenkernel/BKE_curvemapping_cache.h b/source/blender/blenkernel/BKE_curvemapping_cache.h
index 8212c5a4099..cdbd99bb476 100644
--- a/source/blender/blenkernel/BKE_curvemapping_cache.h
+++ b/source/blender/blenkernel/BKE_curvemapping_cache.h
@@ -14,8 +14,6 @@ CurveMapping *BKE_curvemapping_cache_get(CurveMappingCache *cache,
bool free_input);
void BKE_curvemapping_cache_free(CurveMappingCache *cache);
-CurveMappingCache *BKE_curvemapping_cache_global(void);
-
// takes a curve that's already in the cache and increases its user count
void BKE_curvemapping_cache_aquire(CurveMappingCache *cache, CurveMapping *curve);
void BKE_curvemapping_cache_release(CurveMappingCache *cache, CurveMapping *curve);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index bd3816fdcb0..ee1b3c24620 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -37,6 +37,7 @@
#include "BKE_brush_engine.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
+#include "BKE_curvemapping_cache.h"
#include "BKE_gpencil.h"
#include "BKE_icons.h"
#include "BKE_idtype.h"
@@ -555,12 +556,16 @@ static RNG *brush_rng;
void BKE_brush_system_init(void)
{
+ BKE_brush_channel_system_init();
+
brush_rng = BLI_rng_new(0);
BLI_rng_srandom(brush_rng, 31415682);
}
void BKE_brush_system_exit(void)
{
+ BKE_brush_channel_system_exit();
+
if (brush_rng == NULL) {
return;
}
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index d2b4055e06f..b7ec9b39930 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -17,6 +17,10 @@
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_types.h"
+
#include "DNA_brush_enums.h"
#include "DNA_brush_types.h"
#include "DNA_color_types.h"
@@ -54,15 +58,11 @@
#define IS_CACHE_CURVE(curve) BKE_curvemapping_in_cache(curve)
// frees curve if it wasn't cached, returns cache curved
-#define GET_CACHE_CURVE(curve) \
- BKE_curvemapping_cache_get(BKE_curvemapping_cache_global(), curve, true)
-#define RELEASE_CACHE_CURVE(curve) \
- BKE_curvemapping_cache_release(BKE_curvemapping_cache_global(), curve)
+#define GET_CACHE_CURVE(curve) BKE_curvemapping_cache_get(brush_curve_cache, curve, true)
+#define RELEASE_CACHE_CURVE(curve) BKE_curvemapping_cache_release(brush_curve_cache, curve)
#define RELEASE_OR_FREE_CURVE(curve) \
- curve ? \
- (BKE_curvemapping_cache_release_or_free(BKE_curvemapping_cache_global(), curve), NULL) : \
- NULL
-#define CURVE_ADDREF(curve) BKE_curvemapping_cache_aquire(BKE_curvemapping_cache_global(), curve)
+ curve ? (BKE_curvemapping_cache_release_or_free(brush_curve_cache, curve), NULL) : NULL
+#define CURVE_ADDREF(curve) BKE_curvemapping_cache_aquire(brush_curve_cache, curve)
#ifdef DEBUG_CURVE_MAPPING_ALLOC
static struct {
@@ -98,6 +98,19 @@ void BKE_curvemapping_copy_data_tag_ex(CurveMapping *target,
# define namestack_pop(passthru)
#endif
+struct CurveMappingCache *brush_curve_cache = NULL;
+extern BrushChannelType brush_builtin_channels[];
+extern int brush_builtin_channel_len;
+
+void BKE_brush_channel_system_init()
+{
+ brush_curve_cache = BKE_curvemapping_cache_create();
+}
+
+void BKE_brush_channel_system_exit()
+{
+ BKE_curvemapping_cache_free(brush_curve_cache);
+}
// returns true if curve was duplicated
bool BKE_brush_mapping_ensure_write(BrushMapping *mp)
{
@@ -186,9 +199,6 @@ networks. BrushCommandPreset will be
generated from the node group inputs.
*/
-extern BrushChannelType brush_builtin_channels[];
-extern const int brush_builtin_channel_len;
-
void BKE_brush_channeltype_rna_check(BrushChannelType *def,
int (*getIconFromName)(const char *name))
{
@@ -275,8 +285,7 @@ static void copy_channel_data_keep_mappings(BrushChannel *dst, BrushChannel *src
}
if (src->curve.curve && !IS_CACHE_CURVE(src->curve.curve)) {
- dst->curve.curve = BKE_curvemapping_cache_get(
- BKE_curvemapping_cache_global(), src->curve.curve, false);
+ dst->curve.curve = BKE_curvemapping_cache_get(brush_curve_cache, src->curve.curve, false);
}
else {
dst->curve.curve = src->curve.curve;
@@ -348,8 +357,7 @@ void BKE_brush_channel_copy_data(BrushChannel *dst, BrushChannel *src, bool keep
// dst->curve = GET_CACHE_CURVE(src->curve);
// hrm, let's not modify src->curve, GET_CACHE_CURVE might free it
- dst->curve.curve = BKE_curvemapping_cache_get(
- BKE_curvemapping_cache_global(), src->curve.curve, false);
+ dst->curve.curve = BKE_curvemapping_cache_get(brush_curve_cache, src->curve.curve, false);
}
else {
CURVE_ADDREF(dst->curve.curve);
@@ -1807,7 +1815,7 @@ void BKE_brush_mapping_copy_data(BrushMapping *dst, BrushMapping *src)
// dst->curve = GET_CACHE_CURVE(src->curve);
// hrm, let's not modify src->curve, GET_CACHE_CURVE might free it
- dst->curve = BKE_curvemapping_cache_get(BKE_curvemapping_cache_global(), src->curve, false);
+ dst->curve = BKE_curvemapping_cache_get(brush_curve_cache, src->curve, false);
}
else {
dst->curve = src->curve;
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index 4786f83978f..47d58eeab13 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -16,6 +16,9 @@
#include "BLI_threads.h"
#include "BLI_utildefines.h"
+#include "RNA_access.h"
+#include "RNA_define.h"
+
#include "IMB_imbuf.h"
#include "DNA_brush_enums.h"
@@ -30,7 +33,6 @@
#include "BKE_colorband.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
-#include "BKE_curvemapping_cache.h"
#include "BKE_node.h"
#include "BKE_paint.h"
@@ -47,6 +49,8 @@
# pragma warning(error : 4033) /* 'function' must return a value */
#endif
+struct CurveMappingCache *brush_curve_cache;
+
#if 1
struct {
char t1[32], t2[32], t3[32], t4[32];
diff --git a/source/blender/blenkernel/intern/curvemapping_cache.c b/source/blender/blenkernel/intern/curvemapping_cache.c
index 084a0c70c7a..21aa0dc3ece 100644
--- a/source/blender/blenkernel/intern/curvemapping_cache.c
+++ b/source/blender/blenkernel/intern/curvemapping_cache.c
@@ -265,22 +265,8 @@ void BKE_curvemapping_cache_free(CurveMappingCache *cache)
MEM_freeN(cache);
}
-static CurveMappingCache *the_global_cache = NULL;
-
void BKE_curvemapping_cache_exit()
{
- if (the_global_cache) {
- BKE_curvemapping_cache_free(the_global_cache);
- }
-}
-
-CurveMappingCache *BKE_curvemapping_cache_global()
-{
- if (!the_global_cache) {
- the_global_cache = BKE_curvemapping_cache_create();
- }
-
- return the_global_cache;
}
// releases a curve if it's in the cache, otherwise frees it
diff --git a/source/blender/blenkernel/intern/dyntopo.c b/source/blender/blenkernel/intern/dyntopo.c
index 0fcac26b8cc..68ebad70903 100644
--- a/source/blender/blenkernel/intern/dyntopo.c
+++ b/source/blender/blenkernel/intern/dyntopo.c
@@ -5606,7 +5606,7 @@ typedef struct EdgeQueueContext {
if ((node->flag & PBVH_Leaf) && (node->flag & PBVH_UpdateTopology) &&
!(node->flag & PBVH_FullyHidden)) {
- node->flag &= ~PBVH_UpdateTopology;
+ /* do not clear PBVH_UpdateTopology here in case split messes with it */
/* Recursively split nodes that have gotten too many
* elements */
@@ -5616,14 +5616,17 @@ typedef struct EdgeQueueContext {
}
}
}
- else { // still unmark nodes
- for (int i = 0; i < pbvh->totnode; i++) {
- PBVHNode *node = pbvh->nodes + i;
- if ((node->flag & PBVH_Leaf) && (node->flag & PBVH_UpdateTopology)) {
- node->flag &= ~PBVH_UpdateTopology;
- }
+ /* clear PBVH_UpdateTopology flags */
+ for (int i = 0; i < pbvh->totnode; i++) {
+ BMVert *v;
+ PBVHNode *node = pbvh->nodes + i;
+
+ if (!(node->flag & PBVH_Leaf)) {
+ continue;
}
+
+ node->flag &= ~PBVH_UpdateTopology;
}
MEM_SAFE_FREE(eq_ctx.val34_verts);
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index e225247d1b2..b0f12edc05b 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -300,7 +300,7 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
BKE_pbvh_node_mark_rebuild_draw(n);
BKE_pbvh_node_fully_hidden_set(n, !has_visible);
- n->flag |= PBVH_UpdateNormals | PBVH_UpdateTopology | PBVH_UpdateCurvatureDir | PBVH_UpdateTris;
+ n->flag |= PBVH_UpdateNormals | PBVH_UpdateCurvatureDir | PBVH_UpdateTris;
if (add_orco) {
BKE_pbvh_bmesh_check_tris(pbvh, n);
@@ -1872,12 +1872,6 @@ void BKE_pbvh_set_bm_log(PBVH *pbvh, struct BMLog *log)
pbvh->bm_log = log;
}
-/*
-static double last_update_time[128] = {
- 0,
-};
-*/
-
bool BKE_pbvh_bmesh_update_topology_nodes(PBVH *pbvh,
bool (*searchcb)(PBVHNode *node, void *data),
void (*undopush)(PBVHNode *node, void *data),
@@ -1910,8 +1904,6 @@ bool BKE_pbvh_bmesh_update_topology_nodes(PBVH *pbvh,
}
}
- // double start = PIL_check_seconds_timer();
-
modified = modified || BKE_pbvh_bmesh_update_topology(pbvh,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list