Commit Graph

3658 Commits

Author SHA1 Message Date
Michael Jones
8fe2e37dd0 Fix #130641: MetalRT: Motion Blur (render errors)
This PR fixes #130641. The bug was caused by a missing self-object constraint when performing SSS on motion blur scenes. scene_intersect_local tests were erroneously hitting other objects, and out of range primitive IDs were causing spurious downstream behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/131156
2024-12-03 20:24:36 +01:00
Weizhen Huang
e2d7681fe6 Cleanup: Cycles: remove unused ccl_loop_no_unroll
Was added in 6121c28501 to ensure compiling
on OpenCL, now the definition is empty on all platforms

Pull Request: https://projects.blender.org/blender/blender/pulls/131100
2024-11-28 16:37:01 +01:00
Weizhen Huang
aa09169e0a Cleanup: Cycles: remove unused parameter skip_phase in volume
This logic is copied from surface shader, so that the sampled closure
does not need to be evaluated twice when summing all the closures, but
it is not used in volume.
2024-11-28 15:56:28 +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
Thomas Dinges
5ddf8a6495 Merge branch 'blender-v4.3-release' 2024-11-18 19:14:10 +01:00
Lukas Stockner
1a40efbded Fix #130389: Cycles: Numerical issues in GGX_D with associative math flag
Turns out that with `-fassociative-math`, GCC turns
`(1.0f - cos_NH2) + alpha2 * cos_NH2` into
`cos_NH2 * (alpha2 - 1.0f) + 1.0f`.

Not sure why since the operation count is the same, but if alpha2 is very
small, `alpha2 - 1.0f` will be exactly -1.0f, which then causes issues.

Luckily, having one_minus_cos_NH2 as its own variable appears to be enough to
make GCC keep the original formulation.
Just to be safe, I've also used one_minus_cos_NH2 in the other branch to
hopefully reduce the chance of it being folded in again. Also turns a
division into a reciprocal, which is in theory slightly faster.

Pull Request: https://projects.blender.org/blender/blender/pulls/130469
2024-11-18 19:12:22 +01:00
Nikita Sirgienko
2aa9203f2f Cycles: Reintroduce noinline keyword for oneAPI device
In 891d71a4d4 this keyword was
dropped due to performance regression after
fdc2962beb, but currently code
does not experience this performance degradation, and in fact
there is minor performance improvement on Lunar Lake GPUs,
along with an expected improvement in compile time.
However, this change brings a minor performance regression to
shade_surface kernel on Intel Arc and Meteor Lake GPUs, which
will be solved later by disabling this keyword for
these platforms only.

Pull Request: https://projects.blender.org/blender/blender/pulls/130299
2024-11-15 12:09:37 +01:00
weizhen
9488375049 Fix: Cycles: Missing inclusion in CMakeLists 2024-11-12 15:02:59 +01:00
Weizhen Huang
93a34b1077 Refactor: Cycles: add helper struct Interval
To improve readability

Pull Request: https://projects.blender.org/blender/blender/pulls/130156
2024-11-12 12:06:09 +01:00
Weizhen Huang
675e8173fa Refactor: Cycles: separate volume stack and single entry evaluation
So that volume shader evaluation does not rely on the volume stack.
In the future this is useful for baking the density when building the
volume Octree.

Pull Request: https://projects.blender.org/blender/blender/pulls/130157
2024-11-12 12:05:37 +01:00
Weizhen Huang
90ed91dfdb Cleanup: Cycles: Add Kernel prefix to light tree bounding shapes
BoundingBox -> KernelBoundingBox
BoundingCone -> KernelBoundingCone

