device_limits: avoid invalid GIPA call in vkCreateDevice
authorChia-I Wu <olvaffe@gmail.com>
Thu, 28 Apr 2016 08:04:15 +0000 (16:04 +0800)
committerTobin Ehlis <tobine@google.com>
Thu, 5 May 2016 12:42:19 +0000 (06:42 -0600)
Save VkInstance in layer_data so that we query vkCreateDevice with a valid
instance.

layers/device_limits.cpp

index e97c54a..8aa538e 100644 (file)
@@ -49,6 +49,8 @@ namespace device_limits {
 
 // This struct will be stored in a map hashed by the dispatchable object
 struct layer_data {
+    VkInstance instance;
+
     debug_report_data *report_data;
     std::vector<VkDebugReportCallbackEXT> logging_callback;
     VkLayerDispatchTable *device_dispatch_table;
@@ -116,6 +118,7 @@ CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallba
         return result;
 
     layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
+    my_data->instance = *pInstance;
     my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
     layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
 
@@ -403,7 +406,7 @@ CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
     assert(chain_info->u.pLayerInfo);
     PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
     PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
-    PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
+    PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(phy_dev_data->instance, "vkCreateDevice");
     if (fpCreateDevice == NULL) {
         return VK_ERROR_INITIALIZATION_FAILED;
     }