Commit Graph

6356 Commits

Author SHA1 Message Date
Clément Foucault
e19e9e57ee EEVEE: Split eevee_shader_shared.hh into multiple files
The goal of this patch is to reduce final shader code footprint to
hopefully reduce shader compile time (see #145347).

This also contains a pass over most shader file to remove unused
include or use more granular ones to reduce final shader code
length.

Testing with the same setup as #145347:
|          | main (ms) |  PR (ms) |   Delta (ms) |
| -------- | ----------- | ------------ |------------ |
| Nvidia   |         257 |  207 (1.24x) |         50 |
| Mesa AMD |         323 |  295 (1.09x)    |        28 |

In barbershop test scene however the saving are not so noticeable:
|          | main (s) |  PR (s) |   Delta (s) |
| -------- | ----------- | ------------ |------------ |
| Nvidia (OpenGL)  |         40 |  39 (1.02x) |         1 |
| Nvidia (Vulkan)   |         29 |  29 (1.0x) |         0 |

Pull Request: https://projects.blender.org/blender/blender/pulls/145803
2025-09-12 14:09:35 +02:00
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
134110b87f Cleanup: sort file lists 2025-09-12 10:20:40 +10: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
Clément Foucault
1f94af6aa4 GPU: Shader: Add support for loop unroll using macros
It is usually nice to unroll loops with a different number of
iteration based on a macro. This commit adds this functionality
to our shader preprocessor so that we don't have to manually unroll
these loops.

Pull Request: https://projects.blender.org/blender/blender/pulls/146043
2025-09-11 12:42:11 +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
9c9757e52b Cleanup: GPUFence parameter names
Renamed incorrect naming pixbuf->fence

Pull Request: https://projects.blender.org/blender/blender/pulls/146065
2025-09-11 10:36:00 +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
Clément Foucault
6148d50105 GPU: Shader: Remove section of code guarded by #if directives
These lines can be removed to avoid parsing them.
This allow to keep the same processing for shared host files.

Also removes a few lines of code to reduce the size of
shader sources.

This also contains a rewrite of the include parsing using
the shader parser.

Pull Request: https://projects.blender.org/blender/blender/pulls/146025
2025-09-10 16:35:41 +02:00
Clément Foucault
19fb5652af Cleanup: GPU: Avoid warning in shader parser code 2025-09-10 12:48:31 +02:00
Clément Foucault
b3dec6617a Fix: GPU: Avoid accessing GLContext after it is destroyed
This error showed up inside an ASAN build.

Candidate for backporting in 4.5 as this can happen when simply
rendering with EEVEE or Workbench.

Pull Request: https://projects.blender.org/blender/blender/pulls/146017
2025-09-10 12:17:43 +02:00
Clément Foucault
c302b7de7b Refactor: EEVEE: Simplify Gbuffer packing
Implementation of #145417

For more information see pull request.

Pull Request: https://projects.blender.org/blender/blender/pulls/145520
2025-09-10 12:17:21 +02:00
Clément Foucault
805e037df3 GPU: Shader: Use parser for loop unrolling
This refactor the loop unrolling mechanism and
replaces the use of regex by the new parser.

Pull Request: https://projects.blender.org/blender/blender/pulls/145956
2025-09-10 11:59:52 +02:00
Jacques Lucke
32c301e3cf Shader Nodes: support repeat zones, closures and bundles
This adds a function that can turn an existing `bNodeTree` into an inlined one.
The new node tree has all node groups, repeat zones, closures and bundles
inlined. So it's just a flat tree that ideally can be consumed easily by render
engines. As part of the process, it also does constant folding.

The goal is to support more advanced features from geometry nodes (repeat zones,
etc.) in shader nodes which the evaluator is more limited because it has to be
able to run on the GPU. Creating an inlined `bNodeTree` is likely the most
direct way to get but may also be limiting in the future. Since this is a fairly
local change, it's likely still worth it to support these features in all render
engines without having to make their evaluators significantly more complex.

Some limitations apply here that do not apply in Geometry Nodes. For example,
the iterations count in a repeat zone has to be a constant after constant
folding.

There is also a `Test Inlining Shader Nodes` operator that creates the inlined
tree and creates a group node for it. This is just for testing purposes.

#145811 will make this functionality available to the Python API as well so that
external renderers can use it too.
2025-09-09 16:15:43 +02:00
Clément Foucault
79f3c5266a Fix: GL: Missing version parsing for Linux AMD Pro GL implementation
This avoid using the workaround on known working drivers.

Detected when investigating shader compilation performance.
These new drivers where forced to not use threaded compilation.

Candidate for backport to 4.5 LTS.

Pull Request: https://projects.blender.org/blender/blender/pulls/145969
2025-09-09 14:10:26 +02:00
Clément Foucault
18d3f0a1a5 Fix #145651: GPU: Memoryleak drawing node links
The link buffer was not free on exit.
Previous implementation was freing it with the
gpu::Batch which is registered as preset.
This commit introduces buffer registration
to free them on exit.

Pull Request: https://projects.blender.org/blender/blender/pulls/145921
2025-09-09 12:49:32 +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
Brad Smith
c114a1f660 Build: resolve linking error on *BSD systems
Ref !144247
2025-09-02 04:04:20 +00: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
Clément Foucault
62f5965dee Fix: GPU: Compilation failure on windows 2025-09-01 12:38:13 +02:00
Clément Foucault
e7bcec779d GPU: Shader: Use parser for namespace_mutation
Pull Request: https://projects.blender.org/blender/blender/pulls/145496
2025-09-01 11:56:03 +02:00
Clément Foucault
d47ad68b0c GPU: Shader: Use parser for using_mutation 2025-09-01 11:56:02 +02:00
Clément Foucault
278438e504 GPU: Shader: Use parser for assert processing 2025-09-01 11:56:02 +02:00
Clément Foucault
ebf095a4b9 GPU: Shader: Add string parsing and merging
This avoid issues when trying to use printf with
multiline string literals.
2025-09-01 11:56:02 +02:00
Clément Foucault
72e5d5066a GPU: Shader: Fix template in template support
Processing needed to be adapted to support this
use case.
2025-09-01 11:56:02 +02:00
Clément Foucault
13329ad984 Metal: Workaround broken shader log
Disable shader log parsing for now as
it conflicts with the `#line` directives
added during preprocessing.

Pull Request: https://projects.blender.org/blender/blender/pulls/145495
2025-09-01 10:53:25 +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
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