Commit Graph

2311 Commits

Author SHA1 Message Date
Omar Emara
89e0472e49 Compositor: Use gpu::TexturePool instead of DRW pool
This patch removes the compositor texture pool implementation which
relies on the DRW texture pool, and replaces it with the new texture
pool implementation from the GPU module.

Since the GPU module texture pool does not rely on the global DST, we
can use it for both the viewport compositor engine and the GPU
compositor, so the virtual texture pool implementation is removed and
the GPU texture pool is used directly.

The viewport compositor engine does not need to reset the pool because
that is done by the draw manager. But the GPU compositor needs to reset
the pool every evaluation. The pool is deleted directly after rendering
using the render pipeline or through RE_FreeUnusedGPUResources for the
interactive compositor.

Pull Request: https://projects.blender.org/blender/blender/pulls/134437
2025-02-12 15:59:45 +01:00
Omar Emara
df69e6ab50 Merge branch 'blender-v4.4-release' 2025-02-12 11:54:29 +02:00
Omar Emara
25c4dd53dd Fix: Keying Screen and anti-aliasing produce bad results
The Keying Screen and the Anti-Aliasing nodes produce bad results in the
viewport compositor. This is because their cached resources are
allocated from the GPU texture pool, so they might get overwritten.

To fix this, we make sure those are not allocated from the texture pool.
2025-02-12 11:50:44 +02:00
Omar Emara
51789af3cb Cleanup: Compositor: Remove is_int_type method
The method is only used in one place and will be redundant in a future
change.
2025-02-11 14:29:52 +02:00
Clément Foucault
a961c9050d Cleanup: GPU: Remove dependency on legacy common_math_lib.glsl
Replace usage of `common_math_lib.glsl` (deprecated) with gpu shader libs.

Pull Request: https://projects.blender.org/blender/blender/pulls/131579
2025-02-10 18:14:50 +01:00
Omar Emara
a8141f47cf Merge branch 'blender-v4.4-release' 2025-02-10 13:59:08 +02:00
Omar Emara
d006924ebc Fix: Blur is two times slower in 4.4
The symmetric separate blur operation in the compositor is two times
slower in 4.4 compared to 4.3. On Linux, this only happens when Blender
is compiled with GCC, because Clang inlines a small function that GCC
doesn't.

To fix this, we specialize an if statement using templates to help GCC
inline the function. This results in a 3.5 times faster execution.

Pull Request: https://projects.blender.org/blender/blender/pulls/134336
2025-02-10 12:58:02 +01:00
Omar Emara
bd379e1892 Refactor: Compositor: Use gpu_fn for ShaderNode class
This patch refactors the ShaderNode class to be a concrete class that
is implemented in terms of the node type gpu_fn. This is done to make it
easier to reuse existing nodes in other parts of Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/134210
2025-02-10 11:51:57 +01:00
Omar Emara
31444fe5b1 Refactor: Compositor: Use generic container for results
This patch refactors the Result class in the compositor to use
GMutableSpan and std::variant to wrap the result's data. This reduces
the complexity of the code and slightly optimizes performance. This will
also make it easier to add new types and interface with other code like
multi-function procedures.

Pull Request: https://projects.blender.org/blender/blender/pulls/134112
2025-02-06 13:49:44 +01:00
Omar Emara
96f56da030 Fix #134073: Compositor crash with viewer inside muted group
The compositor crashes when the user goes into a muted group that has a
viewer node while the backdrop is enabled. The compositor should not
schedule viewer nodes inside muted contexts, so we need to add checks to
prevent this.

Pull Request: https://projects.blender.org/blender/blender/pulls/134093
2025-02-05 10:41:46 +01:00
Omar Emara
e53ac805af Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.

For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.

For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.

For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.

Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
Omar Emara
2d1e64d32d Fix: Simple Star glare fails in Metal GPU back-end
The Simple Stare glare code writes and reads from the same image in the
same invocation, so we need to insert a fence after the writes.

This is not very efficient, and we can probably use a single fence
between the causal and anti-causal passes. But this can be implemented
later as an optimization.

Pull Request: https://projects.blender.org/blender/blender/pulls/133968
2025-02-03 13:05:46 +01:00
Omar Emara
1a973bcb06 Cleanup: Compositor: Forward declare DerivedResources 2025-02-03 10:40:30 +02:00
Jeroen Bakker
9f5d8756fc Fix #133866: Compositor: Incorrect Binding info keying node
Keying node has incorrect binding info, what leads to incorrect results
when running on Mesa/RADV driver.

