Commit Graph

4525 Commits

Author SHA1 Message Date
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
Brecht Van Lommel
181faaa51b Merge branch 'blender-v4.2-release' 2024-06-05 20:46:03 +02:00
Michael B Johnson
f913fb6159 USD: Add MaterialX shader export
This change adds the ability to export MaterialX networks into the resulting
USD layer.

Details:

A new export option has been added to the USD export to enable MaterialX
export. It is off by default currently due to reasons in the caveats
section.

When enabled, it exports the MaterialX shading network alongside the
UsdPreviewSurface network, on the same USD Material. This allows the same
material to be used by renderers that don't support MaterialX, using the
USDPreviewSurface as a fallback. This is similar to setups in other DCC
packages, and matches the format we've used in our Reality Composer Pro
asset library.

It uses the existing MaterialX framework used to generate MaterialX
documents for rendering, to act as the basis for the USD graph. In this
process it also re-uses the existing texture export code as well if provided
and necessary.

Once the MaterialX document is created, use usdMtlx to generate a USD
shading network. Unfortunately, usdMtlx generates a graph that is unlike
what other DCCs that support MaterialX-embedded-in-USD generates. It
generates several extra prim hierarchies, and externalizes all shader
inputs, making them difficult to edit in other MaterialX graph editors.

To workaround this, generate the MaterialX shading network onto a
temporary stage, where we then run various pre-processing steps to prevent
prim collisions and to reflow the paths once they're converted.

The PrimSpecs are then copied over to their new path. The resulting prim
hierarchy matches what many artists we've worked with prefer to work with.

Caveats:

The Export MaterialX check is off by default. When using the Principled
BSDF, the resulting graph is very usable. However, when using some of the
other BSDFs, the shading networks generated by the existing MaterialX
framework in Blender generate some shading graphs that are difficult for
usdview and other DCC's to understand. The graph is still correct, but
because we're trying to prioritize compatibility, the default is off.

In future PRs we can aim to make the graphs for those other BSDFs play
better with other DCCs.

Other Implementation Details:

As part of this commit we've also done the following:

* Place some of the materialx graphs inside a passthrough nodegraph to
  avoid node conflicts.
* Better handle some shader output types , and better handle some
  conflict cases.
* Moved the ExportTextureFunction to materials.h due to some difficult
  to resolve header ordering issues. This has no effect on any runtime code.
* There is a test for the MaterialX export that does some basic checking to
  make sure we get an export out the other end that matches our expectations

Authored by Apple: Dhruv Govil

This PR is based on an earlier implementation by Brecht van Lommel , as well
as Brian Savery and his teams' work at AMD to implement the general
MaterialX framework within Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/122575
2024-06-05 20:43:44 +02:00
Hans Goudey
84c4ddbbb9 Cleanup: GPU: Use references for some vertex buffer functions
Pull Request: https://projects.blender.org/blender/blender/pulls/122784
2024-06-05 18:47:22 +02:00
Sergey Sharybin
8cba704dfd Fix #122654: GPU Compositor: Cryptomatte node crashes blender
The system context is expected to be bound prior to the Blender
can be properly initialized. Otherwise GHOST will be doing OpenGL
calls without system context bound.

This follows code from DRW_render_context_enable().

Pull Request: https://projects.blender.org/blender/blender/pulls/122708
2024-06-04 13:12:35 +02:00
Omar Emara
a162149cfa Fix #121761: Crash when compositing while rendering
Blender crashes when the interactive GPU compositor is running in a node
editor while rendering. This is because the GPU compositor is sharing
the same GPU context used for rendering, which is not allowed. To fix
this, we use a dedicated render list for interactive compositing, to use
its dedicated GPU context.

This is implemented by keeping another render list for the purpose of
compositing and similarly clearing its context when it is no longer
needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/122472
2024-06-03 09:56:58 +02:00
Hans Goudey
e2402eb4a9 Cleanup: Use C++ types, references for CCGElem access 2024-06-02 20:36:33 -04:00
Hans Goudey
49b52b35d5 Cleanup: Move BKE_ccg.h to C++ 2024-06-02 20:36:33 -04:00
Omar Emara
2b1e825545 Compositor: Refactor GPU context handling
This patch refactors the GPU context handing in the GPU compositor.
First, GPU context handling in the GPU compositor constructor was
removed, that's because the constructor does nothing GPU related.
Second, the destructor and the execute methods were unified to use the
global DST context for main thread execution and a dedicated system GPU
context for threaded execution. The former is the case for blocking
rendering as well as background mode, so the blocking due to the global
DST is not an issue, but it makes the code more robust to implementation
errors like #122070.

Pull Request: https://projects.blender.org/blender/blender/pulls/122389
2024-05-30 15:03:39 +02:00
Sergey Sharybin
9faed28dcd Fix #122401: Missing animation rendering scene with "Render Single Layer"
Ensure that the re->r.scemode has R_SINGLE_LAYER when not rendering the
single layer.

Pull Request: https://projects.blender.org/blender/blender/pulls/122402
2024-05-28 21:19:43 +02:00
Philipp Oeser
fcc481a407 Render: include info string for "render_stats" handler
The "render_stats" handler now includes the message line that was
written to stdout as the first arg (using `BKE_callback_exec_string`
instead of just `BKE_callback_exec_null`).

This can be useful to track render progress (and people were relying on
parsing stdout in the past).

Was a request in chat.

This also corrects possible output from the callback being written in
between message parts in `do_write_image_or_movie` (which was probably a
mistake in 93d5e106aa).

