Commit Graph

6133 Commits

Author SHA1 Message Date
Jeroen Bakker
ea1652dca3 Fix #140229: Vulkan: Crash during depth aware-navigation
Depth navigation sends many small render graphs to the device. It can be
that a subsequent render graph uses the same shader as the previous one
with the same descriptor set tracker. The descriptor set tracker didn't
cleared its full state and a subsequent render graph was generating
commands assuming that the device was in a certain state.

However it wasn't and a command to bind a descriptor set was skipped
resulting in a device out of bound write. Depending on the platform this
could overwrite any data on the GPU, including shader programs as the
select shader writes to a storage buffer. This clarifies why the issue
resulted in very odd and none consistent behavior.

This PR fixes this by clearing the VKPipelineData and
VKDescriptorTracker.

Pull Request: https://projects.blender.org/blender/blender/pulls/140526
2025-06-17 11:17:03 +02:00
Jeroen Bakker
701eb56f5e Fix #140129: Vulkan: Race condition render graph submission
When queueing render graphs for submission the adding of the queue was
not guarded. This could  still introduce a race condition, although
very unlikely.

Co-authored-by: Jorn Visser <git@jornvisser.com>

Pull Request: https://projects.blender.org/blender/blender/pulls/140517
2025-06-17 08:57:36 +02:00
Clément Foucault
7da81b5f39 Fix #140450: Vulkan: profile.json files appears in home directory
Was caused by the shader compilation profiling not checking
for the profiler being enabled.
2025-06-16 11:02:18 +02:00
Campbell Barton
c482c52346 Cleanup: sort CMake file lists 2025-06-14 15:57:33 +10:00
Jeroen Bakker
6899c2dbfd Fix #140342: Vulkan: Assert when quiting
When quiting Blender the timeline doesn't get updated and an assert is
triggered that the order isn't correct. The order isn't that important
anymore as the mechanism has been tested. The assert was useful during
initial development.

This PR removes the assert as it isn't valid in all cases.
2025-06-13 13:28:37 +02:00
Clément Foucault
bb60b85fc7 Fix #139939: GPU: Driver Timeout when switching to Material Preview
This is caused by the late changes to shader compilation.

Using the main thread to compile shaders in a blocking manner
should fix the issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/140140
2025-06-12 16:43:41 +02:00
Jeroen Bakker
38a8512e47 Fix #140129: Vulkan: Discard pool/timeline synchronization issues
In several cases synchronization issues around discarded resources could lead
to crashes. These crashes where more prominent on NVIDIA as they reuse
their handles more often.

This PR requires external synchronization when data is moved from a
discard pool to the main orphaned data discard pool. Also the device
timeline should be guarded by the same mutex.

Pull Request: https://projects.blender.org/blender/blender/pulls/140274
2025-06-12 15:12:04 +02:00
Jeroen Bakker
f6ec5570d4 Fix #140215: Vulkan: performance descriptor buffers
We added descriptor buffers to 4.5 as it contains some core API changes.
However there have been various reports that the system isn't fully
mature resulting in lower performance especially on NVIDIA GPUs.

This PR will disable descriptor buffer feature for NVIDIA GPUs.

Pull Request: https://projects.blender.org/blender/blender/pulls/140263
2025-06-12 12:50:32 +02:00
Clément Foucault
20803fb307 Fix: GPU: Mesa driver on AMD GPU matches GPU_DRIVER_OFFICIAL
The check for Mesa needed to be before the more coarse
check about an AMD GPU. Also, it seems the newer drivers
do not have `X.Org` in the vendor string.
Checking for `Mesa` in the version string seems to be
the correct way.

Pull Request: https://projects.blender.org/blender/blender/pulls/140204
2025-06-11 15:43:50 +02:00
Campbell Barton
3d99ad2e89 Cleanup: correct typo in comments, use doxygen doc-strings 2025-06-11 16:22:18 +10:00
Miguel Pozo
fca4a16975 Fix: GPU: GPUWorker lock
Prevent race conditions caused by calling `GPUWorker::wake_up` when the
worker is not waiting.
Found to be an issue in #139627, since `wake_up` is likely to be called
before the thread has fully started.

