Monado OpenXR Runtime
Loading...
Searching...
No Matches
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
26#include "util/u_logging.h"
28
29#include "vk/vk_print.h"
30#include "vk/vk_pretty_print.h"
31
32#include "os/os_threading.h"
33
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39
40#define VK_BUNDLE_MAX_QUEUES 3
41
42/*
43 *
44 * Structs
45 *
46 */
47
49{
50 //! The queue family index
51 uint32_t family_index;
52 //! The queue (instance) index
53 uint32_t index;
54};
55
56#define VK_NULL_QUEUE_PAIR \
57 XRT_C11_COMPOUND(struct vk_queue_pair) \
58 { \
59 .family_index = VK_QUEUE_FAMILY_IGNORED, .index = (uint32_t)-1, \
60 }
61
63{
64 //! The Vulkan queue handle
65 VkQueue queue;
66 //! The queue family index
67 uint32_t family_index;
68 //! The queue (instance) index
69 uint32_t index;
70 //! The queue mutex - @see vk_queue_lock, vk_queue_unlock
72};
73
74/*!
75 * A bundle of Vulkan functions and objects, used by both @ref comp and @ref
76 * comp_client. Note that they both have different instances of the object, and
77 * thus different VkInstance, etc.
78 *
79 * @ingroup aux_vk
80 */
82{
83 enum u_logging_level log_level;
84
85 VkInstance instance;
86 uint32_t version;
87 VkPhysicalDevice physical_device;
88 int physical_device_index;
89 VkDevice device;
90
91 /*!
92 * @brief queues - a free list of **unique** queues
93 *
94 * One per uniquely identifiable vk queue (family x instance index),
95 * duplicate entries must not be stored.
96 *
97 * Should not be used directly, @see main_queue, graphics_queue, encode_queue
98 */
99 struct vk_bundle_queue queues[VK_BUNDLE_MAX_QUEUES];
100
101 /*!
102 * @brief Main queue for general work.
103 *
104 * In normal mode, this is a graphics queue.
105 * In compute-only mode, this is a compute queue.
106 *
107 * May alias with graphics_queue.
108 */
110
111 /*!
112 * @brief Graphics queue.
113 *
114 * Always a graphics queue, even in compute-only mode.
115 * In normal mode, aliases with main_queue.
116 * In compute-only mode, this is a separate graphics queue.
117 */
119
120#if defined(VK_KHR_video_encode_queue)
121 /*!
122 * @brief Video encode queue.
123 *
124 * May be NULL if video encoding is not supported.
125 * May alias with other queues.
126 */
127 struct vk_bundle_queue *encode_queue;
128#endif
129
130 struct
131 {
132#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE)
133 bool color_image_import_opaque_win32;
134 bool color_image_export_opaque_win32;
135 bool depth_image_import_opaque_win32;
136 bool depth_image_export_opaque_win32;
137
138 bool color_image_import_d3d11;
139 bool color_image_export_d3d11;
140 bool depth_image_import_d3d11;
141 bool depth_image_export_d3d11;
142
143#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
144 bool color_image_import_opaque_fd;
145 bool color_image_export_opaque_fd;
146 bool depth_image_import_opaque_fd;
147 bool depth_image_export_opaque_fd;
148
149#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
150 bool color_image_import_opaque_fd;
151 bool color_image_export_opaque_fd;
152 bool depth_image_import_opaque_fd;
153 bool depth_image_export_opaque_fd;
154
155 bool color_image_import_ahardwarebuffer;
156 bool color_image_export_ahardwarebuffer;
157 bool depth_image_import_ahardwarebuffer;
158 bool depth_image_export_ahardwarebuffer;
159#endif
160
161#if defined(XRT_GRAPHICS_SYNC_HANDLE_IS_FD)
162 bool fence_sync_fd;
163 bool fence_opaque_fd;
164
165 bool binary_semaphore_sync_fd;
166 bool binary_semaphore_opaque_fd;
167
168 bool timeline_semaphore_sync_fd;
169 bool timeline_semaphore_opaque_fd;
170#elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE)
171 bool fence_win32_handle;
172
173 bool binary_semaphore_d3d12_fence;
174 bool binary_semaphore_win32_handle;
175
176 bool timeline_semaphore_d3d12_fence;
177 bool timeline_semaphore_win32_handle;
178#else
179#error "Need port for fence sync handles checkers"
180#endif
181 } external;
182
183 // Include the generated fields for has_KHR_extension.
184#include "vk_helpers_h_ext.h.inc"
185
186 struct
187 {
188 //! Are timestamps available for compute and graphics queues?
190
191 //! Nanoseconds per gpu tick.
193
194 //! Valid bits in the queue selected.
196
197 //! Were timeline semaphore requested, available, and enabled?
199
200 //! Was synchronization2 requested, available, and enabled?
202
203 //! Was KHR_present_id requested, available, and enabled?
205
206 //! Was KHR_present_id2 requested, available, and enabled?
208
209 //! Was KHR_present_wait requested, available, and enabled?
211
212 //! Was KHR_present_wait2 requested, available, and enabled?
214
215 //! Was KHR_video_maintenance1 requested, available, and enabled?
217
218 //! Was EXT_image_tiling_control requested, available, and enabled?
220 } features;
221
222 struct
223 {
224 //! Maximum number of sampler objects, as created by vkCreateSampler, which can simultaneously exist on
226
227 //! Maximum number of descriptor sets that can be simultaneously used by a pipeline.
229
230 //! Maximum number of samplers that can be included in a pipeline layout.
232
233 //! Maximum number of sampled images that can be included in a pipeline layout.
235
236 //! Maximum number of samplers that can be accessible to a single shader stage in a pipeline layout.
238
239 //! Per stage limit on sampled images (includes combined).
241
242 //! Per stage limit on storage images.
244 } limits;
245
246 //! Is the GPU a tegra device.
248
249
250 VkDebugReportCallbackEXT debug_report_cb;
251
252 VkPhysicalDeviceMemoryProperties device_memory_props;
253
254 // Loader functions
255 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
256 PFN_vkCreateInstance vkCreateInstance;
257 PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
258
259 // Include the generated function pointers fields.
260#include "vk_helpers_h_funcs.h.inc"
261};
262
264{
265 VkBuffer handle;
266 VkDeviceMemory memory;
267 uint32_t size;
268 void *data;
269};
270
271
272/*
273 *
274 * Helper defines.
275 *
276 */
277
278/*!
279 * This define will print if `RET` is not `VK_SUCCESS`, printing out that the
280 * @p FUNC_STR string has failed. The implicit argument @p vk will be used for
281 * the @ref vk_print_result call.
282 *
283 * Use this when you need to do special things after an error,
284 * but still want to pirnt the pretty message about the failure.
285 *
286 * @param RET The @p VkResult to check.
287 * @param FUNC_STR String literal with the function name, used for logging.
288 *
289 * @ingroup aux_vk
290 *
291 * @see VK_CHK_AND_RET
292 * @see VK_CHK_WITH_RET
293 * @see VK_CHK_WITH_GOTO
294 */
295#define VK_CHK_ONLY_PRINT(RET, FUNC_STR) \
296 do { \
297 VkResult _ret = RET; \
298 if (_ret != VK_SUCCESS) { \
299 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
300 } \
301 } while (false)
302
303/*!
304 * This define will error if `RET` is not `VK_SUCCESS`, printing out that the
305 * @p FUNC_STR string has failed, then returns @p RET. The implicit argument
306 * @p vk will be used for the @ref vk_print_result call.
307 *
308 * Use this macro when your function returns a `VkResult`.
309 *
310 * @param RET The @p VkResult to check.
311 * @param FUNC_STR String literal with the function name, used for logging.
312 *
313 * @ingroup aux_vk
314 *
315 * @see VK_CHK_ONLY_PRINT
316 * @see VK_CHK_WITH_RET
317 * @see VK_CHK_WITH_GOTO
318 */
319#define VK_CHK_AND_RET(RET, FUNC_STR) \
320 do { \
321 VkResult _ret = RET; \
322 if (_ret != VK_SUCCESS) { \
323 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
324 return _ret; \
325 } \
326 } while (false)
327
328/*!
329 * This define will error if @p RET is not @p VK_SUCCESS, printing out that the
330 * @p FUNC_STR string has failed, then returns @p TO_RET. The implicit argument
331 * @p vk will be used for the @ref vk_print_result call.
332 *
333 * Use this macro when your function doesn't return a `VkResult`.
334 *
335 * @param RET The @p VkResult to check.
336 * @param FUNC_STR String literal with the function name, used for logging.
337 * @param TO_RET Value to return, upon error
338 *
339 * @ingroup aux_vk
340 *
341 * @see VK_CHK_ONLY_PRINT
342 * @see VK_CHK_AND_RET
343 * @see VK_CHK_WITH_GOTO
344 */
345#define VK_CHK_WITH_RET(RET, FUNC_STR, TO_RET) \
346 do { \
347 VkResult _ret = RET; \
348 if (_ret != VK_SUCCESS) { \
349 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
350 return TO_RET; \
351 } \
352 } while (false)
353
354/*!
355 * This define will error if @p RET is not @p VK_SUCCESS, printing out that the
356 * @p FUNC_STR string has failed, then goto @p GOTO. The implicit argument @p vk
357 * will be used for the @ref vk_print_result call.
358 *
359 * Use this macro when your function needs to `goto` some cleanup code and
360 * return from there.
361 *
362 * @param RET The @p VkResult to check.
363 * @param FUNC_STR String literal with the function name, used for logging.
364 * @param GOTO Label to jump to, upon error
365 *
366 * @ingroup aux_vk
367 *
368 * @see VK_CHK_ONLY_PRINT
369 * @see VK_CHK_AND_RET
370 * @see VK_CHK_WITH_RET
371 */
372#define VK_CHK_WITH_GOTO(RET, FUNC_STR, GOTO) \
373 do { \
374 VkResult _ret = RET; \
375 if (_ret != VK_SUCCESS) { \
376 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
377 goto GOTO; \
378 } \
379 } while (false)
380
381//! For xrt_result_t, see @ref VK_CHK_AND_RET.
382#define XVK_CHK_AND_RET(...) U_LOG_CHK_AND_RET(vk->log_level, __VA_ARGS__)
383//! For xrt_result_t, see @ref VK_CHK_WITH_GOTO.
384#define XVK_CHK_WITH_GOTO(...) U_LOG_CHK_WITH_GOTO(vk->log_level, __VA_ARGS__)
385//! For xrt_result_t, see @ref VK_CHK_WITH_RET.
386#define XVK_CHK_WITH_RET(...) U_LOG_CHK_WITH_RET(vk->log_level, __VA_ARGS__)
387//! For xrt_result_t, see @ref VK_CHK_ONLY_PRINT.
388#define XVK_CHK_ONLY_PRINT(...) U_LOG_CHK_ONLY_PRINT(vk->log_level, __VA_ARGS__)
389//! For xrt_result_t, see @ref VK_CHK_ALWAYS_RET.
390#define XVK_CHK_ALWAYS_RET(...) U_LOG_CHK_ALWAYS_RET(vk->log_level, __VA_ARGS__)
391
392static inline void
393vk_append_to_pnext_chain(VkBaseInStructure *head, VkBaseInStructure *new_struct)
394{
395 assert(new_struct->pNext == NULL);
396 // Insert ourselves between head and its previous pNext
397 new_struct->pNext = head->pNext;
398 head->pNext = new_struct;
399}
400
401
402/*
403 *
404 * Function and helpers.
405 *
406 */
407
408#define VK_TRACE(d, ...) U_LOG_IFL_T(d->log_level, __VA_ARGS__)
409#define VK_DEBUG(d, ...) U_LOG_IFL_D(d->log_level, __VA_ARGS__)
410#define VK_INFO(d, ...) U_LOG_IFL_I(d->log_level, __VA_ARGS__)
411#define VK_WARN(d, ...) U_LOG_IFL_W(d->log_level, __VA_ARGS__)
412#define VK_ERROR(d, ...) U_LOG_IFL_E(d->log_level, __VA_ARGS__)
413
414
415/*
416 *
417 * Debug helper functions, in the vk_debug.c file.
418 *
419 */
420
421#if defined(VK_EXT_debug_utils) || defined(XRT_DOXYGEN)
422
423/*!
424 * Uses VK_EXT_debug_utils to set a name for an object, for easier debugging.
425 *
426 * @ingroup aux_vk
427 */
428void
429vk_name_object(struct vk_bundle *vk, VkObjectType type, uint64_t object, const char *name);
430
431/*!
432 * Small helper for @ref vk_name_object that makes use of pre-process to avoid
433 * writing out long type names.
434 *
435 * @ingroup aux_vk
436 */
437#define VK_NAME_OBJ(VK, TYPE, SUFFIX, OBJ, NAME) \
438 do { \
439 if ((VK)->has_EXT_debug_utils) { \
440 XRT_MAYBE_UNUSED TYPE _thing = (TYPE)(OBJ); \
441 vk_name_object(VK, VK_OBJECT_TYPE_##SUFFIX, (uint64_t)OBJ, NAME); \
442 } \
443 } while (false)
444
445
446#else
447
448#define VK_NAME_OBJ(VK, TYPE, SUFFIX, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, TYPE, OBJ)
449
450#endif
451
452/*!
453 * Some combinations of Vulkan implementation and types are broken, we still
454 * want type safety so we have this define. Examples of broken combinations:
455 *
456 * 1. Both Mesa and the Vulkan loader didn't support setting names on the
457 * VkInstance, loader got support in 1.3.261 and Mesa hasn't as of writing.
458 * 2. For Mesa drivers we can not name VkSurfaceKHR objects on some systems as
459 * it causes memory corruption, asserts, crashes or functions failing. This
460 * is as of writing broken on the 23.2.1 release, fixed in main and scheduled
461 * for the 23.2.2 release.
462 * 3. Mesa RADV leaks the name strings for VkDescriptorSet objects for pools
463 * that we use the reset function.
464 *
465 * @ingroup aux_vk
466 */
467#define VK_NAME_OBJ_DISABLED(VK, TYPE, OBJ) \
468 do { \
469 XRT_MAYBE_UNUSED TYPE _thing = (TYPE)(OBJ); \
470 } while (false)
471
472
473// clang-format off
474// VK_DEFINE_HANDLE types are always pointers
475#define VK_NAME_INSTANCE(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkInstance, (uintptr_t)OBJ)
476#define VK_NAME_PHYSICAL_DEVICE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPhysicalDevice, PHYSICAL_DEVICE, (uintptr_t)OBJ, NAME)
477#define VK_NAME_DEVICE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDevice, DEVICE, (uintptr_t)OBJ, NAME)
478#define VK_NAME_QUEUE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkQueue, QUEUE, (uintptr_t)OBJ, NAME)
479#define VK_NAME_COMMAND_BUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkCommandBuffer, COMMAND_BUFFER, (uintptr_t)OBJ, NAME)
480// VK_DEFINE_NON_DISPATCHABLE_HANDLE types are pointers in 64-bits and uint64_t in 32-bits
481#define VK_NAME_SEMAPHORE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSemaphore, SEMAPHORE, OBJ, NAME)
482#define VK_NAME_FENCE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkFence, FENCE, OBJ, NAME)
483#define VK_NAME_DEVICE_MEMORY(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDeviceMemory, DEVICE_MEMORY, OBJ, NAME)
484#define VK_NAME_BUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkBuffer, BUFFER, OBJ, NAME)
485#define VK_NAME_IMAGE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkImage, IMAGE, OBJ, NAME)
486#define VK_NAME_EVENT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkEvent, EVENT, OBJ, NAME)
487#define VK_NAME_QUERY_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkQueryPool, QUERY_POOL, OBJ, NAME)
488#define VK_NAME_BUFFER_VIEW(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkBufferView, BUFFER_VIEW, OBJ, NAME)
489#define VK_NAME_IMAGE_VIEW(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkImageView, IMAGE_VIEW, OBJ, NAME)
490#define VK_NAME_SHADER_MODULE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkShaderModule, SHADER_MODULE, OBJ, NAME)
491#define VK_NAME_PIPELINE_CACHE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipelineCache, PIPELINE_CACHE, OBJ, NAME)
492#define VK_NAME_PIPELINE_LAYOUT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipelineLayout, PIPELINE_LAYOUT, OBJ, NAME)
493#define VK_NAME_RENDER_PASS(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkRenderPass, RENDER_PASS, OBJ, NAME)
494#define VK_NAME_PIPELINE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipeline, PIPELINE, OBJ, NAME)
495#define VK_NAME_DESCRIPTOR_SET_LAYOUT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDescriptorSetLayout, DESCRIPTOR_SET_LAYOUT, OBJ, NAME)
496#define VK_NAME_SAMPLER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSampler, SAMPLER, OBJ, NAME)
497#define VK_NAME_DESCRIPTOR_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDescriptorPool, DESCRIPTOR_POOL, OBJ, NAME)
498#define VK_NAME_DESCRIPTOR_SET(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkDescriptorSet, OBJ)
499#define VK_NAME_FRAMEBUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkFramebuffer, FRAMEBUFFER, OBJ, NAME)
500#define VK_NAME_COMMAND_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkCommandPool, COMMAND_POOL, OBJ, NAME)
501
502#define VK_NAME_SURFACE(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkSurfaceKHR, OBJ)
503#define VK_NAME_SWAPCHAIN(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSwapchainKHR, SWAPCHAIN_KHR, OBJ, NAME)
504// clang-format on
505
506
507/*
508 *
509 * Enumeration helpers, in the vk_enumerate.c file.
510 *
511 */
512
513/*!
514 * Return the @p VkExtensionProperties of the given @p layer_name, NULL means
515 * the "base" driver instance.
516 *
517 * @ingroup aux_vk
518 */
519VkResult
521 const char *layer_name,
522 uint32_t *out_prop_count,
523 VkExtensionProperties **out_props);
524
525/*!
526 * Enumerate the physical devices of the @p VkInstance that has been opened on
527 * the given @ref vk_bundle.
528 *
529 * @ingroup aux_vk
530 */
531VkResult
533 uint32_t *out_physical_device_count,
534 VkPhysicalDevice **out_physical_devices);
535
536/*!
537 * Enumerate the extension properties of the given @p VkPhysicalDevice for the
538 * named @p layer_name, NULL means the "base" driver physical device.
539 *
540 * @ingroup aux_vk
541 */
542VkResult
544 VkPhysicalDevice physical_device,
545 const char *layer_name,
546 uint32_t *out_prop_count,
547 VkExtensionProperties **out_props);
548
549/*!
550 * Get the queue family properties of the given @p VkPhysicalDevice, note this
551 * function does not return a result, it will assert if it can not allocate the
552 * array of properties. If there are no queue family properties, the function
553 * will return a count of 0 and set the output pointer to NULL.
554 *
555 * @ingroup aux_vk
556 */
557void
559 VkPhysicalDevice physical_device,
560 uint32_t *out_prop_count,
561 VkQueueFamilyProperties **out_props);
562
563#if defined(VK_KHR_surface) || defined(XRT_DOXYGEN)
564/*!
565 * Enumerate the surface formats of the given @p VkSurfaceKHR,
566 * returns a list of @p VkSurfaceFormatKHR, not @p VkFormat.
567 *
568 * @ingroup aux_vk
569 */
570VkResult
572 VkSurfaceKHR surface,
573 uint32_t *out_format_count,
574 VkSurfaceFormatKHR **out_formats);
575
576/*!
577 * Enumerate the present modes of the given @p VkSurfaceKHR.
578 *
579 * @ingroup aux_vk
580 */
581VkResult
583 VkSurfaceKHR surface,
584 uint32_t *out_present_mode_count,
585 VkPresentModeKHR **out_present_modes);
586#endif
587
588#if defined(VK_KHR_swapchain) || defined(XRT_DOXYGEN)
589/*!
590 * Enumerate the images of the given @p VkSwapchainKHR.
591 *
592 * @ingroup aux_vk
593 */
594VkResult
596 VkSwapchainKHR swapchain,
597 uint32_t *out_image_count,
598 VkImage **out_images);
599#endif
600
601#if defined(VK_USE_PLATFORM_DISPLAY_KHR) || defined(XRT_DOXYGEN)
602/*!
603 * Enumerate the display properties of the given @p VkPhysicalDevice.
604 *
605 * @ingroup aux_vk
606 */
607VkResult
609 VkPhysicalDevice physical_device,
610 uint32_t *out_prop_count,
611 VkDisplayPropertiesKHR **out_props);
612
613/*!
614 * Enumerate the display plane properties of the given @p VkPhysicalDevice.
615 *
616 * @ingroup aux_vk
617 */
618VkResult
620 VkPhysicalDevice physical_device,
621 uint32_t *out_prop_count,
622 VkDisplayPlanePropertiesKHR **out_props);
623
624/*!
625 * Enumerate the mode properties of the given @p VkDisplayKHR, which belongs
626 * to the given @p VkPhysicalDevice.
627 *
628 * @ingroup aux_vk
629 */
630VkResult
632 VkPhysicalDevice physical_device,
633 VkDisplayKHR display,
634 uint32_t *out_prop_count,
635 VkDisplayModePropertiesKHR **out_props);
636#endif
637
638
639/*
640 *
641 * Struct init functions, in the vk_function_loaders.c file.
642 *
643 */
644
645/*!
646 * Can be done on a completely bare bundle.
647 *
648 * @ingroup aux_vk
649 */
650VkResult
651vk_get_loader_functions(struct vk_bundle *vk, PFN_vkGetInstanceProcAddr g);
652
653/*!
654 * Requires a instance to have been created and set on the bundle.
655 *
656 * @ingroup aux_vk
657 */
658VkResult
660
661/*!
662 * Requires a device to have been created and set on the bundle.
663 *
664 * @ingroup aux_vk
665 */
666VkResult
668
669
670/*
671 *
672 * Bundle init functions, in the vk_bundle_init.c file.
673 *
674 */
675
676/*!
677 * Check if the required instance extensions are supported, if not print error
678 * message with all extensions missing, returns VK_ERROR_EXTENSION_NOT_PRESENT
679 * if not all extensions are supported.
680 *
681 * @ingroup aux_vk
682 */
683VkResult
684vk_check_required_instance_extensions(struct vk_bundle *vk, struct u_extension_list *required_instance_ext_list);
685
686/*!
687 * Build instance extensions from required and optional instance extensions.
688 * This function enumerates available instance extensions, checks required ones,
689 * and builds a final list. Returns VK_SUCCESS if successful.
690 * Only requires @ref vk_get_loader_functions to have been called.
691 *
692 * @ingroup aux_vk
693 */
694VkResult
696 struct u_extension_list *required_instance_ext_list,
697 struct u_extension_list *optional_instance_ext_list,
698 struct u_extension_list **out_instance_ext_list);
699
700/*!
701 * Fills in has_* in vk_bundle given a string of prefiltered instance extensions
702 */
703void
705
706/*!
707 * Setup the physical device, this is called by vk_create_device but has uses
708 * for outside of that.
709 *
710 * @ingroup aux_vk
711 */
712VkResult
713vk_select_physical_device(struct vk_bundle *vk, int forced_index);
714
715/*!
716 * Used to enable device features as a argument @ref vk_create_device.
717 *
718 * @ingroup aux_vk
719 */
721{
722 bool shader_image_gather_extended;
723 bool shader_storage_image_write_without_format;
724 bool null_descriptor;
725 bool timeline_semaphore;
726 bool synchronization_2;
727 bool ext_fmt_resolve;
728 bool storage_buffer_8bit_access;
729 bool present_id;
730 bool present_id2;
731 bool present_wait;
732 bool present_wait2;
733 bool video_maintenance_1;
734 bool image_tiling_control;
735};
736
737/*!
738 * Creates a VkDevice and initialises the VkQueue.
739 *
740 * The @p vk_bundle must have been zero initialized, have the instance functions
741 * loaded and a valid instance.
742 *
743 * @ingroup aux_vk
744 */
745XRT_CHECK_RESULT VkResult
746vk_create_device(struct vk_bundle *vk,
747 int forced_index,
748 bool only_compute,
749 bool realtime_priority,
750 struct u_extension_list *required_device_ext_list,
751 struct u_extension_list *optional_device_ext_list,
752 const struct vk_device_features *optional_device_features);
753
754/*!
755 * @brief Initialize mutexes in the @ref vk_bundle.
756 *
757 * Not required for all uses, but a precondition for some.
758 *
759 * @ingroup aux_vk
760 */
761VkResult
762vk_init_mutex(struct vk_bundle *vk);
763
764/*!
765 * @brief De-initialize mutexes in the @ref vk_bundle.
766 *
767 * @ingroup aux_vk
768 */
769VkResult
770vk_deinit_mutex(struct vk_bundle *vk);
771
772static inline void
773vk_queue_lock(struct vk_bundle_queue *q)
774{
775 assert(q != NULL);
776 os_mutex_lock(&q->mutex);
777}
778
779static inline int
780vk_queue_trylock(struct vk_bundle_queue *q)
781{
782 assert(q != NULL);
783 return os_mutex_trylock(&q->mutex);
784}
785
786static inline void
787vk_queue_unlock(struct vk_bundle_queue *q)
788{
789 assert(q != NULL);
790 os_mutex_unlock(&q->mutex);
791}
792
793/*!
794 * Initialize a bundle with objects given to us by client code,
795 * used by @ref client_vk_compositor in @ref comp_client.
796 *
797 * @ingroup aux_vk
798 */
799XRT_CHECK_RESULT VkResult
801 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
802 VkInstance instance,
803 VkPhysicalDevice physical_device,
804 VkDevice device,
805 uint32_t queue_family_index,
806 uint32_t queue_index,
807 bool external_fence_fd_enabled,
808 bool external_semaphore_fd_enabled,
809 bool timeline_semaphore_enabled,
810 bool image_format_list_enabled,
811 bool debug_utils_enabled,
812 enum u_logging_level log_level);
813
814
815/*
816 *
817 * Other functions.
818 *
819 */
820
821/*!
822 * @ingroup aux_vk
823 */
824bool
825vk_get_memory_type(struct vk_bundle *vk, uint32_t type_bits, VkMemoryPropertyFlags memory_props, uint32_t *out_type_id);
826
827/*!
828 * Allocate memory for an image and bind it to that image.
829 *
830 * Handles the following steps:
831 *
832 * - calling vkGetImageMemoryRequirements
833 * - comparing against the max_size
834 * - getting the memory type (as dictated by the VkMemoryRequirements and
835 * VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
836 * - calling vkAllocateMemory
837 * - calling vkBindImageMemory
838 * - calling vkDestroyMemory in case of an error.
839 *
840 * If this fails, it cleans up the VkDeviceMemory.
841 *
842 * @param vk Vulkan bundle
843 * @param image The VkImage to allocate for and bind.
844 * @param requirements Memory requirements used for finding the memory type and the size.
845 * @param pNext_for_allocate (Optional) a pointer to use in the pNext chain of
846 * VkMemoryAllocateInfo.
847 * @param caller_name Used for error printing, this function is called from
848 * various sources and takes next chains that could influence the result
849 * of various calls inside of it. Since it's up to this function to print
850 * any errors it will add the caller name to error messages.
851 * @param out_mem Output parameter: will be set to the allocated memory if
852 * everything succeeds. Not modified if there is an error.
853 *
854 * If this fails, you may want to destroy your VkImage as well, since this
855 * routine is usually used in combination with vkCreateImage.
856 *
857 * @ingroup aux_vk
858 */
859XRT_CHECK_RESULT VkResult
861 VkImage image,
862 const VkMemoryRequirements *requirements,
863 const void *pNext_for_allocate,
864 const char *caller_name,
865 VkDeviceMemory *out_mem);
866
867/*!
868 *
869 * @brief Creates a Vulkan device memory and image from a native graphics buffer handle.
870 *
871 * In case of error, ownership is never transferred and the caller should close the handle themselves.
872 *
873 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p image_native
874 * handle may have transferred, a reference may have been added, or the Vulkan objects may rely on the caller to keep
875 * the native handle alive until the Vulkan objects are destroyed. Which option applies depends on the particular native
876 * handle type used.
877 *
878 * See the corresponding specification texts:
879 *
880 * - Windows:
881 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportMemoryWin32HandleInfoKHR
882 * - Linux: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportMemoryFdInfoKHR
883 * - Android:
884 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportAndroidHardwareBufferInfoANDROID
885 *
886 * @ingroup aux_vk
887 */
888XRT_CHECK_RESULT VkResult
890 const struct xrt_swapchain_create_info *info,
891 struct xrt_image_native *image_native,
892 VkImage *out_image,
893 VkDeviceMemory *out_mem);
894
895/*!
896 * Given a DeviceMemory handle created to be exportable, outputs the native buffer type (FD on desktop Linux)
897 * equivalent.
898 *
899 * Caller assumes ownership of handle which should be unreferenced with @ref u_graphics_buffer_unref when no longer
900 * needed.
901 *
902 * @param vk Vulkan bundle
903 * @param device_memory The memory to get the handle of
904 * @param[out] out_handle A pointer to the handle to populate
905 *
906 * @ingroup aux_vk
907 */
908XRT_CHECK_RESULT VkResult
910 VkDeviceMemory device_memory,
911 xrt_graphics_buffer_handle_t *out_handle);
912
913/*!
914 * @ingroup aux_vk
915 * Helper to create a VkImage
916 */
917VkResult
919 VkExtent2D extent,
920 VkFormat format,
921 VkImageUsageFlags usage,
922 VkDeviceMemory *out_mem,
923 VkImage *out_image);
924
925/*!
926 * Helper to create a mutable RG88B8A8 VkImage that specializes in the two
927 * UNORM and SRGB variants of that formats.
928 *
929 * @ingroup aux_vk
930 */
931VkResult
933 struct vk_bundle *vk, VkExtent2D extent, VkImageUsageFlags usage, VkDeviceMemory *out_mem, VkImage *out_image);
934
935/*!
936 * @ingroup aux_vk
937 * Helper to create a VkImage, with more options for tiling and memory storage.
938 */
939VkResult
941 VkExtent3D extent,
942 VkFormat format,
943 VkImageTiling image_tiling,
944 VkImageUsageFlags image_usage_flags,
945 VkMemoryPropertyFlags memory_property_flags,
946 VkDeviceMemory *out_mem,
947 VkImage *out_image);
948
949/*!
950 * @ingroup aux_vk
951 */
952VkResult
953vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampler *out_sampler);
954
955
956/*
957 *
958 * Helpers for creating ímage views.
959 *
960 */
961
962/*!
963 * @ingroup aux_vk
964 */
965VkResult
966vk_create_view(struct vk_bundle *vk,
967 VkImage image,
968 VkImageViewType type,
969 VkFormat format,
970 VkImageSubresourceRange subresource_range,
971 VkImageView *out_view);
972
973/*!
974 * @ingroup aux_vk
975 */
976VkResult
977vk_create_view_swizzle(struct vk_bundle *vk,
978 VkImage image,
979 VkImageViewType type,
980 VkFormat format,
981 VkImageSubresourceRange subresource_range,
982 VkComponentMapping components,
983 VkImageView *out_view);
984
985/*!
986 * Creates a swizzled image view with a specific subset of usage, useful for a mutable image where one format might
987 * not support all usages defined by the image.
988 *
989 * @ingroup aux_vk
990 */
991VkResult
993 VkImage image,
994 VkImageViewType type,
995 VkFormat format,
996 VkImageUsageFlags image_usage,
997 VkImageSubresourceRange subresource_range,
998 VkComponentMapping components,
999 VkImageView *out_view);
1000
1001/*!
1002 * Creates a image with a specific subset of usage, useful for a mutable images
1003 * where one format might not support all usages defined by the image.
1004 *
1005 * @ingroup aux_vk
1006 */
1007VkResult
1009 VkImage image,
1010 VkImageViewType type,
1011 VkFormat format,
1012 VkImageUsageFlags image_usage,
1013 VkImageSubresourceRange subresource_range,
1014 VkImageView *out_view);
1015
1016
1017/*
1018 *
1019 * Helpers for creating descriptor pools and sets.
1020 *
1021 */
1022
1023bool
1024vk_init_descriptor_pool(struct vk_bundle *vk,
1025 const VkDescriptorPoolSize *pool_sizes,
1026 uint32_t pool_size_count,
1027 uint32_t set_count,
1028 VkDescriptorPool *out_descriptor_pool);
1029
1030bool
1031vk_allocate_descriptor_sets(struct vk_bundle *vk,
1032 VkDescriptorPool descriptor_pool,
1033 uint32_t count,
1034 const VkDescriptorSetLayout *set_layout,
1035 VkDescriptorSet *sets);
1036
1037
1038/*
1039 *
1040 * Helpers for creating buffers.
1041 *
1042 */
1043
1044bool
1045vk_buffer_init(struct vk_bundle *vk,
1046 VkDeviceSize size,
1047 VkBufferUsageFlags usage,
1048 VkMemoryPropertyFlags properties,
1049 VkBuffer *out_buffer,
1050 VkDeviceMemory *out_mem);
1051
1052void
1053vk_buffer_destroy(struct vk_buffer *self, struct vk_bundle *vk);
1054
1055bool
1056vk_update_buffer(struct vk_bundle *vk, float *buffer, size_t buffer_size, VkDeviceMemory memory);
1057
1058
1059/*
1060 *
1061 * Helpers for writing command buffers, in the vk_helpers.c file.
1062 *
1063 */
1064
1065/*!
1066 * Inserts a image barrier command, doesn't take any locks, the calling code
1067 * will need hold the lock for the pool that cmd_buffer is from or ensure it is
1068 * externally synchronized.
1069 *
1070 * @ingroup aux_vk
1071 */
1072void
1074 VkCommandBuffer cmd_buffer,
1075 VkImage image,
1076 VkAccessFlags src_access_mask,
1077 VkAccessFlags dst_access_mask,
1078 VkImageLayout old_image_layout,
1079 VkImageLayout new_image_layout,
1080 VkPipelineStageFlags src_stage_mask,
1081 VkPipelineStageFlags dst_stage_mask,
1082 VkImageSubresourceRange subresource_range);
1083
1084/*!
1085 * Inserts a image barrier command specifically for GPU commands, doesn't take
1086 * any locks, the calling code will need hold the lock for the pool that
1087 * cmd_buffer is from or ensure it is externally synchronized.
1088 *
1089 * @ingroup aux_vk
1090 */
1091void
1093 VkCommandBuffer cmd_buffer,
1094 VkImage image,
1095 VkAccessFlags src_access_mask,
1096 VkAccessFlags dst_access_mask,
1097 VkImageLayout old_layout,
1098 VkImageLayout new_layout,
1099 VkImageSubresourceRange subresource_range);
1100
1101#if defined(VK_EXT_debug_utils) || defined(XRT_DOXYGEN)
1102/*!
1103 * Uses VK_EXT_debug_utils to insert debug label into a VkCommandBuffer.
1104 *
1105 * In the vk_debug.c file.
1106 *
1107 * @ingroup aux_vk
1108 */
1109void
1110vk_cmd_insert_label(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const char *name);
1111#endif
1112
1113
1114/*
1115 *
1116 * State creation helpers, in the vk_state_creators.c file.
1117 *
1118 */
1119
1120/*!
1121 * Arguments to @ref vk_create_descriptor_pool function.
1122 */
1124{
1125 uint32_t uniform_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
1126 uint32_t sampler_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
1127 uint32_t storage_image_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
1128 uint32_t storage_buffer_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
1129
1130 //! The max count of created descriptors.
1132
1133 //! Are descriptors freeable, or must vkResetDescriptorPool be used.
1135};
1136
1137/*!
1138 * Creates a descriptor pool, made for a single layout.
1139 *
1140 * Does error logging.
1141 */
1142VkResult
1144 const struct vk_descriptor_pool_info *info,
1145 VkDescriptorPool *out_descriptor_pool);
1146
1147/*!
1148 * Creates a descriptor set.
1149 *
1150 * Does error logging.
1151 */
1152VkResult
1154 VkDescriptorPool descriptor_pool,
1155 VkDescriptorSetLayout descriptor_layout,
1156 VkDescriptorSet *out_descriptor_set);
1157
1158/*!
1159 * Creates a pipeline layout from a single descriptor set layout.
1160 *
1161 * Does error logging.
1162 */
1163VkResult
1165 VkDescriptorSetLayout descriptor_set_layout,
1166 VkPipelineLayout *out_pipeline_layout);
1167
1168/*!
1169 * Creates a pipeline cache.
1170 *
1171 * Does error logging.
1172 */
1173VkResult
1174vk_create_pipeline_cache(struct vk_bundle *vk, VkPipelineCache *out_pipeline_cache);
1175
1176/*!
1177 * Creates a compute pipeline, assumes entry function is called 'main'.
1178 *
1179 * Does error logging.
1180 */
1181VkResult
1183 VkPipelineCache pipeline_cache,
1184 VkShaderModule shader,
1185 VkPipelineLayout pipeline_layout,
1186 const VkSpecializationInfo *specialization_info,
1187 VkPipeline *out_compute_pipeline);
1188
1189
1190/*
1191 *
1192 * Sync objects, in the vk_sync_objects.c file.
1193 *
1194 */
1195
1196/*!
1197 * Is there a good likelihood that the import/export of a timeline semaphore
1198 * will succeed, in other words will the below functions work.
1199 *
1200 * @ingroup aux_vk
1201 */
1202XRT_CHECK_RESULT bool
1204
1205/*!
1206 * @brief Creates a Vulkan fence, submits it to the default VkQueue and return
1207 * its native graphics sync handle.
1208 *
1209 * In case of error, out_native is not touched by the function.
1210 *
1211 * See @ref vk_create_fence_sync_from_native for ownership semantics on import.
1212 *
1213 * @ingroup aux_vk
1214 */
1215XRT_CHECK_RESULT VkResult
1217
1218/*!
1219 * @brief Creates a Vulkan fence from a native graphics sync handle.
1220 *
1221 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1222 *
1223 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p native
1224 * handle may have transferred, a reference may have been added, or the Vulkan object may rely on the caller to keep the
1225 * native handle alive until the Vulkan object is destroyed. Which option applies depends on the particular native
1226 * handle type used.
1227 *
1228 * See the corresponding Vulkan specification text:
1229 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#synchronization-fences-importing
1230 *
1231 * @ingroup aux_vk
1232 */
1233XRT_CHECK_RESULT VkResult
1234vk_create_fence_sync_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkFence *out_fence);
1235
1236/*!
1237 * Creates a Vulkan semaphore and a native graphics sync handle.
1238 *
1239 * In case of success, the underlying Vulkan functionality's ownership semantics
1240 * apply: ownership of the @p native handle may have transferred, a reference
1241 * may have been added, or the Vulkan object may rely on the caller to keep the
1242 * native handle alive until the Vulkan object is destroyed. Which option
1243 * applies depends on the particular native handle type used.
1244 *
1245 * In case of error, neither @p out_sem and @p out_native is not touched by the
1246 * function so the caller only becomes responsible for the output on success.
1247 *
1248 * See the corresponding Vulkan specification text:
1249 * https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#synchronization-semaphores
1250 *
1251 * @ingroup aux_vk
1252 */
1253XRT_CHECK_RESULT VkResult
1254vk_create_semaphore_and_native(struct vk_bundle *vk, VkSemaphore *out_sem, xrt_graphics_sync_handle_t *out_native);
1255
1256#if defined(VK_KHR_timeline_semaphore) || defined(XRT_DOXYGEN)
1257/*
1258 * Creates a Vulkan timeline semaphore and a native graphics sync
1259 * handle, see @ref vk_create_semaphore_and_native for more details.
1260 *
1261 * @ingroup aux_vk
1262 */
1263XRT_CHECK_RESULT VkResult
1264vk_create_timeline_semaphore_and_native(struct vk_bundle *vk,
1265 VkSemaphore *out_sem,
1266 xrt_graphics_sync_handle_t *out_native);
1267#endif
1268
1269/*!
1270 * @brief Creates a Vulkan semaphore from a native graphics sync handle.
1271 *
1272 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1273 *
1274 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p native
1275 * handle may have transferred, a reference may have been added, or the Vulkan object may rely on the caller to keep the
1276 * native handle alive until the Vulkan object is destroyed. Which option applies depends on the particular native
1277 * handle type used.
1278 *
1279 * @ingroup aux_vk
1280 */
1281XRT_CHECK_RESULT VkResult
1282vk_create_semaphore_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkSemaphore *out_sem);
1283
1284#if defined(VK_KHR_timeline_semaphore) || defined(XRT_DOXYGEN)
1285/*!
1286 * @brief Creates a Vulkan timeline semaphore from a native graphics sync
1287 * handle, see @ref vk_create_semaphore_from_native for more details.
1288 *
1289 * @ingroup aux_vk
1290 */
1291XRT_CHECK_RESULT VkResult
1293#endif
1294
1295
1296/*
1297 *
1298 * Time function(s), in the vk_time.c file.
1299 *
1300 */
1301
1302#if defined(VK_EXT_calibrated_timestamps) || defined(VK_KHR_calibrated_timestamps) || defined(XRT_DOXYGEN)
1303
1304/*!
1305 * Convert timestamps in GPU ticks (as return by VkQueryPool timestamp queries)
1306 * into host CPU nanoseconds, same time domain as @ref os_monotonic_get_ns.
1307 *
1308 * Note the timestamp needs to be in the past and not to old, this is because
1309 * not all GPU has full 64 bit timer resolution. For instance a Intel GPU "only"
1310 * have 36 bits of valid timestamp and a tick period 83.3333 nanosecond,
1311 * equating to an epoch of 5726 seconds before overflowing. The function can
1312 * handle overflows happening between the given timestamps and when it is called
1313 * but only for one such epoch overflow, any more will only be treated as one
1314 * such overflow. So timestamps needs to be converted reasonably soon after they
1315 * have been captured.
1316 *
1317 * @param vk The Vulkan bundle.
1318 * @param count Number of timestamps to be converted.
1319 * @param[in,out] in_out_timestamps Array of timestamps to be converted, done in place.
1320 *
1321 * @ingroup aux_vk
1322 */
1323XRT_CHECK_RESULT VkResult
1324vk_convert_device_timestamps_to_host_ns(struct vk_bundle *vk, uint32_t count, uint64_t *in_out_timestamps);
1325
1326/*!
1327 * Convert timestamps from an arbitrary domain into host CPU timestamps, in
1328 * nanoseconds.
1329 *
1330 * Must only be used for source domains that are in nanosecond scale and do not
1331 * require any pNext chain.
1332 *
1333 * @param vk The Vulkan bundle.
1334 * @param source_domain Time domain to convert from.
1335 * @param count Number of timestamps to be converted.
1336 * @param[in,out] in_out_timestamps Array of timestamps to be converted, done in place.
1337 *
1338 * @ingroup aux_vk
1339 */
1340XRT_CHECK_RESULT VkResult
1342 VkTimeDomainEXT source_domain,
1343 uint32_t count,
1344 uint64_t *in_out_timestamps);
1345
1346/*!
1347 * Convert timestamps from host CPU domain into an arbitrary domain, in
1348 * nanoseconds.
1349 *
1350 * Must only be used for target domains that are in nanosecond scale and do not
1351 * require any pNext chain.
1352 *
1353 * @param vk The Vulkan bundle.
1354 * @param target_domain Time domain to convert into.
1355 * @param count Number of timestamps to be converted.
1356 * @param[in,out] in_out_timestamps Array of timestamps to be converted, done in place.
1357 *
1358 * @ingroup aux_vk
1359 */
1360XRT_CHECK_RESULT VkResult
1362 VkTimeDomainEXT target_domain,
1363 uint32_t count,
1364 uint64_t *in_out_timestamps);
1365
1366#if defined(VK_EXT_present_timing) || defined(XRT_DOXYGEN)
1367
1368/*!
1369 * Convert swapchain timestamps into host CPU timestamps, in nanoseconds.
1370 *
1371 * @param vk The Vulkan bundle.
1372 * @param source_domain Swapchain time domain to convert from.
1373 * @param swapchain The swapchain info to use for conversion.
1374 * @param count Number of timestamps to be converted.
1375 * @param[in,out] in_out_timestamps Array of timestamps to be converted, done in place.
1376 *
1377 * @ingroup aux_vk
1378 */
1379XRT_CHECK_RESULT VkResult
1381 VkTimeDomainEXT source_domain,
1382 const VkSwapchainCalibratedTimestampInfoEXT *swapchain,
1383 uint32_t count,
1384 uint64_t *in_out_timestamps);
1385
1386/*!
1387 * Convert host CPU timestamps into swapchain timestamps, in nanoseconds.
1388 *
1389 * @param vk The Vulkan bundle.
1390 * @param target_domain Swapchain time domain to convert to.
1391 * @param swapchain The swapchain info to use for conversion.
1392 * @param count Number of timestamps to be converted.
1393 * @param[in,out] in_out_timestamps Array of timestamps to be converted, done in place.
1394 *
1395 * @ingroup aux_vk
1396 */
1397XRT_CHECK_RESULT VkResult
1399 VkTimeDomainEXT target_domain,
1400 const VkSwapchainCalibratedTimestampInfoEXT *swapchain,
1401 uint32_t count,
1402 uint64_t *in_out_timestamps);
1403
1404#endif // defined(VK_EXT_present_timing) || defined(XRT_DOXYGEN)
1405
1406#endif // defined(VK_EXT_calibrated_timestamps) || defined(VK_KHR_calibrated_timestamps) || defined(XRT_DOXYGEN)
1407
1408
1409#ifdef __cplusplus
1410}
1411#endif
u_logging_level
Logging level enum.
Definition u_logging.h:45
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:268
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:1080
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:1320
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:231
VkResult vk_create_view_swizzle_usage(struct vk_bundle *vk, VkImage image, VkImageViewType type, VkFormat format, VkImageUsageFlags image_usage, VkImageSubresourceRange subresource_range, VkComponentMapping components, VkImageView *out_view)
Creates a swizzled image view with a specific subset of usage, useful for a mutable image where one f...
Definition vk_helpers.c:836
XRT_CHECK_RESULT VkResult vk_create_device(struct vk_bundle *vk, int forced_index, bool only_compute, bool realtime_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:929
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:1043
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:210
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:923
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:1301
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:384
XRT_CHECK_RESULT VkResult vk_convert_device_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...
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_convert_host_timestamps_to_swapchain(struct vk_bundle *vk, VkTimeDomainEXT target_domain, const VkSwapchainCalibratedTimestampInfoEXT *swapchain, uint32_t count, uint64_t *in_out_timestamps)
Convert host CPU timestamps into swapchain timestamps, in nanoseconds.
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
XRT_CHECK_RESULT VkResult vk_convert_timestamps_to_host(struct vk_bundle *vk, VkTimeDomainEXT source_domain, uint32_t count, uint64_t *in_out_timestamps)
Convert timestamps from an arbitrary domain into host CPU timestamps, in nanoseconds.
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:878
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:106
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:91
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.
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:693
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
XRT_CHECK_RESULT VkResult vk_convert_timestamps_from_host(struct vk_bundle *vk, VkTimeDomainEXT target_domain, uint32_t count, uint64_t *in_out_timestamps)
Convert timestamps from host CPU domain into an arbitrary domain, in nanoseconds.
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.
VkResult vk_init_mutex(struct vk_bundle *vk)
Initialize mutexes in the vk_bundle.
Definition vk_bundle_init.c:1285
XRT_CHECK_RESULT VkResult vk_convert_swapchain_timestamps_to_host(struct vk_bundle *vk, VkTimeDomainEXT source_domain, const VkSwapchainCalibratedTimestampInfoEXT *swapchain, uint32_t count, uint64_t *in_out_timestamps)
Convert swapchain timestamps into host CPU timestamps, in nanoseconds.
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:92
Wrapper around OS threading native functions.
Definition t_rift_blobwatch.c:118
A wrapper around a native mutex.
Definition os_threading.h:69
Definition u_extension_list.cpp:33
Definition vk_helpers.h:264
Definition vk_helpers.h:63
uint32_t family_index
The queue family index.
Definition vk_helpers.h:67
VkQueue queue
The Vulkan queue handle.
Definition vk_helpers.h:65
struct os_mutex mutex
The queue mutex -.
Definition vk_helpers.h:71
uint32_t index
The queue (instance) index.
Definition vk_helpers.h:69
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition vk_helpers.h:82
uint32_t max_bound_descriptor_sets
Maximum number of descriptor sets that can be simultaneously used by a pipeline.
Definition vk_helpers.h:228
bool synchronization_2
Was synchronization2 requested, available, and enabled?
Definition vk_helpers.h:201
uint32_t max_descriptor_set_samplers
Maximum number of samplers that can be included in a pipeline layout.
Definition vk_helpers.h:231
bool timeline_semaphore
Were timeline semaphore requested, available, and enabled?
Definition vk_helpers.h:198
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:237
bool present_id
Was KHR_present_id requested, available, and enabled?
Definition vk_helpers.h:204
bool video_maintenance_1
Was KHR_video_maintenance1 requested, available, and enabled?
Definition vk_helpers.h:216
bool present_id2
Was KHR_present_id2 requested, available, and enabled?
Definition vk_helpers.h:207
uint32_t timestamp_valid_bits
Valid bits in the queue selected.
Definition vk_helpers.h:195
uint32_t max_sampler_allocation_count
Maximum number of sampler objects, as created by vkCreateSampler, which can simultaneously exist on.
Definition vk_helpers.h:225
uint32_t max_descriptor_set_sampled_images
Maximum number of sampled images that can be included in a pipeline layout.
Definition vk_helpers.h:234
uint32_t max_per_stage_descriptor_storage_images
Per stage limit on storage images.
Definition vk_helpers.h:243
bool is_tegra
Is the GPU a tegra device.
Definition vk_helpers.h:247
struct vk_bundle_queue * main_queue
Main queue for general work.
Definition vk_helpers.h:109
bool timestamp_compute_and_graphics
Are timestamps available for compute and graphics queues?
Definition vk_helpers.h:189
bool present_wait
Was KHR_present_wait requested, available, and enabled?
Definition vk_helpers.h:210
bool present_wait2
Was KHR_present_wait2 requested, available, and enabled?
Definition vk_helpers.h:213
struct vk_bundle_queue queues[3]
queues - a free list of unique queues
Definition vk_helpers.h:99
uint32_t max_per_stage_descriptor_sampled_images
Per stage limit on sampled images (includes combined).
Definition vk_helpers.h:240
bool image_tiling_control
Was EXT_image_tiling_control requested, available, and enabled?
Definition vk_helpers.h:219
float timestamp_period
Nanoseconds per gpu tick.
Definition vk_helpers.h:192
struct vk_bundle_queue * graphics_queue
Graphics queue.
Definition vk_helpers.h:118
Arguments to vk_create_descriptor_pool function.
Definition vk_helpers.h:1124
uint32_t descriptor_count
The max count of created descriptors.
Definition vk_helpers.h:1131
uint32_t uniform_per_descriptor_count
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
Definition vk_helpers.h:1125
bool freeable
Are descriptors freeable, or must vkResetDescriptorPool be used.
Definition vk_helpers.h:1134
uint32_t sampler_per_descriptor_count
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER.
Definition vk_helpers.h:1126
uint32_t storage_image_per_descriptor_count
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE.
Definition vk_helpers.h:1127
uint32_t storage_buffer_per_descriptor_count
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER.
Definition vk_helpers.h:1128
Used to enable device features as a argument vk_create_device.
Definition vk_helpers.h:721
Definition vk_helpers.h:49
uint32_t index
The queue (instance) index.
Definition vk_helpers.h:53
uint32_t family_index
The queue family index.
Definition vk_helpers.h:51
A single image of a swapchain based on native buffer handles.
Definition xrt_compositor.h:2102
Swapchain creation info.
Definition xrt_compositor.h:882
A collection of strings, like a list of extensions to enable.
Basic logging functionality.
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_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:138
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
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
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
Pretty printing various Vulkan things.
Printing helper code.
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.