Commit Graph

14013 Commits

Author SHA1 Message Date
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
Lukas Stockner
4bde68cdd6 Cycles: Compress GPU kernels to reduce file size
Precompiled Cycles kernels make up a considerable fraction of the total size of
Blender builds nowadays. As we add more features and support for more
architectures, this will only continue to increase.

However, since these kernels tend to be quite compressible, we can save a lot
of storage by storing them in compressed form and decompressing the required
kernel(s) during loading.

By using Zstandard compression with a high level, we can get decent compression
ratios (~5x for the current kernels) while keeping decompression time low
(about 30ms in the worse case in my tests). And since we already require zstd
for Blender, this doesn't introduce a new dependency.

While the main improvement is to the size of the extracted Blender installation
(which is reduced by ~400-500MB currently), this also shrinks the download on
Windows, since .zip's deflate compression is less effective. It doesn't help on
Linux since we're already using .tar.xz there, but the smaller installed size
is still a good thing.

See #123522 for initial discussion.

Pull Request: https://projects.blender.org/blender/blender/pulls/123557
2024-06-23 00:52:30 +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
Werner, Stefan
9004e7b668 Fix: Compiler warning about format string
Don't pass string class into printf("%s"), only char* allowed.
2024-06-21 12:29:02 +02:00
Luya Tshimbalanga
a9fe638972 Fix: Cycles runtime compile using outdated HIP parameters
This commit resolves an warning message.

Signed-off-by: Luya Tshimbalanga <luya@fedoraproject.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/118401
2024-06-20 12:43:27 +02:00
Bastien Montagne
32ece7d604 Fix (unreported) 'copy' version of MEM_cnew not handling alignment.
Almost certainly not an issue in current codebase (this 'copy' version
of `MEM_cnew` does not seem much used in the first place), but better be
consistent with the 'allocating' version.

Pull Request: https://projects.blender.org/blender/blender/pulls/123445
2024-06-20 11:00:34 +02:00
Bastien Montagne
461ee89b61 Cleanup: Sync 'alignment' checks of guarded allocator with lockfree one.
Sync a bit better the checks on the alignment value between
`MEM_lockfree_mallocN_aligned` and `MEM_guarded_mallocN_aligned`.

The only significant change, in `MEM_guarded_mallocN_aligned`, is the
usage of `ALIGNED_MALLOC_MINIMUM_ALIGNMENT` instead of 'magic value' `8`.
This should not have any effect on 64bits platforms, but on 32bits ones
the minimum alignment would be reduced from `8` to `4` now.

NOTE: we could also consider making these checks part of a utils
function, instead of duplicating them in the codebase.
2024-06-20 11:00:33 +02:00
Campbell Barton
50bb98fba5 Fix #123339: Blender fails to build with older versions of wayland
Follow up to [0] which only addressed one of the issues.

[0]: bc7cb481da
2024-06-19 19:36:10 +10:00
Alaska
10737d719e Cleanup: Correct Cycles code comment
The code comment references a variable that was removed during the
review process of !123341

Pull Request: https://projects.blender.org/blender/blender/pulls/123409
2024-06-19 10:42:13 +02:00
Alaska
56bb8b2b3c Fix #123324: Improve Cycles camera bounding box size calculation
Cycles runs a check to see if the camera is possibly inside a
volumetric object by seeing if the bounding box of the camera
and volumetric object intersect.

