Commit graph

111 commits

Author SHA1 Message Date
Brecht Van Lommel
1018bbe7e3 Fix: Cycles: OptiX log wrong file path for optional modules
Issue introduced in c487c0a400.

Pull Request: https://projects.blender.org/blender/blender/pulls/164137
2026-09-19 23:14:16 +02:00
Patrick Mours
f97ee31df7 Cleanup: Cycles: Query OptiX hardware ray-tracing state from device
Commit 976ca9d244 fixed the "Hardware
Ray-Tracing" state message being printed to the log always showing off
for OptiX. This improves that further by querying whether the device
actually supports it, since OptiX has a software fallback on devices
without hardware ray tracing support.

Pull Request: https://projects.blender.org/blender/blender/pulls/163807
2026-09-14 15:50:17 +02:00
Sergey Sharybin
f0ec6f183b Cycles: Split shadow modules into own files for OptiX OSL
Both shadow kernels seems to be expensive enough and having them in the
main module leads to very long module creation times.

These new modules are always created (at least for now), but they are
created in parallel with other modules.

Overall it drastically reduces the time it takes to run OptiX OSL tests
for the first time.

Combined with the previous commits this reduces:
- cycles_bake_optix_osl from 1330.44 sec to 177.30 sec
- cycles_attributes_optix_osl from 2809.71 sec to 501.62 sec

Measured on i9-11900K, NVIDIA RTX 6000 Ada.

Pull Request: https://projects.blender.org/blender/blender/pulls/163706
2026-09-10 10:02:12 +02:00
Sergey Sharybin
4487e86741 Cycles: Allow creating different OptiX modules in parallel
There was seemingly a mistake in the code which handled the first
task on the same thread from which module was requested to load.

According to the documentation it is only the optixModuleCreateWithTasks()
that needs to be called outside of threading, and it'll try to
exit as soon as possible, leaving with a task that could be run
on a thread.

This should allow creating main module, MNEE, etc in sepaarte
threads.
2026-09-10 10:02:09 +02:00
Sergey Sharybin
c487c0a400 Cycles: Add logging for OptiX module load time
Enabled with --debug-cycles.

The goal is to provide more tooling for looking into which modules
takes the longest. Comes from the need to investigate OptiX OSL tests
time.
2026-09-10 10:02:09 +02:00
Sergey Sharybin
a70b34065d Refactor: Cycles: Make kernel_features 64bit
This change adds 32 more bit to store kernel features.

While for a short term it might be possible to make a space for one or
two extra bits, it seems going 64bit is inevitable.

Expanding the field to 64bit might introduce some slowdown due to less
optimal cache, but so is consolidation of existing flags could also
lead to performance drop in certain configurations.

The main tricky part of the change is Metal where function constants
are used to store kernel_features, and 64bit constants are only
available on macOS 12. There is a runtime check for it. On older macOS
versions the flags are stored as a pair of 32bit values. It is slower,
but there are unlikely to be many Cycles users on macOS 11.

Ref #159470

Pull Request: https://projects.blender.org/blender/blender/pulls/162737
2026-08-18 10:41:27 +02:00
Brecht Van Lommel
1319a955eb Fix #160256: Cycles OptiX crash with OSL camera and shader raytrace
This particular combination was not computing the stack size correctly,
since shader raytrace was moved to a separate OptiX module. It needs to
be set manually now that it's not part of the same module.

Regression from c51fcf73a7.

Pull Request: https://projects.blender.org/blender/blender/pulls/160318
2026-06-24 14:31:29 +02:00
Brecht Van Lommel
41ba111aee Refactor: Cycles: OptiX hit and miss program group setup utility function
No need to enumerate all the programs, and add utility function for reuse in
the next commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/160318
2026-06-24 14:31:29 +02:00
Brecht Van Lommel
3453c1c571 Fix: Cycles: OptiX optional modules issue with runtime compilation
This case was not properly handled in the recent refactor.

This issue was introduced in c51fcf73a7.

