1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
/*
* Copyright (c) 2021-2023 The Khronos Group Inc.
* Copyright (c) 2021-2023 Valve Corporation
* Copyright (c) 2021-2023 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and/or associated documentation files (the "Materials"), to
* deal in the Materials without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Materials, and to permit persons to whom the Materials are
* furnished to do so, subject to the following conditions:
*
* The above copyright notice(s) and this permission notice shall be included in
* all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
* USE OR OTHER DEALINGS IN THE MATERIALS.
*
* Author: Charles Giessen <charles@lunarg.com>
*/
#pragma once
#include <array>
#include <filesystem>
#include <ostream>
#include <unordered_map>
#include "util/dispatchable_handle.h"
#include "util/platform_wsi.h"
#include "util/functions.h"
#include "layer/layer_util.h"
enum class CalledICDGIPA { not_called, vk_icd_gipa, vk_gipa };
enum class CalledNegotiateInterface { not_called, vk_icd_negotiate, vk_icd_gipa_first };
enum class InterfaceVersionCheck {
not_called,
loader_version_too_old,
loader_version_too_new,
icd_version_too_new,
version_is_supported
};
// clang-format off
inline std::ostream& operator<<(std::ostream& os, const CalledICDGIPA& result) {
switch (result) {
case (CalledICDGIPA::not_called): return os << "CalledICDGIPA::not_called";
case (CalledICDGIPA::vk_icd_gipa): return os << "CalledICDGIPA::vk_icd_gipa";
case (CalledICDGIPA::vk_gipa): return os << "CalledICDGIPA::vk_gipa";
}
return os << static_cast<uint32_t>(result);
}
inline std::ostream& operator<<(std::ostream& os, const CalledNegotiateInterface& result) {
switch (result) {
case (CalledNegotiateInterface::not_called): return os << "CalledNegotiateInterface::not_called";
case (CalledNegotiateInterface::vk_icd_negotiate): return os << "CalledNegotiateInterface::vk_icd_negotiate";
case (CalledNegotiateInterface::vk_icd_gipa_first): return os << "CalledNegotiateInterface::vk_icd_gipa_first";
}
return os << static_cast<uint32_t>(result);
}
inline std::ostream& operator<<(std::ostream& os, const InterfaceVersionCheck& result) {
switch (result) {
case (InterfaceVersionCheck::not_called): return os << "InterfaceVersionCheck::not_called";
case (InterfaceVersionCheck::loader_version_too_old): return os << "InterfaceVersionCheck::loader_version_too_old";
case (InterfaceVersionCheck::loader_version_too_new): return os << "InterfaceVersionCheck::loader_version_too_new";
case (InterfaceVersionCheck::icd_version_too_new): return os << "InterfaceVersionCheck::icd_version_too_new";
case (InterfaceVersionCheck::version_is_supported): return os << "InterfaceVersionCheck::version_is_supported";
}
return os << static_cast<uint32_t>(result);
}
using VulkanUUID = std::array<uint8_t, VK_UUID_SIZE>;
// clang-format on
// Move only type because it holds a DispatchableHandle<VkPhysicalDevice>
struct PhysicalDevice {
PhysicalDevice() {}
PhysicalDevice(std::string name) : deviceName(name) {}
PhysicalDevice(const char* name) : deviceName(name) {}
DispatchableHandle<VkPhysicalDevice> vk_physical_device;
BUILDER_VALUE(std::string, deviceName)
BUILDER_VALUE(VulkanUUID, deviceUUID)
BUILDER_VALUE(VulkanUUID, driverUUID)
BUILDER_VALUE(VkPhysicalDeviceProperties, properties)
BUILDER_VALUE(VkPhysicalDeviceFeatures, features)
BUILDER_VALUE(VkPhysicalDeviceMemoryProperties, memory_properties)
BUILDER_VALUE(VkPhysicalDeviceDriverProperties, driver_properties)
BUILDER_VALUE(VkImageFormatProperties, image_format_properties)
BUILDER_VALUE(VkExternalMemoryProperties, external_memory_properties)
BUILDER_VALUE(VkExternalSemaphoreProperties, external_semaphore_properties)
BUILDER_VALUE(VkExternalFenceProperties, external_fence_properties)
BUILDER_VALUE(uint32_t, pci_bus)
BUILDER_VECTOR(MockQueueFamilyProperties, queue_family_properties, queue_family_properties)
BUILDER_VECTOR(VkFormatProperties, format_properties, format_properties)
BUILDER_VECTOR(VkSparseImageFormatProperties, sparse_image_format_properties, sparse_image_format_properties)
BUILDER_VECTOR(Extension, extensions, extension)
BUILDER_VALUE(VkSurfaceCapabilitiesKHR, surface_capabilities)
BUILDER_VECTOR(VkSurfaceFormatKHR, surface_formats, surface_format)
BUILDER_VECTOR(VkPresentModeKHR, surface_present_modes, surface_present_mode)
BUILDER_VALUE(VkSurfacePresentScalingCapabilitiesEXT, surface_present_scaling_capabilities)
// No good way to make this a builder value. Each std::vector<VkPresentModeKHR> corresponds to each surface_present_modes
// element
std::vector<std::vector<VkPresentModeKHR>> surface_present_mode_compatibility{};
BUILDER_VECTOR(VkDisplayPropertiesKHR, display_properties, display_properties)
BUILDER_VECTOR(VkDisplayPlanePropertiesKHR, display_plane_properties, display_plane_properties)
BUILDER_VECTOR(VkDisplayKHR, displays, displays)
BUILDER_VECTOR(VkDisplayModePropertiesKHR, display_mode_properties, display_mode_properties)
BUILDER_VALUE(VkDisplayModeKHR, display_mode)
BUILDER_VALUE(VkDisplayPlaneCapabilitiesKHR, display_plane_capabilities)
BUILDER_VALUE_WITH_DEFAULT(VkLayeredDriverUnderlyingApiMSFT, layered_driver_underlying_api,
VK_LAYERED_DRIVER_UNDERLYING_API_NONE_MSFT)
PhysicalDevice& set_api_version(uint32_t version) {
properties.apiVersion = version;
return *this;
}
PhysicalDevice&& finish() { return std::move(*this); }
// Defines the order this physical device appears in vkEnumeratePhysicalDevices
uint32_t iteration_order = 0;
// Objects created from this physical device
std::vector<VkDevice> device_handles;
std::vector<DeviceCreateInfo> device_create_infos;
std::vector<DispatchableHandle<VkQueue>> queue_handles;
// Unknown physical device functions. Add a `VulkanFunction` to this list which will be searched in
// vkGetInstanceProcAddr for custom_instance_functions and vk_icdGetPhysicalDeviceProcAddr for custom_physical_device_functions.
// To add unknown device functions, add it to the PhysicalDevice directly (in the known_device_functions member)
BUILDER_VECTOR(VulkanFunction, custom_physical_device_functions, custom_physical_device_function)
// List of function names which are 'known' to the physical device but have test defined implementations
// The purpose of this list is so that vkGetDeviceProcAddr returns 'a real function pointer' in tests
// without actually implementing any of the logic inside of it.
BUILDER_VECTOR(VulkanFunction, known_device_functions, device_function)
};
struct PhysicalDeviceGroup {
PhysicalDeviceGroup() {}
PhysicalDeviceGroup(PhysicalDevice const& physical_device) { physical_device_handles.push_back(&physical_device); }
PhysicalDeviceGroup(PhysicalDevice const* physical_device) { physical_device_handles.push_back(physical_device); }
PhysicalDeviceGroup(std::vector<PhysicalDevice*> const& physical_devices) {
physical_device_handles.insert(physical_device_handles.end(), physical_devices.begin(), physical_devices.end());
}
PhysicalDeviceGroup& use_physical_device(PhysicalDevice const* physical_device) {
physical_device_handles.push_back(physical_device);
return *this;
}
PhysicalDeviceGroup& use_physical_device(PhysicalDevice const& physical_device) {
physical_device_handles.push_back(&physical_device);
return *this;
}
std::vector<PhysicalDevice const*> physical_device_handles;
VkBool32 subset_allocation = false;
};
struct TestICD {
std::filesystem::path manifest_file_path;
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vk_icdNegotiateLoaderICDInterfaceVersion, true)
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vkEnumerateInstanceExtensionProperties, true)
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vkCreateInstance, true)
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vk_icdGetPhysicalDeviceProcAddr, true)
#if defined(WIN32)
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vk_icdEnumerateAdapterPhysicalDevices, true)
#endif
CalledICDGIPA called_vk_icd_gipa = CalledICDGIPA::not_called;
CalledNegotiateInterface called_negotiate_interface = CalledNegotiateInterface::not_called;
InterfaceVersionCheck interface_version_check = InterfaceVersionCheck::not_called;
BUILDER_VALUE_WITH_DEFAULT(uint32_t, min_icd_interface_version, 0)
BUILDER_VALUE_WITH_DEFAULT(uint32_t, max_icd_interface_version, 7)
uint32_t icd_interface_version_received = 0;
bool called_enumerate_adapter_physical_devices = false;
BUILDER_VALUE(bool, enable_icd_wsi);
bool is_using_icd_wsi = false;
TestICD& setup_WSI(const char* api_selection = nullptr) {
enable_icd_wsi = true;
add_instance_extensions({"VK_KHR_surface", get_platform_wsi_extension(api_selection)});
min_icd_interface_version = (3U < min_icd_interface_version) ? min_icd_interface_version : 3U;
return *this;
}
BUILDER_VALUE_WITH_DEFAULT(uint32_t, icd_api_version, VK_API_VERSION_1_0)
BUILDER_VECTOR(LayerDefinition, instance_layers, instance_layer)
BUILDER_VECTOR(Extension, instance_extensions, instance_extension)
std::vector<Extension> enabled_instance_extensions;
std::unordered_map<VkPhysicalDevice, PhysicalDevice> physical_devices;
TestICD& add_physical_device(PhysicalDevice&& physical_device) {
physical_device.iteration_order = physical_devices.size();
physical_devices.emplace(physical_device.vk_physical_device.handle, std::move(physical_device));
return *this;
}
PhysicalDevice& add_and_get_physical_device(PhysicalDevice&& physical_device) {
VkPhysicalDevice pd = physical_device.vk_physical_device.handle;
physical_device.iteration_order = physical_devices.size();
physical_devices.emplace(physical_device.vk_physical_device.handle, std::move(physical_device));
return physical_devices.at(pd);
}
PhysicalDevice& add_physical_device_at_index(size_t index, PhysicalDevice&& physical_device) {
VkPhysicalDevice pd = physical_device.vk_physical_device.handle;
physical_device.iteration_order = index;
for (auto& [handle, phys_dev] : physical_devices) {
if (phys_dev.iteration_order >= index) {
phys_dev.iteration_order++;
}
}
physical_devices.emplace(physical_device.vk_physical_device.handle, std::move(physical_device));
return physical_devices.at(pd);
}
BUILDER_VECTOR(PhysicalDeviceGroup, physical_device_groups, physical_device_group);
DispatchableHandle<VkInstance> instance_handle;
std::vector<DispatchableHandle<VkDevice>> device_handles;
std::vector<uint64_t> surface_handles;
std::vector<uint64_t> messenger_handles;
std::vector<uint64_t> callback_handles;
std::vector<uint64_t> swapchain_handles;
BUILDER_VALUE_WITH_DEFAULT(bool, can_query_vkEnumerateInstanceVersion, true);
BUILDER_VALUE_WITH_DEFAULT(bool, can_query_GetPhysicalDeviceFuncs, true);
// Unknown instance functions Add a `VulkanFunction` to this list which will be searched in
// vkGetInstanceProcAddr for custom_instance_functions and vk_icdGetPhysicalDeviceProcAddr for
// custom_physical_device_functions. To add unknown device functions, add it to the PhysicalDevice directly (in the
// known_device_functions member)
BUILDER_VECTOR(VulkanFunction, custom_instance_functions, custom_instance_function)
// Must explicitely state support for the tooling info extension, that way we can control if vkGetInstanceProcAddr returns a
// function pointer for vkGetPhysicalDeviceToolPropertiesEXT or vkGetPhysicalDeviceToolProperties (core version)
BUILDER_VALUE(bool, supports_tooling_info_ext);
BUILDER_VALUE(bool, supports_tooling_info_core);
// List of tooling properties that this driver 'supports'
BUILDER_VECTOR(VkPhysicalDeviceToolPropertiesEXT, tooling_properties, tooling_property)
std::vector<DispatchableHandle<VkCommandBuffer>> allocated_command_buffers;
VkInstanceCreateFlags passed_in_instance_create_flags{};
BUILDER_VALUE_WITH_DEFAULT(VkResult, enum_physical_devices_return_code, VK_SUCCESS);
BUILDER_VALUE_WITH_DEFAULT(VkResult, enum_adapter_physical_devices_return_code, VK_SUCCESS);
InstanceCreateInfo GetVkInstanceCreateInfo() {
InstanceCreateInfo info;
for (auto& layer : instance_layers) info.enabled_layers.push_back(layer.layerName.data());
for (auto& ext : instance_extensions) info.enabled_extensions.push_back(ext.extensionName.data());
return info;
}
// Speedup looking for physical devices by not having to iterate through the entire physical_device map to find a particular
// physical device
std::unordered_map<VkDevice, VkPhysicalDevice> device_to_physical_device_map;
#if defined(WIN32)
BUILDER_VALUE(LUID, adapterLUID)
#endif // defined(WIN32)
};
using GetTestICDFunc = TestICD* (*)();
#define GET_TEST_ICD_FUNC_STR "get_test_icd_func"
using GetNewTestICDFunc = TestICD* (*)();
#define RESET_ICD_FUNC_STR "reset_icd_func"
|