diff options
| author | Jon Ashburn <jon@lunarg.com> | 2015-05-15 15:09:35 -0600 |
|---|---|---|
| committer | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-06-17 19:47:02 -0600 |
| commit | eddcf1d2462c477f2b1004333adb459d0c2554ce (patch) | |
| tree | 9ab140682db7e8f54271de28d401915c28bbe2e6 | |
| parent | d8107d14e2619740c5ca276ce8fe06cf584b2d9b (diff) | |
| download | usermoji-eddcf1d2462c477f2b1004333adb459d0c2554ce.tar.xz | |
misc: Loader and Layers move device chain activation to CreateDevice
| -rw-r--r-- | include/vkLayer.h | 17 | ||||
| -rw-r--r-- | layers/basic.cpp | 38 | ||||
| -rwxr-xr-x | layers/draw_state.cpp | 4 | ||||
| -rw-r--r-- | layers/mem_tracker.cpp | 4 | ||||
| -rw-r--r-- | layers/multi.cpp | 62 | ||||
| -rw-r--r-- | layers/param_checker.cpp | 12 | ||||
| -rw-r--r-- | layers/shader_checker.cpp | 19 | ||||
| -rw-r--r-- | loader/loader.c | 166 | ||||
| -rw-r--r-- | loader/loader.h | 66 | ||||
| -rw-r--r-- | loader/table_ops.h | 44 | ||||
| -rw-r--r-- | loader/trampoline.c | 53 | ||||
| -rwxr-xr-x | vk-generate.py | 4 | ||||
| -rwxr-xr-x | vk-layer-generate.py | 16 |
13 files changed, 307 insertions, 198 deletions
diff --git a/include/vkLayer.h b/include/vkLayer.h index 021cf3de..9edf3266 100644 --- a/include/vkLayer.h +++ b/include/vkLayer.h @@ -26,17 +26,8 @@ typedef struct VkBaseLayerObject_ typedef struct VkLayerDispatchTable_ { - PFN_vkGetInstanceProcAddr GetInstanceProcAddr; PFN_vkGetProcAddr GetProcAddr; - PFN_vkCreateInstance CreateInstance; - PFN_vkDestroyInstance DestroyInstance; - PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; - PFN_vkGetPhysicalDeviceInfo GetPhysicalDeviceInfo; - PFN_vkCreateDevice CreateDevice; PFN_vkDestroyDevice DestroyDevice; - PFN_vkGetGlobalExtensionInfo GetGlobalExtensionInfo; - PFN_vkGetPhysicalDeviceExtensionInfo GetPhysicalDeviceExtensionInfo; - PFN_vkEnumerateLayers EnumerateLayers; PFN_vkGetDeviceQueue GetDeviceQueue; PFN_vkQueueSubmit QueueSubmit; PFN_vkQueueWaitIdle QueueWaitIdle; @@ -49,7 +40,6 @@ typedef struct VkLayerDispatchTable_ PFN_vkFlushMappedMemoryRanges FlushMappedMemoryRanges; PFN_vkInvalidateMappedMemoryRanges InvalidateMappedMemoryRanges; PFN_vkPinSystemMemory PinSystemMemory; - PFN_vkGetMultiDeviceCompatibility GetMultiDeviceCompatibility; PFN_vkOpenSharedMemory OpenSharedMemory; PFN_vkOpenSharedSemaphore OpenSharedSemaphore; PFN_vkOpenPeerMemory OpenPeerMemory; @@ -141,15 +131,11 @@ typedef struct VkLayerDispatchTable_ PFN_vkCmdBeginRenderPass CmdBeginRenderPass; PFN_vkCmdEndRenderPass CmdEndRenderPass; PFN_vkDbgSetValidationLevel DbgSetValidationLevel; - PFN_vkDbgRegisterMsgCallback DbgRegisterMsgCallback; - PFN_vkDbgUnregisterMsgCallback DbgUnregisterMsgCallback; PFN_vkDbgSetMessageFilter DbgSetMessageFilter; PFN_vkDbgSetObjectTag DbgSetObjectTag; - PFN_vkDbgSetGlobalOption DbgSetGlobalOption; PFN_vkDbgSetDeviceOption DbgSetDeviceOption; PFN_vkCmdDbgMarkerBegin CmdDbgMarkerBegin; PFN_vkCmdDbgMarkerEnd CmdDbgMarkerEnd; - PFN_vkGetDisplayInfoWSI GetDisplayInfoWSI; PFN_vkCreateSwapChainWSI CreateSwapChainWSI; PFN_vkDestroySwapChainWSI DestroySwapChainWSI; PFN_vkGetSwapChainInfoWSI GetSwapChainInfoWSI; @@ -159,7 +145,7 @@ typedef struct VkLayerDispatchTable_ typedef struct VkLayerInstanceDispatchTable_ { PFN_vkGetInstanceProcAddr GetInstanceProcAddr; - PFN_vkGetProcAddr GetProcAddr; + PFN_vkGetProcAddr GetProcAddr; // TODO remove once GPA takes device parameter PFN_vkCreateInstance CreateInstance; PFN_vkDestroyInstance DestroyInstance; PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; @@ -172,6 +158,7 @@ typedef struct VkLayerInstanceDispatchTable_ PFN_vkDbgRegisterMsgCallback DbgRegisterMsgCallback; PFN_vkDbgUnregisterMsgCallback DbgUnregisterMsgCallback; PFN_vkDbgSetGlobalOption DbgSetGlobalOption; + PFN_vkGetDisplayInfoWSI GetDisplayInfoWSI; } VkLayerInstanceDispatchTable; // LL node for tree of dbg callback functions diff --git a/layers/basic.cpp b/layers/basic.cpp index 9f43c6d7..ed35fe01 100644 --- a/layers/basic.cpp +++ b/layers/basic.cpp @@ -133,17 +133,37 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( return VK_SUCCESS; } +VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices( + VkInstance instance, + uint32_t* pPhysicalDeviceCount, + VkPhysicalDevice* pPhysicalDevices) +{ + /* Need to intercept this entrypoint to add the physDev objects to instance map */ + VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[instance]; + printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance); + VkResult result = pInstTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); + if (pPhysicalDevices) + { + // create a mapping for the objects into the dispatch table + for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) + { + tableInstanceMap.emplace(*(pPhysicalDevices + i), pInstTable); + } + } + printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount); + return result; +} + VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkLayerDispatchTable* pTable = tableMap[gpu]; + VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[gpu]; printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu); - VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); - // create a mapping for the device object into the dispatch table - tableMap.emplace(*pDevice, pTable); + VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice); printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice); return result; } + VK_LAYER_EXPORT VkResult VKAPI vkGetFormatInfo(VkDevice device, VkFormat format, VkFormatInfoType infoType, size_t* pDataSize, void* pData) { VkLayerDispatchTable* pTable = tableMap[device]; @@ -158,7 +178,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t ma { if (gpu != NULL) { - VkLayerDispatchTable* pTable = initLayerTable((const VkBaseLayerObject *) gpu); + VkLayerInstanceDispatchTable* pTable = initLayerInstanceTable((const VkBaseLayerObject *) gpu); printf("At start of wrapped vkEnumerateLayers() call w/ gpu: %p\n", gpu); VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); @@ -198,7 +218,9 @@ VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pNa return (void *) vkGetProcAddr; if (!strcmp("vkCreateDevice", pName)) return (void *) vkCreateDevice; - if (!strcmp("GetGlobalExtensionInfo", pName)) + if (!strcmp("vkEnumeratePhysicalDevices", pName)) + return (void*) vkEnumeratePhysicalDevices; + if (!strcmp("vkGetGlobalExtensionInfo", pName)) return (void*) vkGetGlobalExtensionInfo; if (!strcmp("vkEnumerateLayers", pName)) return (void *) vkEnumerateLayers; @@ -225,7 +247,9 @@ VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const ch return (void *) vkGetInstanceProcAddr; if (!strcmp("vkGetProcAddr", pName)) return (void *) vkGetProcAddr; - if (!strcmp("GetGlobalExtensionInfo", pName)) + if (!strcmp("vkEnumeratePhysicalDevices", pName)) + return (void*) vkEnumeratePhysicalDevices; + if (!strcmp("vkGetGlobalExtensionInfo", pName)) return (void*) vkGetGlobalExtensionInfo; if (!strcmp("vkCreateDevice", pName)) return (void *) vkCreateDevice; diff --git a/layers/draw_state.cpp b/layers/draw_state.cpp index 09bb3ee2..e8039402 100755 --- a/layers/draw_state.cpp +++ b/layers/draw_state.cpp @@ -1491,7 +1491,7 @@ static void initDrawState(void) VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice); + VkResult result = nextInstanceTable.CreateDevice(gpu, pCreateInfo, pDevice); return result; } @@ -1572,7 +1572,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t ma { pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&g_initOnce, initDrawState); - VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); + VkResult result = nextInstanceTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); return result; } else { if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL) diff --git a/layers/mem_tracker.cpp b/layers/mem_tracker.cpp index ced65d42..5ab3bca5 100644 --- a/layers/mem_tracker.cpp +++ b/layers/mem_tracker.cpp @@ -828,7 +828,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice( const VkDeviceCreateInfo *pCreateInfo, VkDevice *pDevice) { - VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice); + VkResult result = nextInstanceTable.CreateDevice(gpu, pCreateInfo, pDevice); // Save off device in case we need it to create Fences globalDevice = *pDevice; return result; @@ -937,7 +937,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers( pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&g_initOnce, initMemTracker); loader_platform_thread_once(&g_tabDeviceOnce, initDeviceTable); - VkResult result = nextTable.EnumerateLayers(gpu, + VkResult result = nextInstanceTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); return result; } else diff --git a/layers/multi.cpp b/layers/multi.cpp index 97326545..605a6420 100644 --- a/layers/multi.cpp +++ b/layers/multi.cpp @@ -80,16 +80,13 @@ static VkLayerInstanceDispatchTable * getLayer1InstanceTable(const VkBaseLayerOb extern "C" { #endif - -VK_LAYER_EXPORT VkResult VKAPI multi1CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, - VkDevice* pDevice) +VK_LAYER_EXPORT VkResult VKAPI multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler) { - VkLayerDispatchTable* pTable = tableMap1[gpu]; - printf("At start of multi1 layer vkCreateDevice()\n"); - VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); - // create a mapping for the device object into the dispatch table - tableMap1.emplace(*pDevice, pTable); - printf("Completed multi1 layer vkCreateDevice()\n"); + VkLayerDispatchTable* pTable = tableMap1[device]; + + printf("At start of multi1 layer vkCreateSampler()\n"); + VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler); + printf("Completed multi1 layer vkCreateSampler()\n"); return result; } @@ -123,7 +120,7 @@ VK_LAYER_EXPORT VkResult VKAPI multi1EnumerateLayers(VkPhysicalDevice gpu, size_ if (gpu == NULL) return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); - VkLayerDispatchTable* pTable = tableMap1[gpu]; + VkLayerInstanceDispatchTable* pTable = tableInstanceMap1[gpu]; printf("At start of multi1 layer vkEnumerateLayers()\n"); VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); printf("Completed multi1 layer vkEnumerateLayers()\n"); @@ -139,9 +136,9 @@ VK_LAYER_EXPORT void * VKAPI multi1GetProcAddr(VkPhysicalDevice gpu, const char* getLayer1Table(gpuw); - if (!strcmp("vkCreateDevice", pName)) - return (void *) multi1CreateDevice; - else if (!strcmp("vkEnumerateLayers", pName)) + if (!strcmp("vkCreateSampler", pName)) + return (void *) multi1CreateSampler; + if (!strcmp("vkEnumerateLayers", pName)) return (void *) multi1EnumerateLayers; else if (!strcmp("GetGlobalExtensionInfo", pName)) return (void*) vkGetGlobalExtensionInfo; @@ -165,9 +162,9 @@ VK_LAYER_EXPORT void * VKAPI multi1GetInstanceProcAddr(VkInstance inst, const ch getLayer1InstanceTable(instw); - if (!strcmp("vkCreateDevice", pName)) - return (void *) multi1CreateDevice; - else if (!strcmp("vkEnumerateLayers", pName)) + if (!strcmp("vkCreateSampler", pName)) + return (void *) multi1CreateSampler; + if (!strcmp("vkEnumerateLayers", pName)) return (void *) multi1EnumerateLayers; else if (!strcmp("GetGlobalExtensionInfo", pName)) return (void*) vkGetGlobalExtensionInfo; @@ -219,15 +216,34 @@ static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw) } } +VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices( + VkInstance instance, + uint32_t* pPhysicalDeviceCount, + VkPhysicalDevice* pPhysicalDevices) +{ + /* Need to intercept this entrypoint to add the physDev objects to instance map */ + VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap2[instance]; + printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); + VkResult result = pInstTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); + if (pPhysicalDevices) + { + // create a mapping for the objects into the dispatch table + for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) + { + tableInstanceMap2.emplace(*(pPhysicalDevices + i), pInstTable); + } + } + printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); + return result; +} + VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkLayerDispatchTable* pTable = tableMap2[gpu]; + VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap2[gpu]; printf("At start of multi2 vkCreateDevice()\n"); - VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); - // create a mapping for the device object into the dispatch table for layer2 - tableMap2.emplace(*pDevice, pTable); + VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice); printf("Completed multi2 layer vkCreateDevice()\n"); return result; } @@ -263,7 +279,7 @@ VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalDevice gpu, size_ if (gpu == NULL) return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); - VkLayerDispatchTable* pTable = tableMap2[gpu]; + VkLayerInstanceDispatchTable* pTable = tableInstanceMap2[gpu]; printf("At start of multi2 layer vkEnumerateLayers()\n"); VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); @@ -280,6 +296,8 @@ VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalDevice gpu, const char* getLayer2Table(gpuw); + if (!strcmp("vkEnumeratePhysicalDevices", pName)) + return (void *) multi2EnumeratePhysicalDevices; if (!strcmp("vkCreateDevice", pName)) return (void *) multi2CreateDevice; else if (!strcmp("vkEnumerateLayers", pName)) @@ -306,6 +324,8 @@ VK_LAYER_EXPORT void * VKAPI multi2GetInstanceProcAddr(VkInstance inst, const ch getLayer2InstanceTable(instw); + if (!strcmp("vkEnumeratePhysicalDevices", pName)) + return (void *) multi2EnumeratePhysicalDevices; if (!strcmp("vkCreateDevice", pName)) return (void *) multi2CreateDevice; else if (!strcmp("vkEnumerateLayers", pName)) diff --git a/layers/param_checker.cpp b/layers/param_checker.cpp index cf33f1f5..434f87d2 100644 --- a/layers/param_checker.cpp +++ b/layers/param_checker.cpp @@ -162,7 +162,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceInfo(VkPhysicalDevice gpu, VkP sprintf(str, "Parameter infoType to function GetPhysicalDeviceInfo has invalid value of %i.", (int)infoType); layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str); } - VkResult result = nextTable.GetPhysicalDeviceInfo(gpu, infoType, pDataSize, pData); + VkResult result = nextInstanceTable.GetPhysicalDeviceInfo(gpu, infoType, pDataSize, pData); return result; } @@ -243,7 +243,7 @@ void PostCreateDevice(VkResult result, VkDevice* pDevice) VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { PreCreateDevice(gpu, pCreateInfo); - VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice); + VkResult result = nextInstanceTable.CreateDevice(gpu, pCreateInfo, pDevice); PostCreateDevice(result, pDevice); return result; } @@ -314,7 +314,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionInfo( size_t* pDataSize, void* pData) { - VkResult result = nextTable.GetPhysicalDeviceExtensionInfo(gpu, infoType, extensionIndex, pDataSize, pData); + VkResult result = nextInstanceTable.GetPhysicalDeviceExtensionInfo(gpu, infoType, extensionIndex, pDataSize, pData); return result; } @@ -327,7 +327,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t ma pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&initOnce, initParamChecker); loader_platform_thread_once(&tabDeviceOnce, initDeviceTable); - VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); + VkResult result = nextInstanceTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); sprintf(str, "Completed layered EnumerateLayers\n"); layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, nullptr, 0, 0, "PARAMCHECK", str); fflush(stdout); @@ -445,7 +445,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pS VK_LAYER_EXPORT VkResult VKAPI vkGetMultiDeviceCompatibility(VkPhysicalDevice gpu0, VkPhysicalDevice gpu1, VkPhysicalDeviceCompatibilityInfo* pInfo) { - VkResult result = nextTable.GetMultiDeviceCompatibility(gpu0, gpu1, pInfo); + VkResult result = nextInstanceTable.GetMultiDeviceCompatibility(gpu0, gpu1, pInfo); return result; } @@ -1936,7 +1936,7 @@ VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer) VK_LAYER_EXPORT VkResult VKAPI vkGetDisplayInfoWSI(VkDisplayWSI display, VkDisplayInfoTypeWSI infoType, size_t* pDataSize, void* pData) { - VkResult result = nextTable.GetDisplayInfoWSI(display, infoType, pDataSize, pData); + VkResult result = nextInstanceTable.GetDisplayInfoWSI(display, infoType, pDataSize, pData); return result; } diff --git a/layers/shader_checker.cpp b/layers/shader_checker.cpp index 8de92399..b1b2cf8e 100644 --- a/layers/shader_checker.cpp +++ b/layers/shader_checker.cpp @@ -185,19 +185,6 @@ static VkLayerInstanceDispatchTable * initLayerInstanceTable(const VkBaseLayerOb return pTable; } -VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) -{ - VkLayerDispatchTable* pTable = tableMap[gpu]; - VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); - - loader_platform_thread_once(&g_initOnce, initLayer); - // create a mapping for the device object into the dispatch table - tableMap.emplace(*pDevice, pTable); - pCurObj = (VkBaseLayerObject *) *pDevice; - return result; -} - - VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice physicalDevice, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved) { if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL) @@ -978,7 +965,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback( g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK; } // NOT CORRECT WITH MULTIPLE DEVICES OR INSTANCES, BUT THIS IS ALL GOING AWAY SOON ANYWAY - VkLayerDispatchTable *pTable = tableMap[pCurObj]; + VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pCurObj]; VkResult result = pTable->DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData); return result; } @@ -1009,7 +996,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback( } } // NOT CORRECT WITH MULTIPLE DEVICES OR INSTANCES, BUT THIS IS ALL GOING AWAY SOON ANYWAY - VkLayerDispatchTable *pTable = tableMap[pCurObj]; + VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pCurObj]; VkResult result = pTable->DbgUnregisterMsgCallback(instance, pfnMsgCallback); return result; } @@ -1031,7 +1018,6 @@ VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pNa ADD_HOOK(vkGetProcAddr); ADD_HOOK(vkEnumerateLayers); ADD_HOOK(vkGetGlobalExtensionInfo); - ADD_HOOK(vkCreateDevice); ADD_HOOK(vkCreateShader); ADD_HOOK(vkCreateGraphicsPipeline); ADD_HOOK(vkCreateGraphicsPipelineDerivative); @@ -1061,7 +1047,6 @@ VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* ADD_HOOK(vkGetInstanceProcAddr); ADD_HOOK(vkEnumerateLayers); ADD_HOOK(vkGetGlobalExtensionInfo); - ADD_HOOK(vkCreateDevice); VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; if (instw->pGPA == NULL) diff --git a/loader/loader.c b/loader/loader.c index f80ce610..9cbee3f9 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -60,31 +60,6 @@ struct extension_property { bool hosted; // does the extension reside in one driver/layer }; -struct loader_icd { - const struct loader_scanned_icds *scanned_icds; - - VkLayerDispatchTable *loader_dispatch; - uint32_t layer_count[MAX_GPUS_FOR_LAYER]; - struct loader_layers layer_libs[MAX_GPUS_FOR_LAYER][MAX_LAYER_LIBRARIES]; - VkBaseLayerObject *wrappedGpus[MAX_GPUS_FOR_LAYER]; - uint32_t gpu_count; - VkBaseLayerObject *gpus; - VkInstance instance; // instance object from the icd - PFN_vkGetProcAddr GetProcAddr; - PFN_vkDestroyInstance DestroyInstance; - PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; - PFN_vkGetPhysicalDeviceInfo GetPhysicalDeviceInfo; - PFN_vkCreateDevice CreateDevice; - PFN_vkGetPhysicalDeviceExtensionInfo GetPhysicalDeviceExtensionInfo; - PFN_vkEnumerateLayers EnumerateLayers; - PFN_vkGetMultiDeviceCompatibility GetMultiDeviceCompatibility; - PFN_vkDbgRegisterMsgCallback DbgRegisterMsgCallback; - PFN_vkDbgUnregisterMsgCallback DbgUnregisterMsgCallback; - PFN_vkDbgSetGlobalOption DbgSetGlobalOption; - struct loader_icd *next; -}; - - struct loader_scanned_icds { loader_platform_dl_handle handle; @@ -103,15 +78,16 @@ VkLayerInstanceDispatchTable instance_disp = { .CreateInstance = loader_CreateInstance, .DestroyInstance = loader_DestroyInstance, .EnumeratePhysicalDevices = loader_EnumeratePhysicalDevices, - .GetPhysicalDeviceInfo = vkGetPhysicalDeviceInfo, - .CreateDevice = vkCreateDevice, + .GetPhysicalDeviceInfo = loader_GetPhysicalDeviceInfo, + .CreateDevice = loader_CreateDevice, .GetGlobalExtensionInfo = loader_GetGlobalExtensionInfo, - .GetPhysicalDeviceExtensionInfo = vkGetPhysicalDeviceExtensionInfo, - .EnumerateLayers = vkEnumerateLayers, - .GetMultiDeviceCompatibility = vkGetMultiDeviceCompatibility, + .GetPhysicalDeviceExtensionInfo = loader_GetPhysicalDeviceExtensionInfo, + .EnumerateLayers = loader_EnumerateLayers, + .GetMultiDeviceCompatibility = loader_GetMultiDeviceCompatibility, .DbgRegisterMsgCallback = loader_DbgRegisterMsgCallback, .DbgUnregisterMsgCallback = loader_DbgUnregisterMsgCallback, .DbgSetGlobalOption = loader_DbgSetGlobalOption, + .GetDisplayInfoWSI = loader_GetDisplayInfoWSI }; LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd); @@ -498,6 +474,7 @@ static void loader_icd_init_entrys(struct loader_icd *icd, LOOKUP(DbgRegisterMsgCallback); LOOKUP(DbgUnregisterMsgCallback); LOOKUP(DbgSetGlobalOption); + LOOKUP(GetDisplayInfoWSI); #undef LOOKUP return; @@ -747,11 +724,11 @@ void layer_lib_scan(void) static void* VKAPI loader_gpa_device_internal(VkPhysicalDevice physDev, const char * pName) { + //physDev is not wrapped if (physDev == VK_NULL_HANDLE) { return NULL; } - VkBaseLayerObject* physDevWrap = (VkBaseLayerObject *) physDev; - VkLayerDispatchTable* disp_table = * (VkLayerDispatchTable **) physDevWrap->baseObject; + VkLayerDispatchTable* disp_table = * (VkLayerDispatchTable **) physDev; void *addr; if (disp_table == NULL) @@ -763,9 +740,7 @@ static void* VKAPI loader_gpa_device_internal(VkPhysicalDevice physDev, const ch else { if (disp_table->GetProcAddr == NULL) return NULL; - if (physDevWrap->baseObject == physDevWrap->nextObject) - return physDevWrap->pGPA(physDevWrap->baseObject, pName); - return disp_table->GetProcAddr(physDevWrap->nextObject, pName); + return disp_table->GetProcAddr(physDev, pName); } } @@ -1147,21 +1122,19 @@ uint32_t loader_activate_instance_layers(struct loader_instance *inst) return inst->layer_count; } -extern uint32_t loader_activate_device_layers(struct loader_icd *icd, uint32_t gpu_index, uint32_t ext_count, const char *const* ext_names) +uint32_t loader_activate_device_layers(VkDevice device, struct loader_icd *icd, uint32_t gpu_index, uint32_t ext_count, const char *const* ext_names) { uint32_t count; - VkBaseLayerObject *gpu; struct layer_name_pair *pLayerNames; if (!icd) return 0; assert(gpu_index < MAX_GPUS_FOR_LAYER); - gpu = icd->gpus + gpu_index; /* activate any layer libraries */ if (!loader_layers_activated(icd, gpu_index)) { - // Note gpu object is wrapped once already - VkBaseLayerObject *gpuObj = gpu; - VkBaseLayerObject *nextGpuObj, *baseObj = (VkBaseLayerObject *) gpuObj->baseObject; + VkObject nextObj = (VkObject) device; + VkObject baseObj = nextObj; + VkBaseLayerObject *nextGpuObj; PFN_vkGetProcAddr nextGPA = loader_gpa_device_internal; count = loader_get_layer_libs(ext_count, ext_names, &pLayerNames); @@ -1177,9 +1150,9 @@ extern uint32_t loader_activate_device_layers(struct loader_icd *icd, uint32_t g for (int32_t i = icd->layer_count[gpu_index] - 1; i >= 0; i--) { nextGpuObj = (icd->wrappedGpus[gpu_index] + i); nextGpuObj->pGPA = nextGPA; - nextGpuObj->baseObject = (VkObject) baseObj; - nextGpuObj->nextObject = (VkObject) gpuObj; - gpuObj = nextGpuObj; + nextGpuObj->baseObject = baseObj; + nextGpuObj->nextObject = nextObj; + nextObj = (VkObject) nextGpuObj; char funcStr[256]; snprintf(funcStr, 256, "%sGetProcAddr",icd->layer_libs[gpu_index][i].name); @@ -1191,13 +1164,11 @@ extern uint32_t loader_activate_device_layers(struct loader_icd *icd, uint32_t g } if (i == 0) { - loader_init_device_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, (VkPhysicalDevice) gpuObj); + loader_init_device_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, (VkPhysicalDevice) nextObj); //Insert the new wrapped objects into the list with loader object at head - gpu->nextObject = (VkObject) gpuObj; - gpu->pGPA = nextGPA; - gpuObj = icd->wrappedGpus[gpu_index] + icd->layer_count[gpu_index] - 1; - gpuObj->nextObject = (VkObject) baseObj; - gpuObj->pGPA = icd->GetProcAddr; + nextGpuObj = icd->wrappedGpus[gpu_index] + icd->layer_count[gpu_index] - 1; + nextGpuObj->nextObject = baseObj; + nextGpuObj->pGPA = icd->GetProcAddr; } } @@ -1362,18 +1333,7 @@ VkResult loader_EnumeratePhysicalDevices( loader_init_device_dispatch_table(icd->loader_dispatch + i, get_proc_addr, gpus[i]); - /* Verify ICD compatibility */ - if (!valid_loader_magic_value(gpus[i])) { - loader_log(VK_DBG_MSG_WARNING, 0, - "Loader: Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details.\n"); - assert(0); - } - - const VkLayerDispatchTable **disp; - disp = (const VkLayerDispatchTable **) gpus[i]; - *disp = icd->loader_dispatch + i; - loader_activate_device_layers(icd, i, ptr_instance->extension_count, - (const char *const*) ptr_instance->extension_names); + loader_init_dispatch(gpus[i], ptr_instance->disp); } count += n; @@ -1408,6 +1368,33 @@ VkResult loader_GetPhysicalDeviceInfo( return res; } +VkResult loader_CreateDevice( + VkPhysicalDevice gpu, + const VkDeviceCreateInfo* pCreateInfo, + VkDevice* pDevice) +{ + uint32_t gpu_index; + struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu, &gpu_index); + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + struct loader_instance *ptr_instance; + + ptr_instance = loader.instances; + if (icd->CreateDevice) { + res = icd->CreateDevice(gpu, pCreateInfo, pDevice); + if (res == VK_SUCCESS) { + VkLayerDispatchTable *dev_disp = icd->loader_dispatch + gpu_index; + loader_init_dispatch(*pDevice, dev_disp); + } + //TODO fix this extension parameters once support GetDeviceExtensionInfo() + // don't know which instance we are on with this call + + loader_activate_device_layers(*pDevice, icd, gpu_index, ptr_instance->extension_count, + (const char *const*) ptr_instance->extension_names); + } + + return res; +} + LOADER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char * pName) { if (instance != VK_NULL_HANDLE) { @@ -1505,8 +1492,30 @@ VkResult loader_GetGlobalExtensionInfo( return VK_SUCCESS; } +VkResult loader_GetPhysicalDeviceExtensionInfo( + VkPhysicalDevice gpu, + VkExtensionInfoType infoType, + uint32_t extensionIndex, + size_t* pDataSize, + void* pData) +{ + uint32_t gpu_index; + struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu, &gpu_index); + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + + if (icd->GetPhysicalDeviceExtensionInfo) + res = icd->GetPhysicalDeviceExtensionInfo(gpu, infoType, extensionIndex, + pDataSize, pData); + + return res; +} -LOADER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved) +VkResult loader_EnumerateLayers( + VkPhysicalDevice gpu, + size_t maxStringSize, + size_t* pLayerCount, + char* const* pOutLayers, + void* pReserved) { size_t maxLayerCount; uint32_t gpu_index; @@ -1582,6 +1591,21 @@ LOADER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxS return VK_SUCCESS; } +VkResult loader_GetMultiDeviceCompatibility( + VkPhysicalDevice gpu0, + VkPhysicalDevice gpu1, + VkPhysicalDeviceCompatibilityInfo* pInfo) +{ + uint32_t gpu_index; + struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu0, &gpu_index); + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + + if (icd->GetMultiDeviceCompatibility) + res = icd->GetMultiDeviceCompatibility(gpu0, gpu1, pInfo); + + return res; +} + VkResult loader_DbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData) { const struct loader_icd *icd; @@ -1686,3 +1710,19 @@ VkResult loader_DbgSetGlobalOption(VkInstance instance, VK_DBG_GLOBAL_OPTION dbg return res; } + +VkResult loader_GetDisplayInfoWSI( + VkDisplayWSI display, + VkDisplayInfoTypeWSI infoType, + size_t* pDataSize, + void* pData) +{ + uint32_t gpu_index; + struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) display, &gpu_index); + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + + if (icd->GetDisplayInfoWSI) + res = icd->GetDisplayInfoWSI(display, infoType, pDataSize, pData); + + return res; +}
\ No newline at end of file diff --git a/loader/loader.h b/loader/loader.h index 40046925..54a97584 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -57,8 +57,34 @@ struct loader_layers { char name[256]; }; +struct loader_icd { + const struct loader_scanned_icds *scanned_icds; + + VkLayerDispatchTable *loader_dispatch; + uint32_t layer_count[MAX_GPUS_FOR_LAYER]; + struct loader_layers layer_libs[MAX_GPUS_FOR_LAYER][MAX_LAYER_LIBRARIES]; + VkBaseLayerObject *wrappedGpus[MAX_GPUS_FOR_LAYER]; + uint32_t gpu_count; + VkBaseLayerObject *gpus; + VkInstance instance; // instance object from the icd + PFN_vkGetProcAddr GetProcAddr; + PFN_vkDestroyInstance DestroyInstance; + PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; + PFN_vkGetPhysicalDeviceInfo GetPhysicalDeviceInfo; + PFN_vkCreateDevice CreateDevice; + PFN_vkGetPhysicalDeviceExtensionInfo GetPhysicalDeviceExtensionInfo; + PFN_vkEnumerateLayers EnumerateLayers; + PFN_vkGetMultiDeviceCompatibility GetMultiDeviceCompatibility; + PFN_vkDbgRegisterMsgCallback DbgRegisterMsgCallback; + PFN_vkDbgUnregisterMsgCallback DbgUnregisterMsgCallback; + PFN_vkDbgSetGlobalOption DbgSetGlobalOption; + PFN_vkGetDisplayInfoWSI GetDisplayInfoWSI; + struct loader_icd *next; +}; + struct loader_instance { - VkLayerInstanceDispatchTable *disp; + VkLayerInstanceDispatchTable *disp; // must be first entry in structure + uint32_t layer_count; struct loader_layers layer_libs[MAX_LAYER_LIBRARIES]; VkBaseLayerObject *wrappedInstance; @@ -126,6 +152,16 @@ VkResult loader_EnumeratePhysicalDevices( VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices); +VkResult loader_GetPhysicalDeviceInfo( + VkPhysicalDevice gpu, + VkPhysicalDeviceInfoType infoType, + size_t* pDataSize, + void* pData); + +VkResult loader_CreateDevice( + VkPhysicalDevice gpu, + const VkDeviceCreateInfo* pCreateInfo, + VkDevice* pDevice); VkResult VKAPI loader_GetGlobalExtensionInfo( VkExtensionInfoType infoType, @@ -133,6 +169,25 @@ VkResult VKAPI loader_GetGlobalExtensionInfo( size_t* pDataSize, void* pData); +VkResult loader_GetPhysicalDeviceExtensionInfo( + VkPhysicalDevice gpu, + VkExtensionInfoType infoType, + uint32_t extensionIndex, + size_t* pDataSize, + void* pData); + +VkResult loader_EnumerateLayers( + VkPhysicalDevice gpu, + size_t maxStringSize, + size_t* pLayerCount, + char* const* pOutLayers, + void* pReserved); + +VkResult loader_GetMultiDeviceCompatibility( + VkPhysicalDevice gpu0, + VkPhysicalDevice gpu1, + VkPhysicalDeviceCompatibilityInfo* pInfo); + VkResult loader_DbgRegisterMsgCallback( VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, @@ -148,11 +203,18 @@ VkResult loader_DbgSetGlobalOption( size_t dataSize, const void* pData); +VkResult loader_GetDisplayInfoWSI( + VkDisplayWSI display, + VkDisplayInfoTypeWSI infoType, + size_t* pDataSize, + void* pData); + /* function definitions */ bool loader_is_extension_scanned(const char *name); void loader_icd_scan(void); void layer_lib_scan(void); void loader_coalesce_extensions(void); -struct loader_icd * loader_get_icd(const VkBaseLayerObject *gpu, uint32_t *gpu_index); +struct loader_icd * loader_get_icd(const VkBaseLayerObject *gpu, + uint32_t *gpu_index); uint32_t loader_activate_instance_layers(struct loader_instance *inst); #endif /* LOADER_H */ diff --git a/loader/table_ops.h b/loader/table_ops.h index fedfb79d..5316720b 100644 --- a/loader/table_ops.h +++ b/loader/table_ops.h @@ -32,17 +32,7 @@ static inline void loader_init_device_dispatch_table(VkLayerDispatchTable *table PFN_vkGetProcAddr gpa, VkPhysicalDevice gpu) { - table->CreateInstance = vkCreateInstance; /* non-dispatchable */ - table->DestroyInstance = (PFN_vkDestroyInstance) gpa(gpu, "vkDestroyInstance"); - table->EnumeratePhysicalDevices = (PFN_vkEnumeratePhysicalDevices) gpa(gpu, "vkEnumeratePhysicalDevices"); - table->GetPhysicalDeviceInfo = (PFN_vkGetPhysicalDeviceInfo) gpa(gpu, "vkGetPhysicalDeviceInfo"); - table->GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) gpa(gpu, "vkGetInstanceProcAddr"); - table->GetProcAddr = (PFN_vkGetProcAddr) gpa(gpu, "vkGetProcAddr"); - table->CreateDevice = (PFN_vkCreateDevice) gpa(gpu, "vkCreateDevice"); table->DestroyDevice = (PFN_vkDestroyDevice) gpa(gpu, "vkDestroyDevice"); - table->GetGlobalExtensionInfo = vkGetGlobalExtensionInfo; /* non-dispatchable */ - table->GetPhysicalDeviceExtensionInfo = (PFN_vkGetPhysicalDeviceExtensionInfo) gpa(gpu, "vkGetPhysicalDeviceExtensionInfo"); - table->EnumerateLayers = (PFN_vkEnumerateLayers) gpa(gpu, "vkEnumerateLayers"); table->GetDeviceQueue = (PFN_vkGetDeviceQueue) gpa(gpu, "vkGetDeviceQueue"); table->QueueSubmit = (PFN_vkQueueSubmit) gpa(gpu, "vkQueueSubmit"); table->QueueWaitIdle = (PFN_vkQueueWaitIdle) gpa(gpu, "vkQueueWaitIdle"); @@ -55,7 +45,6 @@ static inline void loader_init_device_dispatch_table(VkLayerDispatchTable *table table->FlushMappedMemoryRanges = (PFN_vkFlushMappedMemoryRanges) gpa(gpu, "vkFlushMappedMemoryRanges"); table->InvalidateMappedMemoryRanges = (PFN_vkInvalidateMappedMemoryRanges) gpa(gpu, "vkInvalidateMappedMemoryRanges"); table->PinSystemMemory = (PFN_vkPinSystemMemory) gpa(gpu, "vkPinSystemMemory"); - table->GetMultiDeviceCompatibility = (PFN_vkGetMultiDeviceCompatibility) gpa(gpu, "vkGetMultiDeviceCompatibility"); table->OpenSharedMemory = (PFN_vkOpenSharedMemory) gpa(gpu, "vkOpenSharedMemory"); table->OpenSharedSemaphore = (PFN_vkOpenSharedSemaphore) gpa(gpu, "vkOpenSharedSemaphore"); table->OpenPeerMemory = (PFN_vkOpenPeerMemory) gpa(gpu, "vkOpenPeerMemory"); @@ -147,15 +136,11 @@ static inline void loader_init_device_dispatch_table(VkLayerDispatchTable *table table->CmdBeginRenderPass = (PFN_vkCmdBeginRenderPass) gpa(gpu, "vkCmdBeginRenderPass"); table->CmdEndRenderPass = (PFN_vkCmdEndRenderPass) gpa(gpu, "vkCmdEndRenderPass"); table->DbgSetValidationLevel = (PFN_vkDbgSetValidationLevel) gpa(gpu, "vkDbgSetValidationLevel"); - table->DbgRegisterMsgCallback = (PFN_vkDbgRegisterMsgCallback) gpa(gpu, "vkDbgRegisterMsgCallback"); - table->DbgUnregisterMsgCallback = (PFN_vkDbgUnregisterMsgCallback) gpa(gpu, "vkDbgUnregisterMsgCallback"); table->DbgSetMessageFilter = (PFN_vkDbgSetMessageFilter) gpa(gpu, "vkDbgSetMessageFilter"); table->DbgSetObjectTag = (PFN_vkDbgSetObjectTag) gpa(gpu, "vkDbgSetObjectTag"); - table->DbgSetGlobalOption = (PFN_vkDbgSetGlobalOption) gpa(gpu, "vkDbgSetGlobalOption"); table->DbgSetDeviceOption = (PFN_vkDbgSetDeviceOption) gpa(gpu, "vkDbgSetDeviceOption"); table->CmdDbgMarkerBegin = (PFN_vkCmdDbgMarkerBegin) gpa(gpu, "vkCmdDbgMarkerBegin"); table->CmdDbgMarkerEnd = (PFN_vkCmdDbgMarkerEnd) gpa(gpu, "vkCmdDbgMarkerEnd"); - table->GetDisplayInfoWSI = (PFN_vkGetDisplayInfoWSI) gpa(gpu, "vkGetDisplayInfoWSI"); table->CreateSwapChainWSI = (PFN_vkCreateSwapChainWSI) gpa(gpu, "vkCreateSwapChainWSI"); table->DestroySwapChainWSI = (PFN_vkDestroySwapChainWSI) gpa(gpu, "vkDestroySwapChainWSI"); table->GetSwapChainInfoWSI = (PFN_vkGetSwapChainInfoWSI) gpa(gpu, "vkGetSwapChainInfoWSI"); @@ -170,24 +155,8 @@ static inline void *loader_lookup_device_dispatch_table( return NULL; name += 2; - if (!strcmp(name, "DestroyInstance")) - return (void *) table->DestroyInstance; - if (!strcmp(name, "EnumeratePhysicalDevices")) - return (void *) table->EnumeratePhysicalDevices; - if (!strcmp(name, "GetPhysicalDeviceInfo")) - return (void *) table->GetPhysicalDeviceInfo; - if (!strcmp(name, "GetInstanceProcAddr")) - return (void *) table->GetInstanceProcAddr; - if (!strcmp(name, "GetProcAddr")) - return (void *) table->GetProcAddr; - if (!strcmp(name, "CreateDevice")) - return (void *) table->CreateDevice; if (!strcmp(name, "DestroyDevice")) return (void *) table->DestroyDevice; - if (!strcmp(name, "GetPhysicalDeviceExtensionInfo")) - return (void *) table->GetPhysicalDeviceExtensionInfo; - if (!strcmp(name, "EnumerateLayers")) - return (void *) table->EnumerateLayers; if (!strcmp(name, "GetDeviceQueue")) return (void *) table->GetDeviceQueue; if (!strcmp(name, "QueueSubmit")) @@ -212,8 +181,6 @@ static inline void *loader_lookup_device_dispatch_table( return (void *) table->InvalidateMappedMemoryRanges; if (!strcmp(name, "PinSystemMemory")) return (void *) table->PinSystemMemory; - if (!strcmp(name, "GetMultiDeviceCompatibility")) - return (void *) table->GetMultiDeviceCompatibility; if (!strcmp(name, "OpenSharedMemory")) return (void *) table->OpenSharedMemory; if (!strcmp(name, "OpenSharedSemaphore")) @@ -396,24 +363,16 @@ static inline void *loader_lookup_device_dispatch_table( return (void *) table->CmdEndRenderPass; if (!strcmp(name, "DbgSetValidationLevel")) return (void *) table->DbgSetValidationLevel; - if (!strcmp(name, "DbgRegisterMsgCallback")) - return (void *) table->DbgRegisterMsgCallback; - if (!strcmp(name, "DbgUnregisterMsgCallback")) - return (void *) table->DbgUnregisterMsgCallback; if (!strcmp(name, "DbgSetMessageFilter")) return (void *) table->DbgSetMessageFilter; if (!strcmp(name, "DbgSetObjectTag")) return (void *) table->DbgSetObjectTag; - if (!strcmp(name, "DbgSetGlobalOption")) - return (void *) table->DbgSetGlobalOption; if (!strcmp(name, "DbgSetDeviceOption")) return (void *) table->DbgSetDeviceOption; if (!strcmp(name, "CmdDbgMarkerBegin")) return (void *) table->CmdDbgMarkerBegin; if (!strcmp(name, "CmdDbgMarkerEnd")) return (void *) table->CmdDbgMarkerEnd; - if (!strcmp(name, "GetDisplayInfoWSI")) - return (void *) table->GetDisplayInfoWSI; if (!strcmp(name, "CreateSwapChainWSI")) return (void *) table->CreateSwapChainWSI; if (!strcmp(name, "DestroySwapChainWSI")) @@ -444,6 +403,7 @@ static inline void loader_init_instance_dispatch_table(VkLayerInstanceDispatchTa table->DbgRegisterMsgCallback = (PFN_vkDbgRegisterMsgCallback) gpa(inst, "vkDbgRegisterMsgCallback"); table->DbgUnregisterMsgCallback = (PFN_vkDbgUnregisterMsgCallback) gpa(inst, "vkDbgUnregisterMsgCallback"); table->DbgSetGlobalOption = (PFN_vkDbgSetGlobalOption) gpa(inst, "vkDbgSetGlobalOption"); + table->GetDisplayInfoWSI = (PFN_vkGetDisplayInfoWSI) gpa(inst, "vkGetDisplayInfoWSI"); } static inline void *loader_lookup_instance_dispatch_table( @@ -482,6 +442,8 @@ static inline void *loader_lookup_instance_dispatch_table( return (void *) table->DbgUnregisterMsgCallback; if (!strcmp(name, "DbgSetGlobalOption")) return (void *) table->DbgSetGlobalOption; + if (!strcmp(name, "GetDisplayInfoWSI")) + return (void *) table->GetDisplayInfoWSI; return NULL; }
\ No newline at end of file diff --git a/loader/trampoline.c b/loader/trampoline.c index b7b6c58d..15d2c5e5 100644 --- a/loader/trampoline.c +++ b/loader/trampoline.c @@ -89,6 +89,7 @@ LOADER_EXPORT VkResult VKAPI vkDestroyInstance( disp = loader_get_instance_dispatch(instance); return disp->DestroyInstance(instance); } + LOADER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices( VkInstance instance, uint32_t* pPhysicalDeviceCount, @@ -107,12 +108,13 @@ LOADER_EXPORT VkResult VKAPI vkGetPhysicalDeviceInfo( size_t* pDataSize, void* pData) { - const VkLayerDispatchTable *disp; + const VkLayerInstanceDispatchTable *disp; VkResult res; - disp = loader_get_dispatch(gpu); + disp = loader_get_instance_dispatch(gpu); res = disp->GetPhysicalDeviceInfo(gpu, infoType, pDataSize, pData); + //TODO add check for extension enabled if (infoType == VK_PHYSICAL_DEVICE_INFO_TYPE_DISPLAY_PROPERTIES_WSI && pData && res == VK_SUCCESS) { VkDisplayPropertiesWSI *info = pData; size_t count = *pDataSize / sizeof(*info), i; @@ -124,18 +126,18 @@ LOADER_EXPORT VkResult VKAPI vkGetPhysicalDeviceInfo( return res; } -LOADER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) +LOADER_EXPORT VkResult VKAPI vkCreateDevice( + VkPhysicalDevice gpu, + const VkDeviceCreateInfo* pCreateInfo, + VkDevice* pDevice) { - const VkLayerDispatchTable *disp; + const VkLayerInstanceDispatchTable *disp; VkResult res; - disp = loader_get_dispatch(gpu); + disp = loader_get_instance_dispatch(gpu); + // CreateDevice is dispatched on the instance chain res = disp->CreateDevice(gpu, pCreateInfo, pDevice); - if (res == VK_SUCCESS) { - loader_init_dispatch(*pDevice, disp); - } - return res; } @@ -161,15 +163,34 @@ LOADER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( return instance_disp.GetGlobalExtensionInfo(infoType, extensionIndex, pDataSize, pData); } -LOADER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionInfo(VkPhysicalDevice gpu, VkExtensionInfoType infoType, uint32_t extensionIndex, size_t* pDataSize, void* pData) +LOADER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionInfo( + VkPhysicalDevice gpu, + VkExtensionInfoType infoType, + uint32_t extensionIndex, + size_t* pDataSize, + void* pData) { - const VkLayerDispatchTable *disp; + const VkLayerInstanceDispatchTable *disp; - disp = loader_get_dispatch(gpu); + disp = loader_get_instance_dispatch(gpu); return disp->GetPhysicalDeviceExtensionInfo(gpu, infoType, extensionIndex, pDataSize, pData); } +LOADER_EXPORT VkResult VKAPI vkEnumerateLayers( + VkPhysicalDevice gpu, + size_t maxStringSize, + size_t* pLayerCount, + char* const* pOutLayers, + void* pReserved) +{ + const VkLayerInstanceDispatchTable *disp; + + disp = loader_get_instance_dispatch(gpu); + + return disp->EnumerateLayers(gpu, maxStringSize, pLayerCount,pOutLayers, pReserved); +} + LOADER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue) { const VkLayerDispatchTable *disp; @@ -286,9 +307,9 @@ LOADER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSys LOADER_EXPORT VkResult VKAPI vkGetMultiDeviceCompatibility(VkPhysicalDevice gpu0, VkPhysicalDevice gpu1, VkPhysicalDeviceCompatibilityInfo* pInfo) { - const VkLayerDispatchTable *disp; + const VkLayerInstanceDispatchTable *disp; - disp = loader_get_dispatch(gpu0); + disp = loader_get_instance_dispatch(gpu0); return disp->GetMultiDeviceCompatibility(gpu0, gpu1, pInfo); } @@ -1192,9 +1213,9 @@ LOADER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer) LOADER_EXPORT VkResult VKAPI vkGetDisplayInfoWSI(VkDisplayWSI display, VkDisplayInfoTypeWSI infoType, size_t* pDataSize, void* pData) { - const VkLayerDispatchTable *disp; + const VkLayerInstanceDispatchTable *disp; - disp = loader_get_dispatch(display); + disp = loader_get_instance_dispatch(display); return disp->GetDisplayInfoWSI(display, infoType, pDataSize, pData); } diff --git a/vk-generate.py b/vk-generate.py index 28e45072..ca3a6d3d 100755 --- a/vk-generate.py +++ b/vk-generate.py @@ -115,6 +115,8 @@ class DispatchTableOpsSubcommand(Subcommand): func = [] if type == "device": for proto in self.protos: + if proto.name == "CreateInstance" or proto.name == "GetGlobalExtensionInfo" or proto.name == "GetDisplayInfoWSI" or proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice": + continue stmts.append("table->%s = (PFN_vk%s) gpa(gpu, \"vk%s\");" % (proto.name, proto.name, proto.name)) func.append("static inline void %s_initialize_dispatch_table(VkLayerDispatchTable *table," @@ -125,7 +127,7 @@ class DispatchTableOpsSubcommand(Subcommand): % (" " * len(self.prefix))) else: for proto in self.protos: - if proto.name != "CreateInstance" and proto.name != "GetGlobalExtensionInfo" and proto.params[0].ty != "VkInstance" and proto.params[0].ty != "VkPhysicalDevice": + if proto.name != "CreateInstance" and proto.name != "GetGlobalExtensionInfo" and proto.name != "GetDisplayInfoWSI" and proto.params[0].ty != "VkInstance" and proto.params[0].ty != "VkPhysicalDevice": continue stmts.append("table->%s = (PFN_vk%s) gpa(instance, \"vk%s\");" % (proto.name, proto.name, proto.name)) diff --git a/vk-layer-generate.py b/vk-layer-generate.py index 09210e15..efea5567 100755 --- a/vk-layer-generate.py +++ b/vk-layer-generate.py @@ -32,6 +32,12 @@ import re import vulkan import vk_helper +def proto_is_global(proto): + if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name == "CreateInstance" or proto.name == "GetGlobalExtensionInfo" or proto.name == "GetDisplayInfoWSI": + return True + else: + return False + def generate_get_proc_addr_check(name): return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ " return NULL;" % ((name,) * 3) @@ -317,7 +323,7 @@ class Subcommand(object): # add layer_intercept_instance_proc lookups = [] for proto in self.protos: - if proto.params[0].ty != "VkInstance" and proto.params[0].ty != "VkPhysicalDevice" and proto.name != "CreateInstance" and proto.name != "GetGlobalExtensionInfo": + if not proto_is_global(proto): continue if not proto in intercepted: @@ -534,7 +540,7 @@ class GenericLayerSubcommand(Subcommand): stmt = '' funcs = [] table = '' - if proto.params[0].ty == "VkInstance" or proto.name == "CreateInstance": + if proto_is_global(proto): table = 'Instance' if proto.ret != "void": @@ -854,7 +860,7 @@ class APIDumpSubcommand(Subcommand): indent = indent[4:] log_func += '\n%s}' % (indent) table = '' - if proto.params[0].ty == "VkInstance" or proto.name == "CreateInstance": + if proto_is_global(proto): table = 'Instance' if proto.name == "EnumerateLayers": @@ -1259,7 +1265,7 @@ class ObjectTrackerSubcommand(Subcommand): if proto.ret != "void": ret_val = "%s result = " % proto.ret stmt = " return result;\n" - if proto.params[0].ty == "VkInstance" or proto.name == "CreateInstance": + if proto_is_global(proto): table = 'Instance' if proto.name == "EnumerateLayers": @@ -1402,7 +1408,7 @@ class ThreadingSubcommand(Subcommand): if proto.ret != "void": ret_val = "%s result = " % proto.ret stmt = " return result;\n" - if proto.params[0].ty == "VkInstance" or proto.name == "CreateInstance": + if proto_is_global(proto): table = 'Instance' if proto.name == "EnumerateLayers": |
