Commit Graph

14433 Commits

Author SHA1 Message Date
Weizhen Huang
16132f8c79 Fix #117667: Remove volume density weight cutoff
`CLOSURE_WEIGHT_CUTOFF` avoids allocating a closure when its weight is
too small. It makes sense for surface closures, but for volume closures
the contribution also depends on the object size/ray length, such a
cutoff seems random and is causing problem in atmospheric scatterings.

Therefore remove the cutoff for volume, just make sure the weight is
positive.

Pull Request: https://projects.blender.org/blender/blender/pulls/131696
2024-12-13 10:28:49 +01:00
Weizhen Huang
27fc091be8 Fix #131723: Cycles volume not sampling channels with zero extinction
The original paper uses the single scattering albedo `sigma_s/sigma_t`
to pick a channel for sampling the scattering distance. However, this
only considers the situation where there is scattering inside the volume.
If some channel has an extinction coefficient of zero, the light passes
through without attenuation for that channel. We assign such channel
with a weight of 1 instead of 0 to make sure it can be sampled.

Pull Request: https://projects.blender.org/blender/blender/pulls/131741
2024-12-13 10:27:53 +01:00
Jeroen Bakker
b8d67aa10f Vulkan: Make provoking vertex optional for MoltenVK
Provoking vertex isn't supported by Metal and MoltenVK. As it only has
some minor artefacts we make it optional when using MoltenVK.

Pull Request: https://projects.blender.org/blender/blender/pulls/131815
2024-12-13 09:56:37 +01:00
Harley Acheson
fe6609c4eb Fix #111379: Allow Win32 Volume Names to Contain Characters > U+FFFF
When processing volume names for the File Browser sidebar lists we are
properly handling Windows "wide" characters (UTF-16) as long as they
are single wide characters, so below U+FFFF. For characters above this
value we get a pair of UTF-16, and end up trying to convert each to
UTF-8 as separate UTF-32 values. The result is blank output and a
console error that "surrogates not allowed." This PR just does this
conversion correctly using utfconv.

Pull Request: https://projects.blender.org/blender/blender/pulls/131763
2024-12-12 00:49:33 +01:00
Weizhen Huang
a16879a5f0 Fix #131240: Cycles: Negative integration range in Huang Hair
The cause is numerical issues with `fast_sinf()`. While fixing
`fast_sinf()` would ultimately fix the problem, it involves more
complications in other code paths, and it is safer to clamp the
integration range anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/131689
2024-12-10 21:56:04 +01:00
Aras Pranckevicius
322415d5b2 Fix: Build WITH_CYCLES_OSL=OFF failure
Code added in d1796b8df0 was not put under WITH_OSL checks
2024-12-10 09:58:22 +02:00
Lukas Stockner
d1796b8df0 Cycles: Make OSL shader compilation threadsafe and multi-threaded
The original OSL Shading System API was stateful: You'd create a shader
group, configure it, and then end it. However, this means that only one
group can be created at a time. Further, since Cycles reuses the
Shading System for multiple instances (e.g. viewport render and
material preview), a process-wide mutex is needed.

However, for years now OSL has had a better interface, where you
explicitly provide the group you refer to. With this, we can not only
get rid of the mutex, but actually multi-thread the shader setup even
within one instance.

Realistically, most time is still spent in the JIT stage, but it's
still better than nothing.

Pull Request: https://projects.blender.org/blender/blender/pulls/130133
2024-12-09 14:36:35 +01:00
Campbell Barton
5dd67c6e1c Cleanup: sort CMake path lists 2024-12-09 09:18:50 +11:00
Lukas Stockner
91a3039bb2 Cleanup: Cycles: Make BlenderCamera a class with proper initialization
Before, we'd just zero out the memory of the struct and then set the
defaults afterwards, but that:
- Prevents us from storing non-POD types
- Silently assumes that array<float> is safe to zero out (it currently
  is, but that is still ugly and risky)
- Bloats the code since every non-zero entry now needs two lines

So, just make use of C++11 here. All the default values that were
previously unset are taken from the Blender-side defaults.

Pull Request: https://projects.blender.org/blender/blender/pulls/130870
2024-12-06 20:40:24 +01:00
Jonas Holzman
720fc44ca3 GHOST: Fix X11 clipboard selection requests
This commit fixes a pretty long-standing bug in the X11 clipboard code
which caused selection target requests (and thus pasting) to sometimes
fail on certain softwares like Firefox.

