Commit Graph

14100 Commits

Author SHA1 Message Date
Bastien Montagne
4195e9e1a7 MEM_guarded: Improve error reporting usefulness.
The main change from this commit is the usage of ASAN poisoning (if
available) to trigger an ASAN report on the erroring memory block.

The main benefit is the report of the allocation backtrace of that
faulty memory block.

Pull Request: https://projects.blender.org/blender/blender/pulls/124231
2024-07-08 12:10:37 +02:00
Campbell Barton
cd1dbab348 Cleanup: spelling in comments 2024-07-07 00:29:39 +10:00
Campbell Barton
2b88bcdd3a Merge branch 'blender-v4.2-release' 2024-07-05 20:49:38 +10:00
Campbell Barton
a796589ed1 Fix memory leak in GHOST_WindowX11::getDPIHint
XrmDatabase wasn't destroyed when it successfully found the DPI.
2024-07-05 20:33:36 +10:00
Alaska
9d1e613292 Cycles: Refactor and add use_gpu() to UI code
Add a `use_gpu()` function to the UI code for Cycles.
This is done to clean up some of the other code (`use_{backend}()`)
and to help isolate `use_multi_device` and `show_device_active` from
their context making them more robust to changes made in other parts
of the UI code.

Pull Request: https://projects.blender.org/blender/blender/pulls/124134
2024-07-04 11:21:45 +02:00
Jeroen Bakker
84cbf33b38 Vulkan: Enable multi draw indirect feature
Multi draw indirect is used by the overlay engine and can lead
to a validation error when multiple instances are drawn.

This PR enabled the feature. We expect that all our devices can handle
this feature.

Pull Request: https://projects.blender.org/blender/blender/pulls/124141
2024-07-04 10:42:20 +02:00
Alexander Brock
717c970297 Add round-trip tests for *_to_direction functions and fix some of them
The function `direction_to_<some projection model>` computes the inverse of `<some projection model>_to_direction`.
Some of these functions had a bug where they mirror the x-axis, and some of them could be simplified.
I added round-trip tests for all of them.
This MR might change the behavior of the renderer when using equiangular_cubemap_face_to_direction:
I normalized the result vector. I looked at the usages and I think it's normalized later anyways, but someone else should probably verify that this doesn't cause issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/123932
2024-07-04 09:54:50 +02:00
Bastien Montagne
06be295946 Add detection of mismatches usages of MEM_new/MEM_freeN.
This commit will error (and abort if enabled) when trying to call
`MEM_freeN` (and related `MEM_dupallocN`, `MEM_reallocN` and
`MEM_recallocN` functions) with a pointer created the C++ way (i.e.
through `MEM_new`, or the guardedalloc-overloaded `new` operator).

To do so, it adds internal use only implementations for `malloc_alligned`
and `free`, which take an extra parameter indicating whether they are
dealing with data created/deleted the 'C++ way' (using `new`/`delete`
and similar).

The cpp-created data are flagged with the new
`MEMHEAD_FLAG_FROM_CPP_NEW`, either in the lower two-bytes len value for
lockfree allocator, or as a new flag member of the guarded allocator
header data.

The public `MEM_new`/`MEM_delete` template functions, and the
guardedalloc-overloaded versions of `new`/`delete` operators are updated
accordingly.

These changes have been successfully tested both with and without
`WITH_CXX_GUARDEDALLOC`.

NOTE: A lot of mismatches have already been fixed in `main` before merging
this change. There are likely some less easy to trigger ones still in our
codebase though.

Pull Request: https://projects.blender.org/blender/blender/pulls/123740
2024-07-03 17:23:03 +02:00
Bastien Montagne
4afb48acad Cleanup: Move internal guardedalloc headers to C++.
Pull Request: https://projects.blender.org/blender/blender/pulls/124106
2024-07-03 16:04:18 +02:00
Sergey Sharybin
35788ca3c9 Merge branch 'blender-v4.2-release' 2024-07-03 16:01:21 +02:00
Alaska
659e19607d Cycles: Cleanup calls to _cycles.available_devices
Refactor the call to `_cycles.available_devices` into it's own function
and update `self.device` at the same time to avoid mis-matches between
`_cycles.available_devices` and `self.device`.

