• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 The Khronos Group Inc.
3  * Copyright (c) 2021 Valve Corporation
4  * Copyright (c) 2021 LunarG, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and/or associated documentation files (the "Materials"), to
8  * deal in the Materials without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Materials, and to permit persons to whom the Materials are
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice(s) and this permission notice shall be included in
14  * all copies or substantial portions of the Materials.
15  *
16  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  *
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23  * USE OR OTHER DEALINGS IN THE MATERIALS.
24  *
25  * Author: Charles Giessen <charles@lunarg.com>
26  */
27 
28 #include "test_environment.h"
29 
InstWrapper(VulkanFunctions & functions,VkAllocationCallbacks * callbacks)30 InstWrapper::InstWrapper(VulkanFunctions& functions, VkAllocationCallbacks* callbacks) noexcept
31     : functions(&functions), callbacks(callbacks) {}
InstWrapper(VulkanFunctions & functions,VkInstance inst,VkAllocationCallbacks * callbacks)32 InstWrapper::InstWrapper(VulkanFunctions& functions, VkInstance inst, VkAllocationCallbacks* callbacks) noexcept
33     : functions(&functions), inst(inst), callbacks(callbacks) {}
~InstWrapper()34 InstWrapper::~InstWrapper() noexcept {
35     if (inst != VK_NULL_HANDLE) functions->vkDestroyInstance(inst, callbacks);
36 }
37 
InstWrapper(InstWrapper && other)38 InstWrapper::InstWrapper(InstWrapper&& other) noexcept {
39     functions = other.functions;
40     inst = other.inst;
41     callbacks = other.callbacks;
42     create_info = other.create_info;
43     other.inst = VK_NULL_HANDLE;
44 }
operator =(InstWrapper && other)45 InstWrapper& InstWrapper::operator=(InstWrapper&& other) noexcept {
46     functions->vkDestroyInstance(inst, callbacks);
47     functions = other.functions;
48     inst = other.inst;
49     callbacks = other.callbacks;
50     create_info = other.create_info;
51     other.inst = VK_NULL_HANDLE;
52     return *this;
53 }
54 
CheckCreate(VkResult result_to_check)55 void InstWrapper::CheckCreate(VkResult result_to_check) {
56     ASSERT_EQ(result_to_check, functions->vkCreateInstance(create_info.get(), callbacks, &inst));
57 }
58 
GetPhysDevs(uint32_t phys_dev_count,VkResult result_to_check)59 std::vector<VkPhysicalDevice> InstWrapper::GetPhysDevs(uint32_t phys_dev_count, VkResult result_to_check) {
60     uint32_t physical_count = phys_dev_count;
61     std::vector<VkPhysicalDevice> physical_devices;
62     physical_devices.resize(phys_dev_count);
63     VkResult res = functions->vkEnumeratePhysicalDevices(inst, &physical_count, physical_devices.data());
64     EXPECT_EQ(result_to_check, res);
65     return physical_devices;
66 }
67 
GetPhysDevs(VkResult result_to_check)68 std::vector<VkPhysicalDevice> InstWrapper::GetPhysDevs(VkResult result_to_check) {
69     uint32_t physical_count = 0;
70     VkResult res = functions->vkEnumeratePhysicalDevices(inst, &physical_count, nullptr);
71     std::vector<VkPhysicalDevice> physical_devices;
72     physical_devices.resize(physical_count);
73     res = functions->vkEnumeratePhysicalDevices(inst, &physical_count, physical_devices.data());
74     EXPECT_EQ(result_to_check, res);
75     return physical_devices;
76 }
77 
GetPhysDev(VkResult result_to_check)78 VkPhysicalDevice InstWrapper::GetPhysDev(VkResult result_to_check) {
79     uint32_t physical_count = 1;
80     VkPhysicalDevice physical_device = VK_NULL_HANDLE;
81     VkResult res = this->functions->vkEnumeratePhysicalDevices(inst, &physical_count, &physical_device);
82     EXPECT_EQ(result_to_check, res);
83     return physical_device;
84 }
85 
EnumerateDeviceExtensions(InstWrapper const & inst,VkPhysicalDevice physical_device)86 std::vector<VkExtensionProperties> EnumerateDeviceExtensions(InstWrapper const& inst, VkPhysicalDevice physical_device) {
87     uint32_t ext_count = 1;
88     VkResult res = inst.functions->vkEnumerateDeviceExtensionProperties(physical_device, nullptr, &ext_count, nullptr);
89     EXPECT_EQ(VK_SUCCESS, res);
90     std::vector<VkExtensionProperties> extensions;
91     extensions.resize(ext_count);
92     res = inst.functions->vkEnumerateDeviceExtensionProperties(physical_device, nullptr, &ext_count, extensions.data());
93     EXPECT_EQ(VK_SUCCESS, res);
94     extensions.resize(ext_count);
95     return extensions;
96 }
97 
DeviceWrapper(InstWrapper & inst_wrapper,VkAllocationCallbacks * callbacks)98 DeviceWrapper::DeviceWrapper(InstWrapper& inst_wrapper, VkAllocationCallbacks* callbacks) noexcept
99     : functions(inst_wrapper.functions), callbacks(callbacks){};
DeviceWrapper(VulkanFunctions & functions,VkDevice device,VkAllocationCallbacks * callbacks)100 DeviceWrapper::DeviceWrapper(VulkanFunctions& functions, VkDevice device, VkAllocationCallbacks* callbacks) noexcept
101     : functions(&functions), dev(device), callbacks(callbacks){};
~DeviceWrapper()102 DeviceWrapper::~DeviceWrapper() noexcept { functions->vkDestroyDevice(dev, callbacks); }
103 
DeviceWrapper(DeviceWrapper && other)104 DeviceWrapper::DeviceWrapper(DeviceWrapper&& other) noexcept {
105     functions = other.functions;
106     dev = other.dev;
107     callbacks = other.callbacks;
108     create_info = other.create_info;
109     other.dev = VK_NULL_HANDLE;
110 }
operator =(DeviceWrapper && other)111 DeviceWrapper& DeviceWrapper::operator=(DeviceWrapper&& other) noexcept {
112     functions->vkDestroyDevice(dev, callbacks);
113     functions = other.functions;
114     dev = other.dev;
115     callbacks = other.callbacks;
116     create_info = other.create_info;
117     other.dev = VK_NULL_HANDLE;
118     return *this;
119 }
120 
CheckCreate(VkPhysicalDevice phys_dev,VkResult result_to_check)121 void DeviceWrapper::CheckCreate(VkPhysicalDevice phys_dev, VkResult result_to_check) {
122     ASSERT_EQ(result_to_check, functions->vkCreateDevice(phys_dev, create_info.get(), callbacks, &dev));
123 }
124 
CreateDebugUtilsMessenger(DebugUtilsWrapper & debug_utils)125 VkResult CreateDebugUtilsMessenger(DebugUtilsWrapper& debug_utils) {
126     return debug_utils.vkCreateDebugUtilsMessengerEXT(debug_utils.inst, debug_utils.get(), debug_utils.callbacks,
127                                                       &debug_utils.messenger);
128 }
129 
FillDebugUtilsCreateDetails(InstanceCreateInfo & create_info,DebugUtilsLogger & logger)130 void FillDebugUtilsCreateDetails(InstanceCreateInfo& create_info, DebugUtilsLogger& logger) {
131     create_info.add_extension("VK_EXT_debug_utils");
132     create_info.instance_info.pNext = logger.get();
133 }
FillDebugUtilsCreateDetails(InstanceCreateInfo & create_info,DebugUtilsWrapper & wrapper)134 void FillDebugUtilsCreateDetails(InstanceCreateInfo& create_info, DebugUtilsWrapper& wrapper) {
135     create_info.add_extension("VK_EXT_debug_utils");
136     create_info.instance_info.pNext = wrapper.get();
137 }
138 
PlatformShimWrapper(std::vector<fs::FolderManager> * folders,bool enable_log)139 PlatformShimWrapper::PlatformShimWrapper(std::vector<fs::FolderManager>* folders, bool enable_log) noexcept {
140 #if defined(WIN32) || defined(__APPLE__)
141     shim_library = LibraryWrapper(SHIM_LIBRARY_NAME);
142     PFN_get_platform_shim get_platform_shim_func = shim_library.get_symbol(GET_PLATFORM_SHIM_STR);
143     assert(get_platform_shim_func != NULL && "Must be able to get \"platform_shim\"");
144     platform_shim = get_platform_shim_func(folders);
145 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
146     platform_shim = get_platform_shim(folders);
147 #endif
148     platform_shim->reset();
149 
150     if (enable_log) {
151         set_env_var("VK_LOADER_DEBUG", "all");
152     }
153 }
~PlatformShimWrapper()154 PlatformShimWrapper::~PlatformShimWrapper() noexcept { platform_shim->reset(); }
155 
TestICDHandle()156 TestICDHandle::TestICDHandle() noexcept {}
TestICDHandle(fs::path const & icd_path)157 TestICDHandle::TestICDHandle(fs::path const& icd_path) noexcept : icd_library(icd_path) {
158     proc_addr_get_test_icd = icd_library.get_symbol(GET_TEST_ICD_FUNC_STR);
159     proc_addr_reset_icd = icd_library.get_symbol(RESET_ICD_FUNC_STR);
160 }
get_test_icd()161 TestICD& TestICDHandle::get_test_icd() noexcept {
162     assert(proc_addr_get_test_icd != NULL && "symbol must be loaded before use");
163     return *proc_addr_get_test_icd();
164 }
reset_icd()165 TestICD& TestICDHandle::reset_icd() noexcept {
166     assert(proc_addr_reset_icd != NULL && "symbol must be loaded before use");
167     return *proc_addr_reset_icd();
168 }
get_icd_full_path()169 fs::path TestICDHandle::get_icd_full_path() noexcept { return icd_library.lib_path; }
get_icd_manifest_path()170 fs::path TestICDHandle::get_icd_manifest_path() noexcept { return manifest_path; }
171 
TestLayerHandle()172 TestLayerHandle::TestLayerHandle() noexcept {}
TestLayerHandle(fs::path const & layer_path)173 TestLayerHandle::TestLayerHandle(fs::path const& layer_path) noexcept : layer_library(layer_path) {
174     proc_addr_get_test_layer = layer_library.get_symbol(GET_TEST_LAYER_FUNC_STR);
175     proc_addr_reset_layer = layer_library.get_symbol(RESET_LAYER_FUNC_STR);
176 }
get_test_layer()177 TestLayer& TestLayerHandle::get_test_layer() noexcept {
178     assert(proc_addr_get_test_layer != NULL && "symbol must be loaded before use");
179     return *proc_addr_get_test_layer();
180 }
reset_layer()181 TestLayer& TestLayerHandle::reset_layer() noexcept {
182     assert(proc_addr_reset_layer != NULL && "symbol must be loaded before use");
183     return *proc_addr_reset_layer();
184 }
get_layer_full_path()185 fs::path TestLayerHandle::get_layer_full_path() noexcept { return layer_library.lib_path; }
get_layer_manifest_path()186 fs::path TestLayerHandle::get_layer_manifest_path() noexcept { return manifest_path; }
187 
FrameworkEnvironment()188 FrameworkEnvironment::FrameworkEnvironment() noexcept : FrameworkEnvironment(true) {}
FrameworkEnvironment(bool enable_log)189 FrameworkEnvironment::FrameworkEnvironment(bool enable_log) noexcept : platform_shim(&folders, enable_log), vulkan_functions() {
190     // This order is important, it matches the enum ManifestLocation, used to index the folders vector
191     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("null_dir"));
192     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("icd_manifests"));
193     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("icd_env_vars_manifests"));
194     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("explicit_layer_manifests"));
195     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("explicit_env_var_layer_folder"));
196     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("explicit_add_env_var_layer_folder"));
197     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("implicit_layer_manifests"));
198     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("override_layer_manifests"));
199     folders.emplace_back(FRAMEWORK_BUILD_DIRECTORY, std::string("app_package_manifests"));
200 
201     platform_shim->redirect_all_paths(get_folder(ManifestLocation::null).location());
202     platform_shim->set_path(ManifestCategory::icd, get_folder(ManifestLocation::driver).location());
203     platform_shim->set_path(ManifestCategory::explicit_layer, get_folder(ManifestLocation::explicit_layer).location());
204     platform_shim->set_path(ManifestCategory::implicit_layer, get_folder(ManifestLocation::implicit_layer).location());
205 }
206 
add_icd(TestICDDetails icd_details)207 void FrameworkEnvironment::add_icd(TestICDDetails icd_details) noexcept {
208     size_t cur_icd_index = icds.size();
209     fs::FolderManager* folder = &get_folder(ManifestLocation::driver);
210     if (icd_details.discovery_type == ManifestDiscoveryType::env_var ||
211         icd_details.discovery_type == ManifestDiscoveryType::add_env_var) {
212         folder = &get_folder(ManifestLocation::driver_env_var);
213     }
214     if (icd_details.discovery_type == ManifestDiscoveryType::windows_app_package) {
215         folder = &get_folder(ManifestLocation::windows_app_package);
216     }
217     if (!icd_details.is_fake) {
218         fs::path new_driver_name = fs::path(icd_details.icd_manifest.lib_path).stem() + "_" + std::to_string(cur_icd_index) +
219                                    fs::path(icd_details.icd_manifest.lib_path).extension();
220 
221         auto new_driver_location = folder->copy_file(icd_details.icd_manifest.lib_path, new_driver_name.str());
222 
223         icds.push_back(TestICDHandle(new_driver_location));
224         icds.back().reset_icd();
225         icd_details.icd_manifest.lib_path = new_driver_location.str();
226     }
227     std::string full_json_name = icd_details.json_name + "_" + std::to_string(cur_icd_index) + ".json";
228 
229     icds.back().manifest_path = folder->write_manifest(full_json_name, icd_details.icd_manifest.get_manifest_str());
230     switch (icd_details.discovery_type) {
231         default:
232         case (ManifestDiscoveryType::generic):
233             platform_shim->add_manifest(ManifestCategory::icd, icds.back().manifest_path);
234             break;
235         case (ManifestDiscoveryType::env_var):
236             if (!env_var_vk_icd_filenames.empty()) {
237                 env_var_vk_icd_filenames += OS_ENV_VAR_LIST_SEPARATOR;
238             }
239             env_var_vk_icd_filenames += (folder->location() / full_json_name).str();
240             set_env_var("VK_DRIVER_FILES", env_var_vk_icd_filenames);
241             break;
242         case (ManifestDiscoveryType::add_env_var):
243             if (!add_env_var_vk_icd_filenames.empty()) {
244                 add_env_var_vk_icd_filenames += OS_ENV_VAR_LIST_SEPARATOR;
245             }
246             add_env_var_vk_icd_filenames += (folder->location() / full_json_name).str();
247             set_env_var("VK_ADD_DRIVER_FILES", add_env_var_vk_icd_filenames);
248             break;
249         case (ManifestDiscoveryType::none):
250             break;
251 #ifdef _WIN32
252         case (ManifestDiscoveryType::windows_app_package):
253             platform_shim->set_app_package_path(folder->location());
254             break;
255 #endif
256     }
257 }
258 
add_implicit_layer(ManifestLayer layer_manifest,const std::string & json_name)259 void FrameworkEnvironment::add_implicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
260     add_layer_impl(TestLayerDetails{layer_manifest, json_name}, ManifestCategory::implicit_layer);
261 }
add_explicit_layer(ManifestLayer layer_manifest,const std::string & json_name)262 void FrameworkEnvironment::add_explicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
263     add_layer_impl(TestLayerDetails{layer_manifest, json_name}, ManifestCategory::explicit_layer);
264 }
add_fake_implicit_layer(ManifestLayer layer_manifest,const std::string & json_name)265 void FrameworkEnvironment::add_fake_implicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
266     add_layer_impl(TestLayerDetails{layer_manifest, json_name}.set_is_fake(true), ManifestCategory::implicit_layer);
267 }
add_fake_explicit_layer(ManifestLayer layer_manifest,const std::string & json_name)268 void FrameworkEnvironment::add_fake_explicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
269     add_layer_impl(TestLayerDetails{layer_manifest, json_name}.set_is_fake(true), ManifestCategory::explicit_layer);
270 }
add_implicit_layer(TestLayerDetails layer_details)271 void FrameworkEnvironment::add_implicit_layer(TestLayerDetails layer_details) noexcept {
272     add_layer_impl(layer_details, ManifestCategory::implicit_layer);
273 }
add_explicit_layer(TestLayerDetails layer_details)274 void FrameworkEnvironment::add_explicit_layer(TestLayerDetails layer_details) noexcept {
275     add_layer_impl(layer_details, ManifestCategory::explicit_layer);
276 }
277 
add_layer_impl(TestLayerDetails layer_details,ManifestCategory category)278 void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, ManifestCategory category) {
279     fs::FolderManager* fs_ptr = &get_folder(ManifestLocation::explicit_layer);
280     switch (layer_details.discovery_type) {
281         default:
282         case (ManifestDiscoveryType::generic):
283             if (category == ManifestCategory::implicit_layer) fs_ptr = &get_folder(ManifestLocation::implicit_layer);
284             break;
285         case (ManifestDiscoveryType::env_var):
286             fs_ptr = &get_folder(ManifestLocation::explicit_layer_env_var);
287             if (!env_var_vk_layer_paths.empty()) {
288                 env_var_vk_layer_paths += OS_ENV_VAR_LIST_SEPARATOR;
289             }
290             env_var_vk_layer_paths += fs_ptr->location().str();
291             set_env_var("VK_LAYER_PATH", env_var_vk_layer_paths);
292             break;
293         case (ManifestDiscoveryType::add_env_var):
294             fs_ptr = &get_folder(ManifestLocation::explicit_layer_add_env_var);
295             if (!add_env_var_vk_layer_paths.empty()) {
296                 add_env_var_vk_layer_paths += OS_ENV_VAR_LIST_SEPARATOR;
297             }
298             add_env_var_vk_layer_paths += fs_ptr->location().str();
299             set_env_var("VK_ADD_LAYER_PATH", add_env_var_vk_layer_paths);
300             break;
301         case (ManifestDiscoveryType::override_folder):
302             fs_ptr = &get_folder(ManifestLocation::override_layer);
303             break;
304         case (ManifestDiscoveryType::none):
305             break;
306     }
307     auto& folder = *fs_ptr;
308     size_t new_layers_start = layers.size();
309     for (auto& layer : layer_details.layer_manifest.layers) {
310         size_t cur_layer_index = layers.size();
311         if (!layer.lib_path.str().empty()) {
312             std::string new_layer_name = layer.name + "_" + std::to_string(cur_layer_index) + "_" + layer.lib_path.filename().str();
313 
314             auto new_layer_location = folder.copy_file(layer.lib_path, new_layer_name);
315 
316             // Don't load the layer binary if using any of the wrap objects layers, since it doesn't export the same interface
317             // functions
318             if (!layer_details.is_fake &&
319                 layer.lib_path.stem().str().find(fs::path(TEST_LAYER_WRAP_OBJECTS).stem().str()) == std::string::npos) {
320                 layers.push_back(TestLayerHandle(new_layer_location));
321                 layers.back().reset_layer();
322             }
323             layer.lib_path = new_layer_location;
324         }
325     }
326     if (layer_details.discovery_type != ManifestDiscoveryType::none) {
327         auto layer_loc = folder.write_manifest(layer_details.json_name, layer_details.layer_manifest.get_manifest_str());
328         platform_shim->add_manifest(category, layer_loc);
329         for (size_t i = new_layers_start; i < layers.size(); i++) {
330             layers.at(i).manifest_path = layer_loc;
331         }
332     }
333 }
334 
get_test_icd(size_t index)335 TestICD& FrameworkEnvironment::get_test_icd(size_t index) noexcept { return icds[index].get_test_icd(); }
reset_icd(size_t index)336 TestICD& FrameworkEnvironment::reset_icd(size_t index) noexcept { return icds[index].reset_icd(); }
get_test_icd_path(size_t index)337 fs::path FrameworkEnvironment::get_test_icd_path(size_t index) noexcept { return icds[index].get_icd_full_path(); }
get_icd_manifest_path(size_t index)338 fs::path FrameworkEnvironment::get_icd_manifest_path(size_t index) noexcept { return icds[index].get_icd_manifest_path(); }
339 
get_test_layer(size_t index)340 TestLayer& FrameworkEnvironment::get_test_layer(size_t index) noexcept { return layers[index].get_test_layer(); }
reset_layer(size_t index)341 TestLayer& FrameworkEnvironment::reset_layer(size_t index) noexcept { return layers[index].reset_layer(); }
get_test_layer_path(size_t index)342 fs::path FrameworkEnvironment::get_test_layer_path(size_t index) noexcept { return layers[index].get_layer_full_path(); }
get_layer_manifest_path(size_t index)343 fs::path FrameworkEnvironment::get_layer_manifest_path(size_t index) noexcept { return layers[index].get_layer_manifest_path(); }
344 
get_folder(ManifestLocation location)345 fs::FolderManager& FrameworkEnvironment::get_folder(ManifestLocation location) noexcept {
346     // index it directly using the enum location since they will always be in that order
347     return folders.at(static_cast<size_t>(location));
348 }
setup_WSI_in_ICD(TestICD & icd)349 void setup_WSI_in_ICD(TestICD& icd) {
350     icd.enable_icd_wsi = true;
351 #ifdef VK_USE_PLATFORM_ANDROID_KHR
352     icd.add_instance_extensions({"VK_KHR_surface", "VK_KHR_android_surface"});
353 #endif
354 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
355     icd.add_instance_extensions({"VK_KHR_surface", "VK_EXT_directfb_surface"});
356 #endif
357 #ifdef VK_USE_PLATFORM_FUCHSIA
358     icd.add_instance_extensions({"VK_KHR_surface", "VK_FUCHSIA_imagepipe_surface"});
359 #endif
360 #ifdef VK_USE_PLATFORM_GGP
361     icd.add_instance_extensions({"VK_KHR_surface", "VK_GGP_stream_descriptor_surface"});
362 #endif
363 #ifdef VK_USE_PLATFORM_IOS_MVK
364     icd.add_instance_extensions({"VK_KHR_surface", "VK_MVK_ios_surface"});
365 #endif
366 #ifdef VK_USE_PLATFORM_MACOS_MVK
367     icd.add_instance_extensions({"VK_KHR_surface", "VK_MVK_macos_surface"});
368 #endif
369 #ifdef VK_USE_PLATFORM_METAL_EXT
370     icd.add_instance_extensions({"VK_KHR_surface", "VK_EXT_metal_surface"});
371 #endif
372 #ifdef VK_USE_PLATFORM_SCREEN_QNX
373     icd.add_instance_extensions({"VK_KHR_surface", "VK_QNX_screen_surface"});
374 #endif
375 #ifdef VK_USE_PLATFORM_VI_NN
376     icd.add_instance_extensions({"VK_KHR_surface", "VK_NN_vi_surface"});
377 #endif
378 #ifdef VK_USE_PLATFORM_XCB_KHR
379     icd.add_instance_extensions({"VK_KHR_surface", "VK_KHR_xcb_surface"});
380 #endif
381 #ifdef VK_USE_PLATFORM_XLIB_KHR
382     icd.add_instance_extensions({"VK_KHR_surface", "VK_KHR_xlib_surface"});
383 #endif
384 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
385     icd.add_instance_extensions({"VK_KHR_surface", "VK_KHR_wayland_surface"});
386 #endif
387 #ifdef VK_USE_PLATFORM_WIN32_KHR
388     icd.add_instance_extensions({"VK_KHR_surface", "VK_KHR_win32_surface"});
389 #endif
390 }
setup_WSI_in_create_instance(InstWrapper & inst)391 void setup_WSI_in_create_instance(InstWrapper& inst) {
392 #ifdef VK_USE_PLATFORM_ANDROID_KHR
393     inst.create_info.add_extensions({"VK_KHR_surface", "VK_KHR_android_surface"});
394 #endif
395 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
396     inst.create_info.add_extensions({"VK_KHR_surface", "VK_EXT_directfb_surface"});
397 #endif
398 #ifdef VK_USE_PLATFORM_FUCHSIA
399     inst.create_info.add_extensions({"VK_KHR_surface", "VK_FUCHSIA_imagepipe_surface"});
400 #endif
401 #ifdef VK_USE_PLATFORM_GGP
402     inst.create_info.add_extensions({"VK_KHR_surface", "VK_GGP_stream_descriptor_surface"});
403 #endif
404 #ifdef VK_USE_PLATFORM_IOS_MVK
405     inst.create_info.add_extensions({"VK_KHR_surface", "VK_MVK_ios_surface"});
406 #endif
407 #ifdef VK_USE_PLATFORM_MACOS_MVK
408     inst.create_info.add_extensions({"VK_KHR_surface", "VK_MVK_macos_surface"});
409 #endif
410 #ifdef VK_USE_PLATFORM_METAL_EXT
411     inst.create_info.add_extensions({"VK_KHR_surface", "VK_EXT_metal_surface"});
412 #endif
413 #ifdef VK_USE_PLATFORM_SCREEN_QNX
414     inst.create_info.add_extensions({"VK_KHR_surface", "VK_QNX_screen_surface"});
415 #endif
416 #ifdef VK_USE_PLATFORM_VI_NN
417     inst.create_info.add_extensions({"VK_KHR_surface", "VK_NN_vi_surface"});
418 #endif
419 #ifdef VK_USE_PLATFORM_XCB_KHR
420     inst.create_info.add_extensions({"VK_KHR_surface", "VK_KHR_xcb_surface"});
421 #endif
422 #ifdef VK_USE_PLATFORM_XLIB_KHR
423     inst.create_info.add_extensions({"VK_KHR_surface", "VK_KHR_xlib_surface"});
424 #endif
425 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
426     inst.create_info.add_extensions({"VK_KHR_surface", "VK_KHR_wayland_surface"});
427 #endif
428 #ifdef VK_USE_PLATFORM_WIN32_KHR
429     inst.create_info.add_extensions({"VK_KHR_surface", "VK_KHR_win32_surface"});
430 #endif
431 }
create_surface(InstWrapper & inst,const char * api_selection)432 VkSurfaceKHR create_surface(InstWrapper& inst, const char* api_selection) {
433     VkSurfaceKHR surface{};
434 #ifdef VK_USE_PLATFORM_ANDROID_KHR
435     PFN_vkCreateAndroidSurfaceKHR pfn_CreateSurface = inst.load("vkCreateAndroidSurfaceKHR");
436     VkAndroidSurfaceCreateInfoKHR surf_create_info{};
437     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
438 #endif
439 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
440     PFN_vkCreateDirectFBSurfaceEXT pfn_CreateSurface = inst.load("vkCreateDirectFBSurfaceEXT");
441     VkDirectFBSurfaceCreateInfoEXT surf_create_info{};
442     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
443 #endif
444 #ifdef VK_USE_PLATFORM_FUCHSIA
445     PFN_vkCreateImagePipeSurfaceFUCHSIA pfn_CreateSurface = inst.load("vkCreateImagePipeSurfaceFUCHSIA");
446     VkImagePipeSurfaceCreateInfoFUCHSIA surf_create_info{};
447     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
448 #endif
449 #ifdef VK_USE_PLATFORM_GGP
450     PFN__vkCreateStreamDescriptorSurfaceGGP pfn_CreateSurface = inst.load("vkCreateStreamDescriptorSurfaceGGP");
451     VkStreamDescriptorSurfaceCreateInfoGGP surf_create_info{};
452     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
453 #endif
454 #ifdef VK_USE_PLATFORM_IOS_MVK
455     PFN_vkCreateIOSSurfaceMVK pfn_CreateSurface = inst.load("vkCreateIOSSurfaceMVK");
456     VkIOSSurfaceCreateInfoMVK surf_create_info{};
457     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
458 #endif
459 #ifdef VK_USE_PLATFORM_MACOS_MVK
460     if (string_eq(api_selection, "VK_USE_PLATFORM_MACOS_MVK")) {
461         PFN_vkCreateMacOSSurfaceMVK pfn_CreateSurface = inst.load("vkCreateMacOSSurfaceMVK");
462         VkMacOSSurfaceCreateInfoMVK surf_create_info{};
463         EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
464     }
465 #endif
466 #ifdef VK_USE_PLATFORM_METAL_EXT
467     if (string_eq(api_selection, "VK_USE_PLATFORM_METAL_EXT")) {
468         PFN_vkCreateMetalSurfaceEXT pfn_CreateSurface = inst.load("vkCreateMetalSurfaceEXT");
469         VkMetalSurfaceCreateInfoEXT surf_create_info{};
470         EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
471     }
472 #endif
473 #ifdef VK_USE_PLATFORM_SCREEN_QNX
474     PFN_vkCreateScreenSurfaceQNX pfn_CreateSurface = inst.load("vkCreateScreenSurfaceQNX");
475     VkScreenSurfaceCreateInfoQNX surf_create_info{};
476     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
477 #endif
478 #ifdef VK_USE_PLATFORM_VI_NN
479     PFN_vkCreateViSurfaceNN pfn_CreateSurface = inst.load("vkCreateViSurfaceNN");
480     VkViSurfaceCreateInfoNN surf_create_info{};
481     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
482 #endif
483 #ifdef VK_USE_PLATFORM_WIN32_KHR
484     PFN_vkCreateWin32SurfaceKHR pfn_CreateSurface = inst.load("vkCreateWin32SurfaceKHR");
485     VkWin32SurfaceCreateInfoKHR surf_create_info{};
486     EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
487 #endif
488 
489 #ifdef VK_USE_PLATFORM_XCB_KHR
490     if (string_eq(api_selection, "VK_USE_PLATFORM_XCB_KHR")) {
491         PFN_vkCreateXcbSurfaceKHR pfn_CreateSurface = inst.load("vkCreateXcbSurfaceKHR");
492         VkXcbSurfaceCreateInfoKHR surf_create_info{};
493         EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
494     }
495 #endif
496 #ifdef VK_USE_PLATFORM_XLIB_KHR
497     if (string_eq(api_selection, "VK_USE_PLATFORM_XLIB_KHR")) {
498         PFN_vkCreateXlibSurfaceKHR pfn_CreateSurface = inst.load("vkCreateXlibSurfaceKHR");
499         VkXlibSurfaceCreateInfoKHR surf_create_info{};
500         EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
501     }
502 #endif
503 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
504     if (string_eq(api_selection, "VK_USE_PLATFORM_WAYLAND_KHR")) {
505         PFN_vkCreateWaylandSurfaceKHR pfn_CreateSurface = inst.load("vkCreateWaylandSurfaceKHR");
506         VkWaylandSurfaceCreateInfoKHR surf_create_info{};
507         EXPECT_EQ(VK_SUCCESS, pfn_CreateSurface(inst, &surf_create_info, nullptr, &surface));
508     }
509 #endif
510 
511     return surface;
512 }
513 
514 extern "C" {
__ubsan_on_report()515 void __ubsan_on_report() { FAIL() << "Encountered an undefined behavior sanitizer error"; }
__asan_on_error()516 void __asan_on_error() { FAIL() << "Encountered an address sanitizer error"; }
__tsan_on_report()517 void __tsan_on_report() { FAIL() << "Encountered a thread sanitizer error"; }
518 }  // extern "C"
519