Commit Graph

15177 Commits

Author SHA1 Message Date
Campbell Barton
ce7561982a Cleanup: use conventional license formatting
Quiet "make check_licenses" warning.
2025-07-10 00:38:11 +00:00
Campbell Barton
16e06a29f0 Cleanup: typo, spelling 2025-07-10 00:38:09 +00:00
Lukas Stockner
eaa5f63ba2 Cycles: Replace thin-film basis function approximation with accurate LUTs
Previously, we used precomputed Gaussian fits to the XYZ CMFs, performed
the spectral integration in that space, and then converted the result
to the RGB working space.

That worked because we're only supporting dielectric base layers for
the thin film code, so the inputs to the spectral integration
(reflectivity and phase) are both constant w.r.t. wavelength.

However, this will no longer work for conductive base layers.
We could handle reflectivity by converting to XYZ, but that won't work
for phase since its effect on the output is nonlinear.

Therefore, it's time to do this properly by performing the spectral
integration directly in the RGB primaries. To do this, we need to:
- Compute the RGB CMFs from the XYZ CMFs and XYZ-to-RGB matrix
- Resample the RGB CMFs to be parametrized by frequency instead of wavelength
- Compute the FFT of the CMFs
- Store it as a LUT to be used by the kernel code

However, there's two optimizations we can make:
- Both the resampling and the FFT are linear operations, as is the
  XYZ-to-RGB conversion. Therefore, we can resample and Fourier-transform
  the XYZ CMFs once, store the result in a precomputed table, and then just
  multiply the entries by the XYZ-to-RGB matrix at runtime.
  - I've included the Python script used to compute the table under
    `intern/cycles/doc/precompute`.
- The reference implementation by the paper authors [1] simply stores the
  real and imaginary parts in the LUT, and then computes
  `cos(shift)*real + sin(shift)*imag`. However, the real and imaginary parts
  are oscillating, so the LUT with linear interpolation is not particularly
  good at representing them. Instead, we can convert the table to
  Magnitude/Phase representation, which is much smoother, and do
  `mag * cos(phase - shift)` in the kernel.
  - Phase needs to be unwrapped to handle the interpolation decently,
    but that's easy.
  - This requires an extra trig operation in the kernel in the dielectric case,
    but for the conductive case we'll actually save three.

Rendered output is mostly the same, just slightly different because we're
no longer using the Gaussian approximation.

[1] "A Practical Extension to Microfacet Theory for the Modeling of
    Varying Iridescence" by Laurent Belcour and Pascal Barla,
    https://belcour.github.io/blog/research/publication/2017/05/01/brdf-thin-film.html

