Commit Graph

801 Commits

Author SHA1 Message Date
Jeroen Bakker
429854363e Vulkan: Disable Stencil Export when Forcing Workarounds
When forcing workarounds stencil export was not disabled. This PR
disables this GPU feature when running blender with `--debug-gpu-force-workarounds` .

Pull Request: https://projects.blender.org/blender/blender/pulls/146130
2025-09-12 09:28:17 +02:00
Campbell Barton
975f42b7b2 Cleanup: use doxygen comments to end groups 2025-09-12 10:19:56 +10:00
Jeroen Bakker
0c75361516 Vulkan: Add Memory Pool for External Pixel Buffers
Adds a separate memory pool for creating external pixel buffers.
Previous the memory type of images was used, but could not be
compatible.

Pull Request: https://projects.blender.org/blender/blender/pulls/146078
2025-09-11 16:19:23 +02:00
Jeroen Bakker
819175961b Fix#145961: Vulkan: Pixelbuffer are Never Exported
Pixel buffers will be imported by Cycles in Cuda/OneAPI/HIP
when supported. However the priority and export field is not filled correctly,
resulting in that the priority is always 1 and the buffer is never exported.

Should be backported to 4.5 as Cycles GPU interop isn't working
when using Vulkan.

Regression introduced by: !144422

Pull Request: https://projects.blender.org/blender/blender/pulls/146090
2025-09-11 16:15:14 +02:00
Jeroen Bakker
790033e0c3 Cleanup: Vulkan: Remove references to Renderpass and Framebuffer
VkRenderPass and VkFramebuffer are not used in Blender 5.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/146082
2025-09-11 15:03:46 +02:00
Jeroen Bakker
6cf0658eee Vulkan: Submission timeline value
Although this doesn't lead to any different behaviour or fixes any issue
it was an oversight as this would not wait for empty render graphs to be
finished in the order of submission

Pull Request: https://projects.blender.org/blender/blender/pulls/146066
2025-09-11 10:36:38 +02:00
Jeroen Bakker
c50c3275be Vulkan: Acquire/release swapchain images
`GHOST_SwapWindowBuffers` doesn't fit well when using swapchains. In
that case an approach where swap chain images are acquired and released
would map better. This PR introduces `GHOST_SwapWindowBufferAcquire`
and `GHOST_SwapWindowBufferRelease` to be more in line with vulkan swap
chains.

Previous implementation would first record all GPU commands based on
the last used swap chain. In case a swapchain needed to be recreated
(window resize, move to other monitor) the recorded commands would
not match the swap chain and could lead to artifacts.

OpenGL only implements the release functions as they don't
have a mechanism to acquire a swap chain image. (Need to validate with
the Metal API how this is working and adapt is needed).

Currently when starting blender on a HDR capable display the first frame
would be based on an sRGB surface and presented on an extended RGB
(or other) surface. As these don't match the first frame could be incorrect and
also lead to UBs as another surface is expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/145728
2025-09-11 07:51:30 +02:00
luz paz
81c8b22eeb Cleanup: Fix typos in source/blender/gpu
Fix some non-user-facing typos.
Found via codespell

Pull Request: https://projects.blender.org/blender/blender/pulls/145815
2025-09-09 09:07:23 +02:00
Jeroen Bakker
62912594d1 Cleanup: Remove instance rate vertex
Instance vertex buffers have been removed in Blender 5.0 due to limited
support in certain drivers. The Vulkan backend still had code in place.

Pull Request: https://projects.blender.org/blender/blender/pulls/145913
2025-09-08 12:46:47 +02:00
Jeroen Bakker
7d3e4a25ac Fix: Vulkan: Unused attachments
Recent changed introduced a VVL error on devices that don't support
`VK_EXT_dynamic_rendering_unused_attachments`. These include
Qualcomm GPUs.

PR introduced regression: !145120

Pull Request: https://projects.blender.org/blender/blender/pulls/145793
2025-09-05 14:32:41 +02:00
Brecht Van Lommel
ffa4f8c7ad Refactor: Split off lighter BLI_color_types.hh from BLI_color.hh
Functions for convert between the color types and ostream support are
now outside the classes.

Many files were changed to fix cases where direct includes for headers
were missing.

Pull Request: https://projects.blender.org/blender/blender/pulls/145756
2025-09-05 11:11:32 +02:00
Jeroen Bakker
41bcdb26dc Fix #144887: Vulkan: Crash when downloading large images
Even when a device is capable to allocate a buffer with a certain size
it can still fail the allocation due to driver internals. This could be that
the memory area doesn't support the required flags or fragmentation.

