Commit Graph

5488 Commits

Author SHA1 Message Date
Falk David
30adc33730 Fix #128827: GPv3: Bucket fill doesn't work on macOS
The issue was that the shader `gpu_shader_gpencil_stroke_vert_no_geom.glsl`
assumed a wrong format of the color attribute (`uchar4`  instead of `float4`).

The fix uses `vertex_fetch_attribute` with `float4`.

Pull Request: https://projects.blender.org/blender/blender/pulls/129072
2024-10-16 10:29:07 +02:00
Jeroen Bakker
6f6efb6ec0 Vulkan: Disable Intel 10th gen and lower on Windows
Intel Windows drivers for 10th gen and lower has some strange behavior
when using dynamic rendering. It requires pipeline conditions to be met,
when beginning a new rendering scope. This is strange as specs + VVL
notes that these conditions should be met during vkCmdDraw* commands.

Pull Request: https://projects.blender.org/blender/blender/pulls/129055
2024-10-15 13:44:05 +02:00
Jeroen Bakker
cdef54a5ce Vulkan: Workaround for unused attachment extension
This change makes unused attachments extension optional.
This extension is fairly new and not all drivers have support for it.

The workaround will create additional pipelines when attachments are
not set.

Pull Request: https://projects.blender.org/blender/blender/pulls/129046
2024-10-15 13:43:21 +02:00
Jeroen Bakker
ceb61ac921 Fix: Vulkan: Strict extension test
VK_EXT_dynamic_rendering_unused_attachments is required for correct working.
Renderdoc hides this extension, but most platforms do work. However the
Windows Intel driver crashes when using iGPUs; they don't support this
extension at all.

This change does a more strict extension test so drivers that do not
support this extension will fallback to OpenGL. When using renderdoc it
is now allowed to compile blender with `WITH_RENDERDOC=On`.

Future developments are needed to add support for Intel iGPUs on
Windows.

Pull Request: https://projects.blender.org/blender/blender/pulls/128986
2024-10-14 15:43:41 +02:00
Jeroen Bakker
d35cd15e12 Fix #128608: Vulkan: Sync issues when sharing context between threads
Resources are shared, when running multiple contexts on the same thread.
Cycles uses the same context on multiple threads and expected same resources.

This change will introduce a single render graph per context and an updated
resource management. Render graphs are not shared anymore; Resource pools
are still shared, but garbage collection depends on the thread and if
background rendering is used.

Pull Request: https://projects.blender.org/blender/blender/pulls/128983
2024-10-14 15:42:46 +02:00
Jeroen Bakker
fb862d082a Fix: Vulkan: Sync issue command buffers
Cycles uses multiple threads to send commands to the GPU. The current
command buffer structure assumed that all commands from the same context
were send via the same thread. This wasn't the case and could lead to
recording commands to command buffers that are still pending (preparing
commands to send to GPU).

This is fixed by creating a command buffer each time a render graph
submits its work.

Detected when researching #128608

Pull Request: https://projects.blender.org/blender/blender/pulls/128978
2024-10-14 15:41:30 +02:00
Jeroen Bakker
3b7dd61e01 Fix: Vulkan: Incorrect Host Visibility Allocation
When allocating a host visible buffer it could be that the returned
buffer was not host visible and access to the buffer would write to
unallocated memory.

Detected when researching #128608

Pull Request: https://projects.blender.org/blender/blender/pulls/128977
2024-10-14 15:39:27 +02:00
Jeroen Bakker
acb205763e Fix: Vulkan: Cycles CPU Synchronization
When using cycles in the viewport there it uses render threads and
workers to update the viewport. All threads can record commands to the
queue and needs to be synchronized. This didn't happen leading to
incorrect renders.

Detected when researching #128608

Pull Request: https://projects.blender.org/blender/blender/pulls/128975
2024-10-14 15:38:22 +02:00
Jeroen Bakker
af151e89a7 Fix: Vulkan: Unguarded Access Device Queues
Multiple threads can access the same device queue from different
threads. This could happen when doing a cycles preview render, baking
eevee volume probes or generating material previews.

This PR adds a mutex around access to the device queues.

Detected when researching #128608

Pull Request: https://projects.blender.org/blender/blender/pulls/128974
2024-10-14 15:30:11 +02:00
Jeroen Bakker
9bcba25bc2 Fix #128282: EEVEE: Unable to compile displacement
When using vertex displacement EEVEE didn't compile the generated
functions into the vertex shader. This could result in errors when
compiling materials.