Pull Request: https://projects.blender.org/blender/blender/pulls/140944
2025-07-09 22:10:28 +02:00
Lukas Stockner
cf92af3ac4 Cycles: Support Thin Film iridescence in the Glass BSDF
Supporting this on the Metallic BSDF will require some extra work,
and on the Glossy BSDF it doesn't make much sense conceptually
(for that kind of shader setup, we'll want to support layering in SVM),
but Glass BSDF just needs to be hooked up so might as well do that.

Pull Request: https://projects.blender.org/blender/blender/pulls/140832
2025-07-09 22:07:24 +02:00
Hans Goudey
e573d9dd24 Revert "Wayland: Set surface color management"
This reverts commit 965b4dce6d.

This commit caused #141688.
2025-07-09 15:11:58 -04:00
Brecht Van Lommel
13ab5067ce Cycles: Detect volume attribute nodes that can use stochastic sampling
Detect which volume attributes nodes have a linear mapping to their usage
as density / color / temperature in volume shader nodes, and use stochastic
sampling for them.

Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 21:04:38 +02:00
Brecht Van Lommel
646dc7fe4d Cycles: Use stochastic sampling to speed up tricubic volume filter
Stochastically turn a tricubic filter into a trilinear one. This
reduces the number of taps from 64 to 8. It combines ideas from
the "Stochastic Texture Filtering" paper and our previous GPU
sampling of 3D textures.

This is currently only used in a few places where we know stochastic
interpolation is valid or close enough in practice.
* Principled volume density, color and temperature
* Motion blur velocity

On an Macbook Pro M3 with the openvdb_smoke.blend regression test
and cubic sampling, this gives a ~2x speedup for CPU and ~4x speedup
for GPU. However it also increases noise, usually only a little. Equal
time renders for this scene show a clear reduction in noise for both
CPU and GPU.

Note we can probably get a bigger speedup with acceptable noise trade-off
using full stochastic sampling, but will investigate that separately.

Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 21:04:38 +02:00
Brecht Van Lommel
4c25b49875 Refactor: Cycles: Deduplicate 3D texture sampling between devices
Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 21:04:38 +02:00
Brecht Van Lommel
b6c4233b28 Refactor: Cycles: Remove now unused 3D image texture support
Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 21:04:38 +02:00
Brecht Van Lommel
7978799e6f Cycles: Always render volume as NanoVDB
All GPU backends now support NanoVDB, using our own kernel side code
that is easily portable. This simplifies kernel and device code.

Volume bounds are now built from the NanoVDB grid instead of OpenVDB,
to avoid having to keep around the OpenVDB grid after loading.

While this reduces memory usage, it does have a performance impact,
particularly for the Cubic filter. That will be addressed by
another commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 21:04:38 +02:00
Brecht Van Lommel
8cf031ba95 Fix: Wrong Cycles NanoVDB memory alignment on Windows
This was not a problem in practice so far, but will be with upcoming changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 20:59:27 +02:00
Brecht Van Lommel
8111152c67 Refactor: Cycles: Add some OpenVDB and NanoVDB functions to util
OpenVDB to NanoVDB was moved, a new NanoVDB to OpenVDB mask grid was
added for future use. Some redundant CMake code was simplified.

Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 20:59:27 +02:00
Brecht Van Lommel
bc507861f2 Logging: Some tweaks to capitalization and log levels
For NDOF, Vulkan context, operators and events.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:27 +02:00
Brecht Van Lommel
d7cc940825 Logging: Log GHOST backend, GPU backend and GPU device
Important information that could not be found directly in the logs yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:27 +02:00
Brecht Van Lommel
4653b65f7c Logging: Add DEBUG, TRACE severity, replace numeric levels
The numeric levels have no obvious meaning. This removes the distinction
between severity and levels, instead there is a single list of named levels
with defined meaning.

Debug means information that's mainly useful for developers, and trace is for
very verbose code execution tracing.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:26 +02:00
Brecht Van Lommel
15d5f957ac Logging: Use CLOG for render progress
* Add render category, which is automatically enabled when using -f or -a
  command line flags for background rendering.
* Add extra logs to mention scene, view layer and frame ahead of time rather
  than including it in every line.
* Remaining time was removed from Cycles, this will be added back for animations
  at the render pipeline level.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:26 +02:00
Brecht Van Lommel
edf2449e67 Logging: Various changes to CLOG
* Change order and formatting of messages
* Change WARN to WARNING, don't print INFO
* Change filter matching "foo" can be used instead of "foo.*"
* Write timestamp as hh::mm::ss.rrr
* Add memory usage writing
* Add macro to print certain INFO logs without checking level
* Indent multi-line log messages with first line
* Add mutex to avoid garbling multi-line logs
* Enable logging by either setting level or filter

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:25 +02:00
Brecht Van Lommel
cf36acbc0c Refactor: Cycles: Replace remaining fprintf with logging
Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:25 +02:00
Brecht Van Lommel
b9d7bab6e6 Refactor: Cycles: Add comments to explain the logging API
Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:25 +02:00
Brecht Van Lommel
fb4e3c8167 Refactor: Cycles: Remove distinction between severity and verbosity
Only use LOG() and LOG_IS_ON() macros, no more VLOG_.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:24 +02:00
Brecht Van Lommel
8392ca915b Cycles: Remove glog dependency, redirect logs to CLOG
* Add own simple logging system to replace glog, which is no longer
  maintained by Google.
* When building in Blender, integrate with CLOG and print all messages
  through that system instead.
* --log cycles now replaces --debug-cycles. The latter still works but
  is no longer documented.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:24 +02:00
Brecht Van Lommel
370ef854c0 Refactor: Cycles: Avoid unnecessary newlines in Metal logs
Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:24 +02:00
Brecht Van Lommel
cf7f276d49 Refactor: Cycles: Tweak logging to prepare for dropping glog
* Implement own simple ScopedMockLog
* Always use names instead of numbers
* Avoid logging in header files

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:24 +02:00
Brecht Van Lommel
9a3a090dbc Refactor: Clog: Port to C++
This is the last remaining C file that uses MEM_guardedalloc.h.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:23 +02:00
Brecht Van Lommel
50a9472604 Fix: Cycles Metal issue rendering with multiple NanoVDB grids
After recent changes in b4be954856, pointer was written at the wrong offset.
2025-07-09 20:59:23 +02:00
Jeroen Bakker
965b4dce6d Wayland: Set surface color management
This PR solves running Wayland on compositors that don't support HDR/
color management. It also allows to let Blender window be drawn across
monitor boundaries and being transferred and clamped to the monitor
it is being displayed on.

From our point of view monitor configurations is a compositor/OS
responsibility. This PR provides the compositor that the provided
swapchain image will be using sRGB whitepoints and transfer
function. The compositor should then take care of performing the
final transfer to the monitor color volume.

The color management protocol doesn't provide guarantees that
every compositor does this. It is mentioned as a recommendation
and 'should do this'.

Pull Request: https://projects.blender.org/blender/blender/pulls/141598
2025-07-09 10:50:20 +02:00
Jeroen Bakker
3fca75d0d7 Vulkan: Only select HDR swapchain on Wayland
Half float swapchains were selected even on platforms that are not able
to use HDR. This PR will limit the creation of HDR swapchains only to
Wayland.

Pull Request: https://projects.blender.org/blender/blender/pulls/141650
2025-07-09 09:00:34 +02:00
Campbell Barton
f528e3d61c GHOST/Wayland: support "resize" cursors from the shape protocol
Also add comments for the different crosshair cursors.
2025-07-09 13:54:47 +10:00
Michael Jones
b4be954856 Cycles: Simplify Metal backend with direct bindless resource encoding
This PR is a more extensive follow on from #123551 (removal of AMD and Intel GPU support).

All supported Apple GPUs have Metal 3 and tier 2 argument buffer support. The invariant resource properties `gpuAddress` and `gpuResourceID` can be written directly into GPU structs once at setup time rather than once per dispatch. More background info can be found in [this article](https://developer.apple.com/documentation/metal/improving-cpu-performance-by-using-argument-buffers?language=objc).

Code changes:
- All code relating to `MTLArgumentEncoder` is removed
- `KernelParamsMetal` updates are directly written into `id<MTLBuffer> launch_params_buffer` which is used for the "static" dispatch arguments
- Dynamic dispatch arguments are small enough to be encoded using the `MTLComputeCommandEncoder.setBytes` function, eliminating the need for cycling temporary arg buffers

Pull Request: https://projects.blender.org/blender/blender/pulls/140671
2025-07-08 23:20:16 +02:00
Brecht Van Lommel
63cfc32dea Merge branch 'blender-v4.5-release' 2025-07-08 14:56:00 +02:00
Brecht Van Lommel
ba5cf35d2a Fix #141381: Cycles unnecessary re-subdivision with persistent data
Pull Request: https://projects.blender.org/blender/blender/pulls/141605
2025-07-08 14:55:30 +02:00
Campbell Barton
7b98f19afb Merge branch 'blender-v4.5-release' 2025-07-08 20:35:16 +10:00
Lukas Stockner
71cdb55953 Fix #140562: Cycles crash with texture in custom camera with SVM on GPU
After spending way too much time looking into the image handle code
because I assumed the issue is some interaction between OSL code using
a texture and the image system that's in SVM mode (which never happened
before the custom camera) with printf debuggine because OptiX doesn't
work in debug builds, it turns out the issue was something else entirely:
C++ iterator bullshit.

Specifically, when we remove an entry from services->textures, this
invalidates the iterator, so the code restarts from the beginning.
However, the for-loop still increments the iterator *before* checking
the termination criterion.
If we remove the only element of the map, we:
- Set it = map.begin(), which equals map.end() since it's empty now
- Increment it at the end of the loop iteration
- Compare it == map.end(), which is wrong now since we're past the end

No idea how this didn't blow up sooner, none of this seems camera-specific??
Anyways, the fix is simple - only increment if we didn't restart.

Pull Request: https://projects.blender.org/blender/blender/pulls/141580
2025-07-08 11:51:22 +02:00
Campbell Barton
542503ddf2 Cleanup: format 2025-07-08 18:01:57 +10:00
Campbell Barton
c0e9edd70c Refactor: minor changes to prepare for Hi-DPI custom cursors on Wayland 2025-07-08 17:22:26 +10:00
Campbell Barton
439253eab5 Cleanup: use consistent terms in capability flags
Consistently use terms "cursor" & "clipboard" as a prefix
so they auto-complete more usefully.

Previously both ordering was used.
2025-07-08 16:35:42 +10:00
Campbell Barton
3ae7ba1255 GHOST/Wayland: use wl_surface_damage_buffer when available
Also damage the entire buffer, there is no reason to clamp this
to the buffer bounds.
2025-07-08 16:35:42 +10:00
Campbell Barton
f2b01dbcb8 Cleanup: order capability flags as defined
When setting GHOST capability flags, use the order they are defined
to make the code easier to follow when manually updating.
2025-07-08 11:04:39 +10:00
Lukas Stockner
bfcfe730ed Cleanup: Cycles: Move F82 Fresnel model into helper function 2025-07-08 01:23:33 +02:00
Campbell Barton
0ec2878cb6 Fix crash freeing cursors in Wayland
Regression in [0] missed clearing the mask when setting RGBA cursors.

[0]: 7b02b813f8
2025-07-08 08:09:04 +10:00
Harley Acheson
4fe0e788a9 Merge of blender-v4.5-release 2025-07-07 10:17:56 -07:00
Pratik Hadawale ~ sake :)
f090572ca8 Fix #141158: Fullscreen startup file causes white flicker with Vulkan backend
When launching Blender via blender-launcher.exe, the window briefly
displays incorrectly on startup when using the Vulkan backend. This is
caused by not properly handling the GHOST_kWindowStateFullScreen case.