The problem lied in the fact that the property format used when setting
the supported target list was dependent on the original request, when
it should always be XA_ATOM (a list of Atom), this can be seen in other
implementations, like GLFW.

This commit also cleans up the surrounding code, by using m_atom to
access atoms instead of redeclaring them in the function, which also
clears up a few instance where the difference between `xse->target`
(the request target) and `target` (the TARGETS Atom) was really unclear.

Pull Request: https://projects.blender.org/blender/blender/pulls/131507
2024-12-06 17:10:50 +01:00
Weizhen Huang
bb3b8d78c2 Refactor: Cycles: split volume integration into smaller functions
Pull Request: https://projects.blender.org/blender/blender/pulls/131414
2024-12-06 16:23:04 +01:00
Weizhen Huang
59ad6d2b9c Refactor: Cycles: Extract code block to check homogeneous volume into a function 2024-12-06 16:23:00 +01:00
Weizhen Huang
13fb28581b Refactor: Cycles: Share function between volume scattering and shadowing 2024-12-06 16:23:00 +01:00
Weizhen Huang
910c2e2ba6 Refactor: Cycles: Add helper struct for stepping through the volume 2024-12-06 16:23:00 +01:00
Weizhen Huang
b16cfd2a87 Cleanup: Cycles: remove unused parameter absorption_only
`!vstate.absorption_only` is always false
2024-12-06 16:23:00 +01:00
Jeroen Bakker
dc6bd96eeb Fix #131315: Vulkan: Provoking vertex incorrect
In OpenGL the last vertex is the provoking vertex. In Vulkan the first
vertex is the provoking vertex. This PR uses `VK_EXT_provoking_vertex`
to use the last vertex as the provoking vertex.

Pull Request: https://projects.blender.org/blender/blender/pulls/131412
2024-12-05 11:03:29 +01:00
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
Jeroen Bakker
108a0f2ec0 Vulkan: Share driver check between GPU and GHOST
GPU and GHOST require to have identical checks to remove faulty drivers.
When not done GHOST can still select a device that isn't supported and
lead to freezing interfaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/131241
2024-12-02 14:50:32 +01:00
Guillermo Venegas
7f7f9e987f Fix #130817: Make resource pool to cycle when swapchain images are presented
Its not standard how `Present Engines` return images for presentation, and
currently is expected that they cycle between swap-chain images with each
`vkAcquireNextImageKHR` call.

However present engines could return any available image, that can mean
to reuse the last presented one if available. (This seem to be the behavior
using `Layered on DXGI Swapchain` the default `Present Method` used
with latest NVIDIA drivers on Windows).

Since resource pools expects to images to cycle in a sequential order, if any
present engine always return the same image for presentation only a single
resource pool would be used for each rendered frame, and since resources
are only released by cycling between resource pools, this resource pool would
overflow since it never releases any resource.

This changes makes resource pools to cycle each time a image is presented.

Pull Request: https://projects.blender.org/blender/blender/pulls/131129
2024-11-29 12:35:44 +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
Raphael Langerhorst
f662caf722 Add RISCV CPU architecture support to build config
Remove assert statement from make_update.py, making it ready for any
architecture.

Add riscv 32, 64 and 128 bit cpu architecture with little/big endian
to Blender's BLI_build_config.h and Libmv's build_config.h

Tested (to compile) on riscv64 little endian machine.

Pull Request: https://projects.blender.org/blender/blender/pulls/130920
2024-11-28 12:37:26 +01:00
Harley Acheson
0193579e90 UI: Win32 - Clipboard Image Paste from File Path
On the Windows platform allow pasting an image into the Image Editor
based on a filepath in the clipboard. For example, selecting "copy" on
the context menu in the file system. This checks for CF_HDROP format
and should work for all image formats we support.

Pull Request: https://projects.blender.org/blender/blender/pulls/127782
2024-11-27 23:55:18 +01:00
Aras Pranckevicius
611940805e Fix #107493, #98480: video rotation metadata is not read
Videos files recorded on most phones were coming in sideways; files
recorded on some laptop cameras were coming in upside down. In both
cases the display_matrix metadata of the video stream was not applied.

