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