15493 Commits

Author SHA1 Message Date
Brecht Van Lommel
5afe338287 GHOST: Rename GHOST_VSYNC to BLENDER_VSYNC, change description
* GHOST is an implementation detail, Blender environment variables should
  have the BLENDER_ prefix.
* Don't put links in command line help output. We don't do this for other
  arguments either, and it's trivial to search for this online.
* Make description more straightforward and line wrap.
* Use CLOG for logging.

Ref #143049

Pull Request: https://projects.blender.org/blender/blender/pulls/144349
2025-08-11 19:03:58 +02:00
Brecht Van Lommel
f6c628e247 Refactor: Cycles: Compute shader usage of volumes earlier
This will be needed for volume null scattering.

Pull Request: https://projects.blender.org/blender/blender/pulls/144370
2025-08-11 18:57:51 +02:00
Bastien Montagne
307d0de26e Allocator: Add MEM_new_for_free to allow construction of almost-trivial types.
The data constructed by this call remains in the 'C-alloc' realm, i.e.
it can be `MEM_dupallocN`'ed, and `MEM_freeN`'ed.

This is intended as a temporary API only, to facilitate transition to
full C++ handling of data in Blender. It's primary target is to allow
pseudo-POD types to use default values for their members. See e.g.
!134531.

Unlike !143827 and !138829, it does not change the current rule (`new`
must be paired with `delete`, and `alloc` must be paired with `free`).

Instead, it defines an explicit and temporary API to allow a very
limited form of construction to happen on C-allocated data, provided
that the type is default-constructible, and remains trivial after
construction.

### Notes
* The new API is purposely as restrictive as possible, trying to
  only allow the current known needs (init with default member values).
  This can easily be extended if needed.
* To try to stay as close as malloc/calloc behavior as possible, and
  avoid the 'zero-initialization' gotcha, it does not use
  value-initialization, but instead default-initialization on zero-
  initialized memory.
  _Ideally it would even not allow any user-defined default constructor,
  but this does not seem simple to detect._

Pull Request: https://projects.blender.org/blender/blender/pulls/144141
2025-08-11 14:56:11 +02:00
Clément Foucault
856a2a9f87 Fix: GHOST: Build error
Caused by aafef977fb
2025-08-11 12:39:37 +02:00
Christoph Neuhauser
aafef977fb GHOST: Add environment variable for enabling or disabling vsync
This PR proposes to add an environment variable for forcing vsync to
be on or off. My primary use case was to disable vsync for forcing
viewport rendering performance tests not to be capped at the display
refresh rate when #142984 is used for removing animation frame rate
limits.

I initially added the environment variable "GHOST_VSYNC_OFF", but
found "GHOST_VSYNC=0/1" to be more easily understandable.

Usage:
- GHOST_VSYNC=0 => Vsync is forced off
- GHOST_VSYNC=1 => Vsync is forced on

Pull Request: https://projects.blender.org/blender/blender/pulls/143049
2025-08-11 12:09:21 +02:00
Brecht Van Lommel
2193096106 Cycles: Change normal map node to work with undisplaced normal and tangent
This fits better with the way normal and displacement maps are typically
combined. Previously there was a mixing of displaced normal and undisplaced
tangent, which was broken behavior.

Additionally, to undisplaced_N and undisplaced_tangent attributes must now
always be used to get undisplaced coordinates. The regular N and tangent
attributes now always include displacement.

Ref #142022

Pull Request: https://projects.blender.org/blender/blender/pulls/143109
2025-08-11 12:08:12 +02:00
Brecht Van Lommel
809260885e Fix #143841: Cycles OptiX error adding AO shader with viewport render
Modify shader update so we simplify the graphs first to determine the
kernel features, then load the kernels, and only then update data on the
device. This avoids errors due to mismatched kernels and shaders.

