|
Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
|
Static helpers for common Vulkan allocation, copy, descriptor, and debug operations. More...
#include <VulkanHelper.h>
Static Public Member Functions | |
| static void | initializeDebugFunctions (VkInstance instance) |
| Loads debug utils extension functions from an instance. | |
| static void | initializeFunctions (VkInstance instance, VkDevice device) |
| Loads all Vulkan extension functions used by the engine. | |
| static const VulkanFunctions & | getFunctions () |
| Returns the loaded Vulkan extension function table. | |
| template<typename T> | |
| static void | loadVkFunction (VkInstance instance, const std::string &name, T &functionPointer) |
| Loads one Vulkan instance-level function pointer. | |
| template<typename T> | |
| static void | loadVkDeviceFunction (VkDevice device, const std::string &name, T &functionPointer) |
| Loads one Vulkan device-level function pointer. | |
| static void | createBuffer (VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory) |
| Creates a Vulkan buffer, allocates memory for it, and binds the memory at offset 0. | |
| static void | uploadDataToExistingBuffer (VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, VkQueue queue, VkDeviceSize size, const void *dataPtr, VkBuffer targetBuffer) |
| Uploads CPU memory into an existing buffer through a temporary staging buffer. | |
| static bool | isValid (void *object) |
| Checks whether a Vulkan dispatchable handle value is non-null. | |
| static std::string | strIsValid (void *object) |
| Returns a checkmark or cross string for a Vulkan dispatchable handle value. | |
| static uint32_t | findMemoryType (VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties) |
| Finds a memory type index that satisfies a bitmask and required properties. | |
| static bool | findSuitableMemoryType (VkPhysicalDevice physicalDevice, VkMemoryRequirements2 requirements, VkMemoryPropertyFlags properties, uint32_t &out_typeIndex) |
| Finds a memory type index without throwing on failure. | |
| static VkDeviceSize | align (VkDeviceSize value, VkDeviceSize alignment) |
| Rounds a size up to the next multiple of an alignment. | |
| static void | copyBuffer (VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, VkBuffer sourceBuffer, VkBuffer destinationBuffer, VkDeviceSize size) |
| Copies bytes from one buffer to another and waits for the queue to become idle. | |
| static void | copyBufferMultiple (VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, const std::vector< BufferCopyObject > &bufferCopyObjects) |
| Copies several buffer regions in one command buffer and waits for the queue to become idle. | |
| static void | recordBufferCopyMultiple (Engine::Core::ApplicationContext *context, VkCommandBuffer commandBuffer, const std::vector< BufferCopyObject > &bufferCopyObjects) |
| Records several buffer copy commands into an existing command buffer. | |
| static VkCommandBuffer | beginSingleTimeCommands (VkDevice device, VkCommandPool commandPool) |
| Allocates and begins a primary command buffer for one-time submission. | |
| static void | endSingleTimeCommands (VkDevice device, VkQueue graphicsQueue, VkCommandPool commandPool, VkCommandBuffer commandBuffer) |
| Ends, submits, waits for, and frees a one-time command buffer. | |
| static void | cleanupBuffer (VkDevice device, VkBuffer buffer, VkDeviceMemory bufferMemory) |
| Destroys a buffer and frees its memory when the handles are non-null. | |
| 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) |
| Creates a 2D image, allocates memory for it, and binds the memory at offset 0. | |
| static void | transitionImageLayout (VkCommandBuffer commandBuffer, VkDevice device, VkQueue graphicsQueue, VkCommandPool commandPool, VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t layerCount=1) |
| Records an image layout transition barrier into an existing command buffer. | |
| static bool | hasStencilComponent (VkFormat format) |
| Checks whether a Vulkan format contains a stencil component. | |
| static void | copyBufferToImage (VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, VkBuffer buffer, VkImage image, uint32_t width, uint32_t height) |
| Copies a buffer into the first layer and mip level of a 2D image. | |
| static VkImageView | createImageView (VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags) |
| Creates a 2D image view over one mip level and one array layer. | |
| static VkDescriptorBufferInfo | fullBufferInfo (VkBuffer buffer) |
| Creates descriptor buffer info for a whole buffer binding. | |
| static VkResult | allocateDescriptorSets (VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, VkDescriptorSet *pDescriptorSets, const std::string &name) |
| Allocates descriptor sets and assigns a debug name to the first returned set. | |
| static VkResult | createSemaphore (VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, const std::string &name) |
| Creates a semaphore and assigns a debug name. | |
| static VkResult | allocateCommandBuffers (VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers, const std::string &name) |
| Allocates command buffers and assigns a debug name to the first returned command buffer. | |
| static VkResult | createDescriptorSetLayout (VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout, const std::string &name) |
| Creates a descriptor set layout and assigns a debug name. | |
| static VkResult | createPipelineLayout (VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkPipelineLayout *pPipelineLayout, const std::string &name) |
| Creates a pipeline layout and assigns a debug name. | |
| static void | createFence (VkDevice device, const VkFenceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkFence *pFence, const std::string &name) |
| Creates a fence and assigns a debug name. | |
| static VkResult | createDescriptorPool (VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool, const std::string &name) |
| Creates a descriptor pool and assigns a debug name. | |
| static void | beginLabel (VkCommandBuffer, const char *, const float *) |
| Release-build no-op for beginning a Vulkan debug label region. | |
| static void | endLabel (VkCommandBuffer) |
| Release-build no-op for ending a Vulkan debug label region. | |
| template<typename VulkanObjectType> | |
| static void | setObjectName (VkDevice device, VulkanObjectType objectHandle, const std::string &name) |
| Release-build no-op for assigning a Vulkan object debug name. | |
| template<typename VulkanObjectType> | |
| static std::string | getDebugName (VulkanObjectType objectHandle) |
| Release-build no-op for retrieving a Vulkan object debug name. | |
Static Private Member Functions | |
| static std::string | getName (const std::string &name, const std::string &suffix) |
| Appends an object-type suffix to a debug name. | |
Static Private Attributes | |
| static VulkanFunctions | s_functions |
| static DynamicFunctionInitState | s_functionInitializationState |
| static std::mutex | s_mutex |
Static helpers for common Vulkan allocation, copy, descriptor, and debug operations.
The helper does not own Vulkan objects unless a function explicitly creates an object and returns it through an output parameter. Destroy buffers, images, image views, descriptor pools, descriptor set layouts, pipeline layouts, fences, semaphores, and command pools with the matching Vulkan destroy call.
Definition at line 93 of file VulkanHelper.h.
|
static |
Rounds a size up to the next multiple of an alignment.
| value | Value to align in bytes. |
| alignment | Alignment in bytes. Must be a non-zero power of two. |
value rounded up to alignment, or 0 when value is 0.
|
static |
Allocates command buffers and assigns a debug name to the first returned command buffer.
| device | Logical device that owns the command pool referenced by pAllocateInfo. |
| pAllocateInfo | Vulkan command buffer allocation info. |
| pCommandBuffers | Output command buffer array. |
| name | Base debug name. The helper appends a command-buffer suffix. |
| std::runtime_error | when vkAllocateCommandBuffers fails. |
|
static |
Allocates descriptor sets and assigns a debug name to the first returned set.
| device | Logical device that owns the descriptor pool referenced by pAllocateInfo. |
| pAllocateInfo | Vulkan allocation info. |
| pDescriptorSets | Output descriptor set array. |
| name | Base debug name. The helper appends a descriptor-set suffix. |
|
inlinestatic |
Release-build no-op for beginning a Vulkan debug label region.
Definition at line 582 of file VulkanHelper.h.
|
static |
Allocates and begins a primary command buffer for one-time submission.
| device | Logical device that owns commandPool. |
| commandPool | Command pool used to allocate the command buffer. |
|
static |
Destroys a buffer and frees its memory when the handles are non-null.
| device | Logical device that owns the buffer and memory. |
| buffer | Buffer handle to destroy. |
| bufferMemory | Device memory handle to free. |
|
static |
Copies bytes from one buffer to another and waits for the queue to become idle.
| device | Logical device that owns the command pool. |
| commandPool | Command pool used to allocate a one-time primary command buffer. |
| graphicsQueue | Queue that executes the copy command. |
| sourceBuffer | Source buffer. It must support VK_BUFFER_USAGE_TRANSFER_SRC_BIT. |
| destinationBuffer | Destination buffer. It must support VK_BUFFER_USAGE_TRANSFER_DST_BIT. |
| size | Number of bytes to copy from offset 0 to offset 0. |
|
static |
Copies several buffer regions in one command buffer and waits for the queue to become idle.
| device | Logical device that owns the command pool. |
| commandPool | Command pool used to allocate a one-time primary command buffer. |
| graphicsQueue | Queue that executes the copy commands. |
| bufferCopyObjects | Copy operations to record. |
|
static |
Copies a buffer into the first layer and mip level of a 2D image.
| device | Logical device that owns the command pool. |
| commandPool | Command pool used for the one-time copy command buffer. |
| graphicsQueue | Queue that executes the copy command and is waited idle before return. |
| buffer | Source buffer. It must support VK_BUFFER_USAGE_TRANSFER_SRC_BIT. |
| image | Destination image. It must be in VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL. |
| width | Copy width in pixels. |
| height | Copy height in pixels. |
|
static |
Creates a Vulkan buffer, allocates memory for it, and binds the memory at offset 0.
| device | Logical device that owns the buffer and memory. |
| physicalDevice | Physical device used to select the memory type. |
| size | Buffer size in bytes. |
| usage | Vulkan buffer usage flags. |
| properties | Required memory property flags. |
| buffer | Output buffer handle. |
| bufferMemory | Output device memory handle bound to buffer. |
| std::runtime_error | when buffer creation, memory type selection, or memory allocation fails. |
|
static |
Creates a descriptor pool and assigns a debug name.
| device | Logical device that owns the pool. |
| pCreateInfo | Vulkan descriptor pool create info. |
| pAllocator | Optional Vulkan allocation callbacks. |
| pDescriptorPool | Output descriptor pool handle. |
| name | Base debug name. The helper appends a descriptor-pool suffix. |
|
static |
Creates a descriptor set layout and assigns a debug name.
| device | Logical device that owns the layout. |
| pCreateInfo | Vulkan descriptor set layout create info. |
| pAllocator | Optional Vulkan allocation callbacks. |
| pSetLayout | Output descriptor set layout handle. |
| name | Base debug name. The helper appends a descriptor-set-layout suffix. |
| std::runtime_error | when vkCreateDescriptorSetLayout fails. |
|
static |
Creates a fence and assigns a debug name.
| device | Logical device that owns the fence. |
| pCreateInfo | Vulkan fence create info. |
| pAllocator | Optional Vulkan allocation callbacks. |
| pFence | Output fence handle. |
| name | Base debug name. The helper appends a fence suffix. |
| std::runtime_error | when vkCreateFence fails. |
|
static |
Creates a 2D image, allocates memory for it, and binds the memory at offset 0.
| device | Logical device that owns the image and memory. |
| physicalDevice | Physical device used to select the memory type. |
| width | Image width in pixels. |
| height | Image height in pixels. |
| format | Image format. |
| tiling | Image tiling mode. |
| usage | Vulkan image usage flags. |
| properties | Required memory property flags. |
| image | Output image handle. |
| imageMemory | Output device memory handle bound to image. |
| std::runtime_error | when image creation, memory type selection, or memory allocation fails. |
|
static |
Creates a 2D image view over one mip level and one array layer.
| device | Logical device that owns image. |
| image | Image handle to view. Must not be VK_NULL_HANDLE. |
| format | View format. |
| aspectFlags | Image aspect flags for the subresource range. |
| std::runtime_error | when vkCreateImageView fails. |
|
static |
Creates a pipeline layout and assigns a debug name.
| device | Logical device that owns the layout. |
| pCreateInfo | Vulkan pipeline layout create info. Must not be null. |
| pAllocator | Optional Vulkan allocation callbacks. |
| pPipelineLayout | Output pipeline layout handle. |
| name | Base debug name. The helper appends a pipeline-layout suffix. |
| std::runtime_error | when vkCreatePipelineLayout fails. |
|
static |
Creates a semaphore and assigns a debug name.
| device | Logical device that owns the semaphore. |
| pCreateInfo | Vulkan semaphore create info. Must not be null. |
| pAllocator | Optional Vulkan allocation callbacks. |
| pSemaphore | Output semaphore handle. |
| name | Base debug name. The helper appends a semaphore suffix. |
| std::runtime_error | when vkCreateSemaphore fails. |
|
inlinestatic |
Release-build no-op for ending a Vulkan debug label region.
Definition at line 587 of file VulkanHelper.h.
|
static |
Ends, submits, waits for, and frees a one-time command buffer.
| device | Logical device that owns commandPool. |
| graphicsQueue | Queue that executes the command buffer. |
| commandPool | Command pool used to free the command buffer. |
| commandBuffer | Command buffer returned by beginSingleTimeCommands(). |
|
static |
Finds a memory type index that satisfies a bitmask and required properties.
| physicalDevice | Physical device whose memory properties are queried. |
| typeFilter | Memory type bitmask from VkMemoryRequirements::memoryTypeBits. |
| properties | Required memory property flags. |
| std::runtime_error | when no supported memory type matches. |
|
static |
Finds a memory type index without throwing on failure.
| physicalDevice | Physical device whose memory properties are queried. |
| requirements | Memory requirements containing the supported memory type bitmask. |
| properties | Required memory property flags. |
| out_typeIndex | Receives the matching memory type index when the function returns true. |
requirements and properties.
|
static |
Creates descriptor buffer info for a whole buffer binding.
| buffer | Buffer handle to describe. |
|
inlinestatic |
Release-build no-op for retrieving a Vulkan object debug name.
| objectHandle | Unused Vulkan object handle. |
Definition at line 661 of file VulkanHelper.h.
|
static |
Returns the loaded Vulkan extension function table.
| std::runtime_error | when no Vulkan helper function initialization has run. |
|
staticprivate |
Appends an object-type suffix to a debug name.
| name | Base debug name. |
| suffix | Suffix added to name. |
|
static |
Checks whether a Vulkan format contains a stencil component.
| format | Format to inspect. |
|
static |
Loads debug utils extension functions from an instance.
| instance | Vulkan instance used with vkGetInstanceProcAddr. |
| std::runtime_error | in debug builds when a required debug utils entry point is unavailable. |
|
static |
Loads all Vulkan extension functions used by the engine.
| instance | Vulkan instance used with vkGetInstanceProcAddr. |
| device | Vulkan device used with vkGetDeviceProcAddr. |
| std::runtime_error | when a required instance or device entry point is unavailable. |
|
static |
Checks whether a Vulkan dispatchable handle value is non-null.
| object | Handle value cast to void*. |
object is not VK_NULL_HANDLE.
|
inlinestatic |
Loads one Vulkan device-level function pointer.
| T | Function pointer type to assign. |
| device | Vulkan device used with vkGetDeviceProcAddr. |
| name | Exact Vulkan entry point name. |
| functionPointer | Output function pointer. |
| std::runtime_error | when the entry point is unavailable. |
Definition at line 149 of file VulkanHelper.h.
|
inlinestatic |
Loads one Vulkan instance-level function pointer.
| T | Function pointer type to assign. |
| instance | Vulkan instance used with vkGetInstanceProcAddr. |
| name | Exact Vulkan entry point name. |
| functionPointer | Output function pointer. |
| std::runtime_error | when the entry point is unavailable. |
Definition at line 127 of file VulkanHelper.h.
|
static |
Records several buffer copy commands into an existing command buffer.
| context | Application context used to inspect graphics and transfer queue family indices. |
| commandBuffer | Command buffer already in the recording state. |
| bufferCopyObjects | Copy operations to record. |
|
inlinestatic |
Release-build no-op for assigning a Vulkan object debug name.
| device | Unused logical device. |
| objectHandle | Unused Vulkan object handle. |
| name | Unused debug name. |
Definition at line 651 of file VulkanHelper.h.
|
static |
Returns a checkmark or cross string for a Vulkan dispatchable handle value.
| object | Handle value cast to void*. |
object is valid, otherwise CROSS_STR.
|
static |
Records an image layout transition barrier into an existing command buffer.
| commandBuffer | Command buffer already in the recording state. |
| device | Reserved; the current implementation does not access it. |
| graphicsQueue | Reserved; the current implementation does not submit work. |
| commandPool | Reserved; the current implementation does not allocate command buffers. |
| image | Image to transition. |
| format | Image format. Stencil formats add VK_IMAGE_ASPECT_STENCIL_BIT for depth-stencil layouts. |
| oldLayout | Source image layout. |
| newLayout | Destination image layout. |
| layerCount | Number of array layers in the barrier subresource range. |
| std::invalid_argument | when the old/new layout pair is unsupported. |
|
static |
Uploads CPU memory into an existing buffer through a temporary staging buffer.
| device | Logical device that owns the buffers. |
| physicalDevice | Physical device used to allocate the staging buffer memory. |
| commandPool | Command pool used for the one-time copy command buffer. |
| queue | Queue that executes the copy command and is waited idle before return. |
| size | Number of bytes to upload. |
| dataPtr | Source CPU memory. The pointer must reference at least size bytes. |
| targetBuffer | Destination buffer. It must support VK_BUFFER_USAGE_TRANSFER_DST_BIT. |
| std::runtime_error | when staging buffer creation or memory allocation fails. |
|
staticprivate |
Definition at line 669 of file VulkanHelper.h.
|
staticprivate |
Definition at line 668 of file VulkanHelper.h.
|
staticprivate |
Definition at line 670 of file VulkanHelper.h.