Commit Graph

63 Commits

Author SHA1 Message Date
Jeroen Bakker
c480b7ffd3 Vulkan: Incorrect image aspect when transferring depth textures
When copying from/to depth stencil images the aspect of the image was
set incorrectly. It pointed to only one aspect of the full image when
building resource links, which could lead to incorrect decisions in the
driver.

Found when researching #131269

Pull Request: https://projects.blender.org/blender/blender/pulls/131298
2024-12-03 12:36:39 +01:00
Jeroen Bakker
61d4f7359b Fix: Vulkan: Compiling issue
PR for colored debug groups didn't had the latest changes of main
2024-11-29 08:16:13 +01:00
Jiarui-Yan
b356c2bec1 Vulkan: Colored debug groups
This PR adds color to debug group so that RenderDoc can give color to different
debug groups and sub-groups in the parent debug group.

Ref: #124099

Pull Request: https://projects.blender.org/blender/blender/pulls/129340
2024-11-29 07:52:00 +01:00
Jeroen Bakker
c69b107a28 Fix #130121: Vulkan: Lightbaking resources freed to early
When lighting baking is used in a background render the resources are
freed to early. The cause is that light baking does some initialization
within a context, that isn't send to the GPU. The first iteration of
light baking is expecting that it can free resources, what leads to GPU
resources to be deleted that are still used by commands that are
scheduled to be send to the GPU.

This PR fixes this by using multiple resource pools when background
rendering and ensure that contexts are send to the GPU when rendering
ends.

Pull Request: https://projects.blender.org/blender/blender/pulls/131094
2024-11-28 16:05:59 +01:00
Jeroen Bakker
faf2c6f0ca Vulkan: Add method to query debug group of node
When debugging render graph the debug group name can narrow down the
place where a node originates from. This PR adds a function to retrieve
the full debug group name of a specific node.

Pull Request: https://projects.blender.org/blender/blender/pulls/131081
2024-11-28 12:00:21 +01:00
Campbell Barton
b9f055459a Cleanup: ensure trailing space around comment blocks 2024-11-27 19:01:00 +11:00
Jeroen Bakker
fc5e38c9b6 Vulkan: Allow suspending/resuming of layer tracking
Layer tracking allows modifying specific layers of a bound texture to a
different layout. This was only supported when suspending/resuming was
not needed. However when using complex scenes EEVEE can trigger suspend/
resume rendering scopes. This resulted into several validation warnings
as images where in the incorrect state.

Fixes validation warnings:
- rain_restaurant.blend
- classroom.blend

Pull Request: https://projects.blender.org/blender/blender/pulls/130957
2024-11-26 12:13:52 +01:00
Guillermo Venegas
2760def19a Fix: Vulkan: Free command pool buffers
Currently `VkCommandBuffer` are allocated with `vkAllocateCommandBuffers`,
however when the commands are submitted pointer are just reset, these leaks
are visible with just play back animations.

This frees commands buffers resolving the leaks.

Ref: #127225 Although related we should check the result as there could be more causes.
Pull Request: https://projects.blender.org/blender/blender/pulls/130203
2024-11-26 08:31:25 +01:00
Campbell Barton
0de8ae8046 Cleanup: spelling in comments 2024-11-25 13:24:46 +11:00
Jeroen Bakker
dfc0d97abf Fix #129678: Vulkan: Synchronization issue
Copying editors to the swap chain is done by a series of draw and copy.
When doing draw, copy, draw the swap chain layout was not matching the
draw command as it resumed previous rendering.

This is solved by validating the pipeline barriers when resuming rendering.
There are also other cases that required this which have been updated.

Pull Request: https://projects.blender.org/blender/blender/pulls/130721
2024-11-22 11:58:23 +01:00
Jeroen Bakker
c2695e2dcc Vulkan: Add support for legacy platforms
Dynamic rendering is a Vulkan 1.3 feature. Most platforms have support
for them, but there are several legacy platforms that don't support dynamic
rendering or have driver bugs that don't allow us to use it.

This change will make dynamic rendering optional allowing legacy
platforms to use Vulkan.

**Limitations**

`GPU_LOADACTION_CLEAR` is implemented as clear attachments.
Render passes do support load clear, but adding support to it would
add complexity as it required multiple pipeline variations to support
suspend/resume rendering. It isn't clear when which variation should
be used what lead to compiling to many pipelines and branches in the
codebase. Using clear attachments doesn't require the complexity
for what is expected to be only used by platforms not supported by
the GPU vendors.

Subpass inputs and dual source blending are not supported as
Subpass inputs can alter the exact binding location of attachments.
Fixing this would add code complexity that is not used.

Ref: #129063

**Current state**

![image](/attachments/9ce012e5-2d88-4775-a636-2b74de812826)