Pull Request: https://projects.blender.org/blender/blender/pulls/139842
2025-06-10 17:24:18 +02:00
Jeroen Bakker
a14a844a99 Fix: #140028: Vulkan: Incorrect move of resources
Previous implementation allows to move VKBuffers, but didn't do a
proper std::move. On second thought it is a bad idea to be able to move
GPU resources. This PR removes the ability to move the buffer and
replace the usages with a unique ptr.

Pull Request: https://projects.blender.org/blender/blender/pulls/140103
2025-06-10 10:24:04 +02:00
Clément Foucault
1c47e31367 GPU: Enable GL multithreaded compilation by default
This allows to reduce the waiting time caused by
shader compilation on some GPU-driver combo.

A new settings in the User Preferences make it
possible to override the default amount of worker
threads and optionally use subprocesses.

We still use only one worker thread in cases where
there is no benefit with adding more workers
(like AMD pro driver and Intel windows).

It doesn't scale as much as subprocesses for material
shader compilation but that is for other reasons
explained in #139818.

Add some heuristic to avoid too much memory usage
and / or too many stalls.

Also add some heuristic to the default number of subprocess for
the platform that shows scalling.

Historically, multithreaded compilation was prevented by the
need of context per thread inside `DRWShader` module.
Also there was no good scaling at that time. But
nowadays numbers shows different results with
good scaling with reasonable amount of threads on many
platforms.

Even if we are going for vulkan in the next release
most of the legacy hardware will still use OpenGL for
a few other releases. So it is relevant to make this
easy improvement.

See pull request for measurements.

Pull Request: https://projects.blender.org/blender/blender/pulls/139821
2025-06-09 12:36:06 +02:00
Jeroen Bakker
1ad6749a85 Revert "Fix #139898: Vulkan: Asan issue during color picking"
Fix introduces many issues. We should fix the asan issue locally

This reverts commit c5317faec4.
2025-06-09 08:56:28 +02:00
Campbell Barton
def2a2d049 Logging: remove explicit newlines
CLOG adds newlines, including them in the string adds a blank line.
2025-06-07 12:13:16 +10:00
Clément Foucault
36f1102756 GPU: GLProgram: Use unique pointer instead of movable object
This avoid issue with not moving the `std::mutex` that was
added in #136991.

Issue reported here https://projects.blender.org/blender/blender/pulls/139821#issuecomment-1592962

Pull Request: https://projects.blender.org/blender/blender/pulls/139937
2025-06-06 16:27:18 +02:00
Clément Foucault
9c305ef522 Fix: GPU: Metal: Compilation error 2025-06-06 16:25:19 +02:00
Jeroen Bakker
4a88c14d95 Fix #139917: Vulkan: Increase number of render frames
The number of render frames influences how long discarded memory will be
kept. There are platforms that require 5 frames to work succesfully.

Pull Request: https://projects.blender.org/blender/blender/pulls/139934
2025-06-06 16:02:47 +02:00
Clément Foucault
e0e5289138 Cleanup: GPU: Use CLOG instead of std::cout for profile error 2025-06-06 14:57:36 +02:00
Clément Foucault
023865b314 Vulkan: Add CPU profiling
This has limited use cases since it doesn't
profile the heavy part of the vulkan backend.

Almost 1:1 port of the metal implementation from #139551.
Doesn't cover rendergraph submission nor GPU timings.

Pull Request: https://projects.blender.org/blender/blender/pulls/139899
2025-06-06 14:39:51 +02:00
Jeroen Bakker
c5317faec4 Fix #139898: Vulkan: Asan issue during color picking
Color picking reads 3 values from a texture that is backed by 4
channels. The conversion would also convert the 4th channel.

This is a short term fix. We should reconsider the usage of reading a
different number of elements than backed by the texture. But that
requires work in the color picking and python GPU module.

Pull Request: https://projects.blender.org/blender/blender/pulls/139929
2025-06-06 14:01:37 +02:00
Jeroen Bakker
9e221a10d3 Fix #139901: UI: Incorrect flow when drawing scopes
When drawing image scope the vulkan backend raised some asserts. After
checking them the issue was in the calling code, that could lead to
undefined behavior on other platforms as well.

