Commit Graph

236 Commits

Author SHA1 Message Date
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
Jeroen Bakker
4ecd6abf78 Vulkan: Make Anisotropy Sampling Optional
Anisotropy samplers are optional in Vulkan. This change will disable
anisotropy samplers when the feature isn't available on the device.

The support for anisotropy samplers is around 90% so would not expect
any compatibility issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/114833
2023-11-14 12:24:46 +01:00
Jeroen Bakker
00f5ae2a8f Vulkan: Implement Samplers
Until now the Vulkan backend supported a single pre-configured sampler.
This PR realizes creation, caching and freeing of samplers based on what
is required by the state manager.

The implementation is similar to OpenGL or Metal. This fixes many issues
including:

- Textures in workbench and eevee use the correct extend and filtering
- Custom icons render correctly
- Depth sampling issues
- Removes artifacts using EEVEE world shader, lighting and indirect lighting.

Pull Request: https://projects.blender.org/blender/blender/pulls/114827
2023-11-14 11:12:19 +01:00
Jeroen Bakker
7813c94461 Vulkan: Initialize Pipeline State
The initial pipeline state was not set and could lead to undetected
state changes.

This fixes several issues, including:
* Fix incorrect colors in the UI, that would be used everywhere, and
  could be fixed by restarting Blender.
* Overlay extra objects where drawn below the grid.

Pull Request: https://projects.blender.org/blender/blender/pulls/114792
2023-11-13 14:02:13 +01:00
Jeroen Bakker
99d97d9993 Vulkan: Fix Depth Texture Data Conversion
Devices that don't support GPU_DEPTH_COMPONENT24 natively will use
GPU_DEPTH_COMPONENT32F in stead. When done the current code path raised
an error as the conversion type wasn't set.

Issue detected on AMD RX5700 device.

Pull Request: https://projects.blender.org/blender/blender/pulls/114786
2023-11-13 12:26:45 +01:00
Jeroen Bakker
2a24e29241 Vulkan: Convert 3 Component Texture Formats
3 component texture formats are often not supported by vulkan devices.
Sometimes the support is less than 5%. The 4 components variants have
more than 90% support.

This PR builds on top of the existing vulkan data conversion to add
the ability to convert between RGB16F<=>RGBA16F and RGB32F<=>RGBA32F
texture formats.

This allows using color management other then Standard/sRGB. Most places
the 3 component texture formats are phased out, but OCIO, external
render engines and real time compositor uses them.

Pull Request: https://projects.blender.org/blender/blender/pulls/114708
2023-11-10 15:19:24 +01:00
Jeroen Bakker
cc04bcd792 Vulkan: Reusing Textures from Pool
This PR solves an issue when using texture pools with textures that are not
natively supported by the device. In the previous implementation the
internal `Texture::format_` was changed. Any check if the texture could
be reused would fail as its format would be different that the requested one.

This PR fixes this by separating the requested format `Texture::format_` and
how it is stored on the GPU `VKTexture::device_format_`.

This solves the next artifacts:
* Workbench flickering artifacts on AMD/Intel GPUs
* Workbench TAA on AMD/Intel GPUs
* Overlays were not always drawn fully solid

Pull Request: https://projects.blender.org/blender/blender/pulls/114697
2023-11-10 12:52:34 +01:00
Jeroen Bakker
0c9433bf44 Vulkan: Retarget Depth Range
OpenGL uses a depth range between -1 and 1, which is then normalized.
Metal & Vulkan uses a depth range between 0 and 1, which is already normalized.

The final plan would be to default to a depth range between 0 and 1, but
for now the depth ranges are retargetted so they won't be clipped away.

This solves the next issues for users:
- Navigate control will be rendered correctly
- Ortographic view clipping artifacts
- EEVEE light evaluation

Retargetting happens at the end of the vertex stage or when a geometry
stage is present at the end of the geometry stage. Derivatives using
depth would have a different value compared to OpenGL, but would match
Metal backend. OpenGL performs clipping and generates derivatives based
on the original depth value.

