Commit Graph

6319 Commits

Author SHA1 Message Date
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
Jeroen Bakker
8d40ecbf85 Cleanup: GPUFramebuffer variable names
The internal wrap/unwrap functions used vert as variable names. Should
be framebuffer.
2025-08-29 08:59:01 +02:00
Clément Foucault
998655f4d9 Cleanup: Metal: Remove unused struct
This is no longer necessary since we do not use geometry shader
workarounds.
2025-08-28 12:08:42 +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
Miguel Pozo
0cf4d39aa9 GPU: Improve the do_static_compilation_ check coverage (2)
162a24e05d had to be reverted, since it
didn't take into account other types of dynamically generated
`ShaderCreateInfo` (external shaders like OCIO or Python ones).
This just marks `ShaderCreateInfo`s as generated by default and only
sets the ones from gpu_shader_create_info_list as non generated.

Pull Request: https://projects.blender.org/blender/blender/pulls/145128
2025-08-27 20:17:04 +02:00
Clément Foucault
03296e6679 GPU: Remove unused workarounds
The line workaround is no longer necessary since the
shader now uses SSBO and is less likely to have
issues (more tested path).

The source patching is now always done in the GL and VK
backend before compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/145240
2025-08-27 16:01:07 +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
Clément Foucault
fa3355c505 Refactor: GPU: NodeLink shader to remove need of instance attributes
Use SSBO loads instead.

Contains a cleanup pass to bring this shader to current shader
standards.

This removes the non-instance version of the shader as it is
not necessary anymore.

The motivation for this is to remove the instance buffer from
the batch API.

Pull Request: https://projects.blender.org/blender/blender/pulls/145238
2025-08-27 15:24:22 +02:00
Clément Foucault
7becc38a3c GPU: Make text rendering not use instance buffer
Use SSBO loads instead.

Add a new `GlyphQuad` interface.

Note that this reduces the size of glyph batch since the
buffer is always fully uploaded.
Can be improved with partial update later on if that causes
significant performance regression.

The motivation for this is to remove the instance buffer from
the batch API.

Pull Request: https://projects.blender.org/blender/blender/pulls/145225
2025-08-27 14:52:19 +02:00
Clément Foucault
ba4589e894 DRW: New Curve Drawing
Implementation of the design task #142969.

This adds the following:
- Exact GPU interpolation of curves of all types.
- Radius attribute support.
- Cyclic curve support.
- Resolution attribute support.
- New Cylinder hair shape type.
![image.png](/attachments/a8e7aea0-b0e5-4694-b660-89fb3df1ddcd)

What changed:
- EEVEE doesn't compute random normals for strand hairs anymore. These are considered legacy now.
- EEVEE now have an internal shadow bias to avoid self shadowing on hair.
- Workbench Curves Strip display option is no longer flat and has better shading.
- Legacy Hair particle system evaluates radius at control points before applying additional subdivision. This now matches Cycles.
- Color Attribute Node without a name do not fetch the active color attribute anymore. This now matches Cycles.

Notes:
- This is not 100% matching the CPU implementation for interpolation (see the epsilons in the tests).
- Legacy Hair Particle points is now stored in local space after interpolation.

The new cylinder shape allows for more correct hair shading in workbench and better intersection in EEVEE.

|      | Strand | Strip | Cylinder |
| ---- | --- | --- | --- |
| Main | ![main_strand.png](/attachments/67d3b792-962c-4272-a92c-1c0c7c6cf8de) | ![main_strip.png](/attachments/f2aa3575-368e-4fbb-b888-74df845918f1) | N/A |
| PR   | ![pr_strand.png](/attachments/cc012483-25f0-491f-a06e-ad3029981d47) | ![pr_strip.png](/attachments/73fa2f5c-5252-4b30-a334-e935ed0fb938) | ![pr_cylinder.png](/attachments/3133b2d4-a6f2-41ee-8e2d-f6fd00db0c8d) |

|      | Strand | Strip | Cylinder |
| ---- | --- | --- | --- |
| Main | ![main_strand_closeup.png](/attachments/730bd79c-6762-446d-819b-3ea47961ff9f) |![main_strip_closeup.png](/attachments/d9ace578-cfeb-4895-9896-3625b6ad7a02) | N/A |
| PR   | ![pr_strand_closeup.png](/attachments/ac8f3b0c-6ef6-4d54-b714-6322f9865036)|![pr_strip_closeup.png](/attachments/8504711a-955b-4ab2-aa3d-c2d114baf9d4)| ![pr_cylinder_closeup.png](/attachments/1e2899a8-0a5c-431f-ac6c-5184d87e9598) |