If the calculation is wrong (Cycles says the camera is outside the
volume when it's inside it), then the volume will not render properly.

This commit resolves most of these issues by making the camera
bounding box larger than before, taking into consideration
features like:

1. The impact DOF could have on the camera ray start position and how
that should impact the bounding box size.
2. Taking into consideration near clipping, which was missed from the
orthographic camera due to a oversight in a previous commit
(08cc73a9bb).

Pull Request: https://projects.blender.org/blender/blender/pulls/123341
2024-06-18 17:35:16 +02:00
Patrick Mours
56c1163c21 Fix: Cycles OptiX wrong stack size for OSL pipeline
The callables generated by OSL reference other external functions
(defined in the OSL services module), in which case OptiX cannot
calculate the right stack size just based on the callable alone, it needs to
know all functions linked together in the pipeline to get to an accurate
result. `optixProgramGroupGetStackSize` has an optional pipeline
argument for this purpose, so make use of that to ensure the correct
stack size is calculated.

Ref #122779

Pull Request: https://projects.blender.org/blender/blender/pulls/123368
2024-06-18 15:27:14 +02:00
Campbell Barton
bc7cb481da Fix #123339: Blender fails to build with older versions of wayland 2024-06-18 20:37:25 +10:00
Anthony Roberts
794a8f35fa Windows: Update GPU error message on ARM64
This makes it more verbose, and a little clearer that devices prior to 8cx Gen3 are not supported in  >=v4.0. It makes the error message from #113674 more prominent than just being printed to cout.

Spurred by an email I got from someone trying to run blender on a Surface Pro X, and getting the not very helpful (to old devices) error.

Pull Request: https://projects.blender.org/blender/blender/pulls/122732
2024-06-18 11:47:01 +02:00
Campbell Barton
0554ec7ec7 Cleanup: spelling in comments 2024-06-18 12:09:40 +10:00
Alaska
08cc73a9bb Fix #123249: Orthographic DOF is influenced by near clip
Fix an issue where the DOF distance in orthographic mode is
specified distance + near clip distance, which can lead to
unpredicable results.

Pull Request: https://projects.blender.org/blender/blender/pulls/123267
2024-06-17 17:45:55 +02:00
Alaska
274da96722 Render: Clamp minimum DOF focus distance
Clamp DOF focus distance to a minimum of 1e-5.
This is to primarily stop focus distances of 0 being used
which would lead to issues in future code changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/123310
2024-06-17 17:42:38 +02:00
Lukas Stockner
e118fe6e47 Cycles: Fix directional artifacts in blue noise sampling pattern
The base-4 Owen scrambling hash needs a seed value that's somewhat random-
looking, so the default value of 0 causes problems. Hashing the input seed
avoids this.

To avoid changing the noise pattern in pre-4.2 scenes, this hash is only
applied to blue-noise patterns.

Pull Request: https://projects.blender.org/blender/blender/pulls/123274
2024-06-15 22:05:18 +02:00
Campbell Barton
8ab246ddde Build: fix linking FFMPEG & x265 on Linux 2024-06-15 14:15:53 +10:00
Brecht Van Lommel
a87907b425 Fix #123201: Cycles OSL bump mapping broken
After the last OSL update, the Normal input to the auto generated Bump
node was getting a constant value instead of the normal.
2024-06-14 16:54:44 +02:00
Brecht Van Lommel
90f09f016e Fix: Incorrect call to cuCtxPopCurrent
cuDevicePrimaryCtxRetain does not push the context onto the stack,
unlike cuCtxCreate.
2024-06-13 19:41:20 +02:00
Brecht Van Lommel
d72c4f0096 Fix: Cycles build issues when disabling various kernel features 2024-06-13 19:41:19 +02:00
Weizhen Huang
e639c3d6e2 Fix #74816: crash in Cycles light distribution due to integer overflow
`num_distribution` in `KernelIntegrator` has type `int`, which holds a
maximal value of 2147483647. However, when computing the distribution,
`size_t` is used, which can go beyond this value and result in a
negative value when converted to `int`.

This PR handles this case as an error, stops rendering and suggests
alternative solutions.

Also early return when `use_light_tree`. The block was there because
`num_distribution` was needed for light tree before bfd1836861.

Pull Request: https://projects.blender.org/blender/blender/pulls/123177
2024-06-13 15:57:11 +02:00
Damien Picard
f87d4e4e40 I18n: Extract and disambiguate a few messages
Extract
- Cycles denoiser enum.
- Extensions user preferences UI.
- Node operator poll message from new node function.

Improve
- Split "(Enabled|Disabled) on startup, overriding the preference."
into two messages.

Disambiguate
- "Add" when describing the action of adding something should use the
  Operator context.
- "Dimensions", in noise textures.
- "Transform" as a noun, the matrix transform type of Geometry Nodes,
  as opposed to the verb to move things in space.
- "Parent" as a noun or verb (the parent of an object, to parent an
  object to another).

Some issues reported by Satoshi Yamasaki, deathblood, and Gabriel Gazzán.

Pull Request: https://projects.blender.org/blender/blender/pulls/122969
2024-06-13 12:15:55 +02:00
Brecht Van Lommel
87dae7d800 Build: Clean up oneAPI cmake messages
* Always define root directories in LIBDIR even when not needed,
  to silence some warnings.
* Only show warnings about not finding libs when oneAPI is enabled.
* Prefix message for context.
2024-06-12 19:21:43 +02:00
Brecht Van Lommel
3a7a9c60df Cleanup: Compiler warning building without OIDN 2024-06-12 18:29:49 +02:00
Brecht Van Lommel
397b96ed2e Fix #121819: OpenColorIO GLSL error after recent change, only apply to Metal 2024-06-12 18:29:49 +02:00
Brecht Van Lommel
f969208405 Fix #121819: OpenColorIO Metal GLSL error with grading curve 2024-06-12 18:10:46 +02:00
Sergey Sharybin
e67c95c8c4 Fix: Cycles renders black on AMD Metal
A mistake in the #122015 which lead to discrepancy between
CPU and GPU states: TargetConditionals.h always defines the
target CPU, and defines it to either 1 or 0.

The proper way of checking it is to `#if TARGET_CPU_ARM64`.

Some examples can be seen there:

  https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary

Pull Request: https://projects.blender.org/blender/blender/pulls/123140
2024-06-12 18:06:06 +02:00
David Murmann
4cfae88f09 Fix #122739: mix causes unnecessary evaluation when ints are used
Fixes #122739.

I added all five missing conversions that the convert node can do in the svm code to the constant folding.

Pull Request: https://projects.blender.org/blender/blender/pulls/123035
2024-06-12 10:37:39 +02:00
Fabian-Herb
1dfdf098d2 Fix #122933: Enable Cycles OpenImageDenoise on Linux ARM64
_M_ARM64 is defined on Visual Studio only, but OpenImageDenoise 2.2 works on
ARM64 Linux, too. ARM64 always has NEON, so that remark was a no-op.

Pull Request: https://projects.blender.org/blender/blender/pulls/122948
2024-06-11 19:28:59 +02:00
Weizhen Huang
f9a75d1e40 Fix #122976: Cycles light linking broken for volumes with light tree
Light linking was never working correctly in volume segment with light
tree, because `sd->object` was not assigned, thus
`light_link_receiver_nee(kg, sd)` always returned `OBJECT_NONE`, causing
the light tree sample to fail. This problem was revealed by fdc2962beb
since now the same light is used for volume segment and volume.

Also ensure we don't sample position on the light if sampling from
volume segment is failed, by setting `emitter_id` to `EMITTER_NONE` in
such cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/122999
2024-06-10 16:11:12 +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
Alaska
599f6f612f Cycles: Add tool tips for debug blue noise sampling patterns
Pull Request: https://projects.blender.org/blender/blender/pulls/122816
2024-06-06 16:47:20 +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
Nikita Sirgienko
2ced22611a Cycles: Fix missing adjustment for device, used for denoising
This is a proper fix for the issue worked around in 11d311e300.

Previously, an incorrect condition adjustment of the device info
was done for a preferred device. Now, this change reverts that
condition, and the adjustment is done correctly and unconditionally.
2024-06-05 11:53:31 +02:00
Lukas Stockner
f3f05f945c Cycles: Add missing make_uintX definitions for Metal 2024-06-05 03:04:04 +02:00
Lukas Stockner
79ddd07e76 Cleanup: Formatting 2024-06-05 03:04:03 +02:00
Lukas Stockner
5246fb5a57 Cycles: Implement blue-noise dithered sampling
This patch implements blue-noise dithered sampling as described by Nathan Vegdahl (https://psychopath.io/post/2022_07_24_owen_scrambling_based_dithered_blue_noise_sampling), which in turn is based on "Screen-Space Blue-Noise Diffusion of Monte Carlo Sampling Error via Hierarchical Ordering of Pixels"(https://repository.kaust.edu.sa/items/1269ae24-2596-400b-a839-e54486033a93).

The basic idea is simple: Instead of generating independent sequences for each pixel by scrambling them, we use a single sequence for the entire image, with each pixel getting one chunk of the samples. The ordering across pixels is determined by hierarchical scrambling of the pixel's position along a space-filling curve, which ends up being pretty much the same operation as already used for the underlying sequence.

This results in a more high-frequency noise distribution, which appears smoother despite not being less noisy overall.

The main limitation at the moment is that the improvement is only clear if the full sample amount is used per pixel, so interactive preview rendering and adaptive sampling will not receive the benefit. One exception to this is that when using the new "Automatic" setting, the first sample in interactive rendering will also be blue-noise-distributed.

The sampling mode option is now exposed in the UI, with the three options being Blue Noise (the new mode), Classic (the previous Tabulated Sobol method) and the new default, Automatic (blue noise, with the additional property of ensuring the first sample is also blue-noise-distributed in interactive rendering). When debug mode is enabled, additional options appear, such as Sobol-Burley.

Note that the scrambling distance option is not compatible with the blue-noise pattern.

Pull Request: https://projects.blender.org/blender/blender/pulls/118479
2024-06-05 02:29:47 +02:00
Weizhen Huang
2ddc936cbb Cleanup: simplify computation in Cycles area light sampling
`diff` in numerator and denominator cancels out, except for the signs,
which we know beforehand since `x1 > x0`, `y1 > y0`

Pull Request: https://projects.blender.org/blender/blender/pulls/122740
2024-06-04 23:37:48 +02:00
Xavier Hallade
a7171e0391 Cycles: oneAPI: Cleanup: Change packed_float3 to float3
float3 is already packed in oneAPI.
No functional change is expected.
2024-06-04 19:42:52 +02:00
zhanghe9702
b7303c5183 Fix: Cycles standalone build failures
Pull Request: https://projects.blender.org/blender/blender/pulls/122718
2024-06-04 19:04:29 +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
Brad Smith
b0fdca60cd Cleanup: Mikktspace: use sqrtf() function with float type
Pull Request: https://projects.blender.org/blender/blender/pulls/121703
2024-06-04 14:27:17 +02:00
Sergey Sharybin
11d311e300 Fix: Cycles assert in device consistency check
A regression since #118841.

It is possible that the selected preference device is not found, in which
case a default-initialized DeviceInfo would have added to the list. This
device is set to CPU, but with differnet other fields (such as description)
compared to the actual CPU device.

Pull Request: https://projects.blender.org/blender/blender/pulls/122701
2024-06-04 12:49:30 +02:00
Lukas Stockner
e8c83aed17 Cleanup: Formatting 2024-06-04 02:01:44 +02:00