The open source OpenXR runtime
at prediction-2 149 lines 3.7 kB view raw
1// Copyright 2019-2021, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Vulkan code for compositors. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @ingroup comp_util 8 */ 9 10#pragma once 11 12#include "xrt/xrt_compositor.h" 13#include "util/u_logging.h" 14#include "util/u_string_list.h" 15#include "vk/vk_helpers.h" 16 17 18#ifdef __cplusplus 19extern "C" { 20#endif 21 22 23/*! 24 * Arguments to Vulkan bundle initialisation, all args needs setting. 25 */ 26struct comp_vulkan_arguments 27{ 28 //! Vulkan version that is required. 29 uint32_t required_instance_version; 30 31 //! Function to get all Vulkan functions from. 32 PFN_vkGetInstanceProcAddr get_instance_proc_address; 33 34 //! Extensions that the instance is created with. 35 struct u_string_list *required_instance_extensions; 36 37 //! Extensions that the instance is created with. 38 struct u_string_list *optional_instance_extensions; 39 40 //! Extensions that the device is created with. 41 struct u_string_list *required_device_extensions; 42 43 //! Extensions that the device is created with. 44 struct u_string_list *optional_device_extensions; 45 46 //! Logging level to be set on the @ref vk_bundle. 47 enum u_logging_level log_level; 48 49 //! Should we look for a queue with no graphics, only compute. 50 bool only_compute_queue; 51 52 //! Should we try to enable timeline semaphores if available 53 bool timeline_semaphore; 54 55 //! Vulkan physical device to be selected, -1 for auto. 56 int selected_gpu_index; 57 58 //! Vulkan physical device index for clients to use, -1 for auto. 59 int client_gpu_index; 60}; 61 62/*! 63 * Extra results from Vulkan bundle initialisation. 64 */ 65struct comp_vulkan_results 66{ 67 //! Vulkan physical device selected. 68 int selected_gpu_index; 69 70 //! Vulkan physical device index for clients to use. 71 int client_gpu_index; 72 73 //! Selected Vulkan device UUID. 74 xrt_uuid_t selected_gpu_deviceUUID; 75 76 //! Selected Vulkan device UUID to suggest to clients. 77 xrt_uuid_t client_gpu_deviceUUID; 78 79 //! The (Windows) LUID for the GPU device suggested for clients. 80 xrt_luid_t client_gpu_deviceLUID; 81 82 //! Whether @ref client_gpu_deviceLUID is valid (probably only on Windows) 83 bool client_gpu_deviceLUID_valid; 84}; 85 86/*! 87 * Fully initialises a @ref vk_bundle, by creating instance, device and queue. 88 * 89 * @ingroup comp_util 90 */ 91bool 92comp_vulkan_init_bundle(struct vk_bundle *vk, 93 const struct comp_vulkan_arguments *vk_args, 94 struct comp_vulkan_results *vk_res); 95 96 97/* 98 * 99 * Format checking. 100 * 101 */ 102 103/*! 104 * Struct with supported format, these are not only check for optimal flags 105 * but also the ability to import and export them. 106 */ 107struct comp_vulkan_formats 108{ 109#define FIELD(IDENT) bool has_##IDENT; 110 VK_CSCI_FORMATS(FIELD, FIELD, FIELD, FIELD) 111#undef FIELD 112 113#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER) 114 //! Is VK_FORMAT_R8G8B8A8_SRGB emulated with VK_FORMAT_R8G8B8A8_UNORM? 115 bool emulated_R8G8B8A8_SRGB; 116#endif 117}; 118 119/*! 120 * Fills in a @ref comp_vulkan_formats struct with the supported formats, use 121 * @ref comp_vulkan_formats_copy_to_info to fill a compositor info struct. 122 * 123 * @ingroup comp_util 124 */ 125void 126comp_vulkan_formats_check(struct vk_bundle *vk, struct comp_vulkan_formats *formats); 127 128/*! 129 * Fills in a @ref xrt_compositor_info struct with the formats listed from a 130 * @ref comp_vulkan_formats. This and @ref comp_vulkan_formats_check are split 131 * to allow the compositor to allow/deny certain formats. 132 * 133 * @ingroup comp_util 134 */ 135void 136comp_vulkan_formats_copy_to_info(const struct comp_vulkan_formats *formats, struct xrt_compositor_info *info); 137 138/*! 139 * Logs the formats at info level. 140 * 141 * @ingroup comp_util 142 */ 143void 144comp_vulkan_formats_log(enum u_logging_level log_level, const struct comp_vulkan_formats *formats); 145 146 147#ifdef __cplusplus 148} 149#endif