Monado OpenXR Runtime
vk_helpers.h
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// Copyright 2024-2025, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Common Vulkan code header.
7 *
8 * Note that some sections of this are generated
9 * by `scripts/generate_vk_helpers.py` - lists of functions
10 * and of optional extensions to check for. In those,
11 * please update the script and run it, instead of editing
12 * directly in this file. The generated parts are delimited
13 * by special comments.
14 *
15 * @author Jakob Bornecrantz <jakob@collabora.com>
16 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
17 * @author Moshi Turner <moshiturner@protonmail.com>
18 * @author Korcan Hussein <korcan.hussein@collabora.com>
19 * @ingroup aux_vk
20 */
21
22#pragma once
23
24#include "xrt/xrt_compiler.h"
25#include "xrt/xrt_compositor.h"
27#include "xrt/xrt_handles.h"
28#include "util/u_logging.h"
29#include "util/u_string_list.h"
30#include "os/os_threading.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#define VK_BUNDLE_MAX_QUEUES 2
37
38/*
39 *
40 * Structs
41 *
42 */
43
45{
46 //! The queue family index
47 uint32_t family_index;
48 //! The queue (instance) index
49 uint32_t index;
50};
51
52#define VK_NULL_QUEUE_PAIR \
53 XRT_C11_COMPOUND(struct vk_queue_pair) \
54 { \
55 .family_index = VK_QUEUE_FAMILY_IGNORED, .index = (uint32_t)-1, \
56 }
57
59{
60 //! The Vulkan queue handle
61 VkQueue queue;
62 //! The queue family index
63 uint32_t family_index;
64 //! The queue (instance) index
65 uint32_t index;
66 //! The queue mutex - @see vk_queue_lock, vk_queue_unlock
68};
69
70/*!
71 * A bundle of Vulkan functions and objects, used by both @ref comp and @ref
72 * comp_client. Note that they both have different instances of the object, and
73 * thus different VkInstance, etc.
74 *
75 * @ingroup aux_vk
76 */
78{
79 enum u_logging_level log_level;
80
81 VkInstance instance;
82 uint32_t version;
83 VkPhysicalDevice physical_device;
84 int physical_device_index;
85 VkDevice device;
86
87 /*!
88 * @brief queues - a free list of **unique** queues
89 *
90 * One per uniquely identifiable vk queue (family x instance index),
91 * duplicate entries must not be stored.
92 *
93 * Should not be used directly, @see main_queue, encode_queue
94 */
95 struct vk_bundle_queue queues[VK_BUNDLE_MAX_QUEUES];
96
97 struct vk_bundle_queue *main_queue;
98#if defined(VK_KHR_video_encode_queue)
99 struct vk_bundle_queue *encode_queue;
100#endif
101
102 struct
103 {
104#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE)
105 bool color_image_import_opaque_win32;
106 bool color_image_export_opaque_win32;
107 bool depth_image_import_opaque_win32;
108 bool depth_image_export_opaque_win32;
109
110 bool color_image_import_d3d11;
111 bool color_image_export_d3d11;
112 bool depth_image_import_d3d11;
113 bool depth_image_export_d3d11;
114
115#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
116 bool color_image_import_opaque_fd;
117 bool color_image_export_opaque_fd;
118 bool depth_image_import_opaque_fd;
119 bool depth_image_export_opaque_fd;
120
121#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
122 bool color_image_import_opaque_fd;
123 bool color_image_export_opaque_fd;
124 bool depth_image_import_opaque_fd;
125 bool depth_image_export_opaque_fd;
126
127 bool color_image_import_ahardwarebuffer;
128 bool color_image_export_ahardwarebuffer;
129 bool depth_image_import_ahardwarebuffer;
130 bool depth_image_export_ahardwarebuffer;
131#endif
132
133#if defined(XRT_GRAPHICS_SYNC_HANDLE_IS_FD)
134 bool fence_sync_fd;
135 bool fence_opaque_fd;
136
137 bool binary_semaphore_sync_fd;
138 bool binary_semaphore_opaque_fd;
139
140 bool timeline_semaphore_sync_fd;
141 bool timeline_semaphore_opaque_fd;
142#elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE)
143 bool fence_win32_handle;
144
145 bool binary_semaphore_d3d12_fence;
146 bool binary_semaphore_win32_handle;
147
148 bool timeline_semaphore_d3d12_fence;
149 bool timeline_semaphore_win32_handle;
150#else
151#error "Need port for fence sync handles checkers"
152#endif
153 } external;
154
155 // beginning of GENERATED instance extension code - do not modify - used by scripts
156 bool has_KHR_external_memory_capabilities;
157 bool has_EXT_display_surface_counter;
158 bool has_EXT_swapchain_colorspace;
159 bool has_EXT_debug_utils;
160 // end of GENERATED instance extension code - do not modify - used by scripts
161
162 // beginning of GENERATED device extension code - do not modify - used by scripts
163 bool has_KHR_8bit_storage;
164 bool has_KHR_external_fence_fd;
165 bool has_KHR_external_memory;
166 bool has_KHR_external_semaphore_fd;
167 bool has_KHR_format_feature_flags2;
168 bool has_KHR_global_priority;
169 bool has_KHR_image_format_list;
170 bool has_KHR_maintenance1;
171 bool has_KHR_maintenance2;
172 bool has_KHR_maintenance3;
173 bool has_KHR_maintenance4;
174 bool has_KHR_present_wait;
175 bool has_KHR_synchronization2;
176 bool has_KHR_timeline_semaphore;
177 bool has_KHR_video_maintenance1;
178 bool has_EXT_calibrated_timestamps;
179 bool has_EXT_display_control;
180 bool has_EXT_external_memory_dma_buf;
181 bool has_EXT_external_memory_host;
182 bool has_EXT_global_priority;
183 bool has_EXT_image_drm_format_modifier;
184 bool has_EXT_robustness2;
185 bool has_ANDROID_external_format_resolve;
186 bool has_GOOGLE_display_timing;
187 // end of GENERATED device extension code - do not modify - used by scripts
188
189 struct
190 {
191 //! Are timestamps available for compute and graphics queues?
193
194 //! Nanoseconds per gpu tick.
196
197 //! Valid bits in the queue selected.
199
200 //! Were timeline semaphore requested, available, and enabled?
202
203 //! Per stage limit on sampled images (includes combined).
205
206 //! Per stage limit on storage images.
208
209 //! Was synchronization2 requested, available, and enabled?
211
212 //! Was KHR_present_wait requested, available, and enabled?
214
215 //! Was KHR_video_maintenance1 requested, available, and enabled?
217 } features;
218
219 //! Is the GPU a tegra device.
221
222
223 VkDebugReportCallbackEXT debug_report_cb;
224
225 VkPhysicalDeviceMemoryProperties device_memory_props;
226
227 // Loader functions
228 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
229 PFN_vkCreateInstance vkCreateInstance;
230 PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
231
232 // beginning of GENERATED instance loader code - do not modify - used by scripts
233 PFN_vkDestroyInstance vkDestroyInstance;
234 PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
235 PFN_vkCreateDevice vkCreateDevice;
236 PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
237
238 PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT;
239 PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT;
240
241 PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
242 PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
243 PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2;
244 PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2;
245 PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
246 PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
247 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
248 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
249 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
250 PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
251 PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
252 PFN_vkGetPhysicalDeviceFormatProperties2KHR vkGetPhysicalDeviceFormatProperties2;
253 PFN_vkGetPhysicalDeviceImageFormatProperties2KHR vkGetPhysicalDeviceImageFormatProperties2;
254 PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR vkGetPhysicalDeviceExternalBufferPropertiesKHR;
255 PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR vkGetPhysicalDeviceExternalFencePropertiesKHR;
256 PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR vkGetPhysicalDeviceExternalSemaphorePropertiesKHR;
257 PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties;
258 PFN_vkEnumerateDeviceLayerProperties vkEnumerateDeviceLayerProperties;
259
260#if defined(VK_EXT_calibrated_timestamps)
261 PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT vkGetPhysicalDeviceCalibrateableTimeDomainsEXT;
262
263#endif // defined(VK_EXT_calibrated_timestamps)
264
265#if defined(VK_USE_PLATFORM_DISPLAY_KHR)
266 PFN_vkCreateDisplayPlaneSurfaceKHR vkCreateDisplayPlaneSurfaceKHR;
267 PFN_vkGetDisplayPlaneCapabilitiesKHR vkGetDisplayPlaneCapabilitiesKHR;
268 PFN_vkGetPhysicalDeviceDisplayPropertiesKHR vkGetPhysicalDeviceDisplayPropertiesKHR;
269 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR vkGetPhysicalDeviceDisplayPlanePropertiesKHR;
270 PFN_vkGetDisplayModePropertiesKHR vkGetDisplayModePropertiesKHR;
271 PFN_vkReleaseDisplayEXT vkReleaseDisplayEXT;
272
273#endif // defined(VK_USE_PLATFORM_DISPLAY_KHR)
274
275#if defined(VK_USE_PLATFORM_XCB_KHR)
276 PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR;
277
278#endif // defined(VK_USE_PLATFORM_XCB_KHR)
279
280#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
281 PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR;
282
283#endif // defined(VK_USE_PLATFORM_WAYLAND_KHR)
284
285#if defined(VK_USE_PLATFORM_WAYLAND_KHR) && defined(VK_EXT_acquire_drm_display)
286 PFN_vkAcquireDrmDisplayEXT vkAcquireDrmDisplayEXT;
287 PFN_vkGetDrmDisplayEXT vkGetDrmDisplayEXT;
288
289#endif // defined(VK_USE_PLATFORM_WAYLAND_KHR) && defined(VK_EXT_acquire_drm_display)
290
291#if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
292 PFN_vkGetRandROutputDisplayEXT vkGetRandROutputDisplayEXT;
293 PFN_vkAcquireXlibDisplayEXT vkAcquireXlibDisplayEXT;
294
295#endif // defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
296
297#if defined(VK_USE_PLATFORM_ANDROID_KHR)
298 PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR;
299
300#endif // defined(VK_USE_PLATFORM_ANDROID_KHR)
301
302#if defined(VK_USE_PLATFORM_WIN32_KHR)
303 PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR;
304
305#endif // defined(VK_USE_PLATFORM_WIN32_KHR)
306
307#if defined(VK_EXT_display_surface_counter)
308 PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT vkGetPhysicalDeviceSurfaceCapabilities2EXT;
309
310#endif // defined(VK_EXT_display_surface_counter)
311
312#if defined(VK_EXT_debug_utils)
313 PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT;
314 PFN_vkSubmitDebugUtilsMessageEXT vkSubmitDebugUtilsMessageEXT;
315 PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT;
316#endif // defined(VK_EXT_debug_utils)
317
318 // end of GENERATED instance loader code - do not modify - used by scripts
319
320 // beginning of GENERATED device loader code - do not modify - used by scripts
321 PFN_vkDestroyDevice vkDestroyDevice;
322 PFN_vkDeviceWaitIdle vkDeviceWaitIdle;
323 PFN_vkAllocateMemory vkAllocateMemory;
324 PFN_vkFreeMemory vkFreeMemory;
325 PFN_vkMapMemory vkMapMemory;
326 PFN_vkUnmapMemory vkUnmapMemory;
327
328 PFN_vkCreateBuffer vkCreateBuffer;
329 PFN_vkDestroyBuffer vkDestroyBuffer;
330 PFN_vkBindBufferMemory vkBindBufferMemory;
331
332 PFN_vkCreateImage vkCreateImage;
333 PFN_vkDestroyImage vkDestroyImage;
334 PFN_vkBindImageMemory vkBindImageMemory;
335
336 PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
337 PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges;
338 PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
339 PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2;
340 PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout;
341
342 PFN_vkCreateImageView vkCreateImageView;
343 PFN_vkDestroyImageView vkDestroyImageView;
344
345 PFN_vkCreateSampler vkCreateSampler;
346 PFN_vkDestroySampler vkDestroySampler;
347
348 PFN_vkCreateShaderModule vkCreateShaderModule;
349 PFN_vkDestroyShaderModule vkDestroyShaderModule;
350
351 PFN_vkCreateQueryPool vkCreateQueryPool;
352 PFN_vkDestroyQueryPool vkDestroyQueryPool;
353 PFN_vkGetQueryPoolResults vkGetQueryPoolResults;
354
355 PFN_vkCreateCommandPool vkCreateCommandPool;
356 PFN_vkDestroyCommandPool vkDestroyCommandPool;
357 PFN_vkResetCommandPool vkResetCommandPool;
358
359 PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
360 PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
361 PFN_vkCmdBeginQuery vkCmdBeginQuery;
362 PFN_vkCmdCopyQueryPoolResults vkCmdCopyQueryPoolResults;
363 PFN_vkCmdEndQuery vkCmdEndQuery;
364 PFN_vkCmdResetQueryPool vkCmdResetQueryPool;
365 PFN_vkCmdWriteTimestamp vkCmdWriteTimestamp;
366 PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
367 PFN_vkCmdBeginRenderPass vkCmdBeginRenderPass;
368 PFN_vkCmdSetScissor vkCmdSetScissor;
369 PFN_vkCmdSetViewport vkCmdSetViewport;
370 PFN_vkCmdClearColorImage vkCmdClearColorImage;
371 PFN_vkCmdEndRenderPass vkCmdEndRenderPass;
372 PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets;
373 PFN_vkCmdBindPipeline vkCmdBindPipeline;
374 PFN_vkCmdBindVertexBuffers vkCmdBindVertexBuffers;
375 PFN_vkCmdBindIndexBuffer vkCmdBindIndexBuffer;
376 PFN_vkCmdDraw vkCmdDraw;
377 PFN_vkCmdDrawIndexed vkCmdDrawIndexed;
378 PFN_vkCmdDispatch vkCmdDispatch;
379 PFN_vkCmdCopyBuffer vkCmdCopyBuffer;
380 PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage;
381 PFN_vkCmdCopyImage vkCmdCopyImage;
382 PFN_vkCmdCopyImageToBuffer vkCmdCopyImageToBuffer;
383 PFN_vkCmdBlitImage vkCmdBlitImage;
384 PFN_vkCmdPushConstants vkCmdPushConstants;
385 PFN_vkEndCommandBuffer vkEndCommandBuffer;
386 PFN_vkFreeCommandBuffers vkFreeCommandBuffers;
387
388 PFN_vkCreateRenderPass vkCreateRenderPass;
389 PFN_vkDestroyRenderPass vkDestroyRenderPass;
390
391 PFN_vkCreateFramebuffer vkCreateFramebuffer;
392 PFN_vkDestroyFramebuffer vkDestroyFramebuffer;
393
394 PFN_vkCreatePipelineCache vkCreatePipelineCache;
395 PFN_vkDestroyPipelineCache vkDestroyPipelineCache;
396
397 PFN_vkResetDescriptorPool vkResetDescriptorPool;
398 PFN_vkCreateDescriptorPool vkCreateDescriptorPool;
399 PFN_vkDestroyDescriptorPool vkDestroyDescriptorPool;
400
401 PFN_vkAllocateDescriptorSets vkAllocateDescriptorSets;
402 PFN_vkFreeDescriptorSets vkFreeDescriptorSets;
403
404 PFN_vkCreateComputePipelines vkCreateComputePipelines;
405 PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines;
406 PFN_vkDestroyPipeline vkDestroyPipeline;
407
408 PFN_vkCreatePipelineLayout vkCreatePipelineLayout;
409 PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout;
410
411 PFN_vkCreateDescriptorSetLayout vkCreateDescriptorSetLayout;
412 PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets;
413 PFN_vkDestroyDescriptorSetLayout vkDestroyDescriptorSetLayout;
414
415 PFN_vkGetDeviceQueue vkGetDeviceQueue;
416 PFN_vkQueueSubmit vkQueueSubmit;
417 PFN_vkQueueWaitIdle vkQueueWaitIdle;
418
419 PFN_vkCreateSemaphore vkCreateSemaphore;
420#if defined(VK_KHR_timeline_semaphore)
421 PFN_vkSignalSemaphoreKHR vkSignalSemaphore;
422 PFN_vkWaitSemaphoresKHR vkWaitSemaphores;
423 PFN_vkGetSemaphoreCounterValueKHR vkGetSemaphoreCounterValue;
424#endif // defined(VK_KHR_timeline_semaphore)
425
426 PFN_vkDestroySemaphore vkDestroySemaphore;
427
428 PFN_vkCreateFence vkCreateFence;
429 PFN_vkWaitForFences vkWaitForFences;
430 PFN_vkGetFenceStatus vkGetFenceStatus;
431 PFN_vkDestroyFence vkDestroyFence;
432 PFN_vkResetFences vkResetFences;
433
434 PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR;
435 PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
436 PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
437 PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
438 PFN_vkQueuePresentKHR vkQueuePresentKHR;
439
440#if defined(VK_USE_PLATFORM_WIN32_KHR)
441 PFN_vkGetMemoryWin32HandleKHR vkGetMemoryWin32HandleKHR;
442 PFN_vkGetFenceWin32HandleKHR vkGetFenceWin32HandleKHR;
443 PFN_vkGetSemaphoreWin32HandleKHR vkGetSemaphoreWin32HandleKHR;
444 PFN_vkImportFenceWin32HandleKHR vkImportFenceWin32HandleKHR;
445 PFN_vkImportSemaphoreWin32HandleKHR vkImportSemaphoreWin32HandleKHR;
446
447#endif // defined(VK_USE_PLATFORM_WIN32_KHR)
448
449#if !defined(VK_USE_PLATFORM_WIN32_KHR)
450 PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR;
451 PFN_vkGetFenceFdKHR vkGetFenceFdKHR;
452 PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR;
453 PFN_vkImportFenceFdKHR vkImportFenceFdKHR;
454 PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR;
455
456#endif // !defined(VK_USE_PLATFORM_WIN32_KHR)
457
458#if defined(VK_USE_PLATFORM_ANDROID_KHR)
459 PFN_vkGetMemoryAndroidHardwareBufferANDROID vkGetMemoryAndroidHardwareBufferANDROID;
460 PFN_vkGetAndroidHardwareBufferPropertiesANDROID vkGetAndroidHardwareBufferPropertiesANDROID;
461
462#endif // defined(VK_USE_PLATFORM_ANDROID_KHR)
463
464#if defined(VK_EXT_external_memory_host)
465 PFN_vkGetMemoryHostPointerPropertiesEXT vkGetMemoryHostPointerPropertiesEXT;
466
467#endif // defined(VK_EXT_external_memory_host)
468
469#if defined(VK_EXT_calibrated_timestamps)
470 PFN_vkGetCalibratedTimestampsEXT vkGetCalibratedTimestampsEXT;
471
472#endif // defined(VK_EXT_calibrated_timestamps)
473
474 PFN_vkGetPastPresentationTimingGOOGLE vkGetPastPresentationTimingGOOGLE;
475
476#if defined(VK_EXT_display_control)
477 PFN_vkGetSwapchainCounterEXT vkGetSwapchainCounterEXT;
478 PFN_vkRegisterDeviceEventEXT vkRegisterDeviceEventEXT;
479 PFN_vkRegisterDisplayEventEXT vkRegisterDisplayEventEXT;
480
481#endif // defined(VK_EXT_display_control)
482
483#if defined(VK_EXT_image_drm_format_modifier)
484 PFN_vkGetImageDrmFormatModifierPropertiesEXT vkGetImageDrmFormatModifierPropertiesEXT;
485
486#endif // defined(VK_EXT_image_drm_format_modifier)
487
488#if defined(VK_EXT_debug_utils)
489 PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT;
490 PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT;
491 PFN_vkCmdInsertDebugUtilsLabelEXT vkCmdInsertDebugUtilsLabelEXT;
492 PFN_vkQueueBeginDebugUtilsLabelEXT vkQueueBeginDebugUtilsLabelEXT;
493 PFN_vkQueueEndDebugUtilsLabelEXT vkQueueEndDebugUtilsLabelEXT;
494 PFN_vkQueueInsertDebugUtilsLabelEXT vkQueueInsertDebugUtilsLabelEXT;
495 PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT;
496 PFN_vkSetDebugUtilsObjectTagEXT vkSetDebugUtilsObjectTagEXT;
497
498#endif // defined(VK_EXT_debug_utils)
499
500#if defined(VK_KHR_present_wait)
501 PFN_vkWaitForPresentKHR vkWaitForPresentKHR;
502#endif // defined(VK_KHR_present_wait)
503
504 // end of GENERATED device loader code - do not modify - used by scripts
505};
506
508{
509 VkBuffer handle;
510 VkDeviceMemory memory;
511 uint32_t size;
512 void *data;
513};
514
515
516/*
517 *
518 * Helper defines.
519 *
520 */
521
522/*!
523 * This define will error if `RET` is not `VK_SUCCESS`, printing out that the
524 * @p FUNC_STR string has failed, then returns @p RET. The implicit argument
525 * @p vk will be used for the @ref vk_print_result call.
526 *
527 * Use this macro when your function returns a `VkResult`.
528 *
529 * @param RET The @p VkResult to check.
530 * @param FUNC_STR String literal with the function name, used for logging.
531 *
532 * @ingroup aux_vk
533 *
534 * @see VK_CHK_WITH_RET
535 * @see VK_CHK_WITH_GOTO
536 */
537#define VK_CHK_AND_RET(RET, FUNC_STR) \
538 do { \
539 VkResult _ret = RET; \
540 if (_ret != VK_SUCCESS) { \
541 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
542 return _ret; \
543 } \
544 } while (false)
545
546/*!
547 * This define will error if @p RET is not @p VK_SUCCESS, printing out that the
548 * @p FUNC_STR string has failed, then returns @p TO_RET. The implicit argument
549 * @p vk will be used for the @ref vk_print_result call.
550 *
551 * Use this macro when your function doesn't return a `VkResult`.
552 *
553 * @param RET The @p VkResult to check.
554 * @param FUNC_STR String literal with the function name, used for logging.
555 * @param TO_RET Value to return, upon error
556 *
557 * @ingroup aux_vk
558 *
559 * @see VK_CHK_AND_RET
560 * @see VK_CHK_WITH_GOTO
561 */
562#define VK_CHK_WITH_RET(RET, FUNC_STR, TO_RET) \
563 do { \
564 VkResult _ret = RET; \
565 if (_ret != VK_SUCCESS) { \
566 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
567 return TO_RET; \
568 } \
569 } while (false)
570
571/*!
572 * This define will error if @p RET is not @p VK_SUCCESS, printing out that the
573 * @p FUNC_STR string has failed, then goto @p GOTO. The implicit argument @p vk
574 * will be used for the @ref vk_print_result call.
575 *
576 * Use this macro when your function needs to `goto` some cleanup code and
577 * return from there.
578 *
579 * @param RET The @p VkResult to check.
580 * @param FUNC_STR String literal with the function name, used for logging.
581 * @param GOTO Label to jump to, upon error
582 *
583 * @ingroup aux_vk
584 *
585 * @see VK_CHK_AND_RET
586 * @see VK_CHK_WITH_RET
587 */
588#define VK_CHK_WITH_GOTO(RET, FUNC_STR, GOTO) \
589 do { \
590 VkResult _ret = RET; \
591 if (_ret != VK_SUCCESS) { \
592 vk_print_result(vk, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
593 goto GOTO; \
594 } \
595 } while (false)
596
597
598static inline void
599vk_append_to_pnext_chain(VkBaseInStructure *head, VkBaseInStructure *new_struct)
600{
601 assert(new_struct->pNext == NULL);
602 // Insert ourselves between head and its previous pNext
603 new_struct->pNext = head->pNext;
604 head->pNext = new_struct;
605}
606
607/*
608 *
609 * String helper functions.
610 *
611 */
612
613XRT_CHECK_RESULT const char *
614vk_result_string(VkResult code);
615
616XRT_CHECK_RESULT const char *
617vk_object_type_string(VkObjectType type);
618
619XRT_CHECK_RESULT const char *
620vk_physical_device_type_string(VkPhysicalDeviceType device_type);
621
622XRT_CHECK_RESULT const char *
623vk_format_string(VkFormat code);
624
625XRT_CHECK_RESULT const char *
626vk_sharing_mode_string(VkSharingMode code);
627
628XRT_CHECK_RESULT const char *
629vk_present_mode_string(VkPresentModeKHR code);
630
631XRT_CHECK_RESULT const char *
632vk_color_space_string(VkColorSpaceKHR code);
633
634XRT_CHECK_RESULT const char *
635vk_power_state_string(VkDisplayPowerStateEXT code);
636
637
638/*
639 *
640 * Flag bits string functions.
641 *
642 */
643
644/*!
645 * Returns the format feature flag if one valid bit is set,
646 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
647 */
648XRT_CHECK_RESULT const char *
649vk_format_feature_flag_string(VkFormatFeatureFlagBits bits, bool null_on_unknown);
650
651/*!
652 * Returns the image usage flag if one valid bit is set,
653 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
654 */
655XRT_CHECK_RESULT const char *
656vk_image_usage_flag_string(VkImageUsageFlagBits bits, bool null_on_unknown);
657
658/*!
659 * Returns the composite alpha flag if one valid bit is set,
660 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
661 */
662XRT_CHECK_RESULT const char *
663vk_composite_alpha_flag_string(VkCompositeAlphaFlagBitsKHR bits, bool null_on_unknown);
664
665/*!
666 * Returns the surface transform flag if one valid bit is set,
667 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
668 */
669XRT_CHECK_RESULT const char *
670vk_surface_transform_flag_string(VkSurfaceTransformFlagBitsKHR bits, bool null_on_unknown);
671
672#ifdef VK_KHR_display
673/*!
674 * Returns the display plane alpha flag if one valid bit is set,
675 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
676 */
677XRT_CHECK_RESULT const char *
678vk_display_plane_alpha_flag_string(VkDisplayPlaneAlphaFlagBitsKHR bits, bool null_on_unknown);
679#endif
680
681/*!
682 * Returns xrt swapchain_usage flag if one valid bit is set,
683 * if multiple bits are set, will return 'MULTIPLE BIT SET'.
684 */
685XRT_CHECK_RESULT const char *
686xrt_swapchain_usage_flag_string(enum xrt_swapchain_usage_bits bits, bool null_on_unknown);
687
688
689/*
690 *
691 * Function and helpers.
692 *
693 */
694
695#define VK_TRACE(d, ...) U_LOG_IFL_T(d->log_level, __VA_ARGS__)
696#define VK_DEBUG(d, ...) U_LOG_IFL_D(d->log_level, __VA_ARGS__)
697#define VK_INFO(d, ...) U_LOG_IFL_I(d->log_level, __VA_ARGS__)
698#define VK_WARN(d, ...) U_LOG_IFL_W(d->log_level, __VA_ARGS__)
699#define VK_ERROR(d, ...) U_LOG_IFL_E(d->log_level, __VA_ARGS__)
700
701
702/*
703 *
704 * Debug helper functions, in the vk_debug.c file.
705 *
706 */
707
708#if defined(VK_EXT_debug_utils) || defined(XRT_DOXYGEN)
709
710/*!
711 * Uses VK_EXT_debug_utils to set a name for an object, for easier debugging.
712 *
713 * @ingroup aux_vk
714 */
715void
716vk_name_object(struct vk_bundle *vk, VkObjectType type, uint64_t object, const char *name);
717
718/*!
719 * Small helper for @ref vk_name_object that makes use of pre-process to avoid
720 * writing out long type names.
721 *
722 * @ingroup aux_vk
723 */
724#define VK_NAME_OBJ(VK, TYPE, SUFFIX, OBJ, NAME) \
725 do { \
726 if ((VK)->has_EXT_debug_utils) { \
727 XRT_MAYBE_UNUSED TYPE _thing = (TYPE)(OBJ); \
728 vk_name_object(VK, VK_OBJECT_TYPE_##SUFFIX, (uint64_t)OBJ, NAME); \
729 } \
730 } while (false)
731
732
733#else
734
735#define VK_NAME_OBJ(VK, TYPE, SUFFIX, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, TYPE, OBJ)
736
737#endif
738
739/*!
740 * Some combinations of Vulkan implementation and types are broken, we still
741 * want type safety so we have this define. Examples of broken combinations:
742 *
743 * 1. Both Mesa and the Vulkan loader didn't support setting names on the
744 * VkInstance, loader got support in 1.3.261 and Mesa hasn't as of writing.
745 * 2. For Mesa drivers we can not name VkSurfaceKHR objects on some systems as
746 * it causes memory corruption, asserts, crashes or functions failing. This
747 * is as of writing broken on the 23.2.1 release, fixed in main and scheduled
748 * for the 23.2.2 release.
749 * 3. Mesa RADV leaks the name strings for VkDescriptorSet objects for pools
750 * that we use the reset function.
751 *
752 * @ingroup aux_vk
753 */
754#define VK_NAME_OBJ_DISABLED(VK, TYPE, OBJ) \
755 do { \
756 XRT_MAYBE_UNUSED TYPE _thing = (TYPE)(OBJ); \
757 } while (false)
758
759
760// clang-format off
761// VK_DEFINE_HANDLE types are always pointers
762#define VK_NAME_INSTANCE(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkInstance, (uintptr_t)OBJ)
763#define VK_NAME_PHYSICAL_DEVICE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPhysicalDevice, PHYSICAL_DEVICE, (uintptr_t)OBJ, NAME)
764#define VK_NAME_DEVICE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDevice, DEVICE, (uintptr_t)OBJ, NAME)
765#define VK_NAME_QUEUE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkQueue, QUEUE, (uintptr_t)OBJ, NAME)
766#define VK_NAME_COMMAND_BUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkCommandBuffer, COMMAND_BUFFER, (uintptr_t)OBJ, NAME)
767// VK_DEFINE_NON_DISPATCHABLE_HANDLE types are pointers in 64-bits and uint64_t in 32-bits
768#define VK_NAME_SEMAPHORE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSemaphore, SEMAPHORE, OBJ, NAME)
769#define VK_NAME_FENCE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkFence, FENCE, OBJ, NAME)
770#define VK_NAME_DEVICE_MEMORY(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDeviceMemory, DEVICE_MEMORY, OBJ, NAME)
771#define VK_NAME_BUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkBuffer, BUFFER, OBJ, NAME)
772#define VK_NAME_IMAGE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkImage, IMAGE, OBJ, NAME)
773#define VK_NAME_EVENT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkEvent, EVENT, OBJ, NAME)
774#define VK_NAME_QUERY_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkQueryPool, QUERY_POOL, OBJ, NAME)
775#define VK_NAME_BUFFER_VIEW(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkBufferView, BUFFER_VIEW, OBJ, NAME)
776#define VK_NAME_IMAGE_VIEW(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkImageView, IMAGE_VIEW, OBJ, NAME)
777#define VK_NAME_SHADER_MODULE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkShaderModule, SHADER_MODULE, OBJ, NAME)
778#define VK_NAME_PIPELINE_CACHE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipelineCache, PIPELINE_CACHE, OBJ, NAME)
779#define VK_NAME_PIPELINE_LAYOUT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipelineLayout, PIPELINE_LAYOUT, OBJ, NAME)
780#define VK_NAME_RENDER_PASS(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkRenderPass, RENDER_PASS, OBJ, NAME)
781#define VK_NAME_PIPELINE(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkPipeline, PIPELINE, OBJ, NAME)
782#define VK_NAME_DESCRIPTOR_SET_LAYOUT(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDescriptorSetLayout, DESCRIPTOR_SET_LAYOUT, OBJ, NAME)
783#define VK_NAME_SAMPLER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSampler, SAMPLER, OBJ, NAME)
784#define VK_NAME_DESCRIPTOR_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkDescriptorPool, DESCRIPTOR_POOL, OBJ, NAME)
785#define VK_NAME_DESCRIPTOR_SET(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkDescriptorSet, OBJ)
786#define VK_NAME_FRAMEBUFFER(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkFramebuffer, FRAMEBUFFER, OBJ, NAME)
787#define VK_NAME_COMMAND_POOL(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkCommandPool, COMMAND_POOL, OBJ, NAME)
788
789#define VK_NAME_SURFACE(VK, OBJ, NAME) VK_NAME_OBJ_DISABLED(VK, VkSurfaceKHR, OBJ)
790#define VK_NAME_SWAPCHAIN(VK, OBJ, NAME) VK_NAME_OBJ(VK, VkSwapchainKHR, SWAPCHAIN_KHR, OBJ, NAME)
791// clang-format on
792
793
794/*
795 *
796 * Printing helpers, in the vk_print.c file.
797 *
798 */
799
800/*!
801 * Print the result of a function, info level if ret == `VK_SUCCESS` and error
802 * level otherwise. Also prints file and line.
803 *
804 * @ingroup aux_vk
805 */
806void
808 struct vk_bundle *vk, const char *file, int line, const char *calling_func, VkResult ret, const char *called_func);
809
810/*!
811 * Print device information to the logger at the given logging level,
812 * if the vk_bundle has that level enabled.
813 *
814 * @ingroup aux_vk
815 */
816void
818 enum u_logging_level log_level,
819 const VkPhysicalDeviceProperties *pdp,
820 uint32_t gpu_index,
821 const char *title);
822
823/*!
824 * Print device information about the device that bundle manages at the given
825 * logging level if the vk_bundle has that level enabled.
826 *
827 * @ingroup aux_vk
828 */
829void
830vk_print_opened_device_info(struct vk_bundle *vk, enum u_logging_level log_level);
831
832/*!
833 * Print device features to the logger at the given logging level, if the
834 * vk_bundle has that level enabled.
835 */
836void
837vk_print_features_info(struct vk_bundle *vk, enum u_logging_level log_level);
838
839/*!
840 * Print external handle features to the logger at the given logging level,
841 * if the vk_bundle has that level enabled.
842 */
843void
845
846/*!
847 * Print a @p VkSwapchainCreateInfoKHR, used to log during creation.
848 */
849void
850vk_print_swapchain_create_info(struct vk_bundle *vk, VkSwapchainCreateInfoKHR *i, enum u_logging_level log_level);
851
852#ifdef VK_KHR_display
853/*!
854 * Print a @p VkDisplaySurfaceCreateInfoKHR, used to log during creation.
855 */
856void
857vk_print_display_surface_create_info(struct vk_bundle *vk,
858 VkDisplaySurfaceCreateInfoKHR *i,
859 enum u_logging_level log_level);
860#endif
861
862/*!
863 * Print queue info to the logger at the given logging level,
864 * if the vk_bundle has that level enabled.
865 */
866void
867vk_print_queues_info(const struct vk_bundle *vk, enum u_logging_level log_level);
868
869
870/*
871 *
872 * Enumeration helpers, in the vk_enumerate.c file.
873 *
874 */
875
876/*!
877 * Return the @p VkExtensionProperties of the given @p layer_name, NULL means
878 * the "base" driver instance.
879 *
880 * @ingroup aux_vk
881 */
882VkResult
884 const char *layer_name,
885 uint32_t *out_prop_count,
886 VkExtensionProperties **out_props);
887
888/*!
889 * Enumerate the physical devices of the @p VkInstance that has been opened on
890 * the given @ref vk_bundle.
891 *
892 * @ingroup aux_vk
893 */
894VkResult
896 uint32_t *out_physical_device_count,
897 VkPhysicalDevice **out_physical_devices);
898
899/*!
900 * Enumerate the extension properties of the given @p VkPhysicalDevice for the
901 * named @p layer_name, NULL means the "base" driver physical device.
902 *
903 * @ingroup aux_vk
904 */
905VkResult
907 VkPhysicalDevice physical_device,
908 const char *layer_name,
909 uint32_t *out_prop_count,
910 VkExtensionProperties **out_props);
911
912#if defined(VK_KHR_surface) || defined(XRT_DOXYGEN)
913/*!
914 * Enumerate the surface formats of the given @p VkSurfaceKHR,
915 * returns a list of @p VkSurfaceFormatKHR, not @p VkFormat.
916 *
917 * @ingroup aux_vk
918 */
919VkResult
921 VkSurfaceKHR surface,
922 uint32_t *out_format_count,
923 VkSurfaceFormatKHR **out_formats);
924
925/*!
926 * Enumerate the present modes of the given @p VkSurfaceKHR.
927 *
928 * @ingroup aux_vk
929 */
930VkResult
932 VkSurfaceKHR surface,
933 uint32_t *out_present_mode_count,
934 VkPresentModeKHR **out_present_modes);
935#endif
936
937#if defined(VK_KHR_swapchain) || defined(XRT_DOXYGEN)
938/*!
939 * Enumerate the images of the given @p VkSwapchainKHR.
940 *
941 * @ingroup aux_vk
942 */
943VkResult
945 VkSwapchainKHR swapchain,
946 uint32_t *out_image_count,
947 VkImage **out_images);
948#endif
949
950#if defined(VK_USE_PLATFORM_DISPLAY_KHR) || defined(XRT_DOXYGEN)
951/*!
952 * Enumerate the display properties of the given @p VkPhysicalDevice.
953 *
954 * @ingroup aux_vk
955 */
956VkResult
958 VkPhysicalDevice physical_device,
959 uint32_t *out_prop_count,
960 VkDisplayPropertiesKHR **out_props);
961
962/*!
963 * Enumerate the display plane properties of the given @p VkPhysicalDevice.
964 *
965 * @ingroup aux_vk
966 */
967VkResult
969 VkPhysicalDevice physical_device,
970 uint32_t *out_prop_count,
971 VkDisplayPlanePropertiesKHR **out_props);
972
973/*!
974 * Enumerate the mode properties of the given @p VkDisplayKHR, which belongs
975 * to the given @p VkPhysicalDevice.
976 *
977 * @ingroup aux_vk
978 */
979VkResult
981 VkPhysicalDevice physical_device,
982 VkDisplayKHR display,
983 uint32_t *out_prop_count,
984 VkDisplayModePropertiesKHR **out_props);
985#endif
986
987
988/*
989 *
990 * Struct init functions, in the vk_function_loaders.c file.
991 *
992 */
993
994/*!
995 * Can be done on a completely bare bundle.
996 *
997 * @ingroup aux_vk
998 */
999VkResult
1000vk_get_loader_functions(struct vk_bundle *vk, PFN_vkGetInstanceProcAddr g);
1001
1002/*!
1003 * Requires a instance to have been created and set on the bundle.
1004 *
1005 * @ingroup aux_vk
1006 */
1007VkResult
1009
1010/*!
1011 * Requires a device to have been created and set on the bundle.
1012 *
1013 * @ingroup aux_vk
1014 */
1015VkResult
1017
1018
1019/*
1020 *
1021 * Bundle init functions, in the vk_bundle_init.c file.
1022 *
1023 */
1024
1025/*!
1026 * Check if the required instance extensions are supported, if not print error
1027 * message with all extensions missing, returns VK_ERROR_EXTENSION_NOT_PRESENT
1028 * if not all extensions are supported.
1029 *
1030 * @ingroup aux_vk
1031 */
1032VkResult
1033vk_check_required_instance_extensions(struct vk_bundle *vk, struct u_string_list *required_instance_ext_list);
1034
1035/*!
1036 * Only requires @ref vk_get_loader_functions to have been called.
1037 *
1038 * @ingroup aux_vk
1039 */
1040struct u_string_list *
1042 struct u_string_list *required_instance_ext_list,
1043 struct u_string_list *optional_instance_ext_list);
1044
1045/*!
1046 * Fills in has_* in vk_bundle given a string of prefiltered instance extensions
1047 */
1048void
1049vk_fill_in_has_instance_extensions(struct vk_bundle *vk, struct u_string_list *ext_list);
1050
1051/*!
1052 * Setup the physical device, this is called by vk_create_device but has uses
1053 * for outside of that.
1054 *
1055 * @ingroup aux_vk
1056 */
1057VkResult
1058vk_select_physical_device(struct vk_bundle *vk, int forced_index);
1059
1060/*!
1061 * Used to enable device features as a argument @ref vk_create_device.
1062 *
1063 * @ingroup aux_vk
1064 */
1066{
1067 bool shader_image_gather_extended;
1068 bool shader_storage_image_write_without_format;
1069 bool null_descriptor;
1070 bool timeline_semaphore;
1071 bool synchronization_2;
1072 bool ext_fmt_resolve;
1073 bool storage_buffer_8bit_access;
1074 bool present_wait;
1075 bool video_maintenance_1;
1076};
1077
1078/*!
1079 * Creates a VkDevice and initialises the VkQueue.
1080 *
1081 * @ingroup aux_vk
1082 */
1083XRT_CHECK_RESULT VkResult
1084vk_create_device(struct vk_bundle *vk,
1085 int forced_index,
1086 bool only_compute,
1087 VkQueueGlobalPriorityEXT global_priority,
1088 struct u_string_list *required_device_ext_list,
1089 struct u_string_list *optional_device_ext_list,
1090 const struct vk_device_features *optional_device_features);
1091
1092/*!
1093 * @brief Initialize mutexes in the @ref vk_bundle.
1094 *
1095 * Not required for all uses, but a precondition for some.
1096 *
1097 * @ingroup aux_vk
1098 */
1099VkResult
1100vk_init_mutex(struct vk_bundle *vk);
1101
1102/*!
1103 * @brief De-initialize mutexes in the @ref vk_bundle.
1104 *
1105 * @ingroup aux_vk
1106 */
1107VkResult
1108vk_deinit_mutex(struct vk_bundle *vk);
1109
1110static inline void
1111vk_queue_lock(struct vk_bundle_queue *q)
1112{
1113 assert(q != NULL);
1114 os_mutex_lock(&q->mutex);
1115}
1116
1117static inline int
1118vk_queue_trylock(struct vk_bundle_queue *q)
1119{
1120 assert(q != NULL);
1121 return os_mutex_trylock(&q->mutex);
1122}
1123
1124static inline void
1125vk_queue_unlock(struct vk_bundle_queue *q)
1126{
1127 assert(q != NULL);
1129}
1130
1131/*!
1132 * Initialize a bundle with objects given to us by client code,
1133 * used by @ref client_vk_compositor in @ref comp_client.
1134 *
1135 * @ingroup aux_vk
1136 */
1137XRT_CHECK_RESULT VkResult
1138vk_init_from_given(struct vk_bundle *vk,
1139 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
1140 VkInstance instance,
1141 VkPhysicalDevice physical_device,
1142 VkDevice device,
1143 uint32_t queue_family_index,
1144 uint32_t queue_index,
1145 bool external_fence_fd_enabled,
1146 bool external_semaphore_fd_enabled,
1147 bool timeline_semaphore_enabled,
1148 bool image_format_list_enabled,
1149 bool debug_utils_enabled,
1150 enum u_logging_level log_level);
1151
1152
1153/*
1154 *
1155 * Other functions.
1156 *
1157 */
1158
1159/*!
1160 * @ingroup aux_vk
1161 */
1162bool
1163vk_get_memory_type(struct vk_bundle *vk, uint32_t type_bits, VkMemoryPropertyFlags memory_props, uint32_t *out_type_id);
1164
1165/*!
1166 * Allocate memory for an image and bind it to that image.
1167 *
1168 * Handles the following steps:
1169 *
1170 * - calling vkGetImageMemoryRequirements
1171 * - comparing against the max_size
1172 * - getting the memory type (as dictated by the VkMemoryRequirements and
1173 * VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
1174 * - calling vkAllocateMemory
1175 * - calling vkBindImageMemory
1176 * - calling vkDestroyMemory in case of an error.
1177 *
1178 * If this fails, it cleans up the VkDeviceMemory.
1179 *
1180 * @param vk Vulkan bundle
1181 * @param image The VkImage to allocate for and bind.
1182 * @param requirements Memory requirements used for finding the memory type and the size.
1183 * @param pNext_for_allocate (Optional) a pointer to use in the pNext chain of
1184 * VkMemoryAllocateInfo.
1185 * @param caller_name Used for error printing, this function is called from
1186 * various sources and takes next chains that could influence the result
1187 * of various calls inside of it. Since it's up to this function to print
1188 * any errors it will add the caller name to error messages.
1189 * @param out_mem Output parameter: will be set to the allocated memory if
1190 * everything succeeds. Not modified if there is an error.
1191 * @param out_size (Optional) pointer to receive the value of
1192 * VkMemoryRequirements::size.
1193 *
1194 * If this fails, you may want to destroy your VkImage as well, since this
1195 * routine is usually used in combination with vkCreateImage.
1196 *
1197 * @ingroup aux_vk
1198 */
1199XRT_CHECK_RESULT VkResult
1201 VkImage image,
1202 const VkMemoryRequirements *requirements,
1203 const void *pNext_for_allocate,
1204 const char *caller_name,
1205 VkDeviceMemory *out_mem);
1206
1207/*!
1208 *
1209 * @brief Creates a Vulkan device memory and image from a native graphics buffer handle.
1210 *
1211 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1212 *
1213 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p image_native
1214 * handle may have transferred, a reference may have been added, or the Vulkan objects may rely on the caller to keep
1215 * the native handle alive until the Vulkan objects are destroyed. Which option applies depends on the particular native
1216 * handle type used.
1217 *
1218 * See the corresponding specification texts:
1219 *
1220 * - Windows:
1221 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportMemoryWin32HandleInfoKHR
1222 * - Linux: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportMemoryFdInfoKHR
1223 * - Android:
1224 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkImportAndroidHardwareBufferInfoANDROID
1225 *
1226 * @ingroup aux_vk
1227 */
1228XRT_CHECK_RESULT VkResult
1230 const struct xrt_swapchain_create_info *info,
1231 struct xrt_image_native *image_native,
1232 VkImage *out_image,
1233 VkDeviceMemory *out_mem);
1234
1235/*!
1236 * Given a DeviceMemory handle created to be exportable, outputs the native buffer type (FD on desktop Linux)
1237 * equivalent.
1238 *
1239 * Caller assumes ownership of handle which should be unreferenced with @ref u_graphics_buffer_unref when no longer
1240 * needed.
1241 *
1242 * @param vk Vulkan bundle
1243 * @param device_memory The memory to get the handle of
1244 * @param[out] out_handle A pointer to the handle to populate
1245 *
1246 * @ingroup aux_vk
1247 */
1248XRT_CHECK_RESULT VkResult
1250 VkDeviceMemory device_memory,
1251 xrt_graphics_buffer_handle_t *out_handle);
1252
1253/*!
1254 * @ingroup aux_vk
1255 * Helper to create a VkImage
1256 */
1257VkResult
1259 VkExtent2D extent,
1260 VkFormat format,
1261 VkImageUsageFlags usage,
1262 VkDeviceMemory *out_mem,
1263 VkImage *out_image);
1264
1265/*!
1266 * Helper to create a mutable RG88B8A8 VkImage that specializes in the two
1267 * UNORM and SRGB variants of that formats.
1268 *
1269 * @ingroup aux_vk
1270 */
1271VkResult
1273 struct vk_bundle *vk, VkExtent2D extent, VkImageUsageFlags usage, VkDeviceMemory *out_mem, VkImage *out_image);
1274
1275/*!
1276 * @ingroup aux_vk
1277 * Helper to create a VkImage, with more options for tiling and memory storage.
1278 */
1279VkResult
1281 VkExtent3D extent,
1282 VkFormat format,
1283 VkImageTiling image_tiling,
1284 VkImageUsageFlags image_usage_flags,
1285 VkMemoryPropertyFlags memory_property_flags,
1286 VkDeviceMemory *out_mem,
1287 VkImage *out_image);
1288
1289/*!
1290 * @ingroup aux_vk
1291 */
1292VkResult
1293vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampler *out_sampler);
1294
1295
1296/*
1297 *
1298 * Helpers for creating ímage views.
1299 *
1300 */
1301
1302/*!
1303 * @ingroup aux_vk
1304 */
1305VkResult
1306vk_create_view(struct vk_bundle *vk,
1307 VkImage image,
1308 VkImageViewType type,
1309 VkFormat format,
1310 VkImageSubresourceRange subresource_range,
1311 VkImageView *out_view);
1312
1313/*!
1314 * @ingroup aux_vk
1315 */
1316VkResult
1317vk_create_view_swizzle(struct vk_bundle *vk,
1318 VkImage image,
1319 VkImageViewType type,
1320 VkFormat format,
1321 VkImageSubresourceRange subresource_range,
1322 VkComponentMapping components,
1323 VkImageView *out_view);
1324
1325/*!
1326 * Creates a image with a specific subset of usage, useful for a mutable images
1327 * where one format might not support all usages defined by the image.
1328 *
1329 * @ingroup aux_vk
1330 */
1331VkResult
1333 VkImage image,
1334 VkImageViewType type,
1335 VkFormat format,
1336 VkImageUsageFlags image_usage,
1337 VkImageSubresourceRange subresource_range,
1338 VkImageView *out_view);
1339
1340
1341/*
1342 *
1343 * Helpers for creating descriptor pools and sets.
1344 *
1345 */
1346
1347bool
1348vk_init_descriptor_pool(struct vk_bundle *vk,
1349 const VkDescriptorPoolSize *pool_sizes,
1350 uint32_t pool_size_count,
1351 uint32_t set_count,
1352 VkDescriptorPool *out_descriptor_pool);
1353
1354bool
1355vk_allocate_descriptor_sets(struct vk_bundle *vk,
1356 VkDescriptorPool descriptor_pool,
1357 uint32_t count,
1358 const VkDescriptorSetLayout *set_layout,
1359 VkDescriptorSet *sets);
1360
1361
1362/*
1363 *
1364 * Helpers for creating buffers.
1365 *
1366 */
1367
1368bool
1369vk_buffer_init(struct vk_bundle *vk,
1370 VkDeviceSize size,
1371 VkBufferUsageFlags usage,
1372 VkMemoryPropertyFlags properties,
1373 VkBuffer *out_buffer,
1374 VkDeviceMemory *out_mem);
1375
1376void
1377vk_buffer_destroy(struct vk_buffer *self, struct vk_bundle *vk);
1378
1379bool
1380vk_update_buffer(struct vk_bundle *vk, float *buffer, size_t buffer_size, VkDeviceMemory memory);
1381
1382
1383/*
1384 *
1385 * Helpers for writing command buffers, in the vk_helpers.c file.
1386 *
1387 */
1388
1389/*!
1390 * Inserts a image barrier command, doesn't take any locks, the calling code
1391 * will need hold the lock for the pool that cmd_buffer is from or ensure it is
1392 * externally synchronized.
1393 *
1394 * @ingroup aux_vk
1395 */
1396void
1398 VkCommandBuffer cmd_buffer,
1399 VkImage image,
1400 VkAccessFlags src_access_mask,
1401 VkAccessFlags dst_access_mask,
1402 VkImageLayout old_image_layout,
1403 VkImageLayout new_image_layout,
1404 VkPipelineStageFlags src_stage_mask,
1405 VkPipelineStageFlags dst_stage_mask,
1406 VkImageSubresourceRange subresource_range);
1407
1408/*!
1409 * Inserts a image barrier command specifically for GPU commands, doesn't take
1410 * any locks, the calling code will need hold the lock for the pool that
1411 * cmd_buffer is from or ensure it is externally synchronized.
1412 *
1413 * @ingroup aux_vk
1414 */
1415void
1417 VkCommandBuffer cmd_buffer,
1418 VkImage image,
1419 VkAccessFlags src_access_mask,
1420 VkAccessFlags dst_access_mask,
1421 VkImageLayout old_layout,
1422 VkImageLayout new_layout,
1423 VkImageSubresourceRange subresource_range);
1424
1425#if defined(VK_EXT_debug_utils) || defined(XRT_DOXYGEN)
1426/*!
1427 * Uses VK_EXT_debug_utils to insert debug label into a VkCommandBuffer.
1428 *
1429 * In the vk_debug.c file.
1430 *
1431 * @ingroup aux_vk
1432 */
1433void
1434vk_cmd_insert_label(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const char *name);
1435#endif
1436
1437
1438/*
1439 *
1440 * State creation helpers, in the vk_state_creators.c file.
1441 *
1442 */
1443
1444/*!
1445 * Arguments to @ref vk_create_descriptor_pool function.
1446 */
1448{
1449 uint32_t uniform_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
1450 uint32_t sampler_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
1451 uint32_t storage_image_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
1452 uint32_t storage_buffer_per_descriptor_count; //!< VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
1453
1454 //! The max count of created descriptors.
1456
1457 //! Are descriptors freeable, or must vkResetDescriptorPool be used.
1459};
1460
1461/*!
1462 * Creates a descriptor pool, made for a single layout.
1463 *
1464 * Does error logging.
1465 */
1466VkResult
1468 const struct vk_descriptor_pool_info *info,
1469 VkDescriptorPool *out_descriptor_pool);
1470
1471/*!
1472 * Creates a descriptor set.
1473 *
1474 * Does error logging.
1475 */
1476VkResult
1478 VkDescriptorPool descriptor_pool,
1479 VkDescriptorSetLayout descriptor_layout,
1480 VkDescriptorSet *out_descriptor_set);
1481
1482/*!
1483 * Creates a pipeline layout from a single descriptor set layout.
1484 *
1485 * Does error logging.
1486 */
1487VkResult
1489 VkDescriptorSetLayout descriptor_set_layout,
1490 VkPipelineLayout *out_pipeline_layout);
1491
1492/*!
1493 * Creates a pipeline cache.
1494 *
1495 * Does error logging.
1496 */
1497VkResult
1498vk_create_pipeline_cache(struct vk_bundle *vk, VkPipelineCache *out_pipeline_cache);
1499
1500/*!
1501 * Creates a compute pipeline, assumes entry function is called 'main'.
1502 *
1503 * Does error logging.
1504 */
1505VkResult
1507 VkPipelineCache pipeline_cache,
1508 VkShaderModule shader,
1509 VkPipelineLayout pipeline_layout,
1510 const VkSpecializationInfo *specialization_info,
1511 VkPipeline *out_compute_pipeline);
1512
1513
1514/*
1515 *
1516 * Compositor buffer and swapchain image flags helpers, in the vk_compositor_flags.c file.
1517 *
1518 */
1519
1520/*!
1521 * Return the extern handle type that a buffer should be created with.
1522 *
1523 * cb = Compositor Buffer.
1524 */
1525VkExternalMemoryHandleTypeFlags
1527
1528/*!
1529 * Helper for all of the supported formats to check support for.
1530 *
1531 * These are the available formats we will expose to our clients.
1532 *
1533 * In order of what we prefer. Start with a SRGB format that works on
1534 * both OpenGL and Vulkan. The two linear formats that works on both
1535 * OpenGL and Vulkan. A SRGB format that only works on Vulkan. The last
1536 * two formats should not be used as they are linear but doesn't have
1537 * enough bits to express it without resulting in banding.
1538 *
1539 * The format VK_FORMAT_A2B10G10R10_UNORM_PACK32 is not listed since
1540 * 10 bits are not considered enough to do linear colors without
1541 * banding. If there was a sRGB variant of it then we would have used it
1542 * instead but there isn't. Since it's not a popular format it's best
1543 * not to list it rather then listing it and people falling into the
1544 * trap. The absolute minimum is R11G11B10, but is a really weird format
1545 * so we are not exposing it.
1546 *
1547 * CSCI = Compositor SwapChain Images.
1548 *
1549 * @ingroup aux_vk
1550 */
1551#define VK_CSCI_FORMATS(THING_COLOR, THING_DS, THING_D, THING_S) \
1552 /* color formats */ \
1553 THING_COLOR(R16G16B16A16_UNORM) /* OGL VK */ \
1554 THING_COLOR(R16G16B16A16_SFLOAT) /* OGL VK */ \
1555 THING_COLOR(R16G16B16_UNORM) /* OGL VK - Uncommon. */ \
1556 THING_COLOR(R16G16B16_SFLOAT) /* OGL VK - Uncommon. */ \
1557 THING_COLOR(R8G8B8A8_SRGB) /* OGL VK */ \
1558 THING_COLOR(B8G8R8A8_SRGB) /* VK */ \
1559 THING_COLOR(R8G8B8_SRGB) /* OGL VK - Uncommon. */ \
1560 THING_COLOR(R8G8B8A8_UNORM) /* OGL VK - Bad color precision. */ \
1561 THING_COLOR(B8G8R8A8_UNORM) /* VK - Bad color precision. */ \
1562 THING_COLOR(R8G8B8_UNORM) /* OGL VK - Uncommon. Bad color precision. */ \
1563 THING_COLOR(B8G8R8_UNORM) /* VK - Uncommon. Bad color precision. */ \
1564 THING_COLOR(R5G6B5_UNORM_PACK16) /* OLG VK - Bad color precision. */ \
1565 THING_COLOR(R32_SFLOAT) /* OGL VK */ \
1566 /* depth formats */ \
1567 THING_D(D32_SFLOAT) /* OGL VK */ \
1568 THING_D(D16_UNORM) /* OGL VK */ \
1569 THING_D(X8_D24_UNORM_PACK32) /* OGL VK */ \
1570 /* depth stencil formats */ \
1571 THING_DS(D24_UNORM_S8_UINT) /* OGL VK */ \
1572 THING_DS(D32_SFLOAT_S8_UINT) /* OGL VK */ \
1573 /* stencil format */ \
1574 THING_S(S8_UINT)
1575
1576/*!
1577 * Returns the access flags for the compositor to app barriers.
1578 *
1579 * CSCI = Compositor SwapChain Images.
1580 */
1581VkAccessFlags
1583
1584/*!
1585 * Return the optimal layout for this format, this is the layout as given to the
1586 * app so is bound to the OpenXR spec.
1587 *
1588 * CSCI = Compositor SwapChain Images.
1589 */
1590VkImageLayout
1591vk_csci_get_barrier_optimal_layout(VkFormat format);
1592
1593/*!
1594 * Return the barrier aspect mask for this format, this is intended for the
1595 * barriers that flush the data out before and after transfers between the
1596 * application and compositor.
1597 *
1598 * CSCI = Compositor SwapChain Images.
1599 */
1600VkImageAspectFlags
1601vk_csci_get_barrier_aspect_mask(VkFormat format);
1602
1603/*!
1604 * Returns the usage bits for a given selected format and usage.
1605 *
1606 * For color formats always adds:
1607 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1608 *
1609 * For depth & stencil formats always adds:
1610 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1611 *
1612 * For depth formats always adds:
1613 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1614 *
1615 * For stencil formats always adds:
1616 * * `VK_IMAGE_USAGE_SAMPLED_BIT` for compositor reading in shaders.
1617 *
1618 * CSCI = Compositor SwapChain Images.
1619 */
1620VkImageUsageFlags
1621vk_csci_get_image_usage_flags(struct vk_bundle *vk, VkFormat format, enum xrt_swapchain_usage_bits bits);
1622
1623/*!
1624 * For images views created by the compositor to sample the images, what aspect
1625 * should be set. For color it's the color, for depth and stencil it's only
1626 * depth as both are disallowed by the Vulkan spec, for depth only depth, and
1627 * for stencil only it's stencil.
1628 *
1629 * CSCI = Compositor SwapChain Images.
1630 */
1631VkImageAspectFlags
1633
1634/*!
1635 * Return the extern handle type that a image should be created with.
1636 *
1637 * CSCI = Compositor SwapChain Images.
1638 */
1639VkExternalMemoryHandleTypeFlags
1641
1642/*!
1643 * Get whether a given image can be imported/exported for a handle type.
1644 *
1645 * CSCI = Compositor SwapChain Images.
1646 */
1647void
1649 VkFormat image_format,
1650 enum xrt_swapchain_usage_bits bits,
1651 VkExternalMemoryHandleTypeFlags handle_type,
1652 bool *out_importable,
1653 bool *out_exportable);
1654
1655/*!
1656 * Verify if a format is supported for a specific usage
1657 *
1658 * CSCI = Compositor SwapChain Images.
1659 */
1660bool
1661vk_csci_is_format_supported(struct vk_bundle *vk, VkFormat format, enum xrt_swapchain_usage_bits xbits);
1662
1663/*
1664 *
1665 * Sync objects, in the vk_sync_objects.c file.
1666 *
1667 */
1668
1669/*!
1670 * Is there a good likelihood that the import/export of a timeline semaphore
1671 * will succeed, in other words will the below functions work.
1672 *
1673 * @ingroup aux_vk
1674 */
1675XRT_CHECK_RESULT bool
1677
1678/*!
1679 * @brief Creates a Vulkan fence, submits it to the default VkQueue and return
1680 * its native graphics sync handle.
1681 *
1682 * In case of error, out_native is not touched by the function.
1683 *
1684 * See @ref vk_create_fence_sync_from_native for ownership semantics on import.
1685 *
1686 * @ingroup aux_vk
1687 */
1688XRT_CHECK_RESULT VkResult
1690
1691/*!
1692 * @brief Creates a Vulkan fence from a native graphics sync handle.
1693 *
1694 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1695 *
1696 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p native
1697 * handle may have transferred, a reference may have been added, or the Vulkan object may rely on the caller to keep the
1698 * native handle alive until the Vulkan object is destroyed. Which option applies depends on the particular native
1699 * handle type used.
1700 *
1701 * See the corresponding Vulkan specification text:
1702 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#synchronization-fences-importing
1703 *
1704 * @ingroup aux_vk
1705 */
1706XRT_CHECK_RESULT VkResult
1707vk_create_fence_sync_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkFence *out_fence);
1708
1709/*!
1710 * Creates a Vulkan semaphore and a native graphics sync handle.
1711 *
1712 * In case of success, the underlying Vulkan functionality's ownership semantics
1713 * apply: ownership of the @p native handle may have transferred, a reference
1714 * may have been added, or the Vulkan object may rely on the caller to keep the
1715 * native handle alive until the Vulkan object is destroyed. Which option
1716 * applies depends on the particular native handle type used.
1717 *
1718 * In case of error, neither @p out_sem and @p out_native is not touched by the
1719 * function so the caller only becomes responsible for the output on success.
1720 *
1721 * See the corresponding Vulkan specification text:
1722 * https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#synchronization-semaphores
1723 *
1724 * @ingroup aux_vk
1725 */
1726XRT_CHECK_RESULT VkResult
1727vk_create_semaphore_and_native(struct vk_bundle *vk, VkSemaphore *out_sem, xrt_graphics_sync_handle_t *out_native);
1728
1729#if defined(VK_KHR_timeline_semaphore) || defined(XRT_DOXYGEN)
1730/*
1731 * Creates a Vulkan timeline semaphore and a native graphics sync
1732 * handle, see @ref vk_create_semaphore_and_native for more details.
1733 *
1734 * @ingroup aux_vk
1735 */
1736XRT_CHECK_RESULT VkResult
1737vk_create_timeline_semaphore_and_native(struct vk_bundle *vk,
1738 VkSemaphore *out_sem,
1739 xrt_graphics_sync_handle_t *out_native);
1740#endif
1741
1742/*!
1743 * @brief Creates a Vulkan semaphore from a native graphics sync handle.
1744 *
1745 * In case of error, ownership is never transferred and the caller should close the handle themselves.
1746 *
1747 * In case of success, the underlying Vulkan functionality's ownership semantics apply: ownership of the @p native
1748 * handle may have transferred, a reference may have been added, or the Vulkan object may rely on the caller to keep the
1749 * native handle alive until the Vulkan object is destroyed. Which option applies depends on the particular native
1750 * handle type used.
1751 *
1752 * @ingroup aux_vk
1753 */
1754XRT_CHECK_RESULT VkResult
1755vk_create_semaphore_from_native(struct vk_bundle *vk, xrt_graphics_sync_handle_t native, VkSemaphore *out_sem);
1756
1757#if defined(VK_KHR_timeline_semaphore) || defined(XRT_DOXYGEN)
1758/*!
1759 * @brief Creates a Vulkan timeline semaphore from a native graphics sync
1760 * handle, see @ref vk_create_semaphore_from_native for more details.
1761 *
1762 * @ingroup aux_vk
1763 */
1764XRT_CHECK_RESULT VkResult
1766#endif
1767
1768
1769/*
1770 *
1771 * Time function(s), in the vk_time.c file.
1772 *
1773 */
1774
1775#if defined(VK_EXT_calibrated_timestamps) || defined(XRT_DOXYGEN)
1776/*!
1777 * Convert timestamps in GPU ticks (as return by VkQueryPool timestamp queries)
1778 * into host CPU nanoseconds, same time domain as @ref os_monotonic_get_ns.
1779 *
1780 * Note the timestamp needs to be in the past and not to old, this is because
1781 * not all GPU has full 64 bit timer resolution. For instance a Intel GPU "only"
1782 * have 36 bits of valid timestamp and a tick period 83.3333 nanosecond,
1783 * equating to an epoch of 5726 seconds before overflowing. The function can
1784 * handle overflows happening between the given timestamps and when it is called
1785 * but only for one such epoch overflow, any more will only be treated as one
1786 * such overflow. So timestamps needs to be converted reasonably soon after they
1787 * have been captured.
1788 *
1789 * @param vk The Vulkan bundle.
1790 * @param count Number of timestamps to be converted.
1791 * @param[in,out] in_out_timestamps Array of timestamps to be converted, done in place.
1792 *
1793 * @ingroup aux_vk
1794 */
1795XRT_CHECK_RESULT VkResult
1796vk_convert_timestamps_to_host_ns(struct vk_bundle *vk, uint32_t count, uint64_t *in_out_timestamps);
1797#endif
1798
1799
1800#ifdef __cplusplus
1801}
1802#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:44
static void os_mutex_lock(struct os_mutex *om)
Lock.
Definition: os_threading.h:86
static int os_mutex_trylock(struct os_mutex *om)
Try to lock, but do not block.
Definition: os_threading.h:98
static void os_mutex_unlock(struct os_mutex *om)
Unlock.
Definition: os_threading.h:110
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:974
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:1308
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:1725
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:1628
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:937
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:1688
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:916
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:1302
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:1609
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:1077
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:43
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:1510
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:128
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:808
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:74
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:152
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:1367
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:57
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:1593
xrt_swapchain_usage_bits
Usage of the swapchain images.
Definition: xrt_compositor.h:509
Wrapper around OS threading native functions.
A wrapper around a native mutex.
Definition: os_threading.h:55
Definition: u_string_list.cpp:19
Definition: vk_helpers.h:508
Definition: vk_helpers.h:59
uint32_t family_index
The queue family index.
Definition: vk_helpers.h:63
VkQueue queue
The Vulkan queue handle.
Definition: vk_helpers.h:61
struct os_mutex mutex
The queue mutex -.
Definition: vk_helpers.h:67
uint32_t index
The queue (instance) index.
Definition: vk_helpers.h:65
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:78
bool synchronization_2
Was synchronization2 requested, available, and enabled?
Definition: vk_helpers.h:210
bool timeline_semaphore
Were timeline semaphore requested, available, and enabled?
Definition: vk_helpers.h:201
bool video_maintenance_1
Was KHR_video_maintenance1 requested, available, and enabled?
Definition: vk_helpers.h:216
struct vk_bundle_queue queues[2]
queues - a free list of unique queues
Definition: vk_helpers.h:95
uint32_t timestamp_valid_bits
Valid bits in the queue selected.
Definition: vk_helpers.h:198
uint32_t max_per_stage_descriptor_storage_images
Per stage limit on storage images.
Definition: vk_helpers.h:207
bool is_tegra
Is the GPU a tegra device.
Definition: vk_helpers.h:220
bool timestamp_compute_and_graphics
Are timestamps available for compute and graphics queues?
Definition: vk_helpers.h:192
bool present_wait
Was KHR_present_wait requested, available, and enabled?
Definition: vk_helpers.h:213
uint32_t max_per_stage_descriptor_sampled_images
Per stage limit on sampled images (includes combined).
Definition: vk_helpers.h:204
float timestamp_period
Nanoseconds per gpu tick.
Definition: vk_helpers.h:195
Arguments to vk_create_descriptor_pool function.
Definition: vk_helpers.h:1448
uint32_t descriptor_count
The max count of created descriptors.
Definition: vk_helpers.h:1455
uint32_t uniform_per_descriptor_count
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
Definition: vk_helpers.h:1449
bool freeable
Are descriptors freeable, or must vkResetDescriptorPool be used.
Definition: vk_helpers.h:1458
uint32_t sampler_per_descriptor_count
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER.
Definition: vk_helpers.h:1450
uint32_t storage_image_per_descriptor_count
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE.
Definition: vk_helpers.h:1451
uint32_t storage_buffer_per_descriptor_count
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER.
Definition: vk_helpers.h:1452
Used to enable device features as a argument vk_create_device.
Definition: vk_helpers.h:1066
Definition: vk_helpers.h:45
uint32_t index
The queue (instance) index.
Definition: vk_helpers.h:49
uint32_t family_index
The queue family index.
Definition: vk_helpers.h:47
A single image of a swapchain based on native buffer handles.
Definition: xrt_compositor.h:2160
Swapchain creation info.
Definition: xrt_compositor.h:879
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:179
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:699
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:744
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:628
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:607
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:680
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:246
int xrt_graphics_sync_handle_t
The type underlying synchronization primitives (semaphores, etc) shared between compositor clients an...
Definition: xrt_handles.h:348
Include all of the Vulkan headers in one place, and cope with any "messy" includes implied by it.