Pull Request: https://projects.blender.org/blender/blender/pulls/144238
2025-08-11 12:05:16 +02:00
Clément Foucault
7a97105b28 GPU: Remove wrapper type for gpu::StorageBuf
This is the first step into merging DRW_gpu_wrapper.hh into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/144329
2025-08-11 10:35:53 +02:00
Clément Foucault
1388a70914 GPU: Remove wrapper type for gpu::Shader
This is the first step into merging DRW_gpu_wrapper.hh into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/144229
2025-08-11 09:34:28 +02:00
Campbell Barton
cd66e6c1a6 GHOST/Wayland: support server-side key-repeat
Support server side key repeat when building with Wayland >=1.24.
2025-08-10 07:54:54 +00:00
Campbell Barton
7c68d603b6 Cleanup: use braces in case statements 2025-08-10 17:31:46 +10:00
Campbell Barton
0a9720a228 Fix #142871: Two cursors visible when panning over a number button
Resolve regression in [0] where setting the cursor wasn't checking
if a software cursor was used. This would then show the hardware &
software cursors.

[0]: 232b106e64
2025-08-10 16:59:57 +10:00
Campbell Barton
388609e7a7 GHOST/Wayland: minor change to error handling when setting the cursor
Don't early exit in the unlikely event setting the cursor fails,
as this could prevent the tablet cursor from being set.
2025-08-10 16:53:59 +10:00
Jeroen Bakker
073b4d4d7b Fix #144048: Vulkan: Crash minimized windows
Swapchain handling of minimized windows wasn't correct. On some
platforms it still tried to create images with no surface.

This PR will discard swapchains of minimized windows, but still being
able to flush the render graph and free resources.

Pull Request: https://projects.blender.org/blender/blender/pulls/144189
2025-08-08 11:03:02 +02:00
Jeroen Bakker
97f1aeb84c Vulkan: Remove support for render passes
Vulkan 1.0 render passes have been replaced by dynamic rendering in 1.2.
Blender Vulkan backend was implemented with dynamic rendering in mind.
All our supported platforms support dynamic rendering. Render pass support
was added to try to work around an issue with legacy drivers. However these
drivers also fail with render passes.

Using render passes had several limitations (blending and some workbench
features were not supported).  As no GPU uses it and it is quite some code
to support it is better to remove it.

Pull Request: https://projects.blender.org/blender/blender/pulls/144149
2025-08-08 08:08:58 +02:00
Campbell Barton
cccc2c77c5 Cleanup: consistent for C-style comment blocks 2025-08-08 07:37:33 +10:00
Brecht Van Lommel
6dc9cd366a Fix: Cycles volume assert on Windows due to wrong comparator
Introduced in 13ab5067ce.

Pull Request: https://projects.blender.org/blender/blender/pulls/144167
2025-08-07 21:23:28 +02:00
Campbell Barton
77d6960d24 Cleanup: quiet GCC warning for pointer subtraction
Ref !144032
2025-08-06 20:31:14 +00:00
Campbell Barton
e8501d2f54 Cleanup: grammar corrections, minor improvements to wording
Also back-tick quote some code references in comments
to differentiate them from English text.
2025-08-06 00:20:39 +00:00
Michael Jones
50363918c7 Cycles: Stop Metal API validation asserts
Dynamic enqueue arguments weren't padded out to struct alignment causing API validation to assert.

Pull Request: https://projects.blender.org/blender/blender/pulls/143991
2025-08-05 14:45:14 +02:00
Damien Picard
5998795aa6 UI: Replace contractions with long-form text
Avoid using contractions for can't, aren't, doesn't, and shouldn't.
Following the writing style guide in the Human Interface Guidelines.

Pull Request: https://projects.blender.org/blender/blender/pulls/143852
2025-08-05 11:16:22 +02:00
Jeroen Bakker
9d039ef29e Fix #141806: Crash with certain layers enabled
This PR removes the deferred allocation of swapchain images. A lot of layers
don't support this and will crash when used.

Thanks to Jorn Visser to point out the potential issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/143924
2025-08-05 10:11:06 +02:00
Lukas Stockner
793040ad1c Cycles: Improve parameter packing for the Principled BSDF
The Principled BSDF has a ton of inputs, and the previous SVM code just always
allocated stack space for all of them. This results in a ton of additional
NODE_VALUE_x SVM nodes, which slow down execution.

However, this is not really needed for two reasons:
- First, many inputs are only used consitionally. For example, if the
  subsurface weight is zero, none of the other subsurface inputs are used.