This PR changes downloading GPU textures to CPU to use at max buffer
sizes of 2GB. Larger textures will be split over multiple buffers.

Pull Request: https://projects.blender.org/blender/blender/pulls/145568
2025-09-04 09:31:20 +02:00
Jeroen Bakker
8b220fa4cf Cleanup: String formatting
Pull Request: https://projects.blender.org/blender/blender/pulls/145575
2025-09-02 15:11:16 +02:00
Jeroen Bakker
75c66158aa Vulkan: Precheck max allowed buffer size
Maintenance4 contains the maxBufferSize property that contains the
maximum allowed buffer allocation.

This PR uses this property to precheck if allocations will fail. It
was an attempt to improve the reliability of failing allocations but
currently they fail at the driver side.

Pull Request: https://projects.blender.org/blender/blender/pulls/145555
2025-09-02 10:57:24 +02:00
Jeroen Bakker
dfd168f905 Vulkan: Remove resource pools
Multiple previous changes made resource pools obsolete. Resource
pools were used to keep track of resources when the frame is rendered.
Multiple frames can be rendered at the same time and resources could
overlap.

This has been replaced (not this commit) to be part of the render graph
and when an submission has completed the resources are recycled.

Continuation of: https://projects.blender.org/blender/blender/pulls/145408

Pull Request: https://projects.blender.org/blender/blender/pulls/145511
2025-09-01 15:34:14 +02:00
Jeroen Bakker
f80083491a Revert "Vulkan: Remove resource pools"
This reverts commit ce0406b97b.
Reports on blender-coders mentioned that it could fail on startup.
2025-09-01 12:39:39 +02:00
Jeroen Bakker
ce0406b97b Vulkan: Remove resource pools
Multiple previous changes made resource pools obsolete. Resource
pools were used to keep track of resources when the frame is rendered.
Multiple frames can be rendered at the same time and resources could
overlap.

This has been replaced (not this commit) to be part of the render graph
and when an submission has completed the resources are recycled.

Pull Request: https://projects.blender.org/blender/blender/pulls/145408
2025-09-01 08:37:55 +02:00
Jeroen Bakker
246c01037f Refactor: Move Vulkan descriptor pools
Moves the descriptor pools from resource pools to thread data.

The descriptor pools uses a recycling approach and don't need
to be guarded anymore inside a resource pool. Now only the
descriptor set tracker is inside the resource pool.

Pull Request: https://projects.blender.org/blender/blender/pulls/145393
2025-08-29 13:33:35 +02:00
Clément Foucault
8c7ba3579f GPU: Batch: Remove unused instance attributes
This has been completely replaced by SSBOs overtime.

