Commit Graph

6138 Commits

Author SHA1 Message Date
Hans Goudey
8f1f509368 Cleanup: GPU: Use smaller backing types for a few enums
This makes a few structs a little bit smaller.

Pull Request: https://projects.blender.org/blender/blender/pulls/140157
2025-06-11 18:17:28 +02:00
Clément Foucault
ad1bb4602d Fix: GPU: Assert on startup in Vulkan caused by polyline
The polyline workarounds were not working as expected
since #139627 as it was not garanteed that the polylines
shader would be correctly initialized with the workaround
tag.

Adding a wrapper class to ensure the initialization fixes
the issue.
2025-06-11 17:28:38 +02:00
Brecht Van Lommel
142eab27ef Merge branch 'blender-v4.5-release' 2025-06-11 15:47:58 +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
Clément Foucault
4c655f076c GPU: Shader: Parallel warmup of builtin shaders
This reduces the time needed to get to the first pixel
on screen by multithreading the builtin shader compilation.

We avoid doing this if subprocess compilation is on as
the overhead of potentially partially starting all subprocess
is far greater than the benefit of paralllel compilation.

For some reasons, the compilation is much slower when
done async for these shaders (on Metal ~200ms > ~1.2ms),
so the saving might not be substantial.

Mac M1: First frame 6s > 5s.

Pull Request: https://projects.blender.org/blender/blender/pulls/139627
2025-06-11 14:08:38 +02:00
Omar Emara
9bcb536c95 Fix #138009: Extend Bounds doesn't work with Fast Gaussian
The Extend Bounds input has no effect when the Fast Gaussian filter is
used. Similarly, it has no effect if the Bokeh Blur node is using
variable size. This is a known limitation and was just not implemented.

So to fix this, we implement a general solution that works globally
across the node by pre-padding the inputs of the blur. This uses more
memory but also speeds up the base case when Extend Bounds is disabled,
while also reducing the binary size due to fewer blur specializations.

The variable size Bokeh Blur test was updated since it Extend Bounds was
silently ignored.

Pull Request: https://projects.blender.org/blender/blender/pulls/140192
2025-06-11 11:41:00 +02:00
Campbell Barton
07121d44ae Cleanup: use braces (follow own style guide) 2025-06-11 09:05:26 +00:00
Clément Foucault
afd778ec01 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-11 11:04:10 +02:00
Campbell Barton
0e5d2a3fc7 Merge branch 'blender-v4.5-release' 2025-06-11 16:23:28 +10:00
Campbell Barton
3d99ad2e89 Cleanup: correct typo in comments, use doxygen doc-strings 2025-06-11 16:22:18 +10:00
John Kiril Swenson
fa5178e366 Cleanup: VSE: Remove Legacy Handle Tweaking
This patch removes the older handle selection and transformation logic,
which was accessible through user preferences by switching off the
default "simple tweaking" mode in Editing -> Video Sequencer.

There was some initial bugginess with the new handle behavior, hence
the option to revert to legacy mode, but with recent updates this no
longer applies. With the new system, all selection workflows
are still possible -- this just drops older code to make things simpler.

No functional changes intended.

Pull Request: https://projects.blender.org/blender/blender/pulls/140031
2025-06-11 04:03:17 +02:00
Miguel Pozo
5459d11ed9 Merge branch 'blender-v4.5-release' 2025-06-10 17:25:37 +02: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
Clément Foucault
a5dc8026ee GPU: Shader: Add runtime dependency resolution
This allows to generate source file that will
be injected in a predefined source dependance tree.

This allow much cleaner shader workflow where
all sources are explicitly referenced from the
main source file.

Pull Request: https://projects.blender.org/blender/blender/pulls/140047
2025-06-10 17:22:58 +02:00
Clément Foucault
e57359726f GPU: VertexFormat: Use new data types
This prevents the use of unaligned data types in
vertex formats. These formats are not supported on many
platform.

This simplify the `GPUVertexFormat` class a lot as
we do not need packing shenanigans anymore and just
compute the vertex stride.

The old enums are kept for progressive porting of the
backends and user code.

This will break compatibility with python addons.

TODO:
- [x] Deprecation warning for PyGPU (4.5)
  - [x] Deprecate matrix attributes
- [x] Error handling for PyGPU (5.0)
- [x] Backends
  - [x] Metal
  - [x] OpenGL
  - [x] Vulkan

Pull Request: https://projects.blender.org/blender/blender/pulls/138846
2025-06-10 17:20:45 +02:00
Clément Foucault
368a64f386 GPU: Shader: Add support for shader entry points
This works by wrapping the entry point call inside a
`main` function.

Since resources are still defined in global space,
function accessing these are marked with a custom
attribute. This custom attribute expands in a
`#ifdef` guard for the matching stage.
This is a temporary solution and will eventually
be lifted once we support SRD.

### TODO
- [ ] Implement `[[gpu::vertex/fragment_function]]`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139233
2025-06-10 12:37:20 +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