Pull Request: https://projects.blender.org/blender/blender/pulls/129062
2024-11-19 16:30:31 +01:00
Jeroen Bakker
791f90ab8d Vulkan: Remove guardedalloc option
WITH_VULKAN_GUARDEDALLOC is a development option to use Blenders guarded
allocator when allocating internal vulkan driver resources. It does not provide any benefits
as this should be covered by vulkan validation and drivers are often ignoring this. This
change will remove the option from cmake and source code.

Pull Request: https://projects.blender.org/blender/blender/pulls/129039
2024-10-15 13:46:00 +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
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
Campbell Barton
8c3ef77a35 Cleanup: spelling in comments 2024-10-08 09:03:49 +11: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
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
e8e89b751d Vulkan: Fix incorrect reordering when copying attachment
Solved by not supporting complex reordering at this moment. It
is currently better to focus on quality and add back performance
later. During tests I didn't detect any user noticeable performance
degradation. Could also be because we support rendering
suspending/resuming.

Fixes artifacts in EEVEE volumes and raytracing.

Pull Request: https://projects.blender.org/blender/blender/pulls/126974
2024-08-30 13:24:57 +02:00
Jeroen Bakker
d48986eec9 Fix: Vulkan: EEVEE irradiance baking
Fix crash when using EEVEE irradiance baking. When reading back the
intermediate result the active rendering was not ended, resulting
in an assert as the rendergraph is cleared and assumed to be in an
initial state (not rendering).

Pull Request: https://projects.blender.org/blender/blender/pulls/126688
2024-08-23 14:45:40 +02:00
Jeroen Bakker
7a7ae5defe Vulkan: Occlusion Queries
Implements occlusion queries using VkQueryPools.

Pull Request: https://projects.blender.org/blender/blender/pulls/123883
2024-08-20 11:27:33 +02:00
Jeroen Bakker
ef3ceb3629 Vulkan: Resource Pools
This PR implements #126353; In short: keep discard list as part of swap chain images. This allows
better determination when resources are actually not in use anymore.

## Resource pool

Resource pools keep track of the resources for a swap chain image.

In Blender this is a bit more complicated due to the way GPUContext work. A single thread can have
multiple contexts. Some of them have a swap chain (GHOST Window) other don't (draw manager). The
resource pool should be shared between the contexts running on the same thread.

When opening multiple windows there are also multiple swap chains to consider.

### Discard pile

Resource handles that are deleted and stored in the discard pile. When we are sure that these
resources are not used on the GPU anymore these are destroyed.

### Reusable resources

There are other resources as well like:
- Descriptor sets
- Descriptor pools

## Open issues

There are some limitations that require future PRs to fix including:
- Background rendering
- Handling multiple windows
- Improve CPU/GPU synchronization
- Reuse staging buffers

Pull Request: https://projects.blender.org/blender/blender/pulls/126353
2024-08-19 15:37:48 +02:00
Jeroen Bakker
ca0e1d696a Vulkan: Layer tracking during render scope
EEVEE can bind layers of a texture that is also used as an attachment. When binding
the image layout of these specific layers can be different that the image layout of
the whole image.

This fixes the known synchronization issues inside EEVEE. wasp_bot, tree_creature and
wanderer scenes can be rendered without any synchronization issue reported by the
Vulkan validation layers.

Design task: #124214

When beginning to render the attachments are being evaluated. If there is an arrayed
texture (with multiple layers) the individual layers of that texture can be tracked
during until the rendering is ended.