It isn't allowed to have an immediate mode shader bound, when performing
batch drawing. There was also a point batch that didn't use any point
shader resulting in undefined behavior as well.

For 5.0 we should add this as a GPU module check.

Pull Request: https://projects.blender.org/blender/blender/pulls/139926
2025-06-06 14:01:02 +02:00
Jeroen Bakker
66d361bd29 Vulkan: Add support for descriptor buffers
Descriptor sets/pools are known to be troublesome as it doesn't match
how GPUs work, or how application want to work, adding more complexity
than needed. This results is quite an overhead allocating and
deallocating descriptor sets.

This PR will use descriptor buffers when they are available. Most platforms
support descriptor buffers. When not available descriptor pools/sets
will be used.

Although this is a feature I would like to land it in 4.5 due to the API changes.
This makes it easier to fix issues when 4.5 is released.
The feature can easily be disabled by setting the feature to false if it has
to many problems.

Pull Request: https://projects.blender.org/blender/blender/pulls/138266
2025-06-06 10:20:36 +02:00
Jeroen Bakker
3a16f3b45f Fix #137909: Vulkan: Recover from allocation errors
When buffers/images are allocated that use larger limits than supported
by the GPU blender would crash. This PR adds some safety mechanism to
allow Blender to recover from allocation errors.

This has been tested on NVIDIA drivers.

Pull Request: https://projects.blender.org/blender/blender/pulls/139876
2025-06-05 14:11:37 +02:00
Clément Foucault
2257ee7e56 GPU: OpenGL: Add support for non-blocking specialization
This avoid having to compile specializations JIT and
use the same API as subprocess compilation.

This bridges the gap between subprocess and threaded
compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/139702
2025-06-04 11:24:20 +02:00
Campbell Barton
6a1fa176ef Cleanup: spelling in comments & duplicate terms (check_spelling.py)
Also minor clarification in doc-string.
2025-06-04 01:51:29 +00:00
Clément Foucault
32c50e35c4 GPU: Add profiling groups for subprocess compilation 2025-06-03 17:57:16 +02:00
Clément Foucault
60f7ca21c3 GPU: Shader: Also move the compilation handle in static shaders
Small oversight.
2025-06-03 17:39:33 +02:00
Clément Foucault
e69762b8dd GPU: Add compilation constants
Compilation constants are constants defined in the create info.
They cannot be changed after the shader is created.
It is a replacement to macros with added type safety.

Reuse most of the logic from Specialization constants.

Pull Request: https://projects.blender.org/blender/blender/pulls/139703
2025-06-03 17:34:04 +02:00
Miguel Pozo
8907567a00 Fix: OpenGL: Hang when subprocess crashes
If the compilation subprocess crashes due to an internal driver error,
the end semaphore is never signaled and leaves Blender hanging.

This replaces the `decrement` calls with `try_decrement` and checks
every second if the subprocess is lost.

Additionally, if the issue comes from a broken binary, the crashes will
happen every time a Blender session tries to load it.
So now we store the shader hash in the shared memory before trying to
load the binary. If the subprocess is lost mid compilation, the main
process will delete the broken cached binary.

Pull Request: https://projects.blender.org/blender/blender/pulls/139747
2025-06-03 15:37:21 +02:00
Jeroen Bakker
e91e8eef41 Refactor: Vulkan: Use VKDevice& in finalize_pipeline_layout
!139630 requires the VKDevice to access the device function pointers.
2025-06-03 10:49:14 +02:00
Jeroen Bakker
3a875b2910 Vulkan: Don't run tests on unsupported platforms 2025-06-03 10:43:36 +02:00
Jeroen Bakker
9bbcbd06e8 Vulkan: Allow NVIDIA layers
Fixes a typo, NVIDIA layers use an abbreviation nowadays.
2025-06-03 10:07:19 +02:00
Jeroen Bakker
b416152cb9 Vulkan: Only load layers that we trust
This PR changes loading of implicit vulkan layers. See #139543 where we
detected that there are vulkan layers installed on systems that try to
impersonate other software, but crashes when used in Blender.
2025-06-03 08:37:48 +02:00
Hans Goudey
77b14f2dcb Cleanup: Grammar: Fallback vs. fall back
The former is a noun or adjective, the latter is a verb.
2025-06-02 17:13:56 -04:00
Hans Goudey
20ca13e4e4 Fix: Compile error in node socket shape shader 2025-06-02 10:10:46 -04:00
quackarooni
0a1ff2b2ff Nodes: add "Power" and "Sign" operations to Vector Math node
This adds "Power" and "Sign" as per-element/channel operations to the Vector Math node.