Pull Request: https://projects.blender.org/blender/blender/pulls/159666
2026-06-16 16:24:47 +02:00
Sebastian Parborg
3a0ab5eadc Fix: Cycles compile fails without OSL support
After some refactoring in #159499, disabling OSL now results in compile
errors because the code tries to use "osl_volume_module" that is only
available when OSL support is enabled.

Expand the "WITH_OSL" guard to include this code as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/159649
2026-06-05 18:48:35 +02:00
Brecht Van Lommel
c51fcf73a7 Cycles: Split OptiX kernels into smaller modules to improve load time
This helps especially for OSL, where load time is very long. By
splitting off shader raytrace, MNEE and volumes, the first time
rendering is much faster.

The downside is that noinline functions will be duplicated. However OSL
startup performance is very bad currently and this seems the better
trade-off for now. There are ways to make this work if we do not mark
noinline functions as static, but this will require some bigger code
reorganization.

Without OSL, shader raytrace and MNEE were combined in a single module,
and that has been split into two as well.

Besides a better user experience, This will fix OptiX OSL test timeouts
on the buildbot, where some tests need to compute a few different
specializations and the 600s timeout is exceeded, with the longest test
run time being around 300s.

Pull Request: https://projects.blender.org/blender/blender/pulls/159499
2026-06-04 23:38:05 +02:00
Brecht Van Lommel
fc9917352b Refactor: Cycles: Hair/Point positions include motion, kernel attribute
Motion is now part of the position attribute. On the kernel side, a
combined position + radius attribute is now stored, replacing the
previous motion only attribute.

Legacy motion attributes are now removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:25 +02:00
Brecht Van Lommel
0baa98866c Refactor: Cycles: Mesh positions include motion, store kernel attribute
Motion is now part of the position attribute. On the kernel side, this
position is now stored as an attribute as well, replacing the previous
motion only attribute.

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:25 +02:00
Brecht Van Lommel
e9c36249f7 Refactor: Cycles: Store hair curve key positions and radii as attributes
This will enable implicit sharing with Blender data.

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:24 +02:00
Brecht Van Lommel
00c344e3dc Refactor: Cycles: Add per-step motion infrastructure to Attribute
Replace the single buffer/sharing_info pair on Attribute with a Buffer
struct, with one buffer for the center step and a vector of buffers for
the other motion sub-steps. Each step is its own allocation, so a single
step can be replaced or implicitly shared without disturbing the others.

Add Attribute::add_motion(), remove_motion(), and has_motion() to manage
motion sub-step allocations relative to the owning geometry's
motion_steps, and add data_motion_*() accessors for reading/writing the
sub-step data.

This is preparation for moving motion blur position/normal storage from
separate ATTR_STD_MOTION_* attributes into the corresponding base
attributes. No call sites are updated yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:24 +02:00
Brecht Van Lommel
7933f92f89 Refactor: Cycles: Use packed_float3 for arrays, accessors for geometry data
Use packed_float3 instead of float3 for geometry positions and various
other arrays.

Add and use unified accessor methods get_position() and get_radius() for
all geometry, as well as num_verts(), num_points() and num_keys().

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:24 +02:00
Brecht Van Lommel
5fc85d1cb7 Refactor: Cycles: Move MNEE walk into separate kernel
The new intersect_mnee kernel runs before shade_surface, and
shade_surface_mnee is eliminated. That large kernel was causing problems
for some GPU compilers.

MNEE state is packed into a shadow path state to avoid significantly
increasing the path state size. This shadow state is then either turned
into an actual shadow ray state or discarded in shade_surface.

MNEE was re-enabled on HIP RDNA2 as it works again now. Texture cache
misses now also work correctly with MNEE.

This adds some extra code to the regular shade_surface kernel even when
MNEE is not used, to use the MNEE sampled point instead of sampling a
light. But there seems to be no significant performance impact.

Co-authored-by: Sergey Sharybin <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/158698
2026-05-27 20:34:06 +02:00
Brecht Van Lommel
ab0cb89d89 Cleanup: Cycles: Fix various compiler warnings
* Uninitialized variable warning in oneAPI.
* Use std::copy_n instead of memcpy.
* Use simpler bit packing for normal map convention that avoids
  signed/unsigned warning.
