From 07c0c0cb3416bcf7ee7fe8a03f7216b0c57639c4 Mon Sep 17 00:00:00 2001 From: Jon Ashburn Date: Wed, 15 Apr 2015 11:31:12 -0600 Subject: [PATCH] misc: Change vkEnumerateGpus to vkEnumeratePhysicalDevices Conflicts: loader/loader.h --- demos/cube.c | 3 +- demos/tri.c | 3 +- demos/vulkaninfo.c | 10 +++- include/vkLayer.h | 2 +- include/vulkan.h | 10 ++-- layers/param_checker.cpp | 7 --- loader/loader.c | 123 ++++++++++++++++++++++----------------- loader/loader.h | 2 + vk-generate.py | 4 +- vulkan.py | 7 +-- 10 files changed, 95 insertions(+), 76 deletions(-) diff --git a/demos/cube.c b/demos/cube.c index 13d2ff08..f046c02f 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -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); diff --git a/demos/tri.c b/demos/tri.c index 8918a2c3..a594cf9a 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -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); diff --git a/demos/vulkaninfo.c b/demos/vulkaninfo.c index 2966dfd1..4189e732 100644 --- a/demos/vulkaninfo.c +++ b/demos/vulkaninfo.c @@ -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); diff --git a/include/vkLayer.h b/include/vkLayer.h index 53460c73..e9e8b037 100644 --- a/include/vkLayer.h +++ b/include/vkLayer.h @@ -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; diff --git a/include/vulkan.h b/include/vulkan.h index d80c15a2..4e91b433 100644 --- a/include/vulkan.h +++ b/include/vulkan.h @@ -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, diff --git a/layers/param_checker.cpp b/layers/param_checker.cpp index fae24d1c..5408ee77 100644 --- a/layers/param_checker.cpp +++ b/layers/param_checker.cpp @@ -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; diff --git a/loader/loader.c b/loader/loader.c index 20646a7b..b71a39a5 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -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; } diff --git a/loader/loader.h b/loader/loader.h index b615989f..79d77c8d 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -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 */ diff --git a/vk-generate.py b/vk-generate.py index 120d7b4c..11476201 100755 --- a/vk-generate.py +++ b/vk-generate.py @@ -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": diff --git a/vulkan.py b/vulkan.py index 4c51bd4c..3e497044 100755 --- 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"), -- 2.34.1