Monado OpenXR Runtime
vk_image_allocator.h
Go to the documentation of this file.
1// Copyright 2020-2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Vulkan image allocator helper.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup aux_vk
8 */
9
10#pragma once
11
12#include "xrt/xrt_limits.h"
13#include "xrt/xrt_config_os.h"
15#include "vk/vk_helpers.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21
22/*!
23 * @addtogroup aux_vk
24 * @{
25 */
26
28{
29 VkImage handle;
30 VkDeviceMemory memory;
31 VkDeviceSize size;
32 bool use_dedicated_allocation;
33};
34
36{
37 struct xrt_swapchain_create_info info;
38
39 /*!
40 * Limit set to same as max swapchain images because
41 * this struct is mostly used to back swapchains.
42 */
44
45 uint32_t image_count;
46};
47
48/*!
49 * Allocates image(s) using the information specified in the swapchain create
50 * info.
51 */
52VkResult
53vk_ic_allocate(struct vk_bundle *vk,
54 const struct xrt_swapchain_create_info *xscci,
55 uint32_t image_count,
56 struct vk_image_collection *out_vkic);
57
58/*!
59 * Imports and set images from the given FDs.
60 */
61VkResult
63 const struct xrt_swapchain_create_info *xscci,
64 struct xrt_image_native *native_images,
65 uint32_t image_count,
66 struct vk_image_collection *out_vkic);
67
68/*!
69 * Free all images created on this image collection, doesn't free the struct
70 * itself so the caller needs to ensure that.
71 */
72void
73vk_ic_destroy(struct vk_bundle *vk, struct vk_image_collection *vkic);
74
75/*!
76 * Get the native handles (FDs on desktop Linux) for the images, this is a all
77 * or nothing function. The ownership is transferred from the images to the
78 * caller so it is responsible for them to be closed just like with
79 * vkGetMemoryFdKHR.
80 *
81 * @see
82 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_KHR_external_memory_fd.html
83 */
84VkResult
86 struct vk_image_collection *vkic,
87 uint32_t max_handles,
88 xrt_graphics_buffer_handle_t *out_handles);
89
90
91/*!
92 * @}
93 */
94
95#ifdef __cplusplus
96}
97#endif
VkResult vk_ic_from_natives(struct vk_bundle *vk, const struct xrt_swapchain_create_info *xscci, struct xrt_image_native *native_images, uint32_t image_count, struct vk_image_collection *out_vkic)
Imports and set images from the given FDs.
Definition: vk_image_allocator.c:395
VkResult vk_ic_get_handles(struct vk_bundle *vk, struct vk_image_collection *vkic, uint32_t max_handles, xrt_graphics_buffer_handle_t *out_handles)
Get the native handles (FDs on desktop Linux) for the images, this is a all or nothing function.
Definition: vk_image_allocator.c:478
VkResult vk_ic_allocate(struct vk_bundle *vk, const struct xrt_swapchain_create_info *xscci, uint32_t image_count, struct vk_image_collection *out_vkic)
Allocates image(s) using the information specified in the swapchain create info.
Definition: vk_image_allocator.c:347
void vk_ic_destroy(struct vk_bundle *vk, struct vk_image_collection *vkic)
Free all images created on this image collection, doesn't free the struct itself so the caller needs ...
Definition: vk_image_allocator.c:468
#define XRT_MAX_SWAPCHAIN_IMAGES
Max swapchain images, artificial limit.
Definition: xrt_limits.h:34
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:49
Definition: vk_image_allocator.h:36
struct vk_image images[XRT_MAX_SWAPCHAIN_IMAGES]
Limit set to same as max swapchain images because this struct is mostly used to back swapchains.
Definition: vk_image_allocator.h:43
Definition: vk_image_allocator.h:28
A single image of a swapchain based on native buffer handles.
Definition: xrt_compositor.h:2156
Swapchain creation info.
Definition: xrt_compositor.h:876
Common Vulkan code header.
Auto detect OS and certain features.
int xrt_graphics_buffer_handle_t
The type underlying buffers shared between compositor clients and the main compositor.
Definition: xrt_handles.h:246
Header for limits of the XRT interfaces.
Include all of the Vulkan headers in one place, and cope with any "messy" includes implied by it.