Pull Request: https://projects.blender.org/blender/blender/pulls/139474
2025-06-02 08:53:13 +02:00
Jacques Lucke
cb795cc13a Cleanup: repeated typo
This changes `ouput`  to `output`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139711
2025-06-02 08:36:43 +02:00
Brecht Van Lommel
becc2fa9cb Fix: Metal parallel shader compilation does not respect -t option
This command line option to control the number of threads was already taken
into account for OpenGL and Vulkan.
2025-05-30 17:50:56 +02:00
Miguel Pozo
045926a305 GPU: Always use MTLShaderCompiler
No reason to use the base compiler on Metal.

Pull Request: https://projects.blender.org/blender/blender/pulls/139638
2025-05-30 17:41:13 +02:00
Jeroen Bakker
cfe0dc2cc1 Refactor: Vulkan: Reuse GHOST VkInstance
This PR will reuse the VkInstance of GHOST_ContextVK when querying for
possible compatible devices. Previously a temporary VkInstance was
created but could trigger an error in the Vulkan loader.

Pull Request: https://projects.blender.org/blender/blender/pulls/139640
2025-05-30 16:03:45 +02:00
Clément Foucault
940ef330c8 Fix: GPU: Make StaticShader::ensure_compile_async request for ready state
This was missing from the initial implementation.

This did not affect any user code path since they were not
checking for completion and only blocking on first `get`.
2025-05-30 15:21:06 +02:00
Clément Foucault
f82673afd9 Fix: GPU: Invalid logic in StaticShader::get()
Simple oversight. Didn't have any effect.
2025-05-30 15:21:06 +02:00
Jeroen Bakker
5e690aa217 Fix: Shader CPP compiler error
Shader CPP compiler broke due to recent shaders not including the
correct resources.
2025-05-30 09:30:42 +02:00
Clément Foucault
c3f4dd27f1 GPU: Add async compilation to StaticShader class
This allow to easily request async compilation
in a safe way for every static shader.

The get function will always wait if async
compilation has been requested.
2025-05-30 09:14:02 +02:00
Clément Foucault
87bab6b425 Fix: GPU: Failling test caused by missing push constant 2025-05-30 09:14:02 +02:00
Campbell Barton
50f3240abd Cleanup: spelling & duplicate terms (check_spelling.py) 2025-05-30 11:03:56 +10:00
Miguel Pozo
2db0b92280 GPU: Add CompilationPriority
Allow adding compilation batches to different priority queues.
Set priorities so static shaders are always compiled first,
then materials, and optimized materials last.

Pull Request: https://projects.blender.org/blender/blender/pulls/139456
2025-05-29 19:43:02 +02:00
Jeroen Bakker
c56a855b9f Fix #139565: PyGPU: Add builtin point shaders
This PR adds builtin shaders for drawing points. Using `FLAT_COLOR`,
`SMOOTH_COLOR`, `UNIFORM_COLOR` can lead to undesired behavior
on Metal and Vulkan backends. To ensure future compatibility this PR
adds `POINT_FLAT_COLOR` and `POINT_UNIFORM_COLOR`.

The point size can be set using `gpu.state.point_size_set`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139583
2025-05-29 14:36:32 +02:00
Jeroen Bakker
cd3bd7774f Fix #139546: Vulkan: Race condition during rendering resulting in a stall
Race condition between the main thread and worker thread. In this case
the worker thread was waiting for a device idle, but the main thread was
waiting on a specific timeline. As long as the timeline didn't pass the
device was locked.

Releaved the race condition to check on queue idle as the timeline event
isn't part of the queue.

On windows drivers could be reset and could lead to other crashes as handles
were not used anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/139579
2025-05-29 12:13:43 +02:00