Previously, even if the window state was set to fullscreen, nCmdShow
would default to SW_SHOWNORMAL or SW_SHOWNOACTIVATE. With this fix,
nCmdShow is explicitly set to SW_SHOWMAXIMIZED when the window is in
fullscreen state, preventing the flicker.

Pull Request: https://projects.blender.org/blender/blender/pulls/141518
2025-07-07 19:12:59 +02:00
Alaska
a6f92974ac Cycles: Allow Metal to print GPU Queue stats
When running Blender with `--debug-cycles` and the right
verbosity level, Cycles can output "GPU Queue Stats" to the terminal
at the end of rendering detailing how much time was spent in each kernel.

The Metal GPU backend did not support this specific way of gathering the
information. This commit fixes that by implementing support to the Metal
GPU backend.

Note: This kind of information could already be gathered for the Metal
GPU backend using the `CYCLES_METAL_PROFILING` environment variable,
and this is still the recommended way of gathering that information for
Metal. This change is just to add some consistency between platforms.

Pull Request: https://projects.blender.org/blender/blender/pulls/137592
2025-07-07 16:16:37 +02:00
Jeroen Bakker
b617c6d825 Merge branch 'blender-v4.5-release' 2025-07-07 11:20:46 +02:00
Jeroen Bakker
f40e6e8a60 Fix: Vulkan: Use feature struct
Detected an incorrect structure type. A property struct was used to
store feature data. This could lead to incorrect values for enabling
descriptorBufferPushDescriptor, what isn't used.
2025-07-07 11:14:09 +02:00
Campbell Barton
97612fd8ef Cleanup: add missing license header
Add license header, removed in !139923.
2025-07-05 08:50:25 +10:00
Harley Acheson
7580da6bd2 UI: Removal of Win32 Platform-Specific Cursor Files
We are now able to make antialiased mouse cursors at any size directly
from SVG sources. Therefore there is no need for the platform-specific
"cur" versions of these cursors. This removes the work required in
duplicating the cursors in this format. Otherwise the results should be
identical.

Pull Request: https://projects.blender.org/blender/blender/pulls/141309
2025-07-05 00:39:50 +02:00
Campbell Barton
c2c8f54a52 Merge branch 'blender-v4.5-release' 2025-07-04 09:19:25 +10:00
Jorn Visser
94f4df8ec4 Fix #141339: Mantaflow: Clear Python errors when grids aren't available
Adding a Flow to a Mantaflow domain could sometimes cause a crash. This
was because the grids are allocated lazily, and as such, getting them
through `PyObject_GetAttrString` will fail when they are not yet
available. As the resulting Python errors were not cleared, Python could
be left in a bad state, leading to crashes. This is avoided by clearing
these errors before returning from `callPythonFunction` when such an
error is raised.

Ref !141364
2025-07-03 23:17:25 +00:00
Jonas Holzman
95abfc00a5 Merge branch 'blender-v4.5-release' 2025-07-03 00:07:52 +02:00