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
103 lines
2.3 KiB
C++
103 lines
2.3 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2022 Blender Foundation. All rights reserved. */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#include "vk_context.hh"
|
|
|
|
#include "vk_backend.hh"
|
|
#include "vk_memory.hh"
|
|
#include "vk_state_manager.hh"
|
|
|
|
#include "GHOST_C-api.h"
|
|
|
|
namespace blender::gpu {
|
|
|
|
VKContext::VKContext(void *ghost_window, void *ghost_context)
|
|
{
|
|
VK_ALLOCATION_CALLBACKS;
|
|
ghost_window_ = ghost_window;
|
|
if (ghost_window) {
|
|
ghost_context = GHOST_GetDrawingContext((GHOST_WindowHandle)ghost_window);
|
|
}
|
|
ghost_context_ = ghost_context;
|
|
|
|
GHOST_GetVulkanHandles((GHOST_ContextHandle)ghost_context,
|
|
&vk_instance_,
|
|
&vk_physical_device_,
|
|
&vk_device_,
|
|
&vk_queue_family_,
|
|
&vk_queue_);
|
|
|
|
/* Initialize the memory allocator. */
|
|
VmaAllocatorCreateInfo info = {};
|
|
/* Should use same vulkan version as GHOST (1.2), but set to 1.0 as 1.2 requires
|
|
* correct extensions and functions to be found by VMA, which isn't working as expected and
|
|
* requires more research. To continue development we lower the API to version 1.0.*/
|
|
info.vulkanApiVersion = VK_API_VERSION_1_0;
|
|
info.physicalDevice = vk_physical_device_;
|
|
info.device = vk_device_;
|
|
info.instance = vk_instance_;
|
|
info.pAllocationCallbacks = vk_allocation_callbacks;
|
|
vmaCreateAllocator(&info, &mem_allocator_);
|
|
descriptor_pools_.init(vk_device_);
|
|
|
|
state_manager = new VKStateManager();
|
|
|
|
VKBackend::capabilities_init(*this);
|
|
}
|
|
|
|
VKContext::~VKContext()
|
|
{
|
|
vmaDestroyAllocator(mem_allocator_);
|
|
}
|
|
|
|
void VKContext::activate()
|
|
{
|
|
}
|
|
|
|
void VKContext::deactivate()
|
|
{
|
|
}
|
|
|
|
void VKContext::begin_frame()
|
|
{
|
|
VkCommandBuffer command_buffer = VK_NULL_HANDLE;
|
|
GHOST_GetVulkanCommandBuffer(static_cast<GHOST_ContextHandle>(ghost_context_), &command_buffer);
|
|
command_buffer_.init(vk_device_, vk_queue_, command_buffer);
|
|
command_buffer_.begin_recording();
|
|
|
|
descriptor_pools_.reset();
|
|
}
|
|
|
|
void VKContext::end_frame()
|
|
{
|
|
command_buffer_.end_recording();
|
|
}
|
|
|
|
void VKContext::flush()
|
|
{
|
|
command_buffer_.submit();
|
|
}
|
|
|
|
void VKContext::finish()
|
|
{
|
|
command_buffer_.submit();
|
|
}
|
|
|
|
void VKContext::memory_statistics_get(int * /*total_mem*/, int * /*free_mem*/)
|
|
{
|
|
}
|
|
|
|
void VKContext::debug_group_begin(const char *, int)
|
|
{
|
|
}
|
|
|
|
void VKContext::debug_group_end()
|
|
{
|
|
}
|
|
|
|
} // namespace blender::gpu
|