**Notes**

- Should be back-ported to Blender 4.2

Pull Request: https://projects.blender.org/blender/blender/pulls/128525
2024-10-10 12:16:28 +02:00
Jeroen Bakker
27932162d8 Fix: Cache files location
Adds an additional precheck to identify if the app cache dir is correct.
Reduces placing cache files all over the place when the app dir isn't
correct.
2024-10-08 11:32:41 +02:00
Jeroen Bakker
3cd579208b Vulkan: SPIR-V Caching
Adds a SPIR-V cache that skips frontend compilation for shaders
that are already compiled in a previous run of Blender.

Initially this was postponed to 4.4 but it was observed that
the vulkan backend didn't perform well on Windows in debug
builds. The reason is that the compiler would also be a debug
build which makes compiling a shader really slow. Starting
Blender on a debug build could take minutes.

So the decision was made to give this task a higher priority so
the vulkan backend would become more usable to developers
as well.

The cache is stored in the application cache dir. The SPIR-V
binaries can be used by different Blender versions so there
is no version specific cache folder.

**Sidecar**: SPIR-V files are a stream of bytes. There is no
header information that allow us to validate the stream. To
add basic validations we could add our custom header or
a sidecar. It was chosen to use a sidecar as having the SPIR-V
files unmodified allows us to load them directly in
debug tools for analyzing.

**Retention**: Shaders that are not used are automatically
removed with a retention period of 30 days.

**Shader builder**: Shader builder cannot use the SPIR-V
cache as it uses stubs that returns invalid cache directories.
This would load/save the cache to the location where you
started the build.

Pull Request: https://projects.blender.org/blender/blender/pulls/128741
2024-10-08 10:55:10 +02:00
Campbell Barton
8c3ef77a35 Cleanup: spelling in comments 2024-10-08 09:03:49 +11:00
Clément Foucault
301c853b9c DRW: Rename draw_debug_info.hh to avoid conflict with main branch
Between 0bfd5e3536
and b1cbd9c889
the main branch is incorrectly processing the file
`draw_debug_info.hh` as GLSL and does some string
preprocessing on it. But the output filename matches
the name of the header source file used for compiling
the gpu module. This file not having been updated
since a long time doesn't get copied from the source
folder when switching to other branch and make compilation
fail.

In order to avoid breaking the buildbot longer, we
rename the incriminating file to force recreate it
when building the release branch.
2024-10-07 16:11:09 +02:00
Miguel Pozo
40d20f023a Fix: gpu_shader_create_info_get_unfinalized_copy 2024-10-05 01:22:51 +02:00
Miguel Pozo
6e6e3da454 Workaround: Allow patching CreateInfos at runtime
Temporary workaround for Overlay Next.

Pull Request: https://projects.blender.org/blender/blender/pulls/128452
2024-10-04 19:16:30 +02:00
Miguel Pozo
3a39121a07 Fix: Finalize CreateInfos at startup
Prevents race conditions on ShaderCreateInfo::finalize.
Previoulsy fixed by #128281, but it doesn't work for the render thread.
2024-10-04 19:16:02 +02:00
Jeroen Bakker
4334774a68 Fix: Vulkan: Incorrect image view layer size
When attaching a layered image with offset, the size of the attached
layers should be decreased. Otherwise an image view is created that can
access incorrect data.

Pull Request: https://projects.blender.org/blender/blender/pulls/128583
2024-10-04 14:26:22 +02:00
Jeroen Bakker
7596a08b2c Vulkan: Add back command reordering for buffer updates.
Related to #126974, which removed command reordering due to some
EEVEE/framebuffer requirements. However buffer can still be reordered
without any artifacts.

Update buffers are common operations and are often isolated; safe to
move them outside the rendering scope.

Pull Request: https://projects.blender.org/blender/blender/pulls/128538
2024-10-04 12:11:40 +02:00
Chris Clyne
5a27280916 EEVEE: Light & Shadow linking
This adds feature parity with Cycles regarding light and shadow liking.

Technically, this extends the GBuffer header to 32 bits, and uses
the top bits to store the object's light set membership index.
The same index is also added to `ObjectInfo` in place of padding bytes.