Pull Request: https://projects.blender.org/blender/blender/pulls/130141
2024-11-11 17:13:55 +01:00
Weizhen Huang
ec3128ee37 Cleanup: Cycles: Remove unused functions
Wasn't used even when they were added
2024-11-11 16:42:50 +01:00
Weizhen Huang
e9593a6619 Cleanup: Cycles: update light tree paper link
The original one was expired
2024-11-11 15:46:52 +01:00
Sergey Sharybin
40ba18c4cd Merge branch 'blender-v4.3-release' 2024-11-08 17:22:02 +01:00
Sergey Sharybin
e5de274faf Fix: Cycles HIP-RT compilation happens in parallel with CUDA
This was an oversight in #129945: the cycles_kernel_hiprt was not
handled in the original code, hence it was missing in the change.

Pull Request: https://projects.blender.org/blender/blender/pulls/130037
2024-11-08 17:21:20 +01:00
Sergey Sharybin
9abf9b15f4 Merge branch 'blender-v4.3-release' 2024-11-08 11:06:11 +01:00
Sergey Sharybin
f58522fc10 Cycles: Tweak scheduling of GPU kernel compilation
This change makes it so only kernels of the same vendor are compiled in
parallel. For example for the release builds it will be:

1. All CUDA kernels
2. All OptiX kernels
3. All HIP kernels
4. All OneAPI kernels

This potentially leads to a lower CPU utilization, but it makes it much
easier to manage memory usage and tweak per-vendor concurrency.

The goal of this change is to solve occasional out-of-memory during the
GPU kernels compilation step on the CI/CD farm.

This change also includes tweaks to the prallel jobs for HIP-RT and
oneAPI. The tweak is based on measuring apparent memory usage peak on
Linux when doing single-thread compilation, and giving some safe margin
from the available memory on the buildbot.

Pull Request: https://projects.blender.org/blender/blender/pulls/129945
2024-11-08 11:05:38 +01:00
Patrick Mours
d0dd587b60 Fix #108372: GPU implementation of OSL matrix intrinsic functions
All the OSL matrix functions had been implemented using the
`Transform` utility of Cycles, but that's built around a 4x3 matrix,
when the OSL matrix functions are working with 4x4 matrices.
This resulted in them not producing results consistent with the
CPU implementation.

This fixes that by making use of the `ProjectionTransform` utility
of Cycles instead, because it's built around a 4x4 matrix. Since
matrix inversion is required, I had to make a few more utility
functions available on the GPU (except Metal, due to use of
references/pointers without specification) that were previously
CPU-only.

Co-authored-by: Brecht Van Lommel <brecht@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/110102
2024-11-04 17:59:29 +01:00
Sergey Sharybin
51193ce71d Merge branch 'blender-v4.3-release' 2024-10-31 12:48:26 +01:00
Patrick Mours
3a36d638a5 Fix #127205: OptiX error with OSL material using wavelength node
The `osl_wavelength_color_vf` intrinsic was missing an implementation for
OptiX, causing a link error when attempting to load OSL shaders using the
wavelength node.

Pull Request: https://projects.blender.org/blender/blender/pulls/129372
2024-10-31 12:47:45 +01:00
Weizhen Huang
81590dab5e Merge branch 'blender-v4.3-release' 2024-10-29 18:01:41 +01:00
Weizhen Huang
219e655119 Fix #129420: precision issue in light tree distant light angle
In volume segment, the minimal angle formed by the emitter bounding cone
axis and the vector pointing from the cluster centroid to any point on
the ray is computed via `dot(bcone.axis, point_to_centroid)`, see Fig.8.
in paper.
For distant light this angle is 0, but due to numerical issues this is
not always true. Therefore explicitly assign `-bcone.axis` to
`point_to_centroid` in this case.

Pull Request: https://projects.blender.org/blender/blender/pulls/129489
2024-10-29 18:00:59 +01:00
Campbell Barton
1b320d5205 Merge branch 'blender-v4.3-release' 2024-10-25 08:03:11 +11:00
Michael Jones
029cd1f739 Cycles: Remove invalid use of MetalRT accept_any_intersection in scene_intersect_local
This PR fixes a latent issue arising from invalid use of `accept_any_intersection(true)` when performing SSS ray-stepping with MetalRT. The comment incorrectly states that "we can optimize and accept the first hit", but to guarantee correct behaviour in future we need to request the closest hit.
2024-10-24 10:42:59 +01:00
Weizhen Huang
60b8fd005d Merge branch 'blender-v4.3-release' 2024-10-22 15:38:48 +02:00
Weizhen Huang
afd629bffc Cycles: make switching of sampling techniques in Draine less noticeable
Draine phase function sampling internally use Henyey-Greenstein and
Rayleigh sampling for degenerated cases, but the sampling pattern was
different between Draine and Rayleigh. The commit effectively replace
`rand` with `1 - rand` in Rayleigh sampling.

