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
198 lines
4.8 KiB
C++
198 lines
4.8 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2023 Blender Foundation. All rights reserved. */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#include "vk_common.hh"
|
|
|
|
namespace blender::gpu {
|
|
VkImageAspectFlagBits to_vk_image_aspect_flag_bits(const eGPUTextureFormat format)
|
|
{
|
|
switch (format) {
|
|
case GPU_RGBA32F:
|
|
case GPU_RGBA8UI:
|
|
case GPU_RGBA8I:
|
|
case GPU_RGBA8:
|
|
case GPU_RGBA32UI:
|
|
case GPU_RGBA32I:
|
|
case GPU_RGBA16UI:
|
|
case GPU_RGBA16I:
|
|
case GPU_RGBA16F:
|
|
case GPU_RGBA16:
|
|
case GPU_RG8UI:
|
|
case GPU_RG8I:
|
|
case GPU_RG8:
|
|
case GPU_RG32UI:
|
|
case GPU_RG32I:
|
|
case GPU_RG32F:
|
|
case GPU_RG16UI:
|
|
case GPU_RG16I:
|
|
case GPU_RG16F:
|
|
case GPU_RG16:
|
|
case GPU_R8UI:
|
|
case GPU_R8I:
|
|
case GPU_R8:
|
|
case GPU_R32UI:
|
|
case GPU_R32I:
|
|
case GPU_R32F:
|
|
case GPU_R16UI:
|
|
case GPU_R16I:
|
|
case GPU_R16F:
|
|
case GPU_R16:
|
|
case GPU_RGB10_A2:
|
|
case GPU_R11F_G11F_B10F:
|
|
case GPU_SRGB8_A8:
|
|
case GPU_RGB16F:
|
|
case GPU_SRGB8_A8_DXT1:
|
|
case GPU_SRGB8_A8_DXT3:
|
|
case GPU_SRGB8_A8_DXT5:
|
|
case GPU_RGBA8_DXT1:
|
|
case GPU_RGBA8_DXT3:
|
|
case GPU_RGBA8_DXT5:
|
|
return VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
|
case GPU_DEPTH32F_STENCIL8:
|
|
case GPU_DEPTH24_STENCIL8:
|
|
return static_cast<VkImageAspectFlagBits>(VK_IMAGE_ASPECT_DEPTH_BIT |
|
|
VK_IMAGE_ASPECT_STENCIL_BIT);
|
|
|
|
case GPU_DEPTH_COMPONENT24:
|
|
case GPU_DEPTH_COMPONENT16:
|
|
return VK_IMAGE_ASPECT_DEPTH_BIT;
|
|
|
|
case GPU_DEPTH_COMPONENT32F:
|
|
/* Not supported by Vulkan*/
|
|
BLI_assert_unreachable();
|
|
}
|
|
return static_cast<VkImageAspectFlagBits>(0);
|
|
}
|
|
|
|
VkFormat to_vk_format(const eGPUTextureFormat format)
|
|
{
|
|
switch (format) {
|
|
case GPU_RGBA32F:
|
|
return VK_FORMAT_R32G32B32A32_SFLOAT;
|
|
case GPU_RGBA8UI:
|
|
case GPU_RGBA8I:
|
|
case GPU_RGBA8:
|
|
case GPU_RGBA32UI:
|
|
case GPU_RGBA32I:
|
|
case GPU_RGBA16UI:
|
|
case GPU_RGBA16I:
|
|
case GPU_RGBA16F:
|
|
case GPU_RGBA16:
|
|
case GPU_RG8UI:
|
|
case GPU_RG8I:
|
|
case GPU_RG8:
|
|
case GPU_RG32UI:
|
|
case GPU_RG32I:
|
|
case GPU_RG32F:
|
|
case GPU_RG16UI:
|
|
case GPU_RG16I:
|
|
case GPU_RG16F:
|
|
case GPU_RG16:
|
|
case GPU_R8UI:
|
|
case GPU_R8I:
|
|
case GPU_R8:
|
|
case GPU_R32UI:
|
|
case GPU_R32I:
|
|
case GPU_R32F:
|
|
case GPU_R16UI:
|
|
case GPU_R16I:
|
|
case GPU_R16F:
|
|
case GPU_R16:
|
|
|
|
case GPU_RGB10_A2:
|
|
case GPU_R11F_G11F_B10F:
|
|
case GPU_DEPTH32F_STENCIL8:
|
|
case GPU_DEPTH24_STENCIL8:
|
|
case GPU_SRGB8_A8:
|
|
|
|
/* Texture only format */
|
|
case GPU_RGB16F:
|
|
|
|
/* Special formats texture only */
|
|
case GPU_SRGB8_A8_DXT1:
|
|
case GPU_SRGB8_A8_DXT3:
|
|
case GPU_SRGB8_A8_DXT5:
|
|
case GPU_RGBA8_DXT1:
|
|
case GPU_RGBA8_DXT3:
|
|
case GPU_RGBA8_DXT5:
|
|
|
|
/* Depth Formats */
|
|
case GPU_DEPTH_COMPONENT32F:
|
|
case GPU_DEPTH_COMPONENT24:
|
|
case GPU_DEPTH_COMPONENT16:
|
|
BLI_assert_unreachable();
|
|
}
|
|
return VK_FORMAT_UNDEFINED;
|
|
}
|
|
|
|
VkImageType to_vk_image_type(const eGPUTextureType type)
|
|
{
|
|
switch (type) {
|
|
case GPU_TEXTURE_1D:
|
|
case GPU_TEXTURE_BUFFER:
|
|
case GPU_TEXTURE_1D_ARRAY:
|
|
return VK_IMAGE_TYPE_1D;
|
|
case GPU_TEXTURE_2D:
|
|
case GPU_TEXTURE_2D_ARRAY:
|
|
return VK_IMAGE_TYPE_2D;
|
|
case GPU_TEXTURE_3D:
|
|
case GPU_TEXTURE_CUBE:
|
|
case GPU_TEXTURE_CUBE_ARRAY:
|
|
return VK_IMAGE_TYPE_3D;
|
|
|
|
case GPU_TEXTURE_ARRAY:
|
|
/* GPU_TEXTURE_ARRAY should always be used together with 1D, 2D, or CUBE*/
|
|
BLI_assert_unreachable();
|
|
break;
|
|
}
|
|
|
|
return VK_IMAGE_TYPE_1D;
|
|
}
|
|
|
|
VkImageViewType to_vk_image_view_type(const eGPUTextureType type)
|
|
{
|
|
switch (type) {
|
|
case GPU_TEXTURE_1D:
|
|
case GPU_TEXTURE_BUFFER:
|
|
return VK_IMAGE_VIEW_TYPE_1D;
|
|
case GPU_TEXTURE_2D:
|
|
return VK_IMAGE_VIEW_TYPE_2D;
|
|
case GPU_TEXTURE_3D:
|
|
return VK_IMAGE_VIEW_TYPE_3D;
|
|
case GPU_TEXTURE_CUBE:
|
|
return VK_IMAGE_VIEW_TYPE_CUBE;
|
|
case GPU_TEXTURE_1D_ARRAY:
|
|
return VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
|
case GPU_TEXTURE_2D_ARRAY:
|
|
return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
case GPU_TEXTURE_CUBE_ARRAY:
|
|
return VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
|
|
|
|
case GPU_TEXTURE_ARRAY:
|
|
/* GPU_TEXTURE_ARRAY should always be used together with 1D, 2D, or CUBE*/
|
|
BLI_assert_unreachable();
|
|
break;
|
|
}
|
|
|
|
return VK_IMAGE_VIEW_TYPE_1D;
|
|
}
|
|
|
|
VkComponentMapping to_vk_component_mapping(const eGPUTextureFormat /*format*/)
|
|
{
|
|
/* TODO: this should map to OpenGL defaults based on the eGPUTextureFormat. The implementation of
|
|
* this function will be implemented when implementing other parts of VKTexture.*/
|
|
VkComponentMapping component_mapping;
|
|
component_mapping.r = VK_COMPONENT_SWIZZLE_R;
|
|
component_mapping.g = VK_COMPONENT_SWIZZLE_G;
|
|
component_mapping.b = VK_COMPONENT_SWIZZLE_B;
|
|
component_mapping.a = VK_COMPONENT_SWIZZLE_A;
|
|
return component_mapping;
|
|
}
|
|
|
|
} // namespace blender::gpu
|