* Unnecessary device keyword for default constructor.
* Unused variables in Principled BSDF due to constexpr.
* Hydra function that should be static.

Pull Request: https://projects.blender.org/blender/blender/pulls/154430
2026-02-16 12:57:53 +01:00
Brecht Van Lommel
4b34743b4e Cycles: Perform direct light shader eval in own kernel
This improves performance by 5-10% for various benchmark scenes and GPU
devices, while on others it's roughly the same. There is a performance
regression with Intel Arc A750 on Linux related to shadow queueing
overhead, that is planned to be fixed separately.

Another goal of this change is to sidestep GPU compiler bugs that seems
more likely to happen with bigger kernels, and to make it easier for the
texture cache to cancel and resume on cache miss.

A new shade_light_nee kernel was added, and shade_light was renamed to
shade_light_forward (following naming for MIS functions). The shade_light_nee
kernel is only used when the light does not have constant emission.

The shade_dedicate_light kernel no longer does any shading. A future
optimization may be to fold this into the intersect_dedicated_light kernel.

LightSample.uv was removed as shading no longer happens immediately. A new
LightPdf was added for the cases where only the pdf is needed, avoiding the
overhead of constructing a full LightSample. There may be more room to
shrink LightSample in future refactors.

The integrate state memory usage is increased by 1 float when not using the
light tree, for the light threshold. All other informating for shading is
reconstructed the shadow ray, including position, normal and uv.

