Commit Graph

4547 Commits

Author SHA1 Message Date
Hans Goudey
024d7d12e2 Mesh: Move BVH storage to shared cache system
Avoid rebuilding BVH trees when meshes are copied.
Similar to the other uses of the shared cache system,
this can arbitrarily improve performance when meshes
are copied but not deformed and BVH building is the
main bottleneck. In a simple test file I got a 6x speedup.

The amount of code is also reduced and the system is
much simpler overall-- built out of common threading
patterns like `SharedCache` with its double-checked lock.
RAII is used in a few places to simplify memory management
too.

The downside is storing more `SharedCache` items in the
mesh runtime struct. That has a slight cost when copying
a small mesh many times, but we have ideas to improve that
in the future anyway (#104327).

Pull Request: https://projects.blender.org/blender/blender/pulls/130865
2024-12-04 00:17:17 +01:00
Omar Emara
c2b1b84094 Cleanup: Remove unused variable 2024-12-02 18:51:41 +02:00
Omar Emara
eaa0ae23a9 Fix: Lighten blend mode is wrong for factors less than 1
The Lighten blend mode is wrong for factors less than 1, as it is
computed as a weighted maximum using the factor as the weight, while it
should be a simple component-wise maximum.

This is correctly implemented for Compositor, EEVEE, and Cycles. But the
render/material implementation is wrong. So we adjust the implementation
to match the correct one.

The Darken counterpart was already fixed in 1dcf956849. While the
lighten was fixed in 8b7b165ad9 among other patches. This just completes
the fix.

Pull Request: https://projects.blender.org/blender/blender/pulls/131242
2024-12-02 17:12:08 +01:00
Bastien Montagne
b325142d17 Merge branch 'blender-v4.3-release' 2024-11-12 16:55:40 +01:00
Bastien Montagne
0b3a7cbe69 Cleanup: Move BKE_image.h and related headers to C++.
NOTE: This also required some changes to Cycles code itself, who is now
directly including `BKE_image.hh` instead of declaring a few prototypes
of these functions in its `blender/utils.h` header (due to C++ functions
names mangling, this was not working anymore).

Pull Request: https://projects.blender.org/blender/blender/pulls/130174
2024-11-12 16:53:54 +01:00
Bastien Montagne
250c10ec64 Merge branch 'blender-v4.3-release' 2024-11-11 11:44:18 +01:00
Clément Foucault
dafa3fb88f Fix #129019: Crash when switching from EEVEE to Cycles while rendering animation
When changing render engine, we discard the persistent data
that could be saved for all the current render instance that
exists. This is to save memory for the new renderer.

When doing so while rendering for F12, `engine_depsgraph_free`
is called after waiting for the render to finish. But this
can be called before the renderer destruction and on the main
thread.

Doing so on the main thread means that the `gpu_context` used
by the renderer cannot be bound for the sake of just receiving
the orphan buffers that the depsgraph holds. This is because
only the worker thread can make the gpu context active.

Binding the draw gpu context in this situation avoid all
possible conflict.

This is basically doing exactly what the
`DRW_render_context_enable/disable` function is doing internally
if the render engine gpu context is null.

Pull Request: https://projects.blender.org/blender/blender/pulls/129982
2024-11-11 11:29:54 +01:00
Omar Emara
b9dbf2959d Fix: Crash with a BadAccess X_GLXMakeCurrent error
Blender crashes when opening files that invokes the interactive
compositor on file load with a BadAccess X_GLXMakeCurrent error.

This is caused by the same system GPU context being active in two
threads at the same time, which happens when the GPU context for the
compositor is created in the main thread, it is made current during
creation, but it is not reset to the main GPU context of the drawable
because it is null. So when the GPU compositor actually executes, it
makes the GPU context current again but in its own thread, causing a
BadAccess error in X11 and potentially other window systems.

So the root cause is that the drawable is nullptr, and an attempt to fix
this was committed in 0a70360eb6 but was reverted in 98722773da because
it caused serious issue that were not obvious.

This patch attempts another fix by simply releasing the system GPU
context created when calling the RE_system_gpu_context_ensure. This is
more robust anyways because callers do not expect the context to be
bound form an API point of view.

Pull Request: https://projects.blender.org/blender/blender/pulls/129793
2024-11-04 16:17:17 +01:00
Richard Antalik
a7f1d76187 Fix #126007: Sequecer renders even if all videos are muted
Check muting in `RE_seq_render_active()`.

This is to allow sequencer timeline to contain reference strips, which
are muted.

Pull Request: https://projects.blender.org/blender/blender/pulls/129561
2024-11-04 03:16:20 +01:00
Omar Emara
c8dd6650db Merge branch 'blender-v4.3-release' 2024-10-22 11:54:27 +03:00
Omar Emara
cce896fe11 Fix #127292: Cryptomatte passes are missing meta-data
Meta-data are missing on Cryptomatte layers in the GPU compositor, so
they do not get saved using the File Output node. This is due to a use
after free error where a temporary string is used in the meta-data
population logic. This is fixed by assigning the string to a temporary
variable instead.

Thanks to Jorn Visser for finding the cause of the issue.
2024-10-22 11:50:04 +03:00
Omar Emara
fdb3dc0377 Fix: Crash when changing compositor device
Blender crashes when changing the compositor execution device. That's
because cached resources that were originally computed for CPU are now
being used for GPU and vice versa, which can be unexpected in code that
uses them.

To fix this, we free and recreate the entire compositor context when the
execution device or precision change, because it is much easier and
safer to recreate everything as opposed to trying to update the
necessary resources.
2024-10-18 16:58:35 +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
Omar Emara
02ff72deb8 Cleanup: Reduce nesting in get_input_texture 2024-10-16 12:20:44 +03:00
Tobias Kozel
a9db29be82 Bake: Speed up "Selected to active" Texture-Baking
For Texture baking, there is a CPU-bound preparation step needed to
establish a mapping between the Hi-Res and Low-Res Meshes before the
rendering engine can take over and start the bake.

Part of this process is now taking advantage of parallel_for,
speeding up this step of the Bake process for many/large textures almost
linearly to the number of CPU-cores.

Pull Request: https://projects.blender.org/blender/blender/pulls/128964
2024-10-15 11:39:56 +02:00
Omar Emara
027d3acb4d Fix #128414: Compositor crashes using GPU compositor
Blender crashes when using the GPU compositor sometimes. This is because
compositor render data was accessed before it was updated in the
realtime compositor when detecting compositing device. So fix that by
first updating compositor data before calling any context methods.
2024-10-07 19:48:32 +03: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
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
Campbell Barton
473bd60164 Cleanup: clarify arguments using const or r_ prefixed return args 2024-09-26 15:03:24 +10:00
Bastien Montagne
22477956e2 Refactor: Move BPY main/public extern headers to proper C++ ones.
Pull Request: https://projects.blender.org/blender/blender/pulls/128081
2024-09-25 18:04:33 +02:00
Bastien Montagne
c3247aa4f0 Refactor: Move BPY generic headers to proper C++ ones.
NOTE: `bgl.h` was left unchanged, as it is deprecated code anyway, and
its conversion to C++ does not seem immediately trivial.
2024-09-25 18:04:27 +02:00
Bastien Montagne
91e4bcd204 Refactor: Move BPY intern bpy_rna headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Campbell Barton
0fc27c8d81 Cleanup: spelling in comments 2024-09-20 13:14:57 +10:00
Campbell Barton
42e94192e5 Logging: suppress render prints in quiet mode 2024-09-19 14:49:02 +10:00
Campbell Barton
2360a3911c BLI_listbase: add a utility to check the number of items in the list
To avoid unnecessary looping over listbase items the function
`BLI_listbase_count_at_most` was used however it resulting in an awkward
expression: `BLI_listbase_count_at_most(list, count + 1) == count`
replace this with `BLI_listbase_count_is_equal_to(list, count)`.
2024-09-16 11:39:00 +10:00
Campbell Barton
fe97bf29a6 Suppress render prints with G.quiet is set 2024-09-13 22:57:51 +10:00
Campbell Barton
e00fed43e6 Cleanup: redundant struct declarations 2024-09-11 16:25:25 +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
844d6d2df0 Fix #126552: Crash on Render Layers node with no scene
Blender crashes when a Render Layers node is used with no scene in the
GPU compositor. This is fixed by a simple nullptr check.
2024-08-21 10:54:00 +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
912284cfa3 Fix: GPU calls in CPU compositor
This patch removes an incorrect GPU call that shouldn't happen in the
CPU compositor, otherwise, it will cause a crash due to a missing
context.
2024-08-16 15:57:15 +03:00
Campbell Barton
b5e0b59736 Cleanup: remove space around identifiers in C-style comments 2024-08-15 20:46:00 +10: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
Jacques Lucke
5861b078f7 Core: rename ID.flag and ID.tag values
Previously, values for `ID.flag` and `ID.tag` used the prefixes `LIB_` and
`LIB_TAG` respectively. This was somewhat confusing because it's not really
related to libraries in general. This patch changes the prefix to `ID_FLAG_` and
`ID_TAG_`. This makes it more obvious what they correspond to, simplifying code.

Pull Request: https://projects.blender.org/blender/blender/pulls/125811
2024-08-07 12:12:17 +02:00
Omar Emara
9c44349204 Fix #124023: File output always saves PNG in sRGB
The File Output node doesn't provide an option to save byte formats like
PNG in a space that is not sRGB. This is problematic for data images
like normal maps, which need to be saved as non-color.

This patch adds a Color Space option to the File Output node to allows
users to override the assumed color space. This also adds a new global
Save As Render option that is used if Use Node Format is enabled.

Pull Request: https://projects.blender.org/blender/blender/pulls/124238
2024-08-02 13:52:22 +02:00
Campbell Barton
004c247670 Cleanup: different declaration names, use r_ prefix for return args 2024-07-29 13:01:10 +10:00
Omar Emara
406a2d3ff0 Fix #125380: Viewport compositor slows complex scenes
The viewport compositor slows down complex scenes even if it has very
simple setups. That's because it internally computes previews which
involves a fair bit of CPU computation, however, those previews are
actually never written to the original tree, so previewers weren't
really visible so it is effectively redundantly computations.

To fix this, we double down on disabling previews for the viewport
compositor and avoid any redundant computations in that case.
2024-07-26 19:08:58 +03:00
Jesse Yurkovich
ec4fc2d34a CMake: Modernize the optional TBB dependency
This continues the cmake modernization effort and introduces support for
allowing our optional dependencies to integrate properly. TBB is added
here as it's proven troublesome to maintain correctly.

Currently the only Blender project which uses the TBB headers directly
is `blenlib`.  However, all downstream projects which require blenlib as
their dependency, and wish to properly make use of its threading
facilities, needed to define various TBB items in their CMake files. Not
only is this unnecessary and arcane, but several projects didn't do this
and ended up not using threading as well as producing ODR violations
along the way[1].

This PR makes TBB a modern dependency and exposes it PUBLIC'ly from
`blenlib`.  All downstream projects which depend on blenlib will now
receive everything they require from TBB automatically. This includes
the `WITH_TBB` define, the headers, and the library itself.

[1] blender/blender@05241f47f5

Pull Request: https://projects.blender.org/blender/blender/pulls/124916
2024-07-19 23:30:56 +02:00
Bastien Montagne
c607ead4b7 Refactor: Makesrna: move generated code further in C++.
This commit moves generated `RNA_blender.h`, `RNA_prototype.h` and
`RNA_blender_cpp.h` headers to become C++ header files.

It also removes the now useless `RNA_EXTERN_C` defines, and just
directly use the `extern` keyword. We do not need anymore `extern "C"`
declarations here.

Pull Request: https://projects.blender.org/blender/blender/pulls/124469
2024-07-15 16:39:45 +02:00
Omar Emara
57a6832b17 Fix #101263: Vector pass wrongly saved in File Output
The vector pass and potentially other vectors that store 4 values are
stored wrongly, in particular, the last channel is ignored. To fix this
we identify if a vector pass is 4D and store the information in the
result meta data, then use this information to either save a 3D or a 4D
pass in the File Output node.

This is a partial fix for the GPU compositor only. The complete fix for
the CPU compositor will be submitted separately as it is not
straightforward and will likely require a refactor.

Pull Request: https://projects.blender.org/blender/blender/pulls/124522
2024-07-11 16:08:19 +02:00
Omar Emara
f954a6b5fb Compositor: Support meta data in GPU compositor
This patch adds support for meta data in the GPU compositor much like
the mechanism that already exist in the CPU compositor. Only Cryptomatte
meta data is handled at the moment because that is the only meta data
that the compositor supports.

The is_data member of the result was moved to the meta data structure for
consistency with the CPU compositor.

Fixes #124222.

Pull Request: https://projects.blender.org/blender/blender/pulls/124460
2024-07-11 11:03:03 +02:00
Jesse Yurkovich
57544887d0 CMake: Add WITH_TBB definition to prevent ODR violation for BLI_spin API
The BLI_spin APIs use a `SpinLock` typedef whose underlying type is
contingent on the precense of `WITH_TBB`. Since our projects did not
consistently define the `WITH_TBB` definition, multiple `SpinLock` types
would end up in our final binary creating ODR violations.

Pull Request: https://projects.blender.org/blender/blender/pulls/124285
2024-07-10 23:02:17 +02:00
Omar Emara
29451489ae Cleanup: Render: Restructure compositor render code
This patch cleanup and refactors the render pipeline compositor render
code to deduplicate code and clarify usage.

The unused this_scene arguemenet was removed, per-node functions were
introduced to simplify loops, C++ Set was used instead of GSet, and
scene change is now detected by any rendered scene in the set.

Pull Request: https://projects.blender.org/blender/blender/pulls/124028
2024-07-02 17:10:27 +02:00
Omar Emara
0e1af55247 Merge branch 'blender-v4.2-release' 2024-07-01 13:30:33 +03:00
Omar Emara
e545c814a4 Fix: Scene not rendered even with Cryptomatte node
Blender doesn't render the scene even though a Cryptomatte node exists.
That's because Blender only considers Render Layer nodes, but
Cryptomatte node can reference scenes as well. This patch fixes that by
putting Cryptomatte nodes into consideration.

Pull Request: https://projects.blender.org/blender/blender/pulls/123814
2024-07-01 12:28:24 +02:00
Brecht Van Lommel
a26fd603b0 Merge branch 'blender-v4.2-release' 2024-06-18 21:19:24 +02:00
Clément Foucault
355c7b788e Fix: EEVEE: Remaining references to EEVEE-Legacy in codebase
Fix #123387
2024-06-18 18:17:34 +02:00
Omar Emara
ce80c3ca23 Merge branch 'blender-v4.2-release' 2024-06-11 12:03:16 +03:00
Omar Emara
b2a58bbdb4 Fix #123007: VSE scene strip crash with GPU compositor
Blender crashes when rendering a scene strip that references a scene
with a GPU compositor active. This is because when rendering a scene
strip, a new render with a nullptr system GPU context is created for the
scene it references, which is then used for compositing.

Ideally, the strip scene would have its own context, but we can't ensure
its context because we are not in the main thread. The alternative is to
then identify scenes that will be rendered before hand and set their
renders before starting the job, which doesn't seem like a great
solution. So for now, we just use the DST context in those cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/123057
2024-06-11 11:02:15 +02:00
Lukas Stockner
db991d8ac0 Cycles: Only store per-pixel seed for vertex color baking
Currently, during baking each pixel stores a seed input that comes from the
Blender side. This is only needed for vertex color baking, however -
for regular image baking, we can just as well hash the pixel coordinates.

Therefore, we can save some memory (4 byte per pixel) by splitting the seed
info out into a separate pass and only storing it when needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/122806
2024-06-06 00:45:38 +02:00