Pull Request: https://projects.blender.org/blender/blender/pulls/124079
2024-07-03 16:00:42 +02: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
Nikita Sirgienko
74c09b2e63 Cycles: oneAPI: Fix undefined behavior when embree fails initializing
Embree device pointer can end up being nullptr even when Embree on GPU is
expected to be used.  Previous implementation overlooked this possibility,
leading to a completely silent fallback to the non-Hardware ray-tracing path,
this commit fixes it.  We've noticed this as now Embree relies on a driver
component: https://github.com/intel/level-zero-raytracing-support that can
potentially be missing from a system.

Pull Request: https://projects.blender.org/blender/blender/pulls/124085
2024-07-03 14:13:01 +02:00
Xavier Hallade
4477641467 Cycles: oneAPI: Fix driver version check for future Intel GPU drivers
SYCL runtime currently relies on an internal driver behavior that will
break the driver version string returned by SYCL if it changes:
https://github.com/oneapi-src/unified-runtime/issues/1777
This will be fixed at SYCL runtime level but until we use a new enough
one, we need to add additional verifications to avoid blocking execution
on a driver that will change this internal behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/124084
2024-07-03 14:12:16 +02:00
Xavier Hallade
275b6ee008 Merge branch 'blender-v4.2-release' 2024-07-03 14:03:37 +02:00
Sergey Sharybin
368143c4f2 Merge branch 'blender-v4.2-release' 2024-07-02 16:03:21 +02:00
Alaska
f3fb3a9ecd Cycles: Update device entries more often
This resolves two issues:
1. On macOS the GPU Compute device would be disabled by default unless
the user opens user preferences. This is unexpected behaviour ever
since 09ba1486f8224
2. Fixes incorrect automatic denoiser display settings and errors in
terminal related to the denoising UI on macOS if the user hasn't opened
user preferences.

Pull Request: https://projects.blender.org/blender/blender/pulls/123911
2024-07-02 16:02:53 +02:00
Sergey Sharybin
de6037c43d Merge branch 'blender-v4.2-release' 2024-07-02 15:59:33 +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
Lukas Stockner
87159b2871 Cycles: Add Diffuse Roughness option to Principled BSDF
Setting this option to a value above zero replaces the lambertian Diffuse term
with the modified energy-preserving Oren-Nayar BSDF, which matches the OpenPBR
behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/123616
2024-07-01 15:49:09 +02:00
Weizhen Huang
f2215d7564 Fix: safe_normalize() not defined for float2 on Metal 2024-07-01 13:58:30 +02:00
Alexander Brock
1b09654530 Fix and test direction_to_fisheye_lens_polynomial
The function direction_to_fisheye_lens_polynomial computes the inverse of
fisheye_lens_polynomial_to_direction.

Previously the function worked almost correctly if all parameters except k_0
and k_1 were zero (in that case it was correct except for flipping the x-axis).

I replaced the fixed-point iteration (?) by Newton's method and implemented a
test to make sure it works correctly with a wider range of parameter sets.

Pull Request: https://projects.blender.org/blender/blender/pulls/123737
2024-07-01 13:56:35 +02:00
Weizhen Huang
4c5c5e2fd7 Fix: safe_normalize() not defined for float2 on Metal 2024-06-29 07:56:46 +02:00
Alexander Brock
fe54824f24 Fix and test direction_to_fisheye_lens_polynomial
The function direction_to_fisheye_lens_polynomial computes the inverse of
fisheye_lens_polynomial_to_direction.

Previously the function worked almost correctly if all parameters except k_0
and k_1 were zero (in that case it was correct except for flipping the x-axis).

I replaced the fixed-point iteration (?) by Newton's method and implemented a
test to make sure it works correctly with a wider range of parameter sets.

Pull Request: https://projects.blender.org/blender/blender/pulls/123737
2024-06-28 20:33:17 +02:00
Lukas Stockner
6967255906 Color management: Support white balance as part of the display transform
This implements a von-Kries-style chromatic adaption using the Bradford matrix.
The adaption is performed in scene linear space in the OCIO GLSL shader, with
the matrix being computed on the host.

