Geometry Nodes: refactor simulation storage and how simulation nodes access it #111623

Merged
Jacques Lucke merged 41 commits from JacquesLucke/blender:better-simulation-state-api into main 2023-08-31 16:28:11 +02:00
Member

Goals of the refactor:

  • Internal support for baking individual simulation zones (not exposed in the UI yet).
  • More well-defined access to simulation data in geometry nodes. Especially, it should be more obvious where data is modified. A similar approach should also work for the Bake node.

Previously, there were a bunch of simulation specific properties in GeoNodesModifierData and then the simulation input and output nodes would have to figure out what to do with that data. Now, there is a new GeoNodesSimulationParams which controls the behavior of simulation zones. Contrary to before, different simulation zones can now be handled independently, even if that is not really used yet. GeoNodesSimulationParams has to be subclassed by a user of the geometry nodes API. The subclass controls what each simulation input and output node does. This some of the logic that was part of the node before, into the modifier.

The way we store simulation data is "transposed". Previously, we stored zone data per frame, but now we store frame data per zone. This allows different zones to be more independent. Consequently, the way the simulation cache is accessed changed. I kept things simpler for now, avoiding many of the methods we had before, and directly accessing the data more often which is often simple enough. This change also makes it theoretically possible to store baked data for separate zones independently. A downside of this is, that existing baked data can't be read anymore. We don't really have compatibility guarantees for this format yet, so it's ok. Users will have to bake again. The bake folder for the modifier now contains an extra subfolder for every zone.

Drawing the cached/baked frames in the timeline is less straight forward now. Currently, it just draws the state of one of the zones, which usually is identical to that of all other zones. This will change in the future though, and then the timeline drawing also needs some new UI work.

There are a few things that could be worked on after this patch:

  • Move the writing and reading of baked storage on/from disk to a more centralized position.
  • Improve the namespaces for bake/simulation stuff in blenkernel.
  • Investigate the use of implicit sharing to better decouple different depsgraph (instead of the std::shared_ptr that is used currently).
Goals of the refactor: * Internal support for baking individual simulation zones (not exposed in the UI yet). * More well-defined access to simulation data in geometry nodes. Especially, it should be more obvious where data is modified. A similar approach should also work for the Bake node. Previously, there were a bunch of simulation specific properties in `GeoNodesModifierData` and then the simulation input and output nodes would have to figure out what to do with that data. Now, there is a new `GeoNodesSimulationParams` which controls the behavior of simulation zones. Contrary to before, different simulation zones can now be handled independently, even if that is not really used yet. `GeoNodesSimulationParams` has to be subclassed by a user of the geometry nodes API. The subclass controls what each simulation input and output node does. This some of the logic that was part of the node before, into the modifier. The way we store simulation data is "transposed". Previously, we stored zone data per frame, but now we store frame data per zone. This allows different zones to be more independent. Consequently, the way the simulation cache is accessed changed. I kept things simpler for now, avoiding many of the methods we had before, and directly accessing the data more often which is often simple enough. This change also makes it theoretically possible to store baked data for separate zones independently. A downside of this is, that existing baked data can't be read anymore. We don't really have compatibility guarantees for this format yet, so it's ok. Users will have to bake again. The bake folder for the modifier now contains an extra subfolder for every zone. Drawing the cached/baked frames in the timeline is less straight forward now. Currently, it just draws the state of one of the zones, which usually is identical to that of all other zones. This will change in the future though, and then the timeline drawing also needs some new UI work. There are a few things that could be worked on after this patch: * Move the writing and reading of baked storage on/from disk to a more centralized position. * Improve the namespaces for bake/simulation stuff in blenkernel. * Investigate the use of implicit sharing to better decouple different depsgraph (instead of the `std::shared_ptr` that is used currently).
Jacques Lucke added 16 commits 2023-08-28 17:22:17 +02:00
Jacques Lucke added 1 commit 2023-08-28 17:31:36 +02:00
Jacques Lucke added 5 commits 2023-08-29 14:26:45 +02:00
Jacques Lucke added 3 commits 2023-08-29 14:56:47 +02:00
Jacques Lucke added 1 commit 2023-08-30 10:39:11 +02:00
Jacques Lucke added 8 commits 2023-08-30 14:49:47 +02:00
Jacques Lucke added 1 commit 2023-08-30 14:59:22 +02:00
Jacques Lucke added 1 commit 2023-08-30 15:45:38 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
e9509eb760
cleanup magic number
Author
Member

@blender-bot build

@blender-bot build
Jacques Lucke changed title from WIP: Geometry Nodes: refactor simulation storage and how simulation nodes access it to Geometry Nodes: refactor simulation storage and how simulation nodes access it 2023-08-30 15:53:55 +02:00
Jacques Lucke requested review from Hans Goudey 2023-08-30 15:54:04 +02:00
Hans Goudey requested changes 2023-08-30 17:22:31 +02:00
Hans Goudey left a comment
Member

