Commit Graph

2166 Commits

Author SHA1 Message Date
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
Omar Emara
9b903d4c6f Compositor: Implement type conversion in new CPU compositor
This patch implements implicit conversion operations for the new CPU
compositor.
2024-08-22 11:15:57 +03:00
Iliya Katueshenock
1b67be14c6 Cleanup: BKE: Nodes: Functions renaming
Use snake style naming for all the kernel nodes functions.
Omit kernel prefix in the names since of the using namespace.
Use full forms of the terms
('iter' -> 'iterator', 'ntree' -> 'node_tree', 'rem' -> 'remove', ...).

Pull Request: https://projects.blender.org/blender/blender/pulls/126416
2024-08-19 20:27:37 +02:00
Omar Emara
5930e0404a Compositor: Support Image node in new CPU compositor
This patch supports the Image node in the new CPU compositor.
2024-08-19 18:38:50 +03:00
Omar Emara
ba61fc9326 Compositor: Allow delayed typing for results
This patch allows result to have their types set after construction but
before allocation.
2024-08-19 11:07:12 +03:00
Omar Emara
5e88a1466c Compositor: Support Viewer node in new CPU compositor
This patch supports the viewer node in the new CPU compositor. To do
that, the context viewer output mechanism was refactored to allow CPU
storage by utilizing the result class as opposed to a GPU texture.
2024-08-16 16:40:43 +03:00
Omar Emara
75cc1e4a15 Compositor: Add utility for 2D parallel for 2024-08-16 16:03:16 +03:00
Omar Emara
a54cf472c3 Compositor: Add utils for accessing pixel data 2024-08-16 15:55:29 +03:00
Campbell Barton
b5e0b59736 Cleanup: remove space around identifiers in C-style comments 2024-08-15 20:46:00 +10:00
Omar Emara
59a4fdfc81 Cleanup: Fix warning about non void function 2024-08-13 16:36:05 +03:00
Omar Emara
edc4d0d84a Compositor: Support CPU storage in result class
This patch adds support for CPU side buffers for the result class. A new
storage type member was added to identify the type of buffer storage,
and allocation will either allocate a GPU texture or a CPU buffer based
on the context's GPU usage.
2024-08-13 16:13:22 +03:00
Omar Emara
58c10d191e Cleanup: Default initialize Result class members 2024-08-13 11:56:12 +03:00
Omar Emara
10f64edb3a Compositor: Allow non-pooled result allocation
This patch allows the result to be allocated using new textures as
opposed to using pooled texture. This is useful to allow the result
class to be used for persistent data like cached resources which can't
be pooled since it spans multiple evaluations.
2024-08-13 11:33:37 +03:00
Omar Emara
f40cf759c7 Compositor: Add experimental option for new CPU compositor
This patch introduces a new experimental option for the new CPU
compositor under development. This is to make development easier such
that it happens directly in main, but the compositor is not expected to
work and will probably crash.

Pull Request: https://projects.blender.org/blender/blender/pulls/125960
2024-08-08 15:40:06 +02:00
Omar Emara
885db0986c Refactor: Remove concept of temporary result
Temporary results are essentially results with a default reference count
of 1, so we default to 1 for all results and set the initial reference
count differently as need.
2024-08-06 19:37:18 +03:00
Omar Emara
69ae62a94e Refactor: Store reference to context in Result
This patch stores a reference to the entire context in the Result class,
as opposed to just the texture pool. This is in preparation for adding
CPU side texture to the result, such that allocations can automatically
allocate CPU or GPU textures based on context.
2024-08-05 18:38:32 +03:00
Sergey Sharybin
89ededeec4 Cleanup: Code style 2024-08-02 14:41:33 +02:00