From 64f32c61709bfd17f552c91f49074b8615be885b Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 8 May 2023 10:55:34 -0400 Subject: [PATCH 1/4] Cleanup: Add comments to simulation state header --- .../blenkernel/BKE_simulation_state.hh | 42 ++++++++++++------- .../blenkernel/intern/simulation_state.cc | 5 --- .../intern/simulation_state_serialize.cc | 3 +- .../nodes/node_geo_simulation_output.cc | 4 +- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/source/blender/blenkernel/BKE_simulation_state.hh b/source/blender/blenkernel/BKE_simulation_state.hh index db059764abc..bc4be11b132 100644 --- a/source/blender/blenkernel/BKE_simulation_state.hh +++ b/source/blender/blenkernel/BKE_simulation_state.hh @@ -18,23 +18,15 @@ class SimulationStateItem { }; class GeometrySimulationStateItem : public SimulationStateItem { - private: - GeometrySet geometry_; - public: - GeometrySimulationStateItem(GeometrySet geometry); - - const GeometrySet &geometry() const - { - return geometry_; - } - - GeometrySet &geometry() - { - return geometry_; - } + GeometrySet geometry; }; +/** + * References a field input/output that becomes an attribute as part of the simulation state. + * The attribute is actually stored in a #GeometrySimulationStateItem, so this just references + * the attribute's name. + */ class AttributeSimulationStateItem : public SimulationStateItem { private: std::string name_; @@ -48,6 +40,7 @@ class AttributeSimulationStateItem : public SimulationStateItem { } }; +/** Storage for a single value of a trivial type like `float`, `int`, etc. */ class PrimitiveSimulationStateItem : public SimulationStateItem { private: const CPPType &type_; @@ -81,12 +74,19 @@ class StringSimulationStateItem : public SimulationStateItem { } }; +/** + * Storage of values for a single simulation input and output node pair. + * Used as a cache to allow random access in time, and as an intermediate form before data is + * baked. + */ class SimulationZoneState { public: Map> item_by_identifier; }; +/** Identifies a simulation zone (input and output node pair) used by a modifier. */ struct SimulationZoneID { + /** Every node identifier in the heirarchy of compute contexts. */ Vector node_ids; uint64_t hash() const @@ -100,6 +100,10 @@ struct SimulationZoneID { } }; +/** + * Stores a single frame of simulation states for all simulation zones in a modifier's node + * hierarchy. + */ class ModifierSimulationState { private: mutable bool bake_loaded_; @@ -122,8 +126,14 @@ struct ModifierSimulationStateAtFrame { }; enum class CacheState { + /** The cache is up-to-date with the inputs. */ Valid, + /** + * Nodes or input values have changed since the cache was created, i.e. the output would be + * different if the simulation was run again. + */ Invalid, + /** The cache has been baked and will not be invalidated by changing inputs. */ Baked, }; @@ -136,6 +146,10 @@ struct StatesAroundFrame { class ModifierSimulationCache { private: Vector> states_at_frames_; + /** + * Used for baking to deduplicate arrays when writing to storage. Sharing info must be kept + * alive for multiple frames to detect if each data array's version has changed. + */ std::unique_ptr bdata_sharing_; friend ModifierSimulationState; diff --git a/source/blender/blenkernel/intern/simulation_state.cc b/source/blender/blenkernel/intern/simulation_state.cc index 703a174648c..d832816703a 100644 --- a/source/blender/blenkernel/intern/simulation_state.cc +++ b/source/blender/blenkernel/intern/simulation_state.cc @@ -15,11 +15,6 @@ namespace blender::bke::sim { -GeometrySimulationStateItem::GeometrySimulationStateItem(GeometrySet geometry) - : geometry_(std::move(geometry)) -{ -} - PrimitiveSimulationStateItem::PrimitiveSimulationStateItem(const CPPType &type, const void *value) : type_(type) { diff --git a/source/blender/blenkernel/intern/simulation_state_serialize.cc b/source/blender/blenkernel/intern/simulation_state_serialize.cc index 4b0054006a3..070ca85901d 100644 --- a/source/blender/blenkernel/intern/simulation_state_serialize.cc +++ b/source/blender/blenkernel/intern/simulation_state_serialize.cc @@ -835,8 +835,7 @@ void serialize_modifier_simulation_state(const ModifierSimulationState &state, { io_state_item->append_str("type", "GEOMETRY"); - const GeometrySet &geometry = geometry_state_item->geometry(); - + const GeometrySet &geometry = geometry_state_item->geometry; auto io_geometry = serialize_geometry_set(geometry, bdata_writer, bdata_sharing); io_state_item->append("data", io_geometry); } 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 ee15aa2f1d2..cda46948bc9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc @@ -181,7 +181,7 @@ void simulation_state_to_values(const Span node_simulation_i if (const auto *geo_state_item = dynamic_cast(&state_item)) { - GeometrySet *geometry = new (r_output_value) GeometrySet(geo_state_item->geometry()); + GeometrySet *geometry = new (r_output_value) GeometrySet(geo_state_item->geometry); geometries.append(geometry); } else { @@ -282,7 +282,7 @@ void values_to_simulation_state(const Span node_simulation_i GeometrySet &geometry = *static_cast(input_value); auto geometry_state_item = std::make_unique( std::move(geometry)); - stored_geometries.append(&geometry_state_item->geometry()); + stored_geometries.append(&geometry_state_item->geometry); state_item = std::move(geometry_state_item); break; } -- 2.30.2 From 0da53d4eb17cfe8e66e7cd3b9d727cbce44b40e1 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 8 May 2023 12:23:22 -0400 Subject: [PATCH 2/4] Add comments to paths --- source/blender/blenkernel/BKE_simulation_state.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/blender/blenkernel/BKE_simulation_state.hh b/source/blender/blenkernel/BKE_simulation_state.hh index bc4be11b132..4eb30324e52 100644 --- a/source/blender/blenkernel/BKE_simulation_state.hh +++ b/source/blender/blenkernel/BKE_simulation_state.hh @@ -112,7 +112,9 @@ class ModifierSimulationState { ModifierSimulationCache *owner_; mutable std::mutex mutex_; Map> zone_states_; + /** File path to folder containing baked meta-data. */ std::optional meta_path_; + /** File path to folder containing baked data. */ std::optional bdata_dir_; const SimulationZoneState *get_zone_state(const SimulationZoneID &zone_id) const; -- 2.30.2 From b4ae895baf6be6878d9223de2bd34547f2c544a6 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 8 May 2023 12:23:46 -0400 Subject: [PATCH 3/4] sharing is used for reading and writing --- source/blender/blenkernel/BKE_simulation_state.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/BKE_simulation_state.hh b/source/blender/blenkernel/BKE_simulation_state.hh index 4eb30324e52..640f6cdc8cb 100644 --- a/source/blender/blenkernel/BKE_simulation_state.hh +++ b/source/blender/blenkernel/BKE_simulation_state.hh @@ -149,8 +149,8 @@ class ModifierSimulationCache { private: Vector> states_at_frames_; /** - * Used for baking to deduplicate arrays when writing to storage. Sharing info must be kept - * alive for multiple frames to detect if each data array's version has changed. + * Used for baking to deduplicate arrays when writing and writing from storage. Sharing info + * must be kept alive for multiple frames to detect if each data array's version has changed. */ std::unique_ptr bdata_sharing_; -- 2.30.2 From 9227ac692ac618ea7be143d8f45169a25b16ec25 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 8 May 2023 12:24:37 -0400 Subject: [PATCH 4/4] Fix typo --- source/blender/blenkernel/BKE_simulation_state.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/BKE_simulation_state.hh b/source/blender/blenkernel/BKE_simulation_state.hh index 640f6cdc8cb..6ae9bc53ae7 100644 --- a/source/blender/blenkernel/BKE_simulation_state.hh +++ b/source/blender/blenkernel/BKE_simulation_state.hh @@ -86,7 +86,7 @@ class SimulationZoneState { /** Identifies a simulation zone (input and output node pair) used by a modifier. */ struct SimulationZoneID { - /** Every node identifier in the heirarchy of compute contexts. */ + /** Every node identifier in the hierarchy of compute contexts. */ Vector node_ids; uint64_t hash() const -- 2.30.2