| 1 |
// VulkanFunctions - loads vulkan functions for tests to use |
| 2 |
/* |
| 3 |
* Copyright (c) 2025 The Khronos Group Inc. |
| 4 |
* Copyright (c) 2025 Valve Corporation |
| 5 |
* Copyright (c) 2025 LunarG, Inc. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 |
* of this software and/or associated documentation files (the "Materials"), to |
| 9 |
* deal in the Materials without restriction, including without limitation the |
| 10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 11 |
* sell copies of the Materials, and to permit persons to whom the Materials are |
| 12 |
* furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice(s) and this permission notice shall be included in |
| 15 |
* all copies or substantial portions of the Materials. |
| 16 |
* |
| 17 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 |
* |
| 21 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 22 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 24 |
* USE OR OTHER DEALINGS IN THE MATERIALS. |
| 25 |
* |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "dispatch_table.h" |
| 29 |
|
| 30 |
#include "env_var_wrapper.h" |
| 31 |
|
| 32 |
std::filesystem::path get_loader_path() { |
| 33 |
auto loader_path = std::filesystem::path(FRAMEWORK_VULKAN_LIBRARY_PATH); |
| 34 |
auto env_var_res = get_env_var("VK_LOADER_TEST_LOADER_PATH", false); |
| 35 |
if (!env_var_res.empty()) { |
| 36 |
loader_path = std::filesystem::path(env_var_res); |
| 37 |
} |
| 38 |
return loader_path; |
| 39 |
} |
| 40 |
|
| 41 |
void init_vulkan_functions(VulkanFunctions& funcs) { |
| 42 |
#if defined(APPLE_STATIC_LOADER) |
| 43 |
#define GPA(name) name |
| 44 |
#else |
| 45 |
#define GPA(name) funcs.loader.get_symbol(#name) |
| 46 |
#endif |
| 47 |
|
| 48 |
// clang-format off |
| 49 |
funcs.vkGetInstanceProcAddr = GPA(vkGetInstanceProcAddr); |
| 50 |
funcs.vkEnumerateInstanceExtensionProperties = GPA(vkEnumerateInstanceExtensionProperties); |
| 51 |
funcs.vkEnumerateInstanceLayerProperties = GPA(vkEnumerateInstanceLayerProperties); |
| 52 |
funcs.vkEnumerateInstanceVersion = GPA(vkEnumerateInstanceVersion); |
| 53 |
funcs.vkCreateInstance = GPA(vkCreateInstance); |
| 54 |
funcs.vkDestroyInstance = GPA(vkDestroyInstance); |
| 55 |
funcs.vkEnumeratePhysicalDevices = GPA(vkEnumeratePhysicalDevices); |
| 56 |
funcs.vkEnumeratePhysicalDeviceGroups = GPA(vkEnumeratePhysicalDeviceGroups); |
| 57 |
funcs.vkGetPhysicalDeviceFeatures = GPA(vkGetPhysicalDeviceFeatures); |
| 58 |
funcs.vkGetPhysicalDeviceFeatures2 = GPA(vkGetPhysicalDeviceFeatures2); |
| 59 |
funcs.vkGetPhysicalDeviceFormatProperties = GPA(vkGetPhysicalDeviceFormatProperties); |
| 60 |
funcs.vkGetPhysicalDeviceFormatProperties2 = GPA(vkGetPhysicalDeviceFormatProperties2); |
| 61 |
funcs.vkGetPhysicalDeviceImageFormatProperties = GPA(vkGetPhysicalDeviceImageFormatProperties); |
| 62 |
funcs.vkGetPhysicalDeviceImageFormatProperties2 = GPA(vkGetPhysicalDeviceImageFormatProperties2); |
| 63 |
funcs.vkGetPhysicalDeviceSparseImageFormatProperties = GPA(vkGetPhysicalDeviceSparseImageFormatProperties); |
| 64 |
funcs.vkGetPhysicalDeviceSparseImageFormatProperties2 = GPA(vkGetPhysicalDeviceSparseImageFormatProperties2); |
| 65 |
funcs.vkGetPhysicalDeviceProperties = GPA(vkGetPhysicalDeviceProperties); |
| 66 |
funcs.vkGetPhysicalDeviceProperties2 = GPA(vkGetPhysicalDeviceProperties2); |
| 67 |
funcs.vkGetPhysicalDeviceQueueFamilyProperties = GPA(vkGetPhysicalDeviceQueueFamilyProperties); |
| 68 |
funcs.vkGetPhysicalDeviceQueueFamilyProperties2 = GPA(vkGetPhysicalDeviceQueueFamilyProperties2); |
| 69 |
funcs.vkGetPhysicalDeviceMemoryProperties = GPA(vkGetPhysicalDeviceMemoryProperties); |
| 70 |
funcs.vkGetPhysicalDeviceMemoryProperties2 = GPA(vkGetPhysicalDeviceMemoryProperties2); |
| 71 |
funcs.vkGetPhysicalDeviceSurfaceSupportKHR = GPA(vkGetPhysicalDeviceSurfaceSupportKHR); |
| 72 |
funcs.vkGetPhysicalDeviceSurfaceFormatsKHR = GPA(vkGetPhysicalDeviceSurfaceFormatsKHR); |
| 73 |
funcs.vkGetPhysicalDeviceSurfacePresentModesKHR = GPA(vkGetPhysicalDeviceSurfacePresentModesKHR); |
| 74 |
funcs.vkGetPhysicalDeviceSurfaceCapabilitiesKHR = GPA(vkGetPhysicalDeviceSurfaceCapabilitiesKHR); |
| 75 |
funcs.vkEnumerateDeviceExtensionProperties = GPA(vkEnumerateDeviceExtensionProperties); |
| 76 |
funcs.vkEnumerateDeviceLayerProperties = GPA(vkEnumerateDeviceLayerProperties); |
| 77 |
funcs.vkGetPhysicalDeviceExternalBufferProperties = GPA(vkGetPhysicalDeviceExternalBufferProperties); |
| 78 |
funcs.vkGetPhysicalDeviceExternalFenceProperties = GPA(vkGetPhysicalDeviceExternalFenceProperties); |
| 79 |
funcs.vkGetPhysicalDeviceExternalSemaphoreProperties = GPA(vkGetPhysicalDeviceExternalSemaphoreProperties); |
| 80 |
|
| 81 |
funcs.vkDestroySurfaceKHR = GPA(vkDestroySurfaceKHR); |
| 82 |
funcs.vkGetDeviceProcAddr = GPA(vkGetDeviceProcAddr); |
| 83 |
funcs.vkCreateDevice = GPA(vkCreateDevice); |
| 84 |
|
| 85 |
funcs.vkCreateHeadlessSurfaceEXT = GPA(vkCreateHeadlessSurfaceEXT); |
| 86 |
funcs.vkCreateDisplayPlaneSurfaceKHR = GPA(vkCreateDisplayPlaneSurfaceKHR); |
| 87 |
funcs.vkGetPhysicalDeviceDisplayPropertiesKHR = GPA(vkGetPhysicalDeviceDisplayPropertiesKHR); |
| 88 |
funcs.vkGetPhysicalDeviceDisplayPlanePropertiesKHR = GPA(vkGetPhysicalDeviceDisplayPlanePropertiesKHR); |
| 89 |
funcs.vkGetDisplayPlaneSupportedDisplaysKHR = GPA(vkGetDisplayPlaneSupportedDisplaysKHR); |
| 90 |
funcs.vkGetDisplayModePropertiesKHR = GPA(vkGetDisplayModePropertiesKHR); |
| 91 |
funcs.vkCreateDisplayModeKHR = GPA(vkCreateDisplayModeKHR); |
| 92 |
funcs.vkGetDisplayPlaneCapabilitiesKHR = GPA(vkGetDisplayPlaneCapabilitiesKHR); |
| 93 |
funcs.vkGetPhysicalDevicePresentRectanglesKHR = GPA(vkGetPhysicalDevicePresentRectanglesKHR); |
| 94 |
funcs.vkGetPhysicalDeviceDisplayProperties2KHR = GPA(vkGetPhysicalDeviceDisplayProperties2KHR); |
| 95 |
funcs.vkGetPhysicalDeviceDisplayPlaneProperties2KHR = GPA(vkGetPhysicalDeviceDisplayPlaneProperties2KHR); |
| 96 |
funcs.vkGetDisplayModeProperties2KHR = GPA(vkGetDisplayModeProperties2KHR); |
| 97 |
funcs.vkGetDisplayPlaneCapabilities2KHR = GPA(vkGetDisplayPlaneCapabilities2KHR); |
| 98 |
funcs.vkGetPhysicalDeviceSurfaceCapabilities2KHR = GPA(vkGetPhysicalDeviceSurfaceCapabilities2KHR); |
| 99 |
funcs.vkGetPhysicalDeviceSurfaceFormats2KHR = GPA(vkGetPhysicalDeviceSurfaceFormats2KHR); |
| 100 |
|
| 101 |
#if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 102 |
funcs.vkCreateAndroidSurfaceKHR = GPA(vkCreateAndroidSurfaceKHR); |
| 103 |
#endif // VK_USE_PLATFORM_ANDROID_KHR |
| 104 |
#if defined(VK_USE_PLATFORM_DIRECTFB_EXT) |
| 105 |
funcs.vkCreateDirectFBSurfaceEXT = GPA(vkCreateDirectFBSurfaceEXT); |
| 106 |
funcs.vkGetPhysicalDeviceDirectFBPresentationSupportEXT = GPA(vkGetPhysicalDeviceDirectFBPresentationSupportEXT); |
| 107 |
#endif // VK_USE_PLATFORM_DIRECTFB_EXT |
| 108 |
#if defined(VK_USE_PLATFORM_FUCHSIA) |
| 109 |
funcs.vkCreateImagePipeSurfaceFUCHSIA = GPA(vkCreateImagePipeSurfaceFUCHSIA); |
| 110 |
#endif // VK_USE_PLATFORM_FUCHSIA |
| 111 |
#if defined(VK_USE_PLATFORM_GGP) |
| 112 |
funcs.vkCreateStreamDescriptorSurfaceGGP = GPA(vkCreateStreamDescriptorSurfaceGGP); |
| 113 |
#endif // VK_USE_PLATFORM_GGP |
| 114 |
#if defined(VK_USE_PLATFORM_IOS_MVK) |
| 115 |
funcs.vkCreateIOSSurfaceMVK = GPA(vkCreateIOSSurfaceMVK); |
| 116 |
#endif // VK_USE_PLATFORM_IOS_MVK |
| 117 |
#if defined(VK_USE_PLATFORM_MACOS_MVK) |
| 118 |
funcs.vkCreateMacOSSurfaceMVK = GPA(vkCreateMacOSSurfaceMVK); |
| 119 |
#endif // VK_USE_PLATFORM_MACOS_MVK |
| 120 |
#if defined(VK_USE_PLATFORM_METAL_EXT) |
| 121 |
funcs.vkCreateMetalSurfaceEXT = GPA(vkCreateMetalSurfaceEXT); |
| 122 |
#endif // VK_USE_PLATFORM_METAL_EXT |
| 123 |
#if defined(VK_USE_PLATFORM_SCREEN_QNX) |
| 124 |
funcs.vkCreateScreenSurfaceQNX = GPA(vkCreateScreenSurfaceQNX); |
| 125 |
funcs.vkGetPhysicalDeviceScreenPresentationSupportQNX = GPA(vkGetPhysicalDeviceScreenPresentationSupportQNX); |
| 126 |
#endif // VK_USE_PLATFORM_SCREEN_QNX |
| 127 |
#if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 128 |
funcs.vkCreateWaylandSurfaceKHR = GPA(vkCreateWaylandSurfaceKHR); |
| 129 |
funcs.vkGetPhysicalDeviceWaylandPresentationSupportKHR = GPA(vkGetPhysicalDeviceWaylandPresentationSupportKHR); |
| 130 |
#endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 131 |
#if defined(VK_USE_PLATFORM_XCB_KHR) |
| 132 |
funcs.vkCreateXcbSurfaceKHR = GPA(vkCreateXcbSurfaceKHR); |
| 133 |
funcs.vkGetPhysicalDeviceXcbPresentationSupportKHR = GPA(vkGetPhysicalDeviceXcbPresentationSupportKHR); |
| 134 |
#endif // VK_USE_PLATFORM_XCB_KHR |
| 135 |
#if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 136 |
funcs.vkCreateXlibSurfaceKHR = GPA(vkCreateXlibSurfaceKHR); |
| 137 |
funcs.vkGetPhysicalDeviceXlibPresentationSupportKHR = GPA(vkGetPhysicalDeviceXlibPresentationSupportKHR); |
| 138 |
#endif // VK_USE_PLATFORM_XLIB_KHR |
| 139 |
#if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 140 |
funcs.vkCreateWin32SurfaceKHR = GPA(vkCreateWin32SurfaceKHR); |
| 141 |
funcs.vkGetPhysicalDeviceWin32PresentationSupportKHR = GPA(vkGetPhysicalDeviceWin32PresentationSupportKHR); |
| 142 |
#endif // VK_USE_PLATFORM_WIN32_KHR |
| 143 |
funcs.vkDestroyDevice = GPA(vkDestroyDevice); |
| 144 |
funcs.vkGetDeviceQueue = GPA(vkGetDeviceQueue); |
| 145 |
#undef GPA |
| 146 |
// clang-format on |
| 147 |
} |
| 148 |
|
| 149 |
#if defined(APPLE_STATIC_LOADER) |
| 150 |
VulkanFunctions::VulkanFunctions() { |
| 151 |
#else |
| 152 |
VulkanFunctions::VulkanFunctions() : loader(get_loader_path()) { |
| 153 |
#endif |
| 154 |
init_vulkan_functions(*this); |
| 155 |
} |
| 156 |
|
| 157 |
void VulkanFunctions::load_instance_functions(VkInstance instance) { |
| 158 |
vkCreateDebugReportCallbackEXT = FromVoidStarFunc(vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT")); |
| 159 |
vkDestroyDebugReportCallbackEXT = FromVoidStarFunc(vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT")); |
| 160 |
vkCreateDebugUtilsMessengerEXT = FromVoidStarFunc(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT")); |
| 161 |
vkDestroyDebugUtilsMessengerEXT = FromVoidStarFunc(vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT")); |
| 162 |
} |
| 163 |
|
| 164 |
DeviceFunctions::DeviceFunctions(const VulkanFunctions& vulkan_functions, VkDevice device) { |
| 165 |
vkGetDeviceProcAddr = vulkan_functions.vkGetDeviceProcAddr; |
| 166 |
vkDestroyDevice = load(device, "vkDestroyDevice"); |
| 167 |
vkGetDeviceQueue = load(device, "vkGetDeviceQueue"); |
| 168 |
vkCreateCommandPool = load(device, "vkCreateCommandPool"); |
| 169 |
vkAllocateCommandBuffers = load(device, "vkAllocateCommandBuffers"); |
| 170 |
vkDestroyCommandPool = load(device, "vkDestroyCommandPool"); |
| 171 |
vkCreateSwapchainKHR = load(device, "vkCreateSwapchainKHR"); |
| 172 |
vkGetSwapchainImagesKHR = load(device, "vkGetSwapchainImagesKHR"); |
| 173 |
vkDestroySwapchainKHR = load(device, "vkDestroySwapchainKHR"); |
| 174 |
} |