Geometry Nodes: refactor storage for socket values #116231

Merged
Jacques Lucke merged 27 commits from JacquesLucke/blender:generic-socket-value-variant into main 2023-12-17 14:00:17 +01:00
Member

This refactors SocketValueVariant with the following goals in mind:

  • Support type erasure so that not all users of SocketValueVariant have to know about all the types sockets can have.
  • Move towards supporting "rainbow sockets" which are sockets whoose type is only known at run-time.
  • Reduce complexity when dealing with socket values in general. Previously, one had to use SocketValueVariantCPPType a lot to manage uninitialized memory. This is better abstracted away now.

One related change that I had to do that I didn't see coming at first was that I had to refactor set_default_remaining_outputs because now the default value of a SocketValueVariant would not contain any value. Previously, it was initialized the zero-value of the template parameter. Similarly, I had to change how implicit conversions are created, because comparing the CPPType of linked sockets was not enough anymore to determine if a conversion is necessary.

We could potentially use SocketValueVariant for the remaining socket types in the future as well. Not entirely sure if that helps yet. SocketValueVariant can easily be adapted to make that work though. That would also justify the name "SocketValueVariant" better.

This refactors `SocketValueVariant` with the following goals in mind: * Support type erasure so that not all users of `SocketValueVariant` have to know about all the types sockets can have. * Move towards supporting "rainbow sockets" which are sockets whoose type is only known at run-time. * Reduce complexity when dealing with socket values in general. Previously, one had to use `SocketValueVariantCPPType` a lot to manage uninitialized memory. This is better abstracted away now. One related change that I had to do that I didn't see coming at first was that I had to refactor `set_default_remaining_outputs` because now the default value of a `SocketValueVariant` would not contain any value. Previously, it was initialized the zero-value of the template parameter. Similarly, I had to change how implicit conversions are created, because comparing the `CPPType` of linked sockets was not enough anymore to determine if a conversion is necessary. We could potentially use `SocketValueVariant` for the remaining socket types in the future as well. Not entirely sure if that helps yet. `SocketValueVariant` can easily be adapted to make that work though. That would also justify the name "SocketValueVariant" better.
Jacques Lucke added 20 commits 2023-12-15 19:41:48 +01:00
Jacques Lucke requested review from Lukas Tönne 2023-12-15 19:45:41 +01:00
Jacques Lucke requested review from Hans Goudey 2023-12-15 19:45:41 +01:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey reviewed 2023-12-16 02:25:23 +01:00
Hans Goudey left a comment
Member

Looks great overall, especially how we can pass the type and the value with one variable now. Just a couple points inline.

Out of curiosity, did you test to see if there was a performance impact in some of the test files that emphasize per-node overhead?

Looks great overall, especially how we can pass the type and the value with one variable now. Just a couple points inline. Out of curiosity, did you test to see if there was a performance impact in some of the test files that emphasize per-node overhead?
@ -9,3 +9,3 @@
#pragma once
#include "FN_field.hh"
#include "DNA_node_types.h"
Member

DNA_node_types.h is a pretty large header, might be nice to avoid including it everywhere just for eNodeSocketDatatype. In practice it's probably already included nearly everywhere anyway, but in principle it's nice to avoid this. A few potential solutions for that I think:

  • Move these enums to blenkernel headers, use enum class at the same time
  • Support enum class :int8_t in DNA so we can use forward declarations.
  • Add a DNA_node_enums.h similar to other DNA headers (that's probably simplest to do for now)

Long as we agree on one of them, seems fine not to do anything for this PR :)

`DNA_node_types.h` is a pretty large header, might be nice to avoid including it everywhere just for `eNodeSocketDatatype`. In practice it's probably already included nearly everywhere anyway, but in principle it's nice to avoid this. A few potential solutions for that I think: - Move these enums to blenkernel headers, use `enum class` at the same time - Support `enum class :int8_t` in DNA so we can use forward declarations. - Add a `DNA_node_enums.h` similar to other DNA headers (that's probably simplest to do for now) Long as we agree on one of them, seems fine not to do anything for this PR :)
Author
Member

I think the right solution is to split up dna headers.

I think the right solution is to split up dna headers.
@ -15,2 +19,2 @@
/* -------------------------------------------------------------------- */
/** \name Value or Field Class
/**
* #SocketValueVariant is used by geometry nodes to pass data between nodes. Specifically, it is
Member

Maybe used by the lazy function evaluator (geometry nodes) to help justify the generic name of the file?

Maybe `used by the lazy function evaluator (geometry nodes)` to help justify the generic name of the file?
JacquesLucke marked this conversation as resolved
@ -64,0 +118,4 @@
bool is_context_dependent_field() const;
/**
* Cnvert the stored value into a single value. For simple value access, this is not necessary,
Member

Cnvert -> Convert

`Cnvert` -> `Convert`
JacquesLucke marked this conversation as resolved
@ -315,3 +315,2 @@
{
BLI_assert(this->is<T>());
return *static_cast<std::decay_t<T> *>(this->get());
return const_cast<T &>(const_cast<const Any *>(this)->get<T>());
Member

Would like to see some justification of the const casts in a comment, it's raising my eyebrows right now otherwise.

Would like to see some justification of the const casts in a comment, it's raising my eyebrows right now otherwise.
JacquesLucke marked this conversation as resolved
@ -382,0 +382,4 @@
/**
* Outputs the default value of each output socket that has not been output yet.
*/
void set_default_remaining_node_outputs(lf::Params &params, const bNode &node);
Member

Why does this have to work at the bNode level now? I'd think it could just use the lazy function directly. Maybe that's what you're getting at in the description, but I don't see how that leads to this now.

Why does this have to work at the `bNode` level now? I'd think it could just use the lazy function directly. Maybe that's what you're getting at in the description, but I don't see how that leads to this now.
Author
Member
/**
 * Outputs the default value of each output socket that has not been output yet. This needs the
 * #bNode because otherwise the default values for the outputs are not known. The lazy-function
 * parameters do not differentiate between e.g. float and vector sockets. The #SocketValueVariant
 * type is used for both.
 */
``` /** * Outputs the default value of each output socket that has not been output yet. This needs the * #bNode because otherwise the default values for the outputs are not known. The lazy-function * parameters do not differentiate between e.g. float and vector sockets. The #SocketValueVariant * type is used for both. */ ```
Jacques Lucke added 6 commits 2023-12-16 13:36:16 +01:00
Author
Member

Out of curiosity, did you test to see if there was a performance impact in some of the test files that emphasize per-node overhead?

Right now I'm measuring about 5% slowdown in the many math nodes benchmark (with ~400k math node evaluations on single values). The seems to be mostly caused by conversions between socket and cpp types. I think we can probably optimize those away for the most part by spending some time optimizing the individual uses of get_single_ptr and new_single_for_write.

> Out of curiosity, did you test to see if there was a performance impact in some of the test files that emphasize per-node overhead? Right now I'm measuring about 5% slowdown in the many math nodes benchmark (with ~400k math node evaluations on single values). The seems to be mostly caused by conversions between socket and cpp types. I think we can probably optimize those away for the most part by spending some time optimizing the individual uses of `get_single_ptr` and `new_single_for_write`.
Jacques Lucke added 1 commit 2023-12-16 13:41:24 +01:00
Hans Goudey approved these changes 2023-12-16 14:46:51 +01:00
Jacques Lucke merged commit e1d0d70911 into main 2023-12-17 14:00:17 +01:00
Jacques Lucke deleted branch generic-socket-value-variant 2023-12-17 14:00:19 +01: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 project
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#116231
No description provided.