Commit Graph

243 Commits

Author SHA1 Message Date
Sebastian Herholz
5abf42012d Cycles: Guiding cleaning up and refactoring the guiding code
In detail:
- Direct accesses of state attributes are replaced with the INTEGRATOR_STATE and INTEGRATOR_STATE_WRITE macros.
- Unified the checks for the __PATH_GUIDING define to use #  if defined (__PATH_GUIDING__).
- Even if __PATH_GUIDING__ is defined, we now check if the feature is enabled using if ((kernel_data.kernel_features & KERNEL_FEATURE_PATH_GUIDING)) {. This is important for later GPU ports.
- The kernel usage of the guiding field, surface, and volume sampling distributions is wrapped behind macros for each specific device (atm only CPU). This will make it easier for a GPU port later.
2025-05-22 13:46:30 +02:00
Brecht Van Lommel
4d7bd22beb Refactor: Cycles: Graphics interop changes
* Add GraphicsInteropDevice to check if interop is possible with device
* Rename GraphcisInterop to GraphicsInteropBuffer
* Include display device type and memory size in GraphicsInteropBuffer
* Unnest graphics interop class to make forward declarations possible

Pull Request: https://projects.blender.org/blender/blender/pulls/137363
2025-04-28 11:38:56 +02:00
Campbell Barton
2d4290f285 Cleanup: spelling in comments (make check_spelling_*)
Also inconsistent capitalization.
2025-04-24 22:45:22 +00:00
Alaska
6068e05c11 Fix #137676: Clamping of rendered results with OIDN GPU denoising
According to the OptiX denoising guide lines, renders should be in the
0..10000 range. As a result, clamping was applied to renders
prior to GPU denoising.

However this lead to a issue where denoising of bright images would
behave differently between CPU OIDN and GPU OIDN as this same clamping
was also applied to the GPU OIDN denoiser.

According to Attila Áfra, a developer working on OIDN, this clamping
isn't neccesary for OIDN. So this commit removes the clamping from
OIDN.

Pull Request: https://projects.blender.org/blender/blender/pulls/137879
2025-04-24 04:57:36 +02:00
Sergey Sharybin
9f999adfc6 Fix #137230: Cycles OpenPGL crash with shadow catcher
The crash was caused by an overflow in the opgl_path_segment_storage
array. It happened because shadow catcher paths would write to the
segments but not clear them. This made it so the next render loop
iteration for the main path starts with non-empty segments in the
guiding data.

Disable training when megakernel is called for the shadow catcher
state.

To ensure this issue is not forgotten when the guiding is ported to
GPU add asserts in the `guiding.h`. While it is a no-op for default
GPU kernels sometimes we do compile debug kernels. But also it acts
as a plain-text reminder to the future-us in working on the code.

There is now also an assert before the main path megakernel to help
catching such cases in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/137291
2025-04-11 12:31:22 +02:00
Weizhen Huang
0dc46773e0 Fix: Cycles Render Scheduler not respecting sample limit per update
Delay the clamping until later

Pull Request: https://projects.blender.org/blender/blender/pulls/136984
2025-04-04 14:17:08 +02:00
Brecht Van Lommel
14facb987e Fix #132367: Cycles tiled render cancel still does slow denoise
Read the tiles back from disk, but don't run denoiser.

Pull Request: https://projects.blender.org/blender/blender/pulls/133443
2025-01-22 15:54:41 +01:00
Weizhen Huang
f79cae2c59 Fix: Cycles: Compilation issue with WITH_CYCLES_DEBUG enabled
Pull Request: https://projects.blender.org/blender/blender/pulls/133303
2025-01-20 16:11:38 +01:00
Alaska
f09fd9bdef Fix #132935: Add sample subset feature to Cycles
Cycles has a sample offset feature allowing users to render X samples
in a single frame on one device, then the remaining Y samples later or
on a different device and combine them back together at the end.

However in most situations the result from using this method was
different, and usually lower quality than rendering all the samples in
one go.

This was because Cycles tunes it's random number sequence for the
number of samples being rendered. And the random number sequence was
being tuned for the wrong number of samples in the case that a user
was using the sample offset.

This commit fixes this issue by adding a "sample subset" feature.
The user specifies the total sample count being rendered across all
devices in the existing `Max Samples` parameter, then specifies per
device which subset of samples will be rendered (E.g. Render samples
0-1024 out of a 0-2048 range).

This commit also contains some additional clean up work
inside Cycles related to the area being changed.

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/132961
2025-01-15 07:41:16 +01:00
Brecht Van Lommel
96eef81d90 Fix: Cycles assert cancelling render during kernel compilation 2025-01-13 10:07:37 +01:00
Alaska
793918f2b1 Cycles: Update OptiX denoiser type
Update the OptiX denoiser model type to the newer and more frequently
updated `OPTIX_DENOISER_MODEL_KIND_AOV` denoiser.

The output of the new denoiser type is typically higher quality.
And the old denoiser is no longer being updated.

Original change was proposed by Patrick Mours from NVIDIA.

Pull Request: https://projects.blender.org/blender/blender/pulls/132542
2025-01-03 14:11:44 +01:00
Brecht Van Lommel
9971648783 Refactor: Cycles: Replace new/delete by unique_ptr, in simple cases
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:30 +01:00
Brecht Van Lommel
a8654a1dbe Refactor: Cycles: Make CPU kernel globals storage more sane
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:27 +01:00
Brecht Van Lommel
57ff24cb99 Refactor: Cycles: Add const keyword to more function parameters
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:24 +01:00
Brecht Van Lommel
dd51c8660b Refactor: Cycles: Add const keyword where possible, using clang-tidy
Check was misc-const-correctness, combined with readability-isolate-declaration
as suggested by the docs.

Temporarily clang-format "QualifierAlignment: Left" was used to get consistency
with the prevailing order of keywords.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:20 +01:00
Brecht Van Lommel
d0c2e68e5f Refactor: Cycles: Automated clang-tidy fixups in Cycles
* Use .empty() and .data()
* Use nullptr instead of 0
* No else after return
* Simple class member initialization
* Add override for virtual methods
* Include C++ instead of C headers
* Remove some unused includes
* Use default constructors
* Always use braces
* Consistent names in definition and declaration
* Change typedef to using

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:55 +01:00
Brecht Van Lommel
5c46063607 Refactor: Cycles: Make kernel headers work by themselves
Shuffle around some code and add more includes so that individual
header files compile without errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:50 +01:00
Brecht Van Lommel
4e777476b5 Refactor: Cycles: Replace std::bind by lambdas
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:35 +01:00
Brecht Van Lommel
56b7d43887 Fix: Cycles crash when using denoising in build without OIDN
We could try to prevent these parameters to be set earlier in Blender
sync, but I think it's better to handle for all integrations.

Pull Request: https://projects.blender.org/blender/blender/pulls/132477
2024-12-31 15:19:31 +01:00
Sergey Sharybin
d36c2e0fdc Merge branch 'blender-v4.3-release' 2024-10-31 14:48:40 +01:00
Sergey Sharybin
e5a4beb518 Fix #129476: Dual GPU - Bake to Color Attribute Crashes Blender
Various changes to avoid division by zero.

Also avoid invokaiton of kernels with zero work size: CUDA reports an error
in such cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/129633
2024-10-31 14:47:59 +01:00
William Leeson
9ebdd49f39 Fix: Only compact if index is a ratio of the number of paths
Currently the number of shadow paths is multiplied by the ratio of
0.5f which would half the number of paths. However, the index can
never be smaller than the number of paths so the shadow paths will
always be compacted.

Pull Request: https://projects.blender.org/blender/blender/pulls/125048
2024-10-29 14:50:16 +01:00
Patrick Mours
1da221659d Fix #129251: Broken OptiX denoiser output
Looks like some recent changes in the driver broke an assumption
the OptiX denoiser code in Cycles made about being able to set it up
with a different input size than later used to invoke it, which caused
broken output on older GPU architectures. This commit fixes that by
ensuring the input image size passed to `optixDenoiserSetup` matches
that passed to `optixDenoiserInvoke`, even when no tiling is used
(which is the common case).

Pull Request: https://projects.blender.org/blender/blender/pulls/129398
2024-10-29 11:29:22 +01:00
Alaska
8ae944026e Cleanup: Avoid double printing the word 'size' in Cycles debug
Avoid printing the word `size` twice when printing information about
the scheduled tile size to terminal when Blender is launched with
with `--debug-cycles --verbose 3` or higher.

Pull Request: https://projects.blender.org/blender/blender/pulls/127885
2024-09-20 10:10:57 +02:00
Alaska
2d611f7b45 Fix #125392: Cycles: Unnecessary recreation of denoiser
Fix the unnecessary recreation of the denoiser that occurs if
Cycles had fallen back to an alternative denoiser in a previous
interation. (E.g. Fallback from OptiX to OIDN)

This issue occured because Cycles didn't understand that when it
previously setup the denoising device, that it had fallen back to
something else. So it thinks the denoising settings have been changes
and tries to recreate the denoiser.

The solution is to first compute the settings change due to
the fallback, then check to see if it's different from the current
denoiser, then recreate the denoiser device if neccesary.

Pull Request: https://projects.blender.org/blender/blender/pulls/125453
2024-09-12 16:23:59 +02:00
Sergey Sharybin
7e9776a167 Fix #125863: Crash baking textures with Cycles Metal
The issue was caused by an attempt to write buffer pass which is
actually supposed to be calculated as compositing (either summing
direct/indirect lights, optionally diving by albedo).

The fact that the crash was only observed on Metal is a lucky
con-incident: it just happened to be so that writing at offset
-1 to the render buffer did not trigger obvious issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/126057
2024-08-08 12:08:35 +02:00
Sergey Sharybin
f1e82c99b9 Fix: Division by zero in Cycles render scheduler 2024-08-07 18:24:19 +02:00
Campbell Barton
2edc2393d2 Cleanup: spelling in comments 2024-07-25 10:17:42 +10:00
Alaska
090fed06a9 Cycles: Fix automatic OptiX denoiser section criteria
Only select OptiX as the automatic denoiser if an OptiX
device is selected in preferences.

Pull Request: https://projects.blender.org/blender/blender/pulls/124032
2024-07-03 16:00:02 +02:00
Alaska
4961b93136 Cycles: Fix crash using OptiX denoiser with unsupported device selected
Fixes an issue where Blender would crash if the OptiX denoiser was
selected, but an unsupported GPU device (E.g. Intel GPU) was
selected in preferences.

This crash would occur because Cycles uses the device in preferences
to setup the denoiser, and there was no check stopping an unsupported
GPU from being used to try and setup and run the denoiser.

Pull Request: https://projects.blender.org/blender/blender/pulls/124001
2024-07-02 15:58:56 +02:00
Alaska
9e267bbd57 Cycles: Use denoising device info to pick automatic denoiser
Ever since the introduction of GPU OIDN denoising on CPU devices,
using the path_tracing_device info to pick the automatic denoiser has
typically led to incorrect results.

This commit fixes this issue by using the denoising device info to pick
the denoiser.

Pull Request: https://projects.blender.org/blender/blender/pulls/123593
2024-06-24 11:28:02 +02:00
Alaska
47158e1606 Fix #123528: Cycles viewport denoiser not using GPU for CPU render
Cycles automatic denoiser picker assumed that OIDN could not be
run on the GPU while the CPU was the render device. So if the user was
using their CPU for rendering, the automatic denoiser picker would
"fallback" to a different denoiser (OptiX or CPU OIDN). This was true
in Blender 4.1, but changed in 4.2. The UI assumed that OIDN could run
on the GPU if there was a compatible OIDN GPU device.

This lead to a issue on systems using the CPU for rendering
while having a NVIDIA GPU installed in the system. The
UI suggested that OIDN would be used, and would switch between
CPU and GPU depending on user preferences. But the automatic
denoiser picker in Cycle's backend said OIDN could not run on
the GPU in this situation and would always "fallback" to the
OptiX denoiser running on the NVIDIA GPU.
This created a mismatch between the UI and what Cycles was
acutally doing. This issue did not effect other GPU vendors because
their "fallback" was the OIDN denoiser.

This commit fixes this issue by aligning the Cycles automatic
denoiser picker in the backend with the UI. Using OIDN if a GPU
is supported, falling back to OptiX if it's not supported,
falling back to OIDN CPU if OptiX isn't supported,
then falling back to no denoiser if that's not supported.

Pull Request: https://projects.blender.org/blender/blender/pulls/123530
2024-06-21 14:06:50 +02:00
Brecht Van Lommel
3a7a9c60df Cleanup: Compiler warning building without OIDN 2024-06-12 18:29:49 +02:00
Sergey Sharybin
b803d7fabb Fix: Command line Cycles render crash on multi-CUDA device
Since #118841 there are more cases where Cycles would check for the
graphics interop support. This could lead to a crash when graphics
interop functions are called without having active graphics context.

This change makes it so there is no graphics interop calls when doing
headless render. In order to achieve this the device creation is now
aware of the headless mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/122844
2024-06-07 17:53:44 +02:00
Nikita Sirgienko
1790314f89 Cycles: Fix multiple "Loading denoising kernels" messages
Pull Request: https://projects.blender.org/blender/blender/pulls/122880
2024-06-07 16:05:48 +02:00
Sergey Sharybin
7886ce7bd4 Fix: Cycles crash when using multiple devices
Additional requirement is to have OpenImageDenoiser, and the devices
should not support OIDN denoiser.

Reproduced here in the studio with a system on Linux with either double
Quadro GP100 cards, and Limnux with Quadro 6000 + Quadro 6000 ADA.

The reason for the crash is that the find_best_device() might return
nullptr, and it was never checked.

Pull Request: https://projects.blender.org/blender/blender/pulls/122823
2024-06-06 12:31:31 +02:00
Campbell Barton
7f7648c6ed Cleanup: spelling in code comments & minor edits
- Use uppercase NOTE: tags.
- Correct bNote -> bNode.
- Use colon after parameters.
- Use doxy-style doc-strings.
2024-06-06 09:55:13 +10:00
Lukas Stockner
a4d933e93e Cycles: Clamp sample number during viewport navigation to max samples
Previously, Cycles would render up to 4SPP during viewport navigation when
using reduced resolution, even when the overall number of samples was set
lower.

This causes problems with the blue-noise pattern, so ensure that the
number of samples is always clamped to the configured maximum.
2024-06-05 23:17:09 +02:00
Lukas Stockner
27ec99c568 Cycles: Fix building without OpenImageDenoise 2024-06-05 20:24:51 +02:00
Michael Jones
5be30b7d2b Cycles: "Struct-of-array-of-packed-structs" for parts of the integrator state
On a M3 MacBook Pro, this change increases the benchmark score by 8% (with classroom seeing a path-tracing speedup of 15%).

The integrator state is currently store using struct-of-arrays, with one array per field. Such fine grained separation can result in poor GPU cache utilisation in cases where multiple fields of the same parent struct are accessed together. This PR changes the layout of the `ray`, `isect`, `subsurface`, and `shadow_ray` structs so that the data is interleaved (per parent struct) instead of separate. To try and keep this change localised, I encapsulated the layout change by extending the integrator state access macros, however maybe we want to do this more explicitly? (e.g. by updating every bit of code that accesses these parts of the state). Feedback welcome.

Pull Request: https://projects.blender.org/blender/blender/pulls/122015
2024-06-04 14:53:30 +02:00
Sergey Sharybin
6e0a49265a Fix #122622: Cycles GPU performance regression in certain scenes
This is an oversight of #122543, for which benchmarking was done in
the headless mode.

The solution is to tweak policy a little bit, and keep refresh intervals
low for the first 10 seconds of render, after which increase updates to
every 15 seconds. Doing so allows:

- Have quick cancel of complex files when the error is noticed during
  the first few samples.
- Have more predictable cancel time after long render.
- Mitigate the performance regression.

This does not fully solve the regression, but it makes it much more
manageable. There are some compromises to be done from the performance
for the UI renders. The interactivity is also not as fantastic, but it
could be solved later by introducing some "Instant Cancel" operations
which would be able to also stop render in the middle of a sample.

Performance measured with the Spring file (path tracing time in seconds):

    Samples:                  300    1024    2048
    Base (prior to #122543):  29.1   85.4    174.1
    This patch:               37.0   95.7    180.2

This is measured on M2 Ultra GPU render.

The penalty is close to a constant time (the time within which a more
interactive cancel is possible.

Pull Request: https://projects.blender.org/blender/blender/pulls/122658
2024-06-04 14:45:46 +02:00
Lukas Stockner
0566bf11b3 Cycles: Add debugging option to load custom OIDN weights
Pull Request: https://projects.blender.org/blender/blender/pulls/122591
2024-06-04 01:22:44 +02:00
Nikita Sirgienko
4651f8a08f Fix: Respect Blender Cycles setting for GPU denoising
Previously, GPU denoisers were ignoring settings about render
configuration and were using any available GPU. With these changes,
GPU denoisers will use the device selected in Blender Cycles
settings.
This allows any GPU denoiser to be used with CPU rendering.

Pull Request: https://projects.blender.org/blender/blender/pulls/118841
2024-06-03 22:41:25 +02:00
Nikita Sirgienko
e0ecf443d4 Cycles: Fix compile error in 1465076a0a 2024-06-03 11:33:28 +02:00
Nikita Sirgienko
6d87a5d9ed Cleanup: Cycles: Fix type in the OpenImageDenoise name.
There are no functional changes expected.
2024-06-03 11:11:20 +02:00
Nikita Sirgienko
1465076a0a Refactor: Cycles: Unify error reporting code from denoiser's classes
There are no functional changes expected.
2024-06-03 11:11:19 +02:00
Nikita Sirgienko
cb8d2bf4ad Fix: Cycles: Add missing queue init in run_film_convert_kernels 2024-06-03 11:11:19 +02:00
Sergey Sharybin
5f11ae70ea Fix: Cycles is not responsive to cancel render in complex scenes
In some of the complex scenes it could a very long time for Cycles
to respond to cancel request. This is because Cycles only cancels
render at a consistent state of render buffer: when all scheduled
samples are rendered.

This was caused by the render scheduler over-scheduling the number
of samples in an attempt to improve occupancy of the GPU.

This fix makes it so the scheduler only compensates for the low
occupancy if rendering can happen within a desired update time.

There is no visible difference in the benchmark scenes with this
change.

Pull Request: https://projects.blender.org/blender/blender/pulls/122543
2024-05-31 15:54:14 +02:00
Michael Jones
e82d69daa1 Cycles: Disambiguate shadow integrator state buffer names
This patch adds a "shadow" prefix & array index suffixes to the shadow integrator state buffer names. This eliminates confusion when looking at GPU traces etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/121745
2024-05-15 23:19:24 +02:00
Attila Áfra
26c93c8359 Cycles: Enable OIDN 2.3 lazy device module loading
This enables the new lazy module loading behavior introduced in OIDN 2.3,
without breaking compatibility with older versions of OIDN (using separate
code paths).

Also, the detection of OIDN support for devices is now much cleaner, and
devices do not need to be matched by PCI address or device name anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/121362
2024-05-07 14:07:39 +02:00