Commit Graph

270 Commits

Author SHA1 Message Date
Prakhar-Singh-Chouhan
5d076e0e7b Vulkan: Implementing VKBackend::samplers_update()
Implemented `VKBackend::samplers_update()`. When triggered,
if the VK Device is initialized, the `device.samplers` are
freed and reinitialized.

Implements: #117019
Pull Request: https://projects.blender.org/blender/blender/pulls/119109
2024-03-11 07:57:52 +01:00
Campbell Barton
e33f5e36ac Cleanup: spacing around C-style comment blocks 2024-03-09 23:40:57 +11:00
Omar Emara
eb91828aab GPU: Add maximum image units to GPU capabilities
This patch adds the maximum number of supported image units to the GPU
capabilities module. Currently, the GPU module assume a maximum of 8
units, so the patch is not currently particularly useful, but we can
consider committing it for the future anyways.

Pull Request: https://projects.blender.org/blender/blender/pulls/119057
2024-03-05 07:25:20 +01:00
Jeroen Bakker
5698fb2049 RenderDoc: Set Capture Title
Adds an option to set the capture title when using renderdoc
`GPU_debug_capture_begin` has an optional `title` parameter to set
the title of the renderdoc capture.

Pull Request: https://projects.blender.org/blender/blender/pulls/118649
2024-02-23 10:57:37 +01:00
Jeroen Bakker
e70e9e3cf9 GPU: Report on vertex attribute conversions
Blender uses some vertex attributes that are not (and sometimes
never) supported by a GPU. OpenGL silently converted these changes
but for Metal/Vulkan we need to convert then when uploading the
data.

This PR will write to console invalid usages which we should remove
from Blender code-base. Note it is still possible to create attributes
that still need conversions by using the PyGPU API.
2024-02-22 11:13:16 +01:00
Jeroen Bakker
df2b5630d8 Vulkan: Update PCI ids
This change cleans up the PCI ids in the Vulkan backend.

- reuses already exising constants.
- add PCI-id for Apple devices.

Pull Request: https://projects.blender.org/blender/blender/pulls/118485
2024-02-20 10:44:11 +01:00
Jeroen Bakker
98bc3369f8 Cleanup: Silence unused parameter warning in Vulkan backend 2024-02-20 10:02:11 +01:00
Hans Goudey
61e61ce0e1 Cleanup: Use Span instead of Vector const reference
Span is preferrable since it's agnostic of the source container,
makes it clearer that there is no ownership, is 8 bytes smaller,
and can be passed by value.
2024-02-14 17:23:01 -05:00
Bastien Montagne
54618dbae3 Cleanup: Make BKE_global.h a Cpp header. 2024-02-10 18:25:14 +01:00
Brecht Van Lommel
c14e9fc95b Cleanup: Compiler warnings 2024-02-05 12:59:30 +01:00
Miguel Pozo
5d132ac0c6 GPU: Optimize OpenGL indirect drawing overhead
`GLBatch::draw_indirect` has additional overhead compared to
`GLBatch::draw`, and can become a bottleneck in scenes that require
many draw calls (ie. with too many unique meshes).

The performance difference is almost exclusively caused by the
`GL_COMMAND_BARRIER_BIT` barrier that happens on every call.

This PR adds a `GPU_storagebuf_sync_as_indirect_buffer` function that
can be used to place the barrier only once after filling the indirect
buffer content.
This function is a no-op in Vulkan and Metal since they don't need the
barrier.

Pull Request: https://projects.blender.org/blender/blender/pulls/117561
2024-02-01 17:26:08 +01:00
Jeroen Bakker
958ec9f37f Vulkan: Use Generic Buffer to Store DrawList Commands
Previously a storage buffer was used to store draw list commands as it
matches already existing APIs. Unfortunately StorageBuffers prefers to
be stored on the GPU device and would reduce the benefit of a dynamic
draw list.

This PR replaces the storage buffer with a regular buffer, which keeps
more control where to store the buffer.

Pull Request: https://projects.blender.org/blender/blender/pulls/117712
2024-02-01 10:03:47 +01:00
Clément Foucault
749a3880de GL: Remove cube map array workaround 2024-01-31 18:12:59 +01:00
Clément Foucault
71904d7fb3 GL: Remove image load/store workaround
# Conflicts:
#	source/blender/gpu/opengl/gl_backend.cc
2024-01-31 18:12:59 +01:00
Jeroen Bakker
ec80264d09 Vulkan: Bundle Calls in DrawList
A draw list bundles multiple draw commands for the same geometry
and sends the draw commands in a single command. This reduces
the overhead of pipeline checking, resource validation and can
keep the load higher on the gpu as more work needs to be done.

