Blender V5.3
vk_common.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "GPU_texture.hh"
12#include <typeinfo>
13
14#ifdef _WIN32
15# include "BLI_winstuff.hh"
16# define VK_USE_PLATFORM_WIN32_KHR
17#endif
18
19#define VOLK_NAMESPACE
20#define VOLK_NO_DEVICE_PROTOTYPES
21#include "volk.h"
22
23#define VMA_VULKAN_VERSION 1002000 // Vulkan 1.2
24#if !defined(_WIN32) or defined(_M_ARM64)
25/* Silence compilation warning on non-windows x64 systems. */
26# define VMA_EXTERNAL_MEMORY_WIN32 0
27#endif
28#include "vk_mem_alloc.h"
29
30#include "GPU_index_buffer.hh"
31#include "GPU_ray_tracing.hh"
32#include "GPU_state.hh"
33#include "gpu_query.hh"
36
37namespace blender::gpu {
38
40
54
60
63 uint32_t mipmap_count = VK_REMAINING_MIP_LEVELS;
65 uint32_t layer_count = VK_REMAINING_ARRAY_LAYERS;
66};
67
69template<typename HandleType> struct VKResourceWithHandle {
71 HandleType vk_handle = VK_NULL_HANDLE;
72
73 operator ResourceHandle() const
74 {
75 return resource_handle;
76 }
77 operator HandleType() const
78 {
79 return vk_handle;
80 }
81
83 {
84 return other.resource_handle == resource_handle && other.vk_handle == vk_handle;
85 }
86 uint64_t hash() const
87 {
89 }
90};
91
92VkImageAspectFlags to_vk_image_aspect_flag_bits(const TextureFormat format);
93VkImageAspectFlags to_vk_image_aspect_flag_bits(const GPUFrameBufferBits buffers);
94VkFormat to_vk_format(const TextureFormat format);
96{
97 return to_vk_format(to_texture_format(format));
98}
99TextureFormat to_gpu_format(const VkFormat format);
100std::string to_gpu_format_string(VkFormat format);
101VkFormat to_vk_format(const GPUVertCompType type,
102 const uint32_t size,
103 const GPUVertFetchMode fetch_mode);
104VkFormat to_vk_format(const shader::Type type);
105VkQueryType to_vk_query_type(const GPUQueryType query_type);
106
107VkComponentSwizzle to_vk_component_swizzle(const char swizzle);
108VkImageViewType to_vk_image_view_type(const GPUTextureType type,
109 eImageViewUsage view_type,
110 VKImageViewArrayed arrayed);
111VkImageType to_vk_image_type(const GPUTextureType type);
112VkClearColorValue to_vk_clear_color_value(const eGPUDataFormat format, const double4 data);
113VkIndexType to_vk_index_type(const GPUIndexBufType index_type);
114VkPrimitiveTopology to_vk_primitive_topology(const GPUPrimType prim_type);
115VkCullModeFlags to_vk_cull_mode_flags(const GPUFaceCullTest cull_test);
116VkSamplerAddressMode to_vk_sampler_address_mode(const GPUSamplerExtendMode extend_mode);
117VkDescriptorType to_vk_descriptor_type(const shader::ShaderCreateInfo::Resource &resource);
118VkImageCreateFlags to_vk_image_create(const GPUTextureType texture_type,
119 const GPUTextureFormatFlag format_flag,
120 const eGPUTextureUsage usage);
121VkImageUsageFlags to_vk_image_usage(const eGPUTextureUsage usage,
122 const GPUTextureFormatFlag format_flag,
123 bool use_image_host_copy);
124
130 const GPUTextureFormatFlag format_flag);
132VkFormat vk_extended_usage_storage_image_format(const VkFormat format);
133
134template<typename T> VkObjectType to_vk_object_type(T /*vk_obj*/)
135{
136 const std::type_info &tid = typeid(T);
137#define VK_EQ_TYPEID(name, name2) \
138 if (tid == typeid(name)) { \
139 return VK_OBJECT_TYPE_##name2; \
140 }
141
142 VK_EQ_TYPEID(VkInstance, INSTANCE);
143 VK_EQ_TYPEID(VkPhysicalDevice, PHYSICAL_DEVICE);
144 VK_EQ_TYPEID(VkDevice, DEVICE);
145 VK_EQ_TYPEID(VkQueue, QUEUE);
146 VK_EQ_TYPEID(VkSemaphore, SEMAPHORE);
147 VK_EQ_TYPEID(VkCommandBuffer, COMMAND_BUFFER);
148 VK_EQ_TYPEID(VkFence, FENCE);
149 VK_EQ_TYPEID(VkDeviceMemory, DEVICE_MEMORY);
150 VK_EQ_TYPEID(VkBuffer, BUFFER);
151 VK_EQ_TYPEID(VkImage, IMAGE);
152 VK_EQ_TYPEID(VkEvent, EVENT);
153 VK_EQ_TYPEID(VkQueryPool, QUERY_POOL);
154 VK_EQ_TYPEID(VkBufferView, BUFFER_VIEW);
155 VK_EQ_TYPEID(VkImageView, IMAGE_VIEW);
156 VK_EQ_TYPEID(VkShaderModule, SHADER_MODULE);
157 VK_EQ_TYPEID(VkPipelineCache, PIPELINE_CACHE);
158 VK_EQ_TYPEID(VkPipelineLayout, PIPELINE_LAYOUT);
159 VK_EQ_TYPEID(VkRenderPass, RENDER_PASS);
160 VK_EQ_TYPEID(VkPipeline, PIPELINE);
161 VK_EQ_TYPEID(VkDescriptorSetLayout, DESCRIPTOR_SET_LAYOUT);
162 VK_EQ_TYPEID(VkSampler, SAMPLER);
163 VK_EQ_TYPEID(VkDescriptorPool, DESCRIPTOR_POOL);
164 VK_EQ_TYPEID(VkDescriptorSet, DESCRIPTOR_SET);
165 VK_EQ_TYPEID(VkFramebuffer, FRAMEBUFFER);
166 VK_EQ_TYPEID(VkCommandPool, COMMAND_POOL);
167 VK_EQ_TYPEID(VkSamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION);
168 VK_EQ_TYPEID(VkDescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE);
169 VK_EQ_TYPEID(VkSurfaceKHR, SURFACE_KHR);
170 VK_EQ_TYPEID(VkSwapchainKHR, SWAPCHAIN_KHR);
171 VK_EQ_TYPEID(VkDisplayKHR, DISPLAY_KHR);
172 VK_EQ_TYPEID(VkDisplayModeKHR, DISPLAY_MODE_KHR);
173 VK_EQ_TYPEID(VkDebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT);
174#ifdef VK_ENABLE_BETA_EXTENSIONS
175 VK_EQ_TYPEID(VkVideoSessionKHR, VIDEO_SESSION_KHR);
176#endif
177#ifdef VK_ENABLE_BETA_EXTENSIONS
178 VK_EQ_TYPEID(VkVideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KHR);
179#endif
180 VK_EQ_TYPEID(VkCuModuleNVX, CU_MODULE_NVX);
181 VK_EQ_TYPEID(VkCuFunctionNVX, CU_FUNCTION_NVX);
182 VK_EQ_TYPEID(VkDebugUtilsMessengerEXT, DEBUG_UTILS_MESSENGER_EXT);
183 VK_EQ_TYPEID(VkAccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR);
184 VK_EQ_TYPEID(VkValidationCacheEXT, VALIDATION_CACHE_EXT);
185 VK_EQ_TYPEID(VkAccelerationStructureNV, ACCELERATION_STRUCTURE_NV);
186 VK_EQ_TYPEID(VkPerformanceConfigurationINTEL, PERFORMANCE_CONFIGURATION_INTEL);
187 VK_EQ_TYPEID(VkDeferredOperationKHR, DEFERRED_OPERATION_KHR);
188 VK_EQ_TYPEID(VkIndirectCommandsLayoutNV, INDIRECT_COMMANDS_LAYOUT_NV);
189 VK_EQ_TYPEID(VkPrivateDataSlotEXT, PRIVATE_DATA_SLOT_EXT);
190
192#undef VK_EQ_TYPEID
193 return VK_OBJECT_TYPE_UNKNOWN;
194}
195
196#define NOT_YET_IMPLEMENTED \
197 printf("%s:%d `%s` not implemented yet\n", __FILE__, __LINE__, __func__);
198
199} // namespace blender::gpu
Compatibility-like things for windows.
#define BLI_assert_unreachable()
#define BLI_INLINE
#define T
VkQueryType to_vk_query_type(const GPUQueryType query_type)
Definition vk_common.cc:486
VkImageViewType to_vk_image_view_type(const GPUTextureType type, const eImageViewUsage view_type, VKImageViewArrayed arrayed)
Definition vk_common.cc:525
std::string to_gpu_format_string(VkFormat format)
Definition vk_common.cc:138
VkClearColorValue to_vk_clear_color_value(const eGPUDataFormat format, const double4 data)
Definition vk_common.cc:611
bool vk_need_extended_usage_for_storage_image(const eGPUTextureUsage usage, const GPUTextureFormatFlag format_flag)
Definition vk_common.cc:841
uint64_t TimelineValue
Definition vk_common.hh:39
VkImageUsageFlags to_vk_image_usage(const eGPUTextureUsage usage, const GPUTextureFormatFlag format_flag, bool use_image_host_copy)
Definition vk_common.cc:893
VkImageType to_vk_image_type(const GPUTextureType type)
Definition vk_common.cc:496
VkFormat to_vk_format(const TextureFormat format)
Definition vk_common.cc:157
VkIndexType to_vk_index_type(const GPUIndexBufType index_type)
Definition vk_common.cc:652
VkObjectType to_vk_object_type(T)
Definition vk_common.hh:134
VkComponentSwizzle to_vk_component_swizzle(const char swizzle)
Definition vk_common.cc:588
VkImageCreateFlags to_vk_image_create(const GPUTextureType texture_type, const GPUTextureFormatFlag format_flag, eGPUTextureUsage usage)
Definition vk_common.cc:864
VkDescriptorType to_vk_descriptor_type(const shader::ShaderCreateInfo::Resource &resource)
Definition vk_common.cc:823
VkSamplerAddressMode to_vk_sampler_address_mode(const GPUSamplerExtendMode extend_mode)
Definition vk_common.cc:712
VkPrimitiveTopology to_vk_primitive_topology(const GPUPrimType prim_type)
Definition vk_common.cc:666
VkCullModeFlags to_vk_cull_mode_flags(const GPUFaceCullTest cull_test)
Definition vk_common.cc:698
TextureFormat to_gpu_format(const VkFormat format)
Definition vk_common.cc:122
uint64_t ResourceHandle
Definition vk_common.hh:68
VkImageAspectFlags to_vk_image_aspect_flag_bits(const TextureFormat format)
Definition vk_common.cc:16
VkFormat vk_extended_usage_storage_image_format(const VkFormat format)
Definition vk_common.cc:850
constexpr TextureFormat to_texture_format(TextureTargetFormat format)
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint32_t
Definition BKE_text.h:81
BMesh const char void * data
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
VecBase< double, 4 > double4
bool operator==(const VKResourceWithHandle< HandleType > &other) const
Definition vk_common.hh:82
#define VK_EQ_TYPEID(name, name2)