For shadow linking, the shadow blocker sets bitmask is stored per
tilemap. It is then used during the GPU culling phase to cull objects
that do not belong to the shadow's sets.

Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/127514
2024-10-03 18:41:06 +02:00
Jeroen Bakker
52dfb4aa8f Fix #124720: Metal: Crash when trying to allocate large 3d textures
The metal backend assumes that textures can always be allocated. When
metal later detects that the texture cannot be 'baked' it leads to
undesired behavior as Blender think it has a texture with memory
allocated.

This PR only changes the GPU_TEXTURE_3D case as that leads to issues
when loading large voluetric data. Arrayed textures will still fail
as that requires different checks to be added. I rather re-view the
current implementation in the future.

> NOTE: The max depth is hardcoded to 2048

Change should be backported to 4.2

Pull Request: https://projects.blender.org/blender/blender/pulls/128365
2024-10-03 10:11:23 +02:00
Jeroen Bakker
06a4198329 Fix #127274: Vulkan: Incorrect limits.
When using AMD pro-drivers the limits reported of the device can be
`UINT_MAX` but are stored in int fields. In this case the limits would
become negative and GPU materials validation failed resulting into errors.

This is fixed by clamping the value to `INT_MAX`.

Pull Request: https://projects.blender.org/blender/blender/pulls/128437
2024-10-03 10:10:32 +02:00
Alexandre Cardaillac
0315eae536 Cycles: Add more scattering phase functions
Previously, Cycles only supported the Henyey-Greenstein phase function for volume scattering.
While HG is flexible and works for a wide range of effects, sometimes a more physically accurate
phase function may be needed for realism.

Therefore, this adds three new phase functions to the code:
Rayleigh: For particles with a size below the wavelength of light, mostly athmospheric scattering.
Fournier-Forand: For realistic underwater scattering.
Draine: Fairly specific on its own (mostly for interstellar dust), but useful for the next entry.
Mie: Approximates Mie scattering in water droplets using a mix of Draine and HG phase functions.

These phase functions can be combined using Mix nodes as usual.

Co-authored-by: Lukas Stockner <lukas@lukasstockner.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/123532
2024-10-02 11:12:53 +02:00
Miguel Pozo
54ad693486 Fix: Partially revert #128281
Avoid the asserts until we figure out a better design.
2024-10-01 19:55:36 +02:00
Miguel Pozo
ba4c026215 Fix #128164: Race condition in ShaderCreateInfo::finalize()
We can have deferred and non-deferred shaders (so, different threads)
with the same `additonal_info` dependencies trying to finalize the same
`ShaderCreateInfo`.

This ensures `finalize` always runs from the main thread to avoid race
conditions.

Pull Request: https://projects.blender.org/blender/blender/pulls/128281
2024-10-01 15:35:57 +02:00
Jeroen Bakker
4d8581c7ee Vulkan: Add node to update buffers
This change adds the option to update a buffer via the render
graph via `vkCmdUpdateBuffer`. This is only enabled for
uniform buffers as they are small and aligned/sized correctly.

Pull Request: https://projects.blender.org/blender/blender/pulls/128416
2024-10-01 14:22:56 +02:00
Jeroen Bakker
9dfb49d16b Vulkan: Fix incorrect access flag
Detected by latest vulkan validation layers.

Pull Request: https://projects.blender.org/blender/blender/pulls/128417
2024-10-01 14:06:41 +02:00
Jeroen Bakker
71b7dd8079 Vulkan: Remove core 1.2 extensions
Vulkan backend registered extensions that were already part of Vulkan
1.2 core. These extensions don't need to be registered.

Pull Request: https://projects.blender.org/blender/blender/pulls/128408
2024-10-01 13:40:13 +02:00
Kevin Chuang
9f4da19800 Vulkan: Add support for VK_KHR_fragment_shader_barycentric
This PR introduces support for the extension `VK_KHR_fragment_shader_barycentric`,
and includes a few miscellaneous improvements related to it.

1. Add support for `VK_KHR_fragment_shader_barycentric`, if the physical device
  supports it. Otherwise, gpu_BaryCoord is generated through an injected geom
  shader, like it was previously.
2. Simplify the logic of checking has_geometry_stage in vert shader.
3. Fix a potential issue of location mismatch in an injected geom shader.

Related to #127687
Resolves #126228

Pull Request: https://projects.blender.org/blender/blender/pulls/127995
2024-10-01 09:32:59 +02:00
Jeroen Bakker
0eff22dd2a Fix #128258: Vulkan: Memory leak preview job rendering
When performing preview job rendering the memory wasn't recycled leading
to a memory leak. For background rendering we already recycled memory in
a correct way. This change enables the same branch during preview
rendering.