This required changing internal container format of movie proxies to
be MP4 instead of AVI, since AVI does not support rotation metadata.
File extension kept at ".avi" to not disturb existing expectations.

It might be better to "bake" rotation into proxies while building them,
but right now we do not have a trivial way of doing that.

Note that this is a potential behavior change; if someone
already had manually rotated video strips, they would have
to undo that rotation now.

Pull Request: https://projects.blender.org/blender/blender/pulls/130455
2024-11-27 17:08:37 +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
YimingWu
6d7eecb1c4 Fix #130799: Prevent cycles material template to show in Grease Pencil
The `poll()` function for `CYCLES_PT_context_material` was using the
legacy `GPENCIL` identifier as opposed to `GREASEPENCIL`. This caused
duplicated material templates to show in the material tab.

Pull Request: https://projects.blender.org/blender/blender/pulls/130962
2024-11-26 12:18:37 +01:00
Lukas Stockner
0fc58f0aba Cycles: Disable -fassociative-math on Linux to avoid GGX issues
This is the safer fix for now, we can revisit this later.
2024-11-26 02:28:09 +01:00
Jonas Holzman
9a8e9bb61b Fix #129985: macOS headless build fails due to missing CGL context symbols
When making a `headless` macOS build, linking would fail complaining
about missing `GHOST_ContextCGL` symbols, which are required by the Metal
backend. This commit fixes this issue by compiling the macOS CGL GHOST
Context if the Metal backend is enabled, instead of only depending on
`WITH_HEADLESS`, similarly to what's done on Linux/other *nix systems.

Pull Request: https://projects.blender.org/blender/blender/pulls/130847
2024-11-25 22:43:19 +01:00
Hans Goudey
b04ef9827a Subdiv: Start replacement of "converter" abstraction
The converter is an abstraction that takes a base mesh to be subdivided
and provides its topology information to the OpenSubdiv library. It does
this with one level of indirection: first extracting the base mesh
topology with a virtual function call per element to local arrays,
then giving the information in those arrays to OpenSubdiv.

That level of indirection also handles cache invalidation for the
intermediate data structures which optimize repeated subdivisions of a
changing base mesh with constant topology. However, these days the mesh
data is stored with simpler to compare data arrays, and we also have
implicit sharing which provides another way to detect unchanged
shared data.

As a very first step to a design where we use OpenSubdiv more directly
and don't store duplicate topology arrays for the base mesh, this PR
provides the converter with the mesh's face offsets array directly
rather than using function calls. For multires reshape the temporary
format is changed to match.

Next steps will do the same thing for face vertices ("corner verts" in
Blender lingo), edges, and creases. Then we can remove the "converter"
indirection completely, then we can work on a better cache invalidation
strategy using implicit sharing. That's a ways off though. On its own,
this PR should just reduce function call overhead a bit.

Reference #130917.

Pull Request: https://projects.blender.org/blender/blender/pulls/130241
2024-11-25 17:05:30 +01:00
Jeroen Bakker
69f94df026 Fix #130164: Vulkan: Freeze when resizing window
When resizing window some platforms could freeze. The cause was that
depending on a platform the swap chain could get out of date when
acquiring the next swapchain image or when presenting the swap chain
image to the queue.

We only covered one scenario. This PR implements the scenario to
recreating the swap chain when the image could not be acquired.

Pull Request: https://projects.blender.org/blender/blender/pulls/130909
2024-11-25 15:31:09 +01:00
Jeroen Bakker
c2695e2dcc Vulkan: Add support for legacy platforms
Dynamic rendering is a Vulkan 1.3 feature. Most platforms have support
for them, but there are several legacy platforms that don't support dynamic
rendering or have driver bugs that don't allow us to use it.

This change will make dynamic rendering optional allowing legacy
platforms to use Vulkan.

**Limitations**

`GPU_LOADACTION_CLEAR` is implemented as clear attachments.
Render passes do support load clear, but adding support to it would
add complexity as it required multiple pipeline variations to support
suspend/resume rendering. It isn't clear when which variation should
be used what lead to compiling to many pipelines and branches in the
codebase. Using clear attachments doesn't require the complexity
for what is expected to be only used by platforms not supported by
the GPU vendors.

Subpass inputs and dual source blending are not supported as
Subpass inputs can alter the exact binding location of attachments.
Fixing this would add code complexity that is not used.

