From 5de86fc4f8a106ef91949426399ace2f2018ee69 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 1 Dec 2023 17:08:00 +0100 Subject: [PATCH] Cleanup: make name more specific for simulations This is necessary for the bake node (#115466). --- .../BKE_bake_geometry_nodes_modifier.hh | 4 +- .../intern/bake_geometry_nodes_modifier.cc | 6 +-- .../editors/object/object_bake_simulation.cc | 20 ++++---- .../editors/space_action/action_draw.cc | 6 +-- source/blender/modifiers/intern/MOD_nodes.cc | 47 ++++++++++--------- .../nodes/node_geo_simulation_output.cc | 6 +-- 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/source/blender/blenkernel/BKE_bake_geometry_nodes_modifier.hh b/source/blender/blenkernel/BKE_bake_geometry_nodes_modifier.hh index 1ee3f841476..ece548d9314 100644 --- a/source/blender/blenkernel/BKE_bake_geometry_nodes_modifier.hh +++ b/source/blender/blenkernel/BKE_bake_geometry_nodes_modifier.hh @@ -51,7 +51,7 @@ struct PrevCache { /** * Stores the cached/baked data for simulation nodes in geometry nodes. */ -struct NodeCache { +struct SimulationNodeCache { CacheStatus cache_status = CacheStatus::Valid; /** All cached frames. */ @@ -71,7 +71,7 @@ struct NodeCache { struct ModifierCache { mutable std::mutex mutex; - Map> cache_by_id; + Map> simulation_cache_by_id; }; /** diff --git a/source/blender/blenkernel/intern/bake_geometry_nodes_modifier.cc b/source/blender/blenkernel/intern/bake_geometry_nodes_modifier.cc index 569cf5ebd28..02d8c7bba5c 100644 --- a/source/blender/blenkernel/intern/bake_geometry_nodes_modifier.cc +++ b/source/blender/blenkernel/intern/bake_geometry_nodes_modifier.cc @@ -24,10 +24,10 @@ namespace blender::bke::bake { -void NodeCache::reset() +void SimulationNodeCache::reset() { std::destroy_at(this); - new (this) NodeCache(); + new (this) SimulationNodeCache(); } void scene_simulation_states_reset(Scene &scene) { @@ -40,7 +40,7 @@ void scene_simulation_states_reset(Scene &scene) if (!nmd->runtime->cache) { continue; } - for (auto item : nmd->runtime->cache->cache_by_id.items()) { + for (auto item : nmd->runtime->cache->simulation_cache_by_id.items()) { item.value->reset(); } } diff --git a/source/blender/editors/object/object_bake_simulation.cc b/source/blender/editors/object/object_bake_simulation.cc index bf399328229..dbf120a10f6 100644 --- a/source/blender/editors/object/object_bake_simulation.cc +++ b/source/blender/editors/object/object_bake_simulation.cc @@ -102,7 +102,7 @@ static void calculate_simulation_job_startjob(void *customdata, wmJobWorkerStatu if (!nmd->runtime->cache) { continue; } - for (auto item : nmd->runtime->cache->cache_by_id.items()) { + for (auto item : nmd->runtime->cache->simulation_cache_by_id.items()) { if (item.value->cache_status != bake::CacheStatus::Baked) { item.value->reset(); } @@ -296,11 +296,11 @@ static void bake_simulation_job_startjob(void *customdata, wmJobWorkerStatus *wo NodesModifierData &nmd = *modifier_bake_data.nmd; const bake::ModifierCache &modifier_cache = *nmd.runtime->cache; for (NodeBakeData &node_bake_data : modifier_bake_data.nodes) { - if (!modifier_cache.cache_by_id.contains(node_bake_data.id)) { + if (!modifier_cache.simulation_cache_by_id.contains(node_bake_data.id)) { continue; } - const bake::NodeCache &node_cache = *modifier_cache.cache_by_id.lookup( - node_bake_data.id); + const bake::SimulationNodeCache &node_cache = + *modifier_cache.simulation_cache_by_id.lookup(node_bake_data.id); if (node_cache.frame_caches.is_empty()) { continue; } @@ -340,10 +340,10 @@ static void bake_simulation_job_startjob(void *customdata, wmJobWorkerStatus *wo for (ModifierBakeData &modifier_bake_data : object_bake_data.modifiers) { NodesModifierData &nmd = *modifier_bake_data.nmd; for (NodeBakeData &node_bake_data : modifier_bake_data.nodes) { - if (std::unique_ptr *node_cache_ptr = - nmd.runtime->cache->cache_by_id.lookup_ptr(node_bake_data.id)) + if (std::unique_ptr *node_cache_ptr = + nmd.runtime->cache->simulation_cache_by_id.lookup_ptr(node_bake_data.id)) { - bake::NodeCache &node_cache = **node_cache_ptr; + bake::SimulationNodeCache &node_cache = **node_cache_ptr; if (!node_cache.frame_caches.is_empty()) { /* Tag the caches as being baked so that they are not changed anymore. */ node_cache.cache_status = bake::CacheStatus::Baked; @@ -422,7 +422,7 @@ static Vector collect_nodes_to_bake(Main &bmain, ModifierBakeData modifier_bake_data; modifier_bake_data.nmd = nmd; - for (auto item : nmd->runtime->cache->cache_by_id.items()) { + for (auto item : nmd->runtime->cache->simulation_cache_by_id.items()) { item.value->reset(); } @@ -652,10 +652,10 @@ static void try_delete_bake( } bake::ModifierCache &modifier_cache = *nmd.runtime->cache; std::lock_guard lock{modifier_cache.mutex}; - if (!modifier_cache.cache_by_id.contains(bake_id)) { + if (!modifier_cache.simulation_cache_by_id.contains(bake_id)) { return; } - bake::NodeCache &node_cache = *modifier_cache.cache_by_id.lookup(bake_id); + bake::SimulationNodeCache &node_cache = *modifier_cache.simulation_cache_by_id.lookup(bake_id); node_cache.reset(); const std::optional bake_path = bake::get_node_bake_path( *bmain, object, nmd, bake_id); diff --git a/source/blender/editors/space_action/action_draw.cc b/source/blender/editors/space_action/action_draw.cc index 6416db6f397..ce2d7d03d45 100644 --- a/source/blender/editors/space_action/action_draw.cc +++ b/source/blender/editors/space_action/action_draw.cc @@ -886,10 +886,10 @@ void timeline_draw_cache(const SpaceAction *saction, const Object *ob, const Sce const blender::bke::bake::ModifierCache &modifier_cache = *nmd->runtime->cache; { std::lock_guard lock{modifier_cache.mutex}; - for (const std::unique_ptr &node_cache_ptr : - modifier_cache.cache_by_id.values()) + for (const std::unique_ptr &node_cache_ptr : + modifier_cache.simulation_cache_by_id.values()) { - const blender::bke::bake::NodeCache &node_cache = *node_cache_ptr; + const blender::bke::bake::SimulationNodeCache &node_cache = *node_cache_ptr; if (node_cache.frame_caches.is_empty()) { all_simulations_baked = false; continue; diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 95654e2c804..ae76579eb22 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -325,20 +325,22 @@ static void update_existing_bake_caches(NodesModifierData &nmd) bake::ModifierCache &modifier_cache = *nmd.runtime->cache; std::lock_guard lock{modifier_cache.mutex}; - Map> &old_cache_by_id = modifier_cache.cache_by_id; - Map> new_cache_by_id; + Map> &old_cache_by_id = + modifier_cache.simulation_cache_by_id; + Map> new_cache_by_id; for (const NodesModifierBake &bake : Span{nmd.bakes, nmd.bakes_num}) { - std::unique_ptr node_cache; - std::unique_ptr *old_node_cache_ptr = old_cache_by_id.lookup_ptr(bake.id); + std::unique_ptr node_cache; + std::unique_ptr *old_node_cache_ptr = old_cache_by_id.lookup_ptr( + bake.id); if (old_node_cache_ptr == nullptr) { - node_cache = std::make_unique(); + node_cache = std::make_unique(); } else { node_cache = std::move(*old_node_cache_ptr); } new_cache_by_id.add(bake.id, std::move(node_cache)); } - modifier_cache.cache_by_id = std::move(new_cache_by_id); + modifier_cache.simulation_cache_by_id = std::move(new_cache_by_id); } static void update_bakes_from_node_group(NodesModifierData &nmd) @@ -752,7 +754,8 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { if (depsgraph_is_active_) { /* Invalidate data on user edits. */ if (nmd.modifier.flag & eModifierFlag_UserModified) { - for (std::unique_ptr &node_cache : modifier_cache_->cache_by_id.values()) + for (std::unique_ptr &node_cache : + modifier_cache_->simulation_cache_by_id.values()) { if (node_cache->cache_status != bake::CacheStatus::Baked) { node_cache->cache_status = bake::CacheStatus::Invalid; @@ -761,10 +764,10 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { } this->reset_invalid_node_bakes(); } - for (const std::unique_ptr &node_cache_ptr : - modifier_cache_->cache_by_id.values()) + for (const std::unique_ptr &node_cache_ptr : + modifier_cache_->simulation_cache_by_id.values()) { - const bake::NodeCache &node_cache = *node_cache_ptr; + const bake::SimulationNodeCache &node_cache = *node_cache_ptr; if (node_cache.cache_status == bake::CacheStatus::Invalid) { has_invalid_simulation_ = true; break; @@ -774,9 +777,9 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { void reset_invalid_node_bakes() { - for (auto item : modifier_cache_->cache_by_id.items()) { + for (auto item : modifier_cache_->simulation_cache_by_id.items()) { const int id = item.key; - bake::NodeCache &node_cache = *item.value; + bake::SimulationNodeCache &node_cache = *item.value; if (node_cache.cache_status != bake::CacheStatus::Invalid) { continue; } @@ -820,11 +823,12 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { void init_simulation_info(const int zone_id, nodes::SimulationZoneBehavior &zone_behavior) const { - if (!modifier_cache_->cache_by_id.contains(zone_id)) { + if (!modifier_cache_->simulation_cache_by_id.contains(zone_id)) { /* Should have been created in #update_existing_bake_caches. */ return; } - bake::NodeCache &node_cache = *modifier_cache_->cache_by_id.lookup(zone_id); + bake::SimulationNodeCache &node_cache = *modifier_cache_->simulation_cache_by_id.lookup( + zone_id); const IndexRange sim_frame_range = *bake::get_node_bake_frame_range( *scene_, *ctx_.object, nmd_, zone_id); const SubFrame sim_start_frame{int(sim_frame_range.first())}; @@ -945,7 +949,7 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { } } - FrameIndices get_frame_indices(const bake::NodeCache &node_cache) const + FrameIndices get_frame_indices(const bake::SimulationNodeCache &node_cache) const { FrameIndices frame_indices; if (!node_cache.frame_caches.is_empty()) { @@ -983,7 +987,7 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { zone_behavior.output.emplace(); } - void output_store_frame_cache(bake::NodeCache &node_cache, + void output_store_frame_cache(bake::SimulationNodeCache &node_cache, nodes::SimulationZoneBehavior &zone_behavior) const { auto &store_new_state_info = zone_behavior.output.emplace(); @@ -998,7 +1002,7 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { }; } - void store_as_prev_items(bake::NodeCache &node_cache, + void store_as_prev_items(bake::SimulationNodeCache &node_cache, nodes::SimulationZoneBehavior &zone_behavior) const { auto &store_new_state_info = zone_behavior.output.emplace(); @@ -1015,7 +1019,7 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { } void read_from_cache(const FrameIndices &frame_indices, - bake::NodeCache &node_cache, + bake::SimulationNodeCache &node_cache, nodes::SimulationZoneBehavior &zone_behavior) const { if (frame_indices.prev) { @@ -1050,7 +1054,7 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { } void read_single(const int frame_index, - bake::NodeCache &node_cache, + bake::SimulationNodeCache &node_cache, nodes::SimulationZoneBehavior &zone_behavior) const { bake::FrameCache &frame_cache = *node_cache.frame_caches[frame_index]; @@ -1061,7 +1065,7 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { void read_interpolated(const int prev_frame_index, const int next_frame_index, - bake::NodeCache &node_cache, + bake::SimulationNodeCache &node_cache, nodes::SimulationZoneBehavior &zone_behavior) const { bake::FrameCache &prev_frame_cache = *node_cache.frame_caches[prev_frame_index]; @@ -1076,7 +1080,8 @@ class NodesModifierSimulationParams : public nodes::GeoNodesSimulationParams { read_interpolated_info.next_state = next_frame_cache.state; } - void ensure_bake_loaded(bake::NodeCache &node_cache, bake::FrameCache &frame_cache) const + void ensure_bake_loaded(bake::SimulationNodeCache &node_cache, + bake::FrameCache &frame_cache) const { if (!frame_cache.state.items_by_id.is_empty()) { 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 424c0a1081c..63fa873adc1 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc @@ -780,10 +780,10 @@ static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) if (nmd.runtime->cache) { const bke::bake::ModifierCache &cache = *nmd.runtime->cache; std::lock_guard lock{cache.mutex}; - if (const std::unique_ptr *node_cache_ptr = cache.cache_by_id.lookup_ptr( - *bake_id)) + if (const std::unique_ptr *node_cache_ptr = + cache.simulation_cache_by_id.lookup_ptr(*bake_id)) { - const bke::bake::NodeCache &node_cache = **node_cache_ptr; + const bke::bake::SimulationNodeCache &node_cache = **node_cache_ptr; if (node_cache.cache_status == bke::bake::CacheStatus::Baked && !node_cache.frame_caches.is_empty()) {