Pull Request: https://projects.blender.org/blender/blender/pulls/119789
2024-05-28 17:07:27 +02:00
Omar Emara
0dca908191 Compositor: Add GPU per-node execution time report
This patch adds support for timing GPU compositor executions. This was
previously not possible since there was no mechanism to measure GPU
calls, which is still the case. However, since 2cf8b5c4e1, we now flush
GPU calls immediately for interactive editing, so we can now measure the
GPU evaluation on the host, which is not a very accurate method, but it
is better than having no timing information. Therefore, timing is only
implemented for interactive editing.

This is different from the CPU implementation in that it measures the
total evaluation time, including any preprocessing of the inputs like
implicit type conversion as well as things like previews.

The profiling implementation was moved to the realtime compositor since
the compositor module is optional.

Pull Request: https://projects.blender.org/blender/blender/pulls/122230
2024-05-28 08:13:46 +02:00
Campbell Barton
c110d26c61 Cleanup: use const pointers where possible 2024-05-28 13:47:43 +10:00
Sergey Sharybin
62ebc5f351 Fix Image Save operator locking when saving render result
The issue has been introduced by #122105

The image save operator does exactly the thing which was not supported by
the change and was not caught during development or view: it acquires and
releases image buffers while a render result of the Image data-block is
held acquired.

The solution is to implement a simple user-counter for the render result.
Currently it is only used by the image's render result acquire/release API,
as it is the most important case for now. The render pipeline uses its own
way of protecting the result, for which the user counter is not needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/122231
2024-05-24 20:41:08 +02:00
Sergey Sharybin
1b18e07232 Fix #121480: Cryptomatte shows some objects as black
The issue originates to the change in default view transform from Filmic
to AgX, which does slightly different clipping, and clips color to black
if there is any negative values.

This change implements an idea of skipping view transform for viewer
node when it is connected to the Pick output of the cryptomatte node.
It actually goes a bit deeper than this and any operation can tag its
result as a non-color data, and the viewer node will respect that.
It is achieved by passing some extra meta-data along the evaluation
pipeline. For the CPU compositor it is done via MetaData, and for the
GPU compositor it is done as part of Result.

Connecting any other node in-between of viewer and Cryptomatte's Pick
will treat the result as color values, and apply color management.

Connecting Pick to the Composite output will also consider it as color,
since there is no concept of non-color-managed render result.

An alternative approaches were tested, including:

- Doing negative value clamping at the viewer node.
  It does not work for legacy cryptomatte node, as it needs to have
  access to original non-modified Pick result.

- Change the order of components, and store ID in another channel.

  Using one of other of Green or Blue channels might work for some view
  transforms, but it does not work for AgX.

  Using Alpha channel seemingly works better, but it is has different
  issues caused by the fact that display transform de-associates alpha,
  leading to over-exposed regions which are hard to see in the file from
  the report. And might lead to the similar issues as the initial report
  with other objects or view transforms.

- Use positive values in the Pick channel.

  It does make things visible, but they are all white due to the nature
  of how AgX works, making it not so useful as a result.

Pull Request: https://projects.blender.org/blender/blender/pulls/122177
2024-05-24 17:25:57 +02:00
Omar Emara
6ae98e43a9 Fix #122070: Crash when calling python render method
Blender crashes when calling the python render operator when GPU
compositor execution is enabled. This is due to a missing system GPU
context, which is not initialized for blocking rendering. So this patch
ensures the system GPU context before compositing. Additionally, it
removes the assert that ensures a non main thread execution, since the
assumption apparently does not really hold.

Pull Request: https://projects.blender.org/blender/blender/pulls/122176
2024-05-24 07:58:39 +02:00
Hans Goudey
c4fc19f064 Cleanup: Use reference argument for BKE_mesh_copy_for_eval 2024-05-20 13:18:24 -04:00
Hans Goudey
a6ecfe2f79 Cleanup: Rename DerivedMesh.cc and header
After recent commits, the .cc file is only used for actual object data
evaluation in the depsgraph, and the header is only used for the old
DerivedMesh data structure that's still being phased out.
2024-05-20 13:11:18 -04:00
Hans Goudey
da32aeb455 Cleanup: Use C++ types for various mesh array arguments
Also remove duplicated code for creating an array of BMesh positions
2024-05-20 02:58:13 +02:00
Sergey Sharybin
727a90a0f1 Compositor: Make GPU compositor an official feature
Effectively, make GPU compositor available without need to enable
an experimental feature set.

The compositor device is now exposed in the Performance panel of
Render Buttons. It is also still available in the compositor's
N-panel, together with some other options which are more about how
editing works, and not exactly related to render performance.

Pull Request: https://projects.blender.org/blender/blender/pulls/121398
2024-05-14 15:49:20 +02:00
Aras Pranckevicius
008483fe8a Cleanup: Remove non-working channels parameter of BLF_buffer
BLF_buffer was trying to accept "how many colors channels in output
image?" argument and doing math with it, but in the lowest level code
was always writing out full 4 channels for each pixel.

All the call sites would ever call it with argument of 4 however, and
that is why no one noticed the issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/121630
2024-05-10 18:54:53 +02:00
Sergey Sharybin
7b4232e8aa Compositor: Move Execution Mode and Precision from bNodeTree to Scene
This allows to expose these settings in the Performance panel in the
render buttons. Also moves compositor-specific options away from the
generic node tree structure.

For the backwards-compatibility the options are still present in the
DNA for the bNodeTree. This is to minimize the impact on the Studio
which has used the GPU compositor for a while now. They can be
removed in a future release.

There is no functional changes expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/121583
2024-05-10 18:08:33 +02:00
Clément Foucault
7859e0f606 EEVEE-Next: Rename engines and set it default in startup file
Finally.

Pull Request: https://projects.blender.org/blender/blender/pulls/121592
2024-05-08 20:57:00 +02:00