Cyclic Curve, Mixed curve type, and proper radius support:
![image.png](/attachments/7f0bf05e-62ee-4ae9-aef9-a5599249b8d7)

Test file for attribute lookup: [test_attribute_lookup.blend](/attachments/1d54dd06-379b-4480-a1c5-96adc1953f77)

Follow Up Tasks:
- Correct full tube segments orientation based on tangent and normal attributes
- Correct V resolution property per object
- More attribute type support (currently only color)

TODO:
- [x] Attribute Loading Changes
  - [x] Generic Attributes
  - [x] Length Attribute
  - [x] Intercept Attribute
  - [x] Original Coordinate Attribute
- [x] Cyclic Curves
- [x] Legacy Hair Particle conversion
  - [x] Attribute Loading
  - [x] Additional Subdivision
- [x] Move some function to generic headers (VertBuf, OffsetIndices)
- [x] Fix default UV/Color attribute assignment

Pull Request: https://projects.blender.org/blender/blender/pulls/143180
2025-08-27 09:49:43 +02:00
Clément Foucault
1f3971cae9 Revert "Cleanup: GPU: Remove unused shader library guards"
This reverts commit 05115b0f88.

Material shaders do not compile after this change
2025-08-26 15:39:13 +02:00
Clément Foucault
06ddc55846 Cleanup: GPU: Fix french spelling of Dictionary
...baguette?
2025-08-26 15:38:33 +02:00
Hans Goudey
36222be528 Cleanup: Formatting 2025-08-26 09:33:43 -04:00
Clément Foucault
05115b0f88 Cleanup: GPU: Remove unused shader library guards
Nowadays every shader uses the new include system and
there is no need for these manual double include guards.
2025-08-26 15:11:35 +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
Aras Pranckevicius
a52bed7786 VSE: Do Scopes on the GPU, improve their look, HDR for waveform/parade
Faster and better looking VSE scopes & "show overexposed". Waveform &
RGB Parade now can also show HDR color intensities. (Note: this is
only about VSE scopes; Image Space scopes are to be improved separately)

- Waveform, RGB Parade, Vectorscope scopes are done on the GPU now, by
  drawing points for each input pixel, and placing them according to
  scope logic. The point drawing is implemented in a compute shader,
  with a fragment shader resolve pass; this is because drawing lots of
  points in the same location is very slow on some GPUs (e.g. Apple).
  The compute shader rasterizer is several times faster on regular
  desktop GPU as well.
- If a non-default color management is needed (e.g. VSE colorspace is
  not the same as display colorspace, or a custom look transform is used
  etc. etc.), then transform the VSE preview texture into display space
  RGBA 16F texture using OCIO GPU machinery, and calculate scopes
  from that.
- The "show overexposed" (zebra) preview option is also done on the
  GPU now.
- Waveform/Parade scopes unlock zoom X/Y aspect for viewing HDR scope,
  similar to how it was done for HDR histograms recently.
- Added SEQ_preview_cache.hh that holds GPU textures of VSE preview,
  this is so that when you have a preview and several scopes, each of
  them does not have to create/upload their own GPU texture (that would
  both waste memory, and be slow).

Screenshots and performance details in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/144867
2025-08-26 12:25:43 +02:00
Clément Foucault
505e4fc3ae GPU: Shader: Add support for templated struct
This does a few things:
- Add support for templated struct.
- Change parsing of template scope.
  Now all template scope `<..>` are parsed properly.
- Rework to support better match syntax.
- Avoid warning from scope guard processing. Now initialize
  the return value to zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/145132
2025-08-26 10:10:43 +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
Miguel Pozo
9f59a36181 Revert "GPU: Improve the do_static_compilation_ check coverage"
This reverts commit 162a24e05d.

Needs testing.
There are asserts triggering on startup.
2025-08-25 16:31:43 +02:00
Miguel Pozo
cb9116f58a Fix #145017: EEVEE: Performance regression with Drivers in Shaders
Make the optimization_delay per-pass.
Lower the optimization pass GC collect rate.

Pull Request: https://projects.blender.org/blender/blender/pulls/145114
2025-08-25 15:56:35 +02:00
Miguel Pozo
162a24e05d GPU: Improve the do_static_compilation_ check coverage
Since we use StaticShader now in many places, the check is often
bypassed.