- Many of the inputs have a "usual" value that they will have in most
  materials, so if they happen to have that value we can just indicate that
  by not allocating space for them.
  This is a bit similar to the standard "pack the fixed value and provide
  a stack offset if there's a link" pattern, except that the fixed value
  is a constant in the code and we allocate a NODE_VALUE_x if a different
  fixed value is used.

Therefore, this PR re-implements the parameter packing in a more efficient way:
- If we can determine that a component is disabled, all conditional inputs are
  disconnected (to avoid generating upstream nodes).
- If we can determine that a component is disabled, we skip allocating all
  conditional inputs on the stack.
- The inputs for which a reasonable "usual" value exists are changed to
  respect that, and to only be allocated if they differ.
- param1 and param2 (which are fixed-value-packed as on all BSDF nodes) are
  used to store IOR and roughness, which have a decent chance to be fixed
  values.
- The parameter packing is more aggressive about using uchar4, which allows
  to get rid of two SVM nodes while still storing the same inputs.

The result is a considerable speedup in scenes that make heavy use of the
Principled BSDF:

| Scene | CPU speedup | OptiX speedup |
| --- | --- | --- |
| attic | 5% | 9% |
| bistro | 5% | 8% |
| junkshop | 5% | 10% |
| monster | 3% | 4% |
| spring | 1% | 6% |

Pull Request: https://projects.blender.org/blender/blender/pulls/143910
2025-08-04 18:34:58 +02:00
Alaska
83472b19fe Fix: Cycles: Show correct minimum OptiX GPU driver in preferences
Ever since the OptiX 8 update in Blender 4.5, the minimum GPU driver
requirements to use OptiX has increased to 535 or newer.

This commit update the minimum GPU driver requirement listed in the UI
to reflect this.

Pull Request: https://projects.blender.org/blender/blender/pulls/143917
2025-08-04 15:48:43 +02:00
Amogh Shivaram
ff4d840cf8 Cycles: Add polarized Fresnel function for conductors
This PR adds a new `fresnel_conductor_polarized` function, which calculates reflectance and phase shift (if requested) for both parallel and perpendicular polarized light. This is needed for applying thin film iridescence to conductors (see !141131).

For consistency, this PR also makes `fresnel_conductor` call `fresnel_conductor_polarized` instead of using a fast approximation of the Fresnel equations that is inaccurate at lower n and k values. This will change the output of some Metallic BSDF renders using Physical Conductor and prevent discrepancies when enabling thin film iridescence.

I didn't do any rigorous performance testing, but from timing the functions outside of Blender, `fresnel_conductor_polarized` is significantly slower than the approximation, between 1.5-3x depending on the compiler. This makes sense because it has three square roots and the approximation has none. In some informal tests with metallic_multiggx_physical.blend modified to have more spheres, the new renders took around 1-2% longer on both CPU and GPU.

There are some avoidable inefficiencies in this approach of just calling `fresnel_conductor_polarized`:

- one of the three square roots could be saved since `fresnel_conductor` never needs the phase shift and there are simplifications possible when only calculating the reflectance
- there are several unnecessary multiplications by 1.0 since `fresnel_conductor` uses relative IOR and `fresnel_conductor_polarized` doesn't, though those could get optimized out if inlined

Pull Request: https://projects.blender.org/blender/blender/pulls/143903
2025-08-04 15:36:36 +02:00
Lukas Stockner
e266692688 Fix #143907: Cycles: Crash when custom camera shader is not found 2025-08-04 15:34:16 +02:00
Lukas Stockner
3107d1f962 Cycles: Improve parameter packing for BSDFs and emission
This replaces `stack_assign` with `stack_assign_if_linked`, which should save a few SVM nodes for constant parameters.

Running benchmarks (all scenes in the benchmark repo, 3 runs, median value for each) shows 1.0% improvement on CPU and 1.5% on OptiX. Not huge, but fairly (all between -0.2% and 3.0%).

