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