Ref: #129063

**Current state**

![image](/attachments/9ce012e5-2d88-4775-a636-2b74de812826)

Pull Request: https://projects.blender.org/blender/blender/pulls/129062
2024-11-19 16:30:31 +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
Sebastian Parborg
b1ca2f09db Fix: FFmpeg deprecation warnings
Pull Request: https://projects.blender.org/blender/blender/pulls/127203
2024-11-18 17:46:04 +01:00
Patrick Mours
6f0ed29378 Cycles: Add OptiX 8.1 support
The function table symbol declared in the headers was renamed starting
in OptiX 8.1, from `g_optixFunctionTable` to
`g_optixFunctionTable_<ABI version>`. This adds support for that by
using the new macro for the name when available (after OptiX 8.1) and
falling back to the old name when it is not (before OptiX 8.1).

Pull Request: https://projects.blender.org/blender/blender/pulls/130451
2024-11-18 17:20:49 +01:00
Jeroen Bakker
1a6c586e81 Vulkan: Use Vulkan 1.1 feature enablement
Shader draw parameters was enabled by query-ing the extension. The
feature is core in Vulkan 1.1, and our minimum requirement is Vulkan
1.2. In stead of querying the extension we should use enable the
feature via `VkPhysicalDeviceVulkan11Features`.

This was detected when working on !129062

Pull Request: https://projects.blender.org/blender/blender/pulls/130441
2024-11-18 15:11:42 +01:00
Falk David
1d571a810f Fix: Cycles: Compiler warning
The `ProjectionTransform` object has no trivial copy-assignment constructor.
This results in the following warning on `gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0`:
```
/.../blender-git/blender/intern/cycles/kernel/../util/projection.h: In function ‘ccl::ProjectionTransform ccl::projection_inverse(ProjectionTransform)’:
/.../blender-git/blender/intern/cycles/kernel/../util/projection.h:219:9: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘ccl::ProjectionTransform’ {aka ‘struct ccl::ProjectionTransform’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  219 |   memcpy(&tfmR, R, sizeof(R));
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~
/.../blender-git/blender/intern/cycles/kernel/../util/projection.h:67:16: note: ‘ccl::ProjectionTransform’ {aka ‘struct ccl::ProjectionTransform’} declared here
   67 | typedef struct ProjectionTransform {
      |                ^~~~~~~~~~~~~~~~~~~
```
To fix the warning, cast the pointer to `(void *)`.

Pull Request: https://projects.blender.org/blender/blender/pulls/130321
2024-11-15 15:24:49 +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
Jacques Lucke
64a9260921 Core: remove WITH_CXX_GUARDEDALLOC option
This implements the proposal from #124512. For that it contains the following
changes:
* Remove the global override of `new`/`delete` when `WITH_CXX_GUARDEDALLOC` was
  enabled.
* Always use `MEM_CXX_CLASS_ALLOC_FUNCS` where it is currently used. This used
  to be guarded by `WITH_CXX_GUARDEDALLOC` in some but not all cases. This means
  that a few classes which didn't use our guarded allocator by default before,
  are now using it.

Pull Request: https://projects.blender.org/blender/blender/pulls/130181
2024-11-13 13:39:49 +01:00
Bastien Montagne
b325142d17 Merge branch 'blender-v4.3-release' 2024-11-12 16:55:40 +01:00
Bastien Montagne
0b3a7cbe69 Cleanup: Move BKE_image.h and related headers to C++.
NOTE: This also required some changes to Cycles code itself, who is now
directly including `BKE_image.hh` instead of declaring a few prototypes
of these functions in its `blender/utils.h` header (due to C++ functions
names mangling, this was not working anymore).

Pull Request: https://projects.blender.org/blender/blender/pulls/130174
2024-11-12 16:53:54 +01:00
weizhen
9488375049 Fix: Cycles: Missing inclusion in CMakeLists 2024-11-12 15:02:59 +01:00
weizhen
43187cf174 Fix: Cycles: Compile error on GPU
Missing function qualifiers. Oversight of 93a34b1077
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
Jonas Holzman
263212c4fa Merge branch 'blender-v4.3-release' 2024-11-09 01:35:36 +01:00
Jonas Holzman
574e08272c Cleanup: make format 2024-11-09 01:33:16 +01:00