Pull Request: https://projects.blender.org/blender/blender/pulls/133877
2025-01-31 17:20:05 +01:00
Brecht Van Lommel
1eb1755e1f Cleanup: Various clang-tidy warnings in compositor
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:17 +01:00
Omar Emara
028506712d Fix #133807: File Output node ignores transforms
The File Output node sometime ignores the transformations of their
inputs. That's due to the fact that transforms are now delayed and the
File Output node does not realize its inputs on its domain in case it
was not multi-layer.

To fix this, add another realization mode for transforms only. And use
that in the File Output node, as well as the Bokeh Blur, UV Map, and
Plane Track Deform, which also need this fix.

Pull Request: https://projects.blender.org/blender/blender/pulls/133850
2025-01-31 10:14:54 +01:00
Omar Emara
3fd894a2d9 Fix #133847: Single value node trees fail in GPU
Nodes that process single values can fail to work for GPU compositing.
That's because multi-function procedures writes to the single values but
never uploads them to the GPU, which is what this patch does.

Pull Request: https://projects.blender.org/blender/blender/pulls/133851
2025-01-31 10:10:22 +01:00
Omar Emara
75f1cbb6dd Refactor: Clarify code around scheduling composite nodes
There is a special case in the compositor code where viewer nodes are
treated as composite nodes. This patch renames relevant methods and
updates comments to clarify this use case.

Pull Request: https://projects.blender.org/blender/blender/pulls/133811
2025-01-31 07:43:00 +01:00
Campbell Barton
7de7ea350c Cleanup: quiet compiler warning 2025-01-30 14:33:25 +11:00
Omar Emara
2b2b27abf5 Fix #133565: Single value nodes wrongly return an image
In certain setups, nodes whose inputs are single value and whose outputs
are expected to be single value wrongly return an image. That's because
they wrongly join a pixel operation that operates on images.

To fix this, we split pixel operations by their value types. Single
value sub-trees get compiled into their own pixel operation and none
single value sub-trees get compiled into their own pixel operation.

This might unfortunately break up a long chain of pixel operations if
one of them was single value. This is solvable, but will require more
time and research, so we need to fix the bug first then look into it.

Pull Request: https://projects.blender.org/blender/blender/pulls/133701
2025-01-29 15:13:45 +01:00
Omar Emara
980226662b Compositor: Allow pixel operations to operate on single values
This patch allows the multi-function procedure pixel operation to
operate on single values. While it previously assumes a 1x1 image for
processing which was later reduced to a single value using input
processors. This is more efficient, but will allow us to use
multi-function procedures for single value sub-trees even in GPU
execution.
2025-01-28 13:54:13 +02:00
Omar Emara
a9abb5254e Cleanup: Use none-const get_single_value for setting values
This patch adds a none-const variant of the get_single_value method and
use that in the set_single_value method, which will reduce code
duplication. This is also needed for a future change.
2025-01-28 13:38:28 +02:00
Omar Emara
2028bc8d7d Compositor: Add derived resources optimization
This patch introduces a new Derived Resources concept to the compositor.
Derived resources are resources that are computed from a particular
result and cached in it in case it is needed by another operation, which
can greatly improve performance in some cases at the cost of more memory
usage.

The first use case is to store denoised versions of the Denoising Albedo
and Denoising Normals passes if auxiliary pass denoising is enabled in
the denoise node. Consequently, multi-pass denoising setups where the
same auxiliary passes are used in multiple denoise nodes should be much
faster due to caching of the derived resources.

This implementation has the limitation that it can't preemptively
invalidate the cache when the derived resources are no longer needed to
free up memory. This requires a special resource tracking mechanism that
need to happen during node tree compilation, and will be submitted
later. The limitation is not significant in the particular derived
resources that is currently implemented. Since the auxiliary passes are
rarely used outside of denoising.

Fixes #131171.

Pull Request: https://projects.blender.org/blender/blender/pulls/125671
2025-01-27 14:58:09 +01:00
Omar Emara
109478d599 Compositor: Delay transformations until realization
This patch delays applying transformations until realization happens on
some other domain.

Currently, transformations are applied immediately at the point of
transform nodes, this is problematic for a few reasons:

