test: Add TestICD DeviceGroup support
authorCharles Giessen <charles@lunarg.com>
Tue, 31 Aug 2021 20:05:32 +0000 (14:05 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Tue, 31 Aug 2021 21:04:40 +0000 (15:04 -0600)
Add support for tests which use device groups by adding a new structure that
holds pointes to PhysicalDevice structs and implementing the necessary vulkan
API calls.

This commit also:
 - Formats test_icd.cpp
 - Makes vk_icdGetPhysicalDeviceProcAddr return stuff by refactoring the
   instance procaddr functions

tests/framework/icd/physical_device.h
tests/framework/icd/test_icd.cpp
tests/framework/icd/test_icd.h
tests/framework/test_util.cpp
tests/framework/test_util.h

index 01d4f963eede855dcdd40040c9c7d56b38475ce7..2a0ab5daf256a9c061f892ac80beb70ee8fdc9e3 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "test_util.h"
 
+// Move only type because it holds a DispatchableHandle<VkPhysicalDevice>
 struct PhysicalDevice {
     PhysicalDevice() {}
     PhysicalDevice(std::string name) : deviceName(name) {}
@@ -74,4 +75,14 @@ struct PhysicalDevice {
     // The purpose of this list is so that vkGetDeviceProcAddr returns 'a real function pointer' in tests
     // without actually implementing any of the logic inside of it.
     std::vector<const char*> known_device_functions_no_implementation;
+};
+
+struct PhysicalDeviceGroup {
+    PhysicalDeviceGroup& use_physical_device(PhysicalDevice const& physical_device) {
+        physical_device_handles.push_back(&physical_device);
+        return *this;
+    }
+
+    std::vector<PhysicalDevice const*> physical_device_handles;
+    VkBool32 subset_allocation = false;
 };
\ No newline at end of file
index aa25f542fe46cf7137ac719d95d1ff237e38bfdb..ff1c432d8e4aa169c4386b3ca2831b229b94fe9e 100644 (file)
@@ -47,7 +47,6 @@
 #define TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES 0
 #endif
 
-
 TestICD icd;
 extern "C" {
 FRAMEWORK_EXPORT TestICD* get_test_icd_func() { return &icd; }
@@ -190,6 +189,30 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDevices(VkInstance instan
     return VK_SUCCESS;
 }
 
+// VK_SUCCESS,VK_INCOMPLETE, VK_ERROR_INITIALIZATION_FAILED
+VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDeviceGroups(
+    VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) {
+    if (pPhysicalDeviceGroupProperties == nullptr) {
+        *pPhysicalDeviceGroupCount = icd.physical_device_groups.size();
+    } else {
+        for (size_t device_group = 0; device_group < icd.physical_device_groups.size(); device_group++) {
+            if (device_group >= *pPhysicalDeviceGroupCount) {
+                return VK_INCOMPLETE;
+            }
+            pPhysicalDeviceGroupProperties[device_group].subsetAllocation =
+                icd.physical_device_groups[device_group].subset_allocation;
+            uint32_t handles_written = 0;
+            for (size_t i = 0; i < icd.physical_device_groups[device_group].physical_device_handles.size(); i++) {
+                handles_written++;
+                pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] =
+                    icd.physical_device_groups[device_group].physical_device_handles[i]->vk_physical_device.handle;
+            }
+            pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = handles_written;
+        }
+    }
+    return VK_SUCCESS;
+}
+
 //// Physical Device functions ////
 
 // VK_SUCCESS,VK_INCOMPLETE
@@ -273,7 +296,8 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateXlibSurfaceKHR(VkInstance instance,
 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
                                                             const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
     if (nullptr != pSurface) {
-#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
+#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
+    defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
         *pSurface = reinterpret_cast<VkSurfaceKHR>(++icd.created_surface_count);
 #else
         *pSurface = ++icd.created_surface_count;
@@ -290,7 +314,8 @@ VKAPI_ATTR void VKAPI_CALL test_vkDestroySurfaceKHR(VkInstance instance, VkSurfa
 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo,
                                                          const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) {
     if (nullptr != pSwapchain) {
-#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
+#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
+    defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
         *pSwapchain = reinterpret_cast<VkSwapchainKHR>(++icd.created_swapchain_count);
 #else
         *pSwapchain = ++icd.created_swapchain_count;
@@ -349,6 +374,16 @@ PFN_vkVoidFunction get_instance_func_ver_1_2(VkInstance instance, const char* pN
     return nullptr;
 }
 
+PFN_vkVoidFunction get_physical_device_func_wsi(VkInstance instance, const char* pName) {
+    if (string_eq(pName, "vkGetPhysicalDeviceSurfaceSupportKHR")) return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfaceSupportKHR);
+    if (string_eq(pName, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"))
+        return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
+    if (string_eq(pName, "vkGetPhysicalDeviceSurfaceFormatsKHR")) return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfaceFormatsKHR);
+    if (string_eq(pName, "vkGetPhysicalDeviceSurfacePresentModesKHR"))
+        return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfacePresentModesKHR);
+    return nullptr;
+}
+
 PFN_vkVoidFunction get_instance_func_wsi(VkInstance instance, const char* pName) {
     if (icd.min_icd_interface_version >= 3 && icd.enable_icd_wsi == true) {
 #ifdef VK_USE_PLATFORM_ANDROID_KHR
@@ -388,24 +423,11 @@ PFN_vkVoidFunction get_instance_func_wsi(VkInstance instance, const char* pName)
         }
     }
 
-    if (string_eq(pName, "vkGetPhysicalDeviceSurfaceSupportKHR")) return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfaceSupportKHR);
-    if (string_eq(pName, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"))
-        return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
-    if (string_eq(pName, "vkGetPhysicalDeviceSurfaceFormatsKHR")) return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfaceFormatsKHR);
-    if (string_eq(pName, "vkGetPhysicalDeviceSurfacePresentModesKHR"))
-        return TO_VOID_PFN(test_vkGetPhysicalDeviceSurfacePresentModesKHR);
-
+    PFN_vkVoidFunction ret_phys_dev_wsi = get_physical_device_func_wsi(instance, pName);
+    if (ret_phys_dev_wsi != nullptr) return ret_phys_dev_wsi;
     return nullptr;
 }
-
-PFN_vkVoidFunction get_instance_func(VkInstance instance, const char* pName) {
-    if (string_eq(pName, "vkEnumerateInstanceExtensionProperties")) return TO_VOID_PFN(test_vkEnumerateInstanceExtensionProperties);
-    if (string_eq(pName, "vkEnumerateInstanceLayerProperties")) return TO_VOID_PFN(test_vkEnumerateInstanceLayerProperties);
-    if (string_eq(pName, "vkCreateInstance")) return TO_VOID_PFN(test_vkCreateInstance);
-    if (string_eq(pName, "vkDestroyInstance")) return TO_VOID_PFN(test_vkDestroyInstance);
-    if (string_eq(pName, "vkEnumeratePhysicalDevices")) return TO_VOID_PFN(test_vkEnumeratePhysicalDevices);
-    // if (string_eq(pName, "vk_icdEnumerateAdapterPhysicalDevices") ) return
-    // TO_VOID_PFN(test_vk_icdEnumerateAdapterPhysicalDevices);
+PFN_vkVoidFunction get_physical_device_func(VkInstance instance, const char* pName) {
     if (string_eq(pName, "vkEnumerateDeviceLayerProperties")) return TO_VOID_PFN(test_vkEnumerateDeviceLayerProperties);
     if (string_eq(pName, "vkEnumerateDeviceExtensionProperties")) return TO_VOID_PFN(test_vkEnumerateDeviceExtensionProperties);
     if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyProperties"))
@@ -418,6 +440,20 @@ PFN_vkVoidFunction get_instance_func(VkInstance instance, const char* pName) {
         string_eq(pName, "vkGetPhysicalDeviceFormatProperties"))
         return TO_VOID_PFN(test_stub_func_no_return);
     if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties")) return TO_VOID_PFN(test_stub_func_with_return);
+    return nullptr;
+}
+
+PFN_vkVoidFunction get_instance_func(VkInstance instance, const char* pName) {
+    if (string_eq(pName, "vkEnumerateInstanceExtensionProperties")) return TO_VOID_PFN(test_vkEnumerateInstanceExtensionProperties);
+    if (string_eq(pName, "vkEnumerateInstanceLayerProperties")) return TO_VOID_PFN(test_vkEnumerateInstanceLayerProperties);
+    if (string_eq(pName, "vkCreateInstance")) return TO_VOID_PFN(test_vkCreateInstance);
+    if (string_eq(pName, "vkDestroyInstance")) return TO_VOID_PFN(test_vkDestroyInstance);
+    if (string_eq(pName, "vkEnumeratePhysicalDevices")) return TO_VOID_PFN(test_vkEnumeratePhysicalDevices);
+    if (string_eq(pName, "vkEnumeratePhysicalDeviceGroups") || string_eq(pName, "vkEnumeratePhysicalDeviceGroupsKHR"))
+        return TO_VOID_PFN(test_vkEnumeratePhysicalDeviceGroups);
+
+    PFN_vkVoidFunction ret_phys_dev = get_physical_device_func(instance, pName);
+    if (ret_phys_dev != nullptr) return ret_phys_dev;
 
     PFN_vkVoidFunction ret_1_1 = get_instance_func_ver_1_1(instance, pName);
     if (ret_1_1 != nullptr) return ret_1_1;
@@ -512,15 +548,14 @@ extern FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDI
 
     return VK_SUCCESS;
 }
-#endif //TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION
+#endif  // TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION
 
 #if TEST_ICD_EXPORT_ICD_GPDPA
 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName) {
     // std::cout << "icdGetPhysicalDeviceProcAddr: " << pName << "\n";
-
-    return nullptr;
+    return get_physical_device_func(instance, pName);
 }
-#endif //TEST_ICD_EXPORT_ICD_GPDPA
+#endif  // TEST_ICD_EXPORT_ICD_GPDPA
 
 #if TEST_ICD_EXPORT_ICD_GIPA
 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName) {
@@ -531,7 +566,7 @@ FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcA
     return base_get_instance_proc_addr(instance, pName);
     return nullptr;
 }
-#else // !TEST_ICD_EXPORT_ICD_GIPA
+#else   // !TEST_ICD_EXPORT_ICD_GIPA
 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
     // std::cout << "icdGetInstanceProcAddr: " << pName << "\n";
 
index 29ec767585634edc8996cd44c2876ad071d79363..c3d0777f1c665e7877dba2412b38dd53561c4a4e 100644 (file)
 
 #include "physical_device.h"
 
-
 enum class CalledICDGIPA { not_called, vk_icd_gipa, vk_gipa };
 
 enum class CalledNegotiateInterface { not_called, vk_icd_negotiate, vk_icd_gipa_first };
 
-enum class InterfaceVersionCheck { not_called, loader_version_too_old, loader_version_too_new, icd_version_too_new, version_is_supported};
+enum class InterfaceVersionCheck {
+    not_called,
+    loader_version_too_old,
+    loader_version_too_new,
+    icd_version_too_new,
+    version_is_supported
+};
 
-enum class CalledEnumerateAdapterPhysicalDevices { not_called, called, called_but_not_supported};
+enum class CalledEnumerateAdapterPhysicalDevices { not_called, called, called_but_not_supported };
 
-enum class UsingICDProvidedWSI { not_using, is_using};
+enum class UsingICDProvidedWSI { not_using, is_using };
 
 struct TestICD {
     fs::path manifest_file_path;
@@ -55,7 +60,8 @@ struct TestICD {
     uint32_t max_icd_interface_version = 6;
     uint32_t icd_interface_version_received = 0;
 
-    CalledEnumerateAdapterPhysicalDevices called_enumerate_adapter_physical_devices = CalledEnumerateAdapterPhysicalDevices::not_called;
+    CalledEnumerateAdapterPhysicalDevices called_enumerate_adapter_physical_devices =
+        CalledEnumerateAdapterPhysicalDevices::not_called;
 
     bool enable_icd_wsi = false;
     UsingICDProvidedWSI is_using_icd_wsi = UsingICDProvidedWSI::not_using;
@@ -65,13 +71,14 @@ struct TestICD {
     std::vector<Extension> instance_extensions;
     std::vector<PhysicalDevice> physical_devices;
 
+    std::vector<PhysicalDeviceGroup> physical_device_groups;
+
     DispatchableHandle<VkInstance> instance_handle;
     std::vector<DispatchableHandle<VkDevice>> device_handles;
 
     uint64_t created_surface_count = 0;
     uint64_t created_swapchain_count = 0;
 
-
     TestICD() {}
     ~TestICD() {}
 
index 37ca81248f95db155324e66c7f35d96eab033104..47c4470508414771f5f86d7cf538d73c5d4374a5 100644 (file)
@@ -501,6 +501,7 @@ VulkanFunctions::VulkanFunctions() : loader(FRAMEWORK_VULKAN_LIBRARY_PATH) {
     vkCreateInstance = loader.get_symbol<PFN_vkCreateInstance>("vkCreateInstance");
     vkDestroyInstance = loader.get_symbol<PFN_vkDestroyInstance>("vkDestroyInstance");
     vkEnumeratePhysicalDevices = loader.get_symbol<PFN_vkEnumeratePhysicalDevices>("vkEnumeratePhysicalDevices");
+    vkEnumeratePhysicalDeviceGroups = loader.get_symbol<PFN_vkEnumeratePhysicalDeviceGroups>("vkEnumeratePhysicalDeviceGroups");
     vkGetPhysicalDeviceFeatures = loader.get_symbol<PFN_vkGetPhysicalDeviceFeatures>("vkGetPhysicalDeviceFeatures");
     vkGetPhysicalDeviceFeatures2 = loader.get_symbol<PFN_vkGetPhysicalDeviceFeatures2>("vkGetPhysicalDeviceFeatures2");
     vkGetPhysicalDeviceFormatProperties = loader.get_symbol<PFN_vkGetPhysicalDeviceFormatProperties>("vkGetPhysicalDeviceFormatProperties");
index 900f7e82368f0b9f95a5ee8106a251dc3bffe3a1..d69fb3d71bbbf437d89be2d12a752c7b2b76069d 100644 (file)
@@ -531,6 +531,7 @@ struct VulkanFunctions {
     // Instance
     PFN_vkDestroyInstance vkDestroyInstance = nullptr;
     PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices = nullptr;
+    PFN_vkEnumeratePhysicalDeviceGroups vkEnumeratePhysicalDeviceGroups = nullptr;
     PFN_vkGetPhysicalDeviceFeatures vkGetPhysicalDeviceFeatures = nullptr;
     PFN_vkGetPhysicalDeviceFeatures2 vkGetPhysicalDeviceFeatures2 = nullptr;
     PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties = nullptr;