aboutsummaryrefslogtreecommitdiff
path: root/layers/screenshot.cpp
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/screenshot.cpp
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/screenshot.cpp')
-rw-r--r--layers/screenshot.cpp69
1 files changed, 39 insertions, 30 deletions
diff --git a/layers/screenshot.cpp b/layers/screenshot.cpp
index 521aedc6..32312897 100644
--- a/layers/screenshot.cpp
+++ b/layers/screenshot.cpp
@@ -406,21 +406,36 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(
const VkAllocationCallbacks* pAllocator,
VkDevice *pDevice)
{
- VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, *pDevice);
- VkResult result = pDisp->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
-
- if (result == VK_SUCCESS) {
- init_screenshot();
- createDeviceRegisterExtensions(pCreateInfo, *pDevice);
- // Create a mapping from a device to a physicalDevice
- if (deviceMap[*pDevice] == NULL)
- {
- DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
- deviceMap[*pDevice] = deviceMapElem;
- }
- deviceMap[*pDevice]->physicalDevice = gpu;
+ 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;
+ }
+
+ initDeviceTable(*pDevice, fpGetDeviceProcAddr, screenshot_device_table_map);
+
+ init_screenshot();
+ createDeviceRegisterExtensions(pCreateInfo, *pDevice);
+ // Create a mapping from a device to a physicalDevice
+ if (deviceMap[*pDevice] == NULL)
+ {
+ DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
+ deviceMap[*pDevice] = deviceMapElem;
+ }
+ deviceMap[*pDevice]->physicalDevice = gpu;
+
return result;
}
@@ -743,17 +758,9 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(
VkDevice dev,
const char *funcName)
{
- if (dev == NULL) {
- return NULL;
- }
-
- /* loader uses this to force layer initialization; device object is wrapped */
if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
- initDeviceTable(screenshot_device_table_map, (const VkBaseLayerObject *) dev);
return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
}
- if (!strcmp(funcName, "vkCreateDevice"))
- return (PFN_vkVoidFunction) vkCreateDevice;
if (!strcmp(funcName, "vkGetDeviceQueue"))
return (PFN_vkVoidFunction) vkGetDeviceQueue;
@@ -761,6 +768,10 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(
if (!strcmp(funcName, "vkCreateCommandPool"))
return (PFN_vkVoidFunction) vkCreateCommandPool;
+ if (dev == NULL) {
+ return NULL;
+ }
+
VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, dev);
if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].wsi_enabled)
{
@@ -780,21 +791,19 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(
VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
{
- if (instance == VK_NULL_HANDLE) {
- return NULL;
- }
-
- /* loader uses this to force layer initialization; instance object is wrapped */
- if (!strcmp("vkGetInstanceProcAddr", funcName)) {
- initInstanceTable((const VkBaseLayerObject *) instance);
+ if (!strcmp("vkGetInstanceProcAddr", funcName))
return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
- }
-
+ if (!strcmp(funcName, "vkCreateDevice"))
+ return (PFN_vkVoidFunction) vkCreateDevice;
if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices;
if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
return (PFN_vkVoidFunction)vkEnumerateDeviceExtensionProperties;
+ if (instance == VK_NULL_HANDLE) {
+ return NULL;
+ }
+
VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);
if (pTable->GetInstanceProcAddr == NULL)
return NULL;