Commit Graph

22 Commits

Author SHA1 Message Date
Jacques Lucke
70ce733b8c Refactor: Nodes: add general NodeComputeContext
This is used as base class for the compute contexts for group and evaluate
closure nodes. Furthermore, in the future this can be used for the compute
context that is passed into field evaluation.

Pull Request: https://projects.blender.org/blender/blender/pulls/139377
2025-05-24 10:39:24 +02:00
Jacques Lucke
5457cca3de Nodes: auto-hide unused inputs if usage depends on menu
Previously, when a socket was detected to be unused, it was just grayed out.
This patch adds support for automatically hiding unused sockets based on this
convention: Menu inputs control visibility while other inputs only control
whether something is grayed out.

More specifically, an input is visible if any of these conditions is met:
* It affects the output currently.
* It never affects the output. In this case its usage does not depend on any
  menu input.
* It is used if all non-menu inputs are considered to be unknown.

In the future, we could support customizing which inputs are allowed to control
visibility. For now it's good to use the convention that Blender generally
follows itself.

As before, panels are grayed out if they only contain grayed out sockets and
panels are hidden when they don't contain any visible sockets.

Hiding inputs works in group nodes, the Geometry Nodes modifier and node
operators. In theory it will work for all node tree types, but since only
Geometry Nodes supports the Menu Switch node currently, this patch currently
only makes a difference there.

The implementation reuses the existing `SocketUsageInferencer` with a different
sets of inputs. So no new core-inferencing logic was needed.

Design task: #132706.

Pull Request: https://projects.blender.org/blender/blender/pulls/138186
2025-05-22 04:48:43 +02:00
Campbell Barton
43af16a4c1 Cleanup: spelling in comments, correct comment block formatting
Also use doxygen comments more consistently.
2025-05-01 11:44:33 +10:00
Jacques Lucke
b6342a7e94 Cleanup: simplify allocating buffers for a CPPType
This reduces verbosity when using `LinearAllocator` or `ResourceScope` to
allocate values for a `CPPType`. Now, this is simplified and one also does not
have to manually add a destructor call anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/137685
2025-04-17 22:01:07 +02:00
Jacques Lucke
7f1a99e862 Refactor: BLI: Make some CPPType properties public instead of using methods
This makes accessing these properties more convenient. Since we only ever have
const references to `CPPType`, there isn't really a benefit to using methods to
avoid mutation.

Pull Request: https://projects.blender.org/blender/blender/pulls/137482
2025-04-14 17:48:17 +02:00
Jacques Lucke
e8877df863 Cleanup: simplify method name 2025-04-14 13:57:31 +02:00
Jacques Lucke
aab2b6004b Geometry Nodes: add compute context cache
For various purposes we traverse the computation done by a node tree (e.g. for
gizmos and socket usage infeferencing). For that we generally have to keep track
of the compute context we're in at any given time. During the traversal, it's
common to enter and exist the same compute contexts multiple times. Currently,
we'd always build a new compute context when that happens. That happens even
though the old one is generally still around, because other data may reference
it. This patch implements a `ComputeContextHash` type that avoids rebuilding the
same compute contexts over and over again.

I'm considering to also replace the usage of `ComputeContextBuilder` with this
cache somehow, but will see how that works out.

The reason I'm working on this now is that I have to traverse the node tree a
bit again to find where closures might be evaluated. I wanted to be able to
cache the compute contexts for a while already.

Pull Request: https://projects.blender.org/blender/blender/pulls/137360
2025-04-11 21:36:41 +02:00
Lukas Tönne
4b2fc36671 Fix missing topology cache in during node tree updates
Under some circumstances the `value_task` run by node tree updates
needs access to a node group topology cache. Unlike the `usage_task`
it was not ensuring the cache for the node group, so a stale cache
could be used (triggers assert).

Pull Request: https://projects.blender.org/blender/blender/pulls/136878
2025-04-02 12:02:41 +02:00
Hans Goudey
2663c840df Geometry Nodes: Improve performance with many inputs
Resolves #136183

To avoid quadratic worst case runtime when gathering values from
the modifier properties, build a temporary VectorSet of the modifier's
IDProperties. In the file from #136183, this change improves playback
performance by 1.4x for me, from 50 to 70ms.

Ideally IDProperty groups would have constant time lookup on their
own, but that's a much larger change, and this smaller change for just
Geometry Nodes is not so invasive.

