misc: Change vkEnumerateGpus to vkEnumeratePhysicalDevices
authorJon Ashburn <jon@lunarg.com>
Wed, 15 Apr 2015 17:31:12 +0000 (11:31 -0600)
committerTony Barbour <tony@LunarG.com>
Fri, 17 Apr 2015 01:34:59 +0000 (19:34 -0600)
Conflicts:
loader/loader.h

demos/cube.c
demos/tri.c
demos/vulkaninfo.c
include/vkLayer.h
include/vulkan.h
layers/param_checker.cpp
loader/loader.c
loader/loader.h
vk-generate.py
vulkan.py

index 13d2ff082712cb924f44cb2f3735987d5f8818a8..f046c02f0ccfa6b6a54ba9577ab5d7d7f3dbea51 100644 (file)
@@ -1717,7 +1717,8 @@ static void demo_init_vk(struct demo *demo)
         assert(!err);
     }
 
-    err = vkEnumerateGpus(demo->inst, 1, &gpu_count, &demo->gpu);
+    gpu_count = 1;
+    err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, &demo->gpu);
     assert(!err && gpu_count == 1);
 
     err = vkWsiX11AssociateConnection(demo->gpu, &connection);
index 8918a2c3d7b3be2bd87765756144cd3376fe2f50..a594cf9a2ef58a1a8134664ca2e2c3fa8e8bfd5c 100644 (file)
@@ -1256,7 +1256,8 @@ static void demo_init_vk(struct demo *demo)
         assert(!err);
     }
 
-    err = vkEnumerateGpus(demo->inst, 1, &gpu_count, &demo->gpu);
+    gpu_count = 1;
+    err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, &demo->gpu);
     assert(!err && gpu_count == 1);
 
     err = vkWsiX11AssociateConnection(demo->gpu, &connection);
index 2966dfd1dec8eb62d95a07791247ea141c686760..4189e73256d8194bec02a0695a2aeed167d8ff10 100644 (file)
@@ -683,7 +683,15 @@ int main(int argc, char **argv)
 
         ERR_EXIT(err);
     }
-    err = vkEnumerateGpus(inst, MAX_GPUS, &gpu_count, objs);
+    err = vkEnumeratePhysicalDevices(inst, &gpu_count, NULL);
+    if (err)
+        ERR_EXIT(err);
+    if (gpu_count > MAX_GPUS) {
+        printf("Too many GPUS found \nExiting ...\n");
+        fflush(stdout);
+        exit(1);
+    }
+    err = vkEnumeratePhysicalDevices(inst, &gpu_count, objs);
     if (err)
         ERR_EXIT(err);
 
index 53460c7399a4ac80881320ad3c222324cd96ab0b..e9e8b037c0f4ca435f69ba9da3b7a1f4526b75f9 100644 (file)
@@ -30,7 +30,7 @@ typedef struct VkLayerDispatchTable_
     PFN_vkGetProcAddr GetProcAddr;
     PFN_vkCreateInstance CreateInstance;
     PFN_vkDestroyInstance DestroyInstance;
-    PFN_vkEnumerateGpus EnumerateGpus;
+    PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
     PFN_vkGetGpuInfo GetGpuInfo;
     PFN_vkCreateDevice CreateDevice;
     PFN_vkDestroyDevice DestroyDevice;
index d80c15a28d2257ed7f4053698f526d10a4d123ff..4e91b4337aea5883a4c80db1e93ba3ee60ba2623 100644 (file)
@@ -87,7 +87,6 @@ VK_DEFINE_SUBCLASS_HANDLE(VkQueryPool, VkObject)
 VK_DEFINE_SUBCLASS_HANDLE(VkFramebuffer, VkObject)
 VK_DEFINE_SUBCLASS_HANDLE(VkRenderPass, VkObject)
 
-#define VK_MAX_PHYSICAL_GPUS       16
 #define VK_MAX_PHYSICAL_GPU_NAME   256
 #define VK_MAX_EXTENSION_NAME      256
 
@@ -2200,7 +2199,7 @@ typedef struct VkDispatchIndirectCmd_
 // API functions
 typedef VkResult (VKAPI *PFN_vkCreateInstance)(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance);
 typedef VkResult (VKAPI *PFN_vkDestroyInstance)(VkInstance instance);
-typedef VkResult (VKAPI *PFN_vkEnumerateGpus)(VkInstance instance, uint32_t maxGpus, uint32_t* pGpuCount, VkPhysicalGpu* pGpus);
+typedef VkResult (VKAPI *PFN_vkEnumeratePhysicalDevices)(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalGpu* pPhysicalDevices);
 typedef VkResult (VKAPI *PFN_vkGetGpuInfo)(VkPhysicalGpu gpu, VkPhysicalGpuInfoType infoType, size_t* pDataSize, void* pData);
 typedef void *   (VKAPI *PFN_vkGetProcAddr)(VkPhysicalGpu gpu, const char * pName);
 typedef VkResult (VKAPI *PFN_vkCreateDevice)(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice);