The parameters specify the white point of the input, which is to be mapped to
the white point of the scene linear space. The main parameter is temperature,
specified in Kelvin, which defines the blackbody spectrum that is used as the
input white point. Additionally, a tint parameter can be used to shift the
white point away from pure blackbody spectra (e.g. to match a D illuminant).

The defaults are set to match D65 so there is no immediate color shift when
enabling the option. Tint = 10 is needed since the D-series illuminants aren't
perfect blackbody emitters.

As an alternative to manually specifying the values, there's also a color
picker. When a color is selected, temperature and tint are set such that this
color ends up being balanced to white.
This only works if the color is close enough to a blackbody emitter -
specifically, for tint values within +-150. Beyond this, there can be ambiguity
in the representation.
Currently, in this case, the input is just ignored and temperature/tint aren't
changed. Ideally, we'd eventually give UI feedback for this.

Presets are supported, and all the CIE standard illuminants are included.

One part that I'm not quite happy with is that the tint parameter starts to
give weird results at moderate values when the temperature is low.
The reason for this can be seen here:
https://commons.wikimedia.org/wiki/File:Planckian-locus.png
Tint is moving along the isotherm lines (with the plot corresponding to +-150),
but below 4000K some of that range is outside of the gamut. Not much can
be done there, other than possibly clipping those values...

Adding support for this to the compositor should be quite easy and is planned
as a next step.

Pull Request: https://projects.blender.org/blender/blender/pulls/123278
2024-06-27 23:27:58 +02:00
Brecht Van Lommel
3072e6f518 Merge branch 'blender-v4.2-release' 2024-06-26 21:30:39 +02:00
Brecht Van Lommel
4b47a48ea2 Hydra: Fix Cycles render delegate to build with USD 24.x 2024-06-26 21:06:40 +02:00
Brecht Van Lommel
a060de65a4 Cycles: Sync minor build related changes with standalone repo 2024-06-26 20:39:03 +02:00
howetuft
5e40dcc95d Cycles: Expose object node in XML API
The Object node is not currently exposed in the XML API, but rather
implicitly created along with Mesh nodes. This prevents accessing
features that are dependent on this node, like caustics settings.

Pull Request: https://projects.blender.org/blender/cycles/pulls/8
2024-06-26 20:39:03 +02:00
howetuft
dc35852107 Cycles: Expose vertex normals and tangent space attributes in XML API
The vertex normals and tangent space attributes are not currently exposed by
the XML API, in the Mesh node. This notably prevents the XML API user
from applying normal maps to meshes in tangent space.

To overcome this situation, this commit adds three attributes to the Mesh node:
N: vertex normals
tangent: tangents
tangent_sign: tangent signs

Nota: at the moment, these attributes are only available for non-subdivided
meshes.

Pull Request: https://projects.blender.org/blender/cycles/pulls/9
2024-06-26 20:39:02 +02:00
Pierre Pontier
3be050ed47 Fix: Cycles build error with GCC and Clang with some build options
Pull Request: https://projects.blender.org/blender/cycles/pulls/5
2024-06-26 20:39:02 +02:00
Alaska
c8340cf754 Cycles: Remove AMD and Intel GPU support from Metal backend
This is because with the addition of new features to Cycles, these GPUs
experienced significant performance regressions and bugs, all stemming
from bugs in the Metal GPU driver/compiler. The only reasonable way to
work around these issues was to disable parts of Cycles code on
these GPUs to avoid the driver/compiler bugs.

This resulted in increased development time maintaining these platforms
while being unable to deliver feature parity with other
GPU backends.

It has been decided that this development time is better spent
maintaining platforms that are still actively maintained by
hardware/software vendors, and so AMD and Intel GPU support will be
removed from the Metal backend for Cycles.