Ensure that any compiled shader is either marked as static or as a
GPUPass.

Pull Request: https://projects.blender.org/blender/blender/pulls/144950
2025-08-25 15:55:26 +02:00
Clément Foucault
87fe13fb7b Fix: EEVEE: Avoid Valgrind issues
Running valgrind on a render test exhibit a lot of warnings
about `Conditional jump or move depends on uninitialised value(s)`.

This patch makes sure to initialize the memory to avoid
platform dependent bugs.

Pull Request: https://projects.blender.org/blender/blender/pulls/144995
2025-08-25 14:05:50 +02:00
Miguel Pozo
e0a82933ab Cleanup: Remove unused code 2025-08-25 12:43:28 +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
Campbell Barton
85d5ade00f Cleanup: spelling in comments (make check_spelling_*) 2025-08-24 06:26:08 +00: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
Brecht Van Lommel
b0d52c528b Color Management: Remove "High Dynamic Range" setting
This was a temporary solution until we had proper HDR displays.

* Auto detect from the display + view transform if they are HDR, and
  enable it automatically. This is based on encoding hdr-video in the config.
* If a HDR transform is selected and there is no HDR display support, an
  info message will be shown in the color management panel.
* It is now possible to view HDR images in the image editor, without
  needing to use "View as Render".
* There is no versioning to switch to a HDR display, because that also
  affects image saving. So users will have to manually select the
  "Rec.2100 PQ" display to see HDR colors again.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/144565
2025-08-21 15:25:06 +02:00
Brecht Van Lommel
62485a760f Color Management: Wide gamut display
* Change meaning of display device to be the device that we are trying
  to emulate, not the monitor configuration.
* The display transform is now:
 * User specified view and display transform
 * Clamp to 0 to limit colors to gamut
 * Inverse untonemapped display transform
 * Convert to extended sRGB
* When using the display space in the color management API, it now needs to
  be specified if it's for drawing (with emulation) or file output or color
  inspection (without).

Like HDR, this only works on macOS and Linux + Wayland + Vulkan currently.
Support for Windows/Vulkan is under development in #144717.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/144565
2025-08-21 15:25:01 +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
Campbell Barton
b1cd0ff91e Cleanup: add missing headers to source lists 2025-08-21 17:09:18 +10: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
Clément Foucault
e05089362c GPU: Shader: Add support for enum class
In the process, refactor the enum processing
using the new parser.

Pull Request: https://projects.blender.org/blender/blender/pulls/144704
2025-08-18 13:50:49 +02:00
Clément Foucault
dce0fa115f GPU: Shader: Preprocess: Improve error reporting
This makes the new parser code output correct errors.

Also simplify error logging.

Simplify a few things inside the parser interface.
Add debug string to the `Token` and `Scope`.

Pull Request: https://projects.blender.org/blender/blender/pulls/144708
2025-08-18 12:02:26 +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
Campbell Barton
ebfa7edeb1 Cleanup: use snake case, replace "m_" prefix with "_" suffix
Follow our own C++ conventions for GHOST.
2025-08-16 16:14:18 +10:00
Clément Foucault
3c3f21ec00 GPU: Shader: Replace template macro implementation by copy paste
Use the lately introduced parser for that.

This allows to use preprocessor directive inside them.
By extension, it alows having resource accessors inside
templates.
Also error report is less confusing on most shader compilers.

The counterpart is that the shader files that are shipped
with blender are inflated.

Pull Request: https://projects.blender.org/blender/blender/pulls/144588
2025-08-15 15:13:54 +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
Clément Foucault
13d25a5cfc GPU: Shader: Fix parser not being consistent
Using `std::sort` does not garantee the initial
order is kept for items with the same ranking value.

Using `std::stable_sort` fixes the issue.
2025-08-14 20:43:25 +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
Campbell Barton
5540b9440a CLI: move VSync from an environment variable to an argument
Add a command line argument --gpu-vsync on/off/auto.

Prefer command line arguments for GPU settings,
as it means the value is error checked and set when Blender starts.

Also refactor GHOST_Context to take a parameter argument which
includes the stereo-visual & debug arguments and includes the newly
added vsync setting. This makes it possible to add GPU context
parameters more easily in the future.

It also removes redundant parsing & setting the VSync setting for
off-screen contexts.

Changes to recent PR !143049.

Ref !144473
2025-08-14 05:16:12 +00:00