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;
57 VkDeviceSize
size = VK_WHOLE_SIZE;
89 static void loadVkFunction( VkInstance instance,
const std::string & name, T & functionPointer )
91 functionPointer =
reinterpret_cast<T
>( vkGetInstanceProcAddr( instance, name.c_str() ) );
93 if ( !functionPointer )
95 std::stringstream error;
96 error <<
"Vulkan INSTANCE extension function " << name <<
" is not supported!";
98 throw std::runtime_error( error.str() );
102 template <
typename T>
105 functionPointer =
reinterpret_cast<T
>( vkGetDeviceProcAddr( device, name.c_str() ) );
106 if ( !functionPointer )
108 std::stringstream error;
109 error <<
"Vulkan DEVICE extension function " << name <<
" is not supported!";
110 PLOGE << error.str();
111 throw std::runtime_error( error.str() );
117 VkPhysicalDevice physicalDevice,
119 VkBufferUsageFlags usage,
120 VkMemoryPropertyFlags properties,
122 VkDeviceMemory & bufferMemory
127 VkPhysicalDevice physicalDevice,
128 VkCommandPool commandPool,
131 const void * dataPtr,
132 VkBuffer targetBuffer
140 VkPhysicalDevice physicalDevice,
142 VkMemoryPropertyFlags properties
146 VkPhysicalDevice physicalDevice,
147 VkMemoryRequirements2 requirements,
148 VkMemoryPropertyFlags properties,
149 uint32_t & out_typeIndex
152 static VkDeviceSize
align( VkDeviceSize value, VkDeviceSize alignment );
156 VkCommandPool commandPool,
157 VkQueue graphicsQueue,
158 VkBuffer sourceBuffer,
159 VkBuffer destinationBuffer,
165 VkCommandPool commandPool,
166 VkQueue graphicsQueue,
167 const std::vector<BufferCopyObject> & bufferCopyObjects
172 VkCommandBuffer commandBuffer,
173 const std::vector<BufferCopyObject> & bufferCopyObjects
179 VkQueue graphicsQueue,
180 VkCommandPool commandPool,
181 VkCommandBuffer commandBuffer
183 static void cleanupBuffer( VkDevice device, VkBuffer buffer, VkDeviceMemory bufferMemory );
186 VkPhysicalDevice physicalDevice,
190 VkImageTiling tiling,
191 VkImageUsageFlags usage,
192 VkMemoryPropertyFlags properties,
194 VkDeviceMemory & imageMemory
198 VkCommandBuffer commandBuffer,
200 VkQueue graphicsQueue,
201 VkCommandPool commandPool,
204 VkImageLayout oldLayout,
205 VkImageLayout newLayout,
206 uint32_t layerCount = 1
213 VkCommandPool commandPool,
214 VkQueue graphicsQueue,
222 createImageView( VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags );
228 const VkDescriptorSetAllocateInfo * pAllocateInfo,
229 VkDescriptorSet * pDescriptorSets,
230 const std::string & name
235 const VkSemaphoreCreateInfo * pCreateInfo,
236 const VkAllocationCallbacks * pAllocator,
237 VkSemaphore * pSemaphore,
238 const std::string & name
243 const VkCommandBufferAllocateInfo * pAllocateInfo,
244 VkCommandBuffer * pCommandBuffers,
245 const std::string & name
250 const VkDescriptorSetLayoutCreateInfo * pCreateInfo,
251 const VkAllocationCallbacks * pAllocator,
252 VkDescriptorSetLayout * pSetLayout,
253 const std::string & name
258 const VkPipelineLayoutCreateInfo * pCreateInfo,
259 const VkAllocationCallbacks * pAllocator,
260 VkPipelineLayout * pPipelineLayout,
261 const std::string & name
266 const VkFenceCreateInfo * pCreateInfo,
267 const VkAllocationCallbacks * pAllocator,
269 const std::string & name
274 const VkDescriptorPoolCreateInfo * pCreateInfo,
275 const VkAllocationCallbacks * pAllocator,
276 VkDescriptorPool * pDescriptorPool,
277 const std::string & name
281 static std::string
getName(
const std::string & name,
const std::string & suffix );
294 beginLabel( VkCommandBuffer commandBuffer,
const char * pLabelName,
const float color[4] =
nullptr );
301 static void endLabel( VkCommandBuffer commandBuffer );
304 static std::unordered_map<uint64_t, std::string> objectNames;
308 static void beginLabel( VkCommandBuffer,
const char *,
const float * ) {}
316# define VK_OBJECT_TYPE_CASE( VkType, VkEnum ) \
317 if constexpr ( std::is_same_v<VulkanObjectType, VkType> ) \
320 template <
typename VulkanObjectType>
321 static constexpr VkObjectType getVulkanObjectType()
323 VK_OBJECT_TYPE_CASE( VkBuffer, VK_OBJECT_TYPE_BUFFER );
324 VK_OBJECT_TYPE_CASE( VkQueue, VK_OBJECT_TYPE_QUEUE );
325 VK_OBJECT_TYPE_CASE( VkDescriptorPool, VK_OBJECT_TYPE_DESCRIPTOR_POOL );
326 VK_OBJECT_TYPE_CASE( VkDescriptorSetLayout, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT );
327 VK_OBJECT_TYPE_CASE( VkDescriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET );
328 VK_OBJECT_TYPE_CASE( VkPipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT );
329 VK_OBJECT_TYPE_CASE( VkPipeline, VK_OBJECT_TYPE_PIPELINE );
330 VK_OBJECT_TYPE_CASE( VkCommandBuffer, VK_OBJECT_TYPE_COMMAND_BUFFER );
331 VK_OBJECT_TYPE_CASE( VkSemaphore, VK_OBJECT_TYPE_SEMAPHORE );
332 VK_OBJECT_TYPE_CASE( VkFence, VK_OBJECT_TYPE_FENCE );
333 VK_OBJECT_TYPE_CASE( VkImage, VK_OBJECT_TYPE_IMAGE );
334 VK_OBJECT_TYPE_CASE( VkDeviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY );
335 VK_OBJECT_TYPE_CASE( VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW );
336 VK_OBJECT_TYPE_CASE( VkSampler, VK_OBJECT_TYPE_SAMPLER );
337 VK_OBJECT_TYPE_CASE( VkRenderPass, VK_OBJECT_TYPE_RENDER_PASS );
338 VK_OBJECT_TYPE_CASE( VkShaderModule, VK_OBJECT_TYPE_SHADER_MODULE );
339 VK_OBJECT_TYPE_CASE( VkCommandPool, VK_OBJECT_TYPE_COMMAND_POOL );
341 PLOGF <<
"Failed to find the type of " <<
typeid( VulkanObjectType ).name();
342 return VK_OBJECT_TYPE_UNKNOWN;
355 template <
typename VulkanObjectType>
356 static void setObjectName( VkDevice device, VulkanObjectType objectHandle,
const std::string & name );
358 template <
typename VulkanObjectType>
359 static std::string
getDebugName ( VulkanObjectType objectHandle );
361 template <
typename VulkanObjectType>
362 static void setObjectName( VkDevice device, VulkanObjectType objectHandle,
const std::string & name )
366 template <
typename VulkanObjectType>
380template <
typename VulkanObjectType>
390 VkDebugUtilsObjectNameInfoEXT nameInfo = {};
391 nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
392 nameInfo.objectHandle =
reinterpret_cast<uint64_t
>( objectHandle );
393 nameInfo.objectType = VulkanHelper::getVulkanObjectType<VulkanObjectType>();
394 nameInfo.pObjectName = name.c_str();
397 s_functions.vkSetDebugUtilsObjectNameEXT( device, &nameInfo );
399 objectNames.insert( {
reinterpret_cast<uint64_t
>(objectHandle), name} );
402template <
typename VulkanObjectType>
405 const auto objectHandle64 =
reinterpret_cast<uint64_t
>( objectHandle );
406 if (!objectNames.contains( objectHandle64 ) )
408 return "Unnamed Object";
410 return objectNames.find( objectHandle64 )->second;
431 DebugLabel( VkCommandBuffer commandBuffer,
const char * pLabelName,
const float color[4] =
nullptr )
432 : m_commandBuffer( commandBuffer )
443 DebugLabel( VkCommandBuffer,
const char *,
const float * =
nullptr ) {}
456 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)
Manages IBL (Image-Based Lighting) resources for specular reflections.
Description of one buffer copy operation.
VkBuffer sourceBuffer
Source buffer for the copy.
VkDeviceSize srcOffset
Byte offset in the source buffer.
VkDeviceSize size
Number of bytes to copy.
VkDeviceSize dstOffset
Offset in source buffer (usually 0 for staging)
VkBuffer destinationBuffer
Destination buffer for the copy.
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