Commit Graph

6372 Commits

Author SHA1 Message Date
Clément Foucault
aa95220576 Metal: Add workaround for imageAtomic synchronization issue
A compiler/driver bug makes so that we can't rely on image atomics.

Adding a write that is never executed after the atomics tricks
the compiler to issue the correct synchronisation instruction.

This fixes a bunch of our render tests differences.

We will keep this workaround until this is fixed upstream.

Pull Request: https://projects.blender.org/blender/blender/pulls/146442
2025-09-22 11:45:27 +02:00
Clément Foucault
fb3904ce45 GPU: Shader Codegen: Split different graph includes
This allows to reduce the number of includes for each
tree graph (surface, volume, displacement) and
reduce the code size significantly for most vertex
shaders, speeding up compile time.

Rel #145347

Pull Request: https://projects.blender.org/blender/blender/pulls/146419
2025-09-22 10:24:10 +02:00
Brecht Van Lommel
c2e5622d50 Revert "Shaders: Remove old Preetham and Hosek sky texture models"
These are causing quite a big difference in existing files, which is not
easy to address in versioning. Since the goal of removing this was to
simplify things for us and that's not the case, just revert this change.

This reverts commit ab21755aaf.

Ref #139923

Pull Request: https://projects.blender.org/blender/blender/pulls/146336
2025-09-20 16:52:23 +02:00
Clément Foucault
36151962d6 Cleanup: GL: Remove unused AMD workaround
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/146404
2025-09-17 14:23:32 +02:00
Clément Foucault
9d0fe5573b GPU: FrameBuffer: Remove GPUFrameBuffer wrapper opaque type
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/146372
2025-09-16 17:50:48 +02:00
Clément Foucault
ecc495ac39 EEVEE: Optimize Principled BSDF compilation time
This removes unused closure branches in the principled BSDF
code using the Material flags.

On top of this, use constants for weights to use compiler
dead code eliminitation for unused branches when there
is different variants of the principled BSDF node used.

Finally, remove Gbuffer packing cases that are not present
inside the nodetree.

Testing with the same setup as #145347:
|          | main (ms) |  PR (ms) |   Delta (ms) |
| -------- | ----------- | ------------ |------------ |
| Nvidia   |         174 |  132 (1.31x) |          42 |
| Mesa AMD |         191 |  170 (1.12x) |         21 |

Barbershop compilation time is almost equal because it is not using
the principled BSDF.

Rel #145347

Pull Request: https://projects.blender.org/blender/blender/pulls/146324
2025-09-16 16:44:01 +02:00
Clément Foucault
9bbbd833b2 Fix: Material: Compilation error for GPU material using voronoi node
This was caused by a wrong include.
2025-09-16 14:50:03 +02:00
Jeroen Bakker
47fc709987 Fix #146313: Vulkan: Memory leak HDR backbuffer shader
Oversight in !146170 where shader pointers where overwritten each
frame. Should also be a performance regression.

Pull Request: https://projects.blender.org/blender/blender/pulls/146319
2025-09-15 21:01:25 +02:00
marcopavanello
084aefd0e0 Render: Add Multiple Scattering Sky Texture
This mode is based on the same athmospheric model as the previous one, but now
also accounts for multiple scattering and reflections from the ground.
This increases the accuracy, especially at low elevations.

Also renames some options for consistency:
- The previous "Nishita" model is now "Single Scattering"
- "Dust" is now "Aerosols"
- Default altitude is now 100m.

Co-authored-by: Lukas Stockner <lukas@lukasstockner.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/140480
2025-09-15 18:08:28 +02:00
Clément Foucault
50283b9573 GPU: Split GLSL, C++ and metal shader defines
This makes all the defines and boiler plate code use
the generated source include system.

This makes source hierarchy more understandable.

Pull Request: https://projects.blender.org/blender/blender/pulls/146289
2025-09-15 17:22:19 +02:00
Jeroen Bakker
1dedbe3f9a Fix: Vulkan: VMA validation errors
Fixes several validation errors when using VMA.
- Always enable buffer device address in VMA as it is already a Blender
  requirement.
- Add host access hints when host access is needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/146312
2025-09-15 16:47:26 +02:00
Clément Foucault
680fec144c Cleanup: GPU: Remove prefix 'e' from enum types
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/146034
2025-09-15 15:11:02 +02:00
Clément Foucault
bb8e987904 GPU: Simplify matrix lib to reduce dead code
This greatly reduce shader compilation time on some systems.

Pull Request: https://projects.blender.org/blender/blender/pulls/146100
2025-09-15 12:07:26 +02:00
Campbell Barton
e6c0a204f6 Cleanup: use of doxygen params in doc-strings 2025-09-14 15:15:33 +10:00
Christoph Neuhauser
092affc573 Color Management: Use preprocessor for gamma 2.2 vs piecewise sRGB
The referenced commit introduced the use of gamma 2.2 or piecewise sRGB
for the backbuffer blit depending on the operating system. This commit
switches from a push constant for this to a preprocessor define.

Ref 5d72498154

Pull Request: https://projects.blender.org/blender/blender/pulls/146170
2025-09-12 18:30:25 +02:00
Clément Foucault
f729e639f4 GPU: Simplify Codegen dependency injection
Dependencies were previously merged manually
inside the generated_sources by EEVEE.
This caused issues with double includes.

Instead, we now only gather the name of the
nodetree dependencies and add them to the
dependencies of the `GeneratedSource`.

This also make the compositor use the `GeneratedSource`
mechanism.

Pull Request: https://projects.blender.org/blender/blender/pulls/146106
2025-09-12 16:07:55 +02:00
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