15db71995Sopenharmony_ci/* 25db71995Sopenharmony_ci * Copyright (c) 2021-2022 The Khronos Group Inc. 35db71995Sopenharmony_ci * Copyright (c) 2021-2022 Valve Corporation 45db71995Sopenharmony_ci * Copyright (c) 2021-2022 LunarG, Inc. 55db71995Sopenharmony_ci * 65db71995Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 75db71995Sopenharmony_ci * of this software and/or associated documentation files (the "Materials"), to 85db71995Sopenharmony_ci * deal in the Materials without restriction, including without limitation the 95db71995Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 105db71995Sopenharmony_ci * sell copies of the Materials, and to permit persons to whom the Materials are 115db71995Sopenharmony_ci * furnished to do so, subject to the following conditions: 125db71995Sopenharmony_ci * 135db71995Sopenharmony_ci * The above copyright notice(s) and this permission notice shall be included in 145db71995Sopenharmony_ci * all copies or substantial portions of the Materials. 155db71995Sopenharmony_ci * 165db71995Sopenharmony_ci * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 175db71995Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 185db71995Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 195db71995Sopenharmony_ci * 205db71995Sopenharmony_ci * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 215db71995Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 225db71995Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE 235db71995Sopenharmony_ci * USE OR OTHER DEALINGS IN THE MATERIALS. 245db71995Sopenharmony_ci * 255db71995Sopenharmony_ci * Author: Charles Giessen <charles@lunarg.com> 265db71995Sopenharmony_ci * Author: Mark Young <marky@lunarg.com> 275db71995Sopenharmony_ci */ 285db71995Sopenharmony_ci 295db71995Sopenharmony_ci#include "test_environment.h" 305db71995Sopenharmony_ci 315db71995Sopenharmony_ci// These tests are all instance extension tests that touch physical devices. This was 325db71995Sopenharmony_ci// before the idea that physical device extensions were more appropriately found in the 335db71995Sopenharmony_ci// list of device extensions. Because of that, all these tests need to support devices 345db71995Sopenharmony_ci// that don't support the extension and have a fallback path in the loader that needs 355db71995Sopenharmony_ci// validation. 365db71995Sopenharmony_ci 375db71995Sopenharmony_ci// Fill in random but valid data into the device properties struct for the current physical device 385db71995Sopenharmony_civoid FillInRandomICDInfo(uint32_t& vendor_id, uint32_t& driver_vers) { 395db71995Sopenharmony_ci vendor_id = VK_MAKE_API_VERSION(0, rand() % 64, rand() % 255, rand() % 255); 405db71995Sopenharmony_ci driver_vers = VK_MAKE_API_VERSION(0, rand() % 64, rand() % 255, rand() % 255); 415db71995Sopenharmony_ci} 425db71995Sopenharmony_ci 435db71995Sopenharmony_ci// Fill in random but valid data into the device properties struct for the current physical device 445db71995Sopenharmony_civoid FillInRandomDeviceProps(VkPhysicalDeviceProperties& props, uint32_t api_vers, uint32_t vendor, uint32_t driver_vers) { 455db71995Sopenharmony_ci props.apiVersion = api_vers; 465db71995Sopenharmony_ci props.driverVersion = driver_vers; 475db71995Sopenharmony_ci props.vendorID = vendor; 485db71995Sopenharmony_ci props.deviceID = (static_cast<uint32_t>(rand()) >> 4) + (static_cast<uint32_t>(rand()) << 2); 495db71995Sopenharmony_ci props.deviceType = static_cast<VkPhysicalDeviceType>(rand() % 5); 505db71995Sopenharmony_ci for (uint8_t idx = 0; idx < VK_UUID_SIZE; ++idx) { 515db71995Sopenharmony_ci props.pipelineCacheUUID[idx] = static_cast<uint8_t>(rand() % 255); 525db71995Sopenharmony_ci } 535db71995Sopenharmony_ci} 545db71995Sopenharmony_ci 555db71995Sopenharmony_ci// 565db71995Sopenharmony_ci// VK_KHR_get_physical_device_properties2 575db71995Sopenharmony_ci// 585db71995Sopenharmony_ci 595db71995Sopenharmony_ci// Test vkGetPhysicalDeviceProperties2KHR where nothing supports it. 605db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevProps2KHRNoSupport) { 615db71995Sopenharmony_ci FrameworkEnvironment env{}; 625db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 635db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 645db71995Sopenharmony_ci 655db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 665db71995Sopenharmony_ci instance.CheckCreate(); 675db71995Sopenharmony_ci 685db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2KHR GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2KHR"); 695db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevProps2, nullptr); 705db71995Sopenharmony_ci} 715db71995Sopenharmony_ci 725db71995Sopenharmony_ci// Test vkGetPhysicalDeviceProperties2KHR where instance supports it, but nothing else. 735db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevProps2KHRNoICDSupport) { 745db71995Sopenharmony_ci FrameworkEnvironment env{}; 755db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 765db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 775db71995Sopenharmony_ci 785db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 795db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 805db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 815db71995Sopenharmony_ci 825db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2KHR GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2KHR"); 835db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevProps2, nullptr); 845db71995Sopenharmony_ci} 855db71995Sopenharmony_ci 865db71995Sopenharmony_ci// Test vkGetPhysicalDeviceProperties2KHR where instance and ICD supports it, but device does not support it. 875db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevProps2KHRInstanceAndICDSupport) { 885db71995Sopenharmony_ci FrameworkEnvironment env{}; 895db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 905db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 915db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 925db71995Sopenharmony_ci FillInRandomDeviceProps(env.get_test_icd(0).physical_devices.back().properties, VK_API_VERSION_1_0, 5, 123); 935db71995Sopenharmony_ci 945db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 955db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 965db71995Sopenharmony_ci instance.CheckCreate(); 975db71995Sopenharmony_ci 985db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2KHR GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2KHR"); 995db71995Sopenharmony_ci ASSERT_NE(GetPhysDevProps2, nullptr); 1005db71995Sopenharmony_ci 1015db71995Sopenharmony_ci uint32_t driver_count = 1; 1025db71995Sopenharmony_ci VkPhysicalDevice physical_device; 1035db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 1045db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 1055db71995Sopenharmony_ci 1065db71995Sopenharmony_ci VkPhysicalDeviceProperties props{}; 1075db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_device, &props); 1085db71995Sopenharmony_ci VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR}; 1095db71995Sopenharmony_ci GetPhysDevProps2(physical_device, &props2); 1105db71995Sopenharmony_ci 1115db71995Sopenharmony_ci // Both properties should match 1125db71995Sopenharmony_ci ASSERT_EQ(props.apiVersion, props2.properties.apiVersion); 1135db71995Sopenharmony_ci ASSERT_EQ(props.driverVersion, props2.properties.driverVersion); 1145db71995Sopenharmony_ci ASSERT_EQ(props.vendorID, props2.properties.vendorID); 1155db71995Sopenharmony_ci ASSERT_EQ(props.deviceID, props2.properties.deviceID); 1165db71995Sopenharmony_ci ASSERT_EQ(props.deviceType, props2.properties.deviceType); 1175db71995Sopenharmony_ci ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE)); 1185db71995Sopenharmony_ci} 1195db71995Sopenharmony_ci 1205db71995Sopenharmony_ci// Test vkGetPhysicalDeviceProperties2 where instance supports, an ICD, and a device under that ICD 1215db71995Sopenharmony_ci// also support, so everything should work and return properly. 1225db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 1235db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevProps2Simple) { 1245db71995Sopenharmony_ci FrameworkEnvironment env{}; 1255db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_1)); 1265db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 1275db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 1285db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 1295db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 1305db71995Sopenharmony_ci FillInRandomDeviceProps(env.get_test_icd(0).physical_devices.back().properties, VK_API_VERSION_1_1, 5, 123); 1315db71995Sopenharmony_ci { 1325db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 1335db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 1345db71995Sopenharmony_ci instance.CheckCreate(); 1355db71995Sopenharmony_ci 1365db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2"); 1375db71995Sopenharmony_ci ASSERT_NE(GetPhysDevProps2, nullptr); 1385db71995Sopenharmony_ci 1395db71995Sopenharmony_ci uint32_t driver_count = 1; 1405db71995Sopenharmony_ci VkPhysicalDevice physical_device; 1415db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 1425db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 1435db71995Sopenharmony_ci 1445db71995Sopenharmony_ci VkPhysicalDeviceProperties props{}; 1455db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_device, &props); 1465db71995Sopenharmony_ci VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR}; 1475db71995Sopenharmony_ci GetPhysDevProps2(physical_device, &props2); 1485db71995Sopenharmony_ci 1495db71995Sopenharmony_ci // Both properties should match 1505db71995Sopenharmony_ci ASSERT_EQ(props.apiVersion, props2.properties.apiVersion); 1515db71995Sopenharmony_ci ASSERT_EQ(props.driverVersion, props2.properties.driverVersion); 1525db71995Sopenharmony_ci ASSERT_EQ(props.vendorID, props2.properties.vendorID); 1535db71995Sopenharmony_ci ASSERT_EQ(props.deviceID, props2.properties.deviceID); 1545db71995Sopenharmony_ci ASSERT_EQ(props.deviceType, props2.properties.deviceType); 1555db71995Sopenharmony_ci ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE)); 1565db71995Sopenharmony_ci } 1575db71995Sopenharmony_ci 1585db71995Sopenharmony_ci { // Do the same logic but have the application forget to use 1.1 and doesn't enable the extension - should emulate the call 1595db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 1605db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 1615db71995Sopenharmony_ci instance.CheckCreate(); 1625db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 1635db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 1645db71995Sopenharmony_ci 1655db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2"); 1665db71995Sopenharmony_ci ASSERT_NE(GetPhysDevProps2, nullptr); 1675db71995Sopenharmony_ci 1685db71995Sopenharmony_ci uint32_t driver_count = 1; 1695db71995Sopenharmony_ci VkPhysicalDevice physical_device; 1705db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 1715db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 1725db71995Sopenharmony_ci 1735db71995Sopenharmony_ci VkPhysicalDeviceProperties props{}; 1745db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_device, &props); 1755db71995Sopenharmony_ci VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR}; 1765db71995Sopenharmony_ci GetPhysDevProps2(physical_device, &props2); 1775db71995Sopenharmony_ci 1785db71995Sopenharmony_ci // Both properties should match 1795db71995Sopenharmony_ci ASSERT_EQ(props.apiVersion, props2.properties.apiVersion); 1805db71995Sopenharmony_ci ASSERT_EQ(props.driverVersion, props2.properties.driverVersion); 1815db71995Sopenharmony_ci ASSERT_EQ(props.vendorID, props2.properties.vendorID); 1825db71995Sopenharmony_ci ASSERT_EQ(props.deviceID, props2.properties.deviceID); 1835db71995Sopenharmony_ci ASSERT_EQ(props.deviceType, props2.properties.deviceType); 1845db71995Sopenharmony_ci ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE)); 1855db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 1865db71995Sopenharmony_ci } 1875db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 1885db71995Sopenharmony_ci .set_name("modify_api_version_layer") 1895db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 1905db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 1915db71995Sopenharmony_ci "modify_api_version_layer.json"); 1925db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 1935db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 1945db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 1955db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 1965db71995Sopenharmony_ci instance.CheckCreate(); 1975db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 1985db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 1995db71995Sopenharmony_ci 2005db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2"); 2015db71995Sopenharmony_ci ASSERT_NE(GetPhysDevProps2, nullptr); 2025db71995Sopenharmony_ci 2035db71995Sopenharmony_ci uint32_t driver_count = 1; 2045db71995Sopenharmony_ci VkPhysicalDevice physical_device; 2055db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 2065db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 2075db71995Sopenharmony_ci 2085db71995Sopenharmony_ci VkPhysicalDeviceProperties props{}; 2095db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_device, &props); 2105db71995Sopenharmony_ci VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR}; 2115db71995Sopenharmony_ci GetPhysDevProps2(physical_device, &props2); 2125db71995Sopenharmony_ci 2135db71995Sopenharmony_ci // Both properties should match 2145db71995Sopenharmony_ci ASSERT_EQ(props.apiVersion, props2.properties.apiVersion); 2155db71995Sopenharmony_ci ASSERT_EQ(props.driverVersion, props2.properties.driverVersion); 2165db71995Sopenharmony_ci ASSERT_EQ(props.vendorID, props2.properties.vendorID); 2175db71995Sopenharmony_ci ASSERT_EQ(props.deviceID, props2.properties.deviceID); 2185db71995Sopenharmony_ci ASSERT_EQ(props.deviceType, props2.properties.deviceType); 2195db71995Sopenharmony_ci ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE)); 2205db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 2215db71995Sopenharmony_ci } 2225db71995Sopenharmony_ci} 2235db71995Sopenharmony_ci 2245db71995Sopenharmony_ci// Test vkGetPhysicalDeviceProperties2 and vkGetPhysicalDeviceProperties2KHR where ICD is 1.0 and supports 2255db71995Sopenharmony_ci// extension but the instance supports 1.1 and the extension 2265db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevProps2KHRInstanceSupports11) { 2275db71995Sopenharmony_ci FrameworkEnvironment env{}; 2285db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_0)); 2295db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 2305db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 2315db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 2325db71995Sopenharmony_ci FillInRandomDeviceProps(env.get_test_icd(0).physical_devices.back().properties, VK_API_VERSION_1_0, 5, 123); 2335db71995Sopenharmony_ci 2345db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 2355db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 2365db71995Sopenharmony_ci instance.create_info.add_extensions( 2375db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 2385db71995Sopenharmony_ci instance.CheckCreate(); 2395db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 2405db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 2415db71995Sopenharmony_ci 2425db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2"); 2435db71995Sopenharmony_ci ASSERT_NE(GetPhysDevProps2, nullptr); 2445db71995Sopenharmony_ci 2455db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2KHR = instance.load("vkGetPhysicalDeviceProperties2KHR"); 2465db71995Sopenharmony_ci ASSERT_NE(GetPhysDevProps2KHR, nullptr); 2475db71995Sopenharmony_ci 2485db71995Sopenharmony_ci uint32_t driver_count = 1; 2495db71995Sopenharmony_ci VkPhysicalDevice physical_device; 2505db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 2515db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 2525db71995Sopenharmony_ci 2535db71995Sopenharmony_ci VkPhysicalDeviceProperties props{}; 2545db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_device, &props); 2555db71995Sopenharmony_ci VkPhysicalDeviceProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; 2565db71995Sopenharmony_ci GetPhysDevProps2(physical_device, &props2); 2575db71995Sopenharmony_ci 2585db71995Sopenharmony_ci // Both VkPhysicalDeviceProperties2 properties should match 2595db71995Sopenharmony_ci ASSERT_EQ(props.apiVersion, props2.properties.apiVersion); 2605db71995Sopenharmony_ci ASSERT_EQ(props.driverVersion, props2.properties.driverVersion); 2615db71995Sopenharmony_ci ASSERT_EQ(props.vendorID, props2.properties.vendorID); 2625db71995Sopenharmony_ci ASSERT_EQ(props.deviceID, props2.properties.deviceID); 2635db71995Sopenharmony_ci ASSERT_EQ(props.deviceType, props2.properties.deviceType); 2645db71995Sopenharmony_ci ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE)); 2655db71995Sopenharmony_ci 2665db71995Sopenharmony_ci VkPhysicalDeviceProperties2KHR props2KHR{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR}; 2675db71995Sopenharmony_ci GetPhysDevProps2(physical_device, &props2KHR); 2685db71995Sopenharmony_ci 2695db71995Sopenharmony_ci // Both VkPhysicalDeviceProperties2KHR properties should match 2705db71995Sopenharmony_ci ASSERT_EQ(props.apiVersion, props2KHR.properties.apiVersion); 2715db71995Sopenharmony_ci ASSERT_EQ(props.driverVersion, props2KHR.properties.driverVersion); 2725db71995Sopenharmony_ci ASSERT_EQ(props.vendorID, props2KHR.properties.vendorID); 2735db71995Sopenharmony_ci ASSERT_EQ(props.deviceID, props2KHR.properties.deviceID); 2745db71995Sopenharmony_ci ASSERT_EQ(props.deviceType, props2KHR.properties.deviceType); 2755db71995Sopenharmony_ci ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2KHR.properties.pipelineCacheUUID, VK_UUID_SIZE)); 2765db71995Sopenharmony_ci 2775db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 2785db71995Sopenharmony_ci} 2795db71995Sopenharmony_ci 2805db71995Sopenharmony_ci// Test vkGetPhysicalDeviceProperties2 where instance supports it with some ICDs that both support 2815db71995Sopenharmony_ci// and don't support it: 2825db71995Sopenharmony_ci// ICD 0 supports 2835db71995Sopenharmony_ci// Physical device 0 does not 2845db71995Sopenharmony_ci// Physical device 1 does 2855db71995Sopenharmony_ci// Physical device 2 does not 2865db71995Sopenharmony_ci// ICD 1 doesn't support 2875db71995Sopenharmony_ci// Physical device 3 does not 2885db71995Sopenharmony_ci// ICD 2 supports 2895db71995Sopenharmony_ci// Physical device 4 does not 2905db71995Sopenharmony_ci// Physical device 5 does not 2915db71995Sopenharmony_ci// ICD 3 supports 2925db71995Sopenharmony_ci// Physical device 6 does 2935db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevProps2Mixed) { 2945db71995Sopenharmony_ci FrameworkEnvironment env{}; 2955db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 2965db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 2975db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 2985db71995Sopenharmony_ci 2995db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 3005db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 3015db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 3025db71995Sopenharmony_ci 3035db71995Sopenharmony_ci // ICD 1 should not have 1.1 3045db71995Sopenharmony_ci if (icd != 1) { 3055db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 3065db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 3075db71995Sopenharmony_ci } 3085db71995Sopenharmony_ci 3095db71995Sopenharmony_ci uint32_t rand_vendor_id; 3105db71995Sopenharmony_ci uint32_t rand_driver_vers; 3115db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 3125db71995Sopenharmony_ci 3135db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 3145db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 3155db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 3165db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 3175db71995Sopenharmony_ci 3185db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 3195db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 3205db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 3215db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 3225db71995Sopenharmony_ci } 3235db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 3245db71995Sopenharmony_ci } 3255db71995Sopenharmony_ci } 3265db71995Sopenharmony_ci 3275db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 3285db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 3295db71995Sopenharmony_ci instance.CheckCreate(); 3305db71995Sopenharmony_ci 3315db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2"); 3325db71995Sopenharmony_ci ASSERT_NE(GetPhysDevProps2, nullptr); 3335db71995Sopenharmony_ci 3345db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 3355db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 3365db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 3375db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 3385db71995Sopenharmony_ci 3395db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 3405db71995Sopenharmony_ci VkPhysicalDeviceProperties props{}; 3415db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &props); 3425db71995Sopenharmony_ci VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; 3435db71995Sopenharmony_ci GetPhysDevProps2(physical_devices[dev], &props2); 3445db71995Sopenharmony_ci 3455db71995Sopenharmony_ci // Both properties should match 3465db71995Sopenharmony_ci ASSERT_EQ(props.apiVersion, props2.properties.apiVersion); 3475db71995Sopenharmony_ci ASSERT_EQ(props.driverVersion, props2.properties.driverVersion); 3485db71995Sopenharmony_ci ASSERT_EQ(props.vendorID, props2.properties.vendorID); 3495db71995Sopenharmony_ci ASSERT_EQ(props.deviceID, props2.properties.deviceID); 3505db71995Sopenharmony_ci ASSERT_EQ(props.deviceType, props2.properties.deviceType); 3515db71995Sopenharmony_ci ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE)); 3525db71995Sopenharmony_ci } 3535db71995Sopenharmony_ci} 3545db71995Sopenharmony_ci 3555db71995Sopenharmony_ci// Fill in random but valid data into the features struct for the current physical device 3565db71995Sopenharmony_civoid FillInRandomFeatures(VkPhysicalDeviceFeatures& feats) { 3575db71995Sopenharmony_ci feats.robustBufferAccess = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3585db71995Sopenharmony_ci feats.fullDrawIndexUint32 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3595db71995Sopenharmony_ci feats.imageCubeArray = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3605db71995Sopenharmony_ci feats.independentBlend = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3615db71995Sopenharmony_ci feats.geometryShader = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3625db71995Sopenharmony_ci feats.tessellationShader = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3635db71995Sopenharmony_ci feats.sampleRateShading = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3645db71995Sopenharmony_ci feats.dualSrcBlend = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3655db71995Sopenharmony_ci feats.logicOp = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3665db71995Sopenharmony_ci feats.multiDrawIndirect = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3675db71995Sopenharmony_ci feats.drawIndirectFirstInstance = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3685db71995Sopenharmony_ci feats.depthClamp = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3695db71995Sopenharmony_ci feats.depthBiasClamp = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3705db71995Sopenharmony_ci feats.fillModeNonSolid = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3715db71995Sopenharmony_ci feats.depthBounds = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3725db71995Sopenharmony_ci feats.wideLines = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3735db71995Sopenharmony_ci feats.largePoints = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3745db71995Sopenharmony_ci feats.alphaToOne = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3755db71995Sopenharmony_ci feats.multiViewport = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3765db71995Sopenharmony_ci feats.samplerAnisotropy = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3775db71995Sopenharmony_ci feats.textureCompressionETC2 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3785db71995Sopenharmony_ci feats.textureCompressionASTC_LDR = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3795db71995Sopenharmony_ci feats.textureCompressionBC = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3805db71995Sopenharmony_ci feats.occlusionQueryPrecise = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3815db71995Sopenharmony_ci feats.pipelineStatisticsQuery = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3825db71995Sopenharmony_ci feats.vertexPipelineStoresAndAtomics = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3835db71995Sopenharmony_ci feats.fragmentStoresAndAtomics = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3845db71995Sopenharmony_ci feats.shaderTessellationAndGeometryPointSize = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3855db71995Sopenharmony_ci feats.shaderImageGatherExtended = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3865db71995Sopenharmony_ci feats.shaderStorageImageExtendedFormats = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3875db71995Sopenharmony_ci feats.shaderStorageImageMultisample = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3885db71995Sopenharmony_ci feats.shaderStorageImageReadWithoutFormat = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3895db71995Sopenharmony_ci feats.shaderStorageImageWriteWithoutFormat = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3905db71995Sopenharmony_ci feats.shaderUniformBufferArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3915db71995Sopenharmony_ci feats.shaderSampledImageArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3925db71995Sopenharmony_ci feats.shaderStorageBufferArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3935db71995Sopenharmony_ci feats.shaderStorageImageArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3945db71995Sopenharmony_ci feats.shaderClipDistance = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3955db71995Sopenharmony_ci feats.shaderCullDistance = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3965db71995Sopenharmony_ci feats.shaderFloat64 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3975db71995Sopenharmony_ci feats.shaderInt64 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3985db71995Sopenharmony_ci feats.shaderInt16 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 3995db71995Sopenharmony_ci feats.shaderResourceResidency = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4005db71995Sopenharmony_ci feats.shaderResourceMinLod = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4015db71995Sopenharmony_ci feats.sparseBinding = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4025db71995Sopenharmony_ci feats.sparseResidencyBuffer = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4035db71995Sopenharmony_ci feats.sparseResidencyImage2D = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4045db71995Sopenharmony_ci feats.sparseResidencyImage3D = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4055db71995Sopenharmony_ci feats.sparseResidency2Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4065db71995Sopenharmony_ci feats.sparseResidency4Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4075db71995Sopenharmony_ci feats.sparseResidency8Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4085db71995Sopenharmony_ci feats.sparseResidency16Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4095db71995Sopenharmony_ci feats.sparseResidencyAliased = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4105db71995Sopenharmony_ci feats.variableMultisampleRate = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4115db71995Sopenharmony_ci feats.inheritedQueries = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE; 4125db71995Sopenharmony_ci} 4135db71995Sopenharmony_ci 4145db71995Sopenharmony_ci// Compare the contents of the feature structs 4155db71995Sopenharmony_cibool CompareFeatures(const VkPhysicalDeviceFeatures& feats1, const VkPhysicalDeviceFeatures2& feats2) { 4165db71995Sopenharmony_ci return feats1.robustBufferAccess == feats2.features.robustBufferAccess && 4175db71995Sopenharmony_ci feats1.fullDrawIndexUint32 == feats2.features.fullDrawIndexUint32 && 4185db71995Sopenharmony_ci feats1.imageCubeArray == feats2.features.imageCubeArray && feats1.independentBlend == feats2.features.independentBlend && 4195db71995Sopenharmony_ci feats1.geometryShader == feats2.features.geometryShader && 4205db71995Sopenharmony_ci feats1.tessellationShader == feats2.features.tessellationShader && 4215db71995Sopenharmony_ci feats1.sampleRateShading == feats2.features.sampleRateShading && feats1.dualSrcBlend == feats2.features.dualSrcBlend && 4225db71995Sopenharmony_ci feats1.logicOp == feats2.features.logicOp && feats1.multiDrawIndirect == feats2.features.multiDrawIndirect && 4235db71995Sopenharmony_ci feats1.drawIndirectFirstInstance == feats2.features.drawIndirectFirstInstance && 4245db71995Sopenharmony_ci feats1.depthClamp == feats2.features.depthClamp && feats1.depthBiasClamp == feats2.features.depthBiasClamp && 4255db71995Sopenharmony_ci feats1.fillModeNonSolid == feats2.features.fillModeNonSolid && feats1.depthBounds == feats2.features.depthBounds && 4265db71995Sopenharmony_ci feats1.wideLines == feats2.features.wideLines && feats1.largePoints == feats2.features.largePoints && 4275db71995Sopenharmony_ci feats1.alphaToOne == feats2.features.alphaToOne && feats1.multiViewport == feats2.features.multiViewport && 4285db71995Sopenharmony_ci feats1.samplerAnisotropy == feats2.features.samplerAnisotropy && 4295db71995Sopenharmony_ci feats1.textureCompressionETC2 == feats2.features.textureCompressionETC2 && 4305db71995Sopenharmony_ci feats1.textureCompressionASTC_LDR == feats2.features.textureCompressionASTC_LDR && 4315db71995Sopenharmony_ci feats1.textureCompressionBC == feats2.features.textureCompressionBC && 4325db71995Sopenharmony_ci feats1.occlusionQueryPrecise == feats2.features.occlusionQueryPrecise && 4335db71995Sopenharmony_ci feats1.pipelineStatisticsQuery == feats2.features.pipelineStatisticsQuery && 4345db71995Sopenharmony_ci feats1.vertexPipelineStoresAndAtomics == feats2.features.vertexPipelineStoresAndAtomics && 4355db71995Sopenharmony_ci feats1.fragmentStoresAndAtomics == feats2.features.fragmentStoresAndAtomics && 4365db71995Sopenharmony_ci feats1.shaderTessellationAndGeometryPointSize == feats2.features.shaderTessellationAndGeometryPointSize && 4375db71995Sopenharmony_ci feats1.shaderImageGatherExtended == feats2.features.shaderImageGatherExtended && 4385db71995Sopenharmony_ci feats1.shaderStorageImageExtendedFormats == feats2.features.shaderStorageImageExtendedFormats && 4395db71995Sopenharmony_ci feats1.shaderStorageImageMultisample == feats2.features.shaderStorageImageMultisample && 4405db71995Sopenharmony_ci feats1.shaderStorageImageReadWithoutFormat == feats2.features.shaderStorageImageReadWithoutFormat && 4415db71995Sopenharmony_ci feats1.shaderStorageImageWriteWithoutFormat == feats2.features.shaderStorageImageWriteWithoutFormat && 4425db71995Sopenharmony_ci feats1.shaderUniformBufferArrayDynamicIndexing == feats2.features.shaderUniformBufferArrayDynamicIndexing && 4435db71995Sopenharmony_ci feats1.shaderSampledImageArrayDynamicIndexing == feats2.features.shaderSampledImageArrayDynamicIndexing && 4445db71995Sopenharmony_ci feats1.shaderStorageBufferArrayDynamicIndexing == feats2.features.shaderStorageBufferArrayDynamicIndexing && 4455db71995Sopenharmony_ci feats1.shaderStorageImageArrayDynamicIndexing == feats2.features.shaderStorageImageArrayDynamicIndexing && 4465db71995Sopenharmony_ci feats1.shaderClipDistance == feats2.features.shaderClipDistance && 4475db71995Sopenharmony_ci feats1.shaderCullDistance == feats2.features.shaderCullDistance && 4485db71995Sopenharmony_ci feats1.shaderFloat64 == feats2.features.shaderFloat64 && feats1.shaderInt64 == feats2.features.shaderInt64 && 4495db71995Sopenharmony_ci feats1.shaderInt16 == feats2.features.shaderInt16 && 4505db71995Sopenharmony_ci feats1.shaderResourceResidency == feats2.features.shaderResourceResidency && 4515db71995Sopenharmony_ci feats1.shaderResourceMinLod == feats2.features.shaderResourceMinLod && 4525db71995Sopenharmony_ci feats1.sparseBinding == feats2.features.sparseBinding && 4535db71995Sopenharmony_ci feats1.sparseResidencyBuffer == feats2.features.sparseResidencyBuffer && 4545db71995Sopenharmony_ci feats1.sparseResidencyImage2D == feats2.features.sparseResidencyImage2D && 4555db71995Sopenharmony_ci feats1.sparseResidencyImage3D == feats2.features.sparseResidencyImage3D && 4565db71995Sopenharmony_ci feats1.sparseResidency2Samples == feats2.features.sparseResidency2Samples && 4575db71995Sopenharmony_ci feats1.sparseResidency4Samples == feats2.features.sparseResidency4Samples && 4585db71995Sopenharmony_ci feats1.sparseResidency8Samples == feats2.features.sparseResidency8Samples && 4595db71995Sopenharmony_ci feats1.sparseResidency16Samples == feats2.features.sparseResidency16Samples && 4605db71995Sopenharmony_ci feats1.sparseResidencyAliased == feats2.features.sparseResidencyAliased && 4615db71995Sopenharmony_ci feats1.variableMultisampleRate == feats2.features.variableMultisampleRate && 4625db71995Sopenharmony_ci feats1.inheritedQueries == feats2.features.inheritedQueries; 4635db71995Sopenharmony_ci} 4645db71995Sopenharmony_ci 4655db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFeatures2KHR where nothing supports it. 4665db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFeats2KHRNoSupport) { 4675db71995Sopenharmony_ci FrameworkEnvironment env{}; 4685db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 4695db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 4705db71995Sopenharmony_ci 4715db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 4725db71995Sopenharmony_ci instance.CheckCreate(); 4735db71995Sopenharmony_ci 4745db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR"); 4755db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevFeats2KHR, nullptr); 4765db71995Sopenharmony_ci} 4775db71995Sopenharmony_ci 4785db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFeatures2KHR where instance supports it, but nothing else. 4795db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFeatsKHRNoICDSupport) { 4805db71995Sopenharmony_ci FrameworkEnvironment env{}; 4815db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 4825db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 4835db71995Sopenharmony_ci 4845db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 4855db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 4865db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 4875db71995Sopenharmony_ci 4885db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR"); 4895db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevFeats2KHR, nullptr); 4905db71995Sopenharmony_ci} 4915db71995Sopenharmony_ci 4925db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFeatures2KHR where instance and ICD supports it, but device does not support it. 4935db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFeats2KHRInstanceAndICDSupport) { 4945db71995Sopenharmony_ci FrameworkEnvironment env{}; 4955db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 4965db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 4975db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 4985db71995Sopenharmony_ci FillInRandomFeatures(env.get_test_icd(0).physical_devices.back().features); 4995db71995Sopenharmony_ci 5005db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 5015db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 5025db71995Sopenharmony_ci instance.CheckCreate(); 5035db71995Sopenharmony_ci 5045db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR"); 5055db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFeats2KHR, nullptr); 5065db71995Sopenharmony_ci 5075db71995Sopenharmony_ci uint32_t driver_count = 1; 5085db71995Sopenharmony_ci VkPhysicalDevice physical_device; 5095db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 5105db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 5115db71995Sopenharmony_ci 5125db71995Sopenharmony_ci VkPhysicalDeviceFeatures feats{}; 5135db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFeatures(physical_device, &feats); 5145db71995Sopenharmony_ci VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR}; 5155db71995Sopenharmony_ci GetPhysDevFeats2KHR(physical_device, &feats2); 5165db71995Sopenharmony_ci ASSERT_TRUE(CompareFeatures(feats, feats2)); 5175db71995Sopenharmony_ci} 5185db71995Sopenharmony_ci 5195db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFeatures2 where instance supports, an ICD, and a device under that ICD 5205db71995Sopenharmony_ci// also support, so everything should work and return properly. 5215db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 5225db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFeats2Simple) { 5235db71995Sopenharmony_ci FrameworkEnvironment env{}; 5245db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_1)); 5255db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 5265db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 5275db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 5285db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 5295db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().set_api_version(VK_API_VERSION_1_1); 5305db71995Sopenharmony_ci FillInRandomFeatures(env.get_test_icd(0).physical_devices.back().features); 5315db71995Sopenharmony_ci { 5325db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 5335db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 5345db71995Sopenharmony_ci instance.CheckCreate(); 5355db71995Sopenharmony_ci 5365db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2"); 5375db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFeats2, nullptr); 5385db71995Sopenharmony_ci 5395db71995Sopenharmony_ci uint32_t driver_count = 1; 5405db71995Sopenharmony_ci VkPhysicalDevice physical_device; 5415db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 5425db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 5435db71995Sopenharmony_ci 5445db71995Sopenharmony_ci VkPhysicalDeviceFeatures feats{}; 5455db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFeatures(physical_device, &feats); 5465db71995Sopenharmony_ci VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 5475db71995Sopenharmony_ci GetPhysDevFeats2(physical_device, &feats2); 5485db71995Sopenharmony_ci ASSERT_TRUE(CompareFeatures(feats, feats2)); 5495db71995Sopenharmony_ci } 5505db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 5515db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 5525db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 5535db71995Sopenharmony_ci instance.CheckCreate(); 5545db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 5555db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 5565db71995Sopenharmony_ci 5575db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2"); 5585db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFeats2, nullptr); 5595db71995Sopenharmony_ci 5605db71995Sopenharmony_ci uint32_t driver_count = 1; 5615db71995Sopenharmony_ci VkPhysicalDevice physical_device; 5625db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 5635db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 5645db71995Sopenharmony_ci 5655db71995Sopenharmony_ci VkPhysicalDeviceFeatures feats{}; 5665db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFeatures(physical_device, &feats); 5675db71995Sopenharmony_ci VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 5685db71995Sopenharmony_ci GetPhysDevFeats2(physical_device, &feats2); 5695db71995Sopenharmony_ci ASSERT_TRUE(CompareFeatures(feats, feats2)); 5705db71995Sopenharmony_ci 5715db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 5725db71995Sopenharmony_ci } 5735db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 5745db71995Sopenharmony_ci .set_name("modify_api_version_layer") 5755db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 5765db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 5775db71995Sopenharmony_ci "modify_api_version_layer.json"); 5785db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 5795db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 5805db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 5815db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 5825db71995Sopenharmony_ci instance.CheckCreate(); 5835db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 5845db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 5855db71995Sopenharmony_ci 5865db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2"); 5875db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFeats2, nullptr); 5885db71995Sopenharmony_ci 5895db71995Sopenharmony_ci uint32_t driver_count = 1; 5905db71995Sopenharmony_ci VkPhysicalDevice physical_device; 5915db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 5925db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 5935db71995Sopenharmony_ci 5945db71995Sopenharmony_ci VkPhysicalDeviceFeatures feats{}; 5955db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFeatures(physical_device, &feats); 5965db71995Sopenharmony_ci VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 5975db71995Sopenharmony_ci GetPhysDevFeats2(physical_device, &feats2); 5985db71995Sopenharmony_ci ASSERT_TRUE(CompareFeatures(feats, feats2)); 5995db71995Sopenharmony_ci 6005db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 6015db71995Sopenharmony_ci } 6025db71995Sopenharmony_ci} 6035db71995Sopenharmony_ci 6045db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFeatures2 and vkGetPhysicalDeviceFeatures2KHR where ICD is 1.0 and supports 6055db71995Sopenharmony_ci// extension but the instance supports 1.1 and the extension 6065db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFeats2KHRInstanceSupports11) { 6075db71995Sopenharmony_ci FrameworkEnvironment env{}; 6085db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_0)); 6095db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 6105db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 6115db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 6125db71995Sopenharmony_ci FillInRandomFeatures(env.get_test_icd(0).physical_devices.back().features); 6135db71995Sopenharmony_ci 6145db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 6155db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 6165db71995Sopenharmony_ci instance.create_info.add_extensions( 6175db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 6185db71995Sopenharmony_ci instance.CheckCreate(); 6195db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 6205db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 6215db71995Sopenharmony_ci 6225db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR"); 6235db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFeats2KHR, nullptr); 6245db71995Sopenharmony_ci 6255db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2"); 6265db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFeats2, nullptr); 6275db71995Sopenharmony_ci 6285db71995Sopenharmony_ci uint32_t driver_count = 1; 6295db71995Sopenharmony_ci VkPhysicalDevice physical_device; 6305db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 6315db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 6325db71995Sopenharmony_ci 6335db71995Sopenharmony_ci VkPhysicalDeviceFeatures feats{}; 6345db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFeatures(physical_device, &feats); 6355db71995Sopenharmony_ci 6365db71995Sopenharmony_ci VkPhysicalDeviceFeatures2KHR feats2KHR{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR}; 6375db71995Sopenharmony_ci GetPhysDevFeats2KHR(physical_device, &feats2KHR); 6385db71995Sopenharmony_ci ASSERT_TRUE(CompareFeatures(feats, feats2KHR)); 6395db71995Sopenharmony_ci 6405db71995Sopenharmony_ci VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 6415db71995Sopenharmony_ci GetPhysDevFeats2(physical_device, &feats2); 6425db71995Sopenharmony_ci ASSERT_TRUE(CompareFeatures(feats, feats2)); 6435db71995Sopenharmony_ci 6445db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 6455db71995Sopenharmony_ci} 6465db71995Sopenharmony_ci 6475db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFeatures2 where instance supports it with some ICDs that both support 6485db71995Sopenharmony_ci// and don't support it: 6495db71995Sopenharmony_ci// ICD 0 supports 6505db71995Sopenharmony_ci// Physical device 0 does not 6515db71995Sopenharmony_ci// Physical device 1 does 6525db71995Sopenharmony_ci// Physical device 2 does not 6535db71995Sopenharmony_ci// ICD 1 doesn't support 6545db71995Sopenharmony_ci// Physical device 3 does not 6555db71995Sopenharmony_ci// ICD 2 supports 6565db71995Sopenharmony_ci// Physical device 4 does not 6575db71995Sopenharmony_ci// Physical device 5 does not 6585db71995Sopenharmony_ci// ICD 3 supports 6595db71995Sopenharmony_ci// Physical device 6 does 6605db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFeatsMixed) { 6615db71995Sopenharmony_ci FrameworkEnvironment env{}; 6625db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 6635db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 6645db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 6655db71995Sopenharmony_ci 6665db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 6675db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 6685db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 6695db71995Sopenharmony_ci 6705db71995Sopenharmony_ci // ICD 1 should not have 1.1 6715db71995Sopenharmony_ci if (icd != 1) { 6725db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 6735db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 6745db71995Sopenharmony_ci } 6755db71995Sopenharmony_ci 6765db71995Sopenharmony_ci uint32_t rand_vendor_id; 6775db71995Sopenharmony_ci uint32_t rand_driver_vers; 6785db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 6795db71995Sopenharmony_ci 6805db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 6815db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 6825db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 6835db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 6845db71995Sopenharmony_ci 6855db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 6865db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 6875db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 6885db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 6895db71995Sopenharmony_ci } 6905db71995Sopenharmony_ci 6915db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 6925db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 6935db71995Sopenharmony_ci FillInRandomFeatures(cur_dev.features); 6945db71995Sopenharmony_ci } 6955db71995Sopenharmony_ci } 6965db71995Sopenharmony_ci 6975db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 6985db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 6995db71995Sopenharmony_ci instance.CheckCreate(); 7005db71995Sopenharmony_ci 7015db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2"); 7025db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFeats2, nullptr); 7035db71995Sopenharmony_ci 7045db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 7055db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 7065db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 7075db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 7085db71995Sopenharmony_ci 7095db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 7105db71995Sopenharmony_ci VkPhysicalDeviceFeatures feats{}; 7115db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFeatures(physical_devices[dev], &feats); 7125db71995Sopenharmony_ci VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 7135db71995Sopenharmony_ci GetPhysDevFeats2(physical_devices[dev], &feats2); 7145db71995Sopenharmony_ci ASSERT_TRUE(CompareFeatures(feats, feats2)); 7155db71995Sopenharmony_ci } 7165db71995Sopenharmony_ci} 7175db71995Sopenharmony_ci 7185db71995Sopenharmony_ci// Fill in random but valid data into the format properties struct for the current physical device 7195db71995Sopenharmony_civoid FillInRandomFormatProperties(std::vector<VkFormatProperties>& props) { 7205db71995Sopenharmony_ci props.resize(5); 7215db71995Sopenharmony_ci for (uint8_t form = 0; form < 5; ++form) { 7225db71995Sopenharmony_ci props[form].bufferFeatures = static_cast<VkFormatFeatureFlags>(rand()); 7235db71995Sopenharmony_ci props[form].linearTilingFeatures = static_cast<VkFormatFeatureFlags>(rand()); 7245db71995Sopenharmony_ci props[form].optimalTilingFeatures = static_cast<VkFormatFeatureFlags>(rand()); 7255db71995Sopenharmony_ci } 7265db71995Sopenharmony_ci} 7275db71995Sopenharmony_ci 7285db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFormatProperties2KHR where nothing supports it. 7295db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFormatProps2KHRNoSupport) { 7305db71995Sopenharmony_ci FrameworkEnvironment env{}; 7315db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 7325db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 7335db71995Sopenharmony_ci 7345db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 7355db71995Sopenharmony_ci instance.CheckCreate(); 7365db71995Sopenharmony_ci 7375db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR = 7385db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceFormatProperties2KHR"); 7395db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevFormatProps2KHR, nullptr); 7405db71995Sopenharmony_ci} 7415db71995Sopenharmony_ci 7425db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFormatProperties2KHR where instance supports it, but nothing else. 7435db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFormatPropsKHRNoICDSupport) { 7445db71995Sopenharmony_ci FrameworkEnvironment env{}; 7455db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 7465db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 7475db71995Sopenharmony_ci 7485db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 7495db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 7505db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 7515db71995Sopenharmony_ci 7525db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR = 7535db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceFormatProperties2KHR"); 7545db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevFormatProps2KHR, nullptr); 7555db71995Sopenharmony_ci} 7565db71995Sopenharmony_ci 7575db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFormatProperties2KHR where instance and ICD supports it, but device does not support it. 7585db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFormatProps2KHRInstanceAndICDSupport) { 7595db71995Sopenharmony_ci FrameworkEnvironment env{}; 7605db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 7615db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 7625db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 7635db71995Sopenharmony_ci FillInRandomFormatProperties(env.get_test_icd(0).physical_devices.back().format_properties); 7645db71995Sopenharmony_ci 7655db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 7665db71995Sopenharmony_ci instance.create_info.add_extensions( 7675db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 7685db71995Sopenharmony_ci instance.CheckCreate(); 7695db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 7705db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 7715db71995Sopenharmony_ci 7725db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR = 7735db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceFormatProperties2KHR"); 7745db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFormatProps2KHR, nullptr); 7755db71995Sopenharmony_ci 7765db71995Sopenharmony_ci uint32_t driver_count = 1; 7775db71995Sopenharmony_ci VkPhysicalDevice physical_device; 7785db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 7795db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 7805db71995Sopenharmony_ci 7815db71995Sopenharmony_ci VkFormatProperties props{}; 7825db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props); 7835db71995Sopenharmony_ci VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 7845db71995Sopenharmony_ci GetPhysDevFormatProps2KHR(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2); 7855db71995Sopenharmony_ci 7865db71995Sopenharmony_ci ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures); 7875db71995Sopenharmony_ci ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures); 7885db71995Sopenharmony_ci ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures); 7895db71995Sopenharmony_ci} 7905db71995Sopenharmony_ci 7915db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFormatProperties2 where instance supports, an ICD, and a device under that ICD 7925db71995Sopenharmony_ci// also support, so everything should work and return properly. 7935db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 7945db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFormatProps2Simple) { 7955db71995Sopenharmony_ci FrameworkEnvironment env{}; 7965db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_1)); 7975db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 7985db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 7995db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 8005db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 8015db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().set_api_version(VK_API_VERSION_1_1); 8025db71995Sopenharmony_ci FillInRandomFormatProperties(env.get_test_icd(0).physical_devices.back().format_properties); 8035db71995Sopenharmony_ci { 8045db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 8055db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 8065db71995Sopenharmony_ci instance.CheckCreate(); 8075db71995Sopenharmony_ci 8085db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2"); 8095db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFormatProps2, nullptr); 8105db71995Sopenharmony_ci 8115db71995Sopenharmony_ci uint32_t driver_count = 1; 8125db71995Sopenharmony_ci VkPhysicalDevice physical_device; 8135db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 8145db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 8155db71995Sopenharmony_ci 8165db71995Sopenharmony_ci VkFormatProperties props{}; 8175db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props); 8185db71995Sopenharmony_ci VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 8195db71995Sopenharmony_ci GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2); 8205db71995Sopenharmony_ci 8215db71995Sopenharmony_ci ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures); 8225db71995Sopenharmony_ci ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures); 8235db71995Sopenharmony_ci ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures); 8245db71995Sopenharmony_ci } 8255db71995Sopenharmony_ci { // Do the same logic but have the application forget to enable 1.1 and doesn't enable the extension 8265db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 8275db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 8285db71995Sopenharmony_ci instance.CheckCreate(); 8295db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 8305db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 8315db71995Sopenharmony_ci 8325db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2"); 8335db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFormatProps2, nullptr); 8345db71995Sopenharmony_ci 8355db71995Sopenharmony_ci uint32_t driver_count = 1; 8365db71995Sopenharmony_ci VkPhysicalDevice physical_device; 8375db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 8385db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 8395db71995Sopenharmony_ci 8405db71995Sopenharmony_ci VkFormatProperties props{}; 8415db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props); 8425db71995Sopenharmony_ci VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 8435db71995Sopenharmony_ci GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2); 8445db71995Sopenharmony_ci 8455db71995Sopenharmony_ci ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures); 8465db71995Sopenharmony_ci ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures); 8475db71995Sopenharmony_ci ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures); 8485db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 8495db71995Sopenharmony_ci } 8505db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 8515db71995Sopenharmony_ci .set_name("modify_api_version_layer") 8525db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 8535db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 8545db71995Sopenharmony_ci "modify_api_version_layer.json"); 8555db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 8565db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 8575db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 8585db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 8595db71995Sopenharmony_ci instance.CheckCreate(); 8605db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 8615db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 8625db71995Sopenharmony_ci 8635db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2"); 8645db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFormatProps2, nullptr); 8655db71995Sopenharmony_ci 8665db71995Sopenharmony_ci uint32_t driver_count = 1; 8675db71995Sopenharmony_ci VkPhysicalDevice physical_device; 8685db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 8695db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 8705db71995Sopenharmony_ci 8715db71995Sopenharmony_ci VkFormatProperties props{}; 8725db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props); 8735db71995Sopenharmony_ci VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 8745db71995Sopenharmony_ci GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2); 8755db71995Sopenharmony_ci 8765db71995Sopenharmony_ci ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures); 8775db71995Sopenharmony_ci ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures); 8785db71995Sopenharmony_ci ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures); 8795db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 8805db71995Sopenharmony_ci } 8815db71995Sopenharmony_ci} 8825db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFormatProperties2 and vkGetPhysicalDeviceFormatProperties2KHR where ICD is 1.0 and supports 8835db71995Sopenharmony_ci// extension but the instance supports 1.1 and the extension 8845db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFormatProps2KHRInstanceSupports11) { 8855db71995Sopenharmony_ci FrameworkEnvironment env{}; 8865db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 8875db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 8885db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 8895db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 8905db71995Sopenharmony_ci FillInRandomFormatProperties(env.get_test_icd(0).physical_devices.back().format_properties); 8915db71995Sopenharmony_ci 8925db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 8935db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 8945db71995Sopenharmony_ci instance.create_info.add_extensions( 8955db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 8965db71995Sopenharmony_ci instance.CheckCreate(); 8975db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 8985db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 8995db71995Sopenharmony_ci 9005db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2"); 9015db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFormatProps2, nullptr); 9025db71995Sopenharmony_ci 9035db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR = 9045db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceFormatProperties2KHR"); 9055db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFormatProps2KHR, nullptr); 9065db71995Sopenharmony_ci 9075db71995Sopenharmony_ci uint32_t driver_count = 1; 9085db71995Sopenharmony_ci VkPhysicalDevice physical_device; 9095db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 9105db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 9115db71995Sopenharmony_ci 9125db71995Sopenharmony_ci VkFormatProperties props{}; 9135db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props); 9145db71995Sopenharmony_ci VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 9155db71995Sopenharmony_ci GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2); 9165db71995Sopenharmony_ci 9175db71995Sopenharmony_ci ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures); 9185db71995Sopenharmony_ci ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures); 9195db71995Sopenharmony_ci ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures); 9205db71995Sopenharmony_ci 9215db71995Sopenharmony_ci VkFormatProperties2KHR props2KHR{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 9225db71995Sopenharmony_ci GetPhysDevFormatProps2KHR(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2KHR); 9235db71995Sopenharmony_ci 9245db71995Sopenharmony_ci ASSERT_EQ(props.bufferFeatures, props2KHR.formatProperties.bufferFeatures); 9255db71995Sopenharmony_ci ASSERT_EQ(props.linearTilingFeatures, props2KHR.formatProperties.linearTilingFeatures); 9265db71995Sopenharmony_ci ASSERT_EQ(props.optimalTilingFeatures, props2KHR.formatProperties.optimalTilingFeatures); 9275db71995Sopenharmony_ci 9285db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 9295db71995Sopenharmony_ci} 9305db71995Sopenharmony_ci 9315db71995Sopenharmony_ci// Test vkGetPhysicalDeviceFormatProperties2 where instance supports it with some ICDs that both support 9325db71995Sopenharmony_ci// and don't support it: 9335db71995Sopenharmony_ci// ICD 0 supports 9345db71995Sopenharmony_ci// Physical device 0 does not 9355db71995Sopenharmony_ci// Physical device 1 does 9365db71995Sopenharmony_ci// Physical device 2 does not 9375db71995Sopenharmony_ci// ICD 1 doesn't support 9385db71995Sopenharmony_ci// Physical device 3 does not 9395db71995Sopenharmony_ci// ICD 2 supports 9405db71995Sopenharmony_ci// Physical device 4 does not 9415db71995Sopenharmony_ci// Physical device 5 does not 9425db71995Sopenharmony_ci// ICD 3 supports 9435db71995Sopenharmony_ci// Physical device 6 does 9445db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevFormatPropsMixed) { 9455db71995Sopenharmony_ci FrameworkEnvironment env{}; 9465db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 9475db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 9485db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 9495db71995Sopenharmony_ci 9505db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 9515db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 9525db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 9535db71995Sopenharmony_ci 9545db71995Sopenharmony_ci // ICD 1 should not have 1.1 9555db71995Sopenharmony_ci if (icd != 1) { 9565db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 9575db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 9585db71995Sopenharmony_ci } 9595db71995Sopenharmony_ci 9605db71995Sopenharmony_ci uint32_t rand_vendor_id; 9615db71995Sopenharmony_ci uint32_t rand_driver_vers; 9625db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 9635db71995Sopenharmony_ci 9645db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 9655db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 9665db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 9675db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 9685db71995Sopenharmony_ci 9695db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 9705db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 9715db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 9725db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 9735db71995Sopenharmony_ci } 9745db71995Sopenharmony_ci 9755db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 9765db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 9775db71995Sopenharmony_ci FillInRandomFormatProperties(cur_dev.format_properties); 9785db71995Sopenharmony_ci } 9795db71995Sopenharmony_ci } 9805db71995Sopenharmony_ci 9815db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 9825db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 9835db71995Sopenharmony_ci instance.CheckCreate(); 9845db71995Sopenharmony_ci 9855db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2"); 9865db71995Sopenharmony_ci ASSERT_NE(GetPhysDevFormatProps2, nullptr); 9875db71995Sopenharmony_ci 9885db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 9895db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 9905db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 9915db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 9925db71995Sopenharmony_ci 9935db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 9945db71995Sopenharmony_ci VkFormat format = static_cast<VkFormat>((dev + 1) % 5); 9955db71995Sopenharmony_ci VkFormatProperties props{}; 9965db71995Sopenharmony_ci instance->vkGetPhysicalDeviceFormatProperties(physical_devices[dev], format, &props); 9975db71995Sopenharmony_ci VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 9985db71995Sopenharmony_ci GetPhysDevFormatProps2(physical_devices[dev], format, &props2); 9995db71995Sopenharmony_ci 10005db71995Sopenharmony_ci ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures); 10015db71995Sopenharmony_ci ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures); 10025db71995Sopenharmony_ci ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures); 10035db71995Sopenharmony_ci } 10045db71995Sopenharmony_ci} 10055db71995Sopenharmony_ci 10065db71995Sopenharmony_ci// Fill in random but valid data into the image format data struct for the current physical device 10075db71995Sopenharmony_civoid FillInRandomImageFormatData(VkImageFormatProperties& props) { 10085db71995Sopenharmony_ci props.maxExtent = {static_cast<uint32_t>(rand() % 512), static_cast<uint32_t>(rand() % 512), 10095db71995Sopenharmony_ci static_cast<uint32_t>(rand() % 512)}; 10105db71995Sopenharmony_ci props.maxMipLevels = static_cast<uint32_t>(1 << (rand() % 16)); 10115db71995Sopenharmony_ci props.maxArrayLayers = static_cast<uint32_t>(1 << (rand() % 16)); 10125db71995Sopenharmony_ci props.sampleCounts = static_cast<VkSampleCountFlags>(1 << (rand() % 7)); 10135db71995Sopenharmony_ci props.maxResourceSize = static_cast<uint64_t>(rand()); 10145db71995Sopenharmony_ci} 10155db71995Sopenharmony_ci 10165db71995Sopenharmony_ci// Test vkGetPhysicalDeviceImageFormatProperties2KHR where nothing supports it. 10175db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevImageFormatProps2KHRNoSupport) { 10185db71995Sopenharmony_ci FrameworkEnvironment env{}; 10195db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 10205db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 10215db71995Sopenharmony_ci 10225db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 10235db71995Sopenharmony_ci instance.CheckCreate(); 10245db71995Sopenharmony_ci 10255db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysDevImageFormatProps2 = 10265db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2KHR"); 10275db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevImageFormatProps2, nullptr); 10285db71995Sopenharmony_ci} 10295db71995Sopenharmony_ci 10305db71995Sopenharmony_ci// Test vkGetPhysicalDeviceImageFormatProperties2KHR where instance supports it, but nothing else. 10315db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevImageFormatPropsKHRNoICDSupport) { 10325db71995Sopenharmony_ci FrameworkEnvironment env{}; 10335db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 10345db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 10355db71995Sopenharmony_ci 10365db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 10375db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 10385db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 10395db71995Sopenharmony_ci 10405db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysDevImageFormatProps2KHR = 10415db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2KHR"); 10425db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevImageFormatProps2KHR, nullptr); 10435db71995Sopenharmony_ci} 10445db71995Sopenharmony_ci 10455db71995Sopenharmony_ci// Test vkGetPhysicalDeviceImageFormatProperties2KHR where instance and ICD supports it, but device does not support it. 10465db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevImageFormatProps2KHRInstanceAndICDSupport) { 10475db71995Sopenharmony_ci FrameworkEnvironment env{}; 10485db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 10495db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 10505db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 10515db71995Sopenharmony_ci FillInRandomImageFormatData(env.get_test_icd(0).physical_devices.back().image_format_properties); 10525db71995Sopenharmony_ci 10535db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 10545db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 10555db71995Sopenharmony_ci instance.CheckCreate(); 10565db71995Sopenharmony_ci 10575db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysDevImageFormatProps2KHR = 10585db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2KHR"); 10595db71995Sopenharmony_ci ASSERT_NE(GetPhysDevImageFormatProps2KHR, nullptr); 10605db71995Sopenharmony_ci 10615db71995Sopenharmony_ci uint32_t driver_count = 1; 10625db71995Sopenharmony_ci VkPhysicalDevice physical_device; 10635db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 10645db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 10655db71995Sopenharmony_ci 10665db71995Sopenharmony_ci VkImageFormatProperties props{}; 10675db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 10685db71995Sopenharmony_ci instance->vkGetPhysicalDeviceImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 10695db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, 0, 0, &props)); 10705db71995Sopenharmony_ci 10715db71995Sopenharmony_ci VkPhysicalDeviceImageFormatInfo2 info2{ 10725db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, // sType 10735db71995Sopenharmony_ci nullptr, // pNext 10745db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 10755db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 10765db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 10775db71995Sopenharmony_ci 0, // usage 10785db71995Sopenharmony_ci 0, // flags 10795db71995Sopenharmony_ci }; 10805db71995Sopenharmony_ci VkImageFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 10815db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysDevImageFormatProps2KHR(physical_device, &info2, &props2)); 10825db71995Sopenharmony_ci 10835db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.width, props2.imageFormatProperties.maxExtent.width); 10845db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.height, props2.imageFormatProperties.maxExtent.height); 10855db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.depth, props2.imageFormatProperties.maxExtent.depth); 10865db71995Sopenharmony_ci ASSERT_EQ(props.maxMipLevels, props2.imageFormatProperties.maxMipLevels); 10875db71995Sopenharmony_ci ASSERT_EQ(props.maxArrayLayers, props2.imageFormatProperties.maxArrayLayers); 10885db71995Sopenharmony_ci ASSERT_EQ(props.sampleCounts, props2.imageFormatProperties.sampleCounts); 10895db71995Sopenharmony_ci ASSERT_EQ(props.maxResourceSize, props2.imageFormatProperties.maxResourceSize); 10905db71995Sopenharmony_ci} 10915db71995Sopenharmony_ci 10925db71995Sopenharmony_ci// Test vkGetPhysicalDeviceImageFormatProperties2 where instance supports, an ICD, and a device under that ICD 10935db71995Sopenharmony_ci// also support, so everything should work and return properly. 10945db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 10955db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevImageFormatProps2Simple) { 10965db71995Sopenharmony_ci FrameworkEnvironment env{}; 10975db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 10985db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 10995db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 11005db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 11015db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 11025db71995Sopenharmony_ci FillInRandomImageFormatData(env.get_test_icd(0).physical_devices.back().image_format_properties); 11035db71995Sopenharmony_ci { 11045db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 11055db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 11065db71995Sopenharmony_ci instance.CheckCreate(); 11075db71995Sopenharmony_ci 11085db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysDevImageFormatProps2 = 11095db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2"); 11105db71995Sopenharmony_ci ASSERT_NE(GetPhysDevImageFormatProps2, nullptr); 11115db71995Sopenharmony_ci 11125db71995Sopenharmony_ci uint32_t driver_count = 1; 11135db71995Sopenharmony_ci VkPhysicalDevice physical_device; 11145db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 11155db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 11165db71995Sopenharmony_ci 11175db71995Sopenharmony_ci VkImageFormatProperties props{}; 11185db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 11195db71995Sopenharmony_ci instance->vkGetPhysicalDeviceImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 11205db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, 0, 0, &props)); 11215db71995Sopenharmony_ci 11225db71995Sopenharmony_ci VkPhysicalDeviceImageFormatInfo2 info2{ 11235db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, // sType 11245db71995Sopenharmony_ci nullptr, // pNext 11255db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 11265db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 11275db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 11285db71995Sopenharmony_ci 0, // usage 11295db71995Sopenharmony_ci 0, // flags 11305db71995Sopenharmony_ci }; 11315db71995Sopenharmony_ci 11325db71995Sopenharmony_ci VkImageFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 11335db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysDevImageFormatProps2(physical_device, &info2, &props2)); 11345db71995Sopenharmony_ci 11355db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.width, props2.imageFormatProperties.maxExtent.width); 11365db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.height, props2.imageFormatProperties.maxExtent.height); 11375db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.depth, props2.imageFormatProperties.maxExtent.depth); 11385db71995Sopenharmony_ci ASSERT_EQ(props.maxMipLevels, props2.imageFormatProperties.maxMipLevels); 11395db71995Sopenharmony_ci ASSERT_EQ(props.maxArrayLayers, props2.imageFormatProperties.maxArrayLayers); 11405db71995Sopenharmony_ci ASSERT_EQ(props.sampleCounts, props2.imageFormatProperties.sampleCounts); 11415db71995Sopenharmony_ci ASSERT_EQ(props.maxResourceSize, props2.imageFormatProperties.maxResourceSize); 11425db71995Sopenharmony_ci } 11435db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 11445db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 11455db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 11465db71995Sopenharmony_ci instance.CheckCreate(); 11475db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 11485db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 11495db71995Sopenharmony_ci 11505db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysDevImageFormatProps2 = 11515db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2"); 11525db71995Sopenharmony_ci ASSERT_NE(GetPhysDevImageFormatProps2, nullptr); 11535db71995Sopenharmony_ci 11545db71995Sopenharmony_ci uint32_t driver_count = 1; 11555db71995Sopenharmony_ci VkPhysicalDevice physical_device; 11565db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 11575db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 11585db71995Sopenharmony_ci 11595db71995Sopenharmony_ci VkImageFormatProperties props{}; 11605db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 11615db71995Sopenharmony_ci instance->vkGetPhysicalDeviceImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 11625db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, 0, 0, &props)); 11635db71995Sopenharmony_ci 11645db71995Sopenharmony_ci VkPhysicalDeviceImageFormatInfo2 info2{ 11655db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, // sType 11665db71995Sopenharmony_ci nullptr, // pNext 11675db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 11685db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 11695db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 11705db71995Sopenharmony_ci 0, // usage 11715db71995Sopenharmony_ci 0, // flags 11725db71995Sopenharmony_ci }; 11735db71995Sopenharmony_ci 11745db71995Sopenharmony_ci VkImageFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 11755db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysDevImageFormatProps2(physical_device, &info2, &props2)); 11765db71995Sopenharmony_ci 11775db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.width, props2.imageFormatProperties.maxExtent.width); 11785db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.height, props2.imageFormatProperties.maxExtent.height); 11795db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.depth, props2.imageFormatProperties.maxExtent.depth); 11805db71995Sopenharmony_ci ASSERT_EQ(props.maxMipLevels, props2.imageFormatProperties.maxMipLevels); 11815db71995Sopenharmony_ci ASSERT_EQ(props.maxArrayLayers, props2.imageFormatProperties.maxArrayLayers); 11825db71995Sopenharmony_ci ASSERT_EQ(props.sampleCounts, props2.imageFormatProperties.sampleCounts); 11835db71995Sopenharmony_ci ASSERT_EQ(props.maxResourceSize, props2.imageFormatProperties.maxResourceSize); 11845db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 11855db71995Sopenharmony_ci } 11865db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 11875db71995Sopenharmony_ci .set_name("modify_api_version_layer") 11885db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 11895db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 11905db71995Sopenharmony_ci "modify_api_version_layer.json"); 11915db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 11925db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 11935db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 11945db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 11955db71995Sopenharmony_ci instance.CheckCreate(); 11965db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 11975db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 11985db71995Sopenharmony_ci 11995db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysDevImageFormatProps2 = 12005db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2"); 12015db71995Sopenharmony_ci ASSERT_NE(GetPhysDevImageFormatProps2, nullptr); 12025db71995Sopenharmony_ci 12035db71995Sopenharmony_ci uint32_t driver_count = 1; 12045db71995Sopenharmony_ci VkPhysicalDevice physical_device; 12055db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 12065db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 12075db71995Sopenharmony_ci 12085db71995Sopenharmony_ci VkImageFormatProperties props{}; 12095db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 12105db71995Sopenharmony_ci instance->vkGetPhysicalDeviceImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 12115db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, 0, 0, &props)); 12125db71995Sopenharmony_ci 12135db71995Sopenharmony_ci VkPhysicalDeviceImageFormatInfo2 info2{ 12145db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, // sType 12155db71995Sopenharmony_ci nullptr, // pNext 12165db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 12175db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 12185db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 12195db71995Sopenharmony_ci 0, // usage 12205db71995Sopenharmony_ci 0, // flags 12215db71995Sopenharmony_ci }; 12225db71995Sopenharmony_ci 12235db71995Sopenharmony_ci VkImageFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 12245db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysDevImageFormatProps2(physical_device, &info2, &props2)); 12255db71995Sopenharmony_ci 12265db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.width, props2.imageFormatProperties.maxExtent.width); 12275db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.height, props2.imageFormatProperties.maxExtent.height); 12285db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.depth, props2.imageFormatProperties.maxExtent.depth); 12295db71995Sopenharmony_ci ASSERT_EQ(props.maxMipLevels, props2.imageFormatProperties.maxMipLevels); 12305db71995Sopenharmony_ci ASSERT_EQ(props.maxArrayLayers, props2.imageFormatProperties.maxArrayLayers); 12315db71995Sopenharmony_ci ASSERT_EQ(props.sampleCounts, props2.imageFormatProperties.sampleCounts); 12325db71995Sopenharmony_ci ASSERT_EQ(props.maxResourceSize, props2.imageFormatProperties.maxResourceSize); 12335db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 12345db71995Sopenharmony_ci } 12355db71995Sopenharmony_ci} 12365db71995Sopenharmony_ci 12375db71995Sopenharmony_ci// Test vkGetPhysicalDeviceImageFormatProperties2 and vkGetPhysicalDeviceImageFormatProperties2KHR where instance supports, an ICD, 12385db71995Sopenharmony_ci// and a device under that ICD also support, so everything should work and return properly. 12395db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevImageFormatProps2KHRInstanceSupports11) { 12405db71995Sopenharmony_ci FrameworkEnvironment env{}; 12415db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 12425db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 12435db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 12445db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 12455db71995Sopenharmony_ci FillInRandomImageFormatData(env.get_test_icd(0).physical_devices.back().image_format_properties); 12465db71995Sopenharmony_ci 12475db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 12485db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 12495db71995Sopenharmony_ci instance.create_info.add_extensions( 12505db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 12515db71995Sopenharmony_ci instance.CheckCreate(); 12525db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 12535db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 12545db71995Sopenharmony_ci 12555db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysDevImageFormatProps2 = 12565db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2"); 12575db71995Sopenharmony_ci ASSERT_NE(GetPhysDevImageFormatProps2, nullptr); 12585db71995Sopenharmony_ci 12595db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysDevImageFormatProps2KHR = 12605db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2KHR"); 12615db71995Sopenharmony_ci ASSERT_NE(GetPhysDevImageFormatProps2KHR, nullptr); 12625db71995Sopenharmony_ci 12635db71995Sopenharmony_ci uint32_t driver_count = 1; 12645db71995Sopenharmony_ci VkPhysicalDevice physical_device; 12655db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 12665db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 12675db71995Sopenharmony_ci 12685db71995Sopenharmony_ci VkImageFormatProperties props{}; 12695db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 12705db71995Sopenharmony_ci instance->vkGetPhysicalDeviceImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 12715db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, 0, 0, &props)); 12725db71995Sopenharmony_ci 12735db71995Sopenharmony_ci VkPhysicalDeviceImageFormatInfo2 info2{ 12745db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, // sType 12755db71995Sopenharmony_ci nullptr, // pNext 12765db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 12775db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 12785db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 12795db71995Sopenharmony_ci 0, // usage 12805db71995Sopenharmony_ci 0, // flags 12815db71995Sopenharmony_ci }; 12825db71995Sopenharmony_ci 12835db71995Sopenharmony_ci VkImageFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 12845db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysDevImageFormatProps2(physical_device, &info2, &props2)); 12855db71995Sopenharmony_ci 12865db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.width, props2.imageFormatProperties.maxExtent.width); 12875db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.height, props2.imageFormatProperties.maxExtent.height); 12885db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.depth, props2.imageFormatProperties.maxExtent.depth); 12895db71995Sopenharmony_ci ASSERT_EQ(props.maxMipLevels, props2.imageFormatProperties.maxMipLevels); 12905db71995Sopenharmony_ci ASSERT_EQ(props.maxArrayLayers, props2.imageFormatProperties.maxArrayLayers); 12915db71995Sopenharmony_ci ASSERT_EQ(props.sampleCounts, props2.imageFormatProperties.sampleCounts); 12925db71995Sopenharmony_ci ASSERT_EQ(props.maxResourceSize, props2.imageFormatProperties.maxResourceSize); 12935db71995Sopenharmony_ci 12945db71995Sopenharmony_ci VkImageFormatProperties2KHR props2KHR{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR}; 12955db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysDevImageFormatProps2KHR(physical_device, &info2, &props2KHR)); 12965db71995Sopenharmony_ci 12975db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.width, props2KHR.imageFormatProperties.maxExtent.width); 12985db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.height, props2KHR.imageFormatProperties.maxExtent.height); 12995db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.depth, props2KHR.imageFormatProperties.maxExtent.depth); 13005db71995Sopenharmony_ci ASSERT_EQ(props.maxMipLevels, props2KHR.imageFormatProperties.maxMipLevels); 13015db71995Sopenharmony_ci ASSERT_EQ(props.maxArrayLayers, props2KHR.imageFormatProperties.maxArrayLayers); 13025db71995Sopenharmony_ci ASSERT_EQ(props.sampleCounts, props2KHR.imageFormatProperties.sampleCounts); 13035db71995Sopenharmony_ci ASSERT_EQ(props.maxResourceSize, props2KHR.imageFormatProperties.maxResourceSize); 13045db71995Sopenharmony_ci 13055db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 13065db71995Sopenharmony_ci} 13075db71995Sopenharmony_ci 13085db71995Sopenharmony_ci// Test vkGetPhysicalDeviceImageFormatProperties2 where instance supports it with some ICDs that both support 13095db71995Sopenharmony_ci// and don't support it: 13105db71995Sopenharmony_ci// ICD 0 supports 13115db71995Sopenharmony_ci// Physical device 0 does not 13125db71995Sopenharmony_ci// Physical device 1 does 13135db71995Sopenharmony_ci// Physical device 2 does not 13145db71995Sopenharmony_ci// ICD 1 doesn't support 13155db71995Sopenharmony_ci// Physical device 3 does not 13165db71995Sopenharmony_ci// ICD 2 supports 13175db71995Sopenharmony_ci// Physical device 4 does not 13185db71995Sopenharmony_ci// Physical device 5 does not 13195db71995Sopenharmony_ci// ICD 3 supports 13205db71995Sopenharmony_ci// Physical device 6 does 13215db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevImageFormatPropsMixed) { 13225db71995Sopenharmony_ci FrameworkEnvironment env{}; 13235db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 13245db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 13255db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 13265db71995Sopenharmony_ci 13275db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 13285db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 13295db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 13305db71995Sopenharmony_ci 13315db71995Sopenharmony_ci // ICD 1 should not have 1.1 13325db71995Sopenharmony_ci if (icd != 1) { 13335db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 13345db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 13355db71995Sopenharmony_ci } 13365db71995Sopenharmony_ci 13375db71995Sopenharmony_ci uint32_t rand_vendor_id; 13385db71995Sopenharmony_ci uint32_t rand_driver_vers; 13395db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 13405db71995Sopenharmony_ci 13415db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 13425db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 13435db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 13445db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 13455db71995Sopenharmony_ci 13465db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 13475db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 13485db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 13495db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 13505db71995Sopenharmony_ci } 13515db71995Sopenharmony_ci 13525db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 13535db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 13545db71995Sopenharmony_ci FillInRandomImageFormatData(cur_dev.image_format_properties); 13555db71995Sopenharmony_ci } 13565db71995Sopenharmony_ci } 13575db71995Sopenharmony_ci 13585db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 13595db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 13605db71995Sopenharmony_ci instance.CheckCreate(); 13615db71995Sopenharmony_ci 13625db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysDevImageFormatProps2 = 13635db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceImageFormatProperties2"); 13645db71995Sopenharmony_ci ASSERT_NE(GetPhysDevImageFormatProps2, nullptr); 13655db71995Sopenharmony_ci 13665db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 13675db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 13685db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 13695db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 13705db71995Sopenharmony_ci 13715db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 13725db71995Sopenharmony_ci VkImageFormatProperties props{}; 13735db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 13745db71995Sopenharmony_ci instance->vkGetPhysicalDeviceImageFormatProperties(physical_devices[dev], VK_FORMAT_R4G4_UNORM_PACK8, 13755db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, 0, 0, &props)); 13765db71995Sopenharmony_ci 13775db71995Sopenharmony_ci VkPhysicalDeviceImageFormatInfo2 info2{ 13785db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, // sType 13795db71995Sopenharmony_ci nullptr, // pNext 13805db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 13815db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 13825db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 13835db71995Sopenharmony_ci 0, // usage 13845db71995Sopenharmony_ci 0, // flags 13855db71995Sopenharmony_ci }; 13865db71995Sopenharmony_ci VkImageFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; 13875db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysDevImageFormatProps2(physical_devices[dev], &info2, &props2)); 13885db71995Sopenharmony_ci 13895db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.width, props2.imageFormatProperties.maxExtent.width); 13905db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.height, props2.imageFormatProperties.maxExtent.height); 13915db71995Sopenharmony_ci ASSERT_EQ(props.maxExtent.depth, props2.imageFormatProperties.maxExtent.depth); 13925db71995Sopenharmony_ci ASSERT_EQ(props.maxMipLevels, props2.imageFormatProperties.maxMipLevels); 13935db71995Sopenharmony_ci ASSERT_EQ(props.maxArrayLayers, props2.imageFormatProperties.maxArrayLayers); 13945db71995Sopenharmony_ci ASSERT_EQ(props.sampleCounts, props2.imageFormatProperties.sampleCounts); 13955db71995Sopenharmony_ci ASSERT_EQ(props.maxResourceSize, props2.imageFormatProperties.maxResourceSize); 13965db71995Sopenharmony_ci } 13975db71995Sopenharmony_ci} 13985db71995Sopenharmony_ci 13995db71995Sopenharmony_ci// Test vkGetPhysicalDeviceMemoryProperties2KHR where nothing supports it. 14005db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevMemoryProps2KHRNoSupport) { 14015db71995Sopenharmony_ci FrameworkEnvironment env{}; 14025db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 14035db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 14045db71995Sopenharmony_ci 14055db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 14065db71995Sopenharmony_ci instance.CheckCreate(); 14075db71995Sopenharmony_ci 14085db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2KHR GetPhysDevMemoryProps2KHR = 14095db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceMemoryProperties2KHR"); 14105db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevMemoryProps2KHR, nullptr); 14115db71995Sopenharmony_ci} 14125db71995Sopenharmony_ci 14135db71995Sopenharmony_ci// Test vkGetPhysicalDeviceMemoryProperties2KHR where instance supports it, but nothing else. 14145db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevMemoryPropsKHRNoICDSupport) { 14155db71995Sopenharmony_ci FrameworkEnvironment env{}; 14165db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 14175db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 14185db71995Sopenharmony_ci 14195db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 14205db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 14215db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 14225db71995Sopenharmony_ci 14235db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2KHR GetPhysDevMemoryProps2KHR = 14245db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceMemoryProperties2KHR"); 14255db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevMemoryProps2KHR, nullptr); 14265db71995Sopenharmony_ci} 14275db71995Sopenharmony_ci 14285db71995Sopenharmony_ci// Fill in random but valid data into the memory data struct for the current physical device 14295db71995Sopenharmony_civoid FillInRandomMemoryData(VkPhysicalDeviceMemoryProperties& props) { 14305db71995Sopenharmony_ci props.memoryTypeCount = (rand() % 7) + 1; 14315db71995Sopenharmony_ci props.memoryHeapCount = (rand() % 7) + 1; 14325db71995Sopenharmony_ci for (uint32_t i = 0; i < props.memoryHeapCount; ++i) { 14335db71995Sopenharmony_ci props.memoryHeaps[i].size = (rand() % 728) + (rand() % 728) + 1; 14345db71995Sopenharmony_ci props.memoryHeaps[i].flags = (rand() % 2) + 1; 14355db71995Sopenharmony_ci } 14365db71995Sopenharmony_ci for (uint32_t i = 0; i < props.memoryTypeCount; ++i) { 14375db71995Sopenharmony_ci props.memoryTypes[i].propertyFlags = static_cast<VkMemoryPropertyFlags>((rand() % 2) + 1); 14385db71995Sopenharmony_ci props.memoryTypes[i].heapIndex = rand() % props.memoryHeapCount; 14395db71995Sopenharmony_ci } 14405db71995Sopenharmony_ci} 14415db71995Sopenharmony_ci 14425db71995Sopenharmony_ci// Compare the memory structs 14435db71995Sopenharmony_cibool CompareMemoryData(const VkPhysicalDeviceMemoryProperties& props1, const VkPhysicalDeviceMemoryProperties2& props2) { 14445db71995Sopenharmony_ci bool equal = true; 14455db71995Sopenharmony_ci equal = equal && props1.memoryTypeCount == props2.memoryProperties.memoryTypeCount; 14465db71995Sopenharmony_ci equal = equal && props1.memoryHeapCount == props2.memoryProperties.memoryHeapCount; 14475db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.memoryHeapCount; ++i) { 14485db71995Sopenharmony_ci equal = equal && props1.memoryHeaps[i].size == props2.memoryProperties.memoryHeaps[i].size; 14495db71995Sopenharmony_ci equal = equal && props1.memoryHeaps[i].flags == props2.memoryProperties.memoryHeaps[i].flags; 14505db71995Sopenharmony_ci } 14515db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.memoryTypeCount; ++i) { 14525db71995Sopenharmony_ci equal = equal && props1.memoryTypes[i].propertyFlags == props2.memoryProperties.memoryTypes[i].propertyFlags; 14535db71995Sopenharmony_ci equal = equal && props1.memoryTypes[i].heapIndex == props2.memoryProperties.memoryTypes[i].heapIndex; 14545db71995Sopenharmony_ci } 14555db71995Sopenharmony_ci return equal; 14565db71995Sopenharmony_ci} 14575db71995Sopenharmony_ci 14585db71995Sopenharmony_ci// Test vkGetPhysicalDeviceMemoryProperties2KHR where instance and ICD supports it, but device does not support it. 14595db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevMemoryProps2KHRInstanceAndICDSupport) { 14605db71995Sopenharmony_ci FrameworkEnvironment env{}; 14615db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 14625db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 14635db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 14645db71995Sopenharmony_ci FillInRandomMemoryData(env.get_test_icd(0).physical_devices.back().memory_properties); 14655db71995Sopenharmony_ci 14665db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 14675db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 14685db71995Sopenharmony_ci instance.CheckCreate(); 14695db71995Sopenharmony_ci 14705db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2KHR GetPhysDevMemoryProps2KHR = 14715db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceMemoryProperties2KHR"); 14725db71995Sopenharmony_ci ASSERT_NE(GetPhysDevMemoryProps2KHR, nullptr); 14735db71995Sopenharmony_ci 14745db71995Sopenharmony_ci uint32_t driver_count = 1; 14755db71995Sopenharmony_ci VkPhysicalDevice physical_device; 14765db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 14775db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 14785db71995Sopenharmony_ci 14795db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties props{}; 14805db71995Sopenharmony_ci instance->vkGetPhysicalDeviceMemoryProperties(physical_device, &props); 14815db71995Sopenharmony_ci 14825db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2}; 14835db71995Sopenharmony_ci GetPhysDevMemoryProps2KHR(physical_device, &props2); 14845db71995Sopenharmony_ci ASSERT_TRUE(CompareMemoryData(props, props2)); 14855db71995Sopenharmony_ci} 14865db71995Sopenharmony_ci 14875db71995Sopenharmony_ci// Test vkGetPhysicalDeviceMemoryProperties2 where instance supports, an ICD, and a device under that ICD 14885db71995Sopenharmony_ci// also support, so everything should work and return properly. 14895db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 14905db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevMemoryProps2Simple) { 14915db71995Sopenharmony_ci FrameworkEnvironment env{}; 14925db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 14935db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 14945db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 14955db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 14965db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 14975db71995Sopenharmony_ci FillInRandomMemoryData(env.get_test_icd(0).physical_devices.back().memory_properties); 14985db71995Sopenharmony_ci { 14995db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 15005db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 15015db71995Sopenharmony_ci instance.CheckCreate(); 15025db71995Sopenharmony_ci 15035db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysDevMemoryProps2 = instance.load("vkGetPhysicalDeviceMemoryProperties2"); 15045db71995Sopenharmony_ci ASSERT_NE(GetPhysDevMemoryProps2, nullptr); 15055db71995Sopenharmony_ci 15065db71995Sopenharmony_ci uint32_t driver_count = 1; 15075db71995Sopenharmony_ci VkPhysicalDevice physical_device; 15085db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 15095db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 15105db71995Sopenharmony_ci 15115db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties props{}; 15125db71995Sopenharmony_ci instance->vkGetPhysicalDeviceMemoryProperties(physical_device, &props); 15135db71995Sopenharmony_ci 15145db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2}; 15155db71995Sopenharmony_ci GetPhysDevMemoryProps2(physical_device, &props2); 15165db71995Sopenharmony_ci ASSERT_TRUE(CompareMemoryData(props, props2)); 15175db71995Sopenharmony_ci } 15185db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 15195db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 15205db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 15215db71995Sopenharmony_ci instance.CheckCreate(); 15225db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 15235db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 15245db71995Sopenharmony_ci 15255db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysDevMemoryProps2 = instance.load("vkGetPhysicalDeviceMemoryProperties2"); 15265db71995Sopenharmony_ci ASSERT_NE(GetPhysDevMemoryProps2, nullptr); 15275db71995Sopenharmony_ci 15285db71995Sopenharmony_ci uint32_t driver_count = 1; 15295db71995Sopenharmony_ci VkPhysicalDevice physical_device; 15305db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 15315db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 15325db71995Sopenharmony_ci 15335db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties props{}; 15345db71995Sopenharmony_ci instance->vkGetPhysicalDeviceMemoryProperties(physical_device, &props); 15355db71995Sopenharmony_ci 15365db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2}; 15375db71995Sopenharmony_ci GetPhysDevMemoryProps2(physical_device, &props2); 15385db71995Sopenharmony_ci ASSERT_TRUE(CompareMemoryData(props, props2)); 15395db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 15405db71995Sopenharmony_ci } 15415db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 15425db71995Sopenharmony_ci .set_name("modify_api_version_layer") 15435db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 15445db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 15455db71995Sopenharmony_ci "modify_api_version_layer.json"); 15465db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 15475db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 15485db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 15495db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 15505db71995Sopenharmony_ci instance.CheckCreate(); 15515db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 15525db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 15535db71995Sopenharmony_ci 15545db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysDevMemoryProps2 = instance.load("vkGetPhysicalDeviceMemoryProperties2"); 15555db71995Sopenharmony_ci ASSERT_NE(GetPhysDevMemoryProps2, nullptr); 15565db71995Sopenharmony_ci 15575db71995Sopenharmony_ci uint32_t driver_count = 1; 15585db71995Sopenharmony_ci VkPhysicalDevice physical_device; 15595db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 15605db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 15615db71995Sopenharmony_ci 15625db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties props{}; 15635db71995Sopenharmony_ci instance->vkGetPhysicalDeviceMemoryProperties(physical_device, &props); 15645db71995Sopenharmony_ci 15655db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2}; 15665db71995Sopenharmony_ci GetPhysDevMemoryProps2(physical_device, &props2); 15675db71995Sopenharmony_ci ASSERT_TRUE(CompareMemoryData(props, props2)); 15685db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 15695db71995Sopenharmony_ci } 15705db71995Sopenharmony_ci} 15715db71995Sopenharmony_ci 15725db71995Sopenharmony_ci// Test vkGetPhysicalDeviceMemoryProperties2 and vkGetPhysicalDeviceMemoryProperties2KHR where ICD is 1.0 and supports 15735db71995Sopenharmony_ci// extension but the instance supports 1.1 and the extension 15745db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevMemoryProps2KHRInstanceSupports11) { 15755db71995Sopenharmony_ci FrameworkEnvironment env{}; 15765db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 15775db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 15785db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 15795db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 15805db71995Sopenharmony_ci FillInRandomMemoryData(env.get_test_icd(0).physical_devices.back().memory_properties); 15815db71995Sopenharmony_ci 15825db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 15835db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 15845db71995Sopenharmony_ci instance.create_info.add_extensions( 15855db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 15865db71995Sopenharmony_ci instance.CheckCreate(); 15875db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 15885db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 15895db71995Sopenharmony_ci 15905db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysDevMemoryProps2 = instance.load("vkGetPhysicalDeviceMemoryProperties2"); 15915db71995Sopenharmony_ci ASSERT_NE(GetPhysDevMemoryProps2, nullptr); 15925db71995Sopenharmony_ci 15935db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2KHR GetPhysDevMemoryProps2KHR = 15945db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceMemoryProperties2KHR"); 15955db71995Sopenharmony_ci ASSERT_NE(GetPhysDevMemoryProps2KHR, nullptr); 15965db71995Sopenharmony_ci 15975db71995Sopenharmony_ci uint32_t driver_count = 1; 15985db71995Sopenharmony_ci VkPhysicalDevice physical_device; 15995db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 16005db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 16015db71995Sopenharmony_ci 16025db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties props{}; 16035db71995Sopenharmony_ci instance->vkGetPhysicalDeviceMemoryProperties(physical_device, &props); 16045db71995Sopenharmony_ci 16055db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2}; 16065db71995Sopenharmony_ci GetPhysDevMemoryProps2(physical_device, &props2); 16075db71995Sopenharmony_ci ASSERT_TRUE(CompareMemoryData(props, props2)); 16085db71995Sopenharmony_ci 16095db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties2KHR props2KHR{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR}; 16105db71995Sopenharmony_ci GetPhysDevMemoryProps2KHR(physical_device, &props2KHR); 16115db71995Sopenharmony_ci ASSERT_TRUE(CompareMemoryData(props, props2KHR)); 16125db71995Sopenharmony_ci 16135db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 16145db71995Sopenharmony_ci} 16155db71995Sopenharmony_ci// Test vkGetPhysicalDeviceMemoryProperties2 where instance supports it with some ICDs that both support 16165db71995Sopenharmony_ci// and don't support it: 16175db71995Sopenharmony_ci// ICD 0 supports 16185db71995Sopenharmony_ci// Physical device 0 does not 16195db71995Sopenharmony_ci// Physical device 1 does 16205db71995Sopenharmony_ci// Physical device 2 does not 16215db71995Sopenharmony_ci// ICD 1 doesn't support 16225db71995Sopenharmony_ci// Physical device 3 does not 16235db71995Sopenharmony_ci// ICD 2 supports 16245db71995Sopenharmony_ci// Physical device 4 does not 16255db71995Sopenharmony_ci// Physical device 5 does not 16265db71995Sopenharmony_ci// ICD 3 supports 16275db71995Sopenharmony_ci// Physical device 6 does 16285db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevMemoryPropsMixed) { 16295db71995Sopenharmony_ci FrameworkEnvironment env{}; 16305db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 16315db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 16325db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 16335db71995Sopenharmony_ci 16345db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 16355db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 16365db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 16375db71995Sopenharmony_ci 16385db71995Sopenharmony_ci // ICD 1 should not have 1.1 16395db71995Sopenharmony_ci if (icd != 1) { 16405db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 16415db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 16425db71995Sopenharmony_ci } 16435db71995Sopenharmony_ci 16445db71995Sopenharmony_ci uint32_t rand_vendor_id; 16455db71995Sopenharmony_ci uint32_t rand_driver_vers; 16465db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 16475db71995Sopenharmony_ci 16485db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 16495db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 16505db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 16515db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 16525db71995Sopenharmony_ci 16535db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 16545db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 16555db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 16565db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 16575db71995Sopenharmony_ci } 16585db71995Sopenharmony_ci 16595db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 16605db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 16615db71995Sopenharmony_ci FillInRandomMemoryData(cur_dev.memory_properties); 16625db71995Sopenharmony_ci } 16635db71995Sopenharmony_ci } 16645db71995Sopenharmony_ci 16655db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 16665db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 16675db71995Sopenharmony_ci instance.CheckCreate(); 16685db71995Sopenharmony_ci 16695db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysDevMemoryProps2 = instance.load("vkGetPhysicalDeviceMemoryProperties2"); 16705db71995Sopenharmony_ci ASSERT_NE(GetPhysDevMemoryProps2, nullptr); 16715db71995Sopenharmony_ci 16725db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 16735db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 16745db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 16755db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 16765db71995Sopenharmony_ci 16775db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 16785db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties props{}; 16795db71995Sopenharmony_ci instance->vkGetPhysicalDeviceMemoryProperties(physical_devices[dev], &props); 16805db71995Sopenharmony_ci 16815db71995Sopenharmony_ci VkPhysicalDeviceMemoryProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2}; 16825db71995Sopenharmony_ci GetPhysDevMemoryProps2(physical_devices[dev], &props2); 16835db71995Sopenharmony_ci ASSERT_TRUE(CompareMemoryData(props, props2)); 16845db71995Sopenharmony_ci } 16855db71995Sopenharmony_ci} 16865db71995Sopenharmony_ci 16875db71995Sopenharmony_ci// Test vkGetPhysicalDeviceQueueFamilyProperties2KHR where nothing supports it. 16885db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevQueueFamilyProps2KHRNoSupport) { 16895db71995Sopenharmony_ci FrameworkEnvironment env{}; 16905db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 16915db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 16925db71995Sopenharmony_ci 16935db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 16945db71995Sopenharmony_ci instance.CheckCreate(); 16955db71995Sopenharmony_ci 16965db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR GetPhysDevQueueFamilyProps2KHR = 16975db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2KHR"); 16985db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevQueueFamilyProps2KHR, nullptr); 16995db71995Sopenharmony_ci} 17005db71995Sopenharmony_ci 17015db71995Sopenharmony_ci// Test vkGetPhysicalDeviceQueueFamilyProperties2KHR where instance supports it, but nothing else. 17025db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevQueueFamilyPropsKHRNoICDSupport) { 17035db71995Sopenharmony_ci FrameworkEnvironment env{}; 17045db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 17055db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 17065db71995Sopenharmony_ci 17075db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 17085db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 17095db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 17105db71995Sopenharmony_ci 17115db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR GetPhysDevQueueFamilyProps2KHR = 17125db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2KHR"); 17135db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevQueueFamilyProps2KHR, nullptr); 17145db71995Sopenharmony_ci} 17155db71995Sopenharmony_ci 17165db71995Sopenharmony_ci// Fill in random but valid data into the queue family data struct for the current physical device 17175db71995Sopenharmony_ciuint32_t FillInRandomQueueFamilyData(std::vector<MockQueueFamilyProperties>& props) { 17185db71995Sopenharmony_ci props.resize((rand() % 4) + 1); 17195db71995Sopenharmony_ci for (uint32_t i = 0; i < props.size(); ++i) { 17205db71995Sopenharmony_ci props[i].properties.queueFlags = (rand() % 30) + 1; 17215db71995Sopenharmony_ci props[i].properties.queueCount = (rand() % 7) + 1; 17225db71995Sopenharmony_ci props[i].properties.timestampValidBits = (rand() % 30) + 7; 17235db71995Sopenharmony_ci props[i].properties.minImageTransferGranularity.width = (rand() % 30) + 1; 17245db71995Sopenharmony_ci props[i].properties.minImageTransferGranularity.height = (rand() % 30) + 1; 17255db71995Sopenharmony_ci props[i].properties.minImageTransferGranularity.depth = (rand() % 30) + 1; 17265db71995Sopenharmony_ci props[i].support_present = rand() % 2 == 0; 17275db71995Sopenharmony_ci } 17285db71995Sopenharmony_ci return static_cast<uint32_t>(props.size()); 17295db71995Sopenharmony_ci} 17305db71995Sopenharmony_ci 17315db71995Sopenharmony_ci// Compare the queue family structs 17325db71995Sopenharmony_cibool CompareQueueFamilyData(const std::vector<VkQueueFamilyProperties>& props1, 17335db71995Sopenharmony_ci const std::vector<VkQueueFamilyProperties2>& props2) { 17345db71995Sopenharmony_ci if (props1.size() != props2.size()) return false; 17355db71995Sopenharmony_ci bool equal = true; 17365db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.size(); ++i) { 17375db71995Sopenharmony_ci equal = equal && props1[i].queueFlags == props2[i].queueFamilyProperties.queueFlags; 17385db71995Sopenharmony_ci equal = equal && props1[i].queueCount == props2[i].queueFamilyProperties.queueCount; 17395db71995Sopenharmony_ci equal = equal && props1[i].timestampValidBits == props2[i].queueFamilyProperties.timestampValidBits; 17405db71995Sopenharmony_ci equal = equal && 17415db71995Sopenharmony_ci props1[i].minImageTransferGranularity.width == props2[i].queueFamilyProperties.minImageTransferGranularity.width; 17425db71995Sopenharmony_ci equal = equal && 17435db71995Sopenharmony_ci props1[i].minImageTransferGranularity.height == props2[i].queueFamilyProperties.minImageTransferGranularity.height; 17445db71995Sopenharmony_ci equal = equal && 17455db71995Sopenharmony_ci props1[i].minImageTransferGranularity.depth == props2[i].queueFamilyProperties.minImageTransferGranularity.depth; 17465db71995Sopenharmony_ci } 17475db71995Sopenharmony_ci return equal; 17485db71995Sopenharmony_ci} 17495db71995Sopenharmony_ci 17505db71995Sopenharmony_ci// Test vkGetPhysicalDeviceQueueFamilyProperties2KHR where instance and ICD supports it, but device does not support it. 17515db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevQueueFamilyProps2KHRInstanceAndICDSupport) { 17525db71995Sopenharmony_ci FrameworkEnvironment env{}; 17535db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 17545db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 17555db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 17565db71995Sopenharmony_ci uint32_t num_fam = FillInRandomQueueFamilyData(env.get_test_icd(0).physical_devices.back().queue_family_properties); 17575db71995Sopenharmony_ci 17585db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 17595db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 17605db71995Sopenharmony_ci instance.CheckCreate(); 17615db71995Sopenharmony_ci 17625db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR GetPhysDevQueueFamilyProps2KHR = 17635db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2KHR"); 17645db71995Sopenharmony_ci ASSERT_NE(GetPhysDevQueueFamilyProps2KHR, nullptr); 17655db71995Sopenharmony_ci 17665db71995Sopenharmony_ci uint32_t driver_count = 1; 17675db71995Sopenharmony_ci VkPhysicalDevice physical_device; 17685db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 17695db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 17705db71995Sopenharmony_ci 17715db71995Sopenharmony_ci uint32_t ret_fam_1 = 0; 17725db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties> props{}; 17735db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, nullptr); 17745db71995Sopenharmony_ci ASSERT_EQ(num_fam, ret_fam_1); 17755db71995Sopenharmony_ci props.resize(ret_fam_1); 17765db71995Sopenharmony_ci 17775db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, props.data()); 17785db71995Sopenharmony_ci 17795db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties2> props2{}; 17805db71995Sopenharmony_ci uint32_t ret_fam_2 = 0; 17815db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2KHR(physical_device, &ret_fam_2, nullptr); 17825db71995Sopenharmony_ci ASSERT_EQ(ret_fam_1, ret_fam_2); 17835db71995Sopenharmony_ci props2.resize(ret_fam_2, VkQueueFamilyProperties2{VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2}); 17845db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2KHR(physical_device, &ret_fam_2, props2.data()); 17855db71995Sopenharmony_ci ASSERT_TRUE(CompareQueueFamilyData(props, props2)); 17865db71995Sopenharmony_ci} 17875db71995Sopenharmony_ci 17885db71995Sopenharmony_ci// Test vkGetPhysicalDeviceQueueFamilyProperties2 where instance supports, an ICD, and a device under that ICD 17895db71995Sopenharmony_ci// also support, so everything should work and return properly. 17905db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 17915db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevQueueFamilyProps2Simple) { 17925db71995Sopenharmony_ci FrameworkEnvironment env{}; 17935db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 17945db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 17955db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 17965db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 17975db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 17985db71995Sopenharmony_ci uint32_t num_fam = FillInRandomQueueFamilyData(env.get_test_icd(0).physical_devices.back().queue_family_properties); 17995db71995Sopenharmony_ci { 18005db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 18015db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 18025db71995Sopenharmony_ci instance.CheckCreate(); 18035db71995Sopenharmony_ci 18045db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysDevQueueFamilyProps2 = 18055db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2"); 18065db71995Sopenharmony_ci ASSERT_NE(GetPhysDevQueueFamilyProps2, nullptr); 18075db71995Sopenharmony_ci 18085db71995Sopenharmony_ci uint32_t driver_count = 1; 18095db71995Sopenharmony_ci VkPhysicalDevice physical_device; 18105db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 18115db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 18125db71995Sopenharmony_ci 18135db71995Sopenharmony_ci uint32_t ret_fam_1 = 0; 18145db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties> props{}; 18155db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, nullptr); 18165db71995Sopenharmony_ci ASSERT_EQ(num_fam, ret_fam_1); 18175db71995Sopenharmony_ci props.resize(ret_fam_1); 18185db71995Sopenharmony_ci 18195db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, props.data()); 18205db71995Sopenharmony_ci 18215db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties2> props2{}; 18225db71995Sopenharmony_ci uint32_t ret_fam_2 = 0; 18235db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, nullptr); 18245db71995Sopenharmony_ci ASSERT_EQ(ret_fam_1, ret_fam_2); 18255db71995Sopenharmony_ci props2.resize(ret_fam_2, VkQueueFamilyProperties2{VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2}); 18265db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, props2.data()); 18275db71995Sopenharmony_ci ASSERT_TRUE(CompareQueueFamilyData(props, props2)); 18285db71995Sopenharmony_ci } 18295db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 18305db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 18315db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 18325db71995Sopenharmony_ci instance.CheckCreate(); 18335db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 18345db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 18355db71995Sopenharmony_ci 18365db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysDevQueueFamilyProps2 = 18375db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2"); 18385db71995Sopenharmony_ci ASSERT_NE(GetPhysDevQueueFamilyProps2, nullptr); 18395db71995Sopenharmony_ci 18405db71995Sopenharmony_ci uint32_t driver_count = 1; 18415db71995Sopenharmony_ci VkPhysicalDevice physical_device; 18425db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 18435db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 18445db71995Sopenharmony_ci 18455db71995Sopenharmony_ci uint32_t ret_fam_1 = 0; 18465db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties> props{}; 18475db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, nullptr); 18485db71995Sopenharmony_ci ASSERT_EQ(num_fam, ret_fam_1); 18495db71995Sopenharmony_ci props.resize(ret_fam_1); 18505db71995Sopenharmony_ci 18515db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, props.data()); 18525db71995Sopenharmony_ci 18535db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties2> props2{}; 18545db71995Sopenharmony_ci uint32_t ret_fam_2 = 0; 18555db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, nullptr); 18565db71995Sopenharmony_ci ASSERT_EQ(ret_fam_1, ret_fam_2); 18575db71995Sopenharmony_ci props2.resize(ret_fam_2, VkQueueFamilyProperties2{VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2}); 18585db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, props2.data()); 18595db71995Sopenharmony_ci ASSERT_TRUE(CompareQueueFamilyData(props, props2)); 18605db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 18615db71995Sopenharmony_ci } 18625db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 18635db71995Sopenharmony_ci .set_name("modify_api_version_layer") 18645db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 18655db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 18665db71995Sopenharmony_ci "modify_api_version_layer.json"); 18675db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 18685db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 18695db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 18705db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 18715db71995Sopenharmony_ci instance.CheckCreate(); 18725db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 18735db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 18745db71995Sopenharmony_ci 18755db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysDevQueueFamilyProps2 = 18765db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2"); 18775db71995Sopenharmony_ci ASSERT_NE(GetPhysDevQueueFamilyProps2, nullptr); 18785db71995Sopenharmony_ci 18795db71995Sopenharmony_ci uint32_t driver_count = 1; 18805db71995Sopenharmony_ci VkPhysicalDevice physical_device; 18815db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 18825db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 18835db71995Sopenharmony_ci 18845db71995Sopenharmony_ci uint32_t ret_fam_1 = 0; 18855db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties> props{}; 18865db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, nullptr); 18875db71995Sopenharmony_ci ASSERT_EQ(num_fam, ret_fam_1); 18885db71995Sopenharmony_ci props.resize(ret_fam_1); 18895db71995Sopenharmony_ci 18905db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, props.data()); 18915db71995Sopenharmony_ci 18925db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties2> props2{}; 18935db71995Sopenharmony_ci uint32_t ret_fam_2 = 0; 18945db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, nullptr); 18955db71995Sopenharmony_ci ASSERT_EQ(ret_fam_1, ret_fam_2); 18965db71995Sopenharmony_ci props2.resize(ret_fam_2, VkQueueFamilyProperties2{VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2}); 18975db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, props2.data()); 18985db71995Sopenharmony_ci ASSERT_TRUE(CompareQueueFamilyData(props, props2)); 18995db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 19005db71995Sopenharmony_ci } 19015db71995Sopenharmony_ci} 19025db71995Sopenharmony_ci 19035db71995Sopenharmony_ci// Test vkGetPhysicalDeviceQueueFamilyProperties2 and vkGetPhysicalDeviceQueueFamilyProperties2KHR where ICD is 1.0 and supports 19045db71995Sopenharmony_ci// extension but the instance supports 1.1 and the extension 19055db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevQueueFamilyProps2KHRInstanceSupports11) { 19065db71995Sopenharmony_ci FrameworkEnvironment env{}; 19075db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 19085db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 19095db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 19105db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 19115db71995Sopenharmony_ci uint32_t num_fam = FillInRandomQueueFamilyData(env.get_test_icd(0).physical_devices.back().queue_family_properties); 19125db71995Sopenharmony_ci 19135db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 19145db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 19155db71995Sopenharmony_ci instance.create_info.add_extensions( 19165db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 19175db71995Sopenharmony_ci instance.CheckCreate(); 19185db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 19195db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 19205db71995Sopenharmony_ci 19215db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysDevQueueFamilyProps2 = 19225db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2"); 19235db71995Sopenharmony_ci ASSERT_NE(GetPhysDevQueueFamilyProps2, nullptr); 19245db71995Sopenharmony_ci 19255db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR GetPhysDevQueueFamilyProps2KHR = 19265db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2KHR"); 19275db71995Sopenharmony_ci ASSERT_NE(GetPhysDevQueueFamilyProps2KHR, nullptr); 19285db71995Sopenharmony_ci 19295db71995Sopenharmony_ci uint32_t driver_count = 1; 19305db71995Sopenharmony_ci VkPhysicalDevice physical_device; 19315db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 19325db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 19335db71995Sopenharmony_ci 19345db71995Sopenharmony_ci uint32_t ret_fam_1 = 0; 19355db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties> props{}; 19365db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, nullptr); 19375db71995Sopenharmony_ci ASSERT_EQ(num_fam, ret_fam_1); 19385db71995Sopenharmony_ci props.resize(ret_fam_1); 19395db71995Sopenharmony_ci 19405db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &ret_fam_1, props.data()); 19415db71995Sopenharmony_ci 19425db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties2> props2{}; 19435db71995Sopenharmony_ci uint32_t ret_fam_2 = 0; 19445db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, nullptr); 19455db71995Sopenharmony_ci ASSERT_EQ(ret_fam_1, ret_fam_2); 19465db71995Sopenharmony_ci props2.resize(ret_fam_2, VkQueueFamilyProperties2{VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2}); 19475db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_device, &ret_fam_2, props2.data()); 19485db71995Sopenharmony_ci ASSERT_TRUE(CompareQueueFamilyData(props, props2)); 19495db71995Sopenharmony_ci 19505db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties2KHR> props2KHR{}; 19515db71995Sopenharmony_ci uint32_t ret_fam_2_khr = 0; 19525db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2KHR(physical_device, &ret_fam_2_khr, nullptr); 19535db71995Sopenharmony_ci ASSERT_EQ(ret_fam_1, ret_fam_2_khr); 19545db71995Sopenharmony_ci props2KHR.resize(ret_fam_2_khr, VkQueueFamilyProperties2KHR{VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR}); 19555db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2KHR(physical_device, &ret_fam_2_khr, props2KHR.data()); 19565db71995Sopenharmony_ci ASSERT_TRUE(CompareQueueFamilyData(props, props2KHR)); 19575db71995Sopenharmony_ci 19585db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 19595db71995Sopenharmony_ci} 19605db71995Sopenharmony_ci 19615db71995Sopenharmony_ci// Test vkGetPhysicalDeviceQueueFamilyProperties2 where instance supports it with some ICDs that both support 19625db71995Sopenharmony_ci// and don't support it: 19635db71995Sopenharmony_ci// ICD 0 supports 19645db71995Sopenharmony_ci// Physical device 0 does not 19655db71995Sopenharmony_ci// Physical device 1 does 19665db71995Sopenharmony_ci// Physical device 2 does not 19675db71995Sopenharmony_ci// ICD 1 doesn't support 19685db71995Sopenharmony_ci// Physical device 3 does not 19695db71995Sopenharmony_ci// ICD 2 supports 19705db71995Sopenharmony_ci// Physical device 4 does not 19715db71995Sopenharmony_ci// Physical device 5 does not 19725db71995Sopenharmony_ci// ICD 3 supports 19735db71995Sopenharmony_ci// Physical device 6 does 19745db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevQueueFamilyPropsMixed) { 19755db71995Sopenharmony_ci FrameworkEnvironment env{}; 19765db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 19775db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 19785db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 19795db71995Sopenharmony_ci 19805db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 19815db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 19825db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 19835db71995Sopenharmony_ci 19845db71995Sopenharmony_ci // ICD 1 should not have 1.1 19855db71995Sopenharmony_ci if (icd != 1) { 19865db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 19875db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 19885db71995Sopenharmony_ci } 19895db71995Sopenharmony_ci 19905db71995Sopenharmony_ci uint32_t rand_vendor_id; 19915db71995Sopenharmony_ci uint32_t rand_driver_vers; 19925db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 19935db71995Sopenharmony_ci 19945db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 19955db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 19965db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 19975db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 19985db71995Sopenharmony_ci 19995db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 20005db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 20015db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 20025db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 20035db71995Sopenharmony_ci } 20045db71995Sopenharmony_ci 20055db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 20065db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 20075db71995Sopenharmony_ci FillInRandomQueueFamilyData(cur_dev.queue_family_properties); 20085db71995Sopenharmony_ci } 20095db71995Sopenharmony_ci } 20105db71995Sopenharmony_ci 20115db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 20125db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 20135db71995Sopenharmony_ci instance.CheckCreate(); 20145db71995Sopenharmony_ci 20155db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysDevQueueFamilyProps2 = 20165db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceQueueFamilyProperties2"); 20175db71995Sopenharmony_ci ASSERT_NE(GetPhysDevQueueFamilyProps2, nullptr); 20185db71995Sopenharmony_ci 20195db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 20205db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 20215db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 20225db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 20235db71995Sopenharmony_ci 20245db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 20255db71995Sopenharmony_ci uint32_t ret_fam_1 = 0; 20265db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties> props{}; 20275db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[dev], &ret_fam_1, nullptr); 20285db71995Sopenharmony_ci props.resize(ret_fam_1); 20295db71995Sopenharmony_ci instance->vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[dev], &ret_fam_1, props.data()); 20305db71995Sopenharmony_ci 20315db71995Sopenharmony_ci std::vector<VkQueueFamilyProperties2> props2{}; 20325db71995Sopenharmony_ci uint32_t ret_fam_2 = 0; 20335db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_devices[dev], &ret_fam_2, nullptr); 20345db71995Sopenharmony_ci ASSERT_EQ(ret_fam_1, ret_fam_2); 20355db71995Sopenharmony_ci props2.resize(ret_fam_2, VkQueueFamilyProperties2{VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2}); 20365db71995Sopenharmony_ci GetPhysDevQueueFamilyProps2(physical_devices[dev], &ret_fam_2, props2.data()); 20375db71995Sopenharmony_ci ASSERT_TRUE(CompareQueueFamilyData(props, props2)); 20385db71995Sopenharmony_ci } 20395db71995Sopenharmony_ci} 20405db71995Sopenharmony_ci 20415db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSparseImageFormatProperties2KHR where nothing supports it. 20425db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSparseImageFormatProps2KHRNoSupport) { 20435db71995Sopenharmony_ci FrameworkEnvironment env{}; 20445db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 20455db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 20465db71995Sopenharmony_ci 20475db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 20485db71995Sopenharmony_ci instance.CheckCreate(); 20495db71995Sopenharmony_ci 20505db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR GetPhysDevSparseImageFormatProps2KHR = 20515db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2KHR"); 20525db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevSparseImageFormatProps2KHR, nullptr); 20535db71995Sopenharmony_ci} 20545db71995Sopenharmony_ci 20555db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSparseImageFormatProperties2KHR where instance supports it, but nothing else. 20565db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSparseImageFormatPropsKHRNoICDSupport) { 20575db71995Sopenharmony_ci FrameworkEnvironment env{}; 20585db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 20595db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 20605db71995Sopenharmony_ci 20615db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 20625db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 20635db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 20645db71995Sopenharmony_ci 20655db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR GetPhysDevSparseImageFormatProps2KHR = 20665db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2KHR"); 20675db71995Sopenharmony_ci ASSERT_EQ(GetPhysDevSparseImageFormatProps2KHR, nullptr); 20685db71995Sopenharmony_ci} 20695db71995Sopenharmony_ci 20705db71995Sopenharmony_ci// Fill in random but valid data into the sparse image format data struct for the current physical device 20715db71995Sopenharmony_civoid FillInRandomSparseImageFormatData(std::vector<VkSparseImageFormatProperties>& props) { 20725db71995Sopenharmony_ci props.resize((rand() % 4) + 1); 20735db71995Sopenharmony_ci for (uint32_t i = 0; i < props.size(); ++i) { 20745db71995Sopenharmony_ci props[i].aspectMask = static_cast<VkImageAspectFlags>((rand() % 0x7FE) + 1); 20755db71995Sopenharmony_ci props[i].imageGranularity = {static_cast<uint32_t>(rand() % 512), static_cast<uint32_t>(rand() % 512), 20765db71995Sopenharmony_ci static_cast<uint32_t>(rand() % 512)}; 20775db71995Sopenharmony_ci props[i].flags = static_cast<VkSparseImageFormatFlags>((rand() % 6) + 1); 20785db71995Sopenharmony_ci } 20795db71995Sopenharmony_ci} 20805db71995Sopenharmony_ci 20815db71995Sopenharmony_ci// Compare the sparse image format structs 20825db71995Sopenharmony_cibool CompareSparseImageFormatData(const std::vector<VkSparseImageFormatProperties>& props1, 20835db71995Sopenharmony_ci const std::vector<VkSparseImageFormatProperties2>& props2) { 20845db71995Sopenharmony_ci if (props1.size() != props2.size()) return false; 20855db71995Sopenharmony_ci bool equal = true; 20865db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.size(); ++i) { 20875db71995Sopenharmony_ci equal = equal && props1[i].aspectMask == props2[i].properties.aspectMask; 20885db71995Sopenharmony_ci equal = equal && props1[i].imageGranularity.width == props2[i].properties.imageGranularity.width; 20895db71995Sopenharmony_ci equal = equal && props1[i].imageGranularity.height == props2[i].properties.imageGranularity.height; 20905db71995Sopenharmony_ci equal = equal && props1[i].imageGranularity.depth == props2[i].properties.imageGranularity.depth; 20915db71995Sopenharmony_ci equal = equal && props1[i].flags == props2[i].properties.flags; 20925db71995Sopenharmony_ci } 20935db71995Sopenharmony_ci return equal; 20945db71995Sopenharmony_ci} 20955db71995Sopenharmony_ci 20965db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSparseImageFormatProperties2KHR where instance and ICD supports it, but device does not support it. 20975db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSparseImageFormatProps2KHRInstanceAndICDSupport) { 20985db71995Sopenharmony_ci FrameworkEnvironment env{}; 20995db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 21005db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 21015db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 21025db71995Sopenharmony_ci FillInRandomSparseImageFormatData(env.get_test_icd(0).physical_devices.back().sparse_image_format_properties); 21035db71995Sopenharmony_ci 21045db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 21055db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); 21065db71995Sopenharmony_ci instance.CheckCreate(); 21075db71995Sopenharmony_ci 21085db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR GetPhysDevSparseImageFormatProps2KHR = 21095db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2KHR"); 21105db71995Sopenharmony_ci ASSERT_NE(GetPhysDevSparseImageFormatProps2KHR, nullptr); 21115db71995Sopenharmony_ci 21125db71995Sopenharmony_ci uint32_t driver_count = 1; 21135db71995Sopenharmony_ci VkPhysicalDevice physical_device; 21145db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 21155db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 21165db71995Sopenharmony_ci 21175db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties> props{}; 21185db71995Sopenharmony_ci uint32_t sparse_count_1 = 0; 21195db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 21205db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 21215db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, nullptr); 21225db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 21235db71995Sopenharmony_ci props.resize(sparse_count_1); 21245db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 21255db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 21265db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, props.data()); 21275db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 21285db71995Sopenharmony_ci 21295db71995Sopenharmony_ci VkPhysicalDeviceSparseImageFormatInfo2 info2{ 21305db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, // sType 21315db71995Sopenharmony_ci nullptr, // pNext 21325db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 21335db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 21345db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, // samples 21355db71995Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT, // usage 21365db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 21375db71995Sopenharmony_ci }; 21385db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties2> props2{}; 21395db71995Sopenharmony_ci uint32_t sparse_count_2 = 0; 21405db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2KHR(physical_device, &info2, &sparse_count_2, nullptr); 21415db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 21425db71995Sopenharmony_ci props2.resize(sparse_count_2, VkSparseImageFormatProperties2{VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2}); 21435db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2KHR(physical_device, &info2, &sparse_count_2, props2.data()); 21445db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 21455db71995Sopenharmony_ci ASSERT_TRUE(CompareSparseImageFormatData(props, props2)); 21465db71995Sopenharmony_ci} 21475db71995Sopenharmony_ci 21485db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSparseImageFormatProperties2 where instance supports, an ICD, and a device under that ICD 21495db71995Sopenharmony_ci// also support, so everything should work and return properly. 21505db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 21515db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSparseImageFormatProps2Simple) { 21525db71995Sopenharmony_ci FrameworkEnvironment env{}; 21535db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 21545db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 21555db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 21565db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 21575db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 21585db71995Sopenharmony_ci FillInRandomSparseImageFormatData(env.get_test_icd(0).physical_devices.back().sparse_image_format_properties); 21595db71995Sopenharmony_ci { 21605db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 21615db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 21625db71995Sopenharmony_ci instance.CheckCreate(); 21635db71995Sopenharmony_ci 21645db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 GetPhysDevSparseImageFormatProps2 = 21655db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2"); 21665db71995Sopenharmony_ci ASSERT_NE(GetPhysDevSparseImageFormatProps2, nullptr); 21675db71995Sopenharmony_ci 21685db71995Sopenharmony_ci uint32_t driver_count = 1; 21695db71995Sopenharmony_ci VkPhysicalDevice physical_device; 21705db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 21715db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 21725db71995Sopenharmony_ci 21735db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties> props{}; 21745db71995Sopenharmony_ci uint32_t sparse_count_1 = 0; 21755db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 21765db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 21775db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, nullptr); 21785db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 21795db71995Sopenharmony_ci props.resize(sparse_count_1); 21805db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 21815db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 21825db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, props.data()); 21835db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 21845db71995Sopenharmony_ci 21855db71995Sopenharmony_ci VkPhysicalDeviceSparseImageFormatInfo2 info2{ 21865db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, // sType 21875db71995Sopenharmony_ci nullptr, // pNext 21885db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 21895db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 21905db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, // samples 21915db71995Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT, // usage 21925db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 21935db71995Sopenharmony_ci }; 21945db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties2> props2{}; 21955db71995Sopenharmony_ci uint32_t sparse_count_2 = 0; 21965db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, nullptr); 21975db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 21985db71995Sopenharmony_ci props2.resize(sparse_count_2, VkSparseImageFormatProperties2{VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2}); 21995db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, props2.data()); 22005db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 22015db71995Sopenharmony_ci ASSERT_TRUE(CompareSparseImageFormatData(props, props2)); 22025db71995Sopenharmony_ci } 22035db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 22045db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 22055db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 22065db71995Sopenharmony_ci instance.CheckCreate(); 22075db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 22085db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 22095db71995Sopenharmony_ci 22105db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 GetPhysDevSparseImageFormatProps2 = 22115db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2"); 22125db71995Sopenharmony_ci ASSERT_NE(GetPhysDevSparseImageFormatProps2, nullptr); 22135db71995Sopenharmony_ci 22145db71995Sopenharmony_ci uint32_t driver_count = 1; 22155db71995Sopenharmony_ci VkPhysicalDevice physical_device; 22165db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 22175db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 22185db71995Sopenharmony_ci 22195db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties> props{}; 22205db71995Sopenharmony_ci uint32_t sparse_count_1 = 0; 22215db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 22225db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 22235db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, nullptr); 22245db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 22255db71995Sopenharmony_ci props.resize(sparse_count_1); 22265db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 22275db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 22285db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, props.data()); 22295db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 22305db71995Sopenharmony_ci 22315db71995Sopenharmony_ci VkPhysicalDeviceSparseImageFormatInfo2 info2{ 22325db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, // sType 22335db71995Sopenharmony_ci nullptr, // pNext 22345db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 22355db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 22365db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, // samples 22375db71995Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT, // usage 22385db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 22395db71995Sopenharmony_ci }; 22405db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties2> props2{}; 22415db71995Sopenharmony_ci uint32_t sparse_count_2 = 0; 22425db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, nullptr); 22435db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 22445db71995Sopenharmony_ci props2.resize(sparse_count_2, VkSparseImageFormatProperties2{VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2}); 22455db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, props2.data()); 22465db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 22475db71995Sopenharmony_ci ASSERT_TRUE(CompareSparseImageFormatData(props, props2)); 22485db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 22495db71995Sopenharmony_ci } 22505db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 22515db71995Sopenharmony_ci .set_name("modify_api_version_layer") 22525db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 22535db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 22545db71995Sopenharmony_ci "modify_api_version_layer.json"); 22555db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 22565db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 22575db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 22585db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 22595db71995Sopenharmony_ci instance.CheckCreate(); 22605db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 22615db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 22625db71995Sopenharmony_ci 22635db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 GetPhysDevSparseImageFormatProps2 = 22645db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2"); 22655db71995Sopenharmony_ci ASSERT_NE(GetPhysDevSparseImageFormatProps2, nullptr); 22665db71995Sopenharmony_ci 22675db71995Sopenharmony_ci uint32_t driver_count = 1; 22685db71995Sopenharmony_ci VkPhysicalDevice physical_device; 22695db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 22705db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 22715db71995Sopenharmony_ci 22725db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties> props{}; 22735db71995Sopenharmony_ci uint32_t sparse_count_1 = 0; 22745db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 22755db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 22765db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, nullptr); 22775db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 22785db71995Sopenharmony_ci props.resize(sparse_count_1); 22795db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 22805db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 22815db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, props.data()); 22825db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 22835db71995Sopenharmony_ci 22845db71995Sopenharmony_ci VkPhysicalDeviceSparseImageFormatInfo2 info2{ 22855db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, // sType 22865db71995Sopenharmony_ci nullptr, // pNext 22875db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 22885db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 22895db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, // samples 22905db71995Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT, // usage 22915db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 22925db71995Sopenharmony_ci }; 22935db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties2> props2{}; 22945db71995Sopenharmony_ci uint32_t sparse_count_2 = 0; 22955db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, nullptr); 22965db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 22975db71995Sopenharmony_ci props2.resize(sparse_count_2, VkSparseImageFormatProperties2{VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2}); 22985db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, props2.data()); 22995db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 23005db71995Sopenharmony_ci ASSERT_TRUE(CompareSparseImageFormatData(props, props2)); 23015db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 23025db71995Sopenharmony_ci } 23035db71995Sopenharmony_ci} 23045db71995Sopenharmony_ci 23055db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSparseImageFormatProperties2 and vkGetPhysicalDeviceSparseImageFormatProperties2KHR where ICD is 1.0 and 23065db71995Sopenharmony_ci// supports extension but the instance supports 1.1 and the extension 23075db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSparseImageFormatProps2KHRInstanceSupports11) { 23085db71995Sopenharmony_ci FrameworkEnvironment env{}; 23095db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 23105db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 23115db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 23125db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 23135db71995Sopenharmony_ci FillInRandomSparseImageFormatData(env.get_test_icd(0).physical_devices.back().sparse_image_format_properties); 23145db71995Sopenharmony_ci 23155db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 23165db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 23175db71995Sopenharmony_ci instance.create_info.add_extensions( 23185db71995Sopenharmony_ci {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 23195db71995Sopenharmony_ci instance.CheckCreate(); 23205db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 23215db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 23225db71995Sopenharmony_ci 23235db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 GetPhysDevSparseImageFormatProps2 = 23245db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2"); 23255db71995Sopenharmony_ci ASSERT_NE(GetPhysDevSparseImageFormatProps2, nullptr); 23265db71995Sopenharmony_ci 23275db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR GetPhysDevSparseImageFormatProps2KHR = 23285db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2KHR"); 23295db71995Sopenharmony_ci ASSERT_NE(GetPhysDevSparseImageFormatProps2KHR, nullptr); 23305db71995Sopenharmony_ci 23315db71995Sopenharmony_ci uint32_t driver_count = 1; 23325db71995Sopenharmony_ci VkPhysicalDevice physical_device; 23335db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 23345db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 23355db71995Sopenharmony_ci 23365db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties> props{}; 23375db71995Sopenharmony_ci uint32_t sparse_count_1 = 0; 23385db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 23395db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 23405db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, nullptr); 23415db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 23425db71995Sopenharmony_ci props.resize(sparse_count_1); 23435db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, 23445db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 23455db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, props.data()); 23465db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 23475db71995Sopenharmony_ci 23485db71995Sopenharmony_ci VkPhysicalDeviceSparseImageFormatInfo2 info2{ 23495db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, // sType 23505db71995Sopenharmony_ci nullptr, // pNext 23515db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 23525db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 23535db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, // samples 23545db71995Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT, // usage 23555db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 23565db71995Sopenharmony_ci }; 23575db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties2> props2{}; 23585db71995Sopenharmony_ci uint32_t sparse_count_2 = 0; 23595db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, nullptr); 23605db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 23615db71995Sopenharmony_ci props2.resize(sparse_count_2, VkSparseImageFormatProperties2{VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2}); 23625db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_device, &info2, &sparse_count_2, props2.data()); 23635db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 23645db71995Sopenharmony_ci ASSERT_TRUE(CompareSparseImageFormatData(props, props2)); 23655db71995Sopenharmony_ci 23665db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties2KHR> props2KHR{}; 23675db71995Sopenharmony_ci uint32_t sparse_count_2_khr = 0; 23685db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2KHR(physical_device, &info2, &sparse_count_2_khr, nullptr); 23695db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2_khr); 23705db71995Sopenharmony_ci props2KHR.resize(sparse_count_2, VkSparseImageFormatProperties2KHR{VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2_KHR}); 23715db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2KHR(physical_device, &info2, &sparse_count_2_khr, props2KHR.data()); 23725db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2_khr); 23735db71995Sopenharmony_ci ASSERT_TRUE(CompareSparseImageFormatData(props, props2KHR)); 23745db71995Sopenharmony_ci 23755db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 23765db71995Sopenharmony_ci} 23775db71995Sopenharmony_ci 23785db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSparseImageFormatProperties2 where instance supports it with some ICDs that both support 23795db71995Sopenharmony_ci// and don't support it: 23805db71995Sopenharmony_ci// ICD 0 supports 23815db71995Sopenharmony_ci// Physical device 0 does not 23825db71995Sopenharmony_ci// Physical device 1 does 23835db71995Sopenharmony_ci// Physical device 2 does not 23845db71995Sopenharmony_ci// ICD 1 doesn't support 23855db71995Sopenharmony_ci// Physical device 3 does not 23865db71995Sopenharmony_ci// ICD 2 supports 23875db71995Sopenharmony_ci// Physical device 4 does not 23885db71995Sopenharmony_ci// Physical device 5 does not 23895db71995Sopenharmony_ci// ICD 3 supports 23905db71995Sopenharmony_ci// Physical device 6 does 23915db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSparseImageFormatPropsMixed) { 23925db71995Sopenharmony_ci FrameworkEnvironment env{}; 23935db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 23945db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 23955db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 23965db71995Sopenharmony_ci 23975db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 23985db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 23995db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 24005db71995Sopenharmony_ci 24015db71995Sopenharmony_ci // ICD 1 should not have 1.1 24025db71995Sopenharmony_ci if (icd != 1) { 24035db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 24045db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME}); 24055db71995Sopenharmony_ci } 24065db71995Sopenharmony_ci 24075db71995Sopenharmony_ci uint32_t rand_vendor_id; 24085db71995Sopenharmony_ci uint32_t rand_driver_vers; 24095db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 24105db71995Sopenharmony_ci 24115db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 24125db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 24135db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 24145db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 24155db71995Sopenharmony_ci 24165db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 24175db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 24185db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0}); 24195db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 24205db71995Sopenharmony_ci } 24215db71995Sopenharmony_ci 24225db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 24235db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 24245db71995Sopenharmony_ci FillInRandomSparseImageFormatData(cur_dev.sparse_image_format_properties); 24255db71995Sopenharmony_ci } 24265db71995Sopenharmony_ci } 24275db71995Sopenharmony_ci 24285db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 24295db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 24305db71995Sopenharmony_ci instance.CheckCreate(); 24315db71995Sopenharmony_ci 24325db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 GetPhysDevSparseImageFormatProps2 = 24335db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSparseImageFormatProperties2"); 24345db71995Sopenharmony_ci ASSERT_NE(GetPhysDevSparseImageFormatProps2, nullptr); 24355db71995Sopenharmony_ci 24365db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 24375db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 24385db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 24395db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 24405db71995Sopenharmony_ci 24415db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 24425db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties> props{}; 24435db71995Sopenharmony_ci uint32_t sparse_count_1 = 0; 24445db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties( 24455db71995Sopenharmony_ci physical_devices[dev], VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 24465db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, nullptr); 24475db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 24485db71995Sopenharmony_ci props.resize(sparse_count_1); 24495db71995Sopenharmony_ci instance->vkGetPhysicalDeviceSparseImageFormatProperties( 24505db71995Sopenharmony_ci physical_devices[dev], VK_FORMAT_R4G4_UNORM_PACK8, VK_IMAGE_TYPE_2D, VK_SAMPLE_COUNT_4_BIT, VK_IMAGE_USAGE_STORAGE_BIT, 24515db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, &sparse_count_1, props.data()); 24525db71995Sopenharmony_ci ASSERT_NE(sparse_count_1, 0U); 24535db71995Sopenharmony_ci 24545db71995Sopenharmony_ci VkPhysicalDeviceSparseImageFormatInfo2 info2{ 24555db71995Sopenharmony_ci VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, // sType 24565db71995Sopenharmony_ci nullptr, // pNext 24575db71995Sopenharmony_ci VK_FORMAT_R4G4_UNORM_PACK8, // format 24585db71995Sopenharmony_ci VK_IMAGE_TYPE_2D, // type 24595db71995Sopenharmony_ci VK_SAMPLE_COUNT_4_BIT, // samples 24605db71995Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT, // usage 24615db71995Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // tiling 24625db71995Sopenharmony_ci }; 24635db71995Sopenharmony_ci std::vector<VkSparseImageFormatProperties2> props2{}; 24645db71995Sopenharmony_ci uint32_t sparse_count_2 = 0; 24655db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_devices[dev], &info2, &sparse_count_2, nullptr); 24665db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 24675db71995Sopenharmony_ci props2.resize(sparse_count_2, VkSparseImageFormatProperties2{VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2}); 24685db71995Sopenharmony_ci GetPhysDevSparseImageFormatProps2(physical_devices[dev], &info2, &sparse_count_2, props2.data()); 24695db71995Sopenharmony_ci ASSERT_EQ(sparse_count_1, sparse_count_2); 24705db71995Sopenharmony_ci ASSERT_TRUE(CompareSparseImageFormatData(props, props2)); 24715db71995Sopenharmony_ci } 24725db71995Sopenharmony_ci} 24735db71995Sopenharmony_ci 24745db71995Sopenharmony_ci// 24755db71995Sopenharmony_ci// VK_KHR_external_memory_capabilities 24765db71995Sopenharmony_ci// 24775db71995Sopenharmony_ci 24785db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalBufferPropertiesKHR where nothing supports it. 24795db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtBufPropsKHRNoSupport) { 24805db71995Sopenharmony_ci FrameworkEnvironment env{}; 24815db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 24825db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 24835db71995Sopenharmony_ci 24845db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 24855db71995Sopenharmony_ci instance.CheckCreate(); 24865db71995Sopenharmony_ci 24875db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR GetPhysicalDeviceExternalBufferPropertiesKHR = 24885db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalBufferPropertiesKHR"); 24895db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceExternalBufferPropertiesKHR, nullptr); 24905db71995Sopenharmony_ci} 24915db71995Sopenharmony_ci 24925db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalBufferPropertiesKHR where instance supports it, but nothing else. 24935db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtBufPropsKHRNoICDSupport) { 24945db71995Sopenharmony_ci FrameworkEnvironment env{}; 24955db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 24965db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 24975db71995Sopenharmony_ci 24985db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 24995db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME); 25005db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 25015db71995Sopenharmony_ci 25025db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR GetPhysicalDeviceExternalBufferPropertiesKHR = 25035db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalBufferPropertiesKHR"); 25045db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceExternalBufferPropertiesKHR, nullptr); 25055db71995Sopenharmony_ci} 25065db71995Sopenharmony_ci 25075db71995Sopenharmony_ci// Fill in random but valid data into the external memorydata struct for the current physical device 25085db71995Sopenharmony_civoid FillInRandomExtMemoryData(VkExternalMemoryProperties& props) { 25095db71995Sopenharmony_ci props.externalMemoryFeatures = static_cast<VkExternalMemoryFeatureFlags>((rand() % 6) + 1); 25105db71995Sopenharmony_ci props.exportFromImportedHandleTypes = static_cast<VkExternalMemoryHandleTypeFlags>((rand() % 0x1FFE) + 1); 25115db71995Sopenharmony_ci props.compatibleHandleTypes = static_cast<VkExternalMemoryHandleTypeFlags>((rand() % 0x1FFE) + 1); 25125db71995Sopenharmony_ci} 25135db71995Sopenharmony_ci 25145db71995Sopenharmony_ci// Compare the external memory data structs 25155db71995Sopenharmony_cibool CompareExtMemoryData(const VkExternalMemoryProperties& props1, const VkExternalMemoryProperties& props2, 25165db71995Sopenharmony_ci bool supported = true) { 25175db71995Sopenharmony_ci bool equal = true; 25185db71995Sopenharmony_ci if (supported) { 25195db71995Sopenharmony_ci equal = equal && props1.externalMemoryFeatures == props2.externalMemoryFeatures; 25205db71995Sopenharmony_ci equal = equal && props1.exportFromImportedHandleTypes == props2.exportFromImportedHandleTypes; 25215db71995Sopenharmony_ci equal = equal && props1.compatibleHandleTypes == props2.compatibleHandleTypes; 25225db71995Sopenharmony_ci } else { 25235db71995Sopenharmony_ci equal = equal && 0 == props2.externalMemoryFeatures; 25245db71995Sopenharmony_ci equal = equal && 0 == props2.exportFromImportedHandleTypes; 25255db71995Sopenharmony_ci equal = equal && 0 == props2.compatibleHandleTypes; 25265db71995Sopenharmony_ci } 25275db71995Sopenharmony_ci return equal; 25285db71995Sopenharmony_ci} 25295db71995Sopenharmony_ci 25305db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalBufferPropertiesKHR where instance and ICD supports it, but device does not support it. 25315db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtBufProps2KHRInstanceAndICDSupport) { 25325db71995Sopenharmony_ci FrameworkEnvironment env{}; 25335db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 25345db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME}); 25355db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 25365db71995Sopenharmony_ci FillInRandomExtMemoryData(env.get_test_icd(0).physical_devices.back().external_memory_properties); 25375db71995Sopenharmony_ci 25385db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 25395db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME); 25405db71995Sopenharmony_ci instance.CheckCreate(); 25415db71995Sopenharmony_ci 25425db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR GetPhysicalDeviceExternalBufferPropertiesKHR = 25435db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalBufferPropertiesKHR"); 25445db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalBufferPropertiesKHR, nullptr); 25455db71995Sopenharmony_ci 25465db71995Sopenharmony_ci uint32_t driver_count = 1; 25475db71995Sopenharmony_ci VkPhysicalDevice physical_device; 25485db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 25495db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 25505db71995Sopenharmony_ci 25515db71995Sopenharmony_ci VkPhysicalDeviceExternalBufferInfoKHR info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO_KHR}; 25525db71995Sopenharmony_ci VkExternalBufferPropertiesKHR props{VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES_KHR}; 25535db71995Sopenharmony_ci GetPhysicalDeviceExternalBufferPropertiesKHR(physical_device, &info, &props); 25545db71995Sopenharmony_ci ASSERT_TRUE(CompareExtMemoryData(env.get_test_icd(0).physical_devices.back().external_memory_properties, 25555db71995Sopenharmony_ci props.externalMemoryProperties)); 25565db71995Sopenharmony_ci} 25575db71995Sopenharmony_ci 25585db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalBufferProperties where instance supports, an ICD, and a device under that ICD 25595db71995Sopenharmony_ci// also support, so everything should work and return properly. 25605db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 25615db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtBufProps2Simple) { 25625db71995Sopenharmony_ci FrameworkEnvironment env{}; 25635db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 25645db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 25655db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME}); 25665db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 25675db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 0}); 25685db71995Sopenharmony_ci FillInRandomExtMemoryData(env.get_test_icd(0).physical_devices.back().external_memory_properties); 25695db71995Sopenharmony_ci { 25705db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 25715db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 25725db71995Sopenharmony_ci instance.CheckCreate(); 25735db71995Sopenharmony_ci 25745db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties = 25755db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalBufferProperties"); 25765db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalBufferProperties, nullptr); 25775db71995Sopenharmony_ci 25785db71995Sopenharmony_ci uint32_t driver_count = 1; 25795db71995Sopenharmony_ci VkPhysicalDevice physical_device; 25805db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 25815db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 25825db71995Sopenharmony_ci 25835db71995Sopenharmony_ci VkPhysicalDeviceExternalBufferInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO}; 25845db71995Sopenharmony_ci VkExternalBufferProperties props{VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES}; 25855db71995Sopenharmony_ci GetPhysicalDeviceExternalBufferProperties(physical_device, &info, &props); 25865db71995Sopenharmony_ci ASSERT_TRUE(CompareExtMemoryData(env.get_test_icd(0).physical_devices.back().external_memory_properties, 25875db71995Sopenharmony_ci props.externalMemoryProperties)); 25885db71995Sopenharmony_ci } 25895db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 25905db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 25915db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 25925db71995Sopenharmony_ci instance.CheckCreate(); 25935db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 25945db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 25955db71995Sopenharmony_ci 25965db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties = 25975db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalBufferProperties"); 25985db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalBufferProperties, nullptr); 25995db71995Sopenharmony_ci 26005db71995Sopenharmony_ci uint32_t driver_count = 1; 26015db71995Sopenharmony_ci VkPhysicalDevice physical_device; 26025db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 26035db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 26045db71995Sopenharmony_ci 26055db71995Sopenharmony_ci VkPhysicalDeviceExternalBufferInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO}; 26065db71995Sopenharmony_ci VkExternalBufferProperties props{VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES}; 26075db71995Sopenharmony_ci GetPhysicalDeviceExternalBufferProperties(physical_device, &info, &props); 26085db71995Sopenharmony_ci // Compare against 'zeroed' out VkExternalMemoryProperties 26095db71995Sopenharmony_ci ASSERT_TRUE(CompareExtMemoryData(VkExternalMemoryProperties{}, props.externalMemoryProperties)); 26105db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 26115db71995Sopenharmony_ci } 26125db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 26135db71995Sopenharmony_ci .set_name("modify_api_version_layer") 26145db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 26155db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 26165db71995Sopenharmony_ci "modify_api_version_layer.json"); 26175db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 26185db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 26195db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 26205db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 26215db71995Sopenharmony_ci instance.CheckCreate(); 26225db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 26235db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 26245db71995Sopenharmony_ci 26255db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties = 26265db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalBufferProperties"); 26275db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalBufferProperties, nullptr); 26285db71995Sopenharmony_ci 26295db71995Sopenharmony_ci uint32_t driver_count = 1; 26305db71995Sopenharmony_ci VkPhysicalDevice physical_device; 26315db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 26325db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 26335db71995Sopenharmony_ci 26345db71995Sopenharmony_ci VkPhysicalDeviceExternalBufferInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO}; 26355db71995Sopenharmony_ci VkExternalBufferProperties props{VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES}; 26365db71995Sopenharmony_ci GetPhysicalDeviceExternalBufferProperties(physical_device, &info, &props); 26375db71995Sopenharmony_ci ASSERT_TRUE(CompareExtMemoryData(env.get_test_icd(0).physical_devices.back().external_memory_properties, 26385db71995Sopenharmony_ci props.externalMemoryProperties)); 26395db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 26405db71995Sopenharmony_ci } 26415db71995Sopenharmony_ci} 26425db71995Sopenharmony_ci 26435db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalBufferProperties where instance supports it with some ICDs that both support 26445db71995Sopenharmony_ci// and don't support it: 26455db71995Sopenharmony_ci// ICD 0 supports 26465db71995Sopenharmony_ci// Physical device 0 does not 26475db71995Sopenharmony_ci// Physical device 1 does 26485db71995Sopenharmony_ci// Physical device 2 does not 26495db71995Sopenharmony_ci// ICD 1 doesn't support 26505db71995Sopenharmony_ci// Physical device 3 does not 26515db71995Sopenharmony_ci// ICD 2 supports 26525db71995Sopenharmony_ci// Physical device 4 does not 26535db71995Sopenharmony_ci// Physical device 5 does not 26545db71995Sopenharmony_ci// ICD 3 supports 26555db71995Sopenharmony_ci// Physical device 6 does 26565db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtBufPropsMixed) { 26575db71995Sopenharmony_ci FrameworkEnvironment env{}; 26585db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 26595db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 26605db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 26615db71995Sopenharmony_ci 26625db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 26635db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 26645db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 26655db71995Sopenharmony_ci 26665db71995Sopenharmony_ci // ICD 1 should not have 1.1 26675db71995Sopenharmony_ci if (icd != 1) { 26685db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 26695db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME}); 26705db71995Sopenharmony_ci } 26715db71995Sopenharmony_ci 26725db71995Sopenharmony_ci uint32_t rand_vendor_id; 26735db71995Sopenharmony_ci uint32_t rand_driver_vers; 26745db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 26755db71995Sopenharmony_ci 26765db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 26775db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 26785db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 26795db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 26805db71995Sopenharmony_ci 26815db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 26825db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 26835db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 0}); 26845db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 26855db71995Sopenharmony_ci } 26865db71995Sopenharmony_ci 26875db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 26885db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 26895db71995Sopenharmony_ci FillInRandomExtMemoryData(cur_dev.external_memory_properties); 26905db71995Sopenharmony_ci } 26915db71995Sopenharmony_ci } 26925db71995Sopenharmony_ci 26935db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 26945db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 26955db71995Sopenharmony_ci instance.CheckCreate(); 26965db71995Sopenharmony_ci 26975db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties = 26985db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalBufferProperties"); 26995db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalBufferProperties, nullptr); 27005db71995Sopenharmony_ci 27015db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 27025db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 27035db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 27045db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 27055db71995Sopenharmony_ci 27065db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 27075db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 27085db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 27095db71995Sopenharmony_ci 27105db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 27115db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 27125db71995Sopenharmony_ci bool found = false; 27135db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 27145db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 27155db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 27165db71995Sopenharmony_ci // physical devices info with the returned info. 27175db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 27185db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 27195db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 27205db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 27215db71995Sopenharmony_ci VkPhysicalDeviceExternalBufferInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO}; 27225db71995Sopenharmony_ci VkExternalBufferProperties props{VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES}; 27235db71995Sopenharmony_ci GetPhysicalDeviceExternalBufferProperties(physical_devices[dev], &info, &props); 27245db71995Sopenharmony_ci // No driver support for extension or 1.1 for ICD 1, all others support 27255db71995Sopenharmony_ci ASSERT_TRUE(CompareExtMemoryData(cur_dev.external_memory_properties, props.externalMemoryProperties, icd != 1)); 27265db71995Sopenharmony_ci found = true; 27275db71995Sopenharmony_ci break; 27285db71995Sopenharmony_ci } 27295db71995Sopenharmony_ci } 27305db71995Sopenharmony_ci if (found) { 27315db71995Sopenharmony_ci break; 27325db71995Sopenharmony_ci } 27335db71995Sopenharmony_ci } 27345db71995Sopenharmony_ci } 27355db71995Sopenharmony_ci} 27365db71995Sopenharmony_ci 27375db71995Sopenharmony_ci// 27385db71995Sopenharmony_ci// VK_KHR_external_semaphore_capabilities 27395db71995Sopenharmony_ci// 27405db71995Sopenharmony_ci 27415db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalSemaphorePropertiesKHR where nothing supports it. 27425db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtSemPropsKHRNoSupport) { 27435db71995Sopenharmony_ci FrameworkEnvironment env{}; 27445db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 27455db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 27465db71995Sopenharmony_ci 27475db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 27485db71995Sopenharmony_ci instance.CheckCreate(); 27495db71995Sopenharmony_ci 27505db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR GetPhysicalDeviceExternalSemaphorePropertiesKHR = 27515db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"); 27525db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceExternalSemaphorePropertiesKHR, nullptr); 27535db71995Sopenharmony_ci} 27545db71995Sopenharmony_ci 27555db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalSemaphorePropertiesKHR where instance supports it, but nothing else. 27565db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtSemPropsKHRNoICDSupport) { 27575db71995Sopenharmony_ci FrameworkEnvironment env{}; 27585db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 27595db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 27605db71995Sopenharmony_ci 27615db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 27625db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME); 27635db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 27645db71995Sopenharmony_ci 27655db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR GetPhysicalDeviceExternalSemaphorePropertiesKHR = 27665db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"); 27675db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceExternalSemaphorePropertiesKHR, nullptr); 27685db71995Sopenharmony_ci} 27695db71995Sopenharmony_ci 27705db71995Sopenharmony_ci// Fill in random but valid data into the external semaphore data struct for the current physical device 27715db71995Sopenharmony_civoid FillInRandomExtSemData(VkExternalSemaphoreProperties& props) { 27725db71995Sopenharmony_ci props.sType = VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES; 27735db71995Sopenharmony_ci props.pNext = nullptr; 27745db71995Sopenharmony_ci props.exportFromImportedHandleTypes = static_cast<VkExternalSemaphoreHandleTypeFlags>((rand() % 0xFFF) + 1); 27755db71995Sopenharmony_ci props.compatibleHandleTypes = static_cast<VkExternalSemaphoreHandleTypeFlags>((rand() % 0xFFF) + 1); 27765db71995Sopenharmony_ci props.externalSemaphoreFeatures = static_cast<VkExternalSemaphoreFeatureFlags>((rand() % 0xFFF) + 1); 27775db71995Sopenharmony_ci} 27785db71995Sopenharmony_ci 27795db71995Sopenharmony_ci// Compare the external semaphore data structs 27805db71995Sopenharmony_cibool CompareExtSemaphoreData(const VkExternalSemaphoreProperties& props1, const VkExternalSemaphoreProperties& props2, 27815db71995Sopenharmony_ci bool supported = true) { 27825db71995Sopenharmony_ci bool equal = true; 27835db71995Sopenharmony_ci if (supported) { 27845db71995Sopenharmony_ci equal = equal && props1.externalSemaphoreFeatures == props2.externalSemaphoreFeatures; 27855db71995Sopenharmony_ci equal = equal && props1.exportFromImportedHandleTypes == props2.exportFromImportedHandleTypes; 27865db71995Sopenharmony_ci equal = equal && props1.compatibleHandleTypes == props2.compatibleHandleTypes; 27875db71995Sopenharmony_ci } else { 27885db71995Sopenharmony_ci equal = equal && 0 == props2.externalSemaphoreFeatures; 27895db71995Sopenharmony_ci equal = equal && 0 == props2.exportFromImportedHandleTypes; 27905db71995Sopenharmony_ci equal = equal && 0 == props2.compatibleHandleTypes; 27915db71995Sopenharmony_ci } 27925db71995Sopenharmony_ci return equal; 27935db71995Sopenharmony_ci} 27945db71995Sopenharmony_ci 27955db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalSemaphorePropertiesKHR where instance and ICD supports it, but device does not support it. 27965db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtSemProps2KHRInstanceAndICDSupport) { 27975db71995Sopenharmony_ci FrameworkEnvironment env{}; 27985db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 27995db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME}); 28005db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 28015db71995Sopenharmony_ci FillInRandomExtSemData(env.get_test_icd(0).physical_devices.back().external_semaphore_properties); 28025db71995Sopenharmony_ci 28035db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 28045db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME); 28055db71995Sopenharmony_ci instance.CheckCreate(); 28065db71995Sopenharmony_ci 28075db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR GetPhysicalDeviceExternalSemaphorePropertiesKHR = 28085db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"); 28095db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalSemaphorePropertiesKHR, nullptr); 28105db71995Sopenharmony_ci 28115db71995Sopenharmony_ci uint32_t driver_count = 1; 28125db71995Sopenharmony_ci VkPhysicalDevice physical_device; 28135db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 28145db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 28155db71995Sopenharmony_ci 28165db71995Sopenharmony_ci VkPhysicalDeviceExternalSemaphoreInfoKHR info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO_KHR}; 28175db71995Sopenharmony_ci VkExternalSemaphorePropertiesKHR props{VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES_KHR}; 28185db71995Sopenharmony_ci GetPhysicalDeviceExternalSemaphorePropertiesKHR(physical_device, &info, &props); 28195db71995Sopenharmony_ci ASSERT_TRUE(CompareExtSemaphoreData(env.get_test_icd(0).physical_devices.back().external_semaphore_properties, props)); 28205db71995Sopenharmony_ci} 28215db71995Sopenharmony_ci 28225db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalSemaphoreProperties where instance supports, an ICD, and a device under that ICD 28235db71995Sopenharmony_ci// also support, so everything should work and return properly. 28245db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 28255db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtSemProps2Simple) { 28265db71995Sopenharmony_ci FrameworkEnvironment env{}; 28275db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 28285db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 28295db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME}); 28305db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 28315db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, 0}); 28325db71995Sopenharmony_ci FillInRandomExtSemData(env.get_test_icd(0).physical_devices.back().external_semaphore_properties); 28335db71995Sopenharmony_ci { 28345db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 28355db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 28365db71995Sopenharmony_ci instance.CheckCreate(); 28375db71995Sopenharmony_ci 28385db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphoreProperties GetPhysicalDeviceExternalSemaphoreProperties = 28395db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalSemaphoreProperties"); 28405db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalSemaphoreProperties, nullptr); 28415db71995Sopenharmony_ci 28425db71995Sopenharmony_ci uint32_t driver_count = 1; 28435db71995Sopenharmony_ci VkPhysicalDevice physical_device; 28445db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 28455db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 28465db71995Sopenharmony_ci 28475db71995Sopenharmony_ci VkPhysicalDeviceExternalSemaphoreInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO}; 28485db71995Sopenharmony_ci VkExternalSemaphoreProperties props{VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES}; 28495db71995Sopenharmony_ci GetPhysicalDeviceExternalSemaphoreProperties(physical_device, &info, &props); 28505db71995Sopenharmony_ci ASSERT_TRUE(CompareExtSemaphoreData(env.get_test_icd(0).physical_devices.back().external_semaphore_properties, props)); 28515db71995Sopenharmony_ci } 28525db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 28535db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 28545db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 28555db71995Sopenharmony_ci instance.CheckCreate(); 28565db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 28575db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 28585db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphoreProperties GetPhysicalDeviceExternalSemaphoreProperties = 28595db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalSemaphoreProperties"); 28605db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalSemaphoreProperties, nullptr); 28615db71995Sopenharmony_ci 28625db71995Sopenharmony_ci uint32_t driver_count = 1; 28635db71995Sopenharmony_ci VkPhysicalDevice physical_device; 28645db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 28655db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 28665db71995Sopenharmony_ci 28675db71995Sopenharmony_ci VkPhysicalDeviceExternalSemaphoreInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO}; 28685db71995Sopenharmony_ci VkExternalSemaphoreProperties props{VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES}; 28695db71995Sopenharmony_ci GetPhysicalDeviceExternalSemaphoreProperties(physical_device, &info, &props); 28705db71995Sopenharmony_ci // Compare against 'zeroed' out VkExternalSemaphoreProperties 28715db71995Sopenharmony_ci ASSERT_TRUE(CompareExtSemaphoreData(VkExternalSemaphoreProperties{}, props)); 28725db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 28735db71995Sopenharmony_ci } 28745db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 28755db71995Sopenharmony_ci .set_name("modify_api_version_layer") 28765db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 28775db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 28785db71995Sopenharmony_ci "modify_api_version_layer.json"); 28795db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 28805db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 28815db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 28825db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 28835db71995Sopenharmony_ci instance.CheckCreate(); 28845db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 28855db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 28865db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphoreProperties GetPhysicalDeviceExternalSemaphoreProperties = 28875db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalSemaphoreProperties"); 28885db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalSemaphoreProperties, nullptr); 28895db71995Sopenharmony_ci 28905db71995Sopenharmony_ci uint32_t driver_count = 1; 28915db71995Sopenharmony_ci VkPhysicalDevice physical_device; 28925db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 28935db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 28945db71995Sopenharmony_ci 28955db71995Sopenharmony_ci VkPhysicalDeviceExternalSemaphoreInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO}; 28965db71995Sopenharmony_ci VkExternalSemaphoreProperties props{VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES}; 28975db71995Sopenharmony_ci GetPhysicalDeviceExternalSemaphoreProperties(physical_device, &info, &props); 28985db71995Sopenharmony_ci ASSERT_TRUE(CompareExtSemaphoreData(env.get_test_icd(0).physical_devices.back().external_semaphore_properties, props)); 28995db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 29005db71995Sopenharmony_ci } 29015db71995Sopenharmony_ci} 29025db71995Sopenharmony_ci 29035db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalSemaphoreProperties where instance supports it with some ICDs that both support 29045db71995Sopenharmony_ci// and don't support it: 29055db71995Sopenharmony_ci// ICD 0 supports 29065db71995Sopenharmony_ci// Physical device 0 does not 29075db71995Sopenharmony_ci// Physical device 1 does 29085db71995Sopenharmony_ci// Physical device 2 does not 29095db71995Sopenharmony_ci// ICD 1 doesn't support 29105db71995Sopenharmony_ci// Physical device 3 does not 29115db71995Sopenharmony_ci// ICD 2 supports 29125db71995Sopenharmony_ci// Physical device 4 does not 29135db71995Sopenharmony_ci// Physical device 5 does not 29145db71995Sopenharmony_ci// ICD 3 supports 29155db71995Sopenharmony_ci// Physical device 6 does 29165db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtSemPropsMixed) { 29175db71995Sopenharmony_ci FrameworkEnvironment env{}; 29185db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 29195db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 29205db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 29215db71995Sopenharmony_ci 29225db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 29235db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 29245db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 29255db71995Sopenharmony_ci 29265db71995Sopenharmony_ci // ICD 1 should not have 1.1 29275db71995Sopenharmony_ci if (icd != 1) { 29285db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 29295db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME}); 29305db71995Sopenharmony_ci } 29315db71995Sopenharmony_ci 29325db71995Sopenharmony_ci uint32_t rand_vendor_id; 29335db71995Sopenharmony_ci uint32_t rand_driver_vers; 29345db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 29355db71995Sopenharmony_ci 29365db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 29375db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 29385db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 29395db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 29405db71995Sopenharmony_ci 29415db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 29425db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 29435db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, 0}); 29445db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 29455db71995Sopenharmony_ci } 29465db71995Sopenharmony_ci 29475db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 29485db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 29495db71995Sopenharmony_ci FillInRandomExtSemData(cur_dev.external_semaphore_properties); 29505db71995Sopenharmony_ci } 29515db71995Sopenharmony_ci } 29525db71995Sopenharmony_ci 29535db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 29545db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 29555db71995Sopenharmony_ci instance.CheckCreate(); 29565db71995Sopenharmony_ci 29575db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphoreProperties GetPhysicalDeviceExternalSemaphoreProperties = 29585db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalSemaphoreProperties"); 29595db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalSemaphoreProperties, nullptr); 29605db71995Sopenharmony_ci 29615db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 29625db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 29635db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 29645db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 29655db71995Sopenharmony_ci 29665db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 29675db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 29685db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 29695db71995Sopenharmony_ci 29705db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 29715db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 29725db71995Sopenharmony_ci bool found = false; 29735db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 29745db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 29755db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 29765db71995Sopenharmony_ci // physical devices info with the returned info. 29775db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 29785db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 29795db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 29805db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 29815db71995Sopenharmony_ci VkPhysicalDeviceExternalSemaphoreInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO}; 29825db71995Sopenharmony_ci VkExternalSemaphoreProperties props{VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES}; 29835db71995Sopenharmony_ci GetPhysicalDeviceExternalSemaphoreProperties(physical_devices[dev], &info, &props); 29845db71995Sopenharmony_ci // No driver support for extension or 1.1 for ICD 1, all others support 29855db71995Sopenharmony_ci ASSERT_TRUE(CompareExtSemaphoreData(cur_dev.external_semaphore_properties, props, icd != 1)); 29865db71995Sopenharmony_ci found = true; 29875db71995Sopenharmony_ci break; 29885db71995Sopenharmony_ci } 29895db71995Sopenharmony_ci } 29905db71995Sopenharmony_ci if (found) { 29915db71995Sopenharmony_ci break; 29925db71995Sopenharmony_ci } 29935db71995Sopenharmony_ci } 29945db71995Sopenharmony_ci } 29955db71995Sopenharmony_ci} 29965db71995Sopenharmony_ci 29975db71995Sopenharmony_ci// 29985db71995Sopenharmony_ci// VK_KHR_external_fence_capabilities 29995db71995Sopenharmony_ci// 30005db71995Sopenharmony_ci 30015db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalFencePropertiesKHR where nothing supports it. 30025db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtFencePropsKHRNoSupport) { 30035db71995Sopenharmony_ci FrameworkEnvironment env{}; 30045db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 30055db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 30065db71995Sopenharmony_ci 30075db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 30085db71995Sopenharmony_ci instance.CheckCreate(); 30095db71995Sopenharmony_ci 30105db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR GetPhysicalDeviceExternalFencePropertiesKHR = 30115db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalFencePropertiesKHR"); 30125db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceExternalFencePropertiesKHR, nullptr); 30135db71995Sopenharmony_ci} 30145db71995Sopenharmony_ci 30155db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalFencePropertiesKHR where instance supports it, but nothing else. 30165db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtFencePropsKHRNoICDSupport) { 30175db71995Sopenharmony_ci FrameworkEnvironment env{}; 30185db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 30195db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 30205db71995Sopenharmony_ci 30215db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 30225db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME); 30235db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 30245db71995Sopenharmony_ci 30255db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR GetPhysicalDeviceExternalFencePropertiesKHR = 30265db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalFencePropertiesKHR"); 30275db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceExternalFencePropertiesKHR, nullptr); 30285db71995Sopenharmony_ci} 30295db71995Sopenharmony_ci 30305db71995Sopenharmony_ci// Fill in random but valid data into the external fence data struct for the current physical device 30315db71995Sopenharmony_civoid FillInRandomExtFenceData(VkExternalFenceProperties& props) { 30325db71995Sopenharmony_ci props.sType = VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES; 30335db71995Sopenharmony_ci props.pNext = nullptr; 30345db71995Sopenharmony_ci props.exportFromImportedHandleTypes = static_cast<VkExternalFenceHandleTypeFlags>((rand() % 0xFFF) + 1); 30355db71995Sopenharmony_ci props.compatibleHandleTypes = static_cast<VkExternalFenceHandleTypeFlags>((rand() % 0xFFF) + 1); 30365db71995Sopenharmony_ci props.externalFenceFeatures = static_cast<VkExternalFenceFeatureFlags>((rand() % 0xFFF) + 1); 30375db71995Sopenharmony_ci} 30385db71995Sopenharmony_ci 30395db71995Sopenharmony_ci// Compare the external fence data structs 30405db71995Sopenharmony_cibool CompareExtFenceData(const VkExternalFenceProperties& props1, const VkExternalFenceProperties& props2, bool supported = true) { 30415db71995Sopenharmony_ci bool equal = true; 30425db71995Sopenharmony_ci if (supported) { 30435db71995Sopenharmony_ci equal = equal && props1.externalFenceFeatures == props2.externalFenceFeatures; 30445db71995Sopenharmony_ci equal = equal && props1.exportFromImportedHandleTypes == props2.exportFromImportedHandleTypes; 30455db71995Sopenharmony_ci equal = equal && props1.compatibleHandleTypes == props2.compatibleHandleTypes; 30465db71995Sopenharmony_ci } else { 30475db71995Sopenharmony_ci equal = equal && 0 == props2.externalFenceFeatures; 30485db71995Sopenharmony_ci equal = equal && 0 == props2.exportFromImportedHandleTypes; 30495db71995Sopenharmony_ci equal = equal && 0 == props2.compatibleHandleTypes; 30505db71995Sopenharmony_ci } 30515db71995Sopenharmony_ci return equal; 30525db71995Sopenharmony_ci} 30535db71995Sopenharmony_ci 30545db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalFencePropertiesKHR where instance and ICD supports it, but device does not support it. 30555db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtFenceProps2KHRInstanceAndICDSupport) { 30565db71995Sopenharmony_ci FrameworkEnvironment env{}; 30575db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 30585db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME}); 30595db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 30605db71995Sopenharmony_ci FillInRandomExtFenceData(env.get_test_icd(0).physical_devices.back().external_fence_properties); 30615db71995Sopenharmony_ci 30625db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 30635db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME); 30645db71995Sopenharmony_ci instance.CheckCreate(); 30655db71995Sopenharmony_ci 30665db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR GetPhysicalDeviceExternalFencePropertiesKHR = 30675db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalFencePropertiesKHR"); 30685db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalFencePropertiesKHR, nullptr); 30695db71995Sopenharmony_ci 30705db71995Sopenharmony_ci uint32_t driver_count = 1; 30715db71995Sopenharmony_ci VkPhysicalDevice physical_device; 30725db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 30735db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 30745db71995Sopenharmony_ci 30755db71995Sopenharmony_ci VkPhysicalDeviceExternalFenceInfoKHR info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO_KHR}; 30765db71995Sopenharmony_ci VkExternalFencePropertiesKHR props{VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES_KHR}; 30775db71995Sopenharmony_ci GetPhysicalDeviceExternalFencePropertiesKHR(physical_device, &info, &props); 30785db71995Sopenharmony_ci ASSERT_TRUE(CompareExtFenceData(env.get_test_icd(0).physical_devices.back().external_fence_properties, props)); 30795db71995Sopenharmony_ci} 30805db71995Sopenharmony_ci 30815db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalFenceProperties where instance supports, an ICD, and a device under that ICD 30825db71995Sopenharmony_ci// also support, so everything should work and return properly. 30835db71995Sopenharmony_ci// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1 30845db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtFenceProps2Simple) { 30855db71995Sopenharmony_ci FrameworkEnvironment env{}; 30865db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 30875db71995Sopenharmony_ci env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1; 30885db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME}); 30895db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 30905db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, 0}); 30915db71995Sopenharmony_ci FillInRandomExtFenceData(env.get_test_icd(0).physical_devices.back().external_fence_properties); 30925db71995Sopenharmony_ci { 30935db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 30945db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 30955db71995Sopenharmony_ci instance.CheckCreate(); 30965db71995Sopenharmony_ci 30975db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFenceProperties GetPhysicalDeviceExternalFenceProperties = 30985db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalFenceProperties"); 30995db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalFenceProperties, nullptr); 31005db71995Sopenharmony_ci 31015db71995Sopenharmony_ci uint32_t driver_count = 1; 31025db71995Sopenharmony_ci VkPhysicalDevice physical_device; 31035db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 31045db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 31055db71995Sopenharmony_ci 31065db71995Sopenharmony_ci VkPhysicalDeviceExternalFenceInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO}; 31075db71995Sopenharmony_ci VkExternalFenceProperties props{VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES}; 31085db71995Sopenharmony_ci GetPhysicalDeviceExternalFenceProperties(physical_device, &info, &props); 31095db71995Sopenharmony_ci ASSERT_TRUE(CompareExtFenceData(env.get_test_icd(0).physical_devices.back().external_fence_properties, props)); 31105db71995Sopenharmony_ci } 31115db71995Sopenharmony_ci { // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call 31125db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 31135db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 31145db71995Sopenharmony_ci instance.CheckCreate(); 31155db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 31165db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 31175db71995Sopenharmony_ci 31185db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFenceProperties GetPhysicalDeviceExternalFenceProperties = 31195db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalFenceProperties"); 31205db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalFenceProperties, nullptr); 31215db71995Sopenharmony_ci 31225db71995Sopenharmony_ci uint32_t driver_count = 1; 31235db71995Sopenharmony_ci VkPhysicalDevice physical_device; 31245db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 31255db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 31265db71995Sopenharmony_ci 31275db71995Sopenharmony_ci VkPhysicalDeviceExternalFenceInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO}; 31285db71995Sopenharmony_ci VkExternalFenceProperties props{VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES}; 31295db71995Sopenharmony_ci GetPhysicalDeviceExternalFenceProperties(physical_device, &info, &props); 31305db71995Sopenharmony_ci // Compare against 'zeroed' out VkExternalFenceProperties 31315db71995Sopenharmony_ci ASSERT_TRUE(CompareExtFenceData(VkExternalFenceProperties{}, props)); 31325db71995Sopenharmony_ci ASSERT_TRUE(log.find("Emulating call in ICD")); 31335db71995Sopenharmony_ci } 31345db71995Sopenharmony_ci env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} 31355db71995Sopenharmony_ci .set_name("modify_api_version_layer") 31365db71995Sopenharmony_ci .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) 31375db71995Sopenharmony_ci .set_disable_environment("DisableEnvVar")), 31385db71995Sopenharmony_ci "modify_api_version_layer.json"); 31395db71995Sopenharmony_ci env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1); 31405db71995Sopenharmony_ci { // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application 31415db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 31425db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 31435db71995Sopenharmony_ci instance.CheckCreate(); 31445db71995Sopenharmony_ci DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT}; 31455db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 31465db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFenceProperties GetPhysicalDeviceExternalFenceProperties = 31475db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalFenceProperties"); 31485db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalFenceProperties, nullptr); 31495db71995Sopenharmony_ci 31505db71995Sopenharmony_ci uint32_t driver_count = 1; 31515db71995Sopenharmony_ci VkPhysicalDevice physical_device; 31525db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 31535db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 31545db71995Sopenharmony_ci 31555db71995Sopenharmony_ci VkPhysicalDeviceExternalFenceInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO}; 31565db71995Sopenharmony_ci VkExternalFenceProperties props{VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES}; 31575db71995Sopenharmony_ci GetPhysicalDeviceExternalFenceProperties(physical_device, &info, &props); 31585db71995Sopenharmony_ci ASSERT_TRUE(CompareExtFenceData(env.get_test_icd(0).physical_devices.back().external_fence_properties, props)); 31595db71995Sopenharmony_ci ASSERT_FALSE(log.find("Emulating call in ICD")); 31605db71995Sopenharmony_ci } 31615db71995Sopenharmony_ci} 31625db71995Sopenharmony_ci// Test vkGetPhysicalDeviceExternalFenceProperties where instance supports it with some ICDs that both support 31635db71995Sopenharmony_ci// and don't support it: 31645db71995Sopenharmony_ci// ICD 0 supports 31655db71995Sopenharmony_ci// Physical device 0 does not 31665db71995Sopenharmony_ci// Physical device 1 does 31675db71995Sopenharmony_ci// Physical device 2 does not 31685db71995Sopenharmony_ci// ICD 1 doesn't support 31695db71995Sopenharmony_ci// Physical device 3 does not 31705db71995Sopenharmony_ci// ICD 2 supports 31715db71995Sopenharmony_ci// Physical device 4 does not 31725db71995Sopenharmony_ci// Physical device 5 does not 31735db71995Sopenharmony_ci// ICD 3 supports 31745db71995Sopenharmony_ci// Physical device 6 does 31755db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevExtFencePropsMixed) { 31765db71995Sopenharmony_ci FrameworkEnvironment env{}; 31775db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 31785db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 31795db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 31805db71995Sopenharmony_ci 31815db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 31825db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 31835db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 31845db71995Sopenharmony_ci 31855db71995Sopenharmony_ci // ICD 1 should not have 1.1 31865db71995Sopenharmony_ci if (icd != 1) { 31875db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 31885db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME}); 31895db71995Sopenharmony_ci } 31905db71995Sopenharmony_ci 31915db71995Sopenharmony_ci uint32_t rand_vendor_id; 31925db71995Sopenharmony_ci uint32_t rand_driver_vers; 31935db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 31945db71995Sopenharmony_ci 31955db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 31965db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 31975db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 31985db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 31995db71995Sopenharmony_ci 32005db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 32015db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 32025db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, 0}); 32035db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 32045db71995Sopenharmony_ci } 32055db71995Sopenharmony_ci 32065db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 32075db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 32085db71995Sopenharmony_ci FillInRandomExtFenceData(cur_dev.external_fence_properties); 32095db71995Sopenharmony_ci } 32105db71995Sopenharmony_ci } 32115db71995Sopenharmony_ci 32125db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 32135db71995Sopenharmony_ci instance.create_info.set_api_version(VK_API_VERSION_1_1); 32145db71995Sopenharmony_ci instance.CheckCreate(); 32155db71995Sopenharmony_ci 32165db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFenceProperties GetPhysicalDeviceExternalFenceProperties = 32175db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceExternalFenceProperties"); 32185db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceExternalFenceProperties, nullptr); 32195db71995Sopenharmony_ci 32205db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 32215db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 32225db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 32235db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 32245db71995Sopenharmony_ci 32255db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 32265db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 32275db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 32285db71995Sopenharmony_ci 32295db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 32305db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 32315db71995Sopenharmony_ci bool found = false; 32325db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 32335db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 32345db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 32355db71995Sopenharmony_ci // physical devices info with the returned info. 32365db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 32375db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 32385db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 32395db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 32405db71995Sopenharmony_ci VkPhysicalDeviceExternalFenceInfo info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO}; 32415db71995Sopenharmony_ci VkExternalFenceProperties props{VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES}; 32425db71995Sopenharmony_ci GetPhysicalDeviceExternalFenceProperties(physical_devices[dev], &info, &props); 32435db71995Sopenharmony_ci // No driver support for extension or 1.1 for ICD 1, all others support 32445db71995Sopenharmony_ci ASSERT_TRUE(CompareExtFenceData(cur_dev.external_fence_properties, props, icd != 1)); 32455db71995Sopenharmony_ci found = true; 32465db71995Sopenharmony_ci break; 32475db71995Sopenharmony_ci } 32485db71995Sopenharmony_ci } 32495db71995Sopenharmony_ci if (found) { 32505db71995Sopenharmony_ci break; 32515db71995Sopenharmony_ci } 32525db71995Sopenharmony_ci } 32535db71995Sopenharmony_ci } 32545db71995Sopenharmony_ci} 32555db71995Sopenharmony_ci 32565db71995Sopenharmony_ci// 32575db71995Sopenharmony_ci// VK_KHR_get_surface_capabilities2 32585db71995Sopenharmony_ci// 32595db71995Sopenharmony_ci 32605db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceCapabilities2KHR where nothing supports it. 32615db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceCaps2KHRNoSupport) { 32625db71995Sopenharmony_ci FrameworkEnvironment env{}; 32635db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 32645db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 32655db71995Sopenharmony_ci 32665db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 32675db71995Sopenharmony_ci instance.CheckCreate(); 32685db71995Sopenharmony_ci 32695db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR GetPhysicalDeviceSurfaceCapabilities2KHR = 32705db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceCapabilities2KHR"); 32715db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceSurfaceCapabilities2KHR, nullptr); 32725db71995Sopenharmony_ci} 32735db71995Sopenharmony_ci 32745db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceCapabilities2KHR where instance supports it, but nothing else. 32755db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceCaps2KHRNoICDSupport) { 32765db71995Sopenharmony_ci FrameworkEnvironment env{}; 32775db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 32785db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 32795db71995Sopenharmony_ci 32805db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 32815db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME); 32825db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 32835db71995Sopenharmony_ci 32845db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR GetPhysicalDeviceSurfaceCapabilities2KHR = 32855db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceCapabilities2KHR"); 32865db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceSurfaceCapabilities2KHR, nullptr); 32875db71995Sopenharmony_ci} 32885db71995Sopenharmony_ci 32895db71995Sopenharmony_ci// Fill in random but valid data into the surface capability data struct for the current physical device 32905db71995Sopenharmony_civoid FillInRandomSurfaceCapsData(VkSurfaceCapabilitiesKHR& props) { 32915db71995Sopenharmony_ci props.minImageCount = (rand() % 0xFFF) + 1; 32925db71995Sopenharmony_ci props.maxImageCount = (rand() % 0xFFF) + 1; 32935db71995Sopenharmony_ci props.currentExtent.width = (rand() % 0xFFF) + 1; 32945db71995Sopenharmony_ci props.currentExtent.height = (rand() % 0xFFF) + 1; 32955db71995Sopenharmony_ci props.minImageExtent.width = (rand() % 0xFFF) + 1; 32965db71995Sopenharmony_ci props.minImageExtent.height = (rand() % 0xFFF) + 1; 32975db71995Sopenharmony_ci props.maxImageExtent.width = (rand() % 0xFFF) + 1; 32985db71995Sopenharmony_ci props.maxImageExtent.height = (rand() % 0xFFF) + 1; 32995db71995Sopenharmony_ci props.maxImageArrayLayers = (rand() % 0xFFF) + 1; 33005db71995Sopenharmony_ci props.supportedTransforms = static_cast<VkSurfaceTransformFlagsKHR>((rand() % 0xFFF) + 1); 33015db71995Sopenharmony_ci props.currentTransform = static_cast<VkSurfaceTransformFlagBitsKHR>((rand() % 0xFFF) + 1); 33025db71995Sopenharmony_ci props.supportedCompositeAlpha = static_cast<VkCompositeAlphaFlagsKHR>((rand() % 0xFFF) + 1); 33035db71995Sopenharmony_ci props.supportedUsageFlags = static_cast<VkImageUsageFlags>((rand() % 0xFFF) + 1); 33045db71995Sopenharmony_ci} 33055db71995Sopenharmony_ci 33065db71995Sopenharmony_ci// Compare the surface capability data structs 33075db71995Sopenharmony_cibool CompareSurfaceCapsData(const VkSurfaceCapabilitiesKHR& props1, const VkSurfaceCapabilitiesKHR& props2, bool supported = true) { 33085db71995Sopenharmony_ci bool equal = true; 33095db71995Sopenharmony_ci if (supported) { 33105db71995Sopenharmony_ci equal = equal && props1.minImageCount == props2.minImageCount; 33115db71995Sopenharmony_ci equal = equal && props1.maxImageCount == props2.maxImageCount; 33125db71995Sopenharmony_ci equal = equal && props1.currentExtent.width == props2.currentExtent.width; 33135db71995Sopenharmony_ci equal = equal && props1.currentExtent.height == props2.currentExtent.height; 33145db71995Sopenharmony_ci equal = equal && props1.minImageExtent.width == props2.minImageExtent.width; 33155db71995Sopenharmony_ci equal = equal && props1.minImageExtent.height == props2.minImageExtent.height; 33165db71995Sopenharmony_ci equal = equal && props1.maxImageExtent.width == props2.maxImageExtent.width; 33175db71995Sopenharmony_ci equal = equal && props1.maxImageExtent.height == props2.maxImageExtent.height; 33185db71995Sopenharmony_ci equal = equal && props1.maxImageArrayLayers == props2.maxImageArrayLayers; 33195db71995Sopenharmony_ci equal = equal && props1.supportedTransforms == props2.supportedTransforms; 33205db71995Sopenharmony_ci equal = equal && props1.currentTransform == props2.currentTransform; 33215db71995Sopenharmony_ci equal = equal && props1.supportedCompositeAlpha == props2.supportedCompositeAlpha; 33225db71995Sopenharmony_ci equal = equal && props1.supportedUsageFlags == props2.supportedUsageFlags; 33235db71995Sopenharmony_ci } else { 33245db71995Sopenharmony_ci equal = equal && 0 == props2.minImageCount; 33255db71995Sopenharmony_ci equal = equal && 0 == props2.maxImageCount; 33265db71995Sopenharmony_ci equal = equal && 0 == props2.currentExtent.width; 33275db71995Sopenharmony_ci equal = equal && 0 == props2.currentExtent.height; 33285db71995Sopenharmony_ci equal = equal && 0 == props2.minImageExtent.width; 33295db71995Sopenharmony_ci equal = equal && 0 == props2.minImageExtent.height; 33305db71995Sopenharmony_ci equal = equal && 0 == props2.maxImageExtent.width; 33315db71995Sopenharmony_ci equal = equal && 0 == props2.maxImageExtent.height; 33325db71995Sopenharmony_ci equal = equal && 0 == props2.maxImageArrayLayers; 33335db71995Sopenharmony_ci equal = equal && 0 == props2.supportedTransforms; 33345db71995Sopenharmony_ci equal = equal && 0 == props2.currentTransform; 33355db71995Sopenharmony_ci equal = equal && 0 == props2.supportedCompositeAlpha; 33365db71995Sopenharmony_ci equal = equal && 0 == props2.supportedUsageFlags; 33375db71995Sopenharmony_ci } 33385db71995Sopenharmony_ci return equal; 33395db71995Sopenharmony_ci} 33405db71995Sopenharmony_ci 33415db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceCapabilities2KHR where instance and ICD supports it, but device does not support it. 33425db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceCaps2KHRInstanceAndICDSupport) { 33435db71995Sopenharmony_ci FrameworkEnvironment env{}; 33445db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 33455db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 33465db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}; 33475db71995Sopenharmony_ci Extension third_ext{VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME}; 33485db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 33495db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext, third_ext}); 33505db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 33515db71995Sopenharmony_ci cur_icd.min_icd_interface_version = 3; 33525db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 33535db71995Sopenharmony_ci FillInRandomSurfaceCapsData(env.get_test_icd(0).physical_devices.back().surface_capabilities); 33545db71995Sopenharmony_ci 33555db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 33565db71995Sopenharmony_ci instance.create_info.add_extensions( 33575db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}); 33585db71995Sopenharmony_ci instance.CheckCreate(); 33595db71995Sopenharmony_ci 33605db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR = 33615db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceCapabilitiesKHR"); 33625db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceCapabilitiesKHR, nullptr); 33635db71995Sopenharmony_ci PFN_vkCreateHeadlessSurfaceEXT CreateHeadlessSurfaceEXT = instance.load("vkCreateHeadlessSurfaceEXT"); 33645db71995Sopenharmony_ci ASSERT_NE(CreateHeadlessSurfaceEXT, nullptr); 33655db71995Sopenharmony_ci PFN_vkDestroySurfaceKHR DestroySurfaceKHR = instance.load("vkDestroySurfaceKHR"); 33665db71995Sopenharmony_ci ASSERT_NE(DestroySurfaceKHR, nullptr); 33675db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR GetPhysicalDeviceSurfaceCapabilities2KHR = 33685db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceCapabilities2KHR"); 33695db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceCapabilities2KHR, nullptr); 33705db71995Sopenharmony_ci 33715db71995Sopenharmony_ci uint32_t driver_count = 1; 33725db71995Sopenharmony_ci VkPhysicalDevice physical_device; 33735db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 33745db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 33755db71995Sopenharmony_ci 33765db71995Sopenharmony_ci VkSurfaceKHR surface; 33775db71995Sopenharmony_ci VkHeadlessSurfaceCreateInfoEXT create_info{VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT}; 33785db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, CreateHeadlessSurfaceEXT(instance.inst, &create_info, nullptr, &surface)); 33795db71995Sopenharmony_ci 33805db71995Sopenharmony_ci VkSurfaceCapabilitiesKHR props{}; 33815db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &props)); 33825db71995Sopenharmony_ci 33835db71995Sopenharmony_ci VkPhysicalDeviceSurfaceInfo2KHR info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, nullptr, surface}; 33845db71995Sopenharmony_ci VkSurfaceCapabilities2KHR props2{VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR}; 33855db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceCapabilities2KHR(physical_device, &info, &props2)); 33865db71995Sopenharmony_ci ASSERT_TRUE(CompareSurfaceCapsData(props, props2.surfaceCapabilities)); 33875db71995Sopenharmony_ci 33885db71995Sopenharmony_ci DestroySurfaceKHR(instance.inst, surface, nullptr); 33895db71995Sopenharmony_ci} 33905db71995Sopenharmony_ci 33915db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceCapabilities2 where instance supports it with some ICDs that both support 33925db71995Sopenharmony_ci// and don't support it: 33935db71995Sopenharmony_ci// ICD 0 supports 33945db71995Sopenharmony_ci// Physical device 0 does not 33955db71995Sopenharmony_ci// Physical device 1 does 33965db71995Sopenharmony_ci// Physical device 2 does not 33975db71995Sopenharmony_ci// ICD 1 doesn't support 33985db71995Sopenharmony_ci// Physical device 3 does not 33995db71995Sopenharmony_ci// ICD 2 supports 34005db71995Sopenharmony_ci// Physical device 4 does not 34015db71995Sopenharmony_ci// Physical device 5 does not 34025db71995Sopenharmony_ci// ICD 3 supports 34035db71995Sopenharmony_ci// Physical device 6 does 34045db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceCaps2KHRMixed) { 34055db71995Sopenharmony_ci FrameworkEnvironment env{}; 34065db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 34075db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 34085db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 34095db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 34105db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}; 34115db71995Sopenharmony_ci Extension third_ext{VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME}; 34125db71995Sopenharmony_ci 34135db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 34145db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 34155db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 34165db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 34175db71995Sopenharmony_ci cur_icd.min_icd_interface_version = 3; 34185db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 34195db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, third_ext}); 34205db71995Sopenharmony_ci 34215db71995Sopenharmony_ci // ICD 1 should not have 1.1 34225db71995Sopenharmony_ci if (icd != 1) { 34235db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 34245db71995Sopenharmony_ci cur_icd.add_instance_extension(second_ext); 34255db71995Sopenharmony_ci } 34265db71995Sopenharmony_ci 34275db71995Sopenharmony_ci uint32_t rand_vendor_id; 34285db71995Sopenharmony_ci uint32_t rand_driver_vers; 34295db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 34305db71995Sopenharmony_ci 34315db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 34325db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 34335db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 34345db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 34355db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_SURFACE_EXTENSION_NAME, 0}); 34365db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, 0}); 34375db71995Sopenharmony_ci 34385db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 34395db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 34405db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, 0}); 34415db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 34425db71995Sopenharmony_ci } 34435db71995Sopenharmony_ci 34445db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 34455db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 34465db71995Sopenharmony_ci FillInRandomSurfaceCapsData(cur_dev.surface_capabilities); 34475db71995Sopenharmony_ci } 34485db71995Sopenharmony_ci } 34495db71995Sopenharmony_ci 34505db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 34515db71995Sopenharmony_ci instance.create_info.add_extensions( 34525db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}); 34535db71995Sopenharmony_ci instance.CheckCreate(); 34545db71995Sopenharmony_ci 34555db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR = 34565db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceCapabilitiesKHR"); 34575db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceCapabilitiesKHR, nullptr); 34585db71995Sopenharmony_ci PFN_vkCreateHeadlessSurfaceEXT CreateHeadlessSurfaceEXT = instance.load("vkCreateHeadlessSurfaceEXT"); 34595db71995Sopenharmony_ci ASSERT_NE(CreateHeadlessSurfaceEXT, nullptr); 34605db71995Sopenharmony_ci PFN_vkDestroySurfaceKHR DestroySurfaceKHR = instance.load("vkDestroySurfaceKHR"); 34615db71995Sopenharmony_ci ASSERT_NE(DestroySurfaceKHR, nullptr); 34625db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR GetPhysicalDeviceSurfaceCapabilities2KHR = 34635db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceCapabilities2KHR"); 34645db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceCapabilities2KHR, nullptr); 34655db71995Sopenharmony_ci 34665db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 34675db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 34685db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 34695db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 34705db71995Sopenharmony_ci 34715db71995Sopenharmony_ci VkSurfaceKHR surface; 34725db71995Sopenharmony_ci VkHeadlessSurfaceCreateInfoEXT create_info{VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT}; 34735db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, CreateHeadlessSurfaceEXT(instance.inst, &create_info, nullptr, &surface)); 34745db71995Sopenharmony_ci 34755db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 34765db71995Sopenharmony_ci VkSurfaceCapabilitiesKHR props{}; 34775db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceCapabilitiesKHR(physical_devices[dev], surface, &props)); 34785db71995Sopenharmony_ci 34795db71995Sopenharmony_ci VkPhysicalDeviceSurfaceInfo2KHR info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, nullptr, surface}; 34805db71995Sopenharmony_ci VkSurfaceCapabilities2KHR props2{VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR}; 34815db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceCapabilities2KHR(physical_devices[dev], &info, &props2)); 34825db71995Sopenharmony_ci ASSERT_TRUE(CompareSurfaceCapsData(props, props2.surfaceCapabilities)); 34835db71995Sopenharmony_ci } 34845db71995Sopenharmony_ci 34855db71995Sopenharmony_ci DestroySurfaceKHR(instance.inst, surface, nullptr); 34865db71995Sopenharmony_ci} 34875db71995Sopenharmony_ci 34885db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceFormats2KHR where nothing supports it. 34895db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceFormats2KHRNoSupport) { 34905db71995Sopenharmony_ci FrameworkEnvironment env{}; 34915db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 34925db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 34935db71995Sopenharmony_ci 34945db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 34955db71995Sopenharmony_ci instance.CheckCreate(); 34965db71995Sopenharmony_ci 34975db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceFormats2KHR GetPhysicalDeviceSurfaceFormats2KHR = 34985db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceFormats2KHR"); 34995db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceSurfaceFormats2KHR, nullptr); 35005db71995Sopenharmony_ci} 35015db71995Sopenharmony_ci 35025db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceFormats2KHR where instance supports it, but nothing else. 35035db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceFormats2KHRNoICDSupport) { 35045db71995Sopenharmony_ci FrameworkEnvironment env{}; 35055db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 35065db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 35075db71995Sopenharmony_ci 35085db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 35095db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME); 35105db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 35115db71995Sopenharmony_ci 35125db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceFormats2KHR GetPhysicalDeviceSurfaceFormats2KHR = 35135db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceFormats2KHR"); 35145db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceSurfaceFormats2KHR, nullptr); 35155db71995Sopenharmony_ci} 35165db71995Sopenharmony_ci 35175db71995Sopenharmony_ci// Fill in random but valid data into the surface formats data struct for the current physical device 35185db71995Sopenharmony_civoid FillInRandomSurfaceFormatsData(std::vector<VkSurfaceFormatKHR>& props) { 35195db71995Sopenharmony_ci props.resize((rand() % 5) + 1); 35205db71995Sopenharmony_ci for (uint32_t i = 0; i < props.size(); ++i) { 35215db71995Sopenharmony_ci props[i].format = static_cast<VkFormat>((rand() % 0xFFF) + 1); 35225db71995Sopenharmony_ci props[i].colorSpace = static_cast<VkColorSpaceKHR>((rand() % 0xFFF) + 1); 35235db71995Sopenharmony_ci } 35245db71995Sopenharmony_ci} 35255db71995Sopenharmony_ci 35265db71995Sopenharmony_ci// Compare the surface formats data structs 35275db71995Sopenharmony_cibool CompareSurfaceFormatsData(const std::vector<VkSurfaceFormatKHR>& props1, const std::vector<VkSurfaceFormat2KHR>& props2, 35285db71995Sopenharmony_ci bool supported = true) { 35295db71995Sopenharmony_ci if (props1.size() != props2.size()) return false; 35305db71995Sopenharmony_ci bool equal = true; 35315db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.size(); ++i) { 35325db71995Sopenharmony_ci if (supported) { 35335db71995Sopenharmony_ci equal = equal && props1[i].format == props2[i].surfaceFormat.format; 35345db71995Sopenharmony_ci equal = equal && props1[i].colorSpace == props2[i].surfaceFormat.colorSpace; 35355db71995Sopenharmony_ci } else { 35365db71995Sopenharmony_ci equal = equal && 0 == props2[i].surfaceFormat.format; 35375db71995Sopenharmony_ci equal = equal && 0 == props2[i].surfaceFormat.colorSpace; 35385db71995Sopenharmony_ci } 35395db71995Sopenharmony_ci } 35405db71995Sopenharmony_ci return equal; 35415db71995Sopenharmony_ci} 35425db71995Sopenharmony_ci 35435db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceFormats2KHR where instance and ICD supports it, but device does not support it. 35445db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceFormats2KHRInstanceAndICDSupport) { 35455db71995Sopenharmony_ci FrameworkEnvironment env{}; 35465db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 35475db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 35485db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}; 35495db71995Sopenharmony_ci Extension third_ext{VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME}; 35505db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 35515db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext, third_ext}); 35525db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 35535db71995Sopenharmony_ci cur_icd.min_icd_interface_version = 3; 35545db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 35555db71995Sopenharmony_ci FillInRandomSurfaceFormatsData(env.get_test_icd(0).physical_devices.back().surface_formats); 35565db71995Sopenharmony_ci 35575db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 35585db71995Sopenharmony_ci instance.create_info.add_extensions( 35595db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}); 35605db71995Sopenharmony_ci instance.CheckCreate(); 35615db71995Sopenharmony_ci 35625db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR = 35635db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceFormatsKHR"); 35645db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceFormatsKHR, nullptr); 35655db71995Sopenharmony_ci PFN_vkCreateHeadlessSurfaceEXT CreateHeadlessSurfaceEXT = instance.load("vkCreateHeadlessSurfaceEXT"); 35665db71995Sopenharmony_ci ASSERT_NE(CreateHeadlessSurfaceEXT, nullptr); 35675db71995Sopenharmony_ci PFN_vkDestroySurfaceKHR DestroySurfaceKHR = instance.load("vkDestroySurfaceKHR"); 35685db71995Sopenharmony_ci ASSERT_NE(DestroySurfaceKHR, nullptr); 35695db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceFormats2KHR GetPhysicalDeviceSurfaceFormats2KHR = 35705db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceFormats2KHR"); 35715db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceFormats2KHR, nullptr); 35725db71995Sopenharmony_ci 35735db71995Sopenharmony_ci uint32_t driver_count = 1; 35745db71995Sopenharmony_ci VkPhysicalDevice physical_device; 35755db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 35765db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 35775db71995Sopenharmony_ci 35785db71995Sopenharmony_ci VkSurfaceKHR surface; 35795db71995Sopenharmony_ci VkHeadlessSurfaceCreateInfoEXT create_info{VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT}; 35805db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, CreateHeadlessSurfaceEXT(instance.inst, &create_info, nullptr, &surface)); 35815db71995Sopenharmony_ci 35825db71995Sopenharmony_ci std::vector<VkSurfaceFormatKHR> props{}; 35835db71995Sopenharmony_ci uint32_t count_1 = 0; 35845db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &count_1, nullptr)); 35855db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().surface_formats.size(), count_1); 35865db71995Sopenharmony_ci props.resize(count_1); 35875db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &count_1, props.data())); 35885db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().surface_formats.size(), count_1); 35895db71995Sopenharmony_ci 35905db71995Sopenharmony_ci VkPhysicalDeviceSurfaceInfo2KHR info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, nullptr, surface}; 35915db71995Sopenharmony_ci std::vector<VkSurfaceFormat2KHR> props2{}; 35925db71995Sopenharmony_ci uint32_t count_2 = 0; 35935db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormats2KHR(physical_device, &info, &count_2, nullptr)); 35945db71995Sopenharmony_ci ASSERT_EQ(count_1, count_2); 35955db71995Sopenharmony_ci props2.resize(count_2, VkSurfaceFormat2KHR{VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR}); 35965db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormats2KHR(physical_device, &info, &count_2, props2.data())); 35975db71995Sopenharmony_ci ASSERT_TRUE(CompareSurfaceFormatsData(props, props2)); 35985db71995Sopenharmony_ci 35995db71995Sopenharmony_ci DestroySurfaceKHR(instance.inst, surface, nullptr); 36005db71995Sopenharmony_ci} 36015db71995Sopenharmony_ci 36025db71995Sopenharmony_ci// Test vkGetPhysicalDeviceSurfaceFormats2 where instance supports it with some ICDs that both support 36035db71995Sopenharmony_ci// and don't support it: 36045db71995Sopenharmony_ci// ICD 0 supports 36055db71995Sopenharmony_ci// Physical device 0 does not 36065db71995Sopenharmony_ci// Physical device 1 does 36075db71995Sopenharmony_ci// Physical device 2 does not 36085db71995Sopenharmony_ci// ICD 1 doesn't support 36095db71995Sopenharmony_ci// Physical device 3 does not 36105db71995Sopenharmony_ci// ICD 2 supports 36115db71995Sopenharmony_ci// Physical device 4 does not 36125db71995Sopenharmony_ci// Physical device 5 does not 36135db71995Sopenharmony_ci// ICD 3 supports 36145db71995Sopenharmony_ci// Physical device 6 does 36155db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevSurfaceFormats2KHRMixed) { 36165db71995Sopenharmony_ci FrameworkEnvironment env{}; 36175db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 36185db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 36195db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 36205db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 36215db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}; 36225db71995Sopenharmony_ci Extension third_ext{VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME}; 36235db71995Sopenharmony_ci 36245db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 36255db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 36265db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 36275db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 36285db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 36295db71995Sopenharmony_ci cur_icd.min_icd_interface_version = 3; 36305db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, third_ext}); 36315db71995Sopenharmony_ci 36325db71995Sopenharmony_ci // ICD 1 should not have 1.1 36335db71995Sopenharmony_ci if (icd != 1) { 36345db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 36355db71995Sopenharmony_ci cur_icd.add_instance_extension(second_ext); 36365db71995Sopenharmony_ci } 36375db71995Sopenharmony_ci 36385db71995Sopenharmony_ci uint32_t rand_vendor_id; 36395db71995Sopenharmony_ci uint32_t rand_driver_vers; 36405db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 36415db71995Sopenharmony_ci 36425db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 36435db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 36445db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 36455db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 36465db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_SURFACE_EXTENSION_NAME, 0}); 36475db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, 0}); 36485db71995Sopenharmony_ci 36495db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 36505db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 36515db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, 0}); 36525db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 36535db71995Sopenharmony_ci } 36545db71995Sopenharmony_ci 36555db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 36565db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 36575db71995Sopenharmony_ci FillInRandomSurfaceFormatsData(cur_dev.surface_formats); 36585db71995Sopenharmony_ci } 36595db71995Sopenharmony_ci } 36605db71995Sopenharmony_ci 36615db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 36625db71995Sopenharmony_ci instance.create_info.add_extensions( 36635db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME}); 36645db71995Sopenharmony_ci instance.CheckCreate(); 36655db71995Sopenharmony_ci 36665db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR = 36675db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceFormatsKHR"); 36685db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceFormatsKHR, nullptr); 36695db71995Sopenharmony_ci PFN_vkCreateHeadlessSurfaceEXT CreateHeadlessSurfaceEXT = instance.load("vkCreateHeadlessSurfaceEXT"); 36705db71995Sopenharmony_ci ASSERT_NE(CreateHeadlessSurfaceEXT, nullptr); 36715db71995Sopenharmony_ci PFN_vkDestroySurfaceKHR DestroySurfaceKHR = instance.load("vkDestroySurfaceKHR"); 36725db71995Sopenharmony_ci ASSERT_NE(DestroySurfaceKHR, nullptr); 36735db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceSurfaceFormats2KHR GetPhysicalDeviceSurfaceFormats2KHR = 36745db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceSurfaceFormats2KHR"); 36755db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceSurfaceFormats2KHR, nullptr); 36765db71995Sopenharmony_ci 36775db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 36785db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 36795db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 36805db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 36815db71995Sopenharmony_ci 36825db71995Sopenharmony_ci VkSurfaceKHR surface; 36835db71995Sopenharmony_ci VkHeadlessSurfaceCreateInfoEXT create_info{VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT}; 36845db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, CreateHeadlessSurfaceEXT(instance.inst, &create_info, nullptr, &surface)); 36855db71995Sopenharmony_ci 36865db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 36875db71995Sopenharmony_ci std::vector<VkSurfaceFormatKHR> props{}; 36885db71995Sopenharmony_ci uint32_t count_1 = 0; 36895db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormatsKHR(physical_devices[dev], surface, &count_1, nullptr)); 36905db71995Sopenharmony_ci ASSERT_NE(0U, count_1); 36915db71995Sopenharmony_ci props.resize(count_1); 36925db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormatsKHR(physical_devices[dev], surface, &count_1, props.data())); 36935db71995Sopenharmony_ci ASSERT_NE(0U, count_1); 36945db71995Sopenharmony_ci 36955db71995Sopenharmony_ci VkPhysicalDeviceSurfaceInfo2KHR info{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, nullptr, surface}; 36965db71995Sopenharmony_ci std::vector<VkSurfaceFormat2KHR> props2{}; 36975db71995Sopenharmony_ci uint32_t count_2 = 0; 36985db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormats2KHR(physical_devices[dev], &info, &count_2, nullptr)); 36995db71995Sopenharmony_ci ASSERT_EQ(count_1, count_2); 37005db71995Sopenharmony_ci props2.resize(count_2, VkSurfaceFormat2KHR{VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR}); 37015db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceSurfaceFormats2KHR(physical_devices[dev], &info, &count_2, props2.data())); 37025db71995Sopenharmony_ci ASSERT_EQ(count_1, count_2); 37035db71995Sopenharmony_ci ASSERT_TRUE(CompareSurfaceFormatsData(props, props2)); 37045db71995Sopenharmony_ci } 37055db71995Sopenharmony_ci 37065db71995Sopenharmony_ci DestroySurfaceKHR(instance.inst, surface, nullptr); 37075db71995Sopenharmony_ci} 37085db71995Sopenharmony_ci 37095db71995Sopenharmony_ci// 37105db71995Sopenharmony_ci// VK_KHR_display 37115db71995Sopenharmony_ci// 37125db71995Sopenharmony_ci 37135db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPropertiesKHR where nothing supports it. 37145db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPropsKHRNoSupport) { 37155db71995Sopenharmony_ci FrameworkEnvironment env{}; 37165db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 37175db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 37185db71995Sopenharmony_ci 37195db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 37205db71995Sopenharmony_ci instance.CheckCreate(); 37215db71995Sopenharmony_ci 37225db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPropertiesKHR GetPhysicalDeviceDisplayPropertiesKHR = 37235db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPropertiesKHR"); 37245db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayPropertiesKHR, nullptr); 37255db71995Sopenharmony_ci} 37265db71995Sopenharmony_ci 37275db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPropertiesKHR where instance supports it, but nothing else. 37285db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPropsKHRNoICDSupport) { 37295db71995Sopenharmony_ci FrameworkEnvironment env{}; 37305db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 37315db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 37325db71995Sopenharmony_ci 37335db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 37345db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 37355db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 37365db71995Sopenharmony_ci 37375db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPropertiesKHR GetPhysicalDeviceDisplayPropertiesKHR = 37385db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPropertiesKHR"); 37395db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayPropertiesKHR, nullptr); 37405db71995Sopenharmony_ci} 37415db71995Sopenharmony_ci 37425db71995Sopenharmony_ciVkDisplayKHR CreateRandomDisplay() { return (VkDisplayKHR)(((rand() % 0xFFFFFFFBull) << 12) * (rand() % 0xFFFFFFFull) + 1); } 37435db71995Sopenharmony_ci 37445db71995Sopenharmony_ciVkDisplayModeKHR CreateRandomDisplayMode() { 37455db71995Sopenharmony_ci return (VkDisplayModeKHR)(((rand() % 0xFFFFFFFBull) << 12) * (rand() % 0xFFFFFFFull) + 1); 37465db71995Sopenharmony_ci} 37475db71995Sopenharmony_ci 37485db71995Sopenharmony_ci// Fill in random but valid data into the display property data struct for the current physical device 37495db71995Sopenharmony_civoid FillInRandomDisplayPropData(std::vector<VkDisplayPropertiesKHR>& props) { 37505db71995Sopenharmony_ci props.resize((rand() % 5) + 1); 37515db71995Sopenharmony_ci for (uint32_t i = 0; i < props.size(); ++i) { 37525db71995Sopenharmony_ci props[i].display = CreateRandomDisplay(); 37535db71995Sopenharmony_ci props[i].physicalDimensions.width = static_cast<uint32_t>((rand() % 0xFFF) + 1); 37545db71995Sopenharmony_ci props[i].physicalDimensions.height = static_cast<uint32_t>((rand() % 0xFFF) + 1); 37555db71995Sopenharmony_ci props[i].physicalResolution.width = static_cast<uint32_t>((rand() % 0xFFF) + 1); 37565db71995Sopenharmony_ci props[i].physicalResolution.height = static_cast<uint32_t>((rand() % 0xFFF) + 1); 37575db71995Sopenharmony_ci props[i].supportedTransforms = static_cast<VkSurfaceTransformFlagsKHR>((rand() % 0xFFE) + 1); 37585db71995Sopenharmony_ci props[i].planeReorderPossible = rand() % 2 > 0 ? VK_TRUE : VK_FALSE; 37595db71995Sopenharmony_ci props[i].persistentContent = rand() % 2 > 0 ? VK_TRUE : VK_FALSE; 37605db71995Sopenharmony_ci } 37615db71995Sopenharmony_ci} 37625db71995Sopenharmony_ci 37635db71995Sopenharmony_ci// Compare the display property data structs 37645db71995Sopenharmony_cibool CompareDisplayPropData(const std::vector<VkDisplayPropertiesKHR>& props1, const std::vector<VkDisplayPropertiesKHR>& props2) { 37655db71995Sopenharmony_ci if (props1.size() != props2.size()) return false; 37665db71995Sopenharmony_ci bool equal = true; 37675db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.size(); ++i) { 37685db71995Sopenharmony_ci equal = equal && props1[i].display == props2[i].display; 37695db71995Sopenharmony_ci equal = equal && props1[i].physicalDimensions.width == props2[i].physicalDimensions.width; 37705db71995Sopenharmony_ci equal = equal && props1[i].physicalDimensions.height == props2[i].physicalDimensions.height; 37715db71995Sopenharmony_ci equal = equal && props1[i].physicalResolution.width == props2[i].physicalResolution.width; 37725db71995Sopenharmony_ci equal = equal && props1[i].physicalResolution.height == props2[i].physicalResolution.height; 37735db71995Sopenharmony_ci equal = equal && props1[i].supportedTransforms == props2[i].supportedTransforms; 37745db71995Sopenharmony_ci equal = equal && props1[i].planeReorderPossible == props2[i].planeReorderPossible; 37755db71995Sopenharmony_ci equal = equal && props1[i].persistentContent == props2[i].persistentContent; 37765db71995Sopenharmony_ci } 37775db71995Sopenharmony_ci return equal; 37785db71995Sopenharmony_ci} 37795db71995Sopenharmony_ci 37805db71995Sopenharmony_ci// Test vGetPhysicalDeviceDisplayPropertiesKHR where instance and ICD supports it, but device does not support it. 37815db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPropsKHRInstanceAndICDSupport) { 37825db71995Sopenharmony_ci FrameworkEnvironment env{}; 37835db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 37845db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 37855db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 37865db71995Sopenharmony_ci FillInRandomDisplayPropData(env.get_test_icd(0).physical_devices.back().display_properties); 37875db71995Sopenharmony_ci 37885db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 37895db71995Sopenharmony_ci instance.create_info.add_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 37905db71995Sopenharmony_ci instance.CheckCreate(); 37915db71995Sopenharmony_ci 37925db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPropertiesKHR GetPhysicalDeviceDisplayPropertiesKHR = 37935db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPropertiesKHR"); 37945db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPropertiesKHR, nullptr); 37955db71995Sopenharmony_ci 37965db71995Sopenharmony_ci uint32_t driver_count = 1; 37975db71995Sopenharmony_ci VkPhysicalDevice physical_device; 37985db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 37995db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 38005db71995Sopenharmony_ci 38015db71995Sopenharmony_ci std::vector<VkDisplayPropertiesKHR> props{}; 38025db71995Sopenharmony_ci uint32_t prop_count = 0; 38035db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPropertiesKHR(physical_device, &prop_count, nullptr)); 38045db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().display_properties.size(), prop_count); 38055db71995Sopenharmony_ci props.resize(prop_count); 38065db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPropertiesKHR(physical_device, &prop_count, props.data())); 38075db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().display_properties.size(), prop_count); 38085db71995Sopenharmony_ci 38095db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPropData(props, env.get_test_icd(0).physical_devices.back().display_properties)); 38105db71995Sopenharmony_ci} 38115db71995Sopenharmony_ci 38125db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPropertiesKHR where instance supports it with some ICDs that both support 38135db71995Sopenharmony_ci// and don't support it: 38145db71995Sopenharmony_ci// ICD 0 supports 38155db71995Sopenharmony_ci// Physical device 0 does not 38165db71995Sopenharmony_ci// Physical device 1 does 38175db71995Sopenharmony_ci// Physical device 2 does not 38185db71995Sopenharmony_ci// ICD 1 doesn't support 38195db71995Sopenharmony_ci// Physical device 3 does not 38205db71995Sopenharmony_ci// ICD 2 supports 38215db71995Sopenharmony_ci// Physical device 4 does not 38225db71995Sopenharmony_ci// Physical device 5 does not 38235db71995Sopenharmony_ci// ICD 3 supports 38245db71995Sopenharmony_ci// Physical device 6 does 38255db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPropsKHRMixed) { 38265db71995Sopenharmony_ci FrameworkEnvironment env{}; 38275db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 38285db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 38295db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 38305db71995Sopenharmony_ci 38315db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 38325db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 38335db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 38345db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 38355db71995Sopenharmony_ci 38365db71995Sopenharmony_ci // ICD 1 should not have 1.1 38375db71995Sopenharmony_ci if (icd != 1) { 38385db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 38395db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 38405db71995Sopenharmony_ci } 38415db71995Sopenharmony_ci 38425db71995Sopenharmony_ci uint32_t rand_vendor_id; 38435db71995Sopenharmony_ci uint32_t rand_driver_vers; 38445db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 38455db71995Sopenharmony_ci 38465db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 38475db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 38485db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 38495db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 38505db71995Sopenharmony_ci 38515db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 38525db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 38535db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 38545db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 38555db71995Sopenharmony_ci } 38565db71995Sopenharmony_ci 38575db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 38585db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 38595db71995Sopenharmony_ci FillInRandomDisplayPropData(cur_dev.display_properties); 38605db71995Sopenharmony_ci } 38615db71995Sopenharmony_ci } 38625db71995Sopenharmony_ci 38635db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 38645db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 38655db71995Sopenharmony_ci instance.CheckCreate(); 38665db71995Sopenharmony_ci 38675db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPropertiesKHR GetPhysicalDeviceDisplayPropertiesKHR = 38685db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPropertiesKHR"); 38695db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPropertiesKHR, nullptr); 38705db71995Sopenharmony_ci 38715db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 38725db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 38735db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 38745db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 38755db71995Sopenharmony_ci 38765db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 38775db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 38785db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 38795db71995Sopenharmony_ci 38805db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 38815db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 38825db71995Sopenharmony_ci bool found = false; 38835db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 38845db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 38855db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 38865db71995Sopenharmony_ci // physical devices info with the returned info. 38875db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 38885db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 38895db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 38905db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 38915db71995Sopenharmony_ci std::vector<VkDisplayPropertiesKHR> props{}; 38925db71995Sopenharmony_ci uint32_t prop_count = 0; 38935db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPropertiesKHR(physical_devices[dev], &prop_count, nullptr)); 38945db71995Sopenharmony_ci if (icd == 1) { 38955db71995Sopenharmony_ci // For this extension, if no support exists (like for ICD 1), the value of 0 should be returned by the 38965db71995Sopenharmony_ci // loader. 38975db71995Sopenharmony_ci ASSERT_EQ(0U, prop_count); 38985db71995Sopenharmony_ci } else { 38995db71995Sopenharmony_ci ASSERT_EQ(cur_dev.display_properties.size(), prop_count); 39005db71995Sopenharmony_ci props.resize(prop_count); 39015db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 39025db71995Sopenharmony_ci GetPhysicalDeviceDisplayPropertiesKHR(physical_devices[dev], &prop_count, props.data())); 39035db71995Sopenharmony_ci ASSERT_EQ(cur_dev.display_properties.size(), prop_count); 39045db71995Sopenharmony_ci 39055db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPropData(props, cur_dev.display_properties)); 39065db71995Sopenharmony_ci } 39075db71995Sopenharmony_ci found = true; 39085db71995Sopenharmony_ci break; 39095db71995Sopenharmony_ci } 39105db71995Sopenharmony_ci } 39115db71995Sopenharmony_ci if (found) { 39125db71995Sopenharmony_ci break; 39135db71995Sopenharmony_ci } 39145db71995Sopenharmony_ci } 39155db71995Sopenharmony_ci } 39165db71995Sopenharmony_ci} 39175db71995Sopenharmony_ci 39185db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPlanePropertiesKHR where nothing supports it. 39195db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlanePropsKHRNoSupport) { 39205db71995Sopenharmony_ci FrameworkEnvironment env{}; 39215db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 39225db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 39235db71995Sopenharmony_ci 39245db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 39255db71995Sopenharmony_ci instance.CheckCreate(); 39265db71995Sopenharmony_ci 39275db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR GetPhysicalDeviceDisplayPlanePropertiesKHR = 39285db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); 39295db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayPlanePropertiesKHR, nullptr); 39305db71995Sopenharmony_ci} 39315db71995Sopenharmony_ci 39325db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPlanePropertiesKHR where instance supports it, but nothing else. 39335db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlanePropsKHRNoICDSupport) { 39345db71995Sopenharmony_ci FrameworkEnvironment env{}; 39355db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 39365db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 39375db71995Sopenharmony_ci 39385db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 39395db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 39405db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 39415db71995Sopenharmony_ci 39425db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR GetPhysicalDeviceDisplayPlanePropertiesKHR = 39435db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); 39445db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayPlanePropertiesKHR, nullptr); 39455db71995Sopenharmony_ci} 39465db71995Sopenharmony_ci 39475db71995Sopenharmony_ci// Fill in random but valid data into the display plane property data struct for the current physical device 39485db71995Sopenharmony_civoid FillInRandomDisplayPlanePropData(std::vector<VkDisplayPlanePropertiesKHR>& props) { 39495db71995Sopenharmony_ci props.resize((rand() % 5) + 1); 39505db71995Sopenharmony_ci for (uint32_t i = 0; i < props.size(); ++i) { 39515db71995Sopenharmony_ci props[i].currentDisplay = CreateRandomDisplay(); 39525db71995Sopenharmony_ci props[i].currentStackIndex = static_cast<uint32_t>((rand() % 0xFFF) + (rand() % 0xFFF) + 1); 39535db71995Sopenharmony_ci } 39545db71995Sopenharmony_ci} 39555db71995Sopenharmony_ci 39565db71995Sopenharmony_ci// Compare the display plane property data structs 39575db71995Sopenharmony_cibool CompareDisplayPlanePropData(const std::vector<VkDisplayPlanePropertiesKHR>& props1, 39585db71995Sopenharmony_ci const std::vector<VkDisplayPlanePropertiesKHR>& props2) { 39595db71995Sopenharmony_ci if (props1.size() != props2.size()) return false; 39605db71995Sopenharmony_ci bool equal = true; 39615db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.size(); ++i) { 39625db71995Sopenharmony_ci equal = equal && props1[i].currentDisplay == props2[i].currentDisplay; 39635db71995Sopenharmony_ci equal = equal && props1[i].currentStackIndex == props2[i].currentStackIndex; 39645db71995Sopenharmony_ci } 39655db71995Sopenharmony_ci return equal; 39665db71995Sopenharmony_ci} 39675db71995Sopenharmony_ci 39685db71995Sopenharmony_ci// Test vGetPhysicalDeviceDisplayPlanePropertiesKHR where instance and ICD supports it, but device does not support it. 39695db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlanePropsKHRInstanceAndICDSupport) { 39705db71995Sopenharmony_ci FrameworkEnvironment env{}; 39715db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 39725db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 39735db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 39745db71995Sopenharmony_ci FillInRandomDisplayPlanePropData(env.get_test_icd(0).physical_devices.back().display_plane_properties); 39755db71995Sopenharmony_ci 39765db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 39775db71995Sopenharmony_ci instance.create_info.add_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 39785db71995Sopenharmony_ci instance.CheckCreate(); 39795db71995Sopenharmony_ci 39805db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR GetPhysicalDeviceDisplayPlanePropertiesKHR = 39815db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); 39825db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPlanePropertiesKHR, nullptr); 39835db71995Sopenharmony_ci 39845db71995Sopenharmony_ci uint32_t driver_count = 1; 39855db71995Sopenharmony_ci VkPhysicalDevice physical_device; 39865db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 39875db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 39885db71995Sopenharmony_ci 39895db71995Sopenharmony_ci std::vector<VkDisplayPlanePropertiesKHR> props{}; 39905db71995Sopenharmony_ci uint32_t prop_count = 0; 39915db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_device, &prop_count, nullptr)); 39925db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().display_plane_properties.size(), prop_count); 39935db71995Sopenharmony_ci props.resize(prop_count); 39945db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_device, &prop_count, props.data())); 39955db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().display_plane_properties.size(), prop_count); 39965db71995Sopenharmony_ci 39975db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPlanePropData(props, env.get_test_icd(0).physical_devices.back().display_plane_properties)); 39985db71995Sopenharmony_ci} 39995db71995Sopenharmony_ci 40005db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPlanePropertiesKHR where instance supports it with some ICDs that both support 40015db71995Sopenharmony_ci// and don't support it: 40025db71995Sopenharmony_ci// ICD 0 supports 40035db71995Sopenharmony_ci// Physical device 0 does not 40045db71995Sopenharmony_ci// Physical device 1 does 40055db71995Sopenharmony_ci// Physical device 2 does not 40065db71995Sopenharmony_ci// ICD 1 doesn't support 40075db71995Sopenharmony_ci// Physical device 3 does not 40085db71995Sopenharmony_ci// ICD 2 supports 40095db71995Sopenharmony_ci// Physical device 4 does not 40105db71995Sopenharmony_ci// Physical device 5 does not 40115db71995Sopenharmony_ci// ICD 3 supports 40125db71995Sopenharmony_ci// Physical device 6 does 40135db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlanePropsKHRMixed) { 40145db71995Sopenharmony_ci FrameworkEnvironment env{}; 40155db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 40165db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 40175db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 40185db71995Sopenharmony_ci 40195db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 40205db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 40215db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 40225db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 40235db71995Sopenharmony_ci 40245db71995Sopenharmony_ci // ICD 1 should not have 1.1 40255db71995Sopenharmony_ci if (icd != 1) { 40265db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 40275db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 40285db71995Sopenharmony_ci } 40295db71995Sopenharmony_ci 40305db71995Sopenharmony_ci uint32_t rand_vendor_id; 40315db71995Sopenharmony_ci uint32_t rand_driver_vers; 40325db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 40335db71995Sopenharmony_ci 40345db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 40355db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 40365db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 40375db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 40385db71995Sopenharmony_ci 40395db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 40405db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 40415db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 40425db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 40435db71995Sopenharmony_ci } 40445db71995Sopenharmony_ci 40455db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 40465db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 40475db71995Sopenharmony_ci FillInRandomDisplayPlanePropData(cur_dev.display_plane_properties); 40485db71995Sopenharmony_ci } 40495db71995Sopenharmony_ci } 40505db71995Sopenharmony_ci 40515db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 40525db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 40535db71995Sopenharmony_ci instance.CheckCreate(); 40545db71995Sopenharmony_ci 40555db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR GetPhysicalDeviceDisplayPlanePropertiesKHR = 40565db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); 40575db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPlanePropertiesKHR, nullptr); 40585db71995Sopenharmony_ci 40595db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 40605db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 40615db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 40625db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 40635db71995Sopenharmony_ci 40645db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 40655db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 40665db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 40675db71995Sopenharmony_ci 40685db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 40695db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 40705db71995Sopenharmony_ci bool found = false; 40715db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 40725db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 40735db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 40745db71995Sopenharmony_ci // physical devices info with the returned info. 40755db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 40765db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 40775db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 40785db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 40795db71995Sopenharmony_ci std::vector<VkDisplayPlanePropertiesKHR> props{}; 40805db71995Sopenharmony_ci uint32_t prop_count = 0; 40815db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_devices[dev], &prop_count, nullptr)); 40825db71995Sopenharmony_ci if (icd == 1) { 40835db71995Sopenharmony_ci // For this extension, if no support exists (like for ICD 1), the value of 0 should be returned by the 40845db71995Sopenharmony_ci // loader. 40855db71995Sopenharmony_ci ASSERT_EQ(0U, prop_count); 40865db71995Sopenharmony_ci } else { 40875db71995Sopenharmony_ci ASSERT_EQ(cur_dev.display_plane_properties.size(), prop_count); 40885db71995Sopenharmony_ci props.resize(prop_count); 40895db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 40905db71995Sopenharmony_ci GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_devices[dev], &prop_count, props.data())); 40915db71995Sopenharmony_ci ASSERT_EQ(cur_dev.display_plane_properties.size(), prop_count); 40925db71995Sopenharmony_ci 40935db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPlanePropData(props, cur_dev.display_plane_properties)); 40945db71995Sopenharmony_ci } 40955db71995Sopenharmony_ci found = true; 40965db71995Sopenharmony_ci break; 40975db71995Sopenharmony_ci } 40985db71995Sopenharmony_ci } 40995db71995Sopenharmony_ci if (found) { 41005db71995Sopenharmony_ci break; 41015db71995Sopenharmony_ci } 41025db71995Sopenharmony_ci } 41035db71995Sopenharmony_ci } 41045db71995Sopenharmony_ci} 41055db71995Sopenharmony_ci 41065db71995Sopenharmony_ci// Test vkGetDisplayPlaneSupportedDisplaysKHR where nothing supports it. 41075db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneSupDispsKHRNoSupport) { 41085db71995Sopenharmony_ci FrameworkEnvironment env{}; 41095db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 41105db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 41115db71995Sopenharmony_ci 41125db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 41135db71995Sopenharmony_ci instance.CheckCreate(); 41145db71995Sopenharmony_ci 41155db71995Sopenharmony_ci PFN_vkGetDisplayPlaneSupportedDisplaysKHR GetDisplayPlaneSupportedDisplaysKHR = 41165db71995Sopenharmony_ci instance.load("vkGetDisplayPlaneSupportedDisplaysKHR"); 41175db71995Sopenharmony_ci ASSERT_EQ(GetDisplayPlaneSupportedDisplaysKHR, nullptr); 41185db71995Sopenharmony_ci} 41195db71995Sopenharmony_ci 41205db71995Sopenharmony_ci// Test vkGetDisplayPlaneSupportedDisplaysKHR where instance supports it, but nothing else. 41215db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneSupDispsKHRNoICDSupport) { 41225db71995Sopenharmony_ci FrameworkEnvironment env{}; 41235db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 41245db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 41255db71995Sopenharmony_ci 41265db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 41275db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 41285db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 41295db71995Sopenharmony_ci 41305db71995Sopenharmony_ci PFN_vkGetDisplayPlaneSupportedDisplaysKHR GetDisplayPlaneSupportedDisplaysKHR = 41315db71995Sopenharmony_ci instance.load("vkGetDisplayPlaneSupportedDisplaysKHR"); 41325db71995Sopenharmony_ci ASSERT_EQ(GetDisplayPlaneSupportedDisplaysKHR, nullptr); 41335db71995Sopenharmony_ci} 41345db71995Sopenharmony_ci 41355db71995Sopenharmony_ci// Fill in random but valid data into the display plane property data struct for the current physical device 41365db71995Sopenharmony_civoid GenerateRandomDisplays(std::vector<VkDisplayKHR>& disps) { 41375db71995Sopenharmony_ci disps.resize((rand() % 5) + 1); 41385db71995Sopenharmony_ci for (uint32_t i = 0; i < disps.size(); ++i) { 41395db71995Sopenharmony_ci disps[i] = CreateRandomDisplay(); 41405db71995Sopenharmony_ci } 41415db71995Sopenharmony_ci} 41425db71995Sopenharmony_ci 41435db71995Sopenharmony_ci// Compare the display plane property data structs 41445db71995Sopenharmony_cibool CompareDisplays(const std::vector<VkDisplayKHR>& disps1, const std::vector<VkDisplayKHR>& disps2) { 41455db71995Sopenharmony_ci if (disps1.size() != disps2.size()) return false; 41465db71995Sopenharmony_ci bool equal = true; 41475db71995Sopenharmony_ci for (uint32_t i = 0; i < disps1.size(); ++i) { 41485db71995Sopenharmony_ci equal = equal && disps1[i] == disps2[i]; 41495db71995Sopenharmony_ci } 41505db71995Sopenharmony_ci return equal; 41515db71995Sopenharmony_ci} 41525db71995Sopenharmony_ci 41535db71995Sopenharmony_ci// Test vGetDisplayPlaneSupportedDisplaysKHR where instance and ICD supports it, but device does not support it. 41545db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneSupDispsKHRInstanceAndICDSupport) { 41555db71995Sopenharmony_ci FrameworkEnvironment env{}; 41565db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 41575db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 41585db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 41595db71995Sopenharmony_ci GenerateRandomDisplays(env.get_test_icd(0).physical_devices.back().displays); 41605db71995Sopenharmony_ci 41615db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 41625db71995Sopenharmony_ci instance.create_info.add_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 41635db71995Sopenharmony_ci instance.CheckCreate(); 41645db71995Sopenharmony_ci 41655db71995Sopenharmony_ci PFN_vkGetDisplayPlaneSupportedDisplaysKHR GetDisplayPlaneSupportedDisplaysKHR = 41665db71995Sopenharmony_ci instance.load("vkGetDisplayPlaneSupportedDisplaysKHR"); 41675db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneSupportedDisplaysKHR, nullptr); 41685db71995Sopenharmony_ci 41695db71995Sopenharmony_ci uint32_t driver_count = 1; 41705db71995Sopenharmony_ci VkPhysicalDevice physical_device; 41715db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 41725db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 41735db71995Sopenharmony_ci 41745db71995Sopenharmony_ci std::vector<VkDisplayKHR> disps{}; 41755db71995Sopenharmony_ci uint32_t disp_count = 0; 41765db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneSupportedDisplaysKHR(physical_device, 0, &disp_count, nullptr)); 41775db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().displays.size(), disp_count); 41785db71995Sopenharmony_ci disps.resize(disp_count); 41795db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneSupportedDisplaysKHR(physical_device, 0, &disp_count, disps.data())); 41805db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().displays.size(), disp_count); 41815db71995Sopenharmony_ci 41825db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplays(disps, env.get_test_icd(0).physical_devices.back().displays)); 41835db71995Sopenharmony_ci} 41845db71995Sopenharmony_ci 41855db71995Sopenharmony_ci// Test vkGetDisplayPlaneSupportedDisplaysKHR where instance supports it with some ICDs that both support 41865db71995Sopenharmony_ci// and don't support it: 41875db71995Sopenharmony_ci// ICD 0 supports 41885db71995Sopenharmony_ci// Physical device 0 does not 41895db71995Sopenharmony_ci// Physical device 1 does 41905db71995Sopenharmony_ci// Physical device 2 does not 41915db71995Sopenharmony_ci// ICD 1 doesn't support 41925db71995Sopenharmony_ci// Physical device 3 does not 41935db71995Sopenharmony_ci// ICD 2 supports 41945db71995Sopenharmony_ci// Physical device 4 does not 41955db71995Sopenharmony_ci// Physical device 5 does not 41965db71995Sopenharmony_ci// ICD 3 supports 41975db71995Sopenharmony_ci// Physical device 6 does 41985db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneSupDispsKHRMixed) { 41995db71995Sopenharmony_ci FrameworkEnvironment env{}; 42005db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 42015db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 42025db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 42035db71995Sopenharmony_ci 42045db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 42055db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 42065db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 42075db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 42085db71995Sopenharmony_ci 42095db71995Sopenharmony_ci // ICD 1 should not have 1.1 42105db71995Sopenharmony_ci if (icd != 1) { 42115db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 42125db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 42135db71995Sopenharmony_ci } 42145db71995Sopenharmony_ci 42155db71995Sopenharmony_ci uint32_t rand_vendor_id; 42165db71995Sopenharmony_ci uint32_t rand_driver_vers; 42175db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 42185db71995Sopenharmony_ci 42195db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 42205db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 42215db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 42225db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 42235db71995Sopenharmony_ci 42245db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 42255db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 42265db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 42275db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 42285db71995Sopenharmony_ci } 42295db71995Sopenharmony_ci 42305db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 42315db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 42325db71995Sopenharmony_ci GenerateRandomDisplays(cur_dev.displays); 42335db71995Sopenharmony_ci } 42345db71995Sopenharmony_ci } 42355db71995Sopenharmony_ci 42365db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 42375db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 42385db71995Sopenharmony_ci instance.CheckCreate(); 42395db71995Sopenharmony_ci 42405db71995Sopenharmony_ci PFN_vkGetDisplayPlaneSupportedDisplaysKHR GetDisplayPlaneSupportedDisplaysKHR = 42415db71995Sopenharmony_ci instance.load("vkGetDisplayPlaneSupportedDisplaysKHR"); 42425db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneSupportedDisplaysKHR, nullptr); 42435db71995Sopenharmony_ci 42445db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 42455db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 42465db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 42475db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 42485db71995Sopenharmony_ci 42495db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 42505db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 42515db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 42525db71995Sopenharmony_ci 42535db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 42545db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 42555db71995Sopenharmony_ci bool found = false; 42565db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 42575db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 42585db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 42595db71995Sopenharmony_ci // physical devices info with the returned info. 42605db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 42615db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 42625db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 42635db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 42645db71995Sopenharmony_ci std::vector<VkDisplayKHR> disps{}; 42655db71995Sopenharmony_ci uint32_t disp_count = 0; 42665db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneSupportedDisplaysKHR(physical_devices[dev], 0, &disp_count, nullptr)); 42675db71995Sopenharmony_ci if (icd == 1) { 42685db71995Sopenharmony_ci // For this extension, if no support exists (like for ICD 1), the value of 0 should be returned by the 42695db71995Sopenharmony_ci // loader. 42705db71995Sopenharmony_ci ASSERT_EQ(0U, disp_count); 42715db71995Sopenharmony_ci } else { 42725db71995Sopenharmony_ci ASSERT_EQ(cur_dev.displays.size(), disp_count); 42735db71995Sopenharmony_ci disps.resize(disp_count); 42745db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 42755db71995Sopenharmony_ci GetDisplayPlaneSupportedDisplaysKHR(physical_devices[dev], 0, &disp_count, disps.data())); 42765db71995Sopenharmony_ci ASSERT_EQ(cur_dev.displays.size(), disp_count); 42775db71995Sopenharmony_ci 42785db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplays(disps, cur_dev.displays)); 42795db71995Sopenharmony_ci } 42805db71995Sopenharmony_ci found = true; 42815db71995Sopenharmony_ci break; 42825db71995Sopenharmony_ci } 42835db71995Sopenharmony_ci } 42845db71995Sopenharmony_ci if (found) { 42855db71995Sopenharmony_ci break; 42865db71995Sopenharmony_ci } 42875db71995Sopenharmony_ci } 42885db71995Sopenharmony_ci } 42895db71995Sopenharmony_ci} 42905db71995Sopenharmony_ci 42915db71995Sopenharmony_ci// Test vkGetDisplayModePropertiesKHR where nothing supports it. 42925db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModePropsKHRNoSupport) { 42935db71995Sopenharmony_ci FrameworkEnvironment env{}; 42945db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 42955db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 42965db71995Sopenharmony_ci 42975db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 42985db71995Sopenharmony_ci instance.CheckCreate(); 42995db71995Sopenharmony_ci 43005db71995Sopenharmony_ci PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR = instance.load("vkGetDisplayModePropertiesKHR"); 43015db71995Sopenharmony_ci ASSERT_EQ(GetDisplayModePropertiesKHR, nullptr); 43025db71995Sopenharmony_ci} 43035db71995Sopenharmony_ci 43045db71995Sopenharmony_ci// Test vkGetDisplayModePropertiesKHR where instance supports it, but nothing else. 43055db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModePropsKHRNoICDSupport) { 43065db71995Sopenharmony_ci FrameworkEnvironment env{}; 43075db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 43085db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 43095db71995Sopenharmony_ci 43105db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 43115db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 43125db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 43135db71995Sopenharmony_ci 43145db71995Sopenharmony_ci PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR = instance.load("vkGetDisplayModePropertiesKHR"); 43155db71995Sopenharmony_ci ASSERT_EQ(GetDisplayModePropertiesKHR, nullptr); 43165db71995Sopenharmony_ci} 43175db71995Sopenharmony_ci 43185db71995Sopenharmony_ci// Fill in random but valid data into the display mode properties data struct for the current physical device 43195db71995Sopenharmony_civoid GenerateRandomDisplayModeProps(std::vector<VkDisplayModePropertiesKHR>& disps) { 43205db71995Sopenharmony_ci disps.resize((rand() % 5) + 1); 43215db71995Sopenharmony_ci for (uint32_t i = 0; i < disps.size(); ++i) { 43225db71995Sopenharmony_ci disps[i].displayMode = CreateRandomDisplayMode(); 43235db71995Sopenharmony_ci disps[i].parameters.visibleRegion.width = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 43245db71995Sopenharmony_ci disps[i].parameters.visibleRegion.height = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 43255db71995Sopenharmony_ci disps[i].parameters.refreshRate = 1 << (rand() % 8); 43265db71995Sopenharmony_ci } 43275db71995Sopenharmony_ci} 43285db71995Sopenharmony_ci 43295db71995Sopenharmony_ci// Compare the display mode properties data structs 43305db71995Sopenharmony_cibool CompareDisplayModeProps(const std::vector<VkDisplayModePropertiesKHR>& disps1, 43315db71995Sopenharmony_ci const std::vector<VkDisplayModePropertiesKHR>& disps2) { 43325db71995Sopenharmony_ci if (disps1.size() != disps2.size()) return false; 43335db71995Sopenharmony_ci bool equal = true; 43345db71995Sopenharmony_ci for (uint32_t i = 0; i < disps1.size(); ++i) { 43355db71995Sopenharmony_ci equal = equal && disps1[i].displayMode == disps2[i].displayMode; 43365db71995Sopenharmony_ci equal = equal && disps1[i].parameters.visibleRegion.width == disps2[i].parameters.visibleRegion.width; 43375db71995Sopenharmony_ci equal = equal && disps1[i].parameters.visibleRegion.height == disps2[i].parameters.visibleRegion.height; 43385db71995Sopenharmony_ci equal = equal && disps1[i].parameters.refreshRate == disps2[i].parameters.refreshRate; 43395db71995Sopenharmony_ci } 43405db71995Sopenharmony_ci return equal; 43415db71995Sopenharmony_ci} 43425db71995Sopenharmony_ci 43435db71995Sopenharmony_ci// Test vGetDisplayModePropertiesKHR where instance and ICD supports it, but device does not support it. 43445db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModePropsKHRInstanceAndICDSupport) { 43455db71995Sopenharmony_ci FrameworkEnvironment env{}; 43465db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 43475db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 43485db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 43495db71995Sopenharmony_ci GenerateRandomDisplayModeProps(env.get_test_icd(0).physical_devices.back().display_mode_properties); 43505db71995Sopenharmony_ci 43515db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 43525db71995Sopenharmony_ci instance.create_info.add_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 43535db71995Sopenharmony_ci instance.CheckCreate(); 43545db71995Sopenharmony_ci 43555db71995Sopenharmony_ci PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR = instance.load("vkGetDisplayModePropertiesKHR"); 43565db71995Sopenharmony_ci ASSERT_NE(GetDisplayModePropertiesKHR, nullptr); 43575db71995Sopenharmony_ci 43585db71995Sopenharmony_ci uint32_t driver_count = 1; 43595db71995Sopenharmony_ci VkPhysicalDevice physical_device; 43605db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 43615db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 43625db71995Sopenharmony_ci 43635db71995Sopenharmony_ci std::vector<VkDisplayModePropertiesKHR> props{}; 43645db71995Sopenharmony_ci uint32_t props_count = 0; 43655db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModePropertiesKHR(physical_device, VK_NULL_HANDLE, &props_count, nullptr)); 43665db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().display_mode_properties.size(), props_count); 43675db71995Sopenharmony_ci props.resize(props_count); 43685db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModePropertiesKHR(physical_device, VK_NULL_HANDLE, &props_count, props.data())); 43695db71995Sopenharmony_ci ASSERT_EQ(env.get_test_icd(0).physical_devices.back().display_mode_properties.size(), props_count); 43705db71995Sopenharmony_ci 43715db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayModeProps(props, env.get_test_icd(0).physical_devices.back().display_mode_properties)); 43725db71995Sopenharmony_ci} 43735db71995Sopenharmony_ci 43745db71995Sopenharmony_ci// Test vkGetDisplayModePropertiesKHR where instance supports it with some ICDs that both support 43755db71995Sopenharmony_ci// and don't support it: 43765db71995Sopenharmony_ci// ICD 0 supports 43775db71995Sopenharmony_ci// Physical device 0 does not 43785db71995Sopenharmony_ci// Physical device 1 does 43795db71995Sopenharmony_ci// Physical device 2 does not 43805db71995Sopenharmony_ci// ICD 1 doesn't support 43815db71995Sopenharmony_ci// Physical device 3 does not 43825db71995Sopenharmony_ci// ICD 2 supports 43835db71995Sopenharmony_ci// Physical device 4 does not 43845db71995Sopenharmony_ci// Physical device 5 does not 43855db71995Sopenharmony_ci// ICD 3 supports 43865db71995Sopenharmony_ci// Physical device 6 does 43875db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModePropsKHRMixed) { 43885db71995Sopenharmony_ci FrameworkEnvironment env{}; 43895db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 43905db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 43915db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 43925db71995Sopenharmony_ci 43935db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 43945db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 43955db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 43965db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 43975db71995Sopenharmony_ci 43985db71995Sopenharmony_ci // ICD 1 should not have 1.1 43995db71995Sopenharmony_ci if (icd != 1) { 44005db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 44015db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 44025db71995Sopenharmony_ci } 44035db71995Sopenharmony_ci 44045db71995Sopenharmony_ci uint32_t rand_vendor_id; 44055db71995Sopenharmony_ci uint32_t rand_driver_vers; 44065db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 44075db71995Sopenharmony_ci 44085db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 44095db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 44105db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 44115db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 44125db71995Sopenharmony_ci 44135db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 44145db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 44155db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 44165db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 44175db71995Sopenharmony_ci } 44185db71995Sopenharmony_ci 44195db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 44205db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 44215db71995Sopenharmony_ci GenerateRandomDisplayModeProps(cur_dev.display_mode_properties); 44225db71995Sopenharmony_ci } 44235db71995Sopenharmony_ci } 44245db71995Sopenharmony_ci 44255db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 44265db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 44275db71995Sopenharmony_ci instance.CheckCreate(); 44285db71995Sopenharmony_ci 44295db71995Sopenharmony_ci PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR = instance.load("vkGetDisplayModePropertiesKHR"); 44305db71995Sopenharmony_ci ASSERT_NE(GetDisplayModePropertiesKHR, nullptr); 44315db71995Sopenharmony_ci 44325db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 44335db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 44345db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 44355db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 44365db71995Sopenharmony_ci 44375db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 44385db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 44395db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 44405db71995Sopenharmony_ci 44415db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 44425db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 44435db71995Sopenharmony_ci bool found = false; 44445db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 44455db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 44465db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 44475db71995Sopenharmony_ci // physical devices info with the returned info. 44485db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 44495db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 44505db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 44515db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 44525db71995Sopenharmony_ci uint32_t props_count = 0; 44535db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 44545db71995Sopenharmony_ci GetDisplayModePropertiesKHR(physical_devices[dev], VK_NULL_HANDLE, &props_count, nullptr)); 44555db71995Sopenharmony_ci if (icd == 1) { 44565db71995Sopenharmony_ci // For this extension, if no support exists (like for ICD 1), the value of 0 should be returned by the 44575db71995Sopenharmony_ci // loader. 44585db71995Sopenharmony_ci ASSERT_EQ(0U, props_count); 44595db71995Sopenharmony_ci } else { 44605db71995Sopenharmony_ci std::vector<VkDisplayModePropertiesKHR> props{}; 44615db71995Sopenharmony_ci ASSERT_EQ(cur_dev.display_mode_properties.size(), props_count); 44625db71995Sopenharmony_ci props.resize(props_count); 44635db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 44645db71995Sopenharmony_ci GetDisplayModePropertiesKHR(physical_devices[dev], VK_NULL_HANDLE, &props_count, props.data())); 44655db71995Sopenharmony_ci ASSERT_EQ(cur_dev.display_mode_properties.size(), props_count); 44665db71995Sopenharmony_ci 44675db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayModeProps(props, cur_dev.display_mode_properties)); 44685db71995Sopenharmony_ci } 44695db71995Sopenharmony_ci found = true; 44705db71995Sopenharmony_ci break; 44715db71995Sopenharmony_ci } 44725db71995Sopenharmony_ci } 44735db71995Sopenharmony_ci if (found) { 44745db71995Sopenharmony_ci break; 44755db71995Sopenharmony_ci } 44765db71995Sopenharmony_ci } 44775db71995Sopenharmony_ci } 44785db71995Sopenharmony_ci} 44795db71995Sopenharmony_ci 44805db71995Sopenharmony_ci// Test vkCreateDisplayModeKHR where nothing supports it. 44815db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModesKHRNoSupport) { 44825db71995Sopenharmony_ci FrameworkEnvironment env{}; 44835db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 44845db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 44855db71995Sopenharmony_ci 44865db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 44875db71995Sopenharmony_ci instance.CheckCreate(); 44885db71995Sopenharmony_ci 44895db71995Sopenharmony_ci PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR = instance.load("vkCreateDisplayModeKHR"); 44905db71995Sopenharmony_ci ASSERT_EQ(CreateDisplayModeKHR, nullptr); 44915db71995Sopenharmony_ci} 44925db71995Sopenharmony_ci 44935db71995Sopenharmony_ci// Test vkCreateDisplayModeKHR where instance supports it, but nothing else. 44945db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModesKHRNoICDSupport) { 44955db71995Sopenharmony_ci FrameworkEnvironment env{}; 44965db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 44975db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 44985db71995Sopenharmony_ci 44995db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 45005db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 45015db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 45025db71995Sopenharmony_ci 45035db71995Sopenharmony_ci PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR = instance.load("vkCreateDisplayModeKHR"); 45045db71995Sopenharmony_ci ASSERT_EQ(CreateDisplayModeKHR, nullptr); 45055db71995Sopenharmony_ci} 45065db71995Sopenharmony_ci 45075db71995Sopenharmony_ci// Compare the display modes 45085db71995Sopenharmony_cibool CompareDisplayModes(const VkDisplayModeKHR& disps1, VkDisplayModeKHR& disps2) { return disps1 == disps2; } 45095db71995Sopenharmony_ci 45105db71995Sopenharmony_ci// Test vkCreateDisplayModeKHR where instance and ICD supports it, but device does not support it. 45115db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModesKHRInstanceAndICDSupport) { 45125db71995Sopenharmony_ci FrameworkEnvironment env{}; 45135db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 45145db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 45155db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 45165db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().display_mode = CreateRandomDisplayMode(); 45175db71995Sopenharmony_ci 45185db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 45195db71995Sopenharmony_ci instance.create_info.add_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 45205db71995Sopenharmony_ci instance.CheckCreate(); 45215db71995Sopenharmony_ci 45225db71995Sopenharmony_ci PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR = instance.load("vkCreateDisplayModeKHR"); 45235db71995Sopenharmony_ci ASSERT_NE(CreateDisplayModeKHR, nullptr); 45245db71995Sopenharmony_ci 45255db71995Sopenharmony_ci uint32_t driver_count = 1; 45265db71995Sopenharmony_ci VkPhysicalDevice physical_device; 45275db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 45285db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 45295db71995Sopenharmony_ci 45305db71995Sopenharmony_ci VkDisplayModeKHR mode{}; 45315db71995Sopenharmony_ci VkDisplayModeCreateInfoKHR create_info{VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR}; 45325db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, CreateDisplayModeKHR(physical_device, VK_NULL_HANDLE, &create_info, nullptr, &mode)); 45335db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayModes(mode, env.get_test_icd(0).physical_devices.back().display_mode)); 45345db71995Sopenharmony_ci} 45355db71995Sopenharmony_ci 45365db71995Sopenharmony_ci// Test vkCreateDisplayModeKHR where instance supports it with some ICDs that both support 45375db71995Sopenharmony_ci// and don't support it: 45385db71995Sopenharmony_ci// ICD 0 supports 45395db71995Sopenharmony_ci// Physical device 0 does not 45405db71995Sopenharmony_ci// Physical device 1 does 45415db71995Sopenharmony_ci// Physical device 2 does not 45425db71995Sopenharmony_ci// ICD 1 doesn't support 45435db71995Sopenharmony_ci// Physical device 3 does not 45445db71995Sopenharmony_ci// ICD 2 supports 45455db71995Sopenharmony_ci// Physical device 4 does not 45465db71995Sopenharmony_ci// Physical device 5 does not 45475db71995Sopenharmony_ci// ICD 3 supports 45485db71995Sopenharmony_ci// Physical device 6 does 45495db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModesKHRMixed) { 45505db71995Sopenharmony_ci FrameworkEnvironment env{}; 45515db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 45525db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 45535db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 45545db71995Sopenharmony_ci 45555db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 45565db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 45575db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 45585db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 45595db71995Sopenharmony_ci 45605db71995Sopenharmony_ci // ICD 1 should not have 1.1 45615db71995Sopenharmony_ci if (icd != 1) { 45625db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 45635db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 45645db71995Sopenharmony_ci } 45655db71995Sopenharmony_ci 45665db71995Sopenharmony_ci uint32_t rand_vendor_id; 45675db71995Sopenharmony_ci uint32_t rand_driver_vers; 45685db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 45695db71995Sopenharmony_ci 45705db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 45715db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 45725db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 45735db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 45745db71995Sopenharmony_ci 45755db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 45765db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 45775db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 45785db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 45795db71995Sopenharmony_ci } 45805db71995Sopenharmony_ci 45815db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 45825db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 45835db71995Sopenharmony_ci cur_dev.display_mode = CreateRandomDisplayMode(); 45845db71995Sopenharmony_ci } 45855db71995Sopenharmony_ci } 45865db71995Sopenharmony_ci 45875db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 45885db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 45895db71995Sopenharmony_ci instance.CheckCreate(); 45905db71995Sopenharmony_ci 45915db71995Sopenharmony_ci PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR = instance.load("vkCreateDisplayModeKHR"); 45925db71995Sopenharmony_ci ASSERT_NE(CreateDisplayModeKHR, nullptr); 45935db71995Sopenharmony_ci 45945db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 45955db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 45965db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 45975db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 45985db71995Sopenharmony_ci 45995db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 46005db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 46015db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 46025db71995Sopenharmony_ci 46035db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 46045db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 46055db71995Sopenharmony_ci bool found = false; 46065db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 46075db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 46085db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 46095db71995Sopenharmony_ci // physical devices info with the returned info. 46105db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 46115db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 46125db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 46135db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 46145db71995Sopenharmony_ci VkDisplayModeKHR mode{}; 46155db71995Sopenharmony_ci VkDisplayModeCreateInfoKHR create_info{VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR}; 46165db71995Sopenharmony_ci if (icd == 1) { 46175db71995Sopenharmony_ci // Unsupported ICD should return initialization failed (instead of crash) 46185db71995Sopenharmony_ci ASSERT_EQ(VK_ERROR_INITIALIZATION_FAILED, 46195db71995Sopenharmony_ci CreateDisplayModeKHR(physical_devices[dev], VK_NULL_HANDLE, &create_info, nullptr, &mode)); 46205db71995Sopenharmony_ci } else { 46215db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 46225db71995Sopenharmony_ci CreateDisplayModeKHR(physical_devices[dev], VK_NULL_HANDLE, &create_info, nullptr, &mode)); 46235db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayModes(mode, cur_dev.display_mode)); 46245db71995Sopenharmony_ci } 46255db71995Sopenharmony_ci found = true; 46265db71995Sopenharmony_ci break; 46275db71995Sopenharmony_ci } 46285db71995Sopenharmony_ci } 46295db71995Sopenharmony_ci if (found) { 46305db71995Sopenharmony_ci break; 46315db71995Sopenharmony_ci } 46325db71995Sopenharmony_ci } 46335db71995Sopenharmony_ci } 46345db71995Sopenharmony_ci} 46355db71995Sopenharmony_ci 46365db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilitiesKHR where nothing supports it. 46375db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCapsKHRNoSupport) { 46385db71995Sopenharmony_ci FrameworkEnvironment env{}; 46395db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 46405db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 46415db71995Sopenharmony_ci 46425db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 46435db71995Sopenharmony_ci instance.CheckCreate(); 46445db71995Sopenharmony_ci 46455db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 46465db71995Sopenharmony_ci ASSERT_EQ(GetDisplayPlaneCapabilitiesKHR, nullptr); 46475db71995Sopenharmony_ci} 46485db71995Sopenharmony_ci 46495db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilitiesKHR where instance supports it, but nothing else. 46505db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCapsKHRNoICDSupport) { 46515db71995Sopenharmony_ci FrameworkEnvironment env{}; 46525db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 46535db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 46545db71995Sopenharmony_ci 46555db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 46565db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 46575db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 46585db71995Sopenharmony_ci 46595db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 46605db71995Sopenharmony_ci ASSERT_EQ(GetDisplayPlaneCapabilitiesKHR, nullptr); 46615db71995Sopenharmony_ci} 46625db71995Sopenharmony_ci 46635db71995Sopenharmony_ci// Fill in random but valid data into the display plane caps for the current physical device 46645db71995Sopenharmony_civoid GenerateRandomDisplayPlaneCaps(VkDisplayPlaneCapabilitiesKHR& caps) { 46655db71995Sopenharmony_ci caps.supportedAlpha = static_cast<VkDisplayPlaneAlphaFlagsKHR>((rand() % 0xFFFFFFF) + 1); 46665db71995Sopenharmony_ci caps.minSrcPosition.x = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46675db71995Sopenharmony_ci caps.minSrcPosition.y = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46685db71995Sopenharmony_ci caps.maxSrcPosition.x = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46695db71995Sopenharmony_ci caps.maxSrcPosition.y = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46705db71995Sopenharmony_ci caps.minSrcExtent.width = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46715db71995Sopenharmony_ci caps.minSrcExtent.height = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46725db71995Sopenharmony_ci caps.maxSrcExtent.width = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46735db71995Sopenharmony_ci caps.maxSrcExtent.height = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46745db71995Sopenharmony_ci caps.minDstPosition.x = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46755db71995Sopenharmony_ci caps.minDstPosition.y = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46765db71995Sopenharmony_ci caps.maxDstPosition.x = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46775db71995Sopenharmony_ci caps.maxDstPosition.y = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46785db71995Sopenharmony_ci caps.minDstExtent.width = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46795db71995Sopenharmony_ci caps.minDstExtent.height = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46805db71995Sopenharmony_ci caps.maxDstExtent.width = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46815db71995Sopenharmony_ci caps.maxDstExtent.height = static_cast<uint32_t>((rand() % 0xFFFFFFF) + 1); 46825db71995Sopenharmony_ci} 46835db71995Sopenharmony_ci 46845db71995Sopenharmony_ci// Compare the display plane caps 46855db71995Sopenharmony_cibool CompareDisplayPlaneCaps(const VkDisplayPlaneCapabilitiesKHR& caps1, VkDisplayPlaneCapabilitiesKHR& caps2, 46865db71995Sopenharmony_ci bool supported = true) { 46875db71995Sopenharmony_ci bool equal = true; 46885db71995Sopenharmony_ci if (supported) { 46895db71995Sopenharmony_ci equal = equal && caps1.supportedAlpha == caps2.supportedAlpha; 46905db71995Sopenharmony_ci equal = equal && caps1.minSrcPosition.x == caps2.minSrcPosition.x; 46915db71995Sopenharmony_ci equal = equal && caps1.minSrcPosition.y == caps2.minSrcPosition.y; 46925db71995Sopenharmony_ci equal = equal && caps1.maxSrcPosition.x == caps2.maxSrcPosition.x; 46935db71995Sopenharmony_ci equal = equal && caps1.maxSrcPosition.y == caps2.maxSrcPosition.y; 46945db71995Sopenharmony_ci equal = equal && caps1.minSrcExtent.width == caps2.minSrcExtent.width; 46955db71995Sopenharmony_ci equal = equal && caps1.minSrcExtent.height == caps2.minSrcExtent.height; 46965db71995Sopenharmony_ci equal = equal && caps1.maxSrcExtent.width == caps2.maxSrcExtent.width; 46975db71995Sopenharmony_ci equal = equal && caps1.maxSrcExtent.height == caps2.maxSrcExtent.height; 46985db71995Sopenharmony_ci equal = equal && caps1.minDstPosition.x == caps2.minDstPosition.x; 46995db71995Sopenharmony_ci equal = equal && caps1.minDstPosition.y == caps2.minDstPosition.y; 47005db71995Sopenharmony_ci equal = equal && caps1.maxDstPosition.x == caps2.maxDstPosition.x; 47015db71995Sopenharmony_ci equal = equal && caps1.maxDstPosition.y == caps2.maxDstPosition.y; 47025db71995Sopenharmony_ci equal = equal && caps1.minDstExtent.width == caps2.minDstExtent.width; 47035db71995Sopenharmony_ci equal = equal && caps1.minDstExtent.height == caps2.minDstExtent.height; 47045db71995Sopenharmony_ci equal = equal && caps1.maxDstExtent.width == caps2.maxDstExtent.width; 47055db71995Sopenharmony_ci equal = equal && caps1.maxDstExtent.height == caps2.maxDstExtent.height; 47065db71995Sopenharmony_ci } else { 47075db71995Sopenharmony_ci equal = equal && caps1.supportedAlpha == 0; 47085db71995Sopenharmony_ci equal = equal && caps1.minSrcPosition.x == 0; 47095db71995Sopenharmony_ci equal = equal && caps1.minSrcPosition.y == 0; 47105db71995Sopenharmony_ci equal = equal && caps1.maxSrcPosition.x == 0; 47115db71995Sopenharmony_ci equal = equal && caps1.maxSrcPosition.y == 0; 47125db71995Sopenharmony_ci equal = equal && caps1.minSrcExtent.width == 0; 47135db71995Sopenharmony_ci equal = equal && caps1.minSrcExtent.height == 0; 47145db71995Sopenharmony_ci equal = equal && caps1.maxSrcExtent.width == 0; 47155db71995Sopenharmony_ci equal = equal && caps1.maxSrcExtent.height == 0; 47165db71995Sopenharmony_ci equal = equal && caps1.minDstPosition.x == 0; 47175db71995Sopenharmony_ci equal = equal && caps1.minDstPosition.y == 0; 47185db71995Sopenharmony_ci equal = equal && caps1.maxDstPosition.x == 0; 47195db71995Sopenharmony_ci equal = equal && caps1.maxDstPosition.y == 0; 47205db71995Sopenharmony_ci equal = equal && caps1.minDstExtent.width == 0; 47215db71995Sopenharmony_ci equal = equal && caps1.minDstExtent.height == 0; 47225db71995Sopenharmony_ci equal = equal && caps1.maxDstExtent.width == 0; 47235db71995Sopenharmony_ci equal = equal && caps1.maxDstExtent.height == 0; 47245db71995Sopenharmony_ci } 47255db71995Sopenharmony_ci return equal; 47265db71995Sopenharmony_ci} 47275db71995Sopenharmony_ci 47285db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilitiesKHR where instance and ICD supports it, but device does not support it. 47295db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCapsKHRInstanceAndICDSupport) { 47305db71995Sopenharmony_ci FrameworkEnvironment env{}; 47315db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 47325db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 47335db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 47345db71995Sopenharmony_ci GenerateRandomDisplayPlaneCaps(env.get_test_icd(0).physical_devices.back().display_plane_capabilities); 47355db71995Sopenharmony_ci 47365db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 47375db71995Sopenharmony_ci instance.create_info.add_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 47385db71995Sopenharmony_ci instance.CheckCreate(); 47395db71995Sopenharmony_ci 47405db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 47415db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneCapabilitiesKHR, nullptr); 47425db71995Sopenharmony_ci 47435db71995Sopenharmony_ci uint32_t driver_count = 1; 47445db71995Sopenharmony_ci VkPhysicalDevice physical_device; 47455db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 47465db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 47475db71995Sopenharmony_ci 47485db71995Sopenharmony_ci VkDisplayPlaneCapabilitiesKHR caps{}; 47495db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneCapabilitiesKHR(physical_device, 0, 0, &caps)); 47505db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPlaneCaps(caps, env.get_test_icd(0).physical_devices.back().display_plane_capabilities)); 47515db71995Sopenharmony_ci} 47525db71995Sopenharmony_ci 47535db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilitiesKHR where instance supports it with some ICDs that both support 47545db71995Sopenharmony_ci// and don't support it: 47555db71995Sopenharmony_ci// ICD 0 supports 47565db71995Sopenharmony_ci// Physical device 0 does not 47575db71995Sopenharmony_ci// Physical device 1 does 47585db71995Sopenharmony_ci// Physical device 2 does not 47595db71995Sopenharmony_ci// ICD 1 doesn't support 47605db71995Sopenharmony_ci// Physical device 3 does not 47615db71995Sopenharmony_ci// ICD 2 supports 47625db71995Sopenharmony_ci// Physical device 4 does not 47635db71995Sopenharmony_ci// Physical device 5 does not 47645db71995Sopenharmony_ci// ICD 3 supports 47655db71995Sopenharmony_ci// Physical device 6 does 47665db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCapsKHRMixed) { 47675db71995Sopenharmony_ci FrameworkEnvironment env{}; 47685db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 47695db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 47705db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 47715db71995Sopenharmony_ci 47725db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 47735db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 47745db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 47755db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 47765db71995Sopenharmony_ci 47775db71995Sopenharmony_ci // ICD 1 should not have 1.1 47785db71995Sopenharmony_ci if (icd != 1) { 47795db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 47805db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 47815db71995Sopenharmony_ci } 47825db71995Sopenharmony_ci 47835db71995Sopenharmony_ci uint32_t rand_vendor_id; 47845db71995Sopenharmony_ci uint32_t rand_driver_vers; 47855db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 47865db71995Sopenharmony_ci 47875db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 47885db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 47895db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 47905db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 47915db71995Sopenharmony_ci 47925db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 47935db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 47945db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 47955db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 47965db71995Sopenharmony_ci } 47975db71995Sopenharmony_ci 47985db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 47995db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 48005db71995Sopenharmony_ci GenerateRandomDisplayPlaneCaps(cur_dev.display_plane_capabilities); 48015db71995Sopenharmony_ci } 48025db71995Sopenharmony_ci } 48035db71995Sopenharmony_ci 48045db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 48055db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_DISPLAY_EXTENSION_NAME); 48065db71995Sopenharmony_ci instance.CheckCreate(); 48075db71995Sopenharmony_ci 48085db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 48095db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneCapabilitiesKHR, nullptr); 48105db71995Sopenharmony_ci 48115db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 48125db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 48135db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 48145db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 48155db71995Sopenharmony_ci 48165db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 48175db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 48185db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 48195db71995Sopenharmony_ci 48205db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 48215db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 48225db71995Sopenharmony_ci bool found = false; 48235db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 48245db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 48255db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 48265db71995Sopenharmony_ci // physical devices info with the returned info. 48275db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 48285db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 48295db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 48305db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 48315db71995Sopenharmony_ci VkDisplayPlaneCapabilitiesKHR caps{}; 48325db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneCapabilitiesKHR(physical_devices[dev], 0, 0, &caps)); 48335db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPlaneCaps(caps, cur_dev.display_plane_capabilities, icd != 1)); 48345db71995Sopenharmony_ci found = true; 48355db71995Sopenharmony_ci break; 48365db71995Sopenharmony_ci } 48375db71995Sopenharmony_ci } 48385db71995Sopenharmony_ci if (found) { 48395db71995Sopenharmony_ci break; 48405db71995Sopenharmony_ci } 48415db71995Sopenharmony_ci } 48425db71995Sopenharmony_ci } 48435db71995Sopenharmony_ci} 48445db71995Sopenharmony_ci 48455db71995Sopenharmony_ci// 48465db71995Sopenharmony_ci// VK_KHR_get_display_properties2 48475db71995Sopenharmony_ci// 48485db71995Sopenharmony_ci 48495db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayProperties2KHR where nothing supports it. 48505db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispProps2KHRNoSupport) { 48515db71995Sopenharmony_ci FrameworkEnvironment env{}; 48525db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 48535db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 48545db71995Sopenharmony_ci 48555db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 48565db71995Sopenharmony_ci instance.CheckCreate(); 48575db71995Sopenharmony_ci 48585db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayProperties2KHR GetPhysicalDeviceDisplayProperties2KHR = 48595db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayProperties2KHR"); 48605db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayProperties2KHR, nullptr); 48615db71995Sopenharmony_ci} 48625db71995Sopenharmony_ci 48635db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayProperties2KHR where instance supports it, but nothing else. 48645db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispProps2KHRNoICDSupport) { 48655db71995Sopenharmony_ci FrameworkEnvironment env{}; 48665db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 48675db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 48685db71995Sopenharmony_ci 48695db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 48705db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME); 48715db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 48725db71995Sopenharmony_ci 48735db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayProperties2KHR GetPhysicalDeviceDisplayProperties2KHR = 48745db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayProperties2KHR"); 48755db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayProperties2KHR, nullptr); 48765db71995Sopenharmony_ci} 48775db71995Sopenharmony_ci 48785db71995Sopenharmony_ci// Compare the display property data structs 48795db71995Sopenharmony_cibool CompareDisplayPropData(const std::vector<VkDisplayPropertiesKHR>& props1, const std::vector<VkDisplayProperties2KHR>& props2) { 48805db71995Sopenharmony_ci if (props1.size() != props2.size()) return false; 48815db71995Sopenharmony_ci bool equal = true; 48825db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.size(); ++i) { 48835db71995Sopenharmony_ci equal = equal && props1[i].display == props2[i].displayProperties.display; 48845db71995Sopenharmony_ci equal = equal && props1[i].physicalDimensions.width == props2[i].displayProperties.physicalDimensions.width; 48855db71995Sopenharmony_ci equal = equal && props1[i].physicalDimensions.height == props2[i].displayProperties.physicalDimensions.height; 48865db71995Sopenharmony_ci equal = equal && props1[i].physicalResolution.width == props2[i].displayProperties.physicalResolution.width; 48875db71995Sopenharmony_ci equal = equal && props1[i].physicalResolution.height == props2[i].displayProperties.physicalResolution.height; 48885db71995Sopenharmony_ci equal = equal && props1[i].supportedTransforms == props2[i].displayProperties.supportedTransforms; 48895db71995Sopenharmony_ci equal = equal && props1[i].planeReorderPossible == props2[i].displayProperties.planeReorderPossible; 48905db71995Sopenharmony_ci equal = equal && props1[i].persistentContent == props2[i].displayProperties.persistentContent; 48915db71995Sopenharmony_ci } 48925db71995Sopenharmony_ci return equal; 48935db71995Sopenharmony_ci} 48945db71995Sopenharmony_ci 48955db71995Sopenharmony_ci// Test vGetPhysicalDeviceDisplayProperties2KHR where instance and ICD supports it, but device does not support it. 48965db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispProps2KHRInstanceAndICDSupport) { 48975db71995Sopenharmony_ci FrameworkEnvironment env{}; 48985db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 48995db71995Sopenharmony_ci Extension first_ext{VK_KHR_DISPLAY_EXTENSION_NAME}; 49005db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}; 49015db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extensions({first_ext, second_ext}); 49025db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 49035db71995Sopenharmony_ci FillInRandomDisplayPropData(env.get_test_icd(0).physical_devices.back().display_properties); 49045db71995Sopenharmony_ci 49055db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 49065db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 49075db71995Sopenharmony_ci instance.CheckCreate(); 49085db71995Sopenharmony_ci 49095db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPropertiesKHR GetPhysicalDeviceDisplayPropertiesKHR = 49105db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPropertiesKHR"); 49115db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPropertiesKHR, nullptr); 49125db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayProperties2KHR GetPhysicalDeviceDisplayProperties2KHR = 49135db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayProperties2KHR"); 49145db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayProperties2KHR, nullptr); 49155db71995Sopenharmony_ci 49165db71995Sopenharmony_ci uint32_t driver_count = 1; 49175db71995Sopenharmony_ci VkPhysicalDevice physical_device; 49185db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 49195db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 49205db71995Sopenharmony_ci 49215db71995Sopenharmony_ci std::vector<VkDisplayPropertiesKHR> props{}; 49225db71995Sopenharmony_ci uint32_t prop_count = 0; 49235db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPropertiesKHR(physical_device, &prop_count, nullptr)); 49245db71995Sopenharmony_ci ASSERT_NE(0U, prop_count); 49255db71995Sopenharmony_ci props.resize(prop_count); 49265db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPropertiesKHR(physical_device, &prop_count, props.data())); 49275db71995Sopenharmony_ci 49285db71995Sopenharmony_ci std::vector<VkDisplayProperties2KHR> props2{}; 49295db71995Sopenharmony_ci uint32_t prop_count_2 = 0; 49305db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayProperties2KHR(physical_device, &prop_count_2, nullptr)); 49315db71995Sopenharmony_ci ASSERT_EQ(prop_count, prop_count_2); 49325db71995Sopenharmony_ci props2.resize(prop_count_2, {VK_STRUCTURE_TYPE_DISPLAY_PROPERTIES_2_KHR}); 49335db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayProperties2KHR(physical_device, &prop_count_2, props2.data())); 49345db71995Sopenharmony_ci ASSERT_EQ(prop_count, prop_count_2); 49355db71995Sopenharmony_ci 49365db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPropData(props, props2)); 49375db71995Sopenharmony_ci} 49385db71995Sopenharmony_ci 49395db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayProperties2KHR where instance supports it with some ICDs that both support 49405db71995Sopenharmony_ci// and don't support it: 49415db71995Sopenharmony_ci// ICD 0 supports 49425db71995Sopenharmony_ci// Physical device 0 does not 49435db71995Sopenharmony_ci// Physical device 1 does 49445db71995Sopenharmony_ci// Physical device 2 does not 49455db71995Sopenharmony_ci// ICD 1 doesn't support 49465db71995Sopenharmony_ci// Physical device 3 does not 49475db71995Sopenharmony_ci// ICD 2 supports 49485db71995Sopenharmony_ci// Physical device 4 does not 49495db71995Sopenharmony_ci// Physical device 5 does not 49505db71995Sopenharmony_ci// ICD 3 supports 49515db71995Sopenharmony_ci// Physical device 6 does 49525db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispProps2KHRMixed) { 49535db71995Sopenharmony_ci FrameworkEnvironment env{}; 49545db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 49555db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 49565db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 49575db71995Sopenharmony_ci 49585db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 49595db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 49605db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 49615db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 49625db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 49635db71995Sopenharmony_ci 49645db71995Sopenharmony_ci // ICD 1 should not have 1.1 49655db71995Sopenharmony_ci if (icd != 1) { 49665db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 49675db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 49685db71995Sopenharmony_ci } 49695db71995Sopenharmony_ci 49705db71995Sopenharmony_ci uint32_t rand_vendor_id; 49715db71995Sopenharmony_ci uint32_t rand_driver_vers; 49725db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 49735db71995Sopenharmony_ci 49745db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 49755db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 49765db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 49775db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 49785db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 49795db71995Sopenharmony_ci 49805db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 49815db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 49825db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME, 0}); 49835db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 49845db71995Sopenharmony_ci } 49855db71995Sopenharmony_ci 49865db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 49875db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 49885db71995Sopenharmony_ci FillInRandomDisplayPropData(cur_dev.display_properties); 49895db71995Sopenharmony_ci } 49905db71995Sopenharmony_ci } 49915db71995Sopenharmony_ci 49925db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 49935db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 49945db71995Sopenharmony_ci instance.CheckCreate(); 49955db71995Sopenharmony_ci 49965db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPropertiesKHR GetPhysicalDeviceDisplayPropertiesKHR = 49975db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPropertiesKHR"); 49985db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPropertiesKHR, nullptr); 49995db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayProperties2KHR GetPhysicalDeviceDisplayProperties2KHR = 50005db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayProperties2KHR"); 50015db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayProperties2KHR, nullptr); 50025db71995Sopenharmony_ci 50035db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 50045db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 50055db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 50065db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 50075db71995Sopenharmony_ci 50085db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 50095db71995Sopenharmony_ci std::vector<VkDisplayPropertiesKHR> props{}; 50105db71995Sopenharmony_ci uint32_t prop_count = 0; 50115db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPropertiesKHR(physical_devices[dev], &prop_count, nullptr)); 50125db71995Sopenharmony_ci ASSERT_NE(0U, prop_count); 50135db71995Sopenharmony_ci props.resize(prop_count); 50145db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPropertiesKHR(physical_devices[dev], &prop_count, props.data())); 50155db71995Sopenharmony_ci 50165db71995Sopenharmony_ci std::vector<VkDisplayProperties2KHR> props2{}; 50175db71995Sopenharmony_ci uint32_t prop_count_2 = 0; 50185db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayProperties2KHR(physical_devices[dev], &prop_count_2, nullptr)); 50195db71995Sopenharmony_ci ASSERT_EQ(prop_count, prop_count_2); 50205db71995Sopenharmony_ci props2.resize(prop_count_2, {VK_STRUCTURE_TYPE_DISPLAY_PROPERTIES_2_KHR}); 50215db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayProperties2KHR(physical_devices[dev], &prop_count_2, props2.data())); 50225db71995Sopenharmony_ci ASSERT_EQ(prop_count, prop_count_2); 50235db71995Sopenharmony_ci 50245db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPropData(props, props2)); 50255db71995Sopenharmony_ci } 50265db71995Sopenharmony_ci} 50275db71995Sopenharmony_ci 50285db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPlaneProperties2KHR where nothing supports it. 50295db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlaneProps2KHRNoSupport) { 50305db71995Sopenharmony_ci FrameworkEnvironment env{}; 50315db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 50325db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 50335db71995Sopenharmony_ci 50345db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 50355db71995Sopenharmony_ci instance.CheckCreate(); 50365db71995Sopenharmony_ci 50375db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR GetPhysicalDeviceDisplayPlaneProperties2KHR = 50385db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlaneProperties2KHR"); 50395db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayPlaneProperties2KHR, nullptr); 50405db71995Sopenharmony_ci} 50415db71995Sopenharmony_ci 50425db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPlaneProperties2KHR where instance supports it, but nothing else. 50435db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlaneProps2KHRNoICDSupport) { 50445db71995Sopenharmony_ci FrameworkEnvironment env{}; 50455db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 50465db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 50475db71995Sopenharmony_ci 50485db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 50495db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME); 50505db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 50515db71995Sopenharmony_ci 50525db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR GetPhysicalDeviceDisplayPlaneProperties2KHR = 50535db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlaneProperties2KHR"); 50545db71995Sopenharmony_ci ASSERT_EQ(GetPhysicalDeviceDisplayPlaneProperties2KHR, nullptr); 50555db71995Sopenharmony_ci} 50565db71995Sopenharmony_ci 50575db71995Sopenharmony_ci// Compare the display plane property data structs 50585db71995Sopenharmony_cibool CompareDisplayPlanePropData(const std::vector<VkDisplayPlanePropertiesKHR>& props1, 50595db71995Sopenharmony_ci const std::vector<VkDisplayPlaneProperties2KHR>& props2) { 50605db71995Sopenharmony_ci if (props1.size() != props2.size()) return false; 50615db71995Sopenharmony_ci bool equal = true; 50625db71995Sopenharmony_ci for (uint32_t i = 0; i < props1.size(); ++i) { 50635db71995Sopenharmony_ci equal = equal && props1[i].currentDisplay == props2[i].displayPlaneProperties.currentDisplay; 50645db71995Sopenharmony_ci equal = equal && props1[i].currentStackIndex == props2[i].displayPlaneProperties.currentStackIndex; 50655db71995Sopenharmony_ci } 50665db71995Sopenharmony_ci return equal; 50675db71995Sopenharmony_ci} 50685db71995Sopenharmony_ci 50695db71995Sopenharmony_ci// Test vGetPhysicalDeviceDisplayPlaneProperties2KHR where instance and ICD supports it, but device does not support it. 50705db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlaneProps2KHRInstanceAndICDSupport) { 50715db71995Sopenharmony_ci FrameworkEnvironment env{}; 50725db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 50735db71995Sopenharmony_ci Extension first_ext{VK_KHR_DISPLAY_EXTENSION_NAME}; 50745db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}; 50755db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extensions({first_ext, second_ext}); 50765db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 50775db71995Sopenharmony_ci FillInRandomDisplayPlanePropData(env.get_test_icd(0).physical_devices.back().display_plane_properties); 50785db71995Sopenharmony_ci 50795db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 50805db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 50815db71995Sopenharmony_ci instance.CheckCreate(); 50825db71995Sopenharmony_ci 50835db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR GetPhysicalDeviceDisplayPlanePropertiesKHR = 50845db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); 50855db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPlanePropertiesKHR, nullptr); 50865db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR GetPhysicalDeviceDisplayPlaneProperties2KHR = 50875db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlaneProperties2KHR"); 50885db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPlaneProperties2KHR, nullptr); 50895db71995Sopenharmony_ci 50905db71995Sopenharmony_ci uint32_t driver_count = 1; 50915db71995Sopenharmony_ci VkPhysicalDevice physical_device; 50925db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 50935db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 50945db71995Sopenharmony_ci 50955db71995Sopenharmony_ci std::vector<VkDisplayPlanePropertiesKHR> props{}; 50965db71995Sopenharmony_ci uint32_t prop_count = 0; 50975db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_device, &prop_count, nullptr)); 50985db71995Sopenharmony_ci ASSERT_NE(0U, prop_count); 50995db71995Sopenharmony_ci props.resize(prop_count); 51005db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_device, &prop_count, props.data())); 51015db71995Sopenharmony_ci 51025db71995Sopenharmony_ci std::vector<VkDisplayPlaneProperties2KHR> props2{}; 51035db71995Sopenharmony_ci uint32_t prop_count2 = 0; 51045db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlaneProperties2KHR(physical_device, &prop_count2, nullptr)); 51055db71995Sopenharmony_ci ASSERT_EQ(prop_count, prop_count2); 51065db71995Sopenharmony_ci props2.resize(prop_count2, {VK_STRUCTURE_TYPE_DISPLAY_PLANE_PROPERTIES_2_KHR}); 51075db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlaneProperties2KHR(physical_device, &prop_count2, props2.data())); 51085db71995Sopenharmony_ci 51095db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPlanePropData(props, props2)); 51105db71995Sopenharmony_ci} 51115db71995Sopenharmony_ci 51125db71995Sopenharmony_ci// Test vkGetPhysicalDeviceDisplayPlaneProperties2KHR where instance supports it with some ICDs that both support 51135db71995Sopenharmony_ci// and don't support it: 51145db71995Sopenharmony_ci// ICD 0 supports 51155db71995Sopenharmony_ci// Physical device 0 does not 51165db71995Sopenharmony_ci// Physical device 1 does 51175db71995Sopenharmony_ci// Physical device 2 does not 51185db71995Sopenharmony_ci// ICD 1 doesn't support 51195db71995Sopenharmony_ci// Physical device 3 does not 51205db71995Sopenharmony_ci// ICD 2 supports 51215db71995Sopenharmony_ci// Physical device 4 does not 51225db71995Sopenharmony_ci// Physical device 5 does not 51235db71995Sopenharmony_ci// ICD 3 supports 51245db71995Sopenharmony_ci// Physical device 6 does 51255db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, PhysDevDispPlaneProps2KHRMixed) { 51265db71995Sopenharmony_ci FrameworkEnvironment env{}; 51275db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 51285db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 51295db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 51305db71995Sopenharmony_ci 51315db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 51325db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 51335db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 51345db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 51355db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 51365db71995Sopenharmony_ci 51375db71995Sopenharmony_ci // ICD 1 should not have 1.1 51385db71995Sopenharmony_ci if (icd != 1) { 51395db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 51405db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 51415db71995Sopenharmony_ci } 51425db71995Sopenharmony_ci 51435db71995Sopenharmony_ci uint32_t rand_vendor_id; 51445db71995Sopenharmony_ci uint32_t rand_driver_vers; 51455db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 51465db71995Sopenharmony_ci 51475db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 51485db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 51495db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 51505db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 51515db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 51525db71995Sopenharmony_ci 51535db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 51545db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 51555db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME, 0}); 51565db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 51575db71995Sopenharmony_ci } 51585db71995Sopenharmony_ci 51595db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 51605db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 51615db71995Sopenharmony_ci FillInRandomDisplayPlanePropData(cur_dev.display_plane_properties); 51625db71995Sopenharmony_ci } 51635db71995Sopenharmony_ci } 51645db71995Sopenharmony_ci 51655db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 51665db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 51675db71995Sopenharmony_ci instance.CheckCreate(); 51685db71995Sopenharmony_ci 51695db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR GetPhysicalDeviceDisplayPlanePropertiesKHR = 51705db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); 51715db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPlanePropertiesKHR, nullptr); 51725db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR GetPhysicalDeviceDisplayPlaneProperties2KHR = 51735db71995Sopenharmony_ci instance.load("vkGetPhysicalDeviceDisplayPlaneProperties2KHR"); 51745db71995Sopenharmony_ci ASSERT_NE(GetPhysicalDeviceDisplayPlaneProperties2KHR, nullptr); 51755db71995Sopenharmony_ci 51765db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 51775db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 51785db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 51795db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 51805db71995Sopenharmony_ci 51815db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 51825db71995Sopenharmony_ci std::vector<VkDisplayPlanePropertiesKHR> props{}; 51835db71995Sopenharmony_ci uint32_t prop_count = 0; 51845db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_devices[dev], &prop_count, nullptr)); 51855db71995Sopenharmony_ci ASSERT_NE(0U, prop_count); 51865db71995Sopenharmony_ci props.resize(prop_count); 51875db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlanePropertiesKHR(physical_devices[dev], &prop_count, props.data())); 51885db71995Sopenharmony_ci 51895db71995Sopenharmony_ci std::vector<VkDisplayPlaneProperties2KHR> props2{}; 51905db71995Sopenharmony_ci uint32_t prop_count2 = 0; 51915db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlaneProperties2KHR(physical_devices[dev], &prop_count2, nullptr)); 51925db71995Sopenharmony_ci ASSERT_EQ(prop_count, prop_count2); 51935db71995Sopenharmony_ci props2.resize(prop_count2, {VK_STRUCTURE_TYPE_DISPLAY_PLANE_PROPERTIES_2_KHR}); 51945db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceDisplayPlaneProperties2KHR(physical_devices[dev], &prop_count2, props2.data())); 51955db71995Sopenharmony_ci 51965db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPlanePropData(props, props2)); 51975db71995Sopenharmony_ci } 51985db71995Sopenharmony_ci} 51995db71995Sopenharmony_ci 52005db71995Sopenharmony_ci// Test vkGetDisplayModeProperties2KHR where nothing supports it. 52015db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModeProps2KHRNoSupport) { 52025db71995Sopenharmony_ci FrameworkEnvironment env{}; 52035db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 52045db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 52055db71995Sopenharmony_ci 52065db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 52075db71995Sopenharmony_ci instance.CheckCreate(); 52085db71995Sopenharmony_ci 52095db71995Sopenharmony_ci PFN_vkGetDisplayModeProperties2KHR GetDisplayModeProperties2KHR = instance.load("vkGetDisplayModeProperties2KHR"); 52105db71995Sopenharmony_ci ASSERT_EQ(GetDisplayModeProperties2KHR, nullptr); 52115db71995Sopenharmony_ci} 52125db71995Sopenharmony_ci 52135db71995Sopenharmony_ci// Test vkGetDisplayModeProperties2KHR where instance supports it, but nothing else. 52145db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModeProps2KHRNoICDSupport) { 52155db71995Sopenharmony_ci FrameworkEnvironment env{}; 52165db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 52175db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 52185db71995Sopenharmony_ci 52195db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 52205db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME); 52215db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 52225db71995Sopenharmony_ci 52235db71995Sopenharmony_ci PFN_vkGetDisplayModeProperties2KHR GetDisplayModeProperties2KHR = instance.load("vkGetDisplayModeProperties2KHR"); 52245db71995Sopenharmony_ci ASSERT_EQ(GetDisplayModeProperties2KHR, nullptr); 52255db71995Sopenharmony_ci} 52265db71995Sopenharmony_ci 52275db71995Sopenharmony_ci// Compare the display mode properties data structs 52285db71995Sopenharmony_cibool CompareDisplayModeProps(const std::vector<VkDisplayModePropertiesKHR>& disps1, 52295db71995Sopenharmony_ci const std::vector<VkDisplayModeProperties2KHR>& disps2) { 52305db71995Sopenharmony_ci if (disps1.size() != disps2.size()) return false; 52315db71995Sopenharmony_ci 52325db71995Sopenharmony_ci bool equal = true; 52335db71995Sopenharmony_ci for (uint32_t i = 0; i < disps1.size(); ++i) { 52345db71995Sopenharmony_ci equal = equal && disps1[i].displayMode == disps2[i].displayModeProperties.displayMode; 52355db71995Sopenharmony_ci equal = equal && disps1[i].parameters.visibleRegion.width == disps2[i].displayModeProperties.parameters.visibleRegion.width; 52365db71995Sopenharmony_ci equal = 52375db71995Sopenharmony_ci equal && disps1[i].parameters.visibleRegion.height == disps2[i].displayModeProperties.parameters.visibleRegion.height; 52385db71995Sopenharmony_ci equal = equal && disps1[i].parameters.refreshRate == disps2[i].displayModeProperties.parameters.refreshRate; 52395db71995Sopenharmony_ci } 52405db71995Sopenharmony_ci return equal; 52415db71995Sopenharmony_ci} 52425db71995Sopenharmony_ci 52435db71995Sopenharmony_ci// Test vGetDisplayModeProperties2KHR where instance and ICD supports it, but device does not support it. 52445db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModeProps2KHRInstanceAndICDSupport) { 52455db71995Sopenharmony_ci FrameworkEnvironment env{}; 52465db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 52475db71995Sopenharmony_ci Extension first_ext{VK_KHR_DISPLAY_EXTENSION_NAME}; 52485db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}; 52495db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extensions({first_ext, second_ext}); 52505db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 52515db71995Sopenharmony_ci GenerateRandomDisplayModeProps(env.get_test_icd(0).physical_devices.back().display_mode_properties); 52525db71995Sopenharmony_ci 52535db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 52545db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 52555db71995Sopenharmony_ci instance.CheckCreate(); 52565db71995Sopenharmony_ci 52575db71995Sopenharmony_ci PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR = instance.load("vkGetDisplayModePropertiesKHR"); 52585db71995Sopenharmony_ci ASSERT_NE(GetDisplayModePropertiesKHR, nullptr); 52595db71995Sopenharmony_ci PFN_vkGetDisplayModeProperties2KHR GetDisplayModeProperties2KHR = instance.load("vkGetDisplayModeProperties2KHR"); 52605db71995Sopenharmony_ci ASSERT_NE(GetDisplayModeProperties2KHR, nullptr); 52615db71995Sopenharmony_ci 52625db71995Sopenharmony_ci uint32_t driver_count = 1; 52635db71995Sopenharmony_ci VkPhysicalDevice physical_device; 52645db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 52655db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 52665db71995Sopenharmony_ci 52675db71995Sopenharmony_ci std::vector<VkDisplayModePropertiesKHR> props{}; 52685db71995Sopenharmony_ci uint32_t props_count1 = 0; 52695db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModePropertiesKHR(physical_device, VK_NULL_HANDLE, &props_count1, nullptr)); 52705db71995Sopenharmony_ci ASSERT_NE(0U, props_count1); 52715db71995Sopenharmony_ci props.resize(props_count1); 52725db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModePropertiesKHR(physical_device, VK_NULL_HANDLE, &props_count1, props.data())); 52735db71995Sopenharmony_ci 52745db71995Sopenharmony_ci std::vector<VkDisplayModeProperties2KHR> props2{}; 52755db71995Sopenharmony_ci uint32_t props_count2 = 0; 52765db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModeProperties2KHR(physical_device, VK_NULL_HANDLE, &props_count2, nullptr)); 52775db71995Sopenharmony_ci ASSERT_EQ(props_count1, props_count2); 52785db71995Sopenharmony_ci props2.resize(props_count2, {VK_STRUCTURE_TYPE_DISPLAY_MODE_PROPERTIES_2_KHR}); 52795db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModeProperties2KHR(physical_device, VK_NULL_HANDLE, &props_count2, props2.data())); 52805db71995Sopenharmony_ci 52815db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayModeProps(props, props2)); 52825db71995Sopenharmony_ci} 52835db71995Sopenharmony_ci 52845db71995Sopenharmony_ci// Test vkGetDisplayModeProperties2KHR where instance supports it with some ICDs that both support 52855db71995Sopenharmony_ci// and don't support it: 52865db71995Sopenharmony_ci// ICD 0 supports 52875db71995Sopenharmony_ci// Physical device 0 does not 52885db71995Sopenharmony_ci// Physical device 1 does 52895db71995Sopenharmony_ci// Physical device 2 does not 52905db71995Sopenharmony_ci// ICD 1 doesn't support 52915db71995Sopenharmony_ci// Physical device 3 does not 52925db71995Sopenharmony_ci// ICD 2 supports 52935db71995Sopenharmony_ci// Physical device 4 does not 52945db71995Sopenharmony_ci// Physical device 5 does not 52955db71995Sopenharmony_ci// ICD 3 supports 52965db71995Sopenharmony_ci// Physical device 6 does 52975db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispModeProps2KHRMixed) { 52985db71995Sopenharmony_ci FrameworkEnvironment env{}; 52995db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 53005db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 53015db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 53025db71995Sopenharmony_ci 53035db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 53045db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 53055db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 53065db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 53075db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 53085db71995Sopenharmony_ci 53095db71995Sopenharmony_ci // ICD 1 should not have 1.1 53105db71995Sopenharmony_ci if (icd != 1) { 53115db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 53125db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 53135db71995Sopenharmony_ci } 53145db71995Sopenharmony_ci 53155db71995Sopenharmony_ci uint32_t rand_vendor_id; 53165db71995Sopenharmony_ci uint32_t rand_driver_vers; 53175db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 53185db71995Sopenharmony_ci 53195db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 53205db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 53215db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 53225db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 53235db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 53245db71995Sopenharmony_ci 53255db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 53265db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 53275db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME, 0}); 53285db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 53295db71995Sopenharmony_ci } 53305db71995Sopenharmony_ci 53315db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 53325db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 53335db71995Sopenharmony_ci GenerateRandomDisplayModeProps(cur_dev.display_mode_properties); 53345db71995Sopenharmony_ci } 53355db71995Sopenharmony_ci } 53365db71995Sopenharmony_ci 53375db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 53385db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 53395db71995Sopenharmony_ci instance.CheckCreate(); 53405db71995Sopenharmony_ci 53415db71995Sopenharmony_ci PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR = instance.load("vkGetDisplayModePropertiesKHR"); 53425db71995Sopenharmony_ci ASSERT_NE(GetDisplayModePropertiesKHR, nullptr); 53435db71995Sopenharmony_ci PFN_vkGetDisplayModeProperties2KHR GetDisplayModeProperties2KHR = instance.load("vkGetDisplayModeProperties2KHR"); 53445db71995Sopenharmony_ci ASSERT_NE(GetDisplayModeProperties2KHR, nullptr); 53455db71995Sopenharmony_ci 53465db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 53475db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 53485db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 53495db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 53505db71995Sopenharmony_ci 53515db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 53525db71995Sopenharmony_ci std::vector<VkDisplayModePropertiesKHR> props{}; 53535db71995Sopenharmony_ci uint32_t props_count1 = 0; 53545db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModePropertiesKHR(physical_devices[dev], VK_NULL_HANDLE, &props_count1, nullptr)); 53555db71995Sopenharmony_ci ASSERT_NE(0U, props_count1); 53565db71995Sopenharmony_ci props.resize(props_count1); 53575db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModePropertiesKHR(physical_devices[dev], VK_NULL_HANDLE, &props_count1, props.data())); 53585db71995Sopenharmony_ci 53595db71995Sopenharmony_ci std::vector<VkDisplayModeProperties2KHR> props2{}; 53605db71995Sopenharmony_ci uint32_t props_count2 = 0; 53615db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModeProperties2KHR(physical_devices[dev], VK_NULL_HANDLE, &props_count2, nullptr)); 53625db71995Sopenharmony_ci ASSERT_EQ(props_count1, props_count2); 53635db71995Sopenharmony_ci props2.resize(props_count2, {VK_STRUCTURE_TYPE_DISPLAY_MODE_PROPERTIES_2_KHR}); 53645db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayModeProperties2KHR(physical_devices[dev], VK_NULL_HANDLE, &props_count2, props2.data())); 53655db71995Sopenharmony_ci 53665db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayModeProps(props, props2)); 53675db71995Sopenharmony_ci } 53685db71995Sopenharmony_ci} 53695db71995Sopenharmony_ci 53705db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilities2KHR where nothing supports it. 53715db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCaps2KHRNoSupport) { 53725db71995Sopenharmony_ci FrameworkEnvironment env{}; 53735db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 53745db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 53755db71995Sopenharmony_ci 53765db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 53775db71995Sopenharmony_ci instance.CheckCreate(); 53785db71995Sopenharmony_ci 53795db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 53805db71995Sopenharmony_ci ASSERT_EQ(GetDisplayPlaneCapabilitiesKHR, nullptr); 53815db71995Sopenharmony_ci} 53825db71995Sopenharmony_ci 53835db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilities2KHR where instance supports it, but nothing else. 53845db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCaps2KHRNoICDSupport) { 53855db71995Sopenharmony_ci FrameworkEnvironment env{}; 53865db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 53875db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 53885db71995Sopenharmony_ci 53895db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 53905db71995Sopenharmony_ci instance.create_info.add_extension(VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME); 53915db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 53925db71995Sopenharmony_ci 53935db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 53945db71995Sopenharmony_ci ASSERT_EQ(GetDisplayPlaneCapabilitiesKHR, nullptr); 53955db71995Sopenharmony_ci} 53965db71995Sopenharmony_ci 53975db71995Sopenharmony_ci// Compare the display plane caps 53985db71995Sopenharmony_cibool CompareDisplayPlaneCaps(const VkDisplayPlaneCapabilitiesKHR& caps1, VkDisplayPlaneCapabilities2KHR& caps2) { 53995db71995Sopenharmony_ci bool equal = true; 54005db71995Sopenharmony_ci equal = equal && caps1.supportedAlpha == caps2.capabilities.supportedAlpha; 54015db71995Sopenharmony_ci equal = equal && caps1.minSrcPosition.x == caps2.capabilities.minSrcPosition.x; 54025db71995Sopenharmony_ci equal = equal && caps1.minSrcPosition.y == caps2.capabilities.minSrcPosition.y; 54035db71995Sopenharmony_ci equal = equal && caps1.maxSrcPosition.x == caps2.capabilities.maxSrcPosition.x; 54045db71995Sopenharmony_ci equal = equal && caps1.maxSrcPosition.y == caps2.capabilities.maxSrcPosition.y; 54055db71995Sopenharmony_ci equal = equal && caps1.minSrcExtent.width == caps2.capabilities.minSrcExtent.width; 54065db71995Sopenharmony_ci equal = equal && caps1.minSrcExtent.height == caps2.capabilities.minSrcExtent.height; 54075db71995Sopenharmony_ci equal = equal && caps1.maxSrcExtent.width == caps2.capabilities.maxSrcExtent.width; 54085db71995Sopenharmony_ci equal = equal && caps1.maxSrcExtent.height == caps2.capabilities.maxSrcExtent.height; 54095db71995Sopenharmony_ci equal = equal && caps1.minDstPosition.x == caps2.capabilities.minDstPosition.x; 54105db71995Sopenharmony_ci equal = equal && caps1.minDstPosition.y == caps2.capabilities.minDstPosition.y; 54115db71995Sopenharmony_ci equal = equal && caps1.maxDstPosition.x == caps2.capabilities.maxDstPosition.x; 54125db71995Sopenharmony_ci equal = equal && caps1.maxDstPosition.y == caps2.capabilities.maxDstPosition.y; 54135db71995Sopenharmony_ci equal = equal && caps1.minDstExtent.width == caps2.capabilities.minDstExtent.width; 54145db71995Sopenharmony_ci equal = equal && caps1.minDstExtent.height == caps2.capabilities.minDstExtent.height; 54155db71995Sopenharmony_ci equal = equal && caps1.maxDstExtent.width == caps2.capabilities.maxDstExtent.width; 54165db71995Sopenharmony_ci equal = equal && caps1.maxDstExtent.height == caps2.capabilities.maxDstExtent.height; 54175db71995Sopenharmony_ci return equal; 54185db71995Sopenharmony_ci} 54195db71995Sopenharmony_ci 54205db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilities2KHR where instance and ICD supports it, but device does not support it. 54215db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCaps2KHRInstanceAndICDSupport) { 54225db71995Sopenharmony_ci FrameworkEnvironment env{}; 54235db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 54245db71995Sopenharmony_ci Extension first_ext{VK_KHR_DISPLAY_EXTENSION_NAME}; 54255db71995Sopenharmony_ci Extension second_ext{VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}; 54265db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extensions({first_ext, second_ext}); 54275db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 54285db71995Sopenharmony_ci FillInRandomDisplayPropData(env.get_test_icd(0).physical_devices.back().display_properties); 54295db71995Sopenharmony_ci 54305db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 54315db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 54325db71995Sopenharmony_ci instance.CheckCreate(); 54335db71995Sopenharmony_ci 54345db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 54355db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneCapabilitiesKHR, nullptr); 54365db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilities2KHR GetDisplayPlaneCapabilities2KHR = instance.load("vkGetDisplayPlaneCapabilities2KHR"); 54375db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneCapabilities2KHR, nullptr); 54385db71995Sopenharmony_ci 54395db71995Sopenharmony_ci uint32_t driver_count = 1; 54405db71995Sopenharmony_ci VkPhysicalDevice physical_device; 54415db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 54425db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 54435db71995Sopenharmony_ci 54445db71995Sopenharmony_ci VkDisplayPlaneCapabilitiesKHR caps{}; 54455db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneCapabilitiesKHR(physical_device, 0, 0, &caps)); 54465db71995Sopenharmony_ci VkDisplayPlaneCapabilities2KHR caps2{}; 54475db71995Sopenharmony_ci VkDisplayPlaneInfo2KHR info{VK_STRUCTURE_TYPE_DISPLAY_PLANE_INFO_2_KHR}; 54485db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneCapabilities2KHR(physical_device, &info, &caps2)); 54495db71995Sopenharmony_ci ASSERT_TRUE(CompareDisplayPlaneCaps(caps, caps2)); 54505db71995Sopenharmony_ci} 54515db71995Sopenharmony_ci 54525db71995Sopenharmony_ci// Test vkGetDisplayPlaneCapabilities2KHR where instance supports it with some ICDs that both support 54535db71995Sopenharmony_ci// and don't support it: 54545db71995Sopenharmony_ci// ICD 0 supports 54555db71995Sopenharmony_ci// Physical device 0 does not 54565db71995Sopenharmony_ci// Physical device 1 does 54575db71995Sopenharmony_ci// Physical device 2 does not 54585db71995Sopenharmony_ci// ICD 1 doesn't support 54595db71995Sopenharmony_ci// Physical device 3 does not 54605db71995Sopenharmony_ci// ICD 2 supports 54615db71995Sopenharmony_ci// Physical device 4 does not 54625db71995Sopenharmony_ci// Physical device 5 does not 54635db71995Sopenharmony_ci// ICD 3 supports 54645db71995Sopenharmony_ci// Physical device 6 does 54655db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDispPlaneCaps2KHRMixed) { 54665db71995Sopenharmony_ci FrameworkEnvironment env{}; 54675db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 54685db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 54695db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 54705db71995Sopenharmony_ci 54715db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 54725db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 54735db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 54745db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 54755db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 54765db71995Sopenharmony_ci 54775db71995Sopenharmony_ci // ICD 1 should not have 1.1 54785db71995Sopenharmony_ci if (icd != 1) { 54795db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 54805db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 54815db71995Sopenharmony_ci } 54825db71995Sopenharmony_ci 54835db71995Sopenharmony_ci uint32_t rand_vendor_id; 54845db71995Sopenharmony_ci uint32_t rand_driver_vers; 54855db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 54865db71995Sopenharmony_ci 54875db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 54885db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 54895db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 54905db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 54915db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 54925db71995Sopenharmony_ci 54935db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 54945db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 54955db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME, 0}); 54965db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 54975db71995Sopenharmony_ci } 54985db71995Sopenharmony_ci 54995db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 55005db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 55015db71995Sopenharmony_ci GenerateRandomDisplayPlaneCaps(cur_dev.display_plane_capabilities); 55025db71995Sopenharmony_ci } 55035db71995Sopenharmony_ci } 55045db71995Sopenharmony_ci 55055db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 55065db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME}); 55075db71995Sopenharmony_ci instance.CheckCreate(); 55085db71995Sopenharmony_ci 55095db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR = instance.load("vkGetDisplayPlaneCapabilitiesKHR"); 55105db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneCapabilitiesKHR, nullptr); 55115db71995Sopenharmony_ci PFN_vkGetDisplayPlaneCapabilities2KHR GetDisplayPlaneCapabilities2KHR = instance.load("vkGetDisplayPlaneCapabilities2KHR"); 55125db71995Sopenharmony_ci ASSERT_NE(GetDisplayPlaneCapabilities2KHR, nullptr); 55135db71995Sopenharmony_ci 55145db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 55155db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 55165db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 55175db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 55185db71995Sopenharmony_ci 55195db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 55205db71995Sopenharmony_ci VkDisplayPlaneCapabilitiesKHR caps{}; 55215db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneCapabilitiesKHR(physical_devices[dev], 0, 0, &caps)); 55225db71995Sopenharmony_ci VkDisplayPlaneCapabilities2KHR caps2{}; 55235db71995Sopenharmony_ci VkDisplayPlaneInfo2KHR info{VK_STRUCTURE_TYPE_DISPLAY_PLANE_INFO_2_KHR}; 55245db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDisplayPlaneCapabilities2KHR(physical_devices[dev], &info, &caps2)); 55255db71995Sopenharmony_ci CompareDisplayPlaneCaps(caps, caps2); 55265db71995Sopenharmony_ci } 55275db71995Sopenharmony_ci} 55285db71995Sopenharmony_ci 55295db71995Sopenharmony_ci// 55305db71995Sopenharmony_ci// VK_EXT_acquire_drm_display 55315db71995Sopenharmony_ci// 55325db71995Sopenharmony_ci 55335db71995Sopenharmony_ci// Test vkAcquireDrmDisplayEXT where nothing supports it. 55345db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, AcquireDrmDisplayEXTNoSupport) { 55355db71995Sopenharmony_ci FrameworkEnvironment env{}; 55365db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 55375db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 55385db71995Sopenharmony_ci 55395db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 55405db71995Sopenharmony_ci instance.CheckCreate(); 55415db71995Sopenharmony_ci 55425db71995Sopenharmony_ci PFN_vkAcquireDrmDisplayEXT AcquireDrmDisplayEXT = instance.load("vkAcquireDrmDisplayEXT"); 55435db71995Sopenharmony_ci ASSERT_EQ(AcquireDrmDisplayEXT, nullptr); 55445db71995Sopenharmony_ci} 55455db71995Sopenharmony_ci 55465db71995Sopenharmony_ci// Test vkAcquireDrmDisplayEXT where instance supports it, but nothing else. 55475db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, AcquireDrmDisplayEXTNoICDSupport) { 55485db71995Sopenharmony_ci FrameworkEnvironment env{}; 55495db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 55505db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 55515db71995Sopenharmony_ci 55525db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 55535db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME); 55545db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 55555db71995Sopenharmony_ci 55565db71995Sopenharmony_ci PFN_vkAcquireDrmDisplayEXT AcquireDrmDisplayEXT = instance.load("vkAcquireDrmDisplayEXT"); 55575db71995Sopenharmony_ci ASSERT_EQ(AcquireDrmDisplayEXT, nullptr); 55585db71995Sopenharmony_ci} 55595db71995Sopenharmony_ci 55605db71995Sopenharmony_ci// Test vkAcquireDrmDisplayEXT where instance and ICD supports it, but device does not support it. 55615db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, AcquireDrmDisplayEXTInstanceAndICDSupport) { 55625db71995Sopenharmony_ci FrameworkEnvironment env{}; 55635db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 55645db71995Sopenharmony_ci Extension first_ext{VK_KHR_DISPLAY_EXTENSION_NAME}; 55655db71995Sopenharmony_ci Extension second_ext{VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}; 55665db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extensions({first_ext, second_ext}); 55675db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 55685db71995Sopenharmony_ci GenerateRandomDisplays(env.get_test_icd(0).physical_devices.back().displays); 55695db71995Sopenharmony_ci 55705db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 55715db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}); 55725db71995Sopenharmony_ci instance.CheckCreate(); 55735db71995Sopenharmony_ci 55745db71995Sopenharmony_ci PFN_vkAcquireDrmDisplayEXT AcquireDrmDisplayEXT = instance.load("vkAcquireDrmDisplayEXT"); 55755db71995Sopenharmony_ci ASSERT_NE(AcquireDrmDisplayEXT, nullptr); 55765db71995Sopenharmony_ci 55775db71995Sopenharmony_ci uint32_t driver_count = 1; 55785db71995Sopenharmony_ci VkPhysicalDevice physical_device; 55795db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 55805db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 55815db71995Sopenharmony_ci 55825db71995Sopenharmony_ci VkDisplayKHR display = VK_NULL_HANDLE; 55835db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, AcquireDrmDisplayEXT(physical_device, 0, display)); 55845db71995Sopenharmony_ci} 55855db71995Sopenharmony_ci 55865db71995Sopenharmony_ci// Test vkAcquireDrmDisplayEXT where instance supports it with some ICDs that both support 55875db71995Sopenharmony_ci// and don't support it: 55885db71995Sopenharmony_ci// ICD 0 supports 55895db71995Sopenharmony_ci// Physical device 0 does not 55905db71995Sopenharmony_ci// Physical device 1 does 55915db71995Sopenharmony_ci// Physical device 2 does not 55925db71995Sopenharmony_ci// ICD 1 doesn't support 55935db71995Sopenharmony_ci// Physical device 3 does not 55945db71995Sopenharmony_ci// ICD 2 supports 55955db71995Sopenharmony_ci// Physical device 4 does not 55965db71995Sopenharmony_ci// Physical device 5 does not 55975db71995Sopenharmony_ci// ICD 3 supports 55985db71995Sopenharmony_ci// Physical device 6 does 55995db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, AcquireDrmDisplayEXTMixed) { 56005db71995Sopenharmony_ci FrameworkEnvironment env{}; 56015db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 56025db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 56035db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 56045db71995Sopenharmony_ci 56055db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 56065db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 56075db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 56085db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 56095db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 56105db71995Sopenharmony_ci 56115db71995Sopenharmony_ci // ICD 1 should not have 1.1 56125db71995Sopenharmony_ci if (icd != 1) { 56135db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 56145db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}); 56155db71995Sopenharmony_ci } 56165db71995Sopenharmony_ci 56175db71995Sopenharmony_ci uint32_t rand_vendor_id; 56185db71995Sopenharmony_ci uint32_t rand_driver_vers; 56195db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 56205db71995Sopenharmony_ci 56215db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 56225db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 56235db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 56245db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 56255db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 56265db71995Sopenharmony_ci 56275db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 56285db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 56295db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME, 0}); 56305db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 56315db71995Sopenharmony_ci } 56325db71995Sopenharmony_ci 56335db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 56345db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 56355db71995Sopenharmony_ci GenerateRandomDisplays(cur_dev.displays); 56365db71995Sopenharmony_ci } 56375db71995Sopenharmony_ci } 56385db71995Sopenharmony_ci 56395db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 56405db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}); 56415db71995Sopenharmony_ci instance.CheckCreate(); 56425db71995Sopenharmony_ci 56435db71995Sopenharmony_ci PFN_vkAcquireDrmDisplayEXT AcquireDrmDisplayEXT = instance.load("vkAcquireDrmDisplayEXT"); 56445db71995Sopenharmony_ci ASSERT_NE(AcquireDrmDisplayEXT, nullptr); 56455db71995Sopenharmony_ci 56465db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 56475db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 56485db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 56495db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 56505db71995Sopenharmony_ci 56515db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 56525db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 56535db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 56545db71995Sopenharmony_ci 56555db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 56565db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 56575db71995Sopenharmony_ci bool found = false; 56585db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 56595db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 56605db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 56615db71995Sopenharmony_ci // physical devices info with the returned info. 56625db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 56635db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 56645db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 56655db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 56665db71995Sopenharmony_ci VkDisplayKHR display = VK_NULL_HANDLE; 56675db71995Sopenharmony_ci if (icd == 1) { 56685db71995Sopenharmony_ci // For this extension, if no support exists (like for ICD 1), the value of 0 should be returned by the 56695db71995Sopenharmony_ci // loader. 56705db71995Sopenharmony_ci ASSERT_EQ(VK_ERROR_EXTENSION_NOT_PRESENT, AcquireDrmDisplayEXT(physical_devices[dev], 0, display)); 56715db71995Sopenharmony_ci } else { 56725db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, AcquireDrmDisplayEXT(physical_devices[dev], 0, display)); 56735db71995Sopenharmony_ci } 56745db71995Sopenharmony_ci found = true; 56755db71995Sopenharmony_ci break; 56765db71995Sopenharmony_ci } 56775db71995Sopenharmony_ci } 56785db71995Sopenharmony_ci if (found) { 56795db71995Sopenharmony_ci break; 56805db71995Sopenharmony_ci } 56815db71995Sopenharmony_ci } 56825db71995Sopenharmony_ci } 56835db71995Sopenharmony_ci} 56845db71995Sopenharmony_ci 56855db71995Sopenharmony_ci// Test vkGetDrmDisplayEXT where nothing supports it. 56865db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDrmDisplayEXTNoSupport) { 56875db71995Sopenharmony_ci FrameworkEnvironment env{}; 56885db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 56895db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 56905db71995Sopenharmony_ci 56915db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 56925db71995Sopenharmony_ci instance.CheckCreate(); 56935db71995Sopenharmony_ci 56945db71995Sopenharmony_ci PFN_vkGetDrmDisplayEXT GetDrmDisplayEXT = instance.load("vkGetDrmDisplayEXT"); 56955db71995Sopenharmony_ci ASSERT_EQ(GetDrmDisplayEXT, nullptr); 56965db71995Sopenharmony_ci} 56975db71995Sopenharmony_ci 56985db71995Sopenharmony_ci// Test vkGetDrmDisplayEXT where instance supports it, but nothing else. 56995db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDrmDisplayEXTNoICDSupport) { 57005db71995Sopenharmony_ci FrameworkEnvironment env{}; 57015db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 57025db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 57035db71995Sopenharmony_ci 57045db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 57055db71995Sopenharmony_ci instance.create_info.add_extension(VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME); 57065db71995Sopenharmony_ci instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 57075db71995Sopenharmony_ci 57085db71995Sopenharmony_ci PFN_vkGetDrmDisplayEXT GetDrmDisplayEXT = instance.load("vkGetDrmDisplayEXT"); 57095db71995Sopenharmony_ci ASSERT_EQ(GetDrmDisplayEXT, nullptr); 57105db71995Sopenharmony_ci} 57115db71995Sopenharmony_ci 57125db71995Sopenharmony_ci// Test vkGetDrmDisplayEXT where instance and ICD supports it, but device does not support it. 57135db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDrmDisplayEXTInstanceAndICDSupport) { 57145db71995Sopenharmony_ci FrameworkEnvironment env{}; 57155db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)); 57165db71995Sopenharmony_ci Extension first_ext{VK_KHR_DISPLAY_EXTENSION_NAME}; 57175db71995Sopenharmony_ci Extension second_ext{VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}; 57185db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extensions({first_ext, second_ext}); 57195db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({}); 57205db71995Sopenharmony_ci GenerateRandomDisplays(env.get_test_icd(0).physical_devices.back().displays); 57215db71995Sopenharmony_ci 57225db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 57235db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}); 57245db71995Sopenharmony_ci instance.CheckCreate(); 57255db71995Sopenharmony_ci 57265db71995Sopenharmony_ci PFN_vkGetDrmDisplayEXT GetDrmDisplayEXT = instance.load("vkGetDrmDisplayEXT"); 57275db71995Sopenharmony_ci ASSERT_NE(GetDrmDisplayEXT, nullptr); 57285db71995Sopenharmony_ci 57295db71995Sopenharmony_ci uint32_t driver_count = 1; 57305db71995Sopenharmony_ci VkPhysicalDevice physical_device; 57315db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device)); 57325db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 57335db71995Sopenharmony_ci 57345db71995Sopenharmony_ci VkDisplayKHR display = VK_NULL_HANDLE; 57355db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDrmDisplayEXT(physical_device, 0, 0, &display)); 57365db71995Sopenharmony_ci ASSERT_EQ(display, env.get_test_icd(0).physical_devices.back().displays[0]); 57375db71995Sopenharmony_ci} 57385db71995Sopenharmony_ci 57395db71995Sopenharmony_ci// Test vkGetDrmDisplayEXT where instance supports it with some ICDs that both support 57405db71995Sopenharmony_ci// and don't support it: 57415db71995Sopenharmony_ci// ICD 0 supports 57425db71995Sopenharmony_ci// Physical device 0 does not 57435db71995Sopenharmony_ci// Physical device 1 does 57445db71995Sopenharmony_ci// Physical device 2 does not 57455db71995Sopenharmony_ci// ICD 1 doesn't support 57465db71995Sopenharmony_ci// Physical device 3 does not 57475db71995Sopenharmony_ci// ICD 2 supports 57485db71995Sopenharmony_ci// Physical device 4 does not 57495db71995Sopenharmony_ci// Physical device 5 does not 57505db71995Sopenharmony_ci// ICD 3 supports 57515db71995Sopenharmony_ci// Physical device 6 does 57525db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, GetDrmDisplayEXTMixed) { 57535db71995Sopenharmony_ci FrameworkEnvironment env{}; 57545db71995Sopenharmony_ci const uint32_t max_icd_count = 4; 57555db71995Sopenharmony_ci const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1}; 57565db71995Sopenharmony_ci const uint32_t max_phys_devs = 7; 57575db71995Sopenharmony_ci 57585db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 57595db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0)); 57605db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 57615db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 57625db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_DISPLAY_EXTENSION_NAME}); 57635db71995Sopenharmony_ci 57645db71995Sopenharmony_ci // ICD 1 should not have 1.1 57655db71995Sopenharmony_ci if (icd != 1) { 57665db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_1; 57675db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}); 57685db71995Sopenharmony_ci } 57695db71995Sopenharmony_ci 57705db71995Sopenharmony_ci uint32_t rand_vendor_id; 57715db71995Sopenharmony_ci uint32_t rand_driver_vers; 57725db71995Sopenharmony_ci FillInRandomICDInfo(rand_vendor_id, rand_driver_vers); 57735db71995Sopenharmony_ci 57745db71995Sopenharmony_ci for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) { 57755db71995Sopenharmony_ci uint32_t device_version = VK_API_VERSION_1_0; 57765db71995Sopenharmony_ci cur_icd.physical_devices.push_back({}); 57775db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices.back(); 57785db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_KHR_DISPLAY_EXTENSION_NAME, 0}); 57795db71995Sopenharmony_ci 57805db71995Sopenharmony_ci // 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1 57815db71995Sopenharmony_ci if ((icd == 0 && dev == 1) || icd == 3) { 57825db71995Sopenharmony_ci cur_dev.extensions.push_back({VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME, 0}); 57835db71995Sopenharmony_ci device_version = VK_API_VERSION_1_1; 57845db71995Sopenharmony_ci } 57855db71995Sopenharmony_ci 57865db71995Sopenharmony_ci // Still set physical device properties (so we can determine if device is correct API version) 57875db71995Sopenharmony_ci FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers); 57885db71995Sopenharmony_ci GenerateRandomDisplays(cur_dev.displays); 57895db71995Sopenharmony_ci } 57905db71995Sopenharmony_ci } 57915db71995Sopenharmony_ci 57925db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 57935db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_DISPLAY_EXTENSION_NAME, VK_EXT_ACQUIRE_DRM_DISPLAY_EXTENSION_NAME}); 57945db71995Sopenharmony_ci instance.CheckCreate(); 57955db71995Sopenharmony_ci 57965db71995Sopenharmony_ci PFN_vkGetDrmDisplayEXT GetDrmDisplayEXT = instance.load("vkGetDrmDisplayEXT"); 57975db71995Sopenharmony_ci ASSERT_NE(GetDrmDisplayEXT, nullptr); 57985db71995Sopenharmony_ci 57995db71995Sopenharmony_ci uint32_t device_count = max_phys_devs; 58005db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_phys_devs> physical_devices; 58015db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data())); 58025db71995Sopenharmony_ci ASSERT_EQ(device_count, max_phys_devs); 58035db71995Sopenharmony_ci 58045db71995Sopenharmony_ci for (uint32_t dev = 0; dev < device_count; ++dev) { 58055db71995Sopenharmony_ci VkPhysicalDeviceProperties pd_props{}; 58065db71995Sopenharmony_ci instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &pd_props); 58075db71995Sopenharmony_ci 58085db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_icd_count; ++icd) { 58095db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 58105db71995Sopenharmony_ci bool found = false; 58115db71995Sopenharmony_ci for (uint32_t pd = 0; pd < dev_counts[icd]; ++pd) { 58125db71995Sopenharmony_ci auto& cur_dev = cur_icd.physical_devices[pd]; 58135db71995Sopenharmony_ci // Find the ICD device matching the physical device we're looking at info for so we can compare the 58145db71995Sopenharmony_ci // physical devices info with the returned info. 58155db71995Sopenharmony_ci if (cur_dev.properties.apiVersion == pd_props.apiVersion && cur_dev.properties.deviceID == pd_props.deviceID && 58165db71995Sopenharmony_ci cur_dev.properties.deviceType == pd_props.deviceType && 58175db71995Sopenharmony_ci cur_dev.properties.driverVersion == pd_props.driverVersion && 58185db71995Sopenharmony_ci cur_dev.properties.vendorID == pd_props.vendorID) { 58195db71995Sopenharmony_ci VkDisplayKHR display = VK_NULL_HANDLE; 58205db71995Sopenharmony_ci if (icd == 1) { 58215db71995Sopenharmony_ci // For this extension, if no support exists (like for ICD 1), the value of 0 should be returned by the 58225db71995Sopenharmony_ci // loader. 58235db71995Sopenharmony_ci ASSERT_EQ(VK_ERROR_EXTENSION_NOT_PRESENT, GetDrmDisplayEXT(physical_devices[dev], 0, 0, &display)); 58245db71995Sopenharmony_ci } else { 58255db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetDrmDisplayEXT(physical_devices[dev], 0, 0, &display)); 58265db71995Sopenharmony_ci ASSERT_EQ(display, cur_dev.displays[0]); 58275db71995Sopenharmony_ci } 58285db71995Sopenharmony_ci found = true; 58295db71995Sopenharmony_ci break; 58305db71995Sopenharmony_ci } 58315db71995Sopenharmony_ci } 58325db71995Sopenharmony_ci if (found) { 58335db71995Sopenharmony_ci break; 58345db71995Sopenharmony_ci } 58355db71995Sopenharmony_ci } 58365db71995Sopenharmony_ci } 58375db71995Sopenharmony_ci} 58385db71995Sopenharmony_ci 58395db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, DifferentInstanceExtensions) { 58405db71995Sopenharmony_ci FrameworkEnvironment env{}; 58415db71995Sopenharmony_ci 58425db71995Sopenharmony_ci // Add 3 drivers each of which supports a different instance extension 58435db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_0)); 58445db71995Sopenharmony_ci env.get_test_icd(0).add_instance_extension({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME}); 58455db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back({"pd0"}); 58465db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 0}); 58475db71995Sopenharmony_ci 58485db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_0)); 58495db71995Sopenharmony_ci env.get_test_icd(1).add_instance_extension({VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME}); 58505db71995Sopenharmony_ci env.get_test_icd(1).physical_devices.push_back({"pd1"}); 58515db71995Sopenharmony_ci env.get_test_icd(1).physical_devices.back().extensions.push_back({VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, 0}); 58525db71995Sopenharmony_ci 58535db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_0)); 58545db71995Sopenharmony_ci env.get_test_icd(2).add_instance_extension({VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME}); 58555db71995Sopenharmony_ci env.get_test_icd(2).physical_devices.push_back({"pd2"}); 58565db71995Sopenharmony_ci env.get_test_icd(2).physical_devices.back().extensions.push_back({VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, 0}); 58575db71995Sopenharmony_ci 58585db71995Sopenharmony_ci DebugUtilsLogger log{VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT}; 58595db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 58605db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 58615db71995Sopenharmony_ci VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, 58625db71995Sopenharmony_ci VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME}); 58635db71995Sopenharmony_ci FillDebugUtilsCreateDetails(inst.create_info, log); 58645db71995Sopenharmony_ci inst.CheckCreate(); 58655db71995Sopenharmony_ci 58665db71995Sopenharmony_ci const uint32_t expected_device_count = 3; 58675db71995Sopenharmony_ci auto physical_devices = inst.GetPhysDevs(expected_device_count); 58685db71995Sopenharmony_ci 58695db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR GetPhysicalDeviceExternalBufferProperties = 58705db71995Sopenharmony_ci inst.load("vkGetPhysicalDeviceExternalBufferPropertiesKHR"); 58715db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR GetPhysicalDeviceExternalSemaphoreProperties = 58725db71995Sopenharmony_ci inst.load("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"); 58735db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR GetPhysicalDeviceExternalFenceProperties = 58745db71995Sopenharmony_ci inst.load("vkGetPhysicalDeviceExternalFencePropertiesKHR"); 58755db71995Sopenharmony_ci ASSERT_NE(nullptr, GetPhysicalDeviceExternalBufferProperties); 58765db71995Sopenharmony_ci ASSERT_NE(nullptr, GetPhysicalDeviceExternalSemaphoreProperties); 58775db71995Sopenharmony_ci ASSERT_NE(nullptr, GetPhysicalDeviceExternalFenceProperties); 58785db71995Sopenharmony_ci 58795db71995Sopenharmony_ci // The above are instance extensions, so shouldn't crash even if only one physical device supports each 58805db71995Sopenharmony_ci // extension. 58815db71995Sopenharmony_ci for (uint32_t dev = 0; dev < expected_device_count; ++dev) { 58825db71995Sopenharmony_ci VkPhysicalDeviceExternalBufferInfo ext_buf_info{}; 58835db71995Sopenharmony_ci VkExternalBufferProperties ext_buf_props{}; 58845db71995Sopenharmony_ci VkPhysicalDeviceExternalSemaphoreInfo ext_sem_info{}; 58855db71995Sopenharmony_ci VkExternalSemaphoreProperties ext_sem_props{}; 58865db71995Sopenharmony_ci VkPhysicalDeviceExternalFenceInfo ext_fence_info{}; 58875db71995Sopenharmony_ci VkExternalFenceProperties ext_fence_props{}; 58885db71995Sopenharmony_ci GetPhysicalDeviceExternalBufferProperties(physical_devices[dev], &ext_buf_info, &ext_buf_props); 58895db71995Sopenharmony_ci GetPhysicalDeviceExternalSemaphoreProperties(physical_devices[dev], &ext_sem_info, &ext_sem_props); 58905db71995Sopenharmony_ci GetPhysicalDeviceExternalFenceProperties(physical_devices[dev], &ext_fence_info, &ext_fence_props); 58915db71995Sopenharmony_ci } 58925db71995Sopenharmony_ci} 58935db71995Sopenharmony_ci 58945db71995Sopenharmony_ciTEST(LoaderInstPhysDevExts, DifferentPhysicalDeviceExtensions) { 58955db71995Sopenharmony_ci FrameworkEnvironment env{}; 58965db71995Sopenharmony_ci 58975db71995Sopenharmony_ci // Add 3 drivers each of which supports a different physical device extension 58985db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_0)); 58995db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.push_back("pd0"); 59005db71995Sopenharmony_ci env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME, 0}); 59015db71995Sopenharmony_ci 59025db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_0)); 59035db71995Sopenharmony_ci env.get_test_icd(1).physical_devices.push_back("pd1"); 59045db71995Sopenharmony_ci env.get_test_icd(1).physical_devices.back().extensions.push_back({VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME, 0}); 59055db71995Sopenharmony_ci 59065db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_0)); 59075db71995Sopenharmony_ci env.get_test_icd(2).physical_devices.push_back("pd2"); 59085db71995Sopenharmony_ci env.get_test_icd(2).physical_devices.back().extensions.push_back({VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, 0}); 59095db71995Sopenharmony_ci 59105db71995Sopenharmony_ci DebugUtilsLogger log{VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT}; 59115db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 59125db71995Sopenharmony_ci FillDebugUtilsCreateDetails(inst.create_info, log); 59135db71995Sopenharmony_ci inst.CheckCreate(); 59145db71995Sopenharmony_ci 59155db71995Sopenharmony_ci const uint32_t expected_device_count = 3; 59165db71995Sopenharmony_ci auto physical_devices = inst.GetPhysDevs(expected_device_count); 59175db71995Sopenharmony_ci 59185db71995Sopenharmony_ci PFN_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR 59195db71995Sopenharmony_ci EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR = 59205db71995Sopenharmony_ci inst.load("vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR"); 59215db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT GetPhysicalDeviceMultisamplePropertiesEXT = 59225db71995Sopenharmony_ci inst.load("vkGetPhysicalDeviceMultisamplePropertiesEXT"); 59235db71995Sopenharmony_ci PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT GetPhysicalDeviceCalibrateableTimeDomainsEXT = 59245db71995Sopenharmony_ci inst.load("vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"); 59255db71995Sopenharmony_ci ASSERT_NE(nullptr, EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR); 59265db71995Sopenharmony_ci ASSERT_NE(nullptr, GetPhysicalDeviceMultisamplePropertiesEXT); 59275db71995Sopenharmony_ci ASSERT_NE(nullptr, GetPhysicalDeviceCalibrateableTimeDomainsEXT); 59285db71995Sopenharmony_ci 59295db71995Sopenharmony_ci for (uint32_t dev = 0; dev < expected_device_count; ++dev) { 59305db71995Sopenharmony_ci uint32_t extension_count = 0; 59315db71995Sopenharmony_ci std::vector<VkExtensionProperties> device_extensions; 59325db71995Sopenharmony_ci bool supports_query = false; 59335db71995Sopenharmony_ci bool supports_samples = false; 59345db71995Sopenharmony_ci bool supports_timestamps = false; 59355db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, 59365db71995Sopenharmony_ci inst->vkEnumerateDeviceExtensionProperties(physical_devices[dev], nullptr, &extension_count, nullptr)); 59375db71995Sopenharmony_ci ASSERT_GT(extension_count, 0U); 59385db71995Sopenharmony_ci device_extensions.resize(extension_count); 59395db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumerateDeviceExtensionProperties(physical_devices[dev], nullptr, &extension_count, 59405db71995Sopenharmony_ci device_extensions.data())); 59415db71995Sopenharmony_ci for (uint32_t ext = 0; ext < extension_count; ++ext) { 59425db71995Sopenharmony_ci if (string_eq(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME, &device_extensions[ext].extensionName[0])) { 59435db71995Sopenharmony_ci supports_query = true; 59445db71995Sopenharmony_ci } 59455db71995Sopenharmony_ci if (string_eq(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME, &device_extensions[ext].extensionName[0])) { 59465db71995Sopenharmony_ci supports_samples = true; 59475db71995Sopenharmony_ci } 59485db71995Sopenharmony_ci if (string_eq(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, &device_extensions[ext].extensionName[0])) { 59495db71995Sopenharmony_ci supports_timestamps = true; 59505db71995Sopenharmony_ci } 59515db71995Sopenharmony_ci } 59525db71995Sopenharmony_ci 59535db71995Sopenharmony_ci // For physical device extensions, they should work for devices that support it and crash for those that don't. 59545db71995Sopenharmony_ci if (supports_query) { 59555db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(physical_devices[dev], 0, nullptr, 59565db71995Sopenharmony_ci nullptr, nullptr)); 59575db71995Sopenharmony_ci } else { 59585db71995Sopenharmony_ci ASSERT_DEATH( 59595db71995Sopenharmony_ci EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(physical_devices[dev], 0, nullptr, nullptr, nullptr), 59605db71995Sopenharmony_ci ""); 59615db71995Sopenharmony_ci ASSERT_FALSE( 59625db71995Sopenharmony_ci log.find("ICD associated with VkPhysicalDevice does not support " 59635db71995Sopenharmony_ci "EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR")); 59645db71995Sopenharmony_ci } 59655db71995Sopenharmony_ci if (supports_samples) { 59665db71995Sopenharmony_ci GetPhysicalDeviceMultisamplePropertiesEXT(physical_devices[dev], VK_SAMPLE_COUNT_2_BIT, nullptr); 59675db71995Sopenharmony_ci } else { 59685db71995Sopenharmony_ci ASSERT_DEATH(GetPhysicalDeviceMultisamplePropertiesEXT(physical_devices[dev], VK_SAMPLE_COUNT_2_BIT, nullptr), ""); 59695db71995Sopenharmony_ci ASSERT_FALSE( 59705db71995Sopenharmony_ci log.find("ICD associated with VkPhysicalDevice does not support GetPhysicalDeviceMultisamplePropertiesEXT")); 59715db71995Sopenharmony_ci } 59725db71995Sopenharmony_ci if (supports_timestamps) { 59735db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, GetPhysicalDeviceCalibrateableTimeDomainsEXT(physical_devices[dev], nullptr, nullptr)); 59745db71995Sopenharmony_ci } else { 59755db71995Sopenharmony_ci ASSERT_DEATH(GetPhysicalDeviceCalibrateableTimeDomainsEXT(physical_devices[dev], nullptr, nullptr), ""); 59765db71995Sopenharmony_ci ASSERT_FALSE( 59775db71995Sopenharmony_ci log.find("ICD associated with VkPhysicalDevice does not support GetPhysicalDeviceCalibrateableTimeDomainsEXT")); 59785db71995Sopenharmony_ci } 59795db71995Sopenharmony_ci } 59805db71995Sopenharmony_ci} 5981