When the same texture is bound to a shader it will be a different layer (otherwise
there is a feedback loop, which isn't allowed). The bound layers will typically need
a different layout the transition to the new layout is executed and recorded. When
the rendering ends, the layers are transitioned back to the layout the texture is
expected in.

It can happen that a layer is used multiple times during the same rendering. In
that case the rendering should be suspended to perform the transition. Image layout
transitions are not allowed during rendering.

There is one place where a layer needs to be transited multiple times that is when
EEVEE wants to extract the thickness from the shadow. The thickness is stored inside
the gbuffer_normal which is also used as an attachment. Eval then samples the thickness
from the gbuffer_normal as a sampler. To work around this issue we suspend the rendering
when a `GPU_BARRIER_SHADER_IMAGE_ACCESS` is signaled.

Pull Request: https://projects.blender.org/blender/blender/pulls/124407
2024-07-16 16:39:18 +02:00
Jeroen Bakker
0d71d83d47 Vulkan: Share rendergraphs on context inside same thread
This PR will share render graphs between all contexts that run in
the same thread. This allows the draw manager commands to be added
to the same render graph as the UI.

- Fixes debug groups hiearchy. Draw manager would restart a hierarchy as
  it wasn't aware of the debug groups already added by the UI
- Removes cpu sync when switching between contexts.

In a future change this is needed to improve discarding resources.

Pull Request: https://projects.blender.org/blender/blender/pulls/124715
2024-07-15 16:03:51 +02:00
Jeroen Bakker
d953f6b6f7 Vulkan: Reset command buffer
Previously we create a new command buffer when the render graph is being
submitted. This PR changes that by resetting the command buffer for
reuse.

Pull Request: https://projects.blender.org/blender/blender/pulls/124596
2024-07-12 14:38:42 +02:00
Jeroen Bakker
a730454c8a Vulkan: Add test case for render graph draw
Pull Request: https://projects.blender.org/blender/blender/pulls/124507
2024-07-11 11:38:36 +02:00
Jeroen Bakker
615f4a7d4e Cleanup: Vulkan: Remove unused variable
Detected when compiled with clang.

Pull Request: https://projects.blender.org/blender/blender/pulls/124480
2024-07-10 21:44:19 +02:00
Jeroen Bakker
180a257eef Cleanup: Vulkan: Use stamp in stead of version
Pull Request: https://projects.blender.org/blender/blender/pulls/124339
2024-07-08 12:56:21 +02:00
Jeroen Bakker
08d365b810 Vulkan: Cleanup barrier state
Try to reduce the barrier state so we can be more flexible when adding
support for sub resource tracking.

Pull Request: https://projects.blender.org/blender/blender/pulls/124237
2024-07-08 12:28:11 +02:00
Campbell Barton
48383cf20e Cleanup: avoid shadowing, redundant assignment & minor changes
Quiet cppecheck warnings, use const pointers, ELEM(..) macro,
replace NULL -> nullptr, unsigned int -> uint.
2024-07-07 00:18:00 +10:00
Jeroen Bakker
88f04e95c3 Vulkan: Fix HiZ synchronization
HiZ update performs a read/write on different buffers, this lead
to write-after-write hazards as the resources where added multiple
times in the same pipeline barrier with different access masks.
This is fixed by merging pipeline barriers based on their resource.

Pull Request: https://projects.blender.org/blender/blender/pulls/124036
2024-07-02 14:06:49 +02:00
Jeroen Bakker
bf3c6a3480 Vulkan: Improve debugging render graph
Adds debug print function to output a node with its inputs and outputs.
Also keep track of the name of the resource (only images) what will
be presented. Tracking of the resource name is only done in debug builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/124033
2024-07-02 13:29:34 +02:00
Jeroen Bakker
da4746fe96 Vulkan: Fix copy depth images with stencil
When copying the depth aspect of a depth+stencil image the incorrect
barriers where created. The barrier needs to have the full aspect, even
when we only copy a single aspect from the image.

Pull Request: https://projects.blender.org/blender/blender/pulls/123890
2024-06-28 13:13:33 +02:00
Jeroen Bakker
e72e538fdd Vulkan: Fix sequential read hazard
When a buffer resource was read, and after that read from another
shader stage it would not generate the appropriate pipeline barrier.

This is fixed by keeping the last write action around and check
if the shader stage was already included in the previous barriers.

Pull Request: https://projects.blender.org/blender/blender/pulls/123845
2024-06-27 15:53:14 +02:00
Jeroen Bakker
ee0b7b9a95 Vulken: Mix array aspect of image views
The image views type can change depending based on how they are bound
to shaders. When a shader accesses a view without array operations,
the image view should not be an array. This was previously ignored.

Pull Request: https://projects.blender.org/blender/blender/pulls/123726
2024-06-25 15:15:18 +02:00
Jeroen Bakker
f5b173188e Vulkan: Fix incorrect read image barrier
When having a sequential read image barriers for the same resource
and the second one requires an image layout transition the incorrect
barriers where generated.

This was fixed by aligning the implementation with write image barriers.

Pull Request: https://projects.blender.org/blender/blender/pulls/123712
2024-06-25 11:05:07 +02:00
Jeroen Bakker
dbd04310c7 Vulkan: Fix incorrect layout transition
When many text using BLF the glymp texture could be re-written.
In this case the new upload should be done in a separate render
graph node group. This wasn't the case and resulted in
validation warnings about the glyph texture being in an layout
that wasn't expected.

This PR simplifies the group extraction a bit by looking ahead
when the group ends.

Pull Request: https://projects.blender.org/blender/blender/pulls/123547
2024-06-21 13:26:52 +02:00
Jeroen Bakker
4353b7ffba Vulkan: Remove unused code
Vulkan backend has recently switched to a render graph approach. Many
code was left so we could develop the render graph beside the previous
implementation. Last week we removed the switch. This PR will remove
most of the unused code. There might be some left and will be removed
when detected.

Pull Request: https://projects.blender.org/blender/blender/pulls/123422
2024-06-20 11:34:19 +02:00
Campbell Barton
a9447cf09a Cleanup: spelling in comments 2024-06-19 10:03:37 +10:00
Jeroen Bakker
0643f495cd Vulkan: Fix incorrect write access mask in pipeline barriers
By adding the previous mask, masks could be used in pipeline
stages that don't support the mask. Fixed by limiting the
mask to the current node.

Pull Request: https://projects.blender.org/blender/blender/pulls/123381
2024-06-18 17:17:20 +02:00
Jeroen Bakker
22d352dacc Vulkan: Render graph drawing
This PR adds drawing support to the render graph. It adds support for
draw, indirect draw, indexed draw and indexed indirect draw.

Draw commands can only be executed within a rendering scope. Data
transfer commands and dispatch commands cannot be executed within a
rendering scope. Blender can still send in commands in any order and
the render graph needs to find out the best order to minimize context
switches (rendering/begin/end). This is the responsibility of the
scheduler.

The scheduler will push data transfer and dispatch commands outside the
rendering scope:
- data transfer and dispatch commands at the beginning are done before
  the rendering begin.
- data transfer and dispatch commands at the end are done after the
  rendering end.
- data transfer and dispatches in between draw commands will be pushed
  to the beginning if they are not yet being used.
- for all other data transfer and dispatch commands the rendering is
  suspenderd and will be continued afterwards.

Within a rendering context it is not allowed to perform synchronization
commands. Any synchronization commands inside a rendering scope will be
performed before the rendering scope begins. Nodes are now organized
in groups to simplify the code around this area.

Pull Request: https://projects.blender.org/blender/blender/pulls/123168
2024-06-13 09:37:17 +02:00
Jeroen Bakker
049d84d36d Vulkan: Texture view clearing
EEVEE-Next requires clearing texture views. This PR adds that.

Pull Request: https://projects.blender.org/blender/blender/pulls/122650
2024-06-03 13:47:15 +02:00
Jeroen Bakker
5ee46b0ef3 Vulkan: Use macros to reduce code replication
Use macros to reduce code replication.

- `VKRenderGraph::add_node`
- `VKRenderGraphNode::build_commands`
- `VKRenderGraphNode::free_data`

Pull Request: https://projects.blender.org/blender/blender/pulls/122141
2024-05-23 11:21:55 +02:00
Jeroen Bakker
7fb1c4c573 Vulkan: Incorrect memory barrier when presenting
When synchonizing the image for presentation the incorrect access
mask was used. This PR changes the access mask from data transfer
write to memory write. The data transfer write is not allowed to
change the image layout.

Pull Request: https://projects.blender.org/blender/blender/pulls/122138
2024-05-23 10:04:32 +02:00
Jeroen Bakker
c3c4e948b1 Vulkan: Fixing issues in debugging groups
* Debugging groups were not being applied as that part of the code
  wasn't ported to the original patch
* Debugging groups didn't account for nodes that weren't owned by
  any debug group.

Pull Request: https://projects.blender.org/blender/blender/pulls/122136
2024-05-23 09:48:25 +02:00
Jeroen Bakker
488e74a209 Vulkan: Render graph debug groups
This PR implements debug groups in the render graph. Each node contains
a reference to the debug group they belong to. During scheduling the
nodes can be reordered and the correct debug group needs to be
activated.

This is done by keeping track of the current debug group. When a
different debug group is needed, the needed ends/begins are added
to the command buffer.

This mechanism also cleans up debug groups that are not used at all
as they don't have any nodes associated to it.

Pull Request: https://projects.blender.org/blender/blender/pulls/122054
2024-05-21 17:34:55 +02:00
Jeroen Bakker
9b531609bd Vulkan: Fix push constants tests
This fixes several issues with push constants.

Push constants test were failing due to setting incorrect parameters.
The pipeline stage was used as if it was a shader stage.

When using push constants fallback the uniform was loaded to the
descriptor set after the descriptor set was checked.

Suppress updating push constants of non render graph, when render
graph is active.

Pull Request: https://projects.blender.org/blender/blender/pulls/121772
2024-05-14 10:44:10 +02:00
Jeroen Bakker
f625c4e63d Vulkan: Fix compute test cases
Compute tests were failing due to recent changes.
* Incorrect image layout was used for writable image bindings.
* Incorrect pipeline stage was used for indirect command buffers.

Pull Request: https://projects.blender.org/blender/blender/pulls/121744
2024-05-14 08:22:18 +02:00
Jeroen Bakker
5c369768d7 Vulkan: Revert incorrect fix for begin rendering
Reverting a quick fix which didn't solve the root cause. The root
cause was fixed by #121723.

Pull Request: https://projects.blender.org/blender/blender/pulls/121726
2024-05-13 13:28:05 +02:00