Monado OpenXR Runtime
Files | Data Structures | Functions
Vulkan helper code

Vulkan helper structs and functions. More...

Collaboration diagram for Vulkan helper code:

Files

file  vk_documentation.h
 Header with just documentation.
 
file  vk_helpers.c
 Common Vulkan code.
 
file  vk_helpers.h
 Common Vulkan code header.
 

Data Structures

struct  vk_bundle
 A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code. More...
 

Functions

void vk_init_validation_callback (struct vk_bundle *vk)
 
void vk_destroy_validation_callback (struct vk_bundle *vk)
 
VkResult vk_get_loader_functions (struct vk_bundle *vk, PFN_vkGetInstanceProcAddr g)
 
VkResult vk_get_instance_functions (struct vk_bundle *vk)
 
VkResult vk_init_cmd_pool (struct vk_bundle *vk)
 
VkResult vk_create_device (struct vk_bundle *vk, int forced_index)
 
VkResult vk_init_from_given (struct vk_bundle *vk, PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr, VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, uint32_t queue_family_index, uint32_t queue_index)
 Initialize a bundle with objects given to us by client code, used by client_vk_compositor in Compositor client code. More...
 
bool vk_get_memory_type (struct vk_bundle *vk, uint32_t type_bits, VkMemoryPropertyFlags memory_props, uint32_t *out_type_id)
 
VkResult vk_alloc_and_bind_image_memory (struct vk_bundle *vk, VkImage image, size_t max_size, const void *pNext_for_allocate, VkDeviceMemory *out_mem, VkDeviceSize *out_size)
 Allocate memory for an image and bind it to that image. More...
 
VkResult vk_create_image_from_fd (struct vk_bundle *vk, enum xrt_swapchain_usage_bits swapchain_usage, int64_t format, uint32_t width, uint32_t height, uint32_t array_size, uint32_t mip_count, struct xrt_image_fd *image_fd, VkImage *out_image, VkDeviceMemory *out_mem)
 
VkResult vk_create_image_simple (struct vk_bundle *vk, uint32_t width, uint32_t height, VkFormat format, VkDeviceMemory *out_mem, VkImage *out_image)
 
VkResult vk_create_sampler (struct vk_bundle *vk, VkSampler *out_sampler)
 
VkResult vk_create_view (struct vk_bundle *vk, VkImage image, VkFormat format, VkImageSubresourceRange subresource_range, VkImageView *out_view)
 
VkResult vk_init_cmd_buffer (struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer)
 
VkResult vk_set_image_layout (struct vk_bundle *vk, VkCommandBuffer cmd_buffer, VkImage image, VkAccessFlags src_access_mask, VkAccessFlags dst_access_mask, VkImageLayout old_layout, VkImageLayout new_layout, VkImageSubresourceRange subresource_range)
 
VkResult vk_submit_cmd_buffer (struct vk_bundle *vk, VkCommandBuffer cmd_buffer)
 

Detailed Description

Vulkan helper structs and functions.

Function Documentation

◆ vk_alloc_and_bind_image_memory()

VkResult vk_alloc_and_bind_image_memory ( struct vk_bundle vk,
VkImage  image,
size_t  max_size,
const void *  pNext_for_allocate,
VkDeviceMemory *  out_mem,
VkDeviceSize *  out_size 
)

#include <auxiliary/vk/vk_helpers.h>

Allocate memory for an image and bind it to that image.

Handles the following steps:

  • calling vkGetImageMemoryRequirements
    • comparing against the max_size
  • getting the memory type (as dictated by the VkMemoryRequirements and VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
  • calling vkAllocateMemory
  • calling vkBindImageMemory
  • calling vkDestroyMemory in case of an error.

If this fails, it cleans up the VkDeviceMemory.

Parameters
vkVulkan bundle
imageThe VkImage to allocate for and bind.
max_sizeThe maximum value you'll allow for VkMemoryRequirements::size. Pass SIZE_MAX if you will accept any size that works.
pNext_for_allocate(Optional) a pointer to use in the pNext chain of VkMemoryAllocateInfo.
out_memOutput parameter: will be set to the allocated memory if everything succeeds. Not modified if there is an error.
out_size(Optional) pointer to receive the value of VkMemoryRequirements::size.

If this fails, you may want to destroy your VkImage as well, since this routine is usually used in combination with vkCreateImage.

◆ vk_create_device()

VkResult vk_create_device ( struct vk_bundle vk,
int  forced_index 
)

#include <auxiliary/vk/vk_helpers.h>

Todo:
why not vk->queue_family_index ?

◆ vk_init_from_given()

VkResult vk_init_from_given ( struct vk_bundle vk,
PFN_vkGetInstanceProcAddr  vkGetInstanceProcAddr,
VkInstance  instance,
VkPhysicalDevice  physical_device,
VkDevice  device,
uint32_t  queue_family_index,
uint32_t  queue_index 
)

#include <auxiliary/vk/vk_helpers.h>

Initialize a bundle with objects given to us by client code, used by client_vk_compositor in Compositor client code.