Blender V5.0
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 <typeinfo>
12
13#ifdef _WIN32
14# include "BLI_winstuff.h"
15#endif
16
17#include <vulkan/vulkan.h>
18#ifdef _WIN32
19# include <vulkan/vulkan_win32.h>
20#endif
21
22#if !defined(_WIN32) or defined(_M_ARM64)
23/* Silence compilation warning on non-windows x64 systems. */
24# define VMA_EXTERNAL_MEMORY_WIN32 0
25#endif
26#include "vk_mem_alloc.h"
27
28#include "GPU_index_buffer.hh"
29#include "GPU_state.hh"
30#include "gpu_query.hh"
33
34namespace blender::gpu {
35
37
51
57
59 uint32_t mipmap_level = 0;
60 uint32_t mipmap_count = VK_REMAINING_MIP_LEVELS;
61 uint32_t layer_base = 0;
62 uint32_t layer_count = VK_REMAINING_ARRAY_LAYERS;
63};
64
65VkImageAspectFlags to_vk_image_aspect_flag_bits(const TextureFormat format);
67VkFormat to_vk_format(const TextureFormat format);
68TextureFormat to_gpu_format(const VkFormat format);
69VkFormat to_vk_format(const GPUVertCompType type,
70 const uint32_t size,
71 const GPUVertFetchMode fetch_mode);
72VkFormat to_vk_format(const shader::Type type);
73VkQueryType to_vk_query_type(const GPUQueryType query_type);
74
75VkComponentSwizzle to_vk_component_swizzle(const char swizzle);
76VkImageViewType to_vk_image_view_type(const GPUTextureType type,
77 eImageViewUsage view_type,
78 VKImageViewArrayed arrayed);
79VkImageType to_vk_image_type(const GPUTextureType type);
80VkClearColorValue to_vk_clear_color_value(const eGPUDataFormat format, const void *data);
81VkIndexType to_vk_index_type(const GPUIndexBufType index_type);
82VkPrimitiveTopology to_vk_primitive_topology(const GPUPrimType prim_type);
83VkCullModeFlags to_vk_cull_mode_flags(const GPUFaceCullTest cull_test);
84VkSamplerAddressMode to_vk_sampler_address_mode(const GPUSamplerExtendMode extend_mode);
86
87template<typename T> VkObjectType to_vk_object_type(T /*vk_obj*/)
88{
89 const std::type_info &tid = typeid(T);
90#define VK_EQ_TYPEID(name, name2) \
91 if (tid == typeid(name)) { \
92 return VK_OBJECT_TYPE_##name2; \
93 }
94
95 VK_EQ_TYPEID(VkInstance, INSTANCE);
96 VK_EQ_TYPEID(VkPhysicalDevice, PHYSICAL_DEVICE);
97 VK_EQ_TYPEID(VkDevice, DEVICE);
98 VK_EQ_TYPEID(VkQueue, QUEUE);
99 VK_EQ_TYPEID(VkSemaphore, SEMAPHORE);
100 VK_EQ_TYPEID(VkCommandBuffer, COMMAND_BUFFER);
101 VK_EQ_TYPEID(VkFence, FENCE);
102 VK_EQ_TYPEID(VkDeviceMemory, DEVICE_MEMORY);
103 VK_EQ_TYPEID(VkBuffer, BUFFER);
104 VK_EQ_TYPEID(VkImage, IMAGE);
105 VK_EQ_TYPEID(VkEvent, EVENT);
106 VK_EQ_TYPEID(VkQueryPool, QUERY_POOL);
107 VK_EQ_TYPEID(VkBufferView, BUFFER_VIEW);
108 VK_EQ_TYPEID(VkImageView, IMAGE_VIEW);
109 VK_EQ_TYPEID(VkShaderModule, SHADER_MODULE);
110 VK_EQ_TYPEID(VkPipelineCache, PIPELINE_CACHE);
111 VK_EQ_TYPEID(VkPipelineLayout, PIPELINE_LAYOUT);
112 VK_EQ_TYPEID(VkRenderPass, RENDER_PASS);
113 VK_EQ_TYPEID(VkPipeline, PIPELINE);
114 VK_EQ_TYPEID(VkDescriptorSetLayout, DESCRIPTOR_SET_LAYOUT);
115 VK_EQ_TYPEID(VkSampler, SAMPLER);
116 VK_EQ_TYPEID(VkDescriptorPool, DESCRIPTOR_POOL);
117 VK_EQ_TYPEID(VkDescriptorSet, DESCRIPTOR_SET);
118 VK_EQ_TYPEID(VkFramebuffer, FRAMEBUFFER);
119 VK_EQ_TYPEID(VkCommandPool, COMMAND_POOL);
120 VK_EQ_TYPEID(VkSamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION);
121 VK_EQ_TYPEID(VkDescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE);
122 VK_EQ_TYPEID(VkSurfaceKHR, SURFACE_KHR);
123 VK_EQ_TYPEID(VkSwapchainKHR, SWAPCHAIN_KHR);
124 VK_EQ_TYPEID(VkDisplayKHR, DISPLAY_KHR);
125 VK_EQ_TYPEID(VkDisplayModeKHR, DISPLAY_MODE_KHR);
126 VK_EQ_TYPEID(VkDebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT);
127#ifdef VK_ENABLE_BETA_EXTENSIONS
128 VK_EQ_TYPEID(VkVideoSessionKHR, VIDEO_SESSION_KHR);
129#endif
130#ifdef VK_ENABLE_BETA_EXTENSIONS
131 VK_EQ_TYPEID(VkVideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KHR);
132#endif
133 VK_EQ_TYPEID(VkCuModuleNVX, CU_MODULE_NVX);
134 VK_EQ_TYPEID(VkCuFunctionNVX, CU_FUNCTION_NVX);
135 VK_EQ_TYPEID(VkDebugUtilsMessengerEXT, DEBUG_UTILS_MESSENGER_EXT);
136 VK_EQ_TYPEID(VkAccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR);
137 VK_EQ_TYPEID(VkValidationCacheEXT, VALIDATION_CACHE_EXT);
138 VK_EQ_TYPEID(VkAccelerationStructureNV, ACCELERATION_STRUCTURE_NV);
139 VK_EQ_TYPEID(VkPerformanceConfigurationINTEL, PERFORMANCE_CONFIGURATION_INTEL);
140 VK_EQ_TYPEID(VkDeferredOperationKHR, DEFERRED_OPERATION_KHR);
141 VK_EQ_TYPEID(VkIndirectCommandsLayoutNV, INDIRECT_COMMANDS_LAYOUT_NV);
142 VK_EQ_TYPEID(VkPrivateDataSlotEXT, PRIVATE_DATA_SLOT_EXT);
143
145#undef VK_EQ_TYPEID
146 return VK_OBJECT_TYPE_UNKNOWN;
147}
148
149#define NOT_YET_IMPLEMENTED \
150 printf("%s:%d `%s` not implemented yet\n", __FILE__, __LINE__, __func__);
151
152} // namespace blender::gpu
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
Compatibility-like things for windows.
GPUFrameBufferBits
GPUPrimType
GPUFaceCullTest
Definition GPU_state.hh:135
eGPUDataFormat
GPUSamplerExtendMode
GPUVertFetchMode
GPUVertCompType
BMesh const char void * data
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define resource
format
#define T
VkQueryType to_vk_query_type(const GPUQueryType query_type)
Definition vk_common.cc:465
VkImageViewType to_vk_image_view_type(const GPUTextureType type, const eImageViewUsage view_type, VKImageViewArrayed arrayed)
Definition vk_common.cc:504
uint64_t TimelineValue
Definition vk_common.hh:36
VkImageType to_vk_image_type(const GPUTextureType type)
Definition vk_common.cc:475
VkFormat to_vk_format(const TextureFormat format)
Definition vk_common.cc:136
VkIndexType to_vk_index_type(const GPUIndexBufType index_type)
Definition vk_common.cc:633
VkObjectType to_vk_object_type(T)
Definition vk_common.hh:87
VkComponentSwizzle to_vk_component_swizzle(const char swizzle)
Definition vk_common.cc:567
VkDescriptorType to_vk_descriptor_type(const shader::ShaderCreateInfo::Resource &resource)
Definition vk_common.cc:804
VkSamplerAddressMode to_vk_sampler_address_mode(const GPUSamplerExtendMode extend_mode)
Definition vk_common.cc:693
VkPrimitiveTopology to_vk_primitive_topology(const GPUPrimType prim_type)
Definition vk_common.cc:647
VkCullModeFlags to_vk_cull_mode_flags(const GPUFaceCullTest cull_test)
Definition vk_common.cc:679
VkClearColorValue to_vk_clear_color_value(const eGPUDataFormat format, const void *data)
Definition vk_common.cc:598
TextureFormat to_gpu_format(const VkFormat format)
Definition vk_common.cc:120
VkImageAspectFlags to_vk_image_aspect_flag_bits(const TextureFormat format)
Definition vk_common.cc:14
#define VK_EQ_TYPEID(name, name2)
char * buffers[2]