[Bf-blender-cvs] [684b95804e8] master: Refactor: remove cache parameters from `bvhtree_from_` functions
Germano Cavalcante
noreply at git.blender.org
Wed Apr 6 00:33:05 CEST 2022
Commit: 684b95804e8fe8a78488b96b02285b2854809ff9
Author: Germano Cavalcante
Date: Tue Apr 5 18:44:52 2022 -0300
Branches: master
https://developer.blender.org/rB684b95804e8fe8a78488b96b02285b2854809ff9
Refactor: remove cache parameters from `bvhtree_from_` functions
The `BVHCacheType bvh_cache_type` parameter defines specific
`BVHTrees` that cannot be customized.
So it doesn't make sense to pass this value to any
`*bvhtree_from_[...]_ex` function as the `BVHTrees` created in these
cases are custom and cannot be saved in the cache.
This also resulted in a nice cleanup in the code.
Differential Revision: https://developer.blender.org/D14479
===================================================================
M source/blender/blenkernel/BKE_bvhutils.h
M source/blender/blenkernel/intern/bvhutils.cc
M source/blender/blenkernel/intern/mesh_remap.c
M source/blender/editors/transform/transform_snap_object.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index 6bf4f3acc15..ec017dec2e4 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -113,9 +113,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data,
float epsilon,
int tree_type,
int axis,
- BVHCacheType bvh_cache_type,
- struct BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex);
+ const bool isolate);
/**
* Builds a BVH-tree where nodes are the given vertices (NOTE: does not copy given `vert`!).
@@ -133,9 +131,7 @@ BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data,
float epsilon,
int tree_type,
int axis,
- BVHCacheType bvh_cache_type,
- struct BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex);
+ const bool isolate);
BVHTree *bvhtree_from_editmesh_edges(
BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis);
@@ -150,9 +146,7 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data,
float epsilon,
int tree_type,
int axis,
- BVHCacheType bvh_cache_type,
- struct BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex);
+ const bool isolate);
/**
* Builds a BVH-tree where nodes are the given edges.
@@ -173,9 +167,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data,
float epsilon,
int tree_type,
int axis,
- BVHCacheType bvh_cache_type,
- struct BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex);
+ const bool isolate);
/**
* Builds a BVH-tree where nodes are the given tessellated faces
@@ -197,9 +189,7 @@ BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data,
float epsilon,
int tree_type,
int axis,
- BVHCacheType bvh_cache_type,
- struct BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex);
+ const bool isolate);
BVHTree *bvhtree_from_editmesh_looptri(
BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis);
@@ -214,9 +204,7 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data,
float epsilon,
int tree_type,
int axis,
- BVHCacheType bvh_cache_type,
- struct BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex);
+ const bool isolate);
/**
* Builds a BVH-tree where nodes are the looptri faces of the given mesh.
@@ -236,9 +224,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data,
float epsilon,
int tree_type,
int axis,
- BVHCacheType bvh_cache_type,
- struct BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex);
+ const bool isolate);
/**
* Builds or queries a BVH-cache for the cache BVH-tree of the request type.
diff --git a/source/blender/blenkernel/intern/bvhutils.cc b/source/blender/blenkernel/intern/bvhutils.cc
index 1cab5281f0e..85d3c778a6d 100644
--- a/source/blender/blenkernel/intern/bvhutils.cc
+++ b/source/blender/blenkernel/intern/bvhutils.cc
@@ -735,38 +735,16 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data,
float epsilon,
int tree_type,
int axis,
- const BVHCacheType bvh_cache_type,
- BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex)
+ const bool isolate)
{
BVHTree *tree = nullptr;
+ tree = bvhtree_from_editmesh_verts_create_tree(
+ epsilon, tree_type, axis, em, verts_mask, verts_num_active);
- if (bvh_cache_p) {
- bool lock_started = false;
- data->cached = bvhcache_find(
- bvh_cache_p, bvh_cache_type, &data->tree, &lock_started, mesh_eval_mutex);
-
- if (data->cached == false) {
- tree = bvhtree_from_editmesh_verts_create_tree(
- epsilon, tree_type, axis, em, verts_mask, verts_num_active);
- bvhtree_balance(tree, true);
-
- /* Save on cache for later use */
- // printf("BVHTree built and saved on cache\n");
- bvhcache_insert(*bvh_cache_p, tree, bvh_cache_type);
- data->cached = true;
- }
- bvhcache_unlock(*bvh_cache_p, lock_started);
- }
- else {
- tree = bvhtree_from_editmesh_verts_create_tree(
- epsilon, tree_type, axis, em, verts_mask, verts_num_active);
- bvhtree_balance(tree, false);
- }
+ bvhtree_balance(tree, isolate);
if (data) {
bvhtree_from_editmesh_setup_data(tree, BVHTREE_FROM_EM_VERTS, em, data);
- data->cached = bvh_cache_p != nullptr;
}
return tree;
@@ -775,8 +753,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data,
BVHTree *bvhtree_from_editmesh_verts(
BVHTreeFromEditMesh *data, BMEditMesh *em, float epsilon, int tree_type, int axis)
{
- return bvhtree_from_editmesh_verts_ex(
- data, em, nullptr, -1, epsilon, tree_type, axis, BVHTREE_FROM_VERTS, nullptr, nullptr);
+ return bvhtree_from_editmesh_verts_ex(data, em, nullptr, -1, epsilon, tree_type, axis, false);
}
BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
@@ -788,41 +765,19 @@ BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
float epsilon,
int tree_type,
int axis,
- const BVHCacheType bvh_cache_type,
- BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex)
+ const bool isolate)
{
- bool in_cache = false;
- bool lock_started = false;
BVHTree *tree = nullptr;
- if (bvh_cache_p) {
- in_cache = bvhcache_find(bvh_cache_p, bvh_cache_type, &tree, &lock_started, mesh_eval_mutex);
- }
-
- if (in_cache == false) {
- tree = bvhtree_from_mesh_verts_create_tree(
- epsilon, tree_type, axis, vert, verts_num, verts_mask, verts_num_active);
- bvhtree_balance(tree, bvh_cache_p != nullptr);
-
- if (bvh_cache_p) {
- /* Save on cache for later use */
- // printf("BVHTree built and saved on cache\n");
- BVHCache *bvh_cache = *bvh_cache_p;
- bvhcache_insert(bvh_cache, tree, bvh_cache_type);
- in_cache = true;
- }
- }
+ tree = bvhtree_from_mesh_verts_create_tree(
+ epsilon, tree_type, axis, vert, verts_num, verts_mask, verts_num_active);
- if (bvh_cache_p) {
- bvhcache_unlock(*bvh_cache_p, lock_started);
- }
+ bvhtree_balance(tree, isolate);
if (data) {
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(
tree, BVHTREE_FROM_VERTS, vert, nullptr, nullptr, nullptr, nullptr, nullptr, data);
data->vert_allocated = vert_allocated;
- data->cached = in_cache;
}
return tree;
@@ -918,37 +873,16 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data,
float epsilon,
int tree_type,
int axis,
- const BVHCacheType bvh_cache_type,
- BVHCache **bvh_cache_p,
- ThreadMutex *mesh_eval_mutex)
+ const bool isolate)
{
BVHTree *tree = nullptr;
+ tree = bvhtree_from_editmesh_edges_create_tree(
+ epsilon, tree_type, axis, em, edges_mask, edges_num_active);
- if (bvh_cache_p) {
- bool lock_started = false;
- data->cached = bvhcache_find(
- bvh_cache_p, bvh_cache_type, &data->tree, &lock_started, mesh_eval_mutex);
- BVHCache *bvh_cache = *bvh_cache_p;
- if (data->cached == false) {
- tree = bvhtree_from_editmesh_edges_create_tree(
- epsilon, tree_type, axis, em, edges_mask, edges_num_active);
- bvhtree_balance(tree, true);
- /* Save on cache for later use */
- // printf("BVHTree built and saved on cache\n");
- bvhcache_insert(bvh_cache, tree, bvh_cache_type);
- data->cached = true;
- }
- bvhcache_unlock(bvh_cache, lock_started);
- }
- else {
- tree = bvhtree_from_editmesh_edges_create_tree(
- epsilon, tree_type, axis, em, edges_mask, edges_num_active);
- bvhtree_balance(tree, false);
- }
+ bvhtree_balance(tree, isolate);
if (data) {
bvhtree_from_editmesh_setup_data(tree, BVHTREE_FROM_E
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list