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