Files
test2/source/blender/gpu/vulkan/vk_memory.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
2.1 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
Vulkan: Initial Compute Shaders support 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
2023-02-21 15:03:12 +01:00
#include "vk_common.hh"
namespace blender::gpu {
/**
* `VK_ALLOCATION_CALLBACKS` initializes allocation callbacks for host allocations.
* The macro creates a local static variable with the name `vk_allocation_callbacks`
* that can be passed to VULKAN API functions that expect
* `const VkAllocationCallbacks *pAllocator`.
*
* When Blender is compiled with `WITH_VULKAN_GUARDEDALLOC` this will use
* `MEM_guardedalloc` for host allocations that the driver does on behalf
* of blender. More internal allocations are still being allocated via the
* implementation inside the VULKAN device driver.
*
* When `WITH_VULKAN_GUARDEDALLOC=Off` the memory allocation implemented
* in the vulkan device driver is used for both internal and application
* focused memory operations.
*/
#ifdef WITH_VULKAN_GUARDEDALLOC
void *vk_memory_allocation(void *user_data,
size_t size,
size_t alignment,
VkSystemAllocationScope scope);
void *vk_memory_reallocation(
void *user_data, void *original, size_t size, size_t alignment, VkSystemAllocationScope scope);
void vk_memory_free(void *user_data, void *memory);
constexpr VkAllocationCallbacks vk_allocation_callbacks_init(const char *name)
{
VkAllocationCallbacks callbacks = {};
callbacks.pUserData = const_cast<char *>(name);
callbacks.pfnAllocation = vk_memory_allocation;
callbacks.pfnReallocation = vk_memory_reallocation;
callbacks.pfnFree = vk_memory_free;
callbacks.pfnInternalAllocation = nullptr;
callbacks.pfnInternalFree = nullptr;
return callbacks;
}
# define VK_ALLOCATION_CALLBACKS \
static constexpr const VkAllocationCallbacks vk_allocation_callbacks_ = \
vk_allocation_callbacks_init(__func__); \
2023-02-14 10:29:46 +11:00
static constexpr const VkAllocationCallbacks *vk_allocation_callbacks = \
&vk_allocation_callbacks_;
#else
# define VK_ALLOCATION_CALLBACKS \
static constexpr const VkAllocationCallbacks *vk_allocation_callbacks = nullptr;
#endif
} // namespace blender::gpu