[Bf-blender-cvs] [850aa3d26a2] geometry-nodes-simulation: Allow multiple caches in the same node group
Hans Goudey
noreply at git.blender.org
Fri Dec 2 23:13:29 CET 2022
Commit: 850aa3d26a2b38efa04ff233f1df675bcd76673a
Author: Hans Goudey
Date: Fri Dec 2 16:13:18 2022 -0600
Branches: geometry-nodes-simulation
https://developer.blender.org/rB850aa3d26a2b38efa04ff233f1df675bcd76673a
Allow multiple caches in the same node group
The caches now hash the identifier of the output node as well.
===================================================================
M source/blender/blenkernel/BKE_compute_cache.hh
M source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
M source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_compute_cache.hh b/source/blender/blenkernel/BKE_compute_cache.hh
index 33b7f7f3b59..8af09d96618 100644
--- a/source/blender/blenkernel/BKE_compute_cache.hh
+++ b/source/blender/blenkernel/BKE_compute_cache.hh
@@ -131,10 +131,6 @@ struct ComputeCaches {
return cache_per_context.lookup_ptr(context_hash);
}
- /* TODO: Do we need to use the same context for multiple simulation inputs and outputs in the
- * same node group? If so this won't work at all-- we would need some way to link the two nodes,
- * which might be necessary for the "Run" socket anyway, since it needs to know whether the
- * simulation is running in order to know whether to use the last cache or request a new one. */
SimulationCache &ensure_for_context(const ComputeContextHash &context_hash)
{
std::scoped_lock lock{mutex};
diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc b/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
index 3e9be29050c..a9555d27693 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_compute_cache.hh"
+#include "BKE_compute_contexts.hh"
#include "BKE_scene.h"
#include "DEG_depsgraph_query.h"
@@ -66,14 +67,18 @@ static void node_init(bNodeTree *tree, bNode *node)
static void node_geo_exec(GeoNodeExecParams params)
{
- // const NodeGeometrySimulationInput &storage = node_storage(params.node());
+ const NodeGeometrySimulationInput &storage = node_storage(params.node());
+ const int32_t sim_output_node_id = storage.output_node_id;
+
const Scene *scene = DEG_get_input_scene(params.depsgraph());
const float scene_ctime = BKE_scene_ctime_get(scene);
const int scene_frame = int(scene_ctime);
const GeoNodesLFUserData &lf_data = *params.user_data();
bke::ComputeCaches &all_caches = *lf_data.modifier_data->cache_per_frame;
- const bke::SimulationCache *cache = all_caches.lookup_context(lf_data.compute_context->hash());
+
+ const bke::NodeGroupComputeContext cache_context(lf_data.compute_context, sim_output_node_id);
+ const bke::SimulationCache *cache = all_caches.lookup_context(cache_context.hash());
if (!cache) {
params.set_output("Geometry", params.extract_input<GeometrySet>("Geometry"));
return;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
index 1b40c295ed1..b6cc9d11a5e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_compute_cache.hh"
+#include "BKE_compute_contexts.hh"
#include "BKE_scene.h"
#include "DEG_depsgraph_query.h"
@@ -42,14 +43,17 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- const NodeGeometrySimulationOutput &storage = node_storage(params.node());
+ const bNode &node = params.node();
+ const NodeGeometrySimulationOutput &storage = node_storage(node);
const Scene *scene = DEG_get_input_scene(params.depsgraph());
const float scene_ctime = BKE_scene_ctime_get(scene);
const int scene_frame = int(scene_ctime);
const GeoNodesLFUserData &lf_data = *params.user_data();
bke::ComputeCaches &all_caches = *lf_data.modifier_data->cache_per_frame;
- bke::SimulationCache &cache = all_caches.ensure_for_context(lf_data.compute_context->hash());
+
+ const bke::NodeGroupComputeContext cache_context(lf_data.compute_context, node.identifier);
+ bke::SimulationCache &cache = all_caches.ensure_for_context(cache_context.hash());
if (cache.geometry_per_frame.is_empty()) {
if (params.lazy_output_is_required("Started")) {
More information about the Bf-blender-cvs
mailing list