Cleanup: Geometry Nodes: use cache mutex for lazy function graph generation
This is a more standard way to handle caches and avoids the need for a custom double checked lock. Pull Request: https://projects.blender.org/blender/blender/pulls/147345
This commit is contained in:
@@ -190,7 +190,7 @@ class bNodeTreeRuntime : NonCopyable, NonMovable {
|
||||
* evaluate the node group. Caching it here allows us to reuse the preprocessed node tree in case
|
||||
* its used multiple times.
|
||||
*/
|
||||
Mutex geometry_nodes_lazy_function_graph_info_mutex;
|
||||
CacheMutex geometry_nodes_lazy_function_graph_info_mutex;
|
||||
std::unique_ptr<nodes::GeometryNodesLazyFunctionGraphInfo>
|
||||
geometry_nodes_lazy_function_graph_info;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ void preprocess_geometry_node_tree_for_evaluation(bNodeTree &tree_cow)
|
||||
{
|
||||
BLI_assert(tree_cow.type == NTREE_GEOMETRY);
|
||||
/* Rebuild geometry nodes lazy function graph. */
|
||||
tree_cow.runtime->geometry_nodes_lazy_function_graph_info.reset();
|
||||
tree_cow.runtime->geometry_nodes_lazy_function_graph_info_mutex.tag_dirty();
|
||||
blender::nodes::ensure_geometry_nodes_lazy_function_graph(tree_cow);
|
||||
}
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ class NodeTreeMainUpdater {
|
||||
}
|
||||
|
||||
if (result.output_changed) {
|
||||
ntree->runtime->geometry_nodes_lazy_function_graph_info.reset();
|
||||
ntree->runtime->geometry_nodes_lazy_function_graph_info_mutex.tag_dirty();
|
||||
}
|
||||
|
||||
ID *owner_id = BKE_id_owner_get(&ntree->id);
|
||||
|
||||
@@ -1623,9 +1623,8 @@ static void rna_NodeTree_debug_lazy_function_graph(bNodeTree *tree,
|
||||
/* The graph is only stored on the evaluated data. */
|
||||
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
||||
tree = DEG_get_evaluated(depsgraph, tree);
|
||||
}
|
||||
std::lock_guard lock{tree->runtime->geometry_nodes_lazy_function_graph_info_mutex};
|
||||
if (!tree->runtime->geometry_nodes_lazy_function_graph_info) {
|
||||
};
|
||||
if (tree->runtime->geometry_nodes_lazy_function_graph_info_mutex.is_dirty()) {
|
||||
return;
|
||||
}
|
||||
std::string dot_str = tree->runtime->geometry_nodes_lazy_function_graph_info->graph.to_dot();
|
||||
@@ -1644,8 +1643,7 @@ static void rna_NodeTree_debug_zone_body_lazy_function_graph(
|
||||
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
||||
tree = DEG_get_evaluated(depsgraph, tree);
|
||||
}
|
||||
std::lock_guard lock{tree->runtime->geometry_nodes_lazy_function_graph_info_mutex};
|
||||
if (!tree->runtime->geometry_nodes_lazy_function_graph_info) {
|
||||
if (tree->runtime->geometry_nodes_lazy_function_graph_info_mutex.is_dirty()) {
|
||||
return;
|
||||
}
|
||||
const auto *graph = tree->runtime->geometry_nodes_lazy_function_graph_info
|
||||
|
||||
@@ -4162,11 +4162,12 @@ struct GeometryNodesLazyFunctionBuilder {
|
||||
}
|
||||
};
|
||||
|
||||
const GeometryNodesLazyFunctionGraphInfo *ensure_geometry_nodes_lazy_function_graph(
|
||||
const bNodeTree &btree)
|
||||
static std::unique_ptr<GeometryNodesLazyFunctionGraphInfo>
|
||||
ensure_geometry_nodes_lazy_function_graph_impl(const bNodeTree &btree)
|
||||
{
|
||||
btree.ensure_topology_cache();
|
||||
btree.ensure_interface_cache();
|
||||
|
||||
if (btree.has_available_link_cycle()) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -4203,23 +4204,20 @@ const GeometryNodesLazyFunctionGraphInfo *ensure_geometry_nodes_lazy_function_gr
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<GeometryNodesLazyFunctionGraphInfo> &lf_graph_info_ptr =
|
||||
btree.runtime->geometry_nodes_lazy_function_graph_info;
|
||||
|
||||
if (lf_graph_info_ptr) {
|
||||
return lf_graph_info_ptr.get();
|
||||
}
|
||||
std::lock_guard lock{btree.runtime->geometry_nodes_lazy_function_graph_info_mutex};
|
||||
if (lf_graph_info_ptr) {
|
||||
return lf_graph_info_ptr.get();
|
||||
}
|
||||
|
||||
auto lf_graph_info = std::make_unique<GeometryNodesLazyFunctionGraphInfo>();
|
||||
GeometryNodesLazyFunctionBuilder builder{btree, *lf_graph_info};
|
||||
builder.build();
|
||||
return lf_graph_info;
|
||||
}
|
||||
|
||||
lf_graph_info_ptr = std::move(lf_graph_info);
|
||||
return lf_graph_info_ptr.get();
|
||||
const GeometryNodesLazyFunctionGraphInfo *ensure_geometry_nodes_lazy_function_graph(
|
||||
const bNodeTree &btree)
|
||||
{
|
||||
btree.runtime->geometry_nodes_lazy_function_graph_info_mutex.ensure([&]() {
|
||||
btree.runtime->geometry_nodes_lazy_function_graph_info =
|
||||
ensure_geometry_nodes_lazy_function_graph_impl(btree);
|
||||
});
|
||||
return btree.runtime->geometry_nodes_lazy_function_graph_info.get();
|
||||
}
|
||||
|
||||
destruct_ptr<fn::LocalUserData> GeoNodesUserData::get_local(LinearAllocator<> &allocator)
|
||||
|
||||
Reference in New Issue
Block a user