Commit Graph

2182 Commits

Author SHA1 Message Date
Omar Emara
ad7f03c623 Compositor: Implement parallel reduction for new CPU compositor
Reference #125968.
2024-11-07 13:12:54 +02:00
Omar Emara
3cf944bae7 Refactor: Make result channels count public 2024-11-06 15:42:16 +02:00
Omar Emara
7471478b57 Compositor: Implement Texture node for new CPU compositor
Reference #125968.
2024-11-06 13:39:17 +02:00
Omar Emara
65797a5107 Compositor: Implement Mask node for new CPU compositor
Reference #125968.
2024-11-06 13:37:46 +02:00
Omar Emara
7220b3bb19 Compositor: Implement Bokeh Image for new CPU compositor
Reference #125968.
2024-11-06 13:36:41 +02:00
Campbell Barton
15c207a294 Merge branch 'blender-v4.3-release' 2024-11-02 17:34:00 +11:00
Campbell Barton
4df285ccd5 Cleanup: move function comments into headers or implementation notes
For C/C++ doc-strings should be located in headers,
move function comments into the headers, in some cases merging
with existing doc-strings, in other cases, moving implementation
notes into the function body.
2024-11-02 17:27:09 +11:00
Omar Emara
c6d4c759eb Compositor: Implement Color Balance node for new CPU compositor
Reference #125968.
2024-10-29 10:44:20 +03:00
Omar Emara
61eb3e06df Merge branch 'blender-v4.3-release' 2024-10-28 14:19:09 +03:00
Omar Emara
f0125f26fd Fix #129435: Bad Cryptomatte output in camera view
The Cryptomatte node produces a bad output when the viewport is in
camera view. That's because compositing is limited to the camera region
in that case, but the node assumes the full viewport size. To fix this,
only consider the compositing region instead of the full viewport.
2024-10-28 14:14:49 +03:00
Omar Emara
ba5c6c8682 Compositor: Implement Chroma Matte for new CPU compositor
Reference #125968.
2024-10-25 11:25:55 +03:00
Omar Emara
8a02a5de56 Compositor: Implemenet Posterize node for new CPU compositor
Reference #125968.
2024-10-23 13:24:54 +03:00
Omar Emara
471c30fdd9 Refactor: Return cached image by value
Return cached image by value for consistency with other cached
resources.
2024-10-23 13:13:38 +03:00
Omar Emara
1bd64e873e Fix: Corrupt image when compositor is canceled
When the compositor is canceled mid-execution, the image node will get
corrupt in future executions in new CPU execution mode. That's because
the image node treated cached images as an intermediate results that can
be passed through, while they should be treated as external resources
since they are managed by the static cache manager.

This patch fixes that by adding another variant of wrap_external that
takes a Result and wraps its data, then we use that in the Image node.
2024-10-22 17:37:30 +03:00
Omar Emara
141e48258a Fix: Memory leak when canceling compositor
Blender leaks memory when the compositor gets canceled. That's because
later operations in the compositor are responsible for freeing the
results of earlier operations, so when the compositor gets canceled
before all operations got the chance to execute, memory will be leaked.
To fix this, force free all operations when the compositor gets
canceled.
2024-10-21 13:46:26 +03:00
Omar Emara
8a33962357 Compositor: Support passes in new CPU compositor
This patch adds support for passes in the new CPU compositor. This
involves rewriting the get_input_texture method into a get_pass methods
that returns a result as opposed to a texture. The result wraps the
cached GPU texture or image buffer depending on the execution device.

The Render Layers node was implemented for CPU execution and a new
utility constructor for the result class was added to determine type and
precision based on GPU texture format. The fallback depth pass that was
retrieved from the viewport frame buffer was removed, as it was a hack
that can no longer be supported due to the use of stencil format.