Pull Request: https://projects.blender.org/blender/blender/pulls/136463
2025-03-25 15:40:32 +01:00
Jacques Lucke
0f9ef0eefc Fix: Nodes: unavailable sockets are always unused 2025-03-24 19:36:46 +01:00
Jacques Lucke
6624cc5634 Nodes: take panel toggles in builtin nodes into account in socket usage inferencing
If a panel has a toggle, then it's a best practice that everything inside it is
grayed out of the toggle is off. It's not something we can enforce for node
groups, but should enforce it for built-in nodes.  Right now, we don't have
built-in nodes with panels, but that may change e.g. with #135990.

This patch makes it so that the socket usage inferencing takes panel toggles
into account when determining if an input socket in a built-in node in a panel
is used.

Pull Request: https://projects.blender.org/blender/blender/pulls/135993
2025-03-24 19:08:03 +01:00
Jacques Lucke
51904839ac Fix #135948: Geometry Nodes: support evaluating undefined custom group nodes
The main reason that didn't work before because undefined custom node groups
have the undefined `bNodeType` (and thus are ignored in various places) but are
actually still groups that can be evaluated. The fix is just to handle custom
node groups a bit more explicitly.

In the future, we may want to have a separate "undefined custom group"
`bNodetype`, but that might a be a bit bigger project.

Pull Request: https://projects.blender.org/blender/blender/pulls/135974
2025-03-14 18:31:29 +01:00
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Jacques Lucke
3baac1992a Fix: Nodes: handle undefined nodes more gracefully
Found while checking #134193.
2025-02-07 13:26:24 +01:00
Jacques Lucke
4fd236dc32 Fix #134111: sockets are incorrectly grayed out after random node
The issue was that the code did not handle input sockets that are fields
implicitly correctly. It just retrieved a single from them, instead of
treating them as having an unknown value.
2025-02-05 14:09:48 +01:00
Jacques Lucke
7c011440c6 Fix #133925: crash when removing animated input socket 2025-02-03 15:14:38 +01:00
илья _
b7085d8554 Fix: Geometry Nodes: muted nodes have incorrect socket usage inferencing
Only inputs that are passed through internal links are used by the outputs.

Pull Request: https://projects.blender.org/blender/blender/pulls/133903
2025-02-03 12:44:06 +01:00
Campbell Barton
bd1ded952b Cleanup: spelling in comments 2025-01-29 12:31:19 +11:00
Jacques Lucke
a15aaa3aa6 Fix #133603: reroute node breaks graying out node group inputs
The evaluated value was not properly forwarded through reroute nodes.
2025-01-28 16:51:27 +01:00
Jacques Lucke
c1e6cb3a0e Fix: input sockets of output nodes are grayed out
Just like the root group output node, those should be treated
as outputs of the node tree and are thus always used.
2025-01-23 19:34:52 +01:00
Jacques Lucke
74fff8623f Nodes: support input socket usage inferencing for Mix and Mix Shader node
This builds on top of 80441190c6 to gray output
unused inputs of the Mix and Mix Shader node. These nodes have unused inputs if
their mix factor is 0 or 1 (+ some special cases for non-uniform vector mixing
and blend modes).

Pull Request: https://projects.blender.org/blender/blender/pulls/133369
2025-01-21 17:22:12 +01:00
Jacques Lucke
80441190c6 Nodes: automatically gray out input values that don't affect the output
This patch automatically grays out input values which can't affect the output
currently. It works with inputs of group nodes, geometry nodes modifiers and
node tools.

To achieve this, it analyses the node tree and partially evaluates it to figure
out which group inputs are currently not linked to an output or are disabled by e.g.
some switch node.

Original proposal: https://devtalk.blender.org/t/dynamic-socket-visibility/31874
Related info in blog post:
https://code.blender.org/2023/11/geometry-nodes-workshop-november-2023/#dynamic-socket-visibility

Follow up task for designing a UI that allows hiding sockets: #132706

Limitations:
* The inferencing does not update correctly when a socket starts being
  animated/driven. I haven't found a good way to invalidate the cache in a good
  way reliably yet. It's only a very short term problem though. It fixes itself
  after the next modification of the node tree and is only noticeable when
  animating some specific sockets such as the switch node condition.
* Whether a socket is grayed out is not exposed in the Python API yet. That will
  be done separately.
* Only a partial evaluation is done to determine if an input affects an output.
  There should be no cases where a socket is found to be unused when it can actually
  affect the output. However, there can be cases where a socket is inferenced to be used
  even if it is not due to some complex condition. Depending on the exact circumstances,
  this can either be improved or the condition in the node tree should be simplified.

Pull Request: https://projects.blender.org/blender/blender/pulls/132219
2025-01-21 12:53:24 +01:00