`gl_FragCoord` and clipping would have some precision differences as clipping
and normalizing are done in a different order but would match Metal.

Geometry shaders should use `gpu_EmitVertex` to ensure that the retargetting
is done per vertex.

Pull Request: https://projects.blender.org/blender/blender/pulls/114669
2023-11-10 12:32:06 +01:00
Jeroen Bakker
8c7f927ec8 Vulkan: Workbench Shadow Drawing
There were some issues with workbench shadow drawing. This PR
does some tweaks to fix the shadow drawing on vulkan.

* Framebuffer stencil clearing when write stencil is disabled
* Tweaks to stencil operation and tests
* Disable restart for line adjacency

Pull Request: https://projects.blender.org/blender/blender/pulls/114673
2023-11-09 16:07:26 +01:00
Jeroen Bakker
b51027ea0c Vulkan: Fix Issues surrounding Grease Pencil Drawing
Some minor tweaks to the vulkan backend to support grease pencil
drawing. The changes include:

* Add support for GPU_DATA_10_11_11_REV clearing
* Use correct index buffer start and count

Anti aliasing isn't working as they require different samplers being
configured and that require some design work.
Effects haven't been tested.

Pull Request: https://projects.blender.org/blender/blender/pulls/114659
2023-11-09 11:00:09 +01:00
Jeroen Bakker
f76ceddc98 Vulkan: Workaround for Unsupported R8G8B8 Vertex Buffer Formats
On some platforms `VK_FORMAT_R8G8B8_*` are not supported as vertex buffers. The
obvious workaround for this is to use `VK_FORMAT_R8G8B8A8_*`. Using unsupported
vertex formats would crash Blender as it is not able to compile the graphics
pipelines that use them.

Known platforms are:
- NVIDIA Mobile GPUs (Quadro M1000M)
- AMD Polaris (open source drivers)

This PR adds the initial workings for other unsupported vertex buffer formats we
need to fix in the future.

`VKDevice.workarounds.vertex_formats` contain booleans if the workaround for
a specific format should be turned on (`r8g8b8 = true`). `VertexFormatConverter` can be
used to identify if conversions are needed and perform the conversion.

Pull Request: https://projects.blender.org/blender/blender/pulls/114572
2023-11-08 09:44:22 +01:00
Jeroen Bakker
73b15f341e Fix: Enable Vulkan Workarounds
Vulkan workarounds could not be enabled by using the
`--debug-gpu-force-workarounds` command line argument. This PR fixes
this.

Pull Request: https://projects.blender.org/blender/blender/pulls/114579
2023-11-07 14:59:28 +01:00
Jeroen Bakker
e77cf08b02 Cleanup: Vulkan: Replace FlagBits with Flags
Vulkan API uses Flags and FlagBits for enumerations. The FlagBits
contains the options that can be hold with the Flags data type.

This wasn't well understood at the beginning of the project and
the FlagBits where used where Flags should have been used. This cleanup
fixes this, improving the readability of the code where bit
manipulations where used.

Pull Request: https://projects.blender.org/blender/blender/pulls/114459
2023-11-03 14:42:12 +01:00
Jeroen Bakker
e2215fea35 Vulkan: Specify Pipeline Stages When Adding Barriers
This PR adds support to specify pipeline stages when adding barriers.
This would make it possible more carefully specify barriers.

Pull Request: https://projects.blender.org/blender/blender/pulls/114457
2023-11-03 14:24:39 +01:00
Jeroen Bakker
0f5abc5a8b Vulkan: Readback Texture Views
When using EEVEE-Next the final render data is readback from texture
views. This wasn't implemented yet.

This PR adds support for reading back texture views. It also makes sure
the correct layer is read when reading back data from framebuffers and
adds internal support to read back a partial texture.

Pull Request: https://projects.blender.org/blender/blender/pulls/114411
2023-11-02 15:55:05 +01:00
Campbell Barton
6983c14955 Cleanup: spelling in comments, use doxygen doc-strings 2023-11-02 16:43:04 +11:00
Jeroen Bakker
17bff13836 Vulkan: Replace Stencil Test Not Working
`GPU_STENCIL_OP_REPLACE` was different compared with OpenGL. This PR
sets the same operations that OpenGL uses.

