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