Pull Request: https://projects.blender.org/blender/blender/pulls/129261
2024-10-22 15:38:06 +02:00
Weizhen Huang
ee6f27a100 Fix: Cycles: NaN in Draine phase function when g == 0
When `g == 0`, the Draine phase function from
https://doi.org/10.1051/0004-6361/202142437 simplifies to
\[\Phi(\theta)=\frac{3}{4\pi(3+\alpha)}(1+\alpha\cos^2\theta).\]
Similar as Rayleigh sampling in https://doi.org/10.1364/JOSAA.28.002436,
The solution to the CDF of the marginal density function is
\[\cos^3\theta+a\cos\theta+b=0,\]
with
\[a=\frac{3}{\alpha},\quad b=\frac{3+\alpha}{\alpha}(2\xi_1-1),\]
which has only one real root since \(\alpha > 0\),
resulting in the sample technique
\[\cos\theta=u-\frac{1}{\alpha u}.\]

Pull Request: https://projects.blender.org/blender/blender/pulls/129259
2024-10-22 15:37:37 +02:00
Jesse Yurkovich
4f4c3f73b6 Cleanup: Replace deprecated OIIO APIs with modern ones
Noticed while helping validate the soon to be released OpenImageIO 3.x.

This cleanup makes 2 sets of changes to accommodate removed APIs [1]:
- Remove `ustringHash` since it's been defined as `std::hash<ustring>`
  for quite some time and is fully removed in 3.0.
- Replace `TypeDesc::Type*` types with just `Type*` as the former has
  been removed in 3.0. Cycles was using a mix of the deprecated and
  modern forms anyhow.

[1] https://github.com/AcademySoftwareFoundation/OpenImageIO/blob/main/docs/Deprecations-3.0.md

Pull Request: https://projects.blender.org/blender/blender/pulls/129136
2024-10-17 19:48:38 +02:00
Sergey Sharybin
06c0bd6699 Merge branch 'blender-v4.3-release' 2024-10-16 16:29:24 +02:00
Alaska
24f2fe4880 Fix: Cycles HIP: Failing volume renders with HIP 6.1
Fix the failing rendering of volumes on Windows with HIP SDK 6.1
by reducing the optimization level.

There should be no functional or performance difference for the average
user as the Blender foundation currently does not use HIP SDK 6.1
on Windows. This change is primarily to fix issues for community members
building Blender locally.

Pull Request: https://projects.blender.org/blender/blender/pulls/128836
2024-10-16 16:28:54 +02:00
Alaska
356482ecb5 Cleanup: Fix ambiguous Unicode character warning in Cycles tree.h
Gitea would complain the apostrophe in one of the code comments in
tree.h was an ambiguous Unicode character. So fix it by swapping it
for a more common apostrophe type.
2024-10-16 21:21:57 +13:00
Alaska
e0cd45d04a Cleanup: Readd important details to Cycles ray offsetting TODO
The ray offsetting triangle tests are not numerically identical to
those found in custom BVH implementations.
There was a TODO to fix this, but there was no explaination for why
it should be done. This fixes that.
2024-10-11 02:41:20 +13:00
Lukas Stockner
11ae08157e Revert Cycles SVM state cleanup due to Mac ARM test timeout
Not sure what is happening here, needs to be checked by someone on Mac.
Let's revert for now, it's not like this is a critical change.

