4#include <vulkan/vulkan_core.h>
5#include <unordered_map>
28 PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT vkGetPhysicalDeviceCalibrateableTimeDomainsEXT =
30 PFN_vkGetCalibratedTimestampsEXT vkGetCalibratedTimestampsEXT =
nullptr;
31 PFN_vkResetQueryPool vkResetQueryPool =
nullptr;
63 static void loadVkFunction( VkInstance instance,
const std::string & name, T & functionPointer )
65 functionPointer =
reinterpret_cast<T
>( vkGetInstanceProcAddr( instance, name.c_str() ) );
67 if ( !functionPointer )
69 std::stringstream error;
70 error <<
"Vulkan INSTANCE extension function " << name <<
" is not supported!";
72 throw std::runtime_error( error.str() );
79 functionPointer =
reinterpret_cast<T
>( vkGetDeviceProcAddr( device, name.c_str() ) );
80 if ( !functionPointer )
82 std::stringstream error;
83 error <<
"Vulkan DEVICE extension function " << name <<
" is not supported!";
85 throw std::runtime_error( error.str() );
92 [[deprecated(
"Use VulkanBuffer with VMA instead")]]
95 VkPhysicalDevice physicalDevice,
97 VkBufferUsageFlags usage,
98 VkMemoryPropertyFlags properties,
100 VkDeviceMemory & bufferMemory
105 VkPhysicalDevice physicalDevice,
106 VkCommandPool commandPool,
109 const void * dataPtr,
110 VkBuffer targetBuffer
113 static bool isValid(
void *
object );
115 static std::string
strIsValid(
void *
object );
119 VkPhysicalDevice physicalDevice,
120 VkCommandPool commandPool,
123 VkBufferUsageFlags usage,
124 const void * dataPtr,
126 VkDeviceMemory & bufferMemory
131 VkPhysicalDevice physicalDevice,
132 VkCommandPool commandPool,
135 const void * dataPtr,
137 VkDeviceMemory bufferMemory
141 VkPhysicalDevice physicalDevice,
143 VkMemoryPropertyFlags properties
147 VkPhysicalDevice physicalDevice,
148 VkMemoryRequirements2 requirements,
149 VkMemoryPropertyFlags properties,
150 uint32_t & out_typeIndex
153 static VkDeviceSize
align( VkDeviceSize value, VkDeviceSize alignment );
157 VkCommandPool commandPool,
158 VkQueue graphicsQueue,
159 VkBuffer sourceBuffer,
160 VkBuffer destinationBuffer,
166 VkCommandPool commandPool,
167 VkQueue graphicsQueue,
168 const std::vector<BufferCopyObject> & bufferCopyObjects
173 VkCommandBuffer commandBuffer,
174 const std::vector<BufferCopyObject> & bufferCopyObjects
180 VkQueue graphicsQueue,
181 VkCommandPool commandPool,
182 VkCommandBuffer commandBuffer
184 static void cleanupBuffer( VkDevice device, VkBuffer buffer, VkDeviceMemory bufferMemory );
188 [[deprecated(
"Use Texture class with VMA instead")]]
191 VkPhysicalDevice physicalDevice,
195 VkImageTiling tiling,
196 VkImageUsageFlags usage,
197 VkMemoryPropertyFlags properties,
199 VkDeviceMemory & imageMemory
203 VkCommandBuffer commandBuffer,
205 VkQueue graphicsQueue,
206 VkCommandPool commandPool,
209 VkImageLayout oldLayout,
210 VkImageLayout newLayout,
211 uint32_t layerCount = 1
218 VkCommandPool commandPool,
219 VkQueue graphicsQueue,
227 createImageView( VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags );
233 const VkDescriptorSetAllocateInfo * pAllocateInfo,
234 VkDescriptorSet * pDescriptorSets,
235 const std::string & name
240 const VkSemaphoreCreateInfo * pCreateInfo,
241 const VkAllocationCallbacks * pAllocator,
242 VkSemaphore * pSemaphore,
243 const std::string & name
248 const VkCommandBufferAllocateInfo * pAllocateInfo,
249 VkCommandBuffer * pCommandBuffers,
250 const std::string & name
255 const VkDescriptorSetLayoutCreateInfo * pCreateInfo,
256 const VkAllocationCallbacks * pAllocator,
257 VkDescriptorSetLayout * pSetLayout,
258 const std::string & name
263 const VkPipelineLayoutCreateInfo * pCreateInfo,
264 const VkAllocationCallbacks * pAllocator,
265 VkPipelineLayout * pPipelineLayout,
266 const std::string & name
271 const VkFenceCreateInfo * pCreateInfo,
272 const VkAllocationCallbacks * pAllocator,
274 const std::string & name
279 const VkDescriptorPoolCreateInfo * pCreateInfo,
280 const VkAllocationCallbacks * pAllocator,
281 VkDescriptorPool * pDescriptorPool,
282 const std::string & name
286 static std::string
getName(
const std::string & name,
const std::string & suffix );
299 beginLabel( VkCommandBuffer commandBuffer,
const char * pLabelName,
const float color[4] =
nullptr );
306 static void endLabel( VkCommandBuffer commandBuffer );
309 static std::unordered_map<uint64_t, std::string> objectNames;
313 static void beginLabel( VkCommandBuffer,
const char *,
const float * ) {}
321# define VK_OBJECT_TYPE_CASE( VkType, VkEnum ) \
322 if constexpr ( std::is_same_v<VulkanObjectType, VkType> ) \
325 template <
typename VulkanObjectType>
326 static constexpr VkObjectType getVulkanObjectType()
328 VK_OBJECT_TYPE_CASE( VkBuffer, VK_OBJECT_TYPE_BUFFER );
329 VK_OBJECT_TYPE_CASE( VkQueue, VK_OBJECT_TYPE_QUEUE );
330 VK_OBJECT_TYPE_CASE( VkDescriptorPool, VK_OBJECT_TYPE_DESCRIPTOR_POOL );
331 VK_OBJECT_TYPE_CASE( VkDescriptorSetLayout, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT );
332 VK_OBJECT_TYPE_CASE( VkDescriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET );
333 VK_OBJECT_TYPE_CASE( VkPipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT );
334 VK_OBJECT_TYPE_CASE( VkPipeline, VK_OBJECT_TYPE_PIPELINE );
335 VK_OBJECT_TYPE_CASE( VkCommandBuffer, VK_OBJECT_TYPE_COMMAND_BUFFER );
336 VK_OBJECT_TYPE_CASE( VkSemaphore, VK_OBJECT_TYPE_SEMAPHORE );
337 VK_OBJECT_TYPE_CASE( VkFence, VK_OBJECT_TYPE_FENCE );
338 VK_OBJECT_TYPE_CASE( VkImage, VK_OBJECT_TYPE_IMAGE );
339 VK_OBJECT_TYPE_CASE( VkDeviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY );
340 VK_OBJECT_TYPE_CASE( VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW );
341 VK_OBJECT_TYPE_CASE( VkSampler, VK_OBJECT_TYPE_SAMPLER );
342 VK_OBJECT_TYPE_CASE( VkRenderPass, VK_OBJECT_TYPE_RENDER_PASS );
343 VK_OBJECT_TYPE_CASE( VkShaderModule, VK_OBJECT_TYPE_SHADER_MODULE );
344 VK_OBJECT_TYPE_CASE( VkCommandPool, VK_OBJECT_TYPE_COMMAND_POOL );
346 PLOGF <<
"Failed to find the type of " <<
typeid( VulkanObjectType ).name();
347 return VK_OBJECT_TYPE_UNKNOWN;
360 template <
typename VulkanObjectType>
361 static void setObjectName( VkDevice device, VulkanObjectType objectHandle,
const std::string & name );
363 template <
typename VulkanObjectType>
364 static std::string
getDebugName ( VulkanObjectType objectHandle );
366 template <
typename VulkanObjectType>
367 static void setObjectName( VkDevice device, VulkanObjectType objectHandle,
const std::string & name )
371 template <
typename VulkanObjectType>
385template <
typename VulkanObjectType>
395 VkDebugUtilsObjectNameInfoEXT nameInfo = {};
396 nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
397 nameInfo.objectHandle =
reinterpret_cast<uint64_t
>( objectHandle );
398 nameInfo.objectType = VulkanHelper::getVulkanObjectType<VulkanObjectType>();
399 nameInfo.pObjectName = name.c_str();
402 s_functions.vkSetDebugUtilsObjectNameEXT( device, &nameInfo );
404 objectNames.insert( {
reinterpret_cast<uint64_t
>(objectHandle), name} );
407template <
typename VulkanObjectType>
410 const auto objectHandle64 =
reinterpret_cast<uint64_t
>( objectHandle );
411 if (!objectNames.contains( objectHandle64 ) )
413 return "Unnamed Object";
415 return objectNames.find( objectHandle64 )->second;
436 DebugLabel( VkCommandBuffer commandBuffer,
const char * pLabelName,
const float color[4] =
nullptr )
437 : m_commandBuffer( commandBuffer )
448 DebugLabel( VkCommandBuffer,
const char *,
const float * =
nullptr ) {}
461 VkCommandBuffer m_commandBuffer;
@ DEBUG_FUNCTIONS_INITIALIZED
DebugLabel(const DebugLabel &)=delete
DebugLabel & operator=(const DebugLabel &)=delete
DebugLabel(VkCommandBuffer, const char *, const float *=nullptr)
DebugLabel(DebugLabel &&)=delete
DebugLabel & operator=(DebugLabel &&)=delete
The application context is the core class which stores the basic openxr and vulkan objects.
Stores lots of different functions which shorten the amount of code which needs to be written for def...
static VkResult createPipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkPipelineLayout *pPipelineLayout, const std::string &name)
static void createBufferWithStaging(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, VkQueue queue, VkDeviceSize size, VkBufferUsageFlags usage, const void *dataPtr, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
static void endSingleTimeCommands(VkDevice device, VkQueue graphicsQueue, VkCommandPool commandPool, VkCommandBuffer commandBuffer)
static void initializeDebugFunctions(VkInstance instance)
static VkImageView createImageView(VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags)
static void copyDataToBufferViaStaging(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, VkQueue queue, VkDeviceSize size, const void *dataPtr, VkBuffer buffer, VkDeviceMemory bufferMemory)
static VkDeviceSize align(VkDeviceSize value, VkDeviceSize alignment)
static bool findSuitableMemoryType(VkPhysicalDevice physicalDevice, VkMemoryRequirements2 requirements, VkMemoryPropertyFlags properties, uint32_t &out_typeIndex)
static void loadVkDeviceFunction(VkDevice device, const std::string &name, T &functionPointer)
static std::string strIsValid(void *object)
static std::string getDebugName(VulkanObjectType objectHandle)
static void copyBufferToImage(VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, VkBuffer buffer, VkImage image, uint32_t width, uint32_t height)
static void recordBufferCopyMultiple(EngineCore::ApplicationContext *context, VkCommandBuffer commandBuffer, const std::vector< BufferCopyObject > &bufferCopyObjects)
static DynamicFunctionInitState s_functionInitializationState
static void copyBuffer(VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, VkBuffer sourceBuffer, VkBuffer destinationBuffer, VkDeviceSize size)
static VulkanFunctions s_functions
static void endLabel(VkCommandBuffer)
static void createFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkFence *pFence, const std::string &name)
static VkResult allocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers, const std::string &name)
static VkResult createSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, const std::string &name)
static void uploadDataToExistingBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, VkQueue queue, VkDeviceSize size, const void *dataPtr, VkBuffer targetBuffer)
static bool isValid(void *object)
static void transitionImageLayout(VkCommandBuffer commandBuffer, VkDevice device, VkQueue graphicsQueue, VkCommandPool commandPool, VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t layerCount=1)
static void setObjectName(VkDevice device, VulkanObjectType objectHandle, const std::string &name)
static void loadVkFunction(VkInstance instance, const std::string &name, T &functionPointer)
static uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties)
static void cleanupBuffer(VkDevice device, VkBuffer buffer, VkDeviceMemory bufferMemory)
static bool hasStencilComponent(VkFormat format)
static VkResult allocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, VkDescriptorSet *pDescriptorSets, const std::string &name)
static VkDescriptorBufferInfo fullBufferInfo(VkBuffer buffer)
static VkResult createDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool, const std::string &name)
static std::string getName(const std::string &name, const std::string &suffix)
static void initializeFunctions(VkInstance instance, VkDevice device)
static const VulkanFunctions & getFunctions()
static void createBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
static void beginLabel(VkCommandBuffer, const char *, const float *)
static std::mutex s_mutex
static VkResult createDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout, const std::string &name)
static void createImage(VkDevice device, VkPhysicalDevice physicalDevice, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &imageMemory)
static void copyBufferMultiple(VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, const std::vector< BufferCopyObject > &bufferCopyObjects)
static VkCommandBuffer beginSingleTimeCommands(VkDevice device, VkCommandPool commandPool)
Log category system implementation.
VkDeviceSize srcOffset
Offset in source buffer (usually 0 for staging)
VkDeviceSize dstOffset
Offset in destination buffer (for partial uploads)
VkBuffer destinationBuffer
PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT
PFN_vkCmdEndConditionalRenderingEXT vkCmdEndConditionalRenderingEXT
PFN_vkCmdDrawMeshTasksIndirectEXT vkCmdDrawMeshTasksIndirectEXT
PFN_vkCmdBindDescriptorSets2 vkCmdBindDescriptorSets2
PFN_vkCmdBeginConditionalRenderingEXT vkCmdBeginConditionalRenderingEXT
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT
PFN_vkCmdPushConstants2 vkCmdPushConstants2
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT
PFN_vkCmdDrawMeshTasksIndirectCountEXT vkCmdDrawMeshTasksIndirectCountEXT
PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT
PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT