loader: ghlvl 116 Fix CreateDevice to use the proper ICDs PhysDev
authorJon Ashburn <jon@lunarg.com>
Thu, 24 Mar 2016 21:49:57 +0000 (15:49 -0600)
committerJon Ashburn <jon@lunarg.com>
Thu, 24 Mar 2016 22:12:07 +0000 (16:12 -0600)
This is needed for querying extensoins from the ICD.

Change-Id: I5655d33d15bf0ea6de506f81821a30dd81ca3d5a

loader/loader.c
loader/loader.h
loader/trampoline.c

index 426b1a1..c2cb0c5 100644 (file)
@@ -1181,8 +1181,6 @@ static void loader_icd_destroy(struct loader_instance *ptr_inst,
         dev = next_dev;
     }
 
-    if (icd->phys_devs != NULL)
-        loader_heap_free(ptr_inst, icd->phys_devs);
     loader_heap_free(ptr_inst, icd);
 }
 
@@ -3342,7 +3340,7 @@ loader_enable_device_layers(const struct loader_instance *inst,
     return err;
 }
 
-VkResult loader_create_device_chain(const struct loader_physical_device *pd,
+VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd,
                                     const VkDeviceCreateInfo *pCreateInfo,
                                     const VkAllocationCallbacks *pAllocator,
                                     const struct loader_instance *inst,
@@ -3556,7 +3554,7 @@ VkResult loader_validate_instance_extensions(
 }
 
 VkResult loader_validate_device_extensions(
-    struct loader_physical_device *phys_dev,
+    struct loader_physical_device_tramp *phys_dev,
     const struct loader_layer_list *activated_device_layers,
     const struct loader_extension_list *icd_exts,
     const VkDeviceCreateInfo *pCreateInfo) {
@@ -3936,19 +3934,11 @@ terminator_EnumeratePhysicalDevices(VkInstance instance,
         return VK_ERROR_OUT_OF_HOST_MEMORY;
 
     for (i = 0; idx < copy_count && i < inst->total_icd_count; i++) {
-        icd = phys_devs[i].this_icd;
-        if (icd->phys_devs != NULL) {
-            loader_heap_free(inst, icd->phys_devs);
-        }
-        icd->phys_devs = loader_heap_alloc(inst,
-                              sizeof(VkPhysicalDevice) * phys_devs[i].count,
-                              VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 
         for (j = 0; j < phys_devs[i].count && idx < copy_count; j++) {
             loader_set_dispatch((void *)&inst->phys_devs_term[idx], inst->disp);
             inst->phys_devs_term[idx].this_icd = phys_devs[i].this_icd;
             inst->phys_devs_term[idx].phys_dev = phys_devs[i].phys_devs[j];
-            icd->phys_devs[j] = phys_devs[i].phys_devs[j];
             pPhysicalDevices[idx] =
                 (VkPhysicalDevice)&inst->phys_devs_term[idx];
             idx++;
index b0b3663..cae78cc 100644 (file)
@@ -199,7 +199,6 @@ struct loader_icd {
     // pointers to find other structs
     const struct loader_scanned_icds *this_icd_lib;
     const struct loader_instance *this_instance;
-    VkPhysicalDevice *phys_devs;  // physicalDevice object from icd
     struct loader_device *logical_device_list;
     VkInstance instance; // instance object from the icd
     PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
@@ -276,7 +275,7 @@ struct loader_instance {
 
     uint32_t total_gpu_count; // count of the next two arrays
     struct loader_physical_device *phys_devs_term;
-    struct loader_physical_device *phys_devs; // tramp wrapped physDev obj list
+    struct loader_physical_device_tramp *phys_devs; // tramp wrapped physDev obj list
     uint32_t total_icd_count;
     struct loader_icd *icds;
     struct loader_instance *next;
@@ -335,10 +334,18 @@ struct loader_instance {
 
 /* per enumerated PhysicalDevice structure, used to wrap in trampoline code and
    also same structure used to wrap in terminator code */
+struct loader_physical_device_tramp {
+    VkLayerInstanceDispatchTable *disp; // must be first entry in structure
+    struct loader_icd *this_icd;
+    VkPhysicalDevice phys_dev;      // object from layers/loader terminator
+    VkPhysicalDevice icd_phys_dev;  // object from icd
+};
+
+/* per enumerated PhysicalDevice structure, used to wrap in terminator code */
 struct loader_physical_device {
     VkLayerInstanceDispatchTable *disp; // must be first entry in structure
     struct loader_icd *this_icd;
-    VkPhysicalDevice phys_dev; // object from ICD/layers/loader terminator
+    VkPhysicalDevice phys_dev; // object from ICD
 };
 
 struct loader_struct {
@@ -527,14 +534,14 @@ loader_enable_device_layers(const struct loader_instance *inst,
                             const VkDeviceCreateInfo *pCreateInfo,
                             const struct loader_layer_list *device_layers);
 
-VkResult loader_create_device_chain(const struct loader_physical_device *pd,
+VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd,
                                     const VkDeviceCreateInfo *pCreateInfo,
                                     const VkAllocationCallbacks *pAllocator,
                                     const struct loader_instance *inst,
                                     struct loader_icd *icd,
                                     struct loader_device *dev);
 VkResult loader_validate_device_extensions(
-    struct loader_physical_device *phys_dev,
+    struct loader_physical_device_tramp *phys_dev,
     const struct loader_layer_list *activated_device_layers,
     const struct loader_extension_list *icd_exts,
     const VkDeviceCreateInfo *pCreateInfo);
index a26d8c5..41119e9 100644 (file)
@@ -491,8 +491,8 @@ vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
     if (inst->phys_devs)
         loader_heap_free(inst, inst->phys_devs);
     count = inst->total_gpu_count;
-    inst->phys_devs = (struct loader_physical_device *)loader_heap_alloc(
-        inst, count * sizeof(struct loader_physical_device),
+    inst->phys_devs = (struct loader_physical_device_tramp *)loader_heap_alloc(
+        inst, count * sizeof(struct loader_physical_device_tramp),
         VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
     if (!inst->phys_devs) {
         loader_platform_thread_unlock_mutex(&loader_lock);
@@ -505,6 +505,7 @@ vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
         loader_set_dispatch((void *)&inst->phys_devs[i], inst->disp);
         inst->phys_devs[i].this_icd = inst->phys_devs_term[i].this_icd;
         inst->phys_devs[i].phys_dev = pPhysicalDevices[i];
+        inst->phys_devs[i].icd_phys_dev = inst->phys_devs_term[i].phys_dev;
 
         // copy wrapped object into Application provided array
         pPhysicalDevices[i] = (VkPhysicalDevice)&inst->phys_devs[i];
@@ -586,7 +587,7 @@ vkCreateDevice(VkPhysicalDevice physicalDevice,
                const VkDeviceCreateInfo *pCreateInfo,
                const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
     VkResult res;
-    struct loader_physical_device *phys_dev;
+    struct loader_physical_device_tramp *phys_dev;
     struct loader_icd *icd;
     struct loader_device *dev;
     struct loader_instance *inst;
@@ -596,7 +597,7 @@ vkCreateDevice(VkPhysicalDevice physicalDevice,
 
     loader_platform_thread_lock_mutex(&loader_lock);
 
-    phys_dev = (struct loader_physical_device *)physicalDevice;
+    phys_dev = (struct loader_physical_device_tramp *)physicalDevice;
     icd = phys_dev->this_icd;
     if (!icd) {
         loader_platform_thread_unlock_mutex(&loader_lock);
@@ -629,9 +630,8 @@ vkCreateDevice(VkPhysicalDevice physicalDevice,
         return VK_ERROR_OUT_OF_HOST_MEMORY;
     }
 
-    //TODO handle more than one phys dev per icd (icd->phys_devs[0])
     res = loader_add_device_extensions(
-        inst, icd, icd->phys_devs[0],
+        inst, icd, phys_dev->icd_phys_dev,
         phys_dev->this_icd->this_icd_lib->lib_name, &icd_exts);
     if (res != VK_SUCCESS) {
         loader_platform_thread_unlock_mutex(&loader_lock);
@@ -763,8 +763,8 @@ vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
                                      uint32_t *pPropertyCount,
                                      VkExtensionProperties *pProperties) {
     VkResult res = VK_SUCCESS;
-    struct loader_physical_device *phys_dev;
-    phys_dev = (struct loader_physical_device *)physicalDevice;
+    struct loader_physical_device_tramp *phys_dev;
+    phys_dev = (struct loader_physical_device_tramp *)physicalDevice;
 
     loader_platform_thread_lock_mutex(&loader_lock);
 
@@ -830,14 +830,14 @@ vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
                                  uint32_t *pPropertyCount,
                                  VkLayerProperties *pProperties) {
     uint32_t copy_size;
-    struct loader_physical_device *phys_dev;
+    struct loader_physical_device_tramp *phys_dev;
 
     loader_platform_thread_lock_mutex(&loader_lock);
 
     /* Don't dispatch this call down the instance chain, want all device layers
        enumerated and instance chain may not contain all device layers */
 
-    phys_dev = (struct loader_physical_device *)physicalDevice;
+    phys_dev = (struct loader_physical_device_tramp *)physicalDevice;
     const struct loader_instance *inst = phys_dev->this_icd->this_instance;
     uint32_t count = inst->device_layer_list.count;