WIP: Field type inferencing using a constraint solver method #120420

Draft
Lukas Tönne wants to merge 51 commits from LukasTonne/blender:socket-type-inference into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Refactoring of the field type inferencing mechanism for node trees using a general-purpose constraint solver.

Field types can be described as a set of discrete states (single value or fields), with constraints between them (which socket connections are valid). The job of the inferencing mechanism is to determine possible states for each internal socket, as well as produce the FieldInferencingInterface for the tree as a whole.

The legacy algorithm resolves this using left-to-right and right-to-left passes based on topological node sorting. This works reasonably well, but gets complicated by recent addition of loop zones and planned features such

  • Grid socket types
  • List sockets
  • Data type inferencing ("rainbow" sockets)

The addition of zones broke the simple topological dependencies between nodes and requires repetition of the entire solver to ensure all constraints are satisfied. Even before that there were small solver loops nested inside the broad topological passes. The implementation also mixes socket state and constraint properties (always_single, is_field_source). Taken together this results in a complicated system that is hard to understand and quite verbose.

This refactoring adds a general-purpose solver for constraint satisfaction problems (CSP) in BLI. This solver is agnostic to the specific field type inference problem (see the unit tests for some examples of general use). This solver is based on the AC3 algorithm, which is a common method of solving such discrete constraint systems. It is well suited to the problem at hand due to the small domain size.

The legacy solver is moved into a separate file. It is still used when the experimental feature is disabled, and also serves as "ground truth" for verifying the result of the new solver.

Refactoring of the field type inferencing mechanism for node trees using a general-purpose constraint solver. Field types can be described as a set of discrete states (single value or fields), with _constraints_ between them (which socket connections are valid). The job of the inferencing mechanism is to determine possible states for each internal socket, as well as produce the `FieldInferencingInterface` for the tree as a whole. The legacy algorithm resolves this using left-to-right and right-to-left passes based on topological node sorting. This works reasonably well, but gets complicated by recent addition of loop zones and planned features such - Grid socket types - List sockets - Data type inferencing ("rainbow" sockets) The addition of zones broke the simple topological dependencies between nodes and requires repetition of the entire solver to ensure all constraints are satisfied. Even before that there were small solver loops nested inside the broad topological passes. The implementation also mixes socket _state_ and _constraint properties_ (`always_single`, `is_field_source`). Taken together this results in a complicated system that is hard to understand and quite verbose. This refactoring adds a general-purpose solver for _constraint satisfaction problems_ ([CSP](https://en.wikipedia.org/wiki/Constraint_satisfaction_problem)) in BLI. This solver is agnostic to the specific field type inference problem (see the [unit tests](https://projects.blender.org/LukasTonne/blender/src/branch/socket-type-inference/source/blender/blenlib/tests/BLI_constraint_satisfaction_test.cc) for some examples of general use). This solver is based on the [AC3 algorithm](https://en.wikipedia.org/wiki/AC-3_algorithm), which is a common method of solving such discrete constraint systems. It is well suited to the problem at hand due to the small domain size. The legacy solver is moved into a separate file. It is still used when the experimental feature is disabled, and also serves as "ground truth" for verifying the result of the new solver.
Lukas Tönne added 47 commits 2024-04-09 11:29:43 +02:00
fbcfd48d2a Replace int variable indexes with formalized (Mutable)VariableKey.
This helps ensure correctness and clarifies which of the variables is
being modified.
e129d1b99c Add link constraints in the output->input direction.
This forces inputs to become fields when connected outputs can only be
fields (field sources).

There are still missing internal constraints that unify field types
within a single node.
b3128a83e7 Use the gather function to determine group interface.
The states of internal nodes include superpositions of single value and
field to indicate that a socket _can_ be either, but the overall group
interface should only include the concrete connected types. A single
value socket connected to a group output creates a single-or-field
socket, while the group interface should consider it a single value.
The `find_group_output_dependencies` has to be used to determine the
interface types for the tree as a whole, rather than the state of
internal sockets.
Lukas Tönne added this to the Nodes & Physics project 2024-04-09 11:29:46 +02:00
Lukas Tönne added 1 commit 2024-04-19 14:56:18 +02:00
Lukas Tönne added 2 commits 2024-04-21 08:45:48 +02:00
Lukas Tönne added 1 commit 2024-04-28 11:16:42 +02:00
This pull request has changes conflicting with the target branch.
  • source/blender/editors/space_node/node_ops.cc

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u socket-type-inference:LukasTonne-socket-type-inference
git checkout LukasTonne-socket-type-inference
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
1 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#120420
No description provided.