Pull Request: https://projects.blender.org/blender/blender/pulls/129154
2024-10-17 15:04:25 +02:00
Clément Foucault
d712be0662 GPU: Change global scope variable to defines to avoid overhead on Metal 2024-10-15 20:06:46 +02:00
Clément Foucault
86f442df95 GPU: Make create info list not runtime generated
This avoid cmake shenanigans to try to make proper
dependency tracking.

The previous code was not tracking changes inside
the create info files.

There is no real benefit for having these headers listed in
the cmakefile itself.

Pull Request: https://projects.blender.org/blender/blender/pulls/129027
2024-10-15 16:31:37 +02:00
Omar Emara
e8a9de550f Cleanup: Avoid writing to input arguments
This patch adjusts the GLSL compositor code to avoid writing to
inputting as variables. This is to make it easier to port the code to
CPU. Also, write to the output directly instead of per channel.
2024-10-15 14:21:45 +03:00
Omar Emara
fbdb803750 Compositor: Implement Multi-Function Procedure Operation
This patch implements the multi-function procedure operation for the new
CPU compositor, which is a concrete implementation of the PixelOperation
abstraction, much like ShaderOperation, but uses the FN system to more
efficiently evaluate a group of pixel-wise operations.

A few changes were done to FN to support development. The multi-function
builder now allows retrieving the built function. A new builder method
construct_and_set_matching_fn_cb was added to allow using the SI_SO
builders with non static functions. A few other SI_SO were added to. And
a CPP type for float4 was added.

Additionally, the Gamma, Math, Brightness, and Normal nodes were
implemented as an example. The Math node implementation reused the
existing GN math node implementation, so the code was moved to a common
file.

Reference #125968.

Pull Request: https://projects.blender.org/blender/blender/pulls/126988
2024-10-15 06:51:42 +02:00
Omar Emara
30d3aef477 Compositor: Inline 2D threaded for utility
This patch inlines the 2D threaded for utility used by the compositor
for better performance.
2024-10-11 16:03:16 +03:00
Omar Emara
7f90c16d14 Refactor: Avoid processing arguments directly
Avoid processing function arguments directly and instead create
temporary variables for adjustments. This is done to make it easier to
maintain identical code to CPU.
2024-10-11 15:52:22 +03:00
Omar Emara
317cf37680 Compositor: Implement CPU domain realization
This patch implements the domain realization algorithm for the new CPU
compositor. Only nearest interpolation with no wrapping is implemented
at the moment.

A new sampling method was added to the result class and some relevant
methods were moved into inline functions.
2024-10-11 12:12:24 +03:00
Omar Emara
c55edd1310 Compositor: Implement previews for new CPU compositor
This patch moves the preview computation code to its own algorithm and
implements it on the CPU as well to support the new CPU compositor.
2024-10-10 18:28:34 +03:00
Omar Emara
dad7babaae Compositor: Implement single value reduction for CPU
This patch implements single value reduction for the new CPU compositor.

Reference #125968.
2024-10-09 15:18:58 +03:00
Clément Foucault
9c0321ae9b Metal: Simplify MSL translation
Move most of the string preprocessing used for MSL
compatibility to `glsl_preprocess`.

Enforce some changes like matrix constructor and
array constructor to the GLSL codebase. This is
for C++ compatibility.

Additionally reduce the amount of code duplication
inside the compatibility code.

Pull Request: https://projects.blender.org/blender/blender/pulls/128634
2024-10-07 12:54:10 +02:00
Clément Foucault
e4c802e53e GPU: Use macros for create infos
Mass rename create info function to use the new macros.
This allows to define resources in C++ inside IDEs'
precompilation system for linting purpose.

This applies the following script and format afterwards:
https://projects.blender.org/blender/blender/pulls/128602#issuecomment-1310597

Rel #127983

Pull Request: https://projects.blender.org/blender/blender/pulls/128602
2024-10-04 19:04:40 +02:00
Clément Foucault
7e5bc58649 GPU: Change GLSL include directive
This changes the include directive to use the standard C preprocessor
`#include` directive.