Pull Request: https://projects.blender.org/blender/blender/pulls/152649
2026-01-20 20:34:16 +01:00
Patrick Mours
1c95f837d8 Cycles: Fix runtime kernel compilation of OptiX kernels with CUDA 13+
Attempting to render with OptiX with no precompiled kernels (or adaptive
compilation turned on) would fail on some systems with CUDA toolkit 13
or higher installed. This was because nvcc started to launch a PTX
verification pass with Hopper or higher target, which fails for OptiX
code (since it's unable to resolve the OptiX device intrinsics). To
solve this, simply target a lower architecture for PTX compilation as a
workaround.
2026-01-16 14:24:49 +01:00
Brecht Van Lommel
527f9ea306 Refactor: Cycles: More consistent naming of image functions and structs
Previously there was a mix of "image" and "texture" to refer to the same
thing, use "image" when possible now. An exception is MEM_IMAGE_TEXTURE
to avoid conflicts with the MEM_IMAGE macro on Windows.

Pull Request: https://projects.blender.org/blender/blender/pulls/152665
2026-01-14 17:57:46 +01:00
Brecht Van Lommel
694a8e01dc Fix #150441: Cycles OSL multi device GPU rendering crash
The shader has_bump flag had two different meanings that were being conflated.
This caused the shader compilation for the second device to generate an empty
shader, which wasn't really wrong by itself but not handled properly in OSL
kernel compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/150669
2025-11-27 13:17:11 +01:00
Brecht Van Lommel
8e2c7c1108 Fix #149591: Cycles OptiX log warning with shader raytrace
Not known to cause any specific bug. Compute the stack sizes per
pipeline, to silence warning regarding external functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/150091
2025-11-21 19:01:35 +01:00
Patrick Mours
5e81cb4611 Cycles: Fix OptiX context log no longer showing up
Commit 8392ca915b removed
WITH_CYCLES_LOGGING, but missed that the OptiX context log was
conditionally compiled depending on that definition, so this fixes
that.

Pull Request: https://projects.blender.org/blender/blender/pulls/147706
2025-10-09 17:08:22 +02:00
Weizhen Huang
2b0a1cae06 Cycles: Add an option to use ray marching for volume rendering
Null Scattering currently has performance and noise issues, and it will
take time to address them. For now add the previous Ray Marching back as
an option.

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/146317
2025-09-26 12:14:45 +02:00
Weizhen Huang
b2b2d9a4f3 Cycles: Render volume by ray marching through octrees
One octree per volume per shader based on the density. In preparation
for the null scattering
2025-08-13 10:28:50 +02:00
Brecht Van Lommel
dce6269d1f Fix #143714: Cycles OptiX fails to render linear and ribbon curves together
This case was not accounted for previously, but is now possible when
the new curves object has curves with type poly.

Pull Request: https://projects.blender.org/blender/blender/pulls/144087
2025-08-11 19:36:26 +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
Brecht Van Lommel
73fe848e07 Fix: Cycles log levels conflict with macros on some platforms
In particular DEBUG, but prefix all of them to be sure.

Pull Request: https://projects.blender.org/blender/blender/pulls/141749
2025-07-10 19:44:14 +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
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
0add3f31a2 Cycles: Bump OptiX minimum and release version to 8.0.0
This requires a minimum driver version of 535, however most devices
were already requiring 570 due to the CUDA toolkit version.

The update is required to be able to use an API function for correct
stack size calculation.

Code for older API versions has been removed.

Fix #138185: OSL custom camera errors with OptiX

Pull Request: https://projects.blender.org/blender/blender/pulls/139801
2025-06-04 19:24:21 +02:00
Lukas Stockner
39d7576844 Cycles: Switch OptiX OSL to use LLVM bitcode for shadeops
This is required to make ray differentials work correctly for OSL custom
cameras.

But it also lets us simplify the implementation, and makes the OSL
functionality more complete, such as implementing all noise types.

Pull Request: https://projects.blender.org/blender/blender/pulls/138161
2025-06-03 20:12:07 +02:00
Brecht Van Lommel
5046fe168f Cleanup: Compiler warning 2025-04-30 19:06:36 +02:00
Lukas Stockner
b4c8d709e8 Cleanup: Cycles: Deduplicate OptiX module creation
Pull Request: https://projects.blender.org/blender/blender/pulls/138091
2025-04-28 14:04:15 +02:00
Lukas Stockner
0dc4754da4 Cycles: Move OptiX OSL Camera kernel into its own PTX module
On the one hand, this improves initialization time since we don't need to
load/compile the full OSL module with all the shading logic if we're only
using a custom camera with SVM shading.

On the other hand, it also fixes a bug I noticed while preparing test scenes:
The AO and Bevel nodes don't work when using custom cameras with SVM on OptiX.

The issue there is that those two are handled by the SHADE_SURFACE_RAYTRACE
kernel, but since that one has intersection logic, we use the OptiX-specific
kernel even if OSL shading is disabled.
However, with the previous unified OSL module, this would mean loading
SHADE_SURFACE_RAYTRACE from kernel_osl.cu, which has `#undef __SVM__` and
therefore doesn't handle them correctly.

With this change, we'll use the kernels from kernel_shader_raytrace.cu in that
case, which do support SVM nodes just fine.

Disk usage of the new kernel_optix_osl_camera.ptx.zst file is 30KB, so this
also doesn't blow up the kernel disk size (and kernel_optix_osl.ptx.zst is
probably smaller by that amount now).

Since it seems that we can mix modules just fine, I'm suspecting that we could
split the modules properly (intersection, SVM shading with raytracing,
OSL shading, OSL camera), instead of the current approach where modules
essentially correspond to feature set tiers and each includes the previous
one's kernels as well - but that's a separate refactor.

Pull Request: https://projects.blender.org/blender/blender/pulls/138021
2025-04-28 12:49:35 +02:00
Lukas Stockner
bf412ed9dd Cycles: Support for custom OSL cameras
This allows users to implement arbitrary camera models using OSL by writing
shaders that take an image position as input and compute ray origin and
direction.

The obvious applications for this are e.g. panorama modes, lens distortion
models and realistic lens simulation, but the possibilities are endless.

Currently, this is only supported on devices with OSL support, so CPU and
OptiX. However, it is independent from the shading model used, so custom
cameras can be used without getting the performance hit of OSL shading.

A few samples are provided as Text Editor templates.

One notable current limitation (in addition to the limited device support)
is that inverse mapping is not supported, so Window texture coordinates and
the Vector pass will not work with custom cameras.

Pull Request: https://projects.blender.org/blender/blender/pulls/129495
2025-04-25 19:27:30 +02:00
Brecht Van Lommel
c8f9fdc0c8 Fix: Cycles CUDA errors after recent changes for scene update
Broken by 86b67a20d6. Delay upload of shader data to GPU until
after kernels have been loaded.