Previously the draw list didn't bundle any commands and would still
send each call separately to the GPU. This PR implements the bundling
of the commands.

Pull Request: https://projects.blender.org/blender/blender/pulls/117548
2024-01-26 17:45:18 +01:00
Miguel Pozo
333a5b513b GPU: Assert framebuffer operations match attachment layout
Ensure attachment states and load/store configs don't get out of sync
with the framebuffer layout.
In theory, a Framebuffer could have empty attachments interleaved with
valid ones so checking just the attachments "length" is not enough.
What this does instead is to ensure that valid attachments have a valid
config and that null attachments either don't have a matching config or
have an IGNORE/DONT_CARE one.

Pull Request: https://projects.blender.org/blender/blender/pulls/117073
2024-01-15 13:25:20 +01:00
Jeroen Bakker
4ac0267567 OpenGL: Specialization Constants
This PR adds support for specialization constants for the OpenGL
backend. The minimum OpenGL version we are targetting doesn't
have native support for specialization constants. We simulate this
by keeping track of shader programs for each set of specialization
constants that are being used.

Specialization constants can be used to reduce shader complexity
and improve performance as less registry and/or spilling is done.

This requires the ability to recompile GLShaders. In order to do this
we need to keep track of the sources that are used when the shader
was compiled. For static sources we only store references
(`GLSource::source_ref`), for dynamically generated sources we keep
a copy of the source (`GLSource::source`).

When recompiling the shader GLSL source-code is generated for the
constants stored in `Shader::constants`. When compiling the previous
GLSource that contains specialization constants is then replaced
by the new version.

Pull Request: https://projects.blender.org/blender/blender/pulls/116926
2024-01-12 14:28:50 +01:00
Jeroen Bakker
6e17b9c640 Vulkan: Fix: DEPTH_COMPONENT24
Tests for DEPTH_COMPONENT24 crash, so add an implementation to support it.

Co-authored-by: vnapdv <kaz380@hotmail.co.jp>
Pull Request: https://projects.blender.org/blender/blender/pulls/117026
2024-01-11 12:55:33 +01:00
Jeroen Bakker
cd8218d9e4 Vulkan: Fix Image Range Validation Error
Co-authored-by: vnapdv <kaz380@hotmail.co.jp>
Pull Request: https://projects.blender.org/blender/blender/pulls/117024
2024-01-11 12:47:11 +01:00
Jeroen Bakker
6e26249671 Vulkan: Fix vkCmdCopyBufferToImage validation error
Fixes validation error {0xbd041cbe}VUID-VkBufferImageCopy-aspectMask-00212.

Co-authored-by: vnapdv <kaz380@hotmail.co.jp>
Pull Request: https://projects.blender.org/blender/blender/pulls/117021
2024-01-11 11:47:45 +01:00
Jeroen Bakker
46a79ba5a2 Vulkan: Fix Samplers Extend mode
Patch provided by @vnapdv

Pull Request: https://projects.blender.org/blender/blender/pulls/117020
2024-01-11 11:41:35 +01:00
Jeroen Bakker
72d6ca3aff Vulkan: Fix Anisotropic Filtering Validation Error
When anisotropic filtering is enabled on a sampler its value must be
between 1 and 16. In blender it is possible to set a value lower than 1.
0 actually means that anisotropic filtering is disabled in Blender.
This would trigger a validation error in Vulkan.

Pull Request: https://projects.blender.org/blender/blender/pulls/117018
2024-01-11 11:12:35 +01:00
Campbell Barton
7a4f7a1d51 Cleanup: spelling in comments, comment blocks 2024-01-11 16:46:46 +11:00
Jeroen Bakker
5b969f54ca Vulkan: Fix Shader Compilation Issue
The Specialization Shader workaround generated code that wasn't Vulkan
GLSL compliant. The uintBitsToFloat cannot be used during global const
initialization.

This is a temporary work around until we implement the Specialization
Constants for Vulkan.

Pull Request: https://projects.blender.org/blender/blender/pulls/116942
2024-01-09 14:55:02 +01:00
Campbell Barton
617f7b76df Cleanup: comment block formatting 2024-01-08 11:31:43 +11:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Clément Foucault
1c96d0d861 Metal: Improve shader logging
This adds some `#line` directive between the
source file injection so that the log parser knowns
which file the errors originated from.

This is then followed by a scan over the combined
source to find out the real row number.

