7fb1f060ff
This patch adds initial support for compute shaders to the vulkan backend. As the development is oriented to the test- cases we have the implementation is limited to what is used there. It has been validated that with this patch that the following test cases are running as expected - `GPUVulkanTest.gpu_shader_compute_vbo` - `GPUVulkanTest.gpu_shader_compute_ibo` - `GPUVulkanTest.gpu_shader_compute_ssbo` - `GPUVulkanTest.gpu_storage_buffer_create_update_read` - `GPUVulkanTest.gpu_shader_compute_2d` This patch includes: - Allocating VkBuffer on device. - Uploading data from CPU to VkBuffer. - Binding VkBuffer as SSBO to a compute shader. - Execute compute shader and altering VkBuffer. - Download the VkBuffer to CPU ram. - Validate that it worked. - Use device only vertex buffer as SSBO - Use device only index buffer as SSBO - Use device only image buffers GHOST API has been changed as the original design was created before we even had support for compute shaders in blender. The function `GHOST_getVulkanBackbuffer` has been separated to retrieve the command buffer without a backbuffer (`GHOST_getVulkanCommandBuffer`). In order to do correct command buffer processing we needed access to the queue owned by GHOST. This is returned as part of the `GHOST_getVulkanHandles` function. Open topics (not considered part of this patch) - Memory barriers & command buffer encoding - Indirect compute dispatching - Rest of the test cases - Data conversions when requested data format is different than on device. - GPUVulkanTest.gpu_shader_compute_1d is supported on AMD devices. NVIDIA doesn't seem to support 1d textures. Pull-request: #104518
64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2023 Blender Foundation. All rights reserved. */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_vector.hh"
|
|
|
|
#include "vk_descriptor_set.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
/**
|
|
* List of VkDescriptorPools.
|
|
*
|
|
* In Vulkan a pool is constructed with a fixed size per resource type. When more resources are
|
|
* needed it a next pool should be created. VKDescriptorPools will keep track of those pools and
|
|
* construct new pools when the previous one is exhausted.
|
|
*
|
|
* At the beginning of a new frame the descriptor pools are reset. This will start allocating
|
|
* again from the first descriptor pool in order to use freed space from previous pools.
|
|
*/
|
|
class VKDescriptorPools {
|
|
/**
|
|
* Pool sizes to use. When one descriptor pool is requested to allocate a descriptor but isn't
|
|
* able to do so, it will fail.
|
|
*
|
|
* Better defaults should be set later on, when we know more about our resource usage.
|
|
*/
|
|
static constexpr uint32_t POOL_SIZE_STORAGE_BUFFER = 1000;
|
|
static constexpr uint32_t POOL_SIZE_DESCRIPTOR_SETS = 1000;
|
|
static constexpr uint32_t POOL_SIZE_STORAGE_IMAGE = 1000;
|
|
static constexpr uint32_t POOL_SIZE_COMBINED_IMAGE_SAMPLER = 1000;
|
|
static constexpr uint32_t POOL_SIZE_UNIFORM_BUFFER = 1000;
|
|
|
|
VkDevice vk_device_ = VK_NULL_HANDLE;
|
|
Vector<VkDescriptorPool> pools_;
|
|
int64_t active_pool_index_ = 0;
|
|
|
|
public:
|
|
VKDescriptorPools();
|
|
~VKDescriptorPools();
|
|
|
|
void init(const VkDevice vk_device);
|
|
|
|
VKDescriptorSet allocate(const VkDescriptorSetLayout &descriptor_set_layout);
|
|
void free(VKDescriptorSet &descriptor_set);
|
|
|
|
/**
|
|
* Reset the pools to start looking for free space from the first descriptor pool.
|
|
*/
|
|
void reset();
|
|
|
|
private:
|
|
VkDescriptorPool active_pool_get();
|
|
void activate_next_pool();
|
|
void activate_last_pool();
|
|
bool is_last_pool_active();
|
|
void add_new_pool();
|
|
};
|
|
} // namespace blender::gpu
|