aboutsummaryrefslogtreecommitdiff
path: root/layers/unique_objects.h
diff options
context:
space:
mode:
authorCourtney Goeltzenleuchter <courtneygo@google.com>2016-01-08 12:18:43 -0700
committerJon Ashburn <jon@lunarg.com>2016-01-20 18:04:55 -0700
commita1de4b2dffb98222ca59f4a70c301d22bb4c089e (patch)
treeb5d9e5235b444d8995f2c122637280b8e32ef72d /layers/unique_objects.h
parente974568a65f7243dbc1eeb69d94174d0563c9d65 (diff)
downloadusermoji-a1de4b2dffb98222ca59f4a70c301d22bb4c089e.tar.xz
loader: implement new layer init method
New layer init method requires the construction of Link information for CreateInstance and CreateDevice that is accessible to layers via the CreateInfo.pNext pointer. The layer can then use the Get*ProcAddr from the Link structure to initialize their dispatch table if the call down the chain returns successfully. This removes the need to do special initialization work at Get*ProcAddr time. Layer Get*ProcAddr now return their internal function pointers regardless of the value of instance or device. Only need to have valid instance & device when looking up extensions or when passing the request down the chain. This mechanism allows us to remove object wrapping used by the loader previously. Also simplifies the dispatch table setup. Conflicts: layers/device_limits.cpp layers/draw_state.cpp loader/loader.c loader/trampoline.c
Diffstat (limited to 'layers/unique_objects.h')
-rw-r--r--layers/unique_objects.h48
1 files changed, 40 insertions, 8 deletions
diff --git a/layers/unique_objects.h b/layers/unique_objects.h
index 02e66990..8d344a05 100644
--- a/layers/unique_objects.h
+++ b/layers/unique_objects.h
@@ -141,13 +141,27 @@ explicit_CreateInstance(
const VkAllocationCallbacks *pAllocator,
VkInstance *pInstance)
{
+ VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
- VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(unique_objects_instance_table_map, *pInstance);
- VkResult result = pInstanceTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
+ assert(chain_info->u.pLayerInfo);
+ PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
+ PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
+ if (fpCreateInstance == NULL) {
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+ // Advance the link info for the next element on the chain
+ chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
- if (result == VK_SUCCESS) {
- createInstanceRegisterExtensions(pCreateInfo, *pInstance);
+ VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
+ if (result != VK_SUCCESS) {
+ return result;
}
+
+ initInstanceTable(*pInstance, fpGetInstanceProcAddr, unique_objects_instance_table_map);
+
+ createInstanceRegisterExtensions(pCreateInfo, *pInstance);
+
return result;
}
@@ -176,11 +190,29 @@ explicit_CreateDevice(
const VkAllocationCallbacks *pAllocator,
VkDevice *pDevice)
{
- VkLayerDispatchTable *pDeviceTable = get_dispatch_table(unique_objects_device_table_map, *pDevice);
- VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
- if (result == VK_SUCCESS) {
- createDeviceRegisterExtensions(pCreateInfo, *pDevice);
+ VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
+
+ 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");
+ if (fpCreateDevice == NULL) {
+ return VK_ERROR_INITIALIZATION_FAILED;
}
+
+ // Advance the link info for the next element on the chain
+ chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
+
+ VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
+ if (result != VK_SUCCESS) {
+ return result;
+ }
+
+ // Setup layer's device dispatch table
+ initDeviceTable(*pDevice, fpGetDeviceProcAddr, unique_objects_device_table_map);
+
+ createDeviceRegisterExtensions(pCreateInfo, *pDevice);
+
return result;
}