The regex to applied to all glsl sources is:
`pragma BLENDER_REQUIRE\((\w+\.glsl)\)`
`include "$1"`

This allow C++ linter to parse the code and allow easier codebase
traversal.

However there is a small catch. While it does work like a standard
include directive when the code is treated as C++, it doesn't when
compiled by our shader backends. In this case, we still use our
dependency concatenation approach instead of file injection.

This means that included files will always be prepended when compiled
to GLSL and a file cannot be appended more than once.

This is why all GLSL lib file should have the `#pragma once` directive
and always be included at the start of the file.

These requirements are actually already enforced by our code-style
in practice.

On the implementation, the source needed to be mutated to comment
the `#pragma once` and `#include`. This is needed to avoid GLSL
compiler error out as this is an extension that not all vendor
supports.

Rel #127983
Pull Request: https://projects.blender.org/blender/blender/pulls/128076
2024-10-04 15:48:22 +02:00
Jeroen Bakker
607093b506 Merge branch 'blender-v4.3-release' 2024-10-04 14:27:16 +02:00
Omar Emara
6ae3232eda Fix #126565: Render region corrupt compositor output
Activating render region while using the CPU compositor produces corrupt
output for areas outside of the region when using the File Output node.
That's because the Full Frame compositor ignored nodes' render_border
flag, so the areas of interest of nodes that didn't consider render
border like the File Output were corrupt, producing uninitialized
outputs.

To fix this, we just consider the render_border flag when determining
output areas for output nodes in the Full Frame compositor.

Pull Request: https://projects.blender.org/blender/blender/pulls/128546
2024-10-04 14:25:31 +02:00
Omar Emara
ccab8005f6 Fix #126604: Legacy Cryptomatte doesn't work in GPU
The Legacy Cryptomatte node doesn't work in GPU execution mode if
Precision is set to Auto. That's because the colors picked from the Pick
layer might be in half precision and thus will not match the colors in
the Cryptomatte layers. This is due to the compositor using the
context's precision for Viewer outputs as opposed to the precision of
the image that actually needs to be viewed in the Viewer node.

To fix this, we set the Viewer node precision to be the precision of its
input, that way, the Cryptomatte pick layer will be output in full
precision as intended.

Pull Request: https://projects.blender.org/blender/blender/pulls/128495
2024-10-04 14:25:16 +02:00
Clément Foucault
0bfd5e3536 GPU: Add GLSL preprocessor
This splits the GLSL processing into its own file
as it will grow in complexity.

Removes the complexity from `datatoc` and chain them
during the build process.

Rel #128076

Pull Request: https://projects.blender.org/blender/blender/pulls/128261
2024-10-04 11:33:21 +02:00
Omar Emara
db490e90fe Fix #127392: File Output doesn't write empty inputs
The File Output node doesn't write invalid and single value layers,
which can cause differences in EXR structures when rendering animations.

To fix this, we write a dummy image that has the same dimensions as the
other layers in the file, filled with the value of the single value
input.

Pull Request: https://projects.blender.org/blender/blender/pulls/128454
2024-10-02 10:28:55 +02:00
Campbell Barton
0f3fdd25bc Cleanup: various non-functional changes for C++
- Remove redundant parenthesis
- Use strings macros
- NULL -> nullptr
2024-10-02 15:47:05 +10:00
Omar Emara
60bb3b6677 Fix #124737: Scale To Render size is not precise
The Scale node in the Scale To Render size mode is not precise in case
of the use of render size percentage. This is due to floating point
imprecisions and we mitigate it by rounding instead of flooring after
multiplying by the percentage.
2024-09-30 18:58:13 +03:00
Omar Emara
1b392ef016 Fix #127093: Kuwahara node produces NaNs
The Kuwahara node produces NaNs if the pixels have a very high local
standard deviation and sharpness is also high. This is because the
weighted sum of the Kuwahara sectors can have a zero total weight, which
causes zero division. To fix this, we return the original color if the
total weight is zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/128378
2024-09-30 17:29:44 +02:00
Omar Emara
161b110746 Fix #127372: Alpha Over has unexpected output size
The Alpha Over node has an unexpected output size in GPU mode. If the
Factor and first Image inputs were connected to the same output, the
size of the output will assume the size of the second Image input, even
though the first Image input has a higher domain priority.

