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