Also adds a better `VKDevice::debug_print` to see the resources being
tracked by the different threads and resource pools.

Pull Request: https://projects.blender.org/blender/blender/pulls/128377
2024-10-01 09:09:42 +02:00
Campbell Barton
c6fd26a3f5 Cleanup: spelling in comments 2024-10-01 09:59:33 +10:00
Clément Foucault
d401b36509 GPU: Metal: Fix background render crash
GHOST_CreateSystemBackground was not being
followed by the now mandatory GPU_backend_ghost_system_set
2024-09-30 14:20:12 +02:00
Jason Fielder
eb3fe75392 Metal: Add support for parallel compilation and precompilation specialisation
This speeds up EEVEE startup and material compilation time.

Authored by Apple: James McCarthy
Pull Request: https://projects.blender.org/blender/blender/pulls/125657
2024-09-30 11:21:28 +02:00
Jeroen Bakker
6ec35c619f Vulkan: Reduce Pipeline Logging
Pipeline pool could log to much information that confused developers who
are not up to date what pipelines are. This PR will hide the confusing
messages. When working on Vulkan these messages can still be shown by
raising the log level.

See !128254

Pull Request: https://projects.blender.org/blender/blender/pulls/128352
2024-09-30 08:46:17 +02:00
Jeroen Bakker
b6aa4a3142 OpenGL: Add Intel HD 405 to limited support.
This rare GPU has z-fighting issues in editor mode. Might be fixable by
changing the bias, but would decrease precision on other platforms as
well. Better to move this GPU to limited support. It is working, just
has some drawing artifacts.

See #128179

Pull Request: https://projects.blender.org/blender/blender/pulls/128351
2024-09-30 08:44:12 +02:00
Jeroen Bakker
481c8fd5a7 Vulkan: Memory leak in immediate mode during exit
When exiting the immediate buffers are discarded, but where not
destroyed making the buffers still leak.
Detected when looking into descriptor set freeze issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/128249
2024-09-27 15:01:10 +02:00
Jeroen Bakker
5250e57294 Fix #127288: Vulkan: Report Marketed Driver Version
A driver (package) installed by the user can have many different drivers
and they can all report a different version. For AMD the version we
reported was from their Vulkan driver. This version isn't useful during
bug triaging.

This PR will use the driver info and driver name from the driver
properties to construct a driver version string that will be used for
reporting.

Pull Request: https://projects.blender.org/blender/blender/pulls/128232
2024-09-27 09:24:15 +02:00
Campbell Barton
33b80415aa Cleanup: use const, correct arg names, spelling, use ELEMN(..) 2024-09-27 11:01:37 +10:00
Jeroen Bakker
725b5027fb Vulkan: Refactor immediate mode
Immediate mode uses the old 'resource tracker' which has been replaced
by swap chain resource pools. This PR optimizes immediate mode buffers
by utilizing resource pools.

Pull Request: https://projects.blender.org/blender/blender/pulls/128188
2024-09-26 16:01:30 +02:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Jeroen Bakker
70313f68ce Vulkan: Log selected device
Currently the log only contained the first compatible device. It is
more important to the user to know which device is used.

This PR increases the level of the first compatible device so it is only
visible when increasing the log level. It reports the device, driver and
vendor when starting blender with `--debug-gpu`.

Pull Request: https://projects.blender.org/blender/blender/pulls/128168
2024-09-26 12:05:09 +02:00
Jeroen Bakker
88b5467e0e Vulkan: Batch Upload Descriptor Sets
Descriptor sets will be uploaded in batch. This allows drivers to
do additional optimizations or at least push some looping to the
driver side.

Pull Request: https://projects.blender.org/blender/blender/pulls/128167
2024-09-26 12:04:09 +02:00
Jeroen Bakker
d75cf2efd4 Vulkan: Refactor resource binding
Resource binding was over-complicated as I didn't understood the state
manager and vulkan to make the correct decisions at that time. This
refactor will remove a lot of the complexity and improves the performance.

**Performance**

The performance improvement is noticeable in complex grease pencil
scenes.

Grease pencil benchmark file picknick:
- `NVIDIA Quadro RTX 6000` 17 fps -> 24 fps
- `Intel(R) Arc(tm) A750 Graphics (DG2)` 6 -> 21 fps

**Bottle-neck**