That's because the Alpha Over node is compiled into a Shader Operation
which has a single operation input for all inputs connected to the same
output, but only the domain priority of the first input was considered,
so in the case of the Alpha Over node, the domain priority of the Factor
input was assumed, ignoring the priority of the first Image output.

To fix this, we consider the priority of all inputs connected to the
same output, and assume the highest priority of all.

Pull Request: https://projects.blender.org/blender/blender/pulls/128366
2024-09-30 15:46:09 +02:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Habib Gahbiche
aac0c2cc5f Fix #127051: Compositing using multiple Levels nodes freezes Blender
Multiple levels nodes in a row causes blender to freeze when combined with other constant operations. Also, current results of standard deviation are wrong.

The problem was that constant folding optimized constant operations away, which caused a cyclic node graph, and therefore the freeze during node graph evaluation. Preventing such optimizations solves the problem.

Pull Request: https://projects.blender.org/blender/blender/pulls/127316
2024-09-26 01:37:23 +02:00
Campbell Barton
0fc27c8d81 Cleanup: spelling in comments 2024-09-20 13:14:57 +10:00
Campbell Barton
b70925a8cc Cleanup: prefer ASCII characters
Use ASCII quotes, punctuation so strings are easily editable.
2024-09-17 17:28:01 +10:00
Campbell Barton
e00fed43e6 Cleanup: redundant struct declarations 2024-09-11 16:25:25 +10:00
Campbell Barton
e34d9eeac7 Cleanup: use C-style comments, double quote Python text 2024-09-03 21:22:34 +10:00
Campbell Barton
d19c13eb82 Cleanup: spelling & punctuation in comments 2024-09-03 12:59:37 +10:00
Omar Emara
bb87690549 Fix #126984: CPU/GPU difference in jitter Lens Distort
The Lens Distort node is different between CPU and GPU when jitter is
enabled. That's because GPU incorrectly assumed that jitter with no
dispersion would have no effect. So we fix this by adjusting the
identity condition.

Further more, the green channel was not jittered for the GPU, that's
because the jitter was only seeded by the integration steps and was thus
constant for all channels. And since the green channel is the result of
addition of two opposite accumulations, the green channel was left
unaltered. To fix this, we include the start channel of the integration
in the seed to the jitter to make sure different channels get different
jitter.

Pull Request: https://projects.blender.org/blender/blender/pulls/126993
2024-08-30 18:44:29 +02:00
Omar Emara
96416f5401 Refactor: Abstract away the ShaderOperation class
This patch abstracts away the ShaderOperation class into an asbtract
PixelOperation class, which the ShaderOperation now implemenets. This
makes way for a new subclass that uses FN multi-functions for evaluation
for the new CPU compositor.

Reference #125968.
2024-08-27 14:42:11 +03:00
Omar Emara
b61e618886 Cleanup: Remove unused function 2024-08-26 14:44:36 +03:00
Omar Emara
9c3eb49f8b Cleanup: Compositor: Generalize naming of shader operations
This patch generalizes the naming of shader operations into "Pixel
Operations" to prepare for CPU-side support.
2024-08-26 14:38:10 +03:00
Campbell Barton
2ef76b89e4 Cleanup: remove duplicate code-comments 2024-08-23 10:19:53 +10:00
Omar Emara
997ab86906 Compositor: Add Composite node for new CPU compositor
This patch implements the Composite node for the new CPU compositor.
This is essentially equivalent to the Viewer node commit.
2024-08-22 14:48:52 +03:00