Pull Request: https://projects.blender.org/blender/blender/pulls/110443
2024-10-08 00:33:56 +02:00
Lukas Stockner
0a4877264d Cycles: Cleanup: Move SVM execution state into a helper struct
This packs the SVM stack, current node offset and closure weight into one struct, and just passes that to each SVM node implementation.

This way we don't have to pass the offset back and forth all over the place, and adding additional state (e.g. for layering in the future) becomes easier.

Pull Request: https://projects.blender.org/blender/blender/pulls/110443
2024-10-07 19:09:52 +02:00
Lukas Stockner
b8d0bef3b4 Cleanup: Cycles: Consolidate coordinate system conversions
- Deduplicate Fisheye projection code
- Replace spherical/cartesian conversions with shared helpers
- Replace transforms from/to local coordinate systems with shared helpers

The main type of repeated transform that's not covered here is `to/from_coords`, but with separate values for xy and z (e.g. BSDFs that already computed `dot(wi, N)` earlier, so they only need `dot(wi, X)` and `dot(wi, Y)` later). Could also be replaced, but it would feel weirdly specific for a helper function.

Pull Request: https://projects.blender.org/blender/blender/pulls/125999
2024-10-07 02:18:49 +02:00
Xavier Hallade
b614953971 Cycles: oneAPI: fix Linux compilation with fno-honor-nans
Previously, when compiling on Rocky Linux 8 with fno-honor-nans, compile
time was more than 5x longer than expected, and there was an unresolved
symbol to __sqrtf_finite in GPU binaries.
Once defining sqrtf in compat.h, both issues are effectively gone, this
was certainly due to problematic interactions with build system's math
library headers.
So we can remove current workaround of defining fhonor-nans, and now
have the same set of flags on both Windows and Linux.
2024-10-04 17:50:24 +02:00
Alaska
0709743c0c Fix: Cycles: Rendering of the Principled BSDF when using adaptive kernel compilation
Fixes a issue where the Principled BSDF would render incorrectly if
`__SUBSURFACE__` is off. Which is common when using adaptive kernel
compilation (a unsupported Cycles feature).

Pull Request: https://projects.blender.org/blender/blender/pulls/128003
2024-10-04 12:39:03 +02:00
Campbell Barton
4fa3dc0dd4 Cleanup: spelling in comments, use uppercase tags 2024-10-03 12:11:52 +10:00
Alexandre Cardaillac
0315eae536 Cycles: Add more scattering phase functions
Previously, Cycles only supported the Henyey-Greenstein phase function for volume scattering.
While HG is flexible and works for a wide range of effects, sometimes a more physically accurate
phase function may be needed for realism.

Therefore, this adds three new phase functions to the code:
Rayleigh: For particles with a size below the wavelength of light, mostly athmospheric scattering.
Fournier-Forand: For realistic underwater scattering.
Draine: Fairly specific on its own (mostly for interstellar dust), but useful for the next entry.
Mie: Approximates Mie scattering in water droplets using a mix of Draine and HG phase functions.

These phase functions can be combined using Mix nodes as usual.

Co-authored-by: Lukas Stockner <lukas@lukasstockner.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/123532
2024-10-02 11:12:53 +02:00
Nikita Sirgienko
fb21f3fb56 Cleanup: Cycles: oneAPI: Fix deprecation warnings about get_pointer() 2024-10-01 22:26:15 +02:00
Xavier Hallade
284b89a0a3 Cycles: oneAPI: compile kernels with fast-relaxed-math
This enables most of the GPU compiler's optimizations while -ffast-math
isn't set at DPC++ level.
It brings an overall 1% speedup and currently doesn't change the unit
tests pass rate.
2024-09-30 21:40:00 +02:00
Lukas Stockner
de80c24ed4 Cleanup: Cycles: Rename CYCLES_x_KERNEL_FLAGS to CYCLES_x_FLAGS in CMake
Pull Request: https://projects.blender.org/blender/blender/pulls/128342
2024-09-30 15:58:31 +02:00
Sahar A. Kashi
26ed4d3892 Cycles: Linux Support for HIP-RT
This change switches Cycles to an opensource HIP-RT library which
implements hardware ray-tracing. This library is now used on
both Windows and Linux. While there should be no noticeable changes
on Windows, on Linux this adds support for hardware ray-tracing on
AMD GPUs.