I guess mainly I'd like to see a few more comments. Even if they feel obvious, there's a lot going on here, and the functionality is spread out much more than usual. The only places that's a blocking comment for me I've noted in comments though.

What's the reasoning for splitting NodesModifierSimulationParams and GeoNodesSimulationParams? I guess you're thinking we might use simulation without the modifier in the future? That makes sense to me, just want to be sure.

I guess mainly I'd like to see a few more comments. Even if they feel obvious, there's a lot going on here, and the functionality is spread out much more than usual. The only places that's a blocking comment for me I've noted in comments though. What's the reasoning for splitting `NodesModifierSimulationParams` and `GeoNodesSimulationParams`? I guess you're thinking we might use simulation without the modifier in the future? That makes sense to me, just want to be sure.
@ -88,1 +32,3 @@
const ModifierSimulationStateAtFrame *next = nullptr;
struct SimulationZoneFrameCache {
SubFrame frame;
Map<int, std::unique_ptr<BakeItem>> items;
Member

Here and below, add a comment like "map from X to Y". That's helpful because the int here isn't so helpful to the reader.

Here and below, add a comment like "map from X to Y". That's helpful because the int here isn't so helpful to the reader.
Member

Hmm, I don't see a comment here :/ sorry if I'm missing something.

Hmm, I don't see a comment here :/ sorry if I'm missing something.
@ -13,6 +13,7 @@
#include <cstdlib>
#include <cstring>
#include "BLI_binary_search.hh"
Member

Unused include?

Unused include?
JacquesLucke marked this conversation as resolved
@ -43,0 +57,4 @@
Map<int, std::unique_ptr<bke::BakeItem>> prev_items;
};
using SimInputBehavior = std::variant<PassThrough, OutputCopy, OutputMove>;
Member

I find these type names and namespaces redundant. What about:

namespace sim_output {
struct PassThrough {
};
...
using Behavior = std::variant<PassThrough, OutputCopy, OutputMove>; 
}

I think that gets the same thing across without the redundancy

I find these type names and namespaces redundant. What about: ``` namespace sim_output { struct PassThrough { }; ... using Behavior = std::variant<PassThrough, OutputCopy, OutputMove>; } ``` I think that gets the same thing across without the redundancy
JacquesLucke marked this conversation as resolved
@ -43,0 +67,4 @@
};
struct StoreAndPassThrough {
std::function<void(Map<int, std::unique_ptr<bke::BakeItem>>)> store_fn;
Member

Reading this code, it's a bit frustrating to encounter something like this without any comment. There's clearly a lot going on, and some reason for a function object, but to understand why I have to flip through the places it's assigned and used. That gives me the impression it's for code reuse between the "realtime cache" and "frame cache" versions? But it's hard to tell.

Reading this code, it's a bit frustrating to encounter something like this without any comment. There's clearly a lot going on, and some reason for a function object, but to understand why I have to flip through the places it's assigned and used. That gives me the impression it's for code reuse between the "realtime cache" and "frame cache" versions? But it's hard to tell.
JacquesLucke marked this conversation as resolved
Hans Goudey added this to the Nodes & Physics project 2023-08-30 17:22:55 +02:00
Hans Goudey added the
Interest
Geometry Nodes
label 2023-08-30 17:23:02 +02:00
Author
Member

What's the reasoning for splitting NodesModifierSimulationParams and GeoNodesSimulationParams?

Yes right, we already talked about that we would like to use simulations for e.g. modal operators, which don't have a modifier.

> What's the reasoning for splitting `NodesModifierSimulationParams` and `GeoNodesSimulationParams`? Yes right, we already talked about that we would like to use simulations for e.g. modal operators, which don't have a modifier.
Jacques Lucke added 5 commits 2023-08-31 12:39:48 +02:00
Hans Goudey approved these changes 2023-08-31 14:57:05 +02:00
Hans Goudey left a comment
Member

The comments you added since last time help so much, I think they'll save a lot of time for many people over the years. :)

The comments you added since last time help so much, I think they'll save a lot of time for many people over the years. :)
@ -40,6 +42,92 @@ namespace blender::nodes {
using lf::LazyFunction;
using mf::MultiFunction;
/** The structs in here describe the different possible behaviors of a simulation input node. */
Member

Thanks, this is so much more friendly now!

Thanks, this is so much more friendly now!
Author
Member

@blender-bot build

@blender-bot build
Jacques Lucke merged commit e92c59bc9b into main 2023-08-31 16:28:11 +02:00
Jacques Lucke deleted branch better-simulation-state-api 2023-08-31 16:28:13 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#111623
No description provided.