This needed some changes in the `Shader::plint_log`
to skip lines to avoid outputing redundant information.
2024-01-01 00:43:09 +13:00
Clément Foucault
7d6b8737bf Fix #116623: GL/VK: Specialization constant error
Using defines leads to syntax errors. Use global
constants instead.
2023-12-30 11:09:15 +13:00
Jason Fielder
335d3a1b75 GPU: Add Shader specialization constant API
Adds API to allow usage of specialization constants in shaders.
Specialization constants are dynamic runtime constants which can
be compiled into a shader pipeline state object (PSO) to improve
runtime performance by reducing shader complexity through
shader compiler constant-folding.

This API allows specialization constant values to be specified
along with a default value if no constant value has been declared.
Each GPU backend is then responsible for caching PSO permutations
against the current specialization configuration.

This patch adds support for specialization constants in the
Metal backend and provides a generalised high-level solution
which can be adopted by other graphics APIs supporting
this feature.

Authored by Apple: Michael Parkin-White
Authored by Blender: Clément Foucault (files in gpu/test folder)

Pull Request: https://projects.blender.org/blender/blender/pulls/115193
2023-12-28 05:34:38 +01:00
Jeroen Bakker
ac1c75f3d0 Vulkan: Check Resource Bind Type when Binding
GPU module assumes that image and textures uses different bind
namespaces. In Vulkan this isn't the case, leading that some shaders
generate incorrect bind types, when the state has bindings that are not
used by the shader, but would conflict due to namespace differences.

This PR will only return the binding when after validating it is from
the expected namespace. This removes several validation warnings.

This was done in order to debug EEVEE using modern toolsets. These
toolsets don't support OpenGL and we use Vulkan as a workaround if
possible.

Pull Request: https://projects.blender.org/blender/blender/pulls/116465
2023-12-22 19:02:53 +01:00
Campbell Barton
2b3c379850 Cleanup: use boolean & nullptr literals 2023-12-17 16:04:44 +11:00
Jason Fielder
9313750f0a Metal: Add fallback path for texture atomics V2
This patch adds an alternative path for devices/OSs
which do not support native texture atomics in Metal.
Support is encapsulated within the backend, ensuring
any allocated texture with the USAGE_ATOMIC flag is
allocated with a backing buffer, upon which atomic
operations happen.

The shader generation is also changed for the atomic
case, which instructs the backend to insert additional
buffer bind-points for the buffer resource. As Metal
also only supports buffer-backed textures for
textureBuffers or 2D textures, TextureArrays and
3D textures are emulated within a 2D texture, with
sample locations being indirected.

All usage of atomic textures MUST now utilise the
correct atomic texture types in the high level shader
and GPUShaderCreateInfo declarations.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/115956
2023-12-11 23:00:20 +01:00
Jeroen Bakker
fa2f9ef33b Vulkan: Generate Correct GLSL After Changing Workarounds
During normal execution it isn't possible to switch workarounds.
However when running test cases we want to check if shaders and
other tests work when work arounds are enabled. Currently shader
patches are cached globally.

This PR moves the cached shader patch to the device level which
is rebuild every time a device needs to be reinitialized.

For OpenGL this is also an issue, but harder to solve as the concept
device doesn't exist there.

Pull Request: https://projects.blender.org/blender/blender/pulls/116042
2023-12-11 16:25:41 +01:00
Jeroen Bakker
f355575f1d Vulkan: Add Debug Name To Descriptor Sets
When debugging the descriptor sets are unnamed. This PR sets the
active shader name. This helps when debugging so we don't need
to track down the shader it is complaining about.

```
 the descriptor (VkDescriptorSet 0x66da6f0000001c58[workbench_prepass_mesh_opaque_studio_texture_no_clip_1022]
binding 7, index 0) is being used in draw but has never been updated via vkUpdateDescriptorSets() or a similar call.
```

This message direct directly to the shader including what part is
needed to be checked. No need to add break points and that sort
of things.

Pull Request: https://projects.blender.org/blender/blender/pulls/115944
2023-12-08 15:32:35 +01:00
Campbell Barton
7f8efbe593 Cleanup: quiet CLANG conversion warnings 2023-11-30 15:01:58 +11:00
Campbell Barton
8c473df8c3 Cleanup: suppress CLANG warnings, remove unused variables 2023-11-30 10:48:33 +11:00
Campbell Barton
4e10a4f635 Cleanup: various C++ updates from C 2023-11-27 10:59:54 +11:00
Campbell Barton
27c660707d Cleanup: spelling in comments, variables 2023-11-27 09:54:36 +11:00
Campbell Barton
343b48663b Cleanup: format 2023-11-27 09:30:52 +11:00
Jeroen Bakker
ec772ed2f1 Vulkan: Timeline Semaphores
This change adds timeline semaphores to track submissions. The previous
implementation used a fence.

Timeline semaphores can be tracked in more detail as it is an counter.
For each submission the counter can be stored locally and when waiting
for completion the counter can be retrieved again and checked if is
known to be succeeded by a higher value.