Pull Request: https://projects.blender.org/blender/blender/pulls/143404
2025-08-04 15:19:40 +02:00
Campbell Barton
a3bf386d43 Cleanup: use full sentences in text editor code-comments
Also minor improvements, clarifications.
2025-08-02 13:33:05 +10:00
Weizhen Huang
1667d69d3b Cleanup: Cycles: use constexpr in kernel
instead of lambda and macro guard. Should be possible after ce0ae95ed3

Pull Request: https://projects.blender.org/blender/blender/pulls/143723
2025-08-01 14:06:13 +02:00
Campbell Barton
2c27d2be54 Cleanup: grammar corrections, minor improvements to wording 2025-08-01 21:41:24 +10:00
Habib Gahbiche
53380ed8b2 Cleanup: redundant check for shader type
Pull Request: https://projects.blender.org/blender/blender/pulls/143784
2025-08-01 13:38:54 +02:00
Hugh Delaney
930a942dd0 Refactor: Cycles: Move block sizes into common header
This change puts all the block size macros in the same common header, so
they can be included in host side code without needing to also include
the kernels that are defined in the device headers that contained these
values.

This change also removes a magic number used to enqueue a kernel, which
happened to agree with the GPU_PARALLEL_SORT_BLOCK_SIZE macro.

Pull Request: https://projects.blender.org/blender/blender/pulls/143646
2025-08-01 13:26:02 +02:00
Brecht Van Lommel
cedd7edd29 Cleanup: Cycles: Use gtest header instead of Blender test header
To avoid conflicts with glog logging macros, and because there is just no
need to have this dependency.

Pull Request: https://projects.blender.org/blender/blender/pulls/143719
2025-07-31 19:46:54 +02:00
Campbell Barton
941582324c Cleanup: pass const arguments to sort, use C++ radian conversion 2025-07-31 16:18:13 +10:00
Campbell Barton
7c5ba9cb2c Cleanup: pass const arguments in GHOST/Wayland implementation 2025-07-31 03:45:42 +00:00
Felipe Choi
024291987c GHOST/Wayland: add basic touch-screen support
Generate mouse events from touch devices on Wayland.

The code tracks a single contact point and converts it to mouse moves,
LMB presses & releases. Multi-touch, pinch & swipe aren't yet supported.

Addresses #121449.

Ref !143416

Co-authored-by: Campbell Barton <campbell@blender.org>
2025-07-31 03:20:08 +00:00
Weizhen Huang
f8eae6b58a Fix: Cycles: Division by zero in Oren-Nayar shader
`Eavg` can still be 1 for very small roughness, causing division by zero
when computing `Ems`.
A roughness of 1e-5 gives an `Evg` of 0.999998, seems reasonable.

Pull Request: https://projects.blender.org/blender/blender/pulls/143637
2025-07-30 16:57:00 +02:00
Patrick Mours
6487395fa5 Cycles: Add linear curve shape
Add new "Linear 3D Curves" option in the Curves panel in the render
properties. This renders curves as linear segments rather than smooth
curves, for faster render time at the cost of accuracy.

On NVIDIA Blackwell GPUs, this can give a 6x speedup compared to smooth
curves, due to hardware acceleration. On NVIDIA Ada there is still
a 3x speedup, and CPU and other GPU backends will also render this
faster.

A difference with smooth curves is that these have end caps, as this
was simpler to implement and they are usually helpful anyway.

In the future this functionality will also be used to properly support
the CURVE_TYPE_POLY on the new curves object.

Pull Request: https://projects.blender.org/blender/blender/pulls/139735
2025-07-29 17:05:01 +02:00
Stefan Werner
c81e1d95c1 Cycles: Fixed typo in my last commit 2025-07-29 10:53:13 +02:00
Weizhen Huang
a7042ca30c Fix: warning template-id-cdtor on gcc 2025-07-29 10:41:17 +02:00
Stefan Werner
e7312b1ad5 Cycles: Explicitly setting SYCL device for Embree
This fixes issues when using Embree on mutliple GPUs.
A previous workaround used separate contexts, this one now
lets us keep a single context for all GPUs.

Pull Request: https://projects.blender.org/blender/blender/pulls/143089
2025-07-29 10:40:28 +02:00
Brecht Van Lommel
f03ac5ec4b Fix #142876: Cycles crash with OSL and interactive updates
Update use_shading, use_camera and the shading system pointers in the same
location, so that when the render is interrupted they are in a consistent state.

