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