This reduces API size and avoid untested/legacy path
in drivers that are known to break (see #134509).

Pull Request: https://projects.blender.org/blender/blender/pulls/145242
2025-08-28 12:07:41 +02:00
Brecht Van Lommel
5d72498154 Color Management: Improve gamma 2.2 vs piecewise sRGB handling for HDR
See the code comments for detailed explanation. But overall we use particular
combinations of sRGB and gamma 2.2 encode/decode to match SDR applications
while still ensuring HDR values are passed on linearly.

This means the user interface and SDR content will display different in
Windows HDR mode off and on, but that is consistent with other applications.

Split use_hdr variable into use_hdr_buffer about the graphics buffer,
and use_hdr_display about the chosen display in Blender.

Ref #145022

Pull Request: https://projects.blender.org/blender/blender/pulls/145025
2025-08-28 11:35:10 +02:00
Jeroen Bakker
31fa6b62f9 Fix: Vulkan: Incorrect framebuffer size
When a file is loaded with a minimized window the VKFramebuffer can
contain incorrect texture/data that result in a crash when maximizing the
window.

Pull Request: https://projects.blender.org/blender/blender/pulls/145171
2025-08-28 09:38:39 +02:00
Christoph Neuhauser
ad4adccdeb GPU: Added image format validation for shader image bindings
The OpenGL specs require that the storage image qualifier in shaders
(e.g., "rgba32f") needs to be compatible with the format of a bound image
(see https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf#page=318).

We know that Blender currently does not handle this correctly in
multiple places. AMD and NVIDIA seem to silently ignore a mismatch and
just seem to use the format of the bound image. However, for the
Intel Windows drivers, this seems to lead to visual corruptions
(#141436, #141173). While a more graceful handling of a mismatch may
be nice, this is in line with the OpenGL specs.

This PR adds code for validating image formats for bindings.

Pull Request: https://projects.blender.org/blender/blender/pulls/143791
2025-08-27 15:43:09 +02:00
Jeroen Bakker
f82e89183e Fix #142110: Vulkan: Only last planar probe is visible
When using multiple planar probes only the last one would
be visible. The other probes would use the world probe.

Reason is that the data of planar probes are stored in
layered textures. When updating planar probes framebuffers
are created with the correct layer attached.

Vulkan backend missed some code paths to clear a single layer
when clearing a framebuffer where the previous action had depth
write disabled. This PR adds the missing code path.

Pull Request: https://projects.blender.org/blender/blender/pulls/145170
2025-08-26 14:18:47 +02:00
Clément Foucault
1f2c906e2a GPU: Shader: Always mute line directives for GLSL
This is motivated by the latest changes to the preprocessor
which outputs a lot of line directives when code is
generated or unrolled.

In this case the reported line would be correct but not
correctly displayed.

Moreover the system of outputing hashes inside the
`#line` directive proved to be incompatible with some
compilers and tools (renderdoc).

This commit always comments the line directives before
compilation (solves the compatibility issue).
When error logging, we then scan the commented
directives to output the correct filename and source
line. The log line is kept untouched and will show
the correct final generated code that triggered the
error.

This also fixed the error line parsing for vulkan.

Pull Request: https://projects.blender.org/blender/blender/pulls/145096
2025-08-26 12:46:46 +02:00
Jeroen Bakker
0a2c84d48d Fix #144771: Vulkan: Object outlines and workbench transparency
Workbench transparency outlines where not working. The cause was that
the incorrect texture was bound in the pipeline due to unused
attachments being removed from the pipeline.

It seems to be an error since we added render pass support. This support
has already been removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/145120
2025-08-26 10:08:08 +02:00
Jeroen Bakker
32a812682c Fix #144625: Vulkan: Blacklist NVIDIA 580.76.05 on Linux
This PR disables support for NVIDIA 580.76.05 drivers as it can hang
on startup with Wayland. There are reports from other applications
that this driver is faulty and NVIDIA confirmed that an updated driver
is in the making.

For now we will blacklist this specific driver on any Linux system.

Pull Request: https://projects.blender.org/blender/blender/pulls/145094
2025-08-25 12:28:16 +02:00
Jeroen Bakker
98b4c3e252 Cleanup: Remove obsolete comment 2025-08-25 09:23:32 +02:00
Jeroen Bakker
e24e58f293 Vulkan: Recycle descriptor pools
This PR adds recycling of descriptor pools. Currently descriptor pools
are discarded when full or context is flushed. This PR allows
descriptor pools to be discarded for reuse.
It is also more conservative and only discard
Descriptor pools when they are full or fragmented.

When using the Vulkan backend a small amount of descriptor memory can leak. Even
when we clean up all resources, drivers can still keep data around on the
GPU. Eventually this can lead to out of memory issues depending on how
the GPU driver actually manages descriptor sets.

When the descriptor sets of the descriptor pool aren't used anymore
the VKDiscardPool will recycle the pools back to its original VKDescriptorPools.
It needs to be the same instance as descriptor pools/sets are owned by
a single thread.

Pull Request: https://projects.blender.org/blender/blender/pulls/144992
2025-08-22 17:11:26 +02:00
Jeroen Bakker
0ea1feabd9 Vulkan: HDR support for Windows
This PR adds HDR support for Windows for `VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT`
on `VK_FORMAT_R16G16B16A16_SFLOAT` swapchains .

For nonlinear surface formats (sRGB and extended sRGB) the back buffer is blit into the swapchain,
When VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT is used as surface format a compute shader
is used to flip and invert the gamma.

SDR white level is updated from a few window event changes, but actually
none of them immediately respond to SDR white level changes in the system.
That requires using the WinRT API, which we don't do so far.

Current limitations:
- Intel GPU support
- Dual GPU support

In the future we may add controls inside Blender for absolute HDR nits,
across different platforms. But this makes behavior closer to macOS.

See !144565 for details

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/144717
2025-08-22 10:11:55 +02:00
Jeroen Bakker
bca70c85e7 Cleanup: struct initializers 2025-08-21 12:27:19 +02:00
Jeroen Bakker
3b295618f8 Fix #144614: Vulkan: Disable optimization for large shaders
This is a workaround for an issue in SPIRV-Optimizer. When optimizing
large shaders the optimizer can crash. This can be fixed by altering the
maximum object ids and performing a compact ids in the end. However this
part of the API is not accessible via ShaderC.

To work around the issue shader optimizations are being disabled for
large shaders. The issue has been reported upstream.

Pull Request: https://projects.blender.org/blender/blender/pulls/144774
2025-08-21 09:14:56 +02:00
Jorn Visser
0f8eb1b944 Fix: Vulkan: Submission runner crash on start
In `init_submission_pool`, the submission runner was started before
initializing the queues it uses, leading to a race condition that could
result in a crash.

Pull Request: https://projects.blender.org/blender/blender/pulls/144795
2025-08-21 09:06:23 +02:00
Jeroen Bakker
43a2bfa9c3 Vulkan: Add assert for potential driver crash
Pull Request: https://projects.blender.org/blender/blender/pulls/144782
2025-08-21 07:35:15 +02:00
Clément Foucault
2f2ff44e56 GPU: Shader: Remove legacy creation API
This API is no longer used for 5.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/144819
2025-08-20 09:25:32 +02:00
Clément Foucault
869fc2cf4e GPU: Shader: Add Shared Variable in shader create info
This allows to control the type of data inside the create infos for
easy variation of the same shader.

Also this wraps the last global shader resource usage for the future
SRD.

Pull Request: https://projects.blender.org/blender/blender/pulls/144769
2025-08-19 18:27:49 +02:00
Jeroen Bakker
066280446c Vulkan: Enable maintenance4 in VMA
VK_KHR_maintenance4 is enabled when available. VMA isn't aware that we
enabled it and could still use less optimized code-paths. This PR will
inform VMA that it can use the optimized code-paths.

The improvement is that we can decide in which memory area a specific
resource will be allocated, without the need of allocating the resource
header (VkImage/VkBuffer).

Pull Request: https://projects.blender.org/blender/blender/pulls/144552
2025-08-18 09:52:08 +02:00
Jeroen Bakker
ea633b930f Fix #143989: Vulkan: Text drawing performance
Text drawing can be improved. At this moment a vertex buffer is
allocated for 2048 chars. When drawing a string the vertex buffer is
filled from the beginning with the string to draw. The next string will
replace the chars of the previous string. This locks up GPUs as the data
can only be overwritten when the buffer isn't used anymore.

Vulkan backend had an issue that uploading the new data would always
send over 2048 chars even when some chars were only used. By fixing this
the scene in the report went from 0.6 fps to 2.6 fps. OpenGL is 6 fps as
vulkan has to manage a rendergraph with 100.000 of nodes.

Text drawing performance can be improved by continue using the space of
the vertex buffers. In this case more drawing calls can be done, before
the vertex buffer needs to be updated.

Pull Request: https://projects.blender.org/blender/blender/pulls/144604
2025-08-15 10:36:27 +02:00
Jeroen Bakker
1f1098c498 Vulkan: Remove MoltenVK
Blender had some support for using MoltenVK. However there are some key
issues why MotlenVK cannot be used. Bugs have been reported up-stream.
As it doesn't work and holds back regular developments it will be removed
from the main branch.

Any efforts on making Vulkan run on Apple (including KosmicKrisp)
is considered a community effort and can be done in a development
branch.

Pull Request: https://projects.blender.org/blender/blender/pulls/144602
2025-08-15 09:36:38 +02:00
Jeroen Bakker
7286885789 Vulkan: Update VMA to 3.3.0
Updated to latest release. Has some fixes and a new API for easy
integration with Volk.

Pull Request: https://projects.blender.org/blender/blender/pulls/144434
2025-08-14 13:20:45 +02:00
Christoph Neuhauser
1384bad2d2 GPU: Add flag for shader debug info generation
This PR proposes to add a new flag `--shader-debug-info` that enables the generation of shader debug information.

I created this PR as WIP due to the following reasons:
- Currently it only works for the Vulkan backend. I do not know if it makes sense for other backends. For example, OpenGL directly receives the GLSL code, so there no need for this might exist.
- So far `--debug-gpu-renderdoc` already turns on the following changes for GLSL shader compilation with shaderc:
```
options.SetOptimizationLevel(shaderc_optimization_level_zero);
options.SetGenerateDebugInfo();
```
- While combining optimization level zero with debug info is a sensible choice for frame debuggers like RenderDoc, my use case for creating this PR is shader profiling. In this case, one does not want compiler optimizations to be turned off. At the current point in time, the only information my profiler uses (which is unfortunately not public at this point in time) is the name of the shader. When turning on debug information, shaderc/glslang store this information in the generated SPIR-V data. Otherwise, it would be impossible for the profiler to tell the user what the name of the shader it is that is profiled.
- An alternative solution would be to rename the entry point `main` of a shader to the name of the shader. But this might be an even uglier hack, as it requires editing the source code (and the name of the shader then needs to be a valid GLSL function name).
- We should first clarify if there is interest in the Blender side in upstreaming an option like this. While I could just keep this in my local fork of Blender, there is merit in having the possibility to profile arbitrary Blender builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/142986
2025-08-13 13:41:41 +02:00
Jeroen Bakker
ea83567811 Vulkan: Destroy resources in submission thread
This PR moves the responsibility of destroying discarded resources to
the submission thread. Previous implementation could be blocked and
would not always run.

This solves memory leak when rendering in background and keeps the
overall memory usage lower as all is done in a single location.

Pull Request: https://projects.blender.org/blender/blender/pulls/144440
2025-08-12 15:58:49 +02:00
Clément Foucault
cae6c6d81a GPU: Remove Shader Draw Parameter workaround
With 5.0 we start requiring this extension for GL and VK.
All of our target hardware supports it with up to date
drivers.

Some old drivers were disabling this extension because of
buggy behavior. We simply drop support for them in 5.0.

This allows us to remove a lot of code and the last
shader create info override done at startup. This will
unlock more refactoring of the shader create info into
static classes to reduce binary size and other benefits.

## TODO:
- [x] Remove checks for ARB_shader_draw_parameters
- [x] Remove checks for ARB_clip_control
- [x] Check for the extension on startup for OpenGL
- [x] Check for the extension on startup for Vulkan
- [x] ~~Add user facing popup message about minimum
      requirements not being met.~~ Done using the same
      popup as old hardware.

Pull Request: https://projects.blender.org/blender/blender/pulls/142334
2025-08-12 14:04:41 +02:00
Jeroen Bakker
42c3f35780 Vulkan: Swap to system memory for device local memory
This PR will swap device local memory to system ram. It relies on
VK_EXT_external_memory and VK_EXT_pageable_device_local_memory
extensions to be supported by the system.

Most platforms support these extensions.

Pull Request: https://projects.blender.org/blender/blender/pulls/144422
2025-08-12 11:51:40 +02:00
Jeroen Bakker
3b8ea045da Vulkan: Disable descriptor buffers
There are stability issues with the vulkan backend. Some scenes indicate
that there is no space left to allocate the next descriptor buffer. For
stability reasons we will disable descriptor buffers and look into a
better solution.

Pull Request: https://projects.blender.org/blender/blender/pulls/144421
2025-08-12 10:28:28 +02:00
Campbell Barton
c00dfded27 Cleanup: consistently hyphenate the term "swap-chain" 2025-08-12 10:12:19 +10:00
Clément Foucault
7a97105b28 GPU: Remove wrapper type for gpu::StorageBuf
This is the first step into merging DRW_gpu_wrapper.hh into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/144329
2025-08-11 10:35:53 +02:00
Clément Foucault
1388a70914 GPU: Remove wrapper type for gpu::Shader
This is the first step into merging DRW_gpu_wrapper.hh into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/144229
2025-08-11 09:34:28 +02:00
Jeroen Bakker
06b32f6c1d Vulkan: Add assert to check valid API usage
Related to #143691.
2025-08-11 09:08:04 +02:00
Jeroen Bakker
e408029d5b Cleanup: Vulkan: Remove not needed code.
Would never have anything to report. Can be added back when there are
validation messages added.
2025-08-08 11:10:38 +02:00
Jeroen Bakker
073b4d4d7b Fix #144048: Vulkan: Crash minimized windows
Swapchain handling of minimized windows wasn't correct. On some
platforms it still tried to create images with no surface.

This PR will discard swapchains of minimized windows, but still being
able to flush the render graph and free resources.

Pull Request: https://projects.blender.org/blender/blender/pulls/144189
2025-08-08 11:03:02 +02:00