- If that result was then realized on some other domain, interpolation
  will have happened two times, at the transform nodes and at the node
  that required realization, causing less than ideal precision issues.
- It is not possible to repeat or extend a rotated result because its
  empty areas will be zero filled, leaving gaps in its extension. So
  this patch is a prerequisite for #132371 if we want full support for
  repetition.
- Doing inverse transformations will introduce interpolation artifacts
  which might be undesirable. Inverse transformations might be used to
  do pixelation for instance, so this change will be undesirable in this
  case. But we decided that this is not a use case that we want to
  support, and we added explicit pixel size control to the pixelate node
  as an alternative.

So this has four implications, two that might be considered bad:

- Transformations will now be higher quality and more precise.
- Repetition and other boundary extension methods will now be possible.
- Downsampling then upsampling will no longer produce pixelated results.
- Realization might happen multiple times with identical results in some
  cases.

The last point not a big issue, since domain realization is not a big
bottleneck in the compositor, and the plan is to move realization into
pixel operations, so it will even be more efficient than it is now.

Pull Request: https://projects.blender.org/blender/blender/pulls/133158
2025-01-24 13:59:55 +01:00
Omar Emara
759a7a08d9 Fix: Conversion shader fails compilation on MacOS
Argument names can't be the same as a push constant name, so rename the
push constant.

Pull Request: https://projects.blender.org/blender/blender/pulls/133531
2025-01-24 11:14:56 +01:00
Omar Emara
b8db212d95 Compositor: Use OCIO luminance for color to float conversion
This patch uses OCIO luminance for implicit conversion from color to
float in the compositor. This is done to match other node systems, and
because luminance is a much better default than the average formula used
before.

Versioning was added to retain average conversion for old files.

Pull Request: https://projects.blender.org/blender/blender/pulls/133206
2025-01-24 09:40:43 +01:00
Brecht Van Lommel
7a0a173d39 Fix: Missed case of OCIO luminance coefficients in EEVEE
Following up on #133368. Thanks Omar for spotting this.

Pull Request: https://projects.blender.org/blender/blender/pulls/133400
2025-01-22 11:19:02 +01:00
Omar Emara
d4189ee398 Fix #133225: File Output nodes fail inside node groups
The File Output node no longer works inside node groups since the
introduction of the new CPU compositor. This is explicit in the code, so
we just consider all file output nodes recursively to fix this issue.
2025-01-20 13:11:28 +02:00
Jacques Lucke
987003d456 Nodes: replace some node checks with accessor method calls
This uses the following accessor methods in more places in more places:
`is_group()`, `is_group_input()`, `is_group_output()`, `is_muted()`,
`is_frame()` and `is_reroute()`.

This results in simpler code and reduces the use of `bNode.type_legacy`.

Pull Request: https://projects.blender.org/blender/blender/pulls/132899
2025-01-17 12:17:49 +01:00
Omar Emara
e545b6e764 Cleanup: Pass interpolation directly to transform algorithm
The transform algorithm currently takes realization options, but it only
uses the interpolation from it. So pass interpolation directly for
clarity.
2025-01-15 15:45:51 +02:00
Omar Emara
7e5af160bd Cleanup: Rename wrap to repeat in realization options
The wrap member in realization options is no longer used to indicate
wrapping since 8f8ae302ba. So rename it to repeat since the only user is
now repeating in the realization algorithm.
2025-01-15 15:22:36 +02:00
Omar Emara
3b28cf276e Compositor: Add Glare Highlights Smoothness and Max
This patch adds two new inputs to the Glare node, Highlights Smoothness
and Max Highlights. Smoothness allows the user to control how smooth the
highlights are after thresholding and Max allows the user to suppress
very high brightness pixels.

Those are essentially similar to the Knee and Clamp options in old EEVEE
bloom, though they work differently.

The issue with the Knee parameter in old EEVEE bloom, aside from being
named after a body part, is that it actually isn't smooth or continuous
around zero if the threshold is sufficiently close to zero relative to
the Knee parameter. That's because zero lies in the smoothing kernel
region in those cases, and since zero pixels becoming highlights is very
bad, EEVEE just returned zero as a special case for zero brightness, but
values like 0.0001 will be full blown highlights.

The new nicely named Smoothness input uses adaptive smoothing such that
the smoothing kernel size will be reduced as the threshold nears zero,
such that smoothed highlights will be continuous and smooth around zero.