Pull Request: https://projects.blender.org/blender/blender/pulls/114314
2023-10-31 13:41:15 +01:00
Jeroen Bakker
0dbc13529b Cleanup: Remove Debug Statement
In vulkan texturing code.
2023-10-31 11:57:52 +01:00
Jeroen Bakker
f665680024 Vulkan: Mipmap Generation Pipeline Barriers
This PR replaces submissions with pipeline barriers when generating
mipmaps. This would reduce the amount of submissions and improve
performance during mipmap generation as dependencies will be tracked
between commands.

Pull Request: https://projects.blender.org/blender/blender/pulls/114306
2023-10-31 11:46:07 +01:00
Jeroen Bakker
f35b0373d6 Vulkan: Separate DataTransfer, Compute, Graphics Commands
Goal is to reduce the number of command buffer flushes by tracking what is
happening in the different command queues. This is an initial step towards
advanced queue-ing strategies.

The new (intermediate) strategy records commands to different command
buffers based on what they do. There is a command buffer for data transfers,
compute pipelines and graphics pipelines.

When a compute command is recorded it ensures that all graphic commands
are finished. When a graphic command is recorded it ensures all compute
commands are finished. When a graphic or compute command is scheduled
all recorded data transfer commands are scheduled as well.

Some improvements are expected as multiple compute and data transfers
commands can now be scheduled at the same time and don't need to unbind
and rebind render passes. Especially when using EEVEE-Next which is
compute centric the performance change is visible for the user.

Pull Request: https://projects.blender.org/blender/blender/pulls/114104
2023-10-30 14:21:14 +01:00
Campbell Barton
c8c2343b4b Cleanup: spelling in comments 2023-10-23 10:09:05 +11:00
Jason Fielder
1b0ddfa6cb GPU: Add explicit API to sync storage buffer back to host
PR Introduces GPU_storagebuf_sync_to_host as an explicit routine to
flush GPU-resident storage buffer memory back to the host within the
GPU command stream.

The previous implmentation relied on implicit synchronization of
resources using OpenGL barriers which does not match the
paradigm of explicit APIs, where indiviaul resources may need
to be tracked.

This patch ensures GPU_storagebuf_read can be called without
stalling the GPU pipeline while work finishes executing. There are
two possible use cases:

1) If GPU_storagebuf_read is called AFTER an explicit call to
GPU_storagebuf_sync_to_host, the read will be synchronized.
If the dependent work is still executing on the GPU, the host
will stall until GPU work has completed and results are available.

2) If GPU_storagebuf_read is called WITHOUT an explicit call to
GPU_storagebuf_sync_to_host, the read will be asynchronous
and whatever memory is visible to the host at that time will be used.
(This is the same as assuming a sync event has already been signalled.)

This patch also addresses a gap in the Metal implementation where
there was missing read support for GPU-only storage buffers.
This routine now uses a staging buffer to copy results if no
host-visible buffer was available.

Reading from a GPU-only storage buffer will always stall
the host, as it is not possible to pre-flush results, as no
host-resident buffer is available.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/113456
2023-10-20 17:04:36 +02:00
Sergey Sharybin
85c557ffa2 Cleanup: Rename BLI_string_utils.h to BLI_string_utils.hh
All users of it are now C++, which opens doors to add C++ to the
public API.
2023-10-20 10:27:26 +02:00
Jeroen Bakker
f9aca93a47 Vulkan: Add Support for sRGB Framebuffer Enablement
Allow binding of framebuffers without sRGB to linear transform.
`GPU_framebuffer_bind_no_srgb`. This Patch removes color transform
artifacts in node, image and sequence editor.

When the framebuffer is an srgb framebuffer and it is bound without
the transformation, the SRGB textures are bound as UNORM variants.

As framebuffer, render pass and subpass recreation is ensured by
`VKCommandBuffer` we don't need to mark the framebuffer dirty at
this time. Later on we can optimize this by adding a state changed
detection for framebuffers and render passes.

