Monado OpenXR Runtime
vk_helpers.h
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// Copyright 2024-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Common Vulkan code header.
7 *
8 * Note that some functionality in this file is generated by the script
9 * `src/xrt/auxiliary/vk/vk_generate_inc_files.py`. The generated parts are
10 * included via .h.inc files.
11 *
12 * @author Jakob Bornecrantz <jakob@collabora.com>
13 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
14 * @author Moshi Turner <moshiturner@protonmail.com>
15 * @author Korcan Hussein <korcan.hussein@collabora.com>
16 * @ingroup aux_vk
17 */
18
19#pragma once
20
21#include "xrt/xrt_compiler.h"
22#include "xrt/xrt_compositor.h"
24#include "xrt/xrt_handles.h"
25#include "util/u_logging.h"
27#include "os/os_threading.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#define VK_BUNDLE_MAX_QUEUES 3
34
35/*
36 *
37 * Structs
38 *
39 */
40
42{
43 //! The queue family index
44 uint32_t family_index;
45 //! The queue (instance) index
46 uint32_t index;
47};
48
49#define VK_NULL_QUEUE_PAIR \
50 XRT_C11_COMPOUND(struct vk_queue_pair) \
51 { \
52 .family_index = VK_QUEUE_FAMILY_IGNORED, .index = (uint32_t)-1, \
53 }
54
56{
57 //! The Vulkan queue handle
58 VkQueue queue;
59 //! The queue family index
60 uint32_t family_index;
61 //! The queue (instance) index
62 uint32_t index;
63 //! The queue mutex - @see vk_queue_lock, vk_queue_unlock
65};
66
67/*!
68 * A bundle of Vulkan functions and objects, used by both @ref comp and @ref
69 * comp_client. Note that they both have different instances of the object, and
70 * thus different VkInstance, etc.
71 *
72 * @ingroup aux_vk
73 */
75{
76 enum u_logging_level log_level;
77
78 VkInstance instance;
79 uint32_t version;
80 VkPhysicalDevice physical_device;
81 int physical_device_index;
82 VkDevice device;
83
84 /*!
85 * @brief queues - a free list of **unique** queues
86 *
87 * One per uniquely identifiable vk queue (family x instance index),
88 * duplicate entries must not be stored.
89 *
90 * Should not be used directly, @see main_queue, graphics_queue, encode_queue
91 */
92 struct vk_bundle_queue queues[VK_BUNDLE_MAX_QUEUES];
93
94 /*!
95 * @brief Main queue for general work.
96 *
97 * In normal mode, this is a graphics queue.
98 * In compute-only mode, this is a compute queue.
99 *
100 * May alias with graphics_queue.
101 */
103
104 /*!
105 * @brief Graphics queue.
106 *
107 * Always a graphics queue, even in compute-only mode.
108 * In normal mode, aliases with main_queue.
109 * In compute-only mode, this is a separate graphics queue.
110 */
112
113#if defined(VK_KHR_video_encode_queue)
114 /*!
115 * @brief Video encode queue.
116 *
117 * May be NULL if video encoding is not supported.
118 * May alias with other queues.
119 */
120 struct vk_bundle_queue *encode_queue;
121#endif
122
123 struct
124 {
125#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE)
126 bool color_image_import_opaque_win32;
127 bool color_image_export_opaque_win32;
128 bool depth_image_import_opaque_win32;
129 bool depth_image_export_opaque_win32;
130
131 bool color_image_import_d3d11;
132 bool color_image_export_d3d11;
133 bool depth_image_import_d3d11;
134 bool depth_image_export_d3d11;
135
136#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
137 bool color_image_import_opaque_fd;
138 bool color_image_export_opaque_fd;
139 bool depth_image_import_opaque_fd;
140 bool depth_image_export_opaque_fd;
141
142#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
143 bool color_image_import_opaque_fd;
144 bool color_image_export_opaque_fd;
145 bool depth_image_import_opaque_fd;
146 bool depth_image_export_opaque_fd;
147
148 bool color_image_import_ahardwarebuffer;
149 bool color_image_export_ahardwarebuffer;
150 bool depth_image_import_ahardwarebuffer;
151 bool depth_image_export_ahardwarebuffer;
152#endif
153
154#if defined(XRT_GRAPHICS_SYNC_HANDLE_IS_FD)
155 bool fence_sync_fd;
156 bool fence_opaque_fd;
157
158 bool binary_semaphore_sync_fd;
159 bool binary_semaphore_opaque_fd;
160
161 bool timeline_semaphore_sync_fd;
162 bool timeline_semaphore_opaque_fd;
163#elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE)
164 bool fence_win32_handle;
165
166 bool binary_semaphore_d3d12_fence;
167 bool binary_semaphore_win32_handle;
168
169 bool timeline_semaphore_d3d12_fence;
170 bool timeline_semaphore_win32_handle;
171#else
172#error "Need port for fence sync handles checkers"
173#endif
174 } external;
175
176 // Include the generated fields for has_KHR_extension.
177#include "vk_helpers_h_ext.h.inc"
178
179 struct
180 {
181 //! Are timestamps available for compute and graphics queues?
183
184 //! Nanoseconds per gpu tick.
186
187 //! Valid bits in the queue selected.
189
190 //! Were timeline semaphore requested, available, and enabled?
192
193 //! Was synchronization2 requested, available, and enabled?
195
196 //! Was KHR_present_wait requested, available, and enabled?
198
199 //! Was KHR_video_maintenance1 requested, available, and enabled?
201 } features;
202
203 struct
204 {
205 //! Maximum number of sampler objects, as created by vkCreateSampler, which can simultaneously exist on
207
208 //! Maximum number of descriptor sets that can be simultaneously used by a pipeline.
210
211 //! Maximum number of samplers that can be included in a pipeline layout.
213
214 //! Maximum number of sampled images that can be included in a pipeline layout.
216
217 //! Maximum number of samplers that can be accessible to a single shader stage in a pipeline layout.
219
220 //! Per stage limit on sampled images (includes combined).
222
223 //! Per stage limit on storage images.
225 } limits;
226
227 //! Is the GPU a tegra device.
229
230
231 VkDebugReportCallbackEXT debug_report_cb;
232
233 VkPhysicalDeviceMemoryProperties device_memory_props;
234
235 // Loader functions
236 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
237 PFN_vkCreateInstance vkCreateInstance;
238 PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
239
240 // Include the generated function pointers fields.
241#include "vk_helpers_h_funcs.h.inc"
242};
243
245{
246 VkBuffer handle;
247 VkDeviceMemory memory;
248 uint32_t size;
249 void *data;
250};
251
252
253/*
254 *
255 * Helper defines.
256 *
257 */
258
259/*!
260 * This define will print if `RET` is not `VK_SUCCESS`, printing out that the
261 * @p FUNC_STR string has failed. The implicit argument @p vk will be used for
262 * the @ref vk_print_result call.
263 *
264 * Use this when you need to do special things after an error,
265 * but still want to pirnt the pretty message about the failure.
266 *
267 * @param RET The @p VkResult to check.
268 * @param FUNC_STR String literal with the function name, used for logging.
269 *
270 * @ingroup aux_vk
271 *
272 * @see VK_CHK_AND_RET
273 * @see VK_CHK_WITH_RET
274 * @see VK_CHK_WITH_GOTO
275 */
276#define VK_CHK_ONLY_PRINT(RET, FUNC_STR) \
277 do { \
278 VkResult _ret = RET; \
279 if (_ret != VK_SUCCESS) { \
280 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
281 } \
282 } while (false)
283
284/*!
285 * This define will error if `RET` is not `VK_SUCCESS`, printing out that the
286 * @p FUNC_STR string has failed, then returns @p RET. The implicit argument
287 * @p vk will be used for the @ref vk_print_result call.
288 *
289 * Use this macro when your function returns a `VkResult`.
290 *
291 * @param RET The @p VkResult to check.
292 * @param FUNC_STR String literal with the function name, used for logging.
293 *
294 * @ingroup aux_vk
295 *
296 * @see VK_CHK_ONLY_PRINT
297 * @see VK_CHK_WITH_RET
298 * @see VK_CHK_WITH_GOTO
299 */
300#define VK_CHK_AND_RET(RET, FUNC_STR) \
301 do { \
302 VkResult _ret = RET; \
303 if (_ret != VK_SUCCESS) { \
304 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
305 return _ret; \
306 } \
307 } while (false)
308
309/*!
310 * This define will error if @p RET is not @p VK_SUCCESS, printing out that the
311 * @p FUNC_STR string has failed, then returns @p TO_RET. The implicit argument
312 * @p vk will be used for the @ref vk_print_result call.
313 *
314 * Use this macro when your function doesn't return a `VkResult`.
315 *
316 * @param RET The @p VkResult to check.
317 * @param FUNC_STR String literal with the function name, used for logging.
318 * @param TO_RET Value to return, upon error
319 *
320 * @ingroup aux_vk
321 *
322 * @see VK_CHK_ONLY_PRINT
323 * @see VK_CHK_AND_RET
324 * @see VK_CHK_WITH_GOTO
325 */
326#define VK_CHK_WITH_RET(RET, FUNC_STR, TO_RET) \
327 do { \
328 VkResult _ret = RET; \
329 if (_ret != VK_SUCCESS) { \
330 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
331 return TO_RET; \
332 } \
333 } while (false)
334
335/*!
336 * This define will error if @p RET is not @p VK_SUCCESS, printing out that the
337 * @p FUNC_STR string has failed, then goto @p GOTO. The implicit argument @p vk
338 * will be used for the @ref vk_print_result call.
339 *
340 * Use this macro when your function needs to `goto` some cleanup code and
341 * return from there.
342 *
343 * @param RET The @p VkResult to check.
344 * @param FUNC_STR String literal with the function name, used for logging.
345 * @param GOTO Label to jump to, upon error
346 *
347 * @ingroup aux_vk
348 *
349 * @see VK_CHK_ONLY_PRINT
350 * @see VK_CHK_AND_RET
351 * @see VK_CHK_WITH_RET
352 */
353#define VK_CHK_WITH_GOTO(RET, FUNC_STR, GOTO) \
354 do { \
355 VkResult _ret = RET; \
356 if (_ret != VK_SUCCESS) { \
357 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
358 goto GOTO; \
359 } \
360 } while (false)
361
362//! For xrt_result_t, see @ref VK_CHK_AND_RET.
363#define XVK_CHK_AND_RET(...) U_LOG_CHK_AND_RET(vk->log_level, __VA_ARGS__)
364//! For xrt_result_t, see @ref VK_CHK_WITH_GOTO.
365#define XVK_CHK_WITH_GOTO(...) U_LOG_CHK_WITH_GOTO(vk->log_level, __VA_ARGS__)
366//! For xrt_result_t, see @ref VK_CHK_WITH_RET.
367#define XVK_CHK_WITH_RET(...) U_LOG_CHK_WITH_RET(vk->log_level, __VA_ARGS__)
368//! For xrt_result_t, see @ref VK_CHK_ONLY_PRINT.
369#define XVK_CHK_ONLY_PRINT(...) U_LOG_CHK_ONLY_PRINT(vk->log_level, __VA_ARGS__)
370//! For xrt_result_t, see @ref VK_CHK_ALWAYS_RET.
371#define XVK_CHK_ALWAYS_RET(...) U_LOG_CHK_ALWAYS_RET(vk->log_level, __VA_ARGS__)
372
373static inline void
374vk_append_to_pnext_chain(VkBaseInStructure *head, VkBaseInStructure *new_struct)
375{
376 assert(new_struct->pNext == NULL);
377 // Insert ourselves between head and its previous pNext
378 new_struct->pNext = head->pNext;
379 head->pNext = new_struct;
380}
381
382/*
383 *
384 * String helper functions.
385 *
386 */
387
388XRT_CHECK_RESULT const char *
389vk_result_string(VkResult code);
390
391XRT_CHECK_RESULT const char *
392vk_object_type_string(VkObjectType type);
393
394XRT_CHECK_RESULT const char *
395vk_physical_device_type_string(VkPhysicalDeviceType device_type);
396
397XRT_CHECK_RESULT const char *
398vk_format_string(VkFormat code);
399
400XRT_CHECK_RESULT const char *
401vk_sharing_mode_string(VkSharingMode code);
402
403XRT_CHECK_RESULT const char *
404vk_present_mode_string(VkPresentModeKHR code);
405
406XRT_CHECK_RESULT const char *
407vk_color_space_string(VkColorSpaceKHR code);
408
409XRT_CHECK_RESULT const char *
410vk_power_state_string(VkDisplayPowerStateEXT code);
411
412
413/*
414 *
415 * Flag bits string functions.
416 *
417 */
418
419/*!
420 * Returns the format feature flag if one valid bit is set,
421 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
422 */
423XRT_CHECK_RESULT const char *
424vk_format_feature_flag_string(VkFormatFeatureFlagBits bits, bool null_on_unknown);
425
426/*!
427 * Returns the image usage flag if one valid bit is set,
428 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
429 */
430XRT_CHECK_RESULT const char *
431vk_image_usage_flag_string(VkImageUsageFlagBits bits, bool null_on_unknown);
432
433/*!
434 * Returns the composite alpha flag if one valid bit is set,
435 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
436 */
437XRT_CHECK_RESULT const char *
438vk_composite_alpha_flag_string(VkCompositeAlphaFlagBitsKHR bits, bool null_on_unknown);
439
440/*!
441 * Returns the surface transform flag if one valid bit is set,
442 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
443 */
444XRT_CHECK_RESULT const char *
445vk_surface_transform_flag_string(VkSurfaceTransformFlagBitsKHR bits, bool null_on_unknown);
446
447#ifdef VK_KHR_display
448/*!
449 * Returns the display plane alpha flag if one valid bit is set,
450 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
451 */
452XRT_CHECK_RESULT const char *
453vk_display_plane_alpha_flag_string(VkDisplayPlaneAlphaFlagBitsKHR bits, bool null_on_unknown);
454#endif
455
456/*!
457 * Returns xrt swapchain_usage flag if one valid bit is set,
458 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
459 */
460XRT_CHECK_RESULT const char *
461xrt_swapchain_usage_flag_string(enum xrt_swapchain_usage_bits bits, bool null_on_unknown);
462
463
464/*
465 *
466 * Function and helpers.
467 *
468 */
469
470#define VK_TRACE(d, ...) U_LOG_IFL_T(d->log_level, __VA_ARGS__)
471#define VK_DEBUG(d, ...) U_LOG_IFL_D(d->log_level, __VA_ARGS__)
472#define VK_INFO(d, ...) U_LOG_IFL_I(d->log_level, __VA_ARGS__)
473#define VK_WARN(d, ...) U_LOG_IFL_W(d->log_level, __VA_ARGS__)
474#define VK_ERROR(d, ...) U_LOG_IFL_E(d->log_level, __VA_ARGS__)
475
476
477/*
478 *
479 * Debug helper functions, in the vk_debug.c file.
480 *
481 */
482
483#if defined(VK_EXT_debug_utils) || defined(XRT_DOXYGEN)
484
485/*!
486 * Uses VK_EXT_debug_utils to set a name for an object, for easier debugging.
487 *
488 * @ingroup aux_vk
489 */
490void
491vk_name_object(struct vk_bundle *vk, VkObjectType type, uint64_t object, const char *name);
492
493/*!
494 * Small helper for @ref vk_name_object that makes use of pre-process to avoid
495 * writing out long type names.
496 *
497 * @ingroup aux_vk
498 */
499#define VK_NAME_OBJ(VK, TYPE, SUFFIX, OBJ, NAME) \
500 do { \
501 if ((VK)->has_EXT_debug_utils) { \
502 XRT_MAYBE_UNUSED TYPE _thing = (TYPE)(OBJ); \
503 vk_name_object(VK, VK_OBJECT_TYPE_##SUFFIX, (uint64_t)OBJ, NAME); \
504 } \
505 } while (false)
506
507
508#else
509
510#define VK_NAME_OBJ(VK, TYPE, SUFFIX, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, TYPE, OBJ)
511
512#endif
513
514/*!
515 * Some combinations of Vulkan implementation and types are broken, we still
516 * want type safety so we have this define. Examples of broken combinations:
517 *
518 * 1. Both Mesa and the Vulkan loader didn't support setting names on the
519 * VkInstance, loader got support in 1.3.261 and Mesa hasn't as of writing.
520 * 2. For Mesa drivers we can not name VkSurfaceKHR objects on some systems as
521 * it causes memory corruption, asserts, crashes or functions failing. This
522 * is as of writing broken on the 23.2.1 release, fixed in main and scheduled
523 * for the 23.2.2 release.
524 * 3. Mesa RADV leaks the name strings for VkDescriptorSet objects for pools
525 * that we use the reset function.
526 *
527 * @ingroup aux_vk
528 */
529#define VK_NAME_OBJ_DISABLED(VK, TYPE, OBJ) \
530 do { \
531 XRT_MAYBE_UNUSED TYPE _thing = (TYPE)(OBJ); \
532 } while (false)
533
534
535// clang-format off
536// VK_DEFINE_HANDLE types are always pointers
537#define VK_NAME_INSTANCE(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkInstance, (uintptr_t)OBJ)
538#define VK_NAME_PHYSICAL_DEVICE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPhysicalDevice, PHYSICAL_DEVICE, (uintptr_t)OBJ, NAME)
539#define VK_NAME_DEVICE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDevice, DEVICE, (uintptr_t)OBJ, NAME)
540#define VK_NAME_QUEUE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkQueue, QUEUE, (uintptr_t)OBJ, NAME)
541#define VK_NAME_COMMAND_BUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkCommandBuffer, COMMAND_BUFFER, (uintptr_t)OBJ, NAME)
542// VK_DEFINE_NON_DISPATCHABLE_HANDLE types are pointers in 64-bits and uint64_t in 32-bits
543#define VK_NAME_SEMAPHORE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSemaphore, SEMAPHORE, OBJ, NAME)
544#define VK_NAME_FENCE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkFence, FENCE, OBJ, NAME)
545#define VK_NAME_DEVICE_MEMORY(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDeviceMemory, DEVICE_MEMORY, OBJ, NAME)
546#define VK_NAME_BUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkBuffer, BUFFER, OBJ, NAME)
547#define VK_NAME_IMAGE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkImage, IMAGE, OBJ, NAME)
548#define VK_NAME_EVENT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkEvent, EVENT, OBJ, NAME)
549#define VK_NAME_QUERY_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkQueryPool, QUERY_POOL, OBJ, NAME)
550#define VK_NAME_BUFFER_VIEW(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkBufferView, BUFFER_VIEW, OBJ, NAME)
551#define VK_NAME_IMAGE_VIEW(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkImageView, IMAGE_VIEW, OBJ, NAME)
552#define VK_NAME_SHADER_MODULE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkShaderModule, SHADER_MODULE, OBJ, NAME)
553#define VK_NAME_PIPELINE_CACHE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipelineCache, PIPELINE_CACHE, OBJ, NAME)
554#define VK_NAME_PIPELINE_LAYOUT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipelineLayout, PIPELINE_LAYOUT, OBJ, NAME)
555#define VK_NAME_RENDER_PASS(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkRenderPass, RENDER_PASS, OBJ, NAME)
556#define VK_NAME_PIPELINE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipeline, PIPELINE, OBJ, NAME)
557#define VK_NAME_DESCRIPTOR_SET_LAYOUT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDescriptorSetLayout, DESCRIPTOR_SET_LAYOUT, OBJ, NAME)
558#define VK_NAME_SAMPLER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSampler, SAMPLER, OBJ, NAME)
559#define VK_NAME_DESCRIPTOR_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDescriptorPool, DESCRIPTOR_POOL, OBJ, NAME)
560#define VK_NAME_DESCRIPTOR_SET(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkDescriptorSet, OBJ)
561#define VK_NAME_FRAMEBUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkFramebuffer, FRAMEBUFFER, OBJ, NAME)
562#define VK_NAME_COMMAND_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkCommandPool, COMMAND_POOL, OBJ, NAME)
563
564#define VK_NAME_SURFACE(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkSurfaceKHR, OBJ)
565#define VK_NAME_SWAPCHAIN(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSwapchainKHR, SWAPCHAIN_KHR, OBJ, NAME)
566// clang-format on
567
568
569/*
570 *
571 * Printing helpers, in the vk_print.c file.
572 *
573 */
574
575/*!
576 * Print the result of a function, info level if ret == `VK_SUCCESS` and error
577 * level otherwise. Also prints file and line.
578 *
579 * @ingroup aux_vk
580 */
581void
583 struct vk_bundle *vk, const char *file, int line, const char *calling_func, VkResult ret, const char *called_func);
584
585/*!
586 * Print device information to the logger at the given logging level,
587 * if the vk_bundle has that level enabled.
588 *
589 * @ingroup aux_vk
590 */
591void
593 enum u_logging_level log_level,
594 const VkPhysicalDeviceProperties *pdp,
595 uint32_t gpu_index,
596 const char *title);
597
598/*!
599 * Print device information about the device that bundle manages at the given
600 * logging level if the vk_bundle has that level enabled.
601 *
602 * @ingroup aux_vk
603 */
604void
605vk_print_opened_device_info(struct vk_bundle *vk, enum u_logging_level log_level);
606
607/*!
608 * Print device features to the logger at the given logging level, if the
609 * vk_bundle has that level enabled.
610 */
611void
612vk_print_features_info(struct vk_bundle *vk, enum u_logging_level log_level);
613
614/*!
615 * Print external handle features to the logger at the given logging level,
616 * if the vk_bundle has that level enabled.
617 */
618void
620
621/*!
622 * Print a @p VkSwapchainCreateInfoKHR, used to log during creation.
623 */
624void
625vk_print_swapchain_create_info(struct vk_bundle *vk, VkSwapchainCreateInfoKHR *i, enum u_logging_level log_level);
626
627#ifdef VK_KHR_display
628/*!
629 * Print a @p VkDisplaySurfaceCreateInfoKHR, used to log during creation.
630 */
631void
632vk_print_display_surface_create_info(struct vk_bundle *vk,
633 VkDisplaySurfaceCreateInfoKHR *i,
634 enum u_logging_level log_level);
635#endif
636
637/*!
638 * Print queue info to the logger at the given logging level,
639 * if the vk_bundle has that level enabled.
640 */
641void
642vk_print_queues_info(const struct vk_bundle *vk, enum u_logging_level log_level);
643
644
645/*
646 *
647 * Enumeration helpers, in the vk_enumerate.c file.
648 *
649 */
650
651/*!
652 * Return the @p VkExtensionProperties of the given @p layer_name, NULL means
653 * the "base" driver instance.
654 *
655 * @ingroup aux_vk
656 */
657VkResult
659 const char *layer_name,
660 uint32_t *out_prop_count,
661 VkExtensionProperties **out_props);
662
663/*!
664 * Enumerate the physical devices of the @p VkInstance that has been opened on
665 * the given @ref vk_bundle.
666 *
667 * @ingroup aux_vk
668 */
669VkResult
671 uint32_t *out_physical_device_count,
672 VkPhysicalDevice **out_physical_devices);
673
674/*!
675 * Enumerate the extension properties of the given @p VkPhysicalDevice for the
676 * named @p layer_name, NULL means the "base" driver physical device.
677 *
678 * @ingroup aux_vk
679 */
680VkResult
682 VkPhysicalDevice physical_device,
683 const char *layer_name,
684 uint32_t *out_prop_count,
685 VkExtensionProperties **out_props);
686
687/*!
688 * Get the queue family properties of the given @p VkPhysicalDevice, note this
689 * function does not return a result, it will assert if it can not allocate the
690 * array of properties. If there are no queue family properties, the function
691 * will return a count of 0 and set the output pointer to NULL.
692 *
693 * @ingroup aux_vk
694 */
695void
697 VkPhysicalDevice physical_device,
698 uint32_t *out_prop_count,
699 VkQueueFamilyProperties **out_props);
700
701#if defined(VK_KHR_surface) || defined(XRT_DOXYGEN)
702/*!
703 * Enumerate the surface formats of the given @p VkSurfaceKHR,
704 * returns a list of @p VkSurfaceFormatKHR, not @p VkFormat.
705 *
706 * @ingroup aux_vk
707 */
708VkResult
710 VkSurfaceKHR surface,
711 uint32_t *out_format_count,
712 VkSurfaceFormatKHR **out_formats);
713
714/*!
715 * Enumerate the present modes of the given @p VkSurfaceKHR.
716 *
717 * @ingroup aux_vk
718 */
719VkResult
721 VkSurfaceKHR surface,
722 uint32_t *out_present_mode_count,
723 VkPresentModeKHR **out_present_modes);
724#endif
725
726#if defined(VK_KHR_swapchain) || defined(XRT_DOXYGEN)
727/*!
728 * Enumerate the images of the given @p VkSwapchainKHR.
729 *
730 * @ingroup aux_vk
731 */
732VkResult
734 VkSwapchainKHR swapchain,
735 uint32_t *out_image_count,
736 VkImage **out_images);
737#endif
738
739#if defined(VK_USE_PLATFORM_DISPLAY_KHR) || defined(XRT_DOXYGEN)
740/*!
741 * Enumerate the display properties of the given @p VkPhysicalDevice.
742 *
743 * @ingroup aux_vk
744 */
745VkResult
747 VkPhysicalDevice physical_device,
748 uint32_t *out_prop_count,
749 VkDisplayPropertiesKHR **out_props);
750
751/*!
752 * Enumerate the display plane properties of the given @p VkPhysicalDevice.
753 *
754 * @ingroup aux_vk
755 */
756VkResult
758 VkPhysicalDevice physical_device,
759 uint32_t *out_prop_count,
760 VkDisplayPlanePropertiesKHR **out_props);
761
762/*!
763 * Enumerate the mode properties of the given @p VkDisplayKHR, which belongs
764 * to the given @p VkPhysicalDevice.
765 *
766 * @ingroup aux_vk
767 */
768VkResult
770 VkPhysicalDevice physical_device,
771 VkDisplayKHR display,
772 uint32_t *out_prop_count,
773 VkDisplayModePropertiesKHR **out_props);
774#endif
775
776
777/*
778 *
779 * Struct init functions, in the vk_function_loaders.c file.
780 *
781 */
782
783/*!
784 * Can be done on a completely bare bundle.
785 *
786 * @ingroup aux_vk
787 */
788VkResult
789vk_get_loader_functions(struct vk_bundle *vk, PFN_vkGetInstanceProcAddr g);
790
791/*!
792 * Requires a instance to have been created and set on the bundle.
793 *
794 * @ingroup aux_vk
795 */
796VkResult
798
799/*!
800 * Requires a device to have been created and set on the bundle.
801 *
802 * @ingroup aux_vk
803 */
804VkResult
806
807
808/*
809 *
810 * Bundle init functions, in the vk_bundle_init.c file.
811 *
812 */
813
814/*!
815 * Check if the required instance extensions are supported, if not print error
816 * message with all extensions missing, returns VK_ERROR_EXTENSION_NOT_PRESENT
817 * if not all extensions are supported.
818 *
819 * @ingroup aux_vk
820 */
821VkResult
822vk_check_required_instance_extensions(struct vk_bundle *vk, struct u_extension_list *required_instance_ext_list);
823
824/*!
825 * Build instance extensions from required and optional instance extensions.
826 * This function enumerates available instance extensions, checks required ones,
827 * and builds a final list. Returns VK_SUCCESS if successful.
828 * Only requires @ref vk_get_loader_functions to have been called.
829 *
830 * @ingroup aux_vk
831 */
832VkResult
834 struct u_extension_list *required_instance_ext_list,
835 struct u_extension_list *optional_instance_ext_list,
836 struct u_extension_list **out_instance_ext_list);
837
838/*!
839 * Fills in has_* in vk_bundle given a string of prefiltered instance extensions
840 */
841void
843
844/*!
845 * Setup the physical device, this is called by vk_create_device but has uses
846 * for outside of that.
847 *
848 * @ingroup aux_vk
849 */
850VkResult
851vk_select_physical_device(struct vk_bundle *vk, int forced_index);
852
853/*!
854 * Used to enable device features as a argument @ref vk_create_device.
855 *
856 * @ingroup aux_vk
857 */
859{
860 bool shader_image_gather_extended;
861 bool shader_storage_image_write_without_format;
862 bool null_descriptor;
863 bool timeline_semaphore;
864 bool synchronization_2;
865 bool ext_fmt_resolve;
866 bool storage_buffer_8bit_access;
867 bool present_wait;
868 bool video_maintenance_1;
869};
870
871/*!
872 * Creates a VkDevice and initialises the VkQueue.
873 *
874 * The @p vk_bundle must have been zero initialized, have the instance functions
875 * loaded and a valid instance.
876 *
877 * @ingroup aux_vk
878 */
879XRT_CHECK_RESULT VkResult
880vk_create_device(struct vk_bundle *vk,
881 int forced_index,
882 bool only_compute,
883 VkQueueGlobalPriorityEXT global_priority,
884 struct u_extension_list *required_device_ext_list,
885 struct u_extension_list *optional_device_ext_list,
886 const struct vk_device_features *optional_device_features);
887
888/*!
889 * @brief Initialize mutexes in the @ref vk_bundle.
890 *
891 * Not required for all uses, but a precondition for some.
892 *
893 * @ingroup aux_vk
894 */
895VkResult
896vk_init_mutex(struct vk_bundle *vk);
897
898/*!
899 * @brief De-initialize mutexes in the @ref vk_bundle.
900 *
901 * @ingroup aux_vk
902 */
903VkResult
904vk_deinit_mutex(struct vk_bundle *vk);
905
906static inline void
907vk_queue_lock(struct vk_bundle_queue *q)
908{
909 assert(q != NULL);
910 os_mutex_lock(&q->mutex);
911}
912
913static inline int
914vk_queue_trylock(struct vk_bundle_queue *q)
915{
916 assert(q != NULL);
917 return os_mutex_trylock(&q->mutex);
918}
919
920static inline void
921vk_queue_unlock(struct vk_bundle_queue *q)
922{
923 assert(q != NULL);
925}
926
927/*!
928 * Initialize a bundle with objects given to us by client code,
929 * used by @ref client_vk_compositor in @ref comp_client.
930 *
931 * @ingroup aux_vk
932 */
933XRT_CHECK_RESULT VkResult
935 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
936 VkInstance instance,
937 VkPhysicalDevice physical_device,
938 VkDevice device,
939 uint32_t queue_family_index,
940 uint32_t queue_index,
941 bool external_fence_fd_enabled,
942 bool external_semaphore_fd_enabled,
943 bool timeline_semaphore_enabled,
944 bool image_format_list_enabled,
945 bool debug_utils_enabled,
946 enum u_logging_level log_level);
947
948
949/*
950 *
951 * Other functions.
952 *
953 */
954
955/*!
956 * @ingroup aux_vk
957 */
958bool
959vk_get_memory_type(struct vk_bundle *vk, uint32_t type_bits, VkMemoryPropertyFlags memory_props, uint32_t *out_type_id);
960
961/*!
962 * Allocate memory for an image and bind it to that image.
963 *
964 * Handles the following steps:
965 *
966 * - calling vkGetImageMemoryRequirements
967 * - comparing against the max_size
968 * - getting the memory type (as dictated by the VkMemoryRequirements and
969 * VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
970 * - calling vkAllocateMemory
971 * - calling vkBindImageMemory
972 * - calling vkDestroyMemory in case of an error.
973 *
974 * If this fails, it cleans up the VkDeviceMemory.
975 *
976 * @param vk Vulkan bundle
977 * @param image The VkImage to allocate for and bind.
978 * @param requirements Memory requirements used for finding the memory type and the size.
979 * @param pNext_for_allocate (Optional) a pointer to use in the pNext chain of
980 * VkMemoryAllocateInfo.
981 * @param caller_name Used for error printing, this function is called from
982 * various sources and takes next chains that could influence the result
983 * of various calls inside of it. Since it's up to this function to print
984 * any errors it will add the caller name to error messages.
985 * @param out_mem Output parameter: will be set to the allocated memory if
986 * everything succeeds. Not modified if there is an error.
987 *
988 * If this fails, you may want to destroy your VkImage as well, since this
989 * routine is usually used in combination with vkCreateImage.
990 *
991 * @ingroup aux_vk
992 */
993XRT_CHECK_RESULT VkResult
995 VkImage image,
996 const VkMemoryRequirements *requirements,
997 const void *pNext_for_allocate,
998 const char *caller_name,
999 VkDeviceMemory *out_mem);
1000
1001/*!
1002 *
1003 * @brief Creates a Vulkan device memory and image from a native graphics buffer handle.
1004 *
1005 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1006 *
1007 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p image_native
1008 * handle may have transferred, a reference may have been added, or the Vulkan objects may rely on the caller to keep
1009 * the native handle alive until the Vulkan objects are destroyed. Which option applies depends on the particular native
1010 * handle type used.
1011 *
1012 * See the corresponding specification texts:
1013 *
1014 * - Windows:
1015 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportMemoryWin32HandleInfoKHR
1016 * - Linux: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportMemoryFdInfoKHR
1017 * - Android:
1018 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportAndroidHardwareBufferInfoANDROID
1019 *
1020 * @ingroup aux_vk
1021 */
1022XRT_CHECK_RESULT VkResult
1024 const struct xrt_swapchain_create_info *info,
1025 struct xrt_image_native *image_native,
1026 VkImage *out_image,
1027 VkDeviceMemory *out_mem);
1028
1029/*!
1030 * Given a DeviceMemory handle created to be exportable, outputs the native buffer type (FD on desktop Linux)
1031 * equivalent.
1032 *
1033 * Caller assumes ownership of handle which should be unreferenced with @ref u_graphics_buffer_unref when no longer
1034 * needed.
1035 *
1036 * @param vk Vulkan bundle
1037 * @param device_memory The memory to get the handle of
1038 * @param[out] out_handle A pointer to the handle to populate
1039 *
1040 * @ingroup aux_vk
1041 */
1042XRT_CHECK_RESULT VkResult
1044 VkDeviceMemory device_memory,
1045 xrt_graphics_buffer_handle_t *out_handle);
1046
1047/*!
1048 * @ingroup aux_vk
1049 * Helper to create a VkImage
1050 */
1051VkResult
1053 VkExtent2D extent,
1054 VkFormat format,
1055 VkImageUsageFlags usage,
1056 VkDeviceMemory *out_mem,
1057 VkImage *out_image);
1058
1059/*!
1060 * Helper to create a mutable RG88B8A8 VkImage that specializes in the two
1061 * UNORM and SRGB variants of that formats.
1062 *
1063 * @ingroup aux_vk
1064 */
1065VkResult
1067 struct vk_bundle *vk, VkExtent2D extent, VkImageUsageFlags usage, VkDeviceMemory *out_mem, VkImage *out_image);
1068
1069/*!
1070 * @ingroup aux_vk
1071 * Helper to create a VkImage, with more options for tiling and memory storage.
1072 */
1073VkResult
1075 VkExtent3D extent,
1076 VkFormat format,
1077 VkImageTiling image_tiling,
1078 VkImageUsageFlags image_usage_flags,
1079 VkMemoryPropertyFlags memory_property_flags,
1080 VkDeviceMemory *out_mem,
1081 VkImage *out_image);
1082
1083/*!
1084 * @ingroup aux_vk
1085 */
1086VkResult
1087vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampler *out_sampler);
1088
1089
1090/*
1091 *
1092 * Helpers for creating ímage views.
1093 *
1094 */
1095
1096/*!
1097 * @ingroup aux_vk
1098 */
1099VkResult
1100vk_create_view(struct vk_bundle *vk,
1101 VkImage image,
1102 VkImageViewType type,
1103 VkFormat format,
1104 VkImageSubresourceRange subresource_range,
1105 VkImageView *out_view);
1106
1107/*!
1108 * @ingroup aux_vk
1109 */
1110VkResult
1111vk_create_view_swizzle(struct vk_bundle *vk,
1112 VkImage image,
1113 VkImageViewType type,
1114 VkFormat format,
1115 VkImageSubresourceRange subresource_range,
1116 VkComponentMapping components,
1117 VkImageView *out_view);
1118
1119/*!
1120 * Creates a image with a specific subset of usage, useful for a mutable images
1121 * where one format might not support all usages defined by the image.
1122 *
1123 * @ingroup aux_vk
1124 */
1125VkResult
1127 VkImage image,
1128 VkImageViewType type,
1129 VkFormat format,
1130 VkImageUsageFlags image_usage,
1131 VkImageSubresourceRange subresource_range,
1132 VkImageView *out_view);
1133
1134
1135/*
1136 *
1137 * Helpers for creating descriptor pools and sets.
1138 *
1139 */
1140
1141bool
1142vk_init_descriptor_pool(struct vk_bundle *vk,
1143 const VkDescriptorPoolSize *pool_sizes,
1144 uint32_t pool_size_count,
1145 uint32_t set_count,
1146 VkDescriptorPool *out_descriptor_pool);
1147
1148bool
1149vk_allocate_descriptor_sets(struct vk_bundle *vk,
1150 VkDescriptorPool descriptor_pool,
1151 uint32_t count,
1152 const VkDescriptorSetLayout *set_layout,
1153 VkDescriptorSet *sets);
1154
1155
1156/*
1157 *
1158 * Helpers for creating buffers.
1159 *
1160 */
1161
1162bool
1163vk_buffer_init(struct vk_bundle *vk,
1164 VkDeviceSize size,
1165 VkBufferUsageFlags usage,
1166 VkMemoryPropertyFlags properties,
1167 VkBuffer *out_buffer,
1168 VkDeviceMemory *out_mem);
1169
1170void
1171vk_buffer_destroy(struct vk_buffer *self, struct vk_bundle *vk);
1172
1173bool
1174vk_update_buffer(struct vk_bundle *vk, float *buffer, size_t buffer_size, VkDeviceMemory memory);
1175
1176
1177/*
1178 *
1179 * Helpers for writing command buffers, in the vk_helpers.c file.
1180 *
1181 */
1182
1183/*!
1184 * Inserts a image barrier command, doesn't take any locks, the calling code
1185 * will need hold the lock for the pool that cmd_buffer is from or ensure it is
1186 * externally synchronized.
1187 *
1188 * @ingroup aux_vk
1189 */
1190void
1192 VkCommandBuffer cmd_buffer,
1193 VkImage image,
1194 VkAccessFlags src_access_mask,
1195 VkAccessFlags dst_access_mask,
1196 VkImageLayout old_image_layout,
1197 VkImageLayout new_image_layout,
1198 VkPipelineStageFlags src_stage_mask,
1199 VkPipelineStageFlags dst_stage_mask,
1200 VkImageSubresourceRange subresource_range);
1201
1202/*!
1203 * Inserts a image barrier command specifically for GPU commands, doesn't take
1204 * any locks, the calling code will need hold the lock for the pool that
1205 * cmd_buffer is from or ensure it is externally synchronized.
1206 *
1207 * @ingroup aux_vk
1208 */
1209void
1211 VkCommandBuffer cmd_buffer,
1212 VkImage image,
1213 VkAccessFlags src_access_mask,
1214 VkAccessFlags dst_access_mask,
1215 VkImageLayout old_layout,
1216 VkImageLayout new_layout,
1217 VkImageSubresourceRange subresource_range);
1218
1219#if defined(VK_EXT_debug_utils) || defined(XRT_DOXYGEN)
1220/*!
1221 * Uses VK_EXT_debug_utils to insert debug label into a VkCommandBuffer.
1222 *
1223 * In the vk_debug.c file.
1224 *
1225 * @ingroup aux_vk
1226 */
1227void
1228vk_cmd_insert_label(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const char *name);
1229#endif
1230
1231
1232/*
1233 *
1234 * State creation helpers, in the vk_state_creators.c file.
1235 *
1236 */
1237
1238/*!
1239 * Arguments to @ref vk_create_descriptor_pool function.
1240 */
1242{
1243 uint32_t uniform_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
1244 uint32_t sampler_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
1245 uint32_t storage_image_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
1246 uint32_t storage_buffer_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
1247
1248 //! The max count of created descriptors.
1250
1251 //! Are descriptors freeable, or must vkResetDescriptorPool be used.
1253};
1254
1255/*!
1256 * Creates a descriptor pool, made for a single layout.
1257 *
1258 * Does error logging.
1259 */
1260VkResult
1262 const struct vk_descriptor_pool_info *info,
1263 VkDescriptorPool *out_descriptor_pool);
1264
1265/*!
1266 * Creates a descriptor set.
1267 *
1268 * Does error logging.
1269 */
1270VkResult
1272 VkDescriptorPool descriptor_pool,
1273 VkDescriptorSetLayout descriptor_layout,
1274 VkDescriptorSet *out_descriptor_set);
1275
1276/*!
1277 * Creates a pipeline layout from a single descriptor set layout.
1278 *
1279 * Does error logging.
1280 */
1281VkResult
1283 VkDescriptorSetLayout descriptor_set_layout,
1284 VkPipelineLayout *out_pipeline_layout);
1285
1286/*!
1287 * Creates a pipeline cache.
1288 *
1289 * Does error logging.
1290 */
1291VkResult
1292vk_create_pipeline_cache(struct vk_bundle *vk, VkPipelineCache *out_pipeline_cache);
1293
1294/*!
1295 * Creates a compute pipeline, assumes entry function is called 'main'.
1296 *
1297 * Does error logging.
1298 */
1299VkResult
1301 VkPipelineCache pipeline_cache,
1302 VkShaderModule shader,
1303 VkPipelineLayout pipeline_layout,
1304 const VkSpecializationInfo *specialization_info,
1305 VkPipeline *out_compute_pipeline);
1306
1307
1308/*
1309 *
1310 * Compositor buffer and swapchain image flags helpers, in the vk_compositor_flags.c file.
1311 *
1312 */
1313
1314/*!
1315 * Return the extern handle type that a buffer should be created with.
1316 *
1317 * cb = Compositor Buffer.
1318 */
1319VkExternalMemoryHandleTypeFlags
1321
1322/*!
1323 * Helper for all of the supported formats to check support for.
1324 *
1325 * These are the available formats we will expose to our clients.
1326 *
1327 * In order of what we prefer. Start with a SRGB format that works on
1328 * both OpenGL and Vulkan. The two linear formats that works on both
1329 * OpenGL and Vulkan. A SRGB format that only works on Vulkan. The last
1330 * two formats should not be used as they are linear but doesn't have
1331 * enough bits to express it without resulting in banding.
1332 *
1333 * The format VK_FORMAT_A2B10G10R10_UNORM_PACK32 is not listed since
1334 * 10 bits are not considered enough to do linear colors without
1335 * banding. If there was a sRGB variant of it then we would have used it
1336 * instead but there isn't. Since it's not a popular format it's best
1337 * not to list it rather then listing it and people falling into the
1338 * trap. The absolute minimum is R11G11B10, but is a really weird format
1339 * so we are not exposing it.
1340 *
1341 * CSCI = Compositor SwapChain Images.
1342 *
1343 * @ingroup aux_vk
1344 */
1345#define VK_CSCI_FORMATS(THING_COLOR, THING_DS, THING_D, THING_S) \
1346 /* color formats */ \
1347 THING_COLOR(R16G16B16A16_UNORM) /* OGL VK */ \
1348 THING_COLOR(R16G16B16A16_SFLOAT) /* OGL VK */ \
1349 THING_COLOR(R16G16B16_UNORM) /* OGL VK - Uncommon. */ \
1350 THING_COLOR(R16G16B16_SFLOAT) /* OGL VK - Uncommon. */ \
1351 THING_COLOR(R8G8B8A8_SRGB) /* OGL VK */ \
1352 THING_COLOR(B8G8R8A8_SRGB) /* VK */ \
1353 THING_COLOR(R8G8B8_SRGB) /* OGL VK - Uncommon. */ \
1354 THING_COLOR(R8G8B8A8_UNORM) /* OGL VK - Bad color precision. */ \
1355 THING_COLOR(B8G8R8A8_UNORM) /* VK - Bad color precision. */ \
1356 THING_COLOR(R8G8B8_UNORM) /* OGL VK - Uncommon. Bad color precision. */ \
1357 THING_COLOR(B8G8R8_UNORM) /* VK - Uncommon. Bad color precision. */ \
1358 THING_COLOR(R5G6B5_UNORM_PACK16) /* OLG VK - Bad color precision. */ \
1359 THING_COLOR(R32_SFLOAT) /* OGL VK */ \
1360 /* depth formats */ \
1361 THING_D(D32_SFLOAT) /* OGL VK */ \
1362 THING_D(D16_UNORM) /* OGL VK */ \
1363 THING_D(X8_D24_UNORM_PACK32) /* OGL VK */ \
1364 /* depth stencil formats */ \
1365 THING_DS(D24_UNORM_S8_UINT) /* OGL VK */ \
1366 THING_DS(D32_SFLOAT_S8_UINT) /* OGL VK */ \
1367 /* stencil format */ \
1368 THING_S(S8_UINT)
1369
1370/*!
1371 * Returns the access flags for the compositor to app barriers.
1372 *
1373 * CSCI = Compositor SwapChain Images.
1374 */
1375VkAccessFlags
1377
1378/*!
1379 * Return the optimal layout for this format, this is the layout as given to the
1380 * app so is bound to the OpenXR spec.
1381 *
1382 * CSCI = Compositor SwapChain Images.
1383 */
1384VkImageLayout
1385vk_csci_get_barrier_optimal_layout(VkFormat format);
1386
1387/*!
1388 * Return the barrier aspect mask for this format, this is intended for the
1389 * barriers that flush the data out before and after transfers between the
1390 * application and compositor.
1391 *
1392 * CSCI = Compositor SwapChain Images.
1393 */
1394VkImageAspectFlags
1395vk_csci_get_barrier_aspect_mask(VkFormat format);
1396
1397/*!
1398 * Returns the usage bits for a given selected format and usage.
1399 *
1400 * For color formats always adds:
1401 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1402 *
1403 * For depth & stencil formats always adds:
1404 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1405 *
1406 * For depth formats always adds:
1407 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1408 *
1409 * For stencil formats always adds:
1410 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1411 *
1412 * CSCI = Compositor SwapChain Images.
1413 */
1414VkImageUsageFlags
1415vk_csci_get_image_usage_flags(struct vk_bundle *vk, VkFormat format, enum xrt_swapchain_usage_bits bits);
1416
1417/*!
1418 * For images views created by the compositor to sample the images, what aspect
1419 * should be set. For color it's the color, for depth and stencil it's only
1420 * depth as both are disallowed by the Vulkan spec, for depth only depth, and
1421 * for stencil only it's stencil.
1422 *
1423 * CSCI = Compositor SwapChain Images.
1424 */
1425VkImageAspectFlags
1427
1428/*!
1429 * Return the extern handle type that a image should be created with.
1430 *
1431 * CSCI = Compositor SwapChain Images.
1432 */
1433VkExternalMemoryHandleTypeFlags
1435
1436/*!
1437 * Get whether a given image can be imported/exported for a handle type.
1438 *
1439 * CSCI = Compositor SwapChain Images.
1440 */
1441void
1443 VkFormat image_format,
1444 enum xrt_swapchain_usage_bits bits,
1445 VkExternalMemoryHandleTypeFlags handle_type,
1446 bool *out_importable,
1447 bool *out_exportable);
1448
1449/*!
1450 * Verify if a format is supported for a specific usage
1451 *
1452 * CSCI = Compositor SwapChain Images.
1453 */
1454bool
1456 VkFormat format,
1457 enum xrt_swapchain_create_flags create,
1458 enum xrt_swapchain_usage_bits xbits);
1459
1460/*
1461 *
1462 * Sync objects, in the vk_sync_objects.c file.
1463 *
1464 */
1465
1466/*!
1467 * Is there a good likelihood that the import/export of a timeline semaphore
1468 * will succeed, in other words will the below functions work.
1469 *
1470 * @ingroup aux_vk
1471 */
1472XRT_CHECK_RESULT bool
1474
1475/*!
1476 * @brief Creates a Vulkan fence, submits it to the default VkQueue and return
1477 * its native graphics sync handle.
1478 *
1479 * In case of error, out_native is not touched by the function.
1480 *
1481 * See @ref vk_create_fence_sync_from_native for ownership semantics on import.
1482 *
1483 * @ingroup aux_vk
1484 */
1485XRT_CHECK_RESULT VkResult
1487
1488/*!
1489 * @brief Creates a Vulkan fence from a native graphics sync handle.
1490 *
1491 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1492 *
1493 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p native
1494 * handle may have transferred, a reference may have been added, or the Vulkan object may rely on the caller to keep the
1495 * native handle alive until the Vulkan object is destroyed. Which option applies depends on the particular native
1496 * handle type used.
1497 *
1498 * See the corresponding Vulkan specification text:
1499 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#synchronization-fences-importing
1500 *
1501 * @ingroup aux_vk
1502 */
1503XRT_CHECK_RESULT VkResult
1504vk_create_fence_sync_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkFence *out_fence);
1505
1506/*!
1507 * Creates a Vulkan semaphore and a native graphics sync handle.
1508 *
1509 * In case of success, the underlying Vulkan functionality's ownership semantics
1510 * apply: ownership of the @p native handle may have transferred, a reference
1511 * may have been added, or the Vulkan object may rely on the caller to keep the
1512 * native handle alive until the Vulkan object is destroyed. Which option
1513 * applies depends on the particular native handle type used.
1514 *
1515 * In case of error, neither @p out_sem and @p out_native is not touched by the
1516 * function so the caller only becomes responsible for the output on success.
1517 *
1518 * See the corresponding Vulkan specification text:
1519 * https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#synchronization-semaphores
1520 *
1521 * @ingroup aux_vk
1522 */
1523XRT_CHECK_RESULT VkResult
1524vk_create_semaphore_and_native(struct vk_bundle *vk, VkSemaphore *out_sem, xrt_graphics_sync_handle_t *out_native);
1525
1526#if defined(VK_KHR_timeline_semaphore) || defined(XRT_DOXYGEN)
1527/*
1528 * Creates a Vulkan timeline semaphore and a native graphics sync
1529 * handle, see @ref vk_create_semaphore_and_native for more details.
1530 *
1531 * @ingroup aux_vk
1532 */
1533XRT_CHECK_RESULT VkResult
1534vk_create_timeline_semaphore_and_native(struct vk_bundle *vk,
1535 VkSemaphore *out_sem,
1536 xrt_graphics_sync_handle_t *out_native);
1537#endif
1538
1539/*!
1540 * @brief Creates a Vulkan semaphore from a native graphics sync handle.
1541 *
1542 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1543 *
1544 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p native
1545 * handle may have transferred, a reference may have been added, or the Vulkan object may rely on the caller to keep the
1546 * native handle alive until the Vulkan object is destroyed. Which option applies depends on the particular native
1547 * handle type used.
1548 *
1549 * @ingroup aux_vk
1550 */
1551XRT_CHECK_RESULT VkResult
1552vk_create_semaphore_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkSemaphore *out_sem);
1553
1554#if defined(VK_KHR_timeline_semaphore) || defined(XRT_DOXYGEN)
1555/*!
1556 * @brief Creates a Vulkan timeline semaphore from a native graphics sync
1557 * handle, see @ref vk_create_semaphore_from_native for more details.
1558 *
1559 * @ingroup aux_vk
1560 */
1561XRT_CHECK_RESULT VkResult
1563#endif
1564
1565
1566/*
1567 *
1568 * Time function(s), in the vk_time.c file.
1569 *
1570 */
1571
1572#if defined(VK_EXT_calibrated_timestamps) || defined(XRT_DOXYGEN)
1573/*!
1574 * Convert timestamps in GPU ticks (as return by VkQueryPool timestamp queries)
1575 * into host CPU nanoseconds, same time domain as @ref os_monotonic_get_ns.
1576 *
1577 * Note the timestamp needs to be in the past and not to old, this is because
1578 * not all GPU has full 64 bit timer resolution. For instance a Intel GPU "only"
1579 * have 36 bits of valid timestamp and a tick period 83.3333 nanosecond,
1580 * equating to an epoch of 5726 seconds before overflowing. The function can
1581 * handle overflows happening between the given timestamps and when it is called
1582 * but only for one such epoch overflow, any more will only be treated as one
1583 * such overflow. So timestamps needs to be converted reasonably soon after they
1584 * have been captured.
1585 *
1586 * @param vk The Vulkan bundle.
1587 * @param count Number of timestamps to be converted.
1588 * @param[in,out] in_out_timestamps Array of timestamps to be converted, done in place.
1589 *
1590 * @ingroup aux_vk
1591 */
1592XRT_CHECK_RESULT VkResult
1593vk_convert_timestamps_to_host_ns(struct vk_bundle *vk, uint32_t count, uint64_t *in_out_timestamps);
1594#endif
1595
1596
1597#ifdef __cplusplus
1598}
1599#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:45
static void os_mutex_lock(struct os_mutex *om)
Lock.
Definition: os_threading.h:100
static int os_mutex_trylock(struct os_mutex *om)
Try to lock, but do not block.
Definition: os_threading.h:112
static void os_mutex_unlock(struct os_mutex *om)
Unlock.
Definition: os_threading.h:124
VkResult vk_enumerate_display_mode_properties(struct vk_bundle *vk, VkPhysicalDevice physical_device, VkDisplayKHR display, uint32_t *out_prop_count, VkDisplayModePropertiesKHR **out_props)
Enumerate the mode properties of the given VkDisplayKHR, which belongs to the given VkPhysicalDevice.
VkResult vk_enumerate_physical_device_extension_properties(struct vk_bundle *vk, VkPhysicalDevice physical_device, const char *layer_name, uint32_t *out_prop_count, VkExtensionProperties **out_props)
Enumerate the extension properties of the given VkPhysicalDevice for the named layer_name,...
Definition: vk_enumerate.c:103
VkResult vk_create_image_advanced(struct vk_bundle *vk, VkExtent3D extent, VkFormat format, VkImageTiling image_tiling, VkImageUsageFlags image_usage_flags, VkMemoryPropertyFlags memory_property_flags, VkDeviceMemory *out_mem, VkImage *out_image)
Helper to create a VkImage, with more options for tiling and memory storage.
Definition: vk_helpers.c:971
VkResult vk_enumerate_physical_display_plane_properties(struct vk_bundle *vk, VkPhysicalDevice physical_device, uint32_t *out_prop_count, VkDisplayPlanePropertiesKHR **out_props)
Enumerate the display plane properties of the given VkPhysicalDevice.
void vk_cmd_image_barrier_gpu_locked(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)
Inserts a image barrier command specifically for GPU commands, doesn't take any locks,...
Definition: vk_helpers.c:1726
XRT_CHECK_RESULT 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, bool external_fence_fd_enabled, bool external_semaphore_fd_enabled, bool timeline_semaphore_enabled, bool image_format_list_enabled, bool debug_utils_enabled, enum u_logging_level log_level)
Initialize a bundle with objects given to us by client code, used by client_vk_compositor in Composit...
Definition: vk_bundle_init.c:1171
VkResult vk_create_image_mutable_rgba(struct vk_bundle *vk, VkExtent2D extent, VkImageUsageFlags usage, VkDeviceMemory *out_mem, VkImage *out_image)
Helper to create a mutable RG88B8A8 VkImage that specializes in the two UNORM and SRGB variants of th...
Definition: vk_helpers.c:934
XRT_CHECK_RESULT VkResult vk_convert_timestamps_to_host_ns(struct vk_bundle *vk, uint32_t count, uint64_t *in_out_timestamps)
Convert timestamps in GPU ticks (as return by VkQueryPool timestamp queries) into host CPU nanosecond...
XRT_CHECK_RESULT VkResult vk_create_semaphore_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkSemaphore *out_sem)
Creates a Vulkan semaphore from a native graphics sync handle.
Definition: vk_sync_objects.c:461
void vk_cmd_image_barrier_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, VkImage image, VkAccessFlags src_access_mask, VkAccessFlags dst_access_mask, VkImageLayout old_image_layout, VkImageLayout new_image_layout, VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask, VkImageSubresourceRange subresource_range)
Inserts a image barrier command, doesn't take any locks, the calling code will need hold the lock for...
Definition: vk_helpers.c:1689
VkResult vk_enumerate_physical_device_display_properties(struct vk_bundle *vk, VkPhysicalDevice physical_device, uint32_t *out_prop_count, VkDisplayPropertiesKHR **out_props)
Enumerate the display properties of the given VkPhysicalDevice.
XRT_CHECK_RESULT VkResult vk_create_timeline_semaphore_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkSemaphore *out_sem)
Creates a Vulkan timeline semaphore from a native graphics sync handle, see vk_create_semaphore_from_...
VkResult vk_create_image_simple(struct vk_bundle *vk, VkExtent2D extent, VkFormat format, VkImageUsageFlags usage, VkDeviceMemory *out_mem, VkImage *out_image)
Helper to create a VkImage.
Definition: vk_helpers.c:913
void vk_get_physical_device_queue_family_properties(struct vk_bundle *vk, VkPhysicalDevice physical_device, uint32_t *out_prop_count, VkQueueFamilyProperties **out_props)
Get the queue family properties of the given VkPhysicalDevice, note this function does not return a r...
Definition: vk_enumerate.c:128
VkResult vk_select_physical_device(struct vk_bundle *vk, int forced_index)
Setup the physical device, this is called by vk_create_device but has uses for outside of that.
Definition: vk_bundle_init.c:825
XRT_CHECK_RESULT VkResult vk_create_device(struct vk_bundle *vk, int forced_index, bool only_compute, VkQueueGlobalPriorityEXT global_priority, struct u_extension_list *required_device_ext_list, struct u_extension_list *optional_device_ext_list, const struct vk_device_features *optional_device_features)
Creates a VkDevice and initialises the VkQueue.
Definition: vk_bundle_init.c:831
void vk_print_device_info(struct vk_bundle *vk, enum u_logging_level log_level, const VkPhysicalDeviceProperties *pdp, uint32_t gpu_index, const char *title)
Print device information to the logger at the given logging level, if the vk_bundle has that level en...
Definition: vk_print.c:101
VkResult vk_enumerate_swapchain_images(struct vk_bundle *vk, VkSwapchainKHR swapchain, uint32_t *out_image_count, VkImage **out_images)
Enumerate the images of the given VkSwapchainKHR.
VkResult vk_deinit_mutex(struct vk_bundle *vk)
De-initialize mutexes in the vk_bundle.
Definition: vk_bundle_init.c:1152
XRT_CHECK_RESULT VkResult vk_create_semaphore_and_native(struct vk_bundle *vk, VkSemaphore *out_sem, xrt_graphics_sync_handle_t *out_native)
Creates a Vulkan semaphore and a native graphics sync handle.
Definition: vk_sync_objects.c:282
XRT_CHECK_RESULT VkResult vk_create_and_submit_fence_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t *out_native)
Creates a Vulkan fence, submits it to the default VkQueue and return its native graphics sync handle.
Definition: vk_sync_objects.c:105
VkResult vk_enumerate_surface_present_modes(struct vk_bundle *vk, VkSurfaceKHR surface, uint32_t *out_present_mode_count, VkPresentModeKHR **out_present_modes)
Enumerate the present modes of the given VkSurfaceKHR.
XRT_CHECK_RESULT VkResult vk_create_image_from_native(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info, struct xrt_image_native *image_native, VkImage *out_image, VkDeviceMemory *out_mem)
Creates a Vulkan device memory and image from a native graphics buffer handle.
Definition: vk_helpers.c:1074
VkResult vk_get_loader_functions(struct vk_bundle *vk, PFN_vkGetInstanceProcAddr g)
Can be done on a completely bare bundle.
Definition: vk_function_loaders.c:41
XRT_CHECK_RESULT bool vk_can_import_and_export_timeline_semaphore(struct vk_bundle *vk)
Is there a good likelihood that the import/export of a timeline semaphore will succeed,...
Definition: vk_sync_objects.c:77
VkResult vk_enumerate_physical_devices(struct vk_bundle *vk, uint32_t *out_physical_device_count, VkPhysicalDevice **out_physical_devices)
Enumerate the physical devices of the VkInstance that has been opened on the given vk_bundle.
Definition: vk_enumerate.c:80
XRT_CHECK_RESULT VkResult vk_create_fence_sync_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkFence *out_fence)
Creates a Vulkan fence from a native graphics sync handle.
Definition: vk_sync_objects.c:338
VkResult vk_enumerate_instance_extensions_properties(struct vk_bundle *vk, const char *layer_name, uint32_t *out_prop_count, VkExtensionProperties **out_props)
Return the VkExtensionProperties of the given layer_name, NULL means the "base" driver instance.
Definition: vk_enumerate.c:56
VkResult vk_create_view_usage(struct vk_bundle *vk, VkImage image, VkImageViewType type, VkFormat format, VkImageUsageFlags image_usage, VkImageSubresourceRange subresource_range, VkImageView *out_view)
Creates a image with a specific subset of usage, useful for a mutable images where one format might n...
Definition: vk_helpers.c:1511
VkResult vk_check_required_instance_extensions(struct vk_bundle *vk, struct u_extension_list *required_instance_ext_list)
Check if the required instance extensions are supported, if not print error message with all extensio...
Definition: vk_bundle_init.c:98
XRT_CHECK_RESULT VkResult vk_alloc_and_bind_image_memory(struct vk_bundle *vk, VkImage image, const VkMemoryRequirements *requirements, const void *pNext_for_allocate, const char *caller_name, VkDeviceMemory *out_mem)
Allocate memory for an image and bind it to that image.
Definition: vk_helpers.c:805
VkResult vk_enumerate_surface_formats(struct vk_bundle *vk, VkSurfaceKHR surface, uint32_t *out_format_count, VkSurfaceFormatKHR **out_formats)
Enumerate the surface formats of the given VkSurfaceKHR, returns a list of VkSurfaceFormatKHR,...
void vk_name_object(struct vk_bundle *vk, VkObjectType type, uint64_t object, const char *name)
Uses VK_EXT_debug_utils to set a name for an object, for easier debugging.
void vk_print_opened_device_info(struct vk_bundle *vk, enum u_logging_level log_level)
Print device information about the device that bundle manages at the given logging level if the vk_bu...
Definition: vk_print.c:129
VkResult vk_get_device_functions(struct vk_bundle *vk)
Requires a device to have been created and set on the bundle.
Definition: vk_function_loaders.c:64
XRT_CHECK_RESULT VkResult vk_get_native_handle_from_device_memory(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle)
Given a DeviceMemory handle created to be exportable, outputs the native buffer type (FD on desktop L...
Definition: vk_helpers.c:1368
VkResult vk_get_instance_functions(struct vk_bundle *vk)
Requires a instance to have been created and set on the bundle.
Definition: vk_function_loaders.c:55
void vk_cmd_insert_label(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const char *name)
Uses VK_EXT_debug_utils to insert debug label into a VkCommandBuffer.
void vk_print_result(struct vk_bundle *vk, const char *file, int line, const char *calling_func, VkResult ret, const char *called_func)
Print the result of a function, info level if ret == VK_SUCCESS and error level otherwise.
Definition: vk_print.c:75
VkResult vk_init_mutex(struct vk_bundle *vk)
Initialize mutexes in the vk_bundle.
Definition: vk_bundle_init.c:1136
VkResult vk_build_instance_extensions(struct vk_bundle *vk, struct u_extension_list *required_instance_ext_list, struct u_extension_list *optional_instance_ext_list, struct u_extension_list **out_instance_ext_list)
Build instance extensions from required and optional instance extensions.
Definition: vk_bundle_init.c:84
xrt_swapchain_usage_bits
Usage of the swapchain images.
Definition: xrt_compositor.h:510
xrt_swapchain_create_flags
Special flags for creating swapchain images.
Definition: xrt_compositor.h:499
Wrapper around OS threading native functions.
A wrapper around a native mutex.
Definition: os_threading.h:69
Definition: u_extension_list.cpp:32
Definition: vk_helpers.h:245
Definition: vk_helpers.h:56
uint32_t family_index
The queue family index.
Definition: vk_helpers.h:60
VkQueue queue
The Vulkan queue handle.
Definition: vk_helpers.h:58
struct os_mutex mutex
The queue mutex -.
Definition: vk_helpers.h:64
uint32_t index
The queue (instance) index.
Definition: vk_helpers.h:62
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:75
uint32_t max_bound_descriptor_sets
Maximum number of descriptor sets that can be simultaneously used by a pipeline.
Definition: vk_helpers.h:209
bool synchronization_2
Was synchronization2 requested, available, and enabled?
Definition: vk_helpers.h:194
uint32_t max_descriptor_set_samplers
Maximum number of samplers that can be included in a pipeline layout.
Definition: vk_helpers.h:212
bool timeline_semaphore
Were timeline semaphore requested, available, and enabled?
Definition: vk_helpers.h:191
uint32_t max_per_stage_descriptor_samplers
Maximum number of samplers that can be accessible to a single shader stage in a pipeline layout.
Definition: vk_helpers.h:218
bool video_maintenance_1
Was KHR_video_maintenance1 requested, available, and enabled?
Definition: vk_helpers.h:200
uint32_t timestamp_valid_bits
Valid bits in the queue selected.
Definition: vk_helpers.h:188
uint32_t max_sampler_allocation_count
Maximum number of sampler objects, as created by vkCreateSampler, which can simultaneously exist on.
Definition: vk_helpers.h:206
uint32_t max_descriptor_set_sampled_images
Maximum number of sampled images that can be included in a pipeline layout.
Definition: vk_helpers.h:215
uint32_t max_per_stage_descriptor_storage_images
Per stage limit on storage images.
Definition: vk_helpers.h:224
bool is_tegra
Is the GPU a tegra device.
Definition: vk_helpers.h:228
struct vk_bundle_queue * main_queue
Main queue for general work.
Definition: vk_helpers.h:102
bool timestamp_compute_and_graphics
Are timestamps available for compute and graphics queues?
Definition: vk_helpers.h:182
bool present_wait
Was KHR_present_wait requested, available, and enabled?
Definition: vk_helpers.h:197
struct vk_bundle_queue queues[3]
queues - a free list of unique queues
Definition: vk_helpers.h:92
uint32_t max_per_stage_descriptor_sampled_images
Per stage limit on sampled images (includes combined).
Definition: vk_helpers.h:221
float timestamp_period
Nanoseconds per gpu tick.
Definition: vk_helpers.h:185
struct vk_bundle_queue * graphics_queue
Graphics queue.
Definition: vk_helpers.h:111
Arguments to vk_create_descriptor_pool function.
Definition: vk_helpers.h:1242
uint32_t descriptor_count
The max count of created descriptors.
Definition: vk_helpers.h:1249
uint32_t uniform_per_descriptor_count
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
Definition: vk_helpers.h:1243
bool freeable
Are descriptors freeable, or must vkResetDescriptorPool be used.
Definition: vk_helpers.h:1252
uint32_t sampler_per_descriptor_count
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER.
Definition: vk_helpers.h:1244
uint32_t storage_image_per_descriptor_count
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE.
Definition: vk_helpers.h:1245
uint32_t storage_buffer_per_descriptor_count
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER.
Definition: vk_helpers.h:1246
Used to enable device features as a argument vk_create_device.
Definition: vk_helpers.h:859
Definition: vk_helpers.h:42
uint32_t index
The queue (instance) index.
Definition: vk_helpers.h:46
uint32_t family_index
The queue family index.
Definition: vk_helpers.h:44
A single image of a swapchain based on native buffer handles.
Definition: xrt_compositor.h:2162
Swapchain creation info.
Definition: xrt_compositor.h:871
A collection of strings, like a list of extensions to enable.
Basic logging functionality.
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:131
VkResult vk_create_descriptor_set(struct vk_bundle *vk, VkDescriptorPool descriptor_pool, VkDescriptorSetLayout descriptor_layout, VkDescriptorSet *out_descriptor_set)
Creates a descriptor set.
Definition: vk_state_creators.c:88
void vk_print_external_handles_info(struct vk_bundle *vk, enum u_logging_level log_level)
Print external handle features to the logger at the given logging level, if the vk_bundle has that le...
Definition: vk_print.c:153
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:65
XRT_CHECK_RESULT const char * vk_surface_transform_flag_string(VkSurfaceTransformFlagBitsKHR bits, bool null_on_unknown)
Returns the surface transform flag if one valid bit is set, if multiple bits are set,...
Definition: vk_helpers.c:696
void vk_fill_in_has_instance_extensions(struct vk_bundle *vk, struct u_extension_list *ext_list)
Fills in has_* in vk_bundle given a string of prefiltered instance extensions.
Definition: vk_bundle_init.c:130
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_helpers.c:741
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:214
void vk_print_queues_info(const struct vk_bundle *vk, enum u_logging_level log_level)
Print queue info to the logger at the given logging level, if the vk_bundle has that level enabled.
Definition: vk_print.c:308
VkResult vk_create_pipeline_cache(struct vk_bundle *vk, VkPipelineCache *out_pipeline_cache)
Creates a pipeline cache.
Definition: vk_state_creators.c:147
VkResult vk_create_descriptor_pool(struct vk_bundle *vk, const struct vk_descriptor_pool_info *info, VkDescriptorPool *out_descriptor_pool)
Creates a descriptor pool, made for a single layout.
Definition: vk_state_creators.c:16
void vk_print_swapchain_create_info(struct vk_bundle *vk, VkSwapchainCreateInfoKHR *i, enum u_logging_level log_level)
Print a VkSwapchainCreateInfoKHR, used to log during creation.
Definition: vk_print.c:254
XRT_CHECK_RESULT const char * vk_image_usage_flag_string(VkImageUsageFlagBits bits, bool null_on_unknown)
Returns the image usage flag if one valid bit is set, if multiple bits are set, will return 'MULTIPLE...
Definition: vk_helpers.c:625
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:79
XRT_CHECK_RESULT const char * vk_format_feature_flag_string(VkFormatFeatureFlagBits bits, bool null_on_unknown)
Returns the format feature flag if one valid bit is set, if multiple bits are set,...
Definition: vk_helpers.c:605
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:229
XRT_CHECK_RESULT const char * vk_composite_alpha_flag_string(VkCompositeAlphaFlagBitsKHR bits, bool null_on_unknown)
Returns the composite alpha flag if one valid bit is set, if multiple bits are set,...
Definition: vk_helpers.c:677
VkResult vk_create_compute_pipeline(struct vk_bundle *vk, VkPipelineCache pipeline_cache, VkShaderModule shader, VkPipelineLayout pipeline_layout, const VkSpecializationInfo *specialization_info, VkPipeline *out_compute_pipeline)
Creates a compute pipeline, assumes entry function is called 'main'.
Definition: vk_state_creators.c:172
void vk_print_features_info(struct vk_bundle *vk, enum u_logging_level log_level)
Print device features to the logger at the given logging level, if the vk_bundle has that level enabl...
Definition: vk_print.c:138
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:112
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:177
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:344
VkResult vk_create_pipeline_layout(struct vk_bundle *vk, VkDescriptorSetLayout descriptor_set_layout, VkPipelineLayout *out_pipeline_layout)
Creates a pipeline layout from a single descriptor set layout.
Definition: vk_state_creators.c:118
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:154
Header holding common defines.
Header declaring XRT graphics interfaces.
Native handle types.
int xrt_graphics_buffer_handle_t
The type underlying buffers shared between compositor clients and the main compositor.
Definition: xrt_handles.h:252
int xrt_graphics_sync_handle_t
The type underlying synchronization primitives (semaphores, etc) shared between compositor clients an...
Definition: xrt_handles.h:354
Include all of the Vulkan headers in one place, and cope with any "messy" includes implied by it.