4#include <vulkan/vulkan_core.h>
5#include <unordered_map>
14 class ApplicationContext;
32 PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT vkGetPhysicalDeviceCalibrateableTimeDomainsEXT =
34 PFN_vkGetCalibratedTimestampsEXT vkGetCalibratedTimestampsEXT =
nullptr;
35 PFN_vkResetQueryPool vkResetQueryPool =
nullptr;
43 VkDeviceSize
size = VK_WHOLE_SIZE;
67 static void loadVkFunction( VkInstance instance,
const std::string & name, T & functionPointer )
69 functionPointer =
reinterpret_cast<T
>( vkGetInstanceProcAddr( instance, name.c_str() ) );
71 if ( !functionPointer )
73 std::stringstream error;
74 error <<
"Vulkan INSTANCE extension function " << name <<
" is not supported!";
76 throw std::runtime_error( error.str() );
83 functionPointer =
reinterpret_cast<T
>( vkGetDeviceProcAddr( device, name.c_str() ) );
84 if ( !functionPointer )
86 std::stringstream error;
87 error <<
"Vulkan DEVICE extension function " << name <<
" is not supported!";
89 throw std::runtime_error( error.str() );
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
118 VkPhysicalDevice physicalDevice,
120 VkMemoryPropertyFlags properties
124 VkPhysicalDevice physicalDevice,
125 VkMemoryRequirements2 requirements,
126 VkMemoryPropertyFlags properties,
127 uint32_t & out_typeIndex
130 static VkDeviceSize
align( VkDeviceSize value, VkDeviceSize alignment );
134 VkCommandPool commandPool,
135 VkQueue graphicsQueue,
136 VkBuffer sourceBuffer,
137 VkBuffer destinationBuffer,
143 VkCommandPool commandPool,
144 VkQueue graphicsQueue,
145 const std::vector<BufferCopyObject> & bufferCopyObjects
150 VkCommandBuffer commandBuffer,
151 const std::vector<BufferCopyObject> & bufferCopyObjects
157 VkQueue graphicsQueue,
158 VkCommandPool commandPool,
159 VkCommandBuffer commandBuffer
161 static void cleanupBuffer( VkDevice device, VkBuffer buffer, VkDeviceMemory bufferMemory );
164 VkPhysicalDevice physicalDevice,
168 VkImageTiling tiling,
169 VkImageUsageFlags usage,
170 VkMemoryPropertyFlags properties,
172 VkDeviceMemory & imageMemory
176 VkCommandBuffer commandBuffer,
178 VkQueue graphicsQueue,
179 VkCommandPool commandPool,
182 VkImageLayout oldLayout,
183 VkImageLayout newLayout,
184 uint32_t layerCount = 1
191 VkCommandPool commandPool,
192 VkQueue graphicsQueue,
200 createImageView( VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags );
206 const VkDescriptorSetAllocateInfo * pAllocateInfo,
207 VkDescriptorSet * pDescriptorSets,
208 const std::string & name
213 const VkSemaphoreCreateInfo * pCreateInfo,
214 const VkAllocationCallbacks * pAllocator,
215 VkSemaphore * pSemaphore,
216 const std::string & name
221 const VkCommandBufferAllocateInfo * pAllocateInfo,
222 VkCommandBuffer * pCommandBuffers,
223 const std::string & name
228 const VkDescriptorSetLayoutCreateInfo * pCreateInfo,
229 const VkAllocationCallbacks * pAllocator,
230 VkDescriptorSetLayout * pSetLayout,
231 const std::string & name
236 const VkPipelineLayoutCreateInfo * pCreateInfo,
237 const VkAllocationCallbacks * pAllocator,
238 VkPipelineLayout * pPipelineLayout,
239 const std::string & name
244 const VkFenceCreateInfo * pCreateInfo,
245 const VkAllocationCallbacks * pAllocator,
247 const std::string & name
252 const VkDescriptorPoolCreateInfo * pCreateInfo,
253 const VkAllocationCallbacks * pAllocator,
254 VkDescriptorPool * pDescriptorPool,
255 const std::string & name
259 static std::string
getName(
const std::string & name,
const std::string & suffix );
272 beginLabel( VkCommandBuffer commandBuffer,
const char * pLabelName,
const float color[4] =
nullptr );
279 static void endLabel( VkCommandBuffer commandBuffer );
282 static std::unordered_map<uint64_t, std::string> objectNames;
286 static void beginLabel( VkCommandBuffer,
const char *,
const float * ) {}
294# define VK_OBJECT_TYPE_CASE( VkType, VkEnum ) \
295 if constexpr ( std::is_same_v<VulkanObjectType, VkType> ) \
298 template <
typename VulkanObjectType>
299 static constexpr VkObjectType getVulkanObjectType()
301 VK_OBJECT_TYPE_CASE( VkBuffer, VK_OBJECT_TYPE_BUFFER );
302 VK_OBJECT_TYPE_CASE( VkQueue, VK_OBJECT_TYPE_QUEUE );
303 VK_OBJECT_TYPE_CASE( VkDescriptorPool, VK_OBJECT_TYPE_DESCRIPTOR_POOL );
304 VK_OBJECT_TYPE_CASE( VkDescriptorSetLayout, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT );
305 VK_OBJECT_TYPE_CASE( VkDescriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET );
306 VK_OBJECT_TYPE_CASE( VkPipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT );
307 VK_OBJECT_TYPE_CASE( VkPipeline, VK_OBJECT_TYPE_PIPELINE );
308 VK_OBJECT_TYPE_CASE( VkCommandBuffer, VK_OBJECT_TYPE_COMMAND_BUFFER );
309 VK_OBJECT_TYPE_CASE( VkSemaphore, VK_OBJECT_TYPE_SEMAPHORE );
310 VK_OBJECT_TYPE_CASE( VkFence, VK_OBJECT_TYPE_FENCE );
311 VK_OBJECT_TYPE_CASE( VkImage, VK_OBJECT_TYPE_IMAGE );
312 VK_OBJECT_TYPE_CASE( VkDeviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY );
313 VK_OBJECT_TYPE_CASE( VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW );
314 VK_OBJECT_TYPE_CASE( VkSampler, VK_OBJECT_TYPE_SAMPLER );
315 VK_OBJECT_TYPE_CASE( VkRenderPass, VK_OBJECT_TYPE_RENDER_PASS );
316 VK_OBJECT_TYPE_CASE( VkShaderModule, VK_OBJECT_TYPE_SHADER_MODULE );
317 VK_OBJECT_TYPE_CASE( VkCommandPool, VK_OBJECT_TYPE_COMMAND_POOL );
319 PLOGF <<
"Failed to find the type of " <<
typeid( VulkanObjectType ).name();
320 return VK_OBJECT_TYPE_UNKNOWN;
333 template <
typename VulkanObjectType>
334 static void setObjectName( VkDevice device, VulkanObjectType objectHandle,
const std::string & name );
336 template <
typename VulkanObjectType>
337 static std::string
getDebugName ( VulkanObjectType objectHandle );
339 template <
typename VulkanObjectType>
340 static void setObjectName( VkDevice device, VulkanObjectType objectHandle,
const std::string & name )
344 template <
typename VulkanObjectType>
358template <
typename VulkanObjectType>
368 VkDebugUtilsObjectNameInfoEXT nameInfo = {};
369 nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
370 nameInfo.objectHandle =
reinterpret_cast<uint64_t
>( objectHandle );
371 nameInfo.objectType = VulkanHelper::getVulkanObjectType<VulkanObjectType>();
372 nameInfo.pObjectName = name.c_str();
375 s_functions.vkSetDebugUtilsObjectNameEXT( device, &nameInfo );
377 objectNames.insert( {
reinterpret_cast<uint64_t
>(objectHandle), name} );
380template <
typename VulkanObjectType>
383 const auto objectHandle64 =
reinterpret_cast<uint64_t
>( objectHandle );
384 if (!objectNames.contains( objectHandle64 ) )
386 return "Unnamed Object";
388 return objectNames.find( objectHandle64 )->second;
409 DebugLabel( VkCommandBuffer commandBuffer,
const char * pLabelName,
const float color[4] =
nullptr )
410 : m_commandBuffer( commandBuffer )
421 DebugLabel( VkCommandBuffer,
const char *,
const float * =
nullptr ) {}
434 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 VkDescriptorBufferInfo fullBufferInfo(VkBuffer buffer)
static std::string getName(const std::string &name, const std::string &suffix)
static VkResult createPipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkPipelineLayout *pPipelineLayout, const std::string &name)
static bool hasStencilComponent(VkFormat format)
static void initializeFunctions(VkInstance instance, VkDevice device)
static void loadVkDeviceFunction(VkDevice device, const std::string &name, T &functionPointer)
static std::string getDebugName(VulkanObjectType objectHandle)
static void copyBuffer(VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, VkBuffer sourceBuffer, VkBuffer destinationBuffer, VkDeviceSize size)
static VkResult createSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, const std::string &name)
static std::string strIsValid(void *object)
static DynamicFunctionInitState s_functionInitializationState
static VulkanFunctions s_functions
static const VulkanFunctions & getFunctions()
static void endLabel(VkCommandBuffer)
static VkImageView createImageView(VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags)
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 bool isValid(void *object)
static void copyBufferMultiple(VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, const std::vector< BufferCopyObject > &bufferCopyObjects)
static VkDeviceSize align(VkDeviceSize value, VkDeviceSize alignment)
static VkCommandBuffer beginSingleTimeCommands(VkDevice device, VkCommandPool commandPool)
static void setObjectName(VkDevice device, VulkanObjectType objectHandle, const std::string &name)
static void loadVkFunction(VkInstance instance, const std::string &name, T &functionPointer)
static VkResult allocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, VkDescriptorSet *pDescriptorSets, const std::string &name)
static void recordBufferCopyMultiple(Engine::Core::ApplicationContext *context, VkCommandBuffer commandBuffer, const std::vector< BufferCopyObject > &bufferCopyObjects)
static void initializeDebugFunctions(VkInstance instance)
static void endSingleTimeCommands(VkDevice device, VkQueue graphicsQueue, VkCommandPool commandPool, VkCommandBuffer commandBuffer)
static void copyBufferToImage(VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, VkBuffer buffer, VkImage image, uint32_t width, uint32_t height)
static uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties)
static void createBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
static VkResult createDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool, const std::string &name)
static void createFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkFence *pFence, const std::string &name)
static VkResult createDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout, const std::string &name)
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 cleanupBuffer(VkDevice device, VkBuffer buffer, VkDeviceMemory bufferMemory)
static void beginLabel(VkCommandBuffer, const char *, const float *)
static void uploadDataToExistingBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, VkQueue queue, VkDeviceSize size, const void *dataPtr, VkBuffer targetBuffer)
static std::mutex s_mutex
static bool findSuitableMemoryType(VkPhysicalDevice physicalDevice, VkMemoryRequirements2 requirements, VkMemoryPropertyFlags properties, uint32_t &out_typeIndex)
static VkResult allocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers, const std::string &name)
Core audio subsystem owning the miniaudio engine and managing playback.
VkDeviceSize dstOffset
Offset in source buffer (usually 0 for staging)
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