Pull Request: https://projects.blender.org/blender/blender/pulls/113838
2023-10-19 14:41:18 +02:00
Campbell Barton
e7e4e63313 Cleanup: spelling in comments, white-space in comments 2023-10-19 18:53:16 +11:00
Jeroen Bakker
62f721467b Merge branch 'blender-v4.0-release' 2023-10-19 08:03:51 +02:00
Jason Fielder
62219f8da9 Metal: Re-enable workbench NEXT shadows
With the shift to GPU-driven rendering pipeline,
the SSBO vertex fetch paradigm used to
implement workbench shadows on Metal
instead of utilising the geometry shader
path no longer worked correctly.

This is because the draw submission
required vertex amplification up-front,
based on the expected output geometry
amount for a given input geometry.

This patch aims to resolve this
issue through addition of API to
enable the features within the
GPU driven pipeline.

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/113498
2023-10-19 08:01:17 +02:00
Jeroen Bakker
79cbeae939 Vulkan: Incorrect Node Socket Drawing
When drawing node sockets an immediate mode buffer is created that can
contain all the node sockets of the node. Only visible node sockets will
then be added. Vulkan assumed that all elements in the buffer needed to
be drawn, resulting using uninitialzed memory for drawing node sockets.

This resulted in very colorful and big artifacts rendered in the node
editor. This was detected during drawing of node sockets, but would have
been visible in other places as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/113830
2023-10-17 13:45:14 +02:00
Campbell Barton
2e0b844b36 Cleanup: spelling in comments 2023-10-14 13:53:00 +11:00
Jeroen Bakker
db2328436e Vulkan: Reduce Console Flooding
When Vulkan is started with validation layers the console is flooded.
Somewhere in the Vulkan validation layers or mesa driver (or the
combination) there is an issue where maxBufferSize is reported by the
driver to be 4GB, but the validation layers are reporting any buffer
size to be larger than 4GB.

For now we skip this message to be logged.

Pull Request: https://projects.blender.org/blender/blender/pulls/113652
2023-10-13 11:24:59 +02:00
Jeroen Bakker
26adfcdb57 Revert "Metal: Re-enable workbench NEXT shadows"
This reverts commit 95f01288b0.
It fails on non-apple platforms.
2023-10-13 11:05:02 +02:00
Jason Fielder
95f01288b0 Metal: Re-enable workbench NEXT shadows
With the shift to GPU-driven rendering pipeline,
the SSBO vertex fetch paradigm used to
implement workbench shadows on Metal
instead of utilising the geometry shader
path no longer worked correctly.

This is because the draw submission
required vertex amplification up-front,
based on the expected output geometry
amount for a given input geometry.

This WIP patch aims to resolve this
issue through addition of API to
enable the features within the
GPU driven pipeline.

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/113498
2023-10-13 11:02:06 +02:00
Jeroen Bakker
159e798cdb Vulkan: Add Viewport Array/Layer Workarounds
This PR adds workarounds for platforms that don't support `shaderOutputLayer`
or `shaderOutputViewportIndex`. Some NVIDIA laptop GPUs and ARM GPUs don't
have those device features.

The workaround uses the same approach as OpenGL. A geometry shader is injected
to emulate the feature.

For testing the workarounds they have also been connected to the
`--debug-gpu-force-workarounds` command line argument.

Fixes #113475 by implementing #113529

Pull Request: https://projects.blender.org/blender/blender/pulls/113605
2023-10-13 10:40:11 +02:00
Jeroen Bakker
7501a686c2 Vulkan: Fix Subpass Transition Compilation Errors
Vulkan backend doesn't support subpass transition yet. Currently
shader_builder fails as when compiling shaders that use subpass
transitions.

This PR adds a dummy global variable to the GLSL so the compilation
continues.

Development of subpass would take some time as the current API doesn't
fit Vulkan.

Pull Request: https://projects.blender.org/blender/blender/pulls/113604
2023-10-12 15:11:26 +02:00
Campbell Barton
b4504c7840 Cleanup: spelling in comments 2023-10-12 16:03:18 +11:00