Monado OpenXR Runtime
Loading...
Searching...
No Matches
vk_compositor_flags.h
Go to the documentation of this file.
1// Copyright 2019-2025, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Flags helpers for compositor swapchain images.
6 *
7 * These functions all concern only the compositor swapchain images that are
8 * shared between the compositor and the application. That's why they are
9 * grouped together and they are here because they need to be shared between
10 * the @ref vk_image_collection and @ref comp_swapchain code so that they apply
11 * the same flags everywhere.
12 *
13 * CSCI = Compositor SwapChain Images.
14 *
15 * @author Jakob Bornecrantz <jakob@collabora.com>
16 * @author Christoph Haag <christoph.haag@collabora.com>
17 * @author Benjamin Saunders <ben.e.saunders@gmail.com>
18 * @ingroup aux_vk
19 */
20
21#pragma once
22
23#include "xrt/xrt_compiler.h"
25
26#include "vk/vk_helpers.h"
27
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33
34/*
35 *
36 * String pretty printing
37 *
38 */
39
40/*!
41 * Returns xrt swapchain_usage flag if one valid bit is set,
42 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
43 */
44XRT_CHECK_RESULT const char *
45xrt_swapchain_usage_flag_string(enum xrt_swapchain_usage_bits bits, bool null_on_unknown);
46
47
48/*
49 *
50 * Compositor buffer and swapchain image flags helpers, in the vk_compositor_flags.c file.
51 *
52 */
53
54/*!
55 * Return the extern handle type that a buffer should be created with.
56 *
57 * cb = Compositor Buffer.
58 */
59VkExternalMemoryHandleTypeFlags
61
62/*!
63 * Helper for all of the supported formats to check support for.
64 *
65 * These are the available formats we will expose to our clients.
66 *
67 * In order of what we prefer. Start with a SRGB format that works on
68 * both OpenGL and Vulkan. The two linear formats that works on both
69 * OpenGL and Vulkan. A SRGB format that only works on Vulkan. The last
70 * two formats should not be used as they are linear but doesn't have
71 * enough bits to express it without resulting in banding.
72 *
73 * The format VK_FORMAT_A2B10G10R10_UNORM_PACK32 is not listed since
74 * 10 bits are not considered enough to do linear colors without
75 * banding. If there was a sRGB variant of it then we would have used it
76 * instead but there isn't. Since it's not a popular format it's best
77 * not to list it rather then listing it and people falling into the
78 * trap. The absolute minimum is R11G11B10, but is a really weird format
79 * so we are not exposing it.
80 *
81 * CSCI = Compositor SwapChain Images.
82 *
83 * @ingroup aux_vk
84 */
85#define VK_CSCI_FORMATS(THING_COLOR, THING_DS, THING_D, THING_S) \
86 /* color formats */ \
87 THING_COLOR(R16G16B16A16_UNORM) /* OGL VK */ \
88 THING_COLOR(R16G16B16A16_SFLOAT) /* OGL VK */ \
89 THING_COLOR(R16G16B16_UNORM) /* OGL VK - Uncommon. */ \
90 THING_COLOR(R16G16B16_SFLOAT) /* OGL VK - Uncommon. */ \
91 THING_COLOR(R8G8B8A8_SRGB) /* OGL VK */ \
92 THING_COLOR(B8G8R8A8_SRGB) /* VK */ \
93 THING_COLOR(R8G8B8_SRGB) /* OGL VK - Uncommon. */ \
94 THING_COLOR(R8G8B8A8_UNORM) /* OGL VK - Bad color precision. */ \
95 THING_COLOR(B8G8R8A8_UNORM) /* VK - Bad color precision. */ \
96 THING_COLOR(R8G8B8_UNORM) /* OGL VK - Uncommon. Bad color precision. */ \
97 THING_COLOR(B8G8R8_UNORM) /* VK - Uncommon. Bad color precision. */ \
98 THING_COLOR(R5G6B5_UNORM_PACK16) /* OLG VK - Bad color precision. */ \
99 THING_COLOR(R32_SFLOAT) /* OGL VK */ \
100 /* depth formats */ \
101 THING_D(D32_SFLOAT) /* OGL VK */ \
102 THING_D(D16_UNORM) /* OGL VK */ \
103 THING_D(X8_D24_UNORM_PACK32) /* OGL VK */ \
104 /* depth stencil formats */ \
105 THING_DS(D24_UNORM_S8_UINT) /* OGL VK */ \
106 THING_DS(D32_SFLOAT_S8_UINT) /* OGL VK */ \
107 /* stencil format */ \
108 THING_S(S8_UINT)
109
110/*!
111 * Returns the access flags for the compositor to app barriers.
112 *
113 * CSCI = Compositor SwapChain Images.
114 */
115VkAccessFlags
117
118/*!
119 * Return the optimal layout for this format, this is the layout as given to the
120 * app so is bound to the OpenXR spec.
121 *
122 * CSCI = Compositor SwapChain Images.
123 */
124VkImageLayout
126
127/*!
128 * Return the barrier aspect mask for this format, this is intended for the
129 * barriers that flush the data out before and after transfers between the
130 * application and compositor.
131 *
132 * CSCI = Compositor SwapChain Images.
133 */
134VkImageAspectFlags
135vk_csci_get_barrier_aspect_mask(VkFormat format);
136
137/*!
138 * Returns the usage bits for a given selected format and usage.
139 *
140 * For color formats always adds:
141 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
142 *
143 * For depth & stencil formats always adds:
144 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
145 *
146 * For depth formats always adds:
147 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
148 *
149 * For stencil formats always adds:
150 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
151 *
152 * CSCI = Compositor SwapChain Images.
153 */
154VkImageUsageFlags
155vk_csci_get_image_usage_flags(struct vk_bundle *vk, VkFormat format, enum xrt_swapchain_usage_bits bits);
156
157/*!
158 * For images views created by the compositor to sample the images, what aspect
159 * should be set. For color it's the color, for depth and stencil it's only
160 * depth as both are disallowed by the Vulkan spec, for depth only depth, and
161 * for stencil only it's stencil.
162 *
163 * CSCI = Compositor SwapChain Images.
164 */
165VkImageAspectFlags
167
168/*!
169 * Return the extern handle type that a image should be created with.
170 *
171 * CSCI = Compositor SwapChain Images.
172 */
173VkExternalMemoryHandleTypeFlags
175
176/*!
177 * Get whether a given image can be imported/exported for a handle type.
178 *
179 * CSCI = Compositor SwapChain Images.
180 */
181void
183 VkFormat image_format,
184 enum xrt_swapchain_usage_bits bits,
185 VkExternalMemoryHandleTypeFlags handle_type,
186 bool *out_importable,
187 bool *out_exportable);
188
189/*!
190 * Verify if a format is supported for a specific usage
191 *
192 * CSCI = Compositor SwapChain Images.
193 */
194bool
196 VkFormat format,
197 enum xrt_swapchain_create_flags create,
198 enum xrt_swapchain_usage_bits xbits);
199
200
201#ifdef __cplusplus
202}
203#endif
xrt_swapchain_usage_bits
Usage of the swapchain images.
Definition xrt_compositor.h:541
xrt_swapchain_create_flags
Special flags for creating swapchain images.
Definition xrt_compositor.h:523
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition vk_helpers.h:81
A single image of a swapchain based on native buffer handles.
Definition xrt_compositor.h:2194
VkImageAspectFlags vk_csci_get_barrier_aspect_mask(VkFormat format)
Return the barrier aspect mask for this format, this is intended for the barriers that flush the data...
Definition vk_compositor_flags.c:132
VkExternalMemoryHandleTypeFlags vk_cb_get_buffer_external_handle_type(struct vk_bundle *vk)
Return the extern handle type that a buffer should be created with.
Definition vk_compositor_flags.c:66
XRT_CHECK_RESULT const char * xrt_swapchain_usage_flag_string(enum xrt_swapchain_usage_bits bits, bool null_on_unknown)
Returns xrt swapchain_usage flag if one valid bit is set, if multiple bits are set,...
Definition vk_print.c:1028
VkExternalMemoryHandleTypeFlags vk_csci_get_image_external_handle_type(struct vk_bundle *vk, struct xrt_image_native *xin)
Return the extern handle type that a image should be created with.
Definition vk_compositor_flags.c:215
VkAccessFlags vk_csci_get_barrier_access_mask(enum xrt_swapchain_usage_bits bits)
Returns the access flags for the compositor to app barriers.
Definition vk_compositor_flags.c:80
void vk_csci_get_image_external_support(struct vk_bundle *vk, VkFormat image_format, enum xrt_swapchain_usage_bits bits, VkExternalMemoryHandleTypeFlags handle_type, bool *out_importable, bool *out_exportable)
Get whether a given image can be imported/exported for a handle type.
Definition vk_compositor_flags.c:230
VkImageLayout vk_csci_get_barrier_optimal_layout(VkFormat format)
Return the optimal layout for this format, this is the layout as given to the app so is bound to the ...
Definition vk_compositor_flags.c:113
VkImageUsageFlags vk_csci_get_image_usage_flags(struct vk_bundle *vk, VkFormat format, enum xrt_swapchain_usage_bits bits)
Returns the usage bits for a given selected format and usage.
Definition vk_compositor_flags.c:178
bool vk_csci_is_format_supported(struct vk_bundle *vk, VkFormat format, enum xrt_swapchain_create_flags create, enum xrt_swapchain_usage_bits xbits)
Verify if a format is supported for a specific usage.
Definition vk_compositor_flags.c:345
VkImageAspectFlags vk_csci_get_image_view_aspect(VkFormat format, enum xrt_swapchain_usage_bits bits)
For images views created by the compositor to sample the images, what aspect should be set.
Definition vk_compositor_flags.c:155
Common Vulkan code header.
Header holding common defines.
Include all of the Vulkan headers in one place, and cope with any "messy" includes implied by it.