The Max Highlights input is similar to clamped, it it suppresses very
bright highlights such that their brightness doesn't exceed the
specified max.

This is a partial implementation of #124176 to address #131325.

Pull Request: https://projects.blender.org/blender/blender/pulls/132864
2025-01-13 13:54:07 +01:00
Hans Goudey
f2c9fccee0 Cleanup: Move legacy node integer types defines to separate header
Moving these defines to a separate header makes their "legacy" status
more obvious. This commit just adds the include wherever necessary.

Followup to 971c96a92c.

Pull Request: https://projects.blender.org/blender/blender/pulls/132875
2025-01-09 20:03:08 +01:00
Jacques Lucke
971c96a92c Nodes: rename integer type of nodes to type_legacy
The new description for `bNode.type_legacy`:
```
  /**
   * Legacy integer type for nodes. It does not uniquely identify a node type, only the `idname`
   * does that. For example, all custom nodes use #NODE_CUSTOM but do have different idnames.
   * This is mainly kept for compatibility reasons.
   *
   * Currently, this type is also used in many parts of Blender, but that should slowly be phased
   * out by either relying on idnames, accessor methods like `node.is_reroute()`.
   *
   * A main benefit of this integer type over using idnames currently is that integer comparison is
   * much cheaper than string comparison, especially if many idnames have the same prefix (e.g.
   * "GeometryNode"). Eventually, we could introduce cheap-to-compare runtime identifier for node
   * types. That could mean e.g. using `ustring` for idnames (where string comparison is just
   * pointer comparison), or using a run-time generated integer that is automatically assigned when
   * node types are registered.
   */
```

Pull Request: https://projects.blender.org/blender/blender/pulls/132858
2025-01-09 15:28:57 +01:00
Omar Emara
c37d51f73d Compositor: Allow tinting Glare
This patch adds two new inputs to the Glare node, Saturation and Tint.
Their function is to tint the color of Glare to any color the user
wants.

This is a partial implementation of #124176 to address #131325.

Pull Request: https://projects.blender.org/blender/blender/pulls/132744
2025-01-08 13:18:58 +01:00
Omar Emara
8f8ae302ba Refactor: Compositor: Moved wrapped translation to its own code
This patch moves wrapped translation from a special case of the general
transform algorithm to the Translate node. Since the Translate node is
the only user of this special case, it doesn't make sense to complicate
a generate algorithm with it. This will make future refactors of this
code easier.

Pull Request: https://projects.blender.org/blender/blender/pulls/132793
2025-01-08 12:42:13 +01:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Omar Emara
004e3d39fa Compositor: Improve Glare node UX
This patch redesigns the Glare node to improve the user experience. The
improvements are as follows.

Two new outputs were added, Glare and Highlights. The Glare output gives
the generated glare without the input, and is useful when the user wants
to adjust the glare before adding it to the image. The Highlights output
gives the areas that are considered highlights when computing the glare,
and is useful if the user wants to temporally check the highlights while
doing adjustments or wants to use those as a base for creating a custom
glare setup.

The Mix node option was removed and a new Strength single value input
was added to serve the same functionality. The Mix option had a range of
[-1, 1], where the [-1, 0] sub-range essentially controlled the strength
of the glare, 0 being full strength and -1 being zero strength. While
the [0, 1] range returned the generated glare with an attenuated version
of the image added, that is, it was useless except for the value of 1,
which returned the generate glare only.
Aside from being a very intuitive range, it also meant that the power of
glare can't be boosted beyond the full strength of, you guessed it, 0.
The newly added Strength input has a soft range of [0, 1] and can be
boosted beyond 1. If the users want the glare only, they can use the
newly provided Glare output.

The Size node option used for Bloom and Fog Glow was removed and a new
Size single value input was added. The Size node option had yet another
very intuitive range of [1, 9], and it was related exponentially to the
actual size of the Glare. For Bloom, the actual bloom size relative to
the image was 2^(Size-9), so a Size of 8 means the bloom covers half of
the image. For Fog Glow, the actual bloom size in pixels is 2^Size, so
the glare size is not relative to the image size and would thus change
as the image resolution change. Furthermore, the maximum possible glare
size was 512 pixels, and the user couldn't make fine adjustments to the
size.
The newly added Size input has a range [0, 1], where 1 means the glare
covers the entire image, 0.5 means it covers half the image, and so on.
That means it is consistent between Bloom and Fog Glow, it is relative
to the image size, it allows as large of a glare as possible, it is
continuous for Fog Glow, but not for Bloom because that requires an
algorithmic change that will be implemented separately.

