Allow multiple caches in the same node group

The caches now hash the identifier of the output node as well.
This commit is contained in:
Hans Goudey 2022-12-02 16:13:18 -06:00
parent 1ba264d5f0
commit 850aa3d26a
3 changed files with 13 additions and 8 deletions

View File

@ -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};

View File

@ -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;

View File

@ -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")) {