The timeline semaphore is stored next to the queue and can also be used
to synchronize between multiple contexts.

Pull Request: https://projects.blender.org/blender/blender/pulls/115357
2023-11-24 15:23:46 +01:00
Jeroen Bakker
d09d93febf Vulkan: Store Vertex, Index and Storage Buffers on Device Memory
Currently all buffer types were stored in host memory, which is visible to the GPU as well.
This is typically slow as the data would be transferred over the PCI bus when used.

Most of the time Index and Vertex buffers are written once and read many times so it makes
more sense to locate them on the GPU. Storage buffers typically require quick access as they
are created for shading/compute purposes.

This PR will try to store vertex buffers, index buffers and storage buffers on device memory
to improve the performance.

Uniform buffers are still located on host memory as they can be uploaded during binding process.
This can (will) reset the graphics pipeline triggering draw calls using unattached resources.

In future this could be optimized further as in:
* using different pools for allocating specific buffers, with a fallback when buffers cannot be
  stored on the GPU anymore.
* store uniform buffers in device memory

Pull Request: https://projects.blender.org/blender/blender/pulls/115343
2023-11-24 13:52:48 +01:00
Jeroen Bakker
736f446eed Vulkan: Pipeline Cache
This PR adds the default vulkan pipeline cache to when creating
pipelines.

Pipeline caching reuses pipelines that have already been created.
Pipeline creation can be somewhat costly - it has to compile the
shaders at creation time for example.

The cache is recreated at each run of Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/115346
2023-11-24 13:28:09 +01:00
Jeroen Bakker
c0cb39e41b Vulkan: Enable Tests Not Relying on a Context
Some test cases inside the vulkan backend don't rely on an initialized
Vulkan Context and can always be run.

This PR enables those test cases when `WITH_GTEST` and
`WITH_VULKAN_BACKEND` is on. Allowing some tests to run on the
buildbot.

Pull Request: https://projects.blender.org/blender/blender/pulls/114574
2023-11-24 13:27:41 +01:00
Jeroen Bakker
d638357d6f Fix: Vulkan Multi Indirect Drawing
Multi indirect drawing would bind an offset index buffer, but
indirect drawing parameters also offset the index buffer so
incorrect geometry was drawn.

Fixes drawing of meshes with multiple materials.

Pull Request: https://projects.blender.org/blender/blender/pulls/115190
2023-11-20 15:48:06 +01:00
Jeroen Bakker
27fdfb6538 Vulkan: Memory Statistics
This PR shows the memory footprint in the statusbar when activated.
Only memory allocated on the VRAM is counted. Memory allocated on host
memory is not counted.

![image](/attachments/33cedc89-9ada-4c0a-9a94-6c1b3e22b64b)

Pull Request: https://projects.blender.org/blender/blender/pulls/115184
2023-11-20 14:08:19 +01:00
Jeroen Bakker
54e1ee3905 Vulkan: Combine Data Transfer and Compute Commands
Currently we keep track of 3 command buffers. Data transfer, compute and
graphics. The reason is that data transfer and compute commands cannot
be recorded in a command buffer that has an active render pass.

This PR simplifies the implementation by combining data transfer and
compute commands as there is no need to separate those in individual
command buffers.

This is in preparation of improving submission performance.

Pull Request: https://projects.blender.org/blender/blender/pulls/115033
2023-11-17 08:27:44 +01:00
Jeroen Bakker
35db18af2e Cleanup: Remove Never Failing Check 2023-11-17 07:56:56 +01:00
Jeroen Bakker
782e2e5f9a Vulkan: Make Command Pool, Descriptor Sets Context Specific
In Blender a context should not be shared between threads. In Vulkan a
command pool must not be shared between threads. In the current
implementation the command pool are stored on device level and could
therefore be shared between multiple context which made the implementation
not matching these rules.

This PR moves the command pool from device to command buffers where it
would not conflict between other contexts. This PR doesn't make the Vulkan
backend fully multithreaded. The access to the queue is still missing.

Pull Request: https://projects.blender.org/blender/blender/pulls/114977
2023-11-16 15:03:47 +01:00
Jeroen Bakker
0bec7f7360 Fix: Vulkan Texel Buffers Texture Format
Due to recent changes texel buffers could not be attached as the texture
format wasn't set.

Pull Request: https://projects.blender.org/blender/blender/pulls/114844
2023-11-14 15:36:52 +01:00
Jeroen Bakker
0a0689b0b7 Cleanup: Reduce overloaded-virtual warnings
Pull Request: https://projects.blender.org/blender/blender/pulls/114836
2023-11-14 13:55:37 +01:00