The majority of the change is typical platform code to add new
library to the dependency builder, and a change in the way how
ahead-of-time (AoT) kernels are compiled. There are changes in
Cycles itself, but they are rather straightforward: some APIs
changed in the opensource version of the library.

There are a couple of extra files which are needed for this to
work: hiprt02003_6.1_amd.hipfb and oro_compiled_kernels.hipfb.
There are some assumptions in the HIP-RT library about how they
are available. Currently they follow the same rule as AoT
kernels for oneAPI:
- On Windows they are next to blender.exe
- On Linux they are in the lib/ folder

Performance comparison on Ubuntu 22.04.5:
```
GPU: AMD Radeon PRO W7800
Driver: amdgpu-install_6.1.60103-1_all.deb
                       main         hip-rt
attic                  0.1414s      0.0932s
barbershop_interior    0.1563s      0.1258s
bistro                 0.2134s      0.1597s
bmw27                  0.0119s      0.0099s
classroom              0.1006s      0.0803s
fishy_cat              0.0248s      0.0178s
junkshop               0.0916s      0.0713s
koro                   0.0589s      0.0720s
monster                0.0435s      0.0385s
pabellon               0.0543s      0.0391s
sponza                 0.0223s      0.0180s
spring                 0.1026s      1.5145s
victor                 0.1901s      0.1239s
wdas_cloud             0.1153s      0.1125s
```

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Co-authored-by: Ray Molenkamp <github@lazydodo.com>
Co-authored-by: Sergey Sharybin <sergey@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/121050
2024-09-24 14:35:24 +02:00
Campbell Barton
0fc27c8d81 Cleanup: spelling in comments 2024-09-20 13:14:57 +10:00
Alaska
27680118db Fix #127464: Disable HIPRT point clouds to fix performance regression
Temporarily disable point cloud rendering in HIPRT to fix a performance
regression triggered by increased register preasure until
a better solution can be developed.

Pull Request: https://projects.blender.org/blender/blender/pulls/127738
2024-09-17 17:59:18 +02:00
Nikita Sirgienko
d300098ee5 Fix #125093: Cycles: oneAPI: transparent shadows opaque when bounces>=1024
Pull Request: https://projects.blender.org/blender/blender/pulls/127404
2024-09-16 16:37:55 +02:00
Alaska
0e36107433 Fix: Cycles: Rendering of VDB files with HIP-RT
VDB files would fail to render in HIP-RT because NanoVDB wasn't
enabled when compiling HIP-RT kernels, resulting in NanoVDB textures
not being sampled and a blank result being returned instead.

The fix is to enable NanoVDB when compiling HIP-RT kernels.

Ref: #125086

Pull Request: https://projects.blender.org/blender/blender/pulls/127384
2024-09-12 16:26:41 +02:00
Weizhen Huang
ee2fe7fa6c Fix: Cycles: reuse random number for sampling color channel in volume
The same random number was used for sampling color channel at each step,
which leads to bias. Fixed by rescaling the random number.

Another possibility would be to scramble `rng_offset` and use a new
random number each time, similar as in subsurface scattering, but
rescaling random number should be faster than computing a new one, and
is favorable here since the precision here is not very important

Pull Request: https://projects.blender.org/blender/blender/pulls/127454
2024-09-12 14:27:56 +02:00
Xavier Hallade
33dd8dbdac Cycles: simplify fmodf(c, 1.0f) to fractf(c) in hsv node
Pull Request: https://projects.blender.org/blender/blender/pulls/127461
2024-09-12 11:53:07 +02:00
Xavier Hallade
473711b579 Build: avoid compiling Intel GPU binaries if no devices are set
Compilation command was malformed in this case.
2024-09-11 17:34:10 +02:00