The performance improvements originates from moving the update entry
point from state manager to shader interface. The previous implementation
(state manager) had to loop over all the bound resources and find in the
shader interface where it was located in the descriptor set. Ignoring
resources that were not used by the shader. But also making it hard
to determine if descriptor sets actually changed. Previous implementation
assumed descriptor sets always changed.

When descriptor set changed a new descriptor set needed to be allocated.
Most drivers this is a fast operation, but on Intel/Mesa this was measurable
slow. Using an allocation pool doesn't fit the Vulkan API as you are only
able to reuse when the layout matches exactly. Of course doable, but requires
another structure to keep track of the actual layouts.

**Solution**

By using the shader interface as entry point we can:
1. Keep track if there are any changes in the state manager. If not and the
   layout is the same, the previous shader can be reused.
2. In stead of looping over each bound resource, we loop over bind points.

**Future extensions**

Bundle all descriptor set uploads just before use. This would be more
in line with how 'modern' Vulkan should be implemented. This PR already
separates the uploading from the updating and technically allows to upload
more than one descriptor set.

Instead of looking 1 set back we should measure if we can handle multiple
or keep track of the different layouts resources to improve the performance
even further.

Optional use `VK_KHR_descriptor_buffer` when available.

Pull Request: https://projects.blender.org/blender/blender/pulls/128068
2024-09-26 10:59:45 +02:00
Jason Fielder
57f7d6380c Fix #126542 Fix UV Edge overlays in Metal
Takes into account any offset that must be added to the vertex index
(usually supplied as baseVertex or startVertex in the Metal draw call)
in the code that emulates the SSBO vertex fetch.

Authored by Apple: James McCarthy

Pull Request: https://projects.blender.org/blender/blender/pulls/127864
2024-09-25 15:22:30 +02:00
Laurynas Duburas
84dedfaf4b Curves: smooth handles
Adds antialiasing to curve's handles and thickness to active ones.
Also handles now react to
 `Preferences > Interface > Display > Resolution Scale` and
`Preferences > Themes > 3D Viewport > Edge Width` as they do in
legacy curves.

Pull Request: https://projects.blender.org/blender/blender/pulls/122910
2024-09-25 15:21:31 +02:00
Campbell Barton
01825a85cb Cleanup: quiet compiler warnings 2024-09-25 20:14:06 +10:00
Vitalijs Komasilovs
2e11331dfc Fix #127286: fixing memory release after light probe bake
GPU resources created during Light probe bake job were added to discard pool, but the pool itself was never notified by worker thread to release resources.
Bake job creates dedicated `GPUContext` for its needs and later deletes it within the same thread.

Pull Request: https://projects.blender.org/blender/blender/pulls/127977
2024-09-24 10:19:49 +02:00
Jeroen Bakker
13fa6d6ae1 Vulkan: Refactor of descriptor set
Removes two levels of indirection when updating descriptor sets.
These are the easy ones to remove. Others will be removed in
a future PR.

This is part of reworking of how descriptor sets are used.
This PR Mostly reduces complexity.

Pull Request: https://projects.blender.org/blender/blender/pulls/127915
2024-09-24 10:03:16 +02:00
Jeroen Bakker
fe18daacda Vulkan: Validation error when using de-interleaved vertex buffers
De-interleaved vertex buffers offsets the attribute in the buffer to
the de-interleaved position. The vertex attribute offset is limited by a
constrained and would raise an error when the buffers just a bit larger.

*VUID-VkVertexInputAttributeDescription-offset-00622*:  offset must
be less than or equal to `VkPhysicalDeviceLimits::maxVertexInputAttributeOffset`

This PR fixes this by offsetting the buffer in stead of the attribute.
Offsetting buffers is limited by the amount of memory.

Pull Request: https://projects.blender.org/blender/blender/pulls/128031
2024-09-23 15:10:57 +02:00
Jeroen Bakker
ddb2179e37 Vulkan: GPU device selection
Allows users to override the auto detection for GPU
selection. Normally the GPU selection is done by looping
over the order Vulkan provides and finding the highest
performing device based on its type (discrete, integrated,
software).

However users might have multiple discrete cards and want
to switch between them. Or developers want to validate other
GPUs without rebooting.

This PR adds the ability to override the auto detection
for the vulkan backend.

![image](/attachments/5d9198a8-af08-4eee-aa73-363edea11cd9)

**Future improvements**:
- This PR does not include a command line option. This can be added
  later for render farms.

Pull Request: https://projects.blender.org/blender/blender/pulls/127860
2024-09-23 11:18:24 +02:00