Commit Graph

14661 Commits

Author SHA1 Message Date
Bastien Montagne
48e26c3afe MEM_guardedalloc: Refactor to add more type-safety.
The main goal of these changes are to improve static (i.e. build-time)
checks on whether a given data can be allocated and freed with `malloc`
and `free` (C-style), or requires proper C++-style construction and
destruction (`new` and `delete`).

* Add new `MEM_malloc_arrayN_aligned` API.
* Make `MEM_freeN` a template function in C++, which does static assert on
  type triviality.
* Add `MEM_SAFE_DELETE`, similar to `MEM_SAFE_FREE` but calling
  `MEM_delete`.

The changes to `MEM_freeN` was painful and useful, as it allowed to fix a bunch
of invalid calls in existing codebase already.

It also highlighted a fair amount of places where it is called to free incomplete
type pointers, which is likely a sign of badly designed code (there should
rather be an API to destroy and free these data then, if the data type is not fully
publicly exposed). For now, these are 'worked around' by explicitly casting the
freed pointers to `void *` in these cases - which also makes them easy to search for.
Some of these will be addressed separately (see blender/blender!134765).

Finally, MSVC seems to consider structs defining new/delete operators (e.g. by
using the `MEM_CXX_CLASS_ALLOC_FUNCS` macro) as non-trivial. This does not
seem to follow the definition of type triviality, so for now static type checking in
`MEM_freeN` has been disabled for Windows. We'll likely have to do the same
with type-safe `MEM_[cm]allocN` API being worked on in blender/blender!134771

Based on ideas from Brecht in blender/blender!134452

Pull Request: https://projects.blender.org/blender/blender/pulls/134463
2025-02-20 10:37:10 +01:00
Hans Goudey
2555f68267 Merge branch 'blender-v4.4-release' 2025-02-18 10:55:49 -05:00
Brecht Van Lommel
c0f0e2ca6f Fix #129596: Cycles oneAPI crash with interactive BVH updates
There is a bug in Embree that makes BVH updates crash. Disabling multithreaded
BVH updates after the initial BVH build appears to work around it, at the cost
of some performance.

This will not affect performance of the initial BVH build, transforming objects
or editing a single mesh. It will only affect performance when multiple smaller
meshes are edited together, as those can no longer have their BVH updated in
parallel or benefit from parallellization over many primitives.

Pull Request: https://projects.blender.org/blender/blender/pulls/134747
2025-02-18 16:20:59 +01:00
Sergey Sharybin
0a59c7f0ea Cycles: Rudimentary utilities to plot light tree
Plotting happens from the given root node into a graphviz file.
Supports plotting from both scene level LightTreeNode and the kernel
level KernelLightTreeNode.

An external graphviz command is to be used to convert generated file
to an image.

Pull Request: https://projects.blender.org/blender/blender/pulls/134738
2025-02-18 14:29:00 +01:00
Sergey Sharybin
55e45123f5 Merge branch 'blender-v4.4-release' 2025-02-18 13:12:04 +01:00
Sergey Sharybin
24fbd71a56 Fix #130829: Incorrect render result with light trees
The original report stumbled upon this issue with a more tricky
configuration when light linking is combined with light tress.
However, the actual contributing factor was a mesh with emission
shader which is not assigned to any triangles. This triggered a
bug in the BoundBox::transformed() which converted non-valid bounds
to bounds by performing per-corner growing.

Additionally fix incorrect handling of shared nodes which only
worked for leaf nodes. This was due to the fact how the measure
was accumulated: it is possible that add() is called with an empty
measure.

Pull Request: https://projects.blender.org/blender/blender/pulls/134699
2025-02-18 13:11:46 +01:00
Julian Eisel
152c6c54e4 Cleanup: Improve API comment for MEM_new()
194e233d86 caused a discussion in the chat about the initialization
behavior of `MEM_new()`, and agreement was to not rely on
zero-initialization ever. Noted this in the API comment now.

Some people found the existing comment useful but it still left some
questions. Tried to clarify that now.

