aboutsummaryrefslogtreecommitdiff
path: root/loader
diff options
context:
space:
mode:
authorCourtney Goeltzenleuchter <courtney@LunarG.com>2015-06-25 18:01:43 -0600
committerCourtney Goeltzenleuchter <courtney@LunarG.com>2015-06-29 11:45:16 -0600
commitcfa6643201d47ccb6ccc630d60ad4b1f4cdf0102 (patch)
tree1482269daa565a428ecffad7047f0e6b9dab1fa4 /loader
parent1f221b264ed51952fcecd34af0bfa405b0f27734 (diff)
downloadusermoji-cfa6643201d47ccb6ccc630d60ad4b1f4cdf0102.tar.xz
loader: Move CreateDevice to device table
Discovered an issue where a layer was doing cleanup in it's DestroyDevice function but the CreateDevice was never called. This happened because the extension was only enabled on the device chain and the device chain doesn't actually call CreateDevice. That happens on the Instance chain. Making it so that we can call down the device chain - which is terminated by the ICD. We need to know the real device object to construct the device chain heiarchy and when calling down the device chain it should end with the ICD doing the actual device object creation. This patch fixes the issue by using the same process as CreateInstance. The loader will call the ICD's CreateDevice and pass that in the *pDevice argument. The layers then ignore the PhysicalDevice parameter and use the *pDevice to access the device chain. To prevent the ICD from being called twice needed to stub in a special loader_GetDeviceChainProcAddr to provide a stub for only CreateDevice as the end of the chain. integrate review feedback.
Diffstat (limited to 'loader')
-rw-r--r--loader/loader.c120
-rw-r--r--loader/table_ops.h6
-rw-r--r--loader/trampoline.c14
3 files changed, 86 insertions, 54 deletions
diff --git a/loader/loader.c b/loader/loader.c
index 00b46d78..30a5101f 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -92,7 +92,6 @@ const VkLayerInstanceDispatchTable instance_disp = {
.GetPhysicalDeviceFeatures = loader_GetPhysicalDeviceFeatures,
.GetPhysicalDeviceFormatInfo = loader_GetPhysicalDeviceFormatInfo,
.GetPhysicalDeviceLimits = loader_GetPhysicalDeviceLimits,
- .CreateDevice = loader_CreateDevice,
.GetPhysicalDeviceProperties = loader_GetPhysicalDeviceProperties,
.GetPhysicalDevicePerformance = loader_GetPhysicalDevicePerformance,
.GetPhysicalDeviceQueueCount = loader_GetPhysicalDeviceQueueCount,
@@ -1440,12 +1439,37 @@ static void loader_enable_device_layers(
ext_list);
}
+static VkResult scratch_vkCreateDevice(
+ VkPhysicalDevice gpu,
+ const VkDeviceCreateInfo *pCreateInfo,
+ VkDevice *pDevice)
+{
+ return VK_SUCCESS;
+}
+
+static void * VKAPI loader_GetDeviceChainProcAddr(VkDevice device, const char * name)
+{
+ const VkLayerDispatchTable *disp_table = * (VkLayerDispatchTable **) device;
+
+ /* CreateDevice workaround: Make the terminator be a scratch function
+ * that does nothing since we have already called the ICD's create device.
+ * We can then call down the device chain and have all the layers get set up.
+ */
+ if (!strcmp(name, "vkGetDeviceProcAddr"))
+ return (void *) loader_GetDeviceChainProcAddr;
+ if (!strcmp(name, "vkCreateDevice"))
+ return (void *) scratch_vkCreateDevice;
+
+ return disp_table->GetDeviceProcAddr(device, name);
+}
+
static uint32_t loader_activate_device_layers(
- VkDevice device,
- struct loader_device *dev,
- struct loader_icd *icd,
- uint32_t ext_count,
- const VkExtensionProperties *ext_props)
+ VkPhysicalDevice gpu,
+ VkDevice device,
+ struct loader_device *dev,
+ struct loader_icd *icd,
+ uint32_t ext_count,
+ const VkExtensionProperties *ext_props)
{
if (!icd)
return 0;
@@ -1458,8 +1482,9 @@ static uint32_t loader_activate_device_layers(
VkObject nextObj = (VkObject) device;
VkObject baseObj = nextObj;
VkBaseLayerObject *nextGpuObj;
- PFN_vkGetDeviceProcAddr nextGPA = icd->GetDeviceProcAddr;
+ PFN_vkGetDeviceProcAddr nextGPA = loader_GetDeviceChainProcAddr;
VkBaseLayerObject *wrappedGpus;
+
/*
* Figure out how many actual layers will need to be wrapped.
*/
@@ -1482,6 +1507,7 @@ static uint32_t loader_activate_device_layers(
loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc Gpu objects for layer");
return 0;
}
+
for (int32_t i = dev->activated_layer_list.count - 1; i >= 0; i--) {
struct loader_extension_property *ext_prop = &dev->activated_layer_list.list[i];
@@ -1838,50 +1864,58 @@ VkResult loader_CreateDevice(
uint32_t gpu_index;
struct loader_icd *icd = loader_get_icd(gpu, &gpu_index);
struct loader_device *dev;
- VkResult res = VK_ERROR_INITIALIZATION_FAILED;
+ VkResult res;
- if (icd->CreateDevice) {
- res = icd->CreateDevice(gpu, pCreateInfo, pDevice);
- if (res != VK_SUCCESS) {
- return res;
- }
- dev = loader_add_logical_device(*pDevice, &icd->logical_device_list);
- if (dev == NULL) {
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
- PFN_vkGetDeviceProcAddr get_proc_addr = icd->GetDeviceProcAddr;
- loader_init_device_dispatch_table(&dev->loader_dispatch, get_proc_addr,
- icd->gpus[gpu_index], icd->gpus[gpu_index]);
+ if (!icd->CreateDevice) {
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
- loader_init_dispatch(*pDevice, &dev->loader_dispatch);
+ res = icd->CreateDevice(gpu, pCreateInfo, pDevice);
+ if (res != VK_SUCCESS) {
+ return res;
+ }
- dev->app_extension_count = pCreateInfo->extensionCount;
- dev->app_extension_props = (VkExtensionProperties *) malloc(sizeof(VkExtensionProperties) * pCreateInfo->extensionCount);
- if (dev->app_extension_props == NULL && (dev->app_extension_count > 0)) {
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
+ dev = loader_add_logical_device(*pDevice, &icd->logical_device_list);
+ if (dev == NULL) {
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
+ }
+ PFN_vkGetDeviceProcAddr get_proc_addr = icd->GetDeviceProcAddr;
+ loader_init_device_dispatch_table(&dev->loader_dispatch, get_proc_addr,
+ icd->gpus[gpu_index], icd->gpus[gpu_index]);
- /* Make local copy of extension list */
- if (dev->app_extension_count > 0 && dev->app_extension_props != NULL) {
- memcpy(dev->app_extension_props, pCreateInfo->pEnabledExtensions, sizeof(VkExtensionProperties) * pCreateInfo->extensionCount);
- }
+ dev->loader_dispatch.CreateDevice = scratch_vkCreateDevice;
+ loader_init_dispatch(*pDevice, &dev->loader_dispatch);
- /*
- * Put together the complete list of extensions to enable
- * This includes extensions requested via environment variables.
- */
- loader_enable_device_layers(dev, &icd->device_extension_cache[gpu_index]);
+ dev->app_extension_count = pCreateInfo->extensionCount;
+ dev->app_extension_props = (VkExtensionProperties *) malloc(sizeof(VkExtensionProperties) * pCreateInfo->extensionCount);
+ if (dev->app_extension_props == NULL && (dev->app_extension_count > 0)) {
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
+ }
- /*
- * Load the libraries needed by the extensions on the
- * enabled extension list. This will build the device chain
- * terminating with the selected device.
- */
- loader_activate_device_layers(*pDevice, dev, icd,
- dev->app_extension_count,
- dev->app_extension_props);
+ /* Make local copy of extension list */
+ if (dev->app_extension_count > 0 && dev->app_extension_props != NULL) {
+ memcpy(dev->app_extension_props, pCreateInfo->pEnabledExtensions, sizeof(VkExtensionProperties) * pCreateInfo->extensionCount);
}
+ /*
+ * Put together the complete list of extensions to enable
+ * This includes extensions requested via environment variables.
+ */
+ loader_enable_device_layers(dev, &icd->device_extension_cache[gpu_index]);
+
+ /*
+ * Load the libraries needed by the extensions on the
+ * enabled extension list. This will build the device chain
+ * terminating with the selected device.
+ */
+ loader_activate_device_layers(gpu, *pDevice, dev, icd,
+ dev->app_extension_count,
+ dev->app_extension_props);
+
+ res = dev->loader_dispatch.CreateDevice(gpu, pCreateInfo, pDevice);
+
+ dev->loader_dispatch.CreateDevice = icd->CreateDevice;
+
return res;
}
diff --git a/loader/table_ops.h b/loader/table_ops.h
index 6d159507..1bfb6328 100644
--- a/loader/table_ops.h
+++ b/loader/table_ops.h
@@ -37,6 +37,7 @@ static inline void loader_init_device_dispatch_table(VkLayerDispatchTable *table
//then use the gpa in their dispatch for subsequent layers in the chain
table->GetDeviceProcAddr = (PFN_vkGetDeviceProcAddr) gpa(dev_next, "vkGetDeviceProcAddr");
+ table->CreateDevice = (PFN_vkCreateDevice) gpa(dev, "vkCreateDevice");
table->DestroyDevice = (PFN_vkDestroyDevice) gpa(dev, "vkDestroyDevice");
table->GetDeviceQueue = (PFN_vkGetDeviceQueue) gpa(dev, "vkGetDeviceQueue");
table->QueueSubmit = (PFN_vkQueueSubmit) gpa(dev, "vkQueueSubmit");
@@ -151,6 +152,8 @@ static inline void *loader_lookup_device_dispatch_table(
name += 2;
if (!strcmp(name, "GetDeviceProcAddr"))
return (void *) table->GetDeviceProcAddr;
+ if (!strcmp(name, "CreateDevice"))
+ return (void *) table->CreateDevice;
if (!strcmp(name, "DestroyDevice"))
return (void *) table->DestroyDevice;
if (!strcmp(name, "GetDeviceQueue"))
@@ -360,7 +363,6 @@ static inline void loader_init_instance_core_dispatch_table(VkLayerInstanceDispa
table->GetPhysicalDeviceFeatures = (PFN_vkGetPhysicalDeviceFeatures) gpa(inst, "vkGetPhysicalDeviceFeatures");
table->GetPhysicalDeviceFormatInfo = (PFN_vkGetPhysicalDeviceFormatInfo) gpa(inst, "vkGetPhysicalDeviceFormatInfo");
table->GetPhysicalDeviceLimits = (PFN_vkGetPhysicalDeviceLimits) gpa(inst, "vkGetPhysicalDeviceLimits");
- table->CreateDevice = (PFN_vkCreateDevice) gpa(inst, "vkCreateDevice");
table->GetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties) gpa(inst, "vkGetPhysicalDeviceProperties");
table->GetPhysicalDevicePerformance = (PFN_vkGetPhysicalDevicePerformance) gpa(inst, "vkGetPhysicalDevicePerformance");
table->GetPhysicalDeviceQueueCount = (PFN_vkGetPhysicalDeviceQueueCount) gpa(inst, "vkGetPhysicalDeviceQueueCount");
@@ -411,8 +413,6 @@ static inline void *loader_lookup_instance_dispatch_table(
return (void *) table->GetPhysicalDeviceMemoryProperties;
if (!strcmp(name, "GetInstanceProcAddr"))
return (void *) table->GetInstanceProcAddr;
- if (!strcmp(name, "CreateDevice"))
- return (void *) table->CreateDevice;
if (!strcmp(name, "GetPhysicalDeviceExtensionCount"))
return (void *) table->GetPhysicalDeviceExtensionCount;
if (!strcmp(name, "GetPhysicalDeviceExtensionProperties"))
diff --git a/loader/trampoline.c b/loader/trampoline.c
index ec363732..d6a09ef9 100644
--- a/loader/trampoline.c
+++ b/loader/trampoline.c
@@ -277,18 +277,16 @@ LOADER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLimits(
}
LOADER_EXPORT VkResult VKAPI vkCreateDevice(
- VkPhysicalDevice gpu,
- const VkDeviceCreateInfo* pCreateInfo,
- VkDevice* pDevice)
+ VkPhysicalDevice gpu,
+ const VkDeviceCreateInfo* pCreateInfo,
+ VkDevice* pDevice)
{
- const VkLayerInstanceDispatchTable *disp;
VkResult res;
- disp = loader_get_instance_dispatch(gpu);
-
loader_platform_thread_lock_mutex(&loader_lock);
- // CreateDevice is dispatched on the instance chain
- res = disp->CreateDevice(gpu, pCreateInfo, pDevice);
+
+ res = loader_CreateDevice(gpu, pCreateInfo, pDevice);
+
loader_platform_thread_unlock_mutex(&loader_lock);
return res;
}