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