The added null pointer checks are not strictly needed, but just in case it
goes out of sync for another reason.

Pull Request: https://projects.blender.org/blender/blender/pulls/143467
2025-07-28 18:43:57 +02:00
Weizhen Huang
ea45c776fd Cycles: introduce dual types
to replace some uses of dfdx/dfdy/differentials.
No functional change expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/143178
2025-07-28 17:34:24 +02:00
Weizhen Huang
345d23bff8 Cleanup: Cycles: add more float3 util functions
and vectorize `wrap` and `safe_fmod`.
2025-07-28 17:34:21 +02:00
Weizhen Huang
48777385c2 Cleanup: Cycles: simplify computation of dPdx and dPdy
`sd->dPdu`, `sd->dPdv`, `sd->du` and `sd->dv` are computed from
`sd->dP` by constructing a local frame, so both results are the same, subject to some numerical differences.

This avoids constructing the local frame again, so might be faster.
2025-07-28 17:34:21 +02:00
Weizhen Huang
f9a65ebbea Cleanup: Cycles: Deduplication svm bump functions 2025-07-28 17:34:21 +02:00
Sergey Sharybin
07bf1bd87b OpenSubdiv: Switch away from GLSL on Apple
Use MTLPatchShaderSource to provide the patch basis shader source on
all Apple platforms. The immediate advantage of this change is ability
to use GPU subdivision on iOS. Another advantage is that it moves us
further away from frameworks which got deprecated by Apple and it might
save us some headache in the future.

Also tweak backend-specific defines to match definitions from OpenSubdiv.
The annoying difference is that OSD_PATCH_BASIS_METAL is defined by the
OpenSubdiv as 1 in the very beginning of the base code, which is not done
for the OSD_PATCH_BASIS_GLSL is not defined by the OpenSubdiv at all.

Ref #143445

---

TODO:
- [X] Check it works correctly on macOS
- [x] Check it works correctly on Linux

Pull Request: https://projects.blender.org/blender/blender/pulls/143462
2025-07-28 16:54:10 +02:00
Habib Gahbiche
445eceb02a Nodes: Remove "Use Nodes" in Shader Editor for World
Part of https://projects.blender.org/blender/blender/pulls/141278

Blend files compatibility:
If a World exists and "Use Nodes" is disabled, we add new nodes to the
existing node tree (or create one if it doesn't) that emulates the
behavior of a world without a node tree. This ensures backward and
forward compatibility.

Python API compatibility:
- `world.use_nodes` was removed from Python API => **Breaking change**
- `world.color` is still being used by Workbench, so it stays there,
although it has no effect anymore when using Cycles or EEVEE.

Python API changes:
Creating a World using `bpy.data.worlds.new()` now creates a World with
 an empty (embedded) node tree. This was necessary to enable Python
scripts to add nodes without having to create a node tree (which is
currently not possible, because World node trees are embedded).

Pull Request: https://projects.blender.org/blender/blender/pulls/142342
2025-07-28 14:06:08 +02:00
Brecht Van Lommel
fa007002b1 Refactor: Logging: Move G.quiet to CLOG, replace some printfs
* Replace G.quiet by CLG_quiet_set/get
* CLOG_INFO_NOCHECK prints are now suppressed when quiet, these were
  typically inside a if (!G.quiet) conditional already.
* Change some prints for blend files, color management and rendering to
  use CLOG, that were previously using if (!G.quiet) printf().

Pull Request: https://projects.blender.org/blender/blender/pulls/143138
2025-07-28 13:36:13 +02:00
Brecht Van Lommel
fbfa4e3805 Fix #143128: Cycles crash or artifacts with multi device rendering and denoising
Clear graphics interop when mapping the buffer directly, as this might free the
underlying buffer or handle.

Fix #141736: Artifacts on Vulkan GPU + GPU
Fix #143128: Crash on Metal CPU + GPU

Pull Request: https://projects.blender.org/blender/blender/pulls/143243
2025-07-25 21:43:01 +02:00