The Threshold, Streaks, Streaks Angle, Iterations, Fade, and Color
Modulation node option was turned into a single value node input to
allow the option to be used in node groups.

---

Versioning was added to transfer node options into sockets, but it is
not all 1:1 versioning, since the old Size option was not relative to
the image size, so it depends on runtime information of the input size.
As a guess, we assume the render size in that case. Versioning the
[0, 1] range of the Mix option intentionally omits the attenuation of
the image input, because that is almost certainly not what the user
wants and was probably done thinking it controls the strength.

Glare code now sets the alpha channel to 1, that's because it was
already ignored in the mixing step, but now that we expose the Glare
output, we need to set it to 1. So this is not a functional change.

The get_glare_size() method was renamed for clarity since it now
conflicts with the newly added Size input.

---

This is a partial implementation of #124176 to address #131325. In
particular, it adjust existing functionality, it doesn't add any new
ones. Those will be added in separate patches.

Pull Request: https://projects.blender.org/blender/blender/pulls/132499
2025-01-07 11:15:26 +01:00
Campbell Barton
5003253aca Cleanup: spelling & repeated terms 2025-01-07 13:20:19 +11:00
Omar Emara
503e2c46a5 Fix: Compositor crash with group of different typed socket
The compositor crashes if a node inside a node group is connected to a
group input that have a different type and the node group is used
without a connection to that input. That's because the compositor code
assumes the type of the group input without implicit type conversion to
the expected type of the node. To fix this, handle implicit conversion
for unconnected sockets as well.
2025-01-06 11:14:27 +02:00
Omar Emara
b3623feab2 Compositor: Support node integer sockets
This patch adds support for using integer sockets in compositor nodes.
This involves updating the Result class, node tree compiler, implicit
conversion operation, multi-function procedure operation, shader
operation, and some operations that supports multiple types.

Shader operation internally treats integers as floats, doing conversion
to and from int when reading and writing. That's because the GPUMaterial
compiler doesn't support integers. This is also the same workaround used
by the shader system. Though the GPU module are eyeing adding support
for integers, so we will update the code once they do that.

Domain realization is not yet supported for integer types, but this is
an internal limitation so far, as we do not plan to add nodes that
outputs integers soon. We are not yet sure how realization should happen
with regards to interpolation and we do not have base functions to
sample integer images, that's why I decided to delay its implementation
when it is actually needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/132599
2025-01-06 10:09:26 +01:00
Hans Goudey
48cecef1e0 Cleanup: Use is_same_any_v wrapper
Pull Request: https://projects.blender.org/blender/blender/pulls/132567
2025-01-03 19:15:01 +01:00
Campbell Barton
33e38c605f Cleanup: correct indentation for CMake files, strip trailing space 2025-01-03 13:23:38 +11:00
Ray Molenkamp
5783950ac5 Revert: 0dc484f9cc bf_rna modernisation
This caused build errors on the docs builder, I can't seem to reproduce
locally, so revert for now and have another look at some point in the
future.

Sadly as these changes usually go, this took 5c515e26bb and
2f0fc7fc9f with it as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/132559
2025-01-02 19:56:24 +01:00
Omar Emara
4ad1537ff7 Fix: Compositor: Conversion code might fall through
The recently added switch statements in conversion code might fall
through due to missing breaks. Fix that by adding needed breaks.
2025-01-02 17:43:09 +02:00
Omar Emara
0ec7edf411 Cleanup: Compositor: Omit default case for ResultType
Explicitly list all result types to make it easier to add new result
types.
2025-01-02 14:42:44 +02:00
Omar Emara
b6be52c2b2 Refactor: Compositor: Reduplicate type conversion code 2025-01-02 14:02:13 +02:00
Omar Emara
159038ce7c Cleanup: Compositor: Deduplicate single value setters 2025-01-02 10:20:17 +02:00
Campbell Barton
dca0996777 Cleanup: various non-functional changes for C++ 2025-01-02 15:11:20 +11:00
Campbell Barton
5c515e26bb Cleanup: remove trailing space, ensure a newline at EOF 2025-01-02 15:11:18 +11:00