Pull Request: https://projects.blender.org/blender/blender/pulls/137349
2025-04-11 19:14:14 +02:00
Lukas Stockner
dbe275895e Cleanup: Cycles: Deduplicate OptiX OSL code
Not a big difference for now, but will be nicer for #129495.

Pull Request: https://projects.blender.org/blender/blender/pulls/135049
2025-03-10 13:30:58 +01:00
Brecht Van Lommel
d48e73977c Fix: Build errors on Linux/GCC after recent Cycles refactoring 2025-01-03 11:52:13 +01:00
Brecht Van Lommel
9971648783 Refactor: Cycles: Replace new/delete by unique_ptr, in simple cases
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:30 +01:00
Brecht Van Lommel
a8654a1dbe Refactor: Cycles: Make CPU kernel globals storage more sane
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:27 +01:00
Brecht Van Lommel
57ff24cb99 Refactor: Cycles: Add const keyword to more function parameters
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:24 +01:00
Brecht Van Lommel
d0c2e68e5f Refactor: Cycles: Automated clang-tidy fixups in Cycles
* Use .empty() and .data()
* Use nullptr instead of 0
* No else after return
* Simple class member initialization
* Add override for virtual methods
* Include C++ instead of C headers
* Remove some unused includes
* Use default constructors
* Always use braces
* Consistent names in definition and declaration
* Change typedef to using

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:55 +01:00
Brecht Van Lommel
3c2a6fbb9c Refactor: Cycles: Use nullptr instead of NULL
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:43 +01:00
Brecht Van Lommel
4e777476b5 Refactor: Cycles: Replace std::bind by lambdas
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:35 +01:00
Lukas Stockner
0de1cea5c5 Cycles: Use fused OptiX OSL programs
Based on #123377 by @brecht, but Gitea doesn't like the rebase these
so here's a new PR.

The purpose here is to switch to fused OptiX programs for OSL execution
on CUDA. On the one hand, this makes the code easier since, but there's
also another advantage - how memory allocation is managed.

OSL shaders need memory to store intermediate values, but how much is
needed depends on the complexity of the shader. With the split program
approach, Cycles had to provide that memory, so we had to allocate a
certain amount (2 KiB, to be precise) statically and show an error if
the shader would need more. If the shader used less (which is the case
for the vast majority), the memory was just wasted.

By switching to fused kernels, OSL knows the required amount during JIT
codegen, so it can allocate only what's required, which avoids this
waste. One still needs to set a maximum, and in theory, OSL would also
support spilling over into a Cycles-provided alternative memory region.
However, we currently don't implement that - instead, we default to the
same 2048 limit as before and let advanced users override it via the
CYCLES_OSL_GROUPDATA_ALLOC environment variable if really needed.

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/130149
2024-11-26 23:58:32 +01:00
Sergey Sharybin
175e46bb51 Merge branch 'blender-v4.3-release' 2024-10-31 17:22:08 +01:00
Patrick Mours
5804a1cc2c Fix #124200: OptiX error when updating 3D curves in viewport rendering
Changing 3D curve properties while viewport rendering was active
resulted in an error, because Cycles would attempt to update the
acceleration structure containing the curves, but that acceleration
structure was built without the
`OPTIX_BUILD_FLAG_ALLOW_UPDATE` flag allowing updates. This
fixes that by adding the flag to all curve build inputs.

Ideally could just use the same flags as for other build inputs and
differentiate between viewport and final rendering (based on
`bvh_type`), but that's not currently an option since the same flags
have to be specified to query the curve intersection module in
`load_kernels()`, where that differentiation is not known. See also
commit 5c6053ccb1.

Pull Request: https://projects.blender.org/blender/blender/pulls/129634
2024-10-31 17:21:30 +01:00
Weizhen Huang
34b95fe3f6 Cleanup: Cycles: use existing utility functions for geometry types
Pull Request: https://projects.blender.org/blender/blender/pulls/129552
2024-10-30 16:45:56 +01:00