Monado OpenXR Runtime
Loading...
Searching...
No Matches
a_allocator.h
Go to the documentation of this file.
1// Copyright 2025-2026, NVIDIA CORPORATION.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Auxiliary allocation collection helpers.
6 * @author Jakob Bornecrantz <tbornecrantz@nvidia.com>
7 * @ingroup aux_util
8 */
9
10#pragma once
11
12#include "xrt/xrt_compositor.h"
13
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct vk_bundle;
20
21
22/*!
23 * @defgroup aux_allocation Auxiliary allocation utilities
24 * @ingroup aux
25 *
26 * @{
27 */
28
29/*!
30 * Allocates a new allocation collection for the given swapchain create info.
31 * Abstracts platform-specific differences (e.g., Metal on macOS, Vulkan elsewhere).
32 *
33 * @param vk Vulkan bundle.
34 * @param xscci Swapchain creation info describing the images.
35 * @param image_count Number of images to allocate.
36 * @param out_xac Pointer to receive the new allocation collection.
37 * @return XRT_SUCCESS on success, or an appropriate error code.
38 *
39 * @ingroup aux_allocation
40 */
43 const struct xrt_swapchain_create_info *xscci,
44 uint32_t image_count,
45 struct xrt_allocation_collection **out_xac);
46
47/*!
48 * Imports native images into a new allocation collection.
49 *
50 * Takes ownership of the native handles in the native_images array. On success,
51 * the handles are consumed and should not be used by the caller. On failure,
52 * the handles remain valid and owned by the caller. This is an all-or-nothing
53 * operation.
54 *
55 * @param vk Vulkan bundle.
56 * @param xscci Swapchain creation info describing the images.
57 * @param native_images Array of native image handles to import (ownership transferred on success).
58 * @param image_count Number of images to import.
59 * @param out_xac Pointer to receive the new allocation collection.
60 * @return XRT_SUCCESS on success, or an appropriate error code.
61 *
62 * @ingroup aux_allocation
63 */
66 const struct xrt_swapchain_create_info *xscci,
67 struct xrt_image_native *native_images,
68 uint32_t image_count,
69 struct xrt_allocation_collection **out_xac);
70
71/*!
72 * Ensures the allocation collection supports retrieving VkImages.
73 *
74 * Takes an existing allocation collection and returns one that supports getting
75 * VkImages. The conversion logic is as follows:
76 *
77 * - If the given collection already supports VkImage and uses the same
78 * @ref vk_bundle, returns it (with incremented reference count).
79 * - If the collection supports native images
80 * (@ref XRT_ALLOCATION_TYPE_NATIVE_IMAGE), creates a new collection by
81 * importing the native images using @ref a_allocator_import_from_native_images.
82 * - Otherwise, returns XRT_ERROR_ALLOCATION.
83 *
84 * @param vk Vulkan bundle.
85 * @param xac Existing allocation collection to convert.
86 * @param out_xac Pointer to receive the allocation collection with VkImage support.
87 * @return XRT_SUCCESS on success, or an appropriate error code.
88 *
89 * @ingroup aux_allocation
90 */
93 struct xrt_allocation_collection *xac,
94 struct xrt_allocation_collection **out_xac);
95
96/*!
97 * @}
98 */
99
100
101#ifdef __cplusplus
102}
103#endif
xrt_result_t a_allocator_import_from_native_images(struct vk_bundle *vk, const struct xrt_swapchain_create_info *xscci, struct xrt_image_native *native_images, uint32_t image_count, struct xrt_allocation_collection **out_xac)
Imports native images into a new allocation collection.
Definition a_allocator.c:46
xrt_result_t a_allocator_allocate(struct vk_bundle *vk, const struct xrt_swapchain_create_info *xscci, uint32_t image_count, struct xrt_allocation_collection **out_xac)
Allocates a new allocation collection for the given swapchain create info.
Definition a_allocator.c:28
xrt_result_t a_allocator_ensure_vk_images(struct vk_bundle *vk, struct xrt_allocation_collection *xac, struct xrt_allocation_collection **out_xac)
Ensures the allocation collection supports retrieving VkImages.
Definition a_allocator.c:65
enum xrt_result xrt_result_t
Result type used across Monado.
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition vk_helpers.h:82
A collection of allocations, these can be images, buffers or general memory.
Definition xrt_allocation_collection.h:224
A single image of a swapchain based on native buffer handles.
Definition xrt_compositor.h:2103
Swapchain creation info.
Definition xrt_compositor.h:883
Header declaring XRT graphics interfaces.