@@ -2326,11 +2325,10 @@ VkResult VKAPI vkCreateInstance(
 VkResult VKAPI vkDestroyInstance(
     VkInstance                                  instance);
 
-VkResult VKAPI vkEnumerateGpus(
+VkResult VKAPI vkEnumeratePhysicalDevices(
     VkInstance                                  instance,
-    uint32_t                                    maxGpus,
-    uint32_t*                                   pGpuCount,
-    VkPhysicalGpu*                              pGpus);
+    uint32_t*                                   pPhysicalDeviceCount,
+    VkPhysicalGpu*                              pPhysicalDevices);
 
 VkResult VKAPI vkGetGpuInfo(
     VkPhysicalGpu                               gpu,
index fae24d1c83b46c6e48a19803af03f08d8b8eaa85..5408ee77146edfd10084050ee7408505d5b3d0f1 100644 (file)
@@ -139,13 +139,6 @@ VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
     return result;
 }
 
-VK_LAYER_EXPORT VkResult VKAPI vkEnumerateGpus(VkInstance instance, uint32_t maxGpus, uint32_t* pGpuCount, VkPhysicalGpu* pGpus)
-{
-
-    VkResult result = nextTable.EnumerateGpus(instance, maxGpus, pGpuCount, pGpus);
-    return result;
-}
-
 VK_LAYER_EXPORT VkResult VKAPI vkGetGpuInfo(VkPhysicalGpu gpu, VkPhysicalGpuInfoType infoType, size_t* pDataSize, void* pData)
 {
     pCurObj = (VkBaseLayerObject *) gpu;
index 20646a7b1194fbac623c8398b285950d2ce7c77d..b71a39a5dbb6ae00c026e6b09c976d11126c96b8 100644 (file)
@@ -69,9 +69,9 @@ struct loader_icd {
     const struct loader_scanned_icds *scanned_icds;
 
     VkLayerDispatchTable *loader_dispatch;
-    uint32_t layer_count[VK_MAX_PHYSICAL_GPUS];
-    struct loader_layers layer_libs[VK_MAX_PHYSICAL_GPUS][MAX_LAYER_LIBRARIES];
-    VkBaseLayerObject *wrappedGpus[VK_MAX_PHYSICAL_GPUS];
+    uint32_t layer_count[MAX_GPUS_FOR_LAYER];
+    struct loader_layers layer_libs[MAX_GPUS_FOR_LAYER][MAX_LAYER_LIBRARIES];
+    VkBaseLayerObject *wrappedGpus[MAX_GPUS_FOR_LAYER];
     uint32_t gpu_count;
     VkBaseLayerObject *gpus;
 
@@ -85,7 +85,7 @@ struct loader_scanned_icds {
     PFN_vkGetProcAddr GetProcAddr;
     PFN_vkCreateInstance CreateInstance;
     PFN_vkDestroyInstance DestroyInstance;
-    PFN_vkEnumerateGpus EnumerateGpus;
+    PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
     PFN_vkGetGlobalExtensionInfo GetGlobalExtensionInfo;
     VkInstance instance;
     struct loader_scanned_icds *next;
@@ -443,7 +443,7 @@ static void loader_scanned_icd_add(const char *filename)
     LOOKUP(fp_gpa, GetProcAddr);
     LOOKUP(fp_create_inst, CreateInstance);
     LOOKUP(fp_destroy_inst, DestroyInstance);
-    LOOKUP(fp_enumerate, EnumerateGpus);
+    LOOKUP(fp_enumerate, EnumeratePhysicalDevices);
     LOOKUP(fp_get_global_ext_info, GetGlobalExtensionInfo);
 #undef LOOKUP
 
@@ -457,7 +457,7 @@ static void loader_scanned_icd_add(const char *filename)
     new_node->GetProcAddr = fp_gpa;
     new_node->CreateInstance = fp_create_inst;
     new_node->DestroyInstance = fp_destroy_inst;
-    new_node->EnumerateGpus = fp_enumerate;
+    new_node->EnumeratePhysicalDevices = fp_enumerate;
     new_node->GetGlobalExtensionInfo = fp_get_global_ext_info;
     new_node->extension_count = 0;
     new_node->extensions = NULL;
@@ -1017,7 +1017,7 @@ extern uint32_t loader_activate_layers(struct loader_icd *icd, uint32_t gpu_inde
     struct layer_name_pair *pLayerNames;
     if (!icd)
         return 0;
-    assert(gpu_index < VK_MAX_PHYSICAL_GPUS);
+    assert(gpu_index < MAX_GPUS_FOR_LAYER);
 
     gpu = icd->gpus + gpu_index;
     /* activate any layer libraries */
@@ -1194,73 +1194,90 @@ LOADER_EXPORT VkResult VKAPI vkDestroyInstance(
     return VK_SUCCESS;
 }
 
-LOADER_EXPORT VkResult VKAPI vkEnumerateGpus(
+LOADER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(
 
         VkInstance                                instance,
-        uint32_t                                    maxGpus,
-        uint32_t*                                   pGpuCount,
-        VkPhysicalGpu*                           pGpus)
+        uint32_t*                                 pPhysicalDeviceCount,
+        VkPhysicalGpu*                            pPhysicalDevices)
 {
     struct loader_instance *ptr_instance = (struct loader_instance *) instance;
     struct loader_icd *icd;
-    uint32_t count = 0;
+    uint32_t n, count = 0;
     VkResult res;
 
     //in spirit of VK don't error check on the instance parameter
     icd = ptr_instance->icds;
-    while (icd) {
-        VkPhysicalGpu gpus[VK_MAX_PHYSICAL_GPUS];
-        VkBaseLayerObject * wrapped_gpus;
-        PFN_vkGetProcAddr get_proc_addr = icd->scanned_icds->GetProcAddr;
-        uint32_t n, max = maxGpus - count;
-
-        if (max > VK_MAX_PHYSICAL_GPUS) {
-            max = VK_MAX_PHYSICAL_GPUS;
+    if (pPhysicalDevices == NULL) {
+        while (icd) {
+            res = icd->scanned_icds->EnumeratePhysicalDevices(
+                                                icd->scanned_icds->instance,
+                                                &n, NULL);
+            if (res != VK_SUCCESS)
+                return res;
+            icd->gpu_count = n;
+            count += n;
+            icd = icd->next;
         }
 
-        res = icd->scanned_icds->EnumerateGpus(icd->scanned_icds->instance,
-                                               max, &n,
-                                               gpus);
-        if (res == VK_SUCCESS && n) {
-            wrapped_gpus = (VkBaseLayerObject*) malloc(n *
-                                        sizeof(VkBaseLayerObject));
-            icd->gpus = wrapped_gpus;
-            icd->gpu_count = n;
-            icd->loader_dispatch = (VkLayerDispatchTable *) malloc(n *
+        ptr_instance->total_gpu_count = count;
+
+    } else
+    {
+        VkPhysicalGpu* gpus;
+        if (*pPhysicalDeviceCount < ptr_instance->total_gpu_count)
+            return VK_ERROR_INVALID_VALUE;
+        gpus = malloc( sizeof(VkPhysicalGpu) *  *pPhysicalDeviceCount);
+        if (!gpus)
+            return VK_ERROR_OUT_OF_MEMORY;
+        while (icd) {
+            VkBaseLayerObject * wrapped_gpus;
+            PFN_vkGetProcAddr get_proc_addr = icd->scanned_icds->GetProcAddr;
+
+            res = icd->scanned_icds->EnumeratePhysicalDevices(
+                                            icd->scanned_icds->instance,
+                                            &n,
+                                            gpus);
+            if (res == VK_SUCCESS && n) {
+                wrapped_gpus = (VkBaseLayerObject*) malloc(n *
+                                            sizeof(VkBaseLayerObject));
+                icd->gpus = wrapped_gpus;
+                icd->gpu_count = n;
+                icd->loader_dispatch = (VkLayerDispatchTable *) malloc(n *
                                         sizeof(VkLayerDispatchTable));
-            for (unsigned int i = 0; i < n; i++) {
-                (wrapped_gpus + i)->baseObject = gpus[i];
-                (wrapped_gpus + i)->pGPA = get_proc_addr;
-                (wrapped_gpus + i)->nextObject = gpus[i];
-                memcpy(pGpus + count, gpus, sizeof(*pGpus));
-                loader_init_dispatch_table(icd->loader_dispatch + i,
-                                           get_proc_addr, gpus[i]);
-
-                /* Verify ICD compatibility */
-                if (!valid_loader_magic_value(gpus[i])) {
-                    loader_log(VK_DBG_MSG_WARNING, 0,
+                for (unsigned int i = 0; i < n; i++) {
+                    (wrapped_gpus + i)->baseObject = gpus[i];
+                    (wrapped_gpus + i)->pGPA = get_proc_addr;
+                    (wrapped_gpus + i)->nextObject = gpus[i];
+                    memcpy(pPhysicalDevices + count, gpus, sizeof(*pPhysicalDevices));
+                    loader_init_dispatch_table(icd->loader_dispatch + i,
+                                               get_proc_addr, gpus[i]);
+
+                    /* Verify ICD compatibility */
+                    if (!valid_loader_magic_value(gpus[i])) {
+                        loader_log(VK_DBG_MSG_WARNING, 0,
                             "Loader: Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details.\n");
-                    assert(0);
-                }
+                        assert(0);
+                    }
 
-                const VkLayerDispatchTable **disp;
-                disp = (const VkLayerDispatchTable **) gpus[i];
-                *disp = icd->loader_dispatch + i;
-                loader_activate_layers(icd, i, ptr_instance->extension_count,
+                    const VkLayerDispatchTable **disp;
+                    disp = (const VkLayerDispatchTable **) gpus[i];
+                    *disp = icd->loader_dispatch + i;
+                    loader_activate_layers(icd, i, ptr_instance->extension_count,
                         (const char *const*) ptr_instance->extension_names);
-            }
+                }
 
-            count += n;
+                count += n;
 
-            if (count >= maxGpus) {
-                break;
+                if (count >= *pPhysicalDeviceCount) {
+                    break;
+                }
             }
-        }
 
-        icd = icd->next;
+            icd = icd->next;
+        }
     }
 
-    *pGpuCount = count;
+    *pPhysicalDeviceCount = count;
 
     return (count > 0) ? VK_SUCCESS : res;
 }
index b615989f1eec6779e600b5fe6c222fff48e4c986..79d77c8d12e8b66cc360ee94a1c6f6b3e2a99634 100644 (file)
@@ -68,6 +68,7 @@ static inline void loader_init_data(void *obj, const void *data)
 }
 
 struct loader_instance {
+    uint32_t total_gpu_count;
     struct loader_icd *icds;
     struct loader_instance *next;
     uint32_t  extension_count;
@@ -77,5 +78,6 @@ struct loader_instance {
 extern uint32_t loader_activate_layers(struct loader_icd *icd, uint32_t gpu_index, uint32_t ext_count, const char *const* ext_names);
 extern struct loader_icd * loader_get_icd(const VkBaseLayerObject *gpu, uint32_t *gpu_index);
 #define MAX_LAYER_LIBRARIES 64
+#define MAX_GPUS_FOR_LAYER 16
 
 #endif /* LOADER_H */
index 120d7b4c33f79ce9d3b249cb7e4a979131ef9b55..1147620182c488561bb5db1732e431cfd6f4d320 100755 (executable)
@@ -49,7 +49,7 @@ class Subcommand(object):
         return out_objs and out_objs[-1] == proto.params[-1]
 
     def _is_loader_special_case(self, proto):
-        if proto.name in ["GetProcAddr", "EnumerateGpus", "EnumerateLayers", "DbgRegisterMsgCallback", "DbgUnregisterMsgCallback", "DbgSetGlobalOption", "DestroyInstance"]:
+        if proto.name in ["GetProcAddr", "EnumeratePhysicalDevices", "EnumerateLayers", "DbgRegisterMsgCallback", "DbgUnregisterMsgCallback", "DbgSetGlobalOption", "DestroyInstance"]:
             return True
         return not self.is_dispatchable_object_first_param(proto)
 
@@ -348,7 +348,7 @@ class LayerInterceptProcSubcommand(Subcommand):
 
         # we could get the list from argv if wanted
         self.intercepted = [proto.name for proto in self.protos
-                if proto.name not in ["EnumerateGpus"]]
+                if proto.name not in ["EnumeratePhysicalDevices"]]
 
         for proto in self.protos:
             if proto.name == "GetProcAddr":
index 4c51bd4c0f29e40e3f5b5b99dc3f95f532b49a5d..3e49704458011cab0b417741020737cc84a248c5 100755 (executable)
--- a/vulkan.py
+++ b/vulkan.py
@@ -225,11 +225,10 @@ core = Extension(
         Proto("VkResult", "DestroyInstance",
             [Param("VkInstance", "instance")]),
 
-        Proto("VkResult", "EnumerateGpus",
+        Proto("VkResult", "EnumeratePhysicalDevices",
             [Param("VkInstance", "instance"),
-             Param("uint32_t", "maxGpus"),
-             Param("uint32_t*", "pGpuCount"),
-             Param("VkPhysicalGpu*", "pGpus")]),
+             Param("uint32_t*", "pPhysicalDeviceCount"),
+             Param("VkPhysicalGpu*", "pPhysicalDevices")]),
 
         Proto("VkResult", "GetGpuInfo",
             [Param("VkPhysicalGpu", "gpu"),