This is a crucial memory management function, it's important to have
behavior documented well, even if a full explanation is out-of-scope.
Also added another link in case people want to check more details.

Pull Request: https://projects.blender.org/blender/blender/pulls/134577
2025-02-17 16:18:04 +01:00
Jonas Holzman
3c4a4282ea Merge branch 'blender-v4.4-release' 2025-02-16 23:41:30 +01:00
kgalik
c3d92f32dc NDOF: Rework input handling on macOS
This patch modifies the logic behind handling NDOF device events on
macOS so that it can benefit from the `Blender` profile available in
3DConnexion driver v10.8.7 and later.

A new device command was introduced: `kConnexionCmdAppEvent`, which is
sent by the driver upong getting an apprioriate NDOF device button
input. This allow the driver to consumes all NDOF device input and then
send appropriate app events based on its configuration instead of
forwarding raw data to the application directly.

When using 3DConnexion driver versions prior to v10.8.7, the behavior
is unchanged. This approach allows for supporting all of the SpaceMouse
Enterprise buttons, long presses included (solving issue #119206 on macOS)

Co-authored-by: Sergey Sharybin <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/126694
2025-02-16 23:39:24 +01:00
Lukas Stockner
a6a183ab4d Merge branch 'blender-v4.4-release' 2025-02-15 19:56:23 +01:00
Lukas Stockner
0177537c9a Fix #129279: Cycles: Matrix-typed attributes not working in OptiX OSL
The issue here is that the individual components of TypeDesc are 8-bit each,
but the code was applying a 4-bit mask. It just so happens that the only
case where this matters is TypeDesc::MATRIX44, since its value is 16.
2025-02-15 19:31:07 +01:00
Alaska
870f92c6f9 Merge branch 'blender-v4.4-release' 2025-02-15 13:25:13 +13:00
Alaska
bcec81c4be Fix: Overflow when using light falloff node on distant lights
In Cycles lights can be given a light falloff node to control their
light falloff.

This worked by multiplying the light's strength by different
combinations of the ray length, which would be FLT_MAX for
distant lights. This resulting in almost every configuration of the
light falloff node overflowing when used on distant lights, which is
undesirable.

This commit fixes this issue by ignoring most of the functions of the
light falloff node when used on a distant light.

And in the process fixes a small discrepancy between SVM and OSL when
using the light falloff node on distant lights.

Pull Request: https://projects.blender.org/blender/blender/pulls/134539
2025-02-15 01:23:12 +01:00
Xavier Hallade
f4092993dc Merge branch 'blender-v4.4-release' 2025-02-14 17:38:35 +01:00
Xavier Hallade
a5601f68db Fix: Restore Cycles oneAPI host memory fallback on Linux
free_memory queries were disabled due to runtime driver issues on Linux
when using jemalloc.
compute-runtime introduced a fix for these issues with
8527779778
which is part of versions 31740 and higher, and matches the currently
required min-driver version, so we can restore this feature.

Pull Request: https://projects.blender.org/blender/blender/pulls/134542
2025-02-14 17:37:27 +01:00
Alaska
212d22e039 Merge branch 'blender-v4.4-release' 2025-02-14 17:10:41 +13:00
Alaska
fee2f10208 Fix: Incorrect ray depth on emission in Cycles OSL
This commit fixes a issue where ray depth for emissive objects
(E.g. Lights) was incorrect when using the ray depth output of the
light path node in Cycles OSL.

Pull Request: https://projects.blender.org/blender/blender/pulls/134496
2025-02-14 05:09:08 +01:00
Brecht Van Lommel
b487bcd2bd Merge branch 'blender-v4.4-release' 2025-02-13 19:59:25 +01:00
Brecht Van Lommel
c87a269021 Fix #133953: Cycles oneAPI texture randomly renders black
* Do oneAPI copy optimization as part of host memory alloc and free, so
  it is properly released before host memory is freed.
* Synchronize after loading texture info, like CUDA and HIP.

https://projects.blender.org/blender/blender/pulls/134412
2025-02-13 19:58:56 +01:00
Brecht Van Lommel
f99f958c47 Refactor: Cycles: Add host_alloc/free to device API
This may be used for device to do host memory allocation in a way that
is more efficient for copy the host memory to the device.

Also rename and group device memory allocation functions for clarity.

Pull Request: https://projects.blender.org/blender/blender/pulls/134412
2025-02-13 19:58:56 +01:00
Brecht Van Lommel
4786fbe774 Refactor: Remove extern "C" from most headers
The only remaining code in source/blender that must be compiled as C
is now datatoc generated code and the DNA defaults that use designated
initializers.

Pull Request: https://projects.blender.org/blender/blender/pulls/134469
2025-02-13 18:58:08 +01:00
Sergey Sharybin
2050eca8bb Merge branch 'blender-v4.4-release' 2025-02-13 18:43:51 +01:00
Sergey Sharybin
ee8b9a3799 Fix: Adding new objects in HIP-RT rendered viewport errors out
The issue was caused by c0ba800f64.

Simple solution for now: check the data size and free the memory to
allow the device memory to be re-allocated. Seems the safest for the
upcoming release.

Ideally we'd need to avoid having these manual tricks with the device
memory pointers.

Pull Request: https://projects.blender.org/blender/blender/pulls/134516
2025-02-13 18:42:05 +01:00
Campbell Barton
61b2bf4953 Merge branch 'blender-v4.4-release' 2025-02-13 11:23:45 +11:00
Campbell Barton
c83c62439e Cleanup: correct typo 2025-02-13 11:14:50 +11:00
Brecht Van Lommel
68a510fe9b Merge branch 'blender-v4.4-release' 2025-02-12 21:50:28 +01:00
Nikita Sirgienko
2bab4ae370 Cycles: oneAPI: Optimize texture access by using GPU HW sampler
The current usage of software-based texture operations in
the oneAPI implementation puts additional register pressure on
the GPU compiler during register allocation. And it also creates
code that requires maintenance. This commit is intended to address
this situation by utilizing a recently productized SYCL bindless
texture API to enable HW-based texture operations using
Intel GPUs' hardware sampler.

This currently translates to 1-11% rendering speedups (scene-specific)
on my Arc A770 and Arc B580. At the moment, there are small
performance regressions with NanoVDB texture operations on Arc B580
and small performance regressions in shade surface MNEE and Raytrace
kernels on Arc A770, but they look recoverable and will be handled
in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/133457
2025-02-12 21:47:34 +01:00
Nikita Sirgienko
a0b7ad436b Cleanup: Cycles: oneAPI: Switch to non-experimental work item API
There is now a non-experimental API for this_work_item functionality, so
let's use it for better code quality and also to avoid the deprecation
warning during compilation.

No functional or performance changes are expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/133472
2025-02-12 21:46:22 +01:00
Xavier Hallade
89f70855e0 Cycles: oneAPI: Enable kernels compression
This is done using zstd with compression level 19 so it's aligned with
the other backends that had it enabled in
4bde68cdd6.

Pull Request: https://projects.blender.org/blender/blender/pulls/134049
2025-02-12 21:45:16 +01:00
Brecht Van Lommel
416d2c6115 Merge branch 'blender-v4.4-release' 2025-02-12 17:26:38 +01:00
Brecht Van Lommel
44e9e3bfb2 Fix: Build error with latest MSVC 2022 2025-02-12 17:18:55 +01:00
Bastien Montagne
e6f495bf97 Cleanup: OCIO intern wrapper: Use MEM_new.
Existing code was essentailly doing same thing as `MEM_new`, can as well
use that one directly.
2025-02-12 15:01:19 +01:00
Sean Kim
a2b75c87c8 Merge branch 'blender-v4.4-release' 2025-02-11 14:10:10 -08:00
Sergey Sharybin
a535a1a027 Fix #132782: MetalRT: Missing Geometry in Cycles preview on MacOS 15.2
The issue also happens on macOS 15.3.

This is a Metal driver bug, a fix is coming in macOS 15.4. Until then
disable refitting the viewport. There is no perceptible benefit from
refitting, so while it might be less that ideal it allows to side step
the problem and still benefit from the HWRT.

Pull Request: https://projects.blender.org/blender/blender/pulls/134399
2025-02-11 21:42:38 +01:00
Brecht Van Lommel
2c34786474 Merge branch 'blender-v4.4-release' 2025-02-11 20:43:17 +01:00
Brecht Van Lommel
529ce46744 Fix: Cycles silently ignores unknown --cycles--device type
Pull Request: https://projects.blender.org/blender/blender/pulls/134354
2025-02-11 20:42:21 +01:00
Brecht Van Lommel
9ad19396f5 Fix: Cycles Metal invalid storage mode check
Pull Request: https://projects.blender.org/blender/blender/pulls/134337
2025-02-11 20:42:01 +01:00
Brecht Van Lommel
21a90f26b6 Cleanup: Fix C++20 deprecation warnings in Cycles
Pull Request: https://projects.blender.org/blender/blender/pulls/134338
2025-02-11 16:42:03 +01:00
Brecht Van Lommel
ff6ec94226 Merge branch 'blender-v4.4-release' 2025-02-10 19:56:17 +01:00
Brecht Van Lommel
f63c192543 Fix: Cycles OptiX with OSL 1.14 failure in some render tests 2025-02-10 19:34:24 +01:00
Brecht Van Lommel
2f44765bc8 Merge branch 'blender-v4.4-release' 2025-02-10 16:52:04 +01:00
Brecht Van Lommel
d9ea0e0a29 Fix: Cycles oneAPI kernel not rebuilding when the compiler is updated
This is not a complete solution because there may be indirect changes
to the compiler other than the binary that require a rebuild, but this
should catch the simple cases at least.
2025-02-10 16:41:10 +01:00
Weizhen Huang
b76fbb285e Cycles: Change the integration measure in Huang Hair from gamma to h
To align better with the pixel and reduce the samples needed.

The paper was using gamma because the jacobian |d_gamma/d_h| approaches
infinity at the boundaries, but it seems that clamping at 0.999 is
enough for numerical stability.

In practice I did not notice a change in the noise level, but it
simplifies the range computation and renders faster due to reduced
sample amount.

Co-authored-by: Olivier Maury <omaury@meta.com>

Ref: !129616

Pull Request: https://projects.blender.org/blender/blender/pulls/134130
2025-02-10 14:58:26 +01:00
Sergey Sharybin
4e9f85b76f Merge branch 'blender-v4.4-release' 2025-02-10 14:55:57 +01:00
Patrick Mours
5810c94f95 Cycles: Add Blackwell to Cycles CUDA binaries architectures
Enables building of a Cubin for GPUs based on Blackwell architecture
if CUDA toolkit version 12.8 or higher is installed.
Only added sm_120 to the default set, since it is the one relevant for
consumer GPUs (RTX 5090 etc.) that are generally used with Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/134170
2025-02-10 14:55:28 +01:00
Campbell Barton
e659e87a67 Cleanup: cmake formatting, sort file lists 2025-02-10 19:40:06 +11:00
Alaska
a32b8b546d Merge branch 'blender-v4.4-release' 2025-02-08 01:25:00 +13:00
Alaska
3791001b1c Fix: Object info random on lights do not work in Cycles OSL
This commit adds the `light:random` attribute to OSL, allowing the
object info node to now match between SVM and OSL when using the
random output on a light.

Pull Request: https://projects.blender.org/blender/blender/pulls/134095
2025-02-07 13:23:51 +01:00
Hans Goudey
54dc692d7b Refactor: Use StringRef for attribute API and BMesh CustomData functions
Replace `const char *` with `StringRef` for the API in `BKE_attribute.h`.
The benefits are slightly simpler code and possibly slightly improved
performance through avoiding the need to measure string length.

Pull Request: https://projects.blender.org/blender/blender/pulls/134183
2025-02-06 21:38:19 +01:00
weizhen
19fa8e5e77 Merge branch 'blender-v4.4-release' 2025-02-06 18:44:04 +01:00