Pull Request: https://projects.blender.org/blender/blender/pulls/123551
2024-06-26 17:16:20 +02:00
Sergey Sharybin
af71cb6485 Merge branch 'blender-v4.2-release' 2024-06-26 14:16:30 +02:00
Alaska
3232458152 Fix #123763: Cycles Metal renders with MNEE stuck on some Macs
On some Macs, MNEE would be disabled in Cycles to work around a bug.
However this just led to these devices skipping over MNEE related
parts of the rendering pipeline and not properly progressing through
the render.

This commit fixes this issue by properly disabling MNEE on these devices.

Pull Request: https://projects.blender.org/blender/blender/pulls/123765
2024-06-26 14:15:01 +02:00
Bastien Montagne
2d7f00e410 Merge branch 'blender-v4.2-release' 2024-06-26 11:50:27 +02:00
Bastien Montagne
c525e4db83 Revert "GHOST/Wayland: reference the stable tablet-v2 API"
The currently available `wayland-protocol` libraries in lib-linux_x64
repo do not appear to be advertised 1.36 (or 1.35) versions, since the
tablet protocol is not available among the stable ones.

This reverts commit 2a85eaaf169c51cfb24d4564fa58b4c89ce6d773.

Pull Request: https://projects.blender.org/blender/blender/pulls/123774
2024-06-26 11:48:55 +02:00
Campbell Barton
9ee6da08ab Merge branch 'blender-v4.2-release' 2024-06-26 16:29:57 +10:00
Campbell Barton
2a85eaaf16 GHOST/Wayland: reference the stable tablet-v2 API
The tablet API become stable in wayland-protocol 1.35
2024-06-26 16:26:18 +10:00
Brecht Van Lommel
31de58e161 Merge branch 'blender-v4.2-release' 2024-06-26 02:40:26 +02:00
Brecht Van Lommel
224307b9aa Fix: Cycles build error with OptiX after recent changes
Ref #123733

Pull Request: https://projects.blender.org/blender/blender/pulls/123761
2024-06-26 02:39:12 +02:00
Weizhen Huang
e49fda3ff8 Merge branch 'blender-v4.2-release' 2024-06-25 18:50:54 +02:00
Weizhen Huang
02e6985c62 Fix #94323: Cycles blocky artifacts in overlapping volumes due to scale difference
when computing coefficients in volume, the volume density of the object
at the top of the stack is used, which leads to wrong result if
overlapping volumes have different scales.
This commit fixes the problem by pre-multiplying the volume density per
object when evaluating the shader.

Pull Request: https://projects.blender.org/blender/blender/pulls/123733
2024-06-25 18:49:26 +02:00
Sergey Sharybin
111d4e5837 Fix: Misleading description of the samples count pass
It used to be an absolute number, but since the Cycles X project
it became normalized, for easier visual feedback.
2024-06-25 14:23:10 +02:00
Weizhen Huang
f4afd404e5 Merge branch 'blender-v4.2-release' 2024-06-24 12:57:08 +02:00
Weizhen Huang
6fbc958e89 Fix: Cycles Light Tree gives low weight to distant lights in large volume
The original paper only considers the minimal distance of the cluster to
the ray, not the interval length, resulting in low weight for distant
lights that have large influence over a long distance.
This commit modifies the measure by considering `theta_b - theta_a` for
local lights and the ray length `t` for distant lights.

Pull Request: https://projects.blender.org/blender/blender/pulls/123537
2024-06-24 12:48:08 +02:00
Bastien Montagne
069e32b2bf Merge branch 'blender-v4.2-release' 2024-06-24 11:31:01 +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
Lukas Stockner
4547260bda Merge branch 'blender-v4.2-release' 2024-06-23 01:23:51 +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
89583e991d Fix: Cycles rough diffuse rendering with bright input color in OSL
The Oren Nayer diffuse BSDF had a energy compensation term added in a
recent commit[1]. This energy compensation term used the colour input
in it's computation. The colour input was clamped in SVM, but not OSL,
resulting in differences between the two backends. This commit resolves
this issue by clamping the colour in the OSL script to match SVM.

[1] 5e40b9bb5cefdaca2d88bb6316e180b2bdf929db

Pull Request: https://projects.blender.org/blender/blender/pulls/123527
2024-06-21 18:54:15 +02:00