Files
test/source/blender/gpu/vulkan/vk_resource_pool.hh
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

77 lines
2.3 KiB
C++

/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include "vk_common.hh"
#include "vk_descriptor_pools.hh"
#include "vk_immediate.hh"
namespace blender::gpu {
class VKDevice;
/**
* Pool of resources that are discarded, but can still be in used and cannot be destroyed.
*
* When GPU resources are deleted (`GPU_*_delete`) the GPU handles are kept inside a discard pool.
* When we are sure that the resource isn't used on the GPU anymore we can safely destroy it.
*
* When preparing the next frame, the previous frame can still be rendered. Resources that needs to
* be destroyed can only be when the previous frame has been completed and being displayed on the
* screen.
*/
class VKDiscardPool {
friend class VKDevice;
private:
Vector<std::pair<VkImage, VmaAllocation>> images_;
Vector<std::pair<VkBuffer, VmaAllocation>> buffers_;
Vector<VkImageView> image_views_;
Vector<VkShaderModule> shader_modules_;
Vector<VkPipelineLayout> pipeline_layouts_;
Vector<VkRenderPass> render_passes_;
Vector<VkFramebuffer> framebuffers_;
std::mutex mutex_;
public:
void deinit(VKDevice &device);
void discard_image(VkImage vk_image, VmaAllocation vma_allocation);
void discard_image_view(VkImageView vk_image_view);
void discard_buffer(VkBuffer vk_buffer, VmaAllocation vma_allocation);
void discard_shader_module(VkShaderModule vk_shader_module);
void discard_pipeline_layout(VkPipelineLayout vk_pipeline_layout);
void discard_framebuffer(VkFramebuffer vk_framebuffer);
void discard_render_pass(VkRenderPass vk_render_pass);
/**
* Move discarded resources from src_pool into this.
*
* GPU resources that are discarded from the dependency graph are stored in the device orphaned
* data. When a swap chain context list is made active the orphaned data can be merged into a
* swap chain discard pool.
*/
void move_data(VKDiscardPool &src_pool);
void destroy_discarded_resources(VKDevice &device);
};
class VKResourcePool {
public:
VKDescriptorPools descriptor_pools;
VKDescriptorSetTracker descriptor_set;
VKDiscardPool discard_pool;
VKImmediate immediate;
void init(VKDevice &device);
void deinit(VKDevice &device);
void reset();
};
} // namespace blender::gpu