From a65963a5c7edcfd5e44f8d5102e8379ba86916ec Mon Sep 17 00:00:00 2001 From: Jon Ashburn Date: Wed, 8 Apr 2015 21:33:34 -0600 Subject: [PATCH] layers: Remove wrapping of GPU objects by loader and layers Loader only wraps GPU objects for creating a layer chain. After layer activation layers and loader use unwrapped gpu object returned by the driver. This is a large simplification. This fixes a nasty bug where layers intercepting entrypoints with gpu objects but not all these entrypoints would fail. These would cause non-uniform unwrapping of gpu objects by the time the driver was called with a gpu object. Fixes issue in loader_get_icd where it was trying to compare a wrapped GPU against a non-wrapped GPU. --- layers/basic.cpp | 21 ++++++------ layers/draw_state.cpp | 20 +++++------- layers/mem_tracker.cpp | 13 +++----- layers/multi.cpp | 77 ++++++++++++++++++++++++++++---------------- layers/param_checker.cpp | 30 +++++++---------- loader/loader.c | 9 ++++-- loader/loader.h | 9 ------ vk-generate.py | 15 ++------- vk-layer-generate.py | 84 ++++++++++++------------------------------------ 9 files changed, 115 insertions(+), 163 deletions(-) diff --git a/layers/basic.cpp b/layers/basic.cpp index 3854577..524bd40 100644 --- a/layers/basic.cpp +++ b/layers/basic.cpp @@ -39,11 +39,11 @@ static VkLayerDispatchTable * initLayerTable(const VkBaseLayerObject *gpuw) VkLayerDispatchTable *pTable; assert(gpuw); - std::unordered_map::const_iterator it = tableMap.find((void *) gpuw); + std::unordered_map::const_iterator it = tableMap.find((void *) gpuw->baseObject); if (it == tableMap.end()) { pTable = new VkLayerDispatchTable; - tableMap[(void *) gpuw] = pTable; + tableMap[(void *) gpuw->baseObject] = pTable; } else { return it->second; @@ -64,7 +64,6 @@ VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device) VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName) { VkResult result; - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */ if (!strncmp(pExtName, "vkLayerExtension1", strlen("vkLayerExtension1"))) @@ -73,11 +72,11 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const ch } else if (!strncmp(pExtName, "Basic", strlen("Basic"))) { result = VK_SUCCESS; - } else if (!tableMap.empty() && (tableMap.find(gpuw) != tableMap.end())) + } else if (!tableMap.empty() && (tableMap.find(gpu) != tableMap.end())) { printf("At start of wrapped vkGetExtensionSupport() call w/ gpu: %p\n", (void*)gpu); - VkLayerDispatchTable* pTable = tableMap[gpuw]; - result = pTable->GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName); + VkLayerDispatchTable* pTable = tableMap[gpu]; + result = pTable->GetExtensionSupport(gpu, pExtName); printf("Completed wrapped vkGetExtensionSupport() call w/ gpu: %p\n", (void*)gpu); } else { @@ -88,11 +87,10 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const ch VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - VkLayerDispatchTable* pTable = tableMap[gpuw]; + VkLayerDispatchTable* pTable = tableMap[gpu]; printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu); - VkResult result = pTable->CreateDevice((VkPhysicalGpu)gpuw->nextObject, pCreateInfo, pDevice); + VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); // create a mapping for the device object into the dispatch table tableMap.emplace(*pDevice, pTable); printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice); @@ -112,11 +110,10 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLa { if (gpu != NULL) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - VkLayerDispatchTable* pTable = initLayerTable(gpuw); + VkLayerDispatchTable* pTable = initLayerTable((const VkBaseLayerObject *) gpu); printf("At start of wrapped vkEnumerateLayers() call w/ gpu: %p\n", gpu); - VkResult result = pTable->EnumerateLayers((VkPhysicalGpu)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); + VkResult result = pTable->EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); return result; } else { diff --git a/layers/draw_state.cpp b/layers/draw_state.cpp index cb3e683..1de84b1 100644 --- a/layers/draw_state.cpp +++ b/layers/draw_state.cpp @@ -1443,10 +1443,9 @@ static void initDrawState(void) VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&g_initOnce, initDrawState); - VkResult result = nextTable.CreateDevice((VkPhysicalGpu)gpuw->nextObject, pCreateInfo, pDevice); + VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice); return result; } @@ -1469,8 +1468,8 @@ VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; VkResult result; + /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */ if (!strcmp(pExtName, "DrawState") || !strcmp(pExtName, "drawStateDumpDotFile") || !strcmp(pExtName, "drawStateDumpCommandBufferDotFile") || !strcmp(pExtName, "drawStateDumpPngFile")) @@ -1478,9 +1477,8 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const ch result = VK_SUCCESS; } else if (nextTable.GetExtensionSupport != NULL) { - result = nextTable.GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName); - } else - { + result = nextTable.GetExtensionSupport(gpu, pExtName); + } else { result = VK_ERROR_INVALID_EXTENSION; } return result; @@ -1490,13 +1488,11 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLa { if (gpu != NULL) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&g_initOnce, initDrawState); - VkResult result = nextTable.EnumerateLayers((VkPhysicalGpu)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); + VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); return result; - } else - { + } else { if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL) return VK_ERROR_INVALID_POINTER; // This layer compatible with all GPUs diff --git a/layers/mem_tracker.cpp b/layers/mem_tracker.cpp index 1a00669..1b32f88 100644 --- a/layers/mem_tracker.cpp +++ b/layers/mem_tracker.cpp @@ -823,10 +823,9 @@ static void initMemTracker(void) VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&g_initOnce, initMemTracker); - VkResult result = nextTable.CreateDevice((VkPhysicalGpu)gpuw->nextObject, pCreateInfo, pDevice); + VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice); // Save off device in case we need it to create Fences globalDevice = *pDevice; return result; @@ -867,7 +866,6 @@ VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; VkResult result; /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */ if (!strcmp(pExtName, "MemTracker")) @@ -875,7 +873,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const ch result = VK_SUCCESS; } else if (nextTable.GetExtensionSupport != NULL) { - result = nextTable.GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName); + result = nextTable.GetExtensionSupport(gpu, pExtName); } else { result = VK_ERROR_INVALID_EXTENSION; @@ -888,10 +886,9 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLa { if (gpu != NULL) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&g_initOnce, initMemTracker); - VkResult result = nextTable.EnumerateLayers((VkPhysicalGpu)gpuw->nextObject, maxLayerCount, + VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); return result; } else diff --git a/layers/multi.cpp b/layers/multi.cpp index 53286c5..910bc5b 100644 --- a/layers/multi.cpp +++ b/layers/multi.cpp @@ -45,11 +45,11 @@ static VkLayerDispatchTable * getLayer1Table(const VkBaseLayerObject *gpuw) VkLayerDispatchTable *pTable; assert(gpuw); - std::unordered_map::const_iterator it = tableMap1.find((void *) gpuw); + std::unordered_map::const_iterator it = tableMap1.find((void *) gpuw->baseObject); if (it == tableMap1.end()) { pTable = new VkLayerDispatchTable; - tableMap1[(void *) gpuw] = pTable; + tableMap1[(void *) gpuw->baseObject] = pTable; initLayerTable(gpuw, pTable, 1); return pTable; } else @@ -65,11 +65,9 @@ extern "C" { VK_LAYER_EXPORT VkResult VKAPI multi1CreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - VkLayerDispatchTable* pTable = getLayer1Table(gpuw); - + VkLayerDispatchTable* pTable = tableMap1[gpu]; printf("At start of multi1 layer vkCreateDevice()\n"); - VkResult result = pTable->CreateDevice((VkPhysicalGpu)gpuw->nextObject, pCreateInfo, pDevice); + 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"); @@ -106,15 +104,28 @@ VK_LAYER_EXPORT VkResult VKAPI multi1EnumerateLayers(VkPhysicalGpu gpu, size_t m if (gpu == NULL) return vkEnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - VkLayerDispatchTable* pTable = getLayer1Table(gpuw); - + VkLayerDispatchTable* pTable = tableMap1[gpu]; printf("At start of multi1 layer vkEnumerateLayers()\n"); - VkResult result = pTable->EnumerateLayers((VkPhysicalGpu)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); + VkResult result = pTable->EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); printf("Completed multi1 layer vkEnumerateLayers()\n"); return result; } +VK_LAYER_EXPORT VkResult VKAPI multi1GetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName) +{ + VkResult result; + + if (!tableMap1.empty() && (tableMap1.find(gpu) != tableMap1.end())) + { + VkLayerDispatchTable* pTable = tableMap1[gpu]; + result = pTable->GetExtensionSupport(gpu, pExtName); + } else + { + result = VK_ERROR_INVALID_EXTENSION; + } + return result; +} + VK_LAYER_EXPORT void * VKAPI multi1GetProcAddr(VkPhysicalGpu gpu, const char* pName) { VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; @@ -133,7 +144,7 @@ VK_LAYER_EXPORT void * VKAPI multi1GetProcAddr(VkPhysicalGpu gpu, const char* pN else if (!strncmp("vkStorePipeline", pName, sizeof ("vkStorePipeline"))) return (void *) multi1StorePipeline; else if (!strncmp("vkGetExtensionSupport", pName, sizeof ("vkGetExtensionSupport"))) - return (void *) vkGetExtensionSupport; + return (void *) multi1GetExtensionSupport; else { if (gpuw->pGPA == NULL) return NULL; @@ -150,11 +161,11 @@ static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw) VkLayerDispatchTable *pTable; assert(gpuw); - std::unordered_map::const_iterator it = tableMap2.find((void *) gpuw); + std::unordered_map::const_iterator it = tableMap2.find((void *) gpuw->baseObject); if (it == tableMap2.end()) { pTable = new VkLayerDispatchTable; - tableMap2[(void *) gpuw] = pTable; + tableMap2[(void *) gpuw->baseObject] = pTable; initLayerTable(gpuw, pTable, 2); return pTable; } else @@ -166,11 +177,10 @@ static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw) VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - VkLayerDispatchTable* pTable = getLayer2Table(gpuw); + VkLayerDispatchTable* pTable = tableMap2[gpu]; printf("At start of multi2 vkCreateDevice()\n"); - VkResult result = pTable->CreateDevice((VkPhysicalGpu)gpuw->nextObject, pCreateInfo, pDevice); + VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); // create a mapping for the device object into the dispatch table for layer2 tableMap2.emplace(*pDevice, pTable); printf("Completed multi2 layer vkCreateDevice()\n"); @@ -208,15 +218,29 @@ VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalGpu gpu, size_t m if (gpu == NULL) return vkEnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - VkLayerDispatchTable* pTable = getLayer2Table(gpuw); + VkLayerDispatchTable* pTable = tableMap2[gpu]; printf("At start of multi2 layer vkEnumerateLayers()\n"); - VkResult result = pTable->EnumerateLayers((VkPhysicalGpu)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); + VkResult result = pTable->EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); printf("Completed multi2 layer vkEnumerateLayers()\n"); return result; } +VK_LAYER_EXPORT VkResult VKAPI multi2GetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName) +{ + VkResult result; + + if (!tableMap2.empty() && (tableMap2.find(gpu) != tableMap2.end())) + { + VkLayerDispatchTable* pTable = tableMap2[gpu]; + result = pTable->GetExtensionSupport(gpu, pExtName); + } else + { + result = VK_ERROR_INVALID_EXTENSION; + } + return result; +} + VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalGpu gpu, const char* pName) { VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; @@ -235,7 +259,7 @@ VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalGpu gpu, const char* pN else if (!strncmp("vkBeginCommandBuffer", pName, sizeof ("vkBeginCommandBuffer"))) return (void *) multi2BeginCommandBuffer; else if (!strncmp("vkGetExtensionSupport", pName, sizeof ("vkGetExtensionSupport"))) - return (void *) vkGetExtensionSupport; + return (void *) multi2GetExtensionSupport; else { if (gpuw->pGPA == NULL) return NULL; @@ -262,7 +286,6 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLa VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName) { VkResult result; - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */ if (!strncmp(pExtName, "multi1", strlen("multi1"))) @@ -271,14 +294,14 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const ch } else if (!strncmp(pExtName, "multi2", strlen("multi2"))) { result = VK_SUCCESS; - } else if (!tableMap1.empty() && (tableMap1.find(gpuw) != tableMap1.end())) + } else if (!tableMap1.empty() && (tableMap1.find(gpu) != tableMap1.end())) { - VkLayerDispatchTable* pTable = tableMap1[gpuw]; - result = pTable->GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName); - } else if (!tableMap2.empty() && (tableMap2.find(gpuw) != tableMap2.end())) + VkLayerDispatchTable* pTable = tableMap1[gpu]; + result = pTable->GetExtensionSupport(gpu, pExtName); + } else if (!tableMap2.empty() && (tableMap2.find(gpu) != tableMap2.end())) { - VkLayerDispatchTable* pTable = tableMap2[gpuw]; - result = pTable->GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName); + VkLayerDispatchTable* pTable = tableMap2[gpu]; + result = pTable->GetExtensionSupport(gpu, pExtName); } else { result = VK_ERROR_INVALID_EXTENSION; diff --git a/layers/param_checker.cpp b/layers/param_checker.cpp index 1ce946a..4c2b440 100644 --- a/layers/param_checker.cpp +++ b/layers/param_checker.cpp @@ -148,15 +148,14 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateGpus(VkInstance instance, uint32_t max VK_LAYER_EXPORT VkResult VKAPI vkGetGpuInfo(VkPhysicalGpu gpu, VkPhysicalGpuInfoType infoType, size_t* pDataSize, void* pData) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&tabOnce, initParamChecker); char str[1024]; if (!validate_VkPhysicalGpuInfoType(infoType)) { sprintf(str, "Parameter infoType to function GetGpuInfo has invalid value of %i.", (int)infoType); layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str); } - VkResult result = nextTable.GetGpuInfo((VkPhysicalGpu)gpuw->nextObject, infoType, pDataSize, pData); + VkResult result = nextTable.GetGpuInfo(gpu, infoType, pDataSize, pData); return result; } @@ -243,11 +242,10 @@ void PostCreateDevice(VkResult result, VkDevice* pDevice) VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&tabOnce, initParamChecker); PreCreateDevice(gpu, pCreateInfo); - VkResult result = nextTable.CreateDevice((VkPhysicalGpu)gpuw->nextObject, pCreateInfo, pDevice); + VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice); PostCreateDevice(result, pDevice); return result; } @@ -261,11 +259,10 @@ VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&tabOnce, initParamChecker); - VkResult result = nextTable.GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName); + VkResult result = nextTable.GetExtensionSupport(gpu, pExtName); return result; } @@ -273,12 +270,11 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLa { char str[1024]; if (gpu != NULL) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; sprintf(str, "At start of layered EnumerateLayers\n"); layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, nullptr, 0, 0, "PARAMCHECK", str); - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&tabOnce, initParamChecker); - VkResult result = nextTable.EnumerateLayers((VkPhysicalGpu)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); + VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved); sprintf(str, "Completed layered EnumerateLayers\n"); layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, nullptr, 0, 0, "PARAMCHECK", str); fflush(stdout); @@ -386,11 +382,10 @@ VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pS VK_LAYER_EXPORT VkResult VKAPI vkGetMultiGpuCompatibility(VkPhysicalGpu gpu0, VkPhysicalGpu gpu1, VkGpuCompatibilityInfo* pInfo) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu0; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu0; loader_platform_thread_once(&tabOnce, initParamChecker); - VkResult result = nextTable.GetMultiGpuCompatibility((VkPhysicalGpu)gpuw->nextObject, gpu1, pInfo); + VkResult result = nextTable.GetMultiGpuCompatibility(gpu0, gpu1, pInfo); return result; } @@ -1932,11 +1927,10 @@ VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer) VK_LAYER_EXPORT VkResult VKAPI vkWsiX11AssociateConnection(VkPhysicalGpu gpu, const VK_WSI_X11_CONNECTION_INFO* pConnectionInfo) { - VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; - pCurObj = gpuw; + pCurObj = (VkBaseLayerObject *) gpu; loader_platform_thread_once(&tabOnce, initParamChecker); - VkResult result = nextTable.WsiX11AssociateConnection((VkPhysicalGpu)gpuw->nextObject, pConnectionInfo); + VkResult result = nextTable.WsiX11AssociateConnection(gpu, pConnectionInfo); return result; } diff --git a/loader/loader.c b/loader/loader.c index 648a258..dc05376 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -520,11 +520,16 @@ static void loader_init_dispatch_table(VkLayerDispatchTable *tab, PFN_vkGetProcA extern struct loader_icd * loader_get_icd(const VkBaseLayerObject *gpu, uint32_t *gpu_index) { + /* + * NOTE: at this time icd->gpus is pointing to wrapped GPUs, but no where else + * are wrapped gpus used. Should go away. The incoming gpu is NOT wrapped so + * need to test it against the wrapped GPU's base object. + */ for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { for (uint32_t i = 0; i < icd->gpu_count; i++) if ((icd->gpus + i) == gpu || (icd->gpus +i)->baseObject == - gpu->baseObject) { + gpu) { *gpu_index = i; return icd; } @@ -1000,7 +1005,7 @@ LOADER_EXPORT VkResult VKAPI vkEnumerateGpus( (wrapped_gpus + i)->baseObject = gpus[i]; (wrapped_gpus + i)->pGPA = get_proc_addr; (wrapped_gpus + i)->nextObject = gpus[i]; - memcpy(pGpus + count, &wrapped_gpus, sizeof(*pGpus)); + memcpy(pGpus + count, gpus, sizeof(*pGpus)); loader_init_dispatch_table(icd->loader_dispatch + i, get_proc_addr, gpus[i]); diff --git a/loader/loader.h b/loader/loader.h index 77c50c9..0ff9a59 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -65,15 +65,6 @@ static inline void loader_init_data(void *obj, const void *data) loader_set_data(obj, data); } -static inline void *loader_unwrap_gpu(VkPhysicalGpu *gpu) -{ - const VkBaseLayerObject *wrap = (const VkBaseLayerObject *) *gpu; - - *gpu = (VkPhysicalGpu) wrap->nextObject; - - return loader_get_data(wrap->baseObject); -} - struct loader_instance { struct loader_icd *icds; struct loader_instance *next; diff --git a/vk-generate.py b/vk-generate.py index df033c9..af80709 100755 --- a/vk-generate.py +++ b/vk-generate.py @@ -159,18 +159,9 @@ class LoaderEntrypointsSubcommand(Subcommand): func.append(" VkResult res;") func.append("") - # get dispatch table and unwrap GPUs - for param in proto.params: - stmt = "" - if param.ty == "VkPhysicalGpu": - stmt = "loader_unwrap_gpu(&%s);" % param.name - if param == proto.params[0]: - stmt = "disp = " + stmt - elif param == proto.params[0]: - stmt = "disp = loader_get_data(%s);" % param.name - - if stmt: - func.append(" " + stmt) + # get dispatch table + func.append(" disp = loader_get_data(%s);" % + proto.params[0].name) func.append("") # dispatch! diff --git a/vk-layer-generate.py b/vk-layer-generate.py index c97bedf..e95729f 100755 --- a/vk-layer-generate.py +++ b/vk-layer-generate.py @@ -199,7 +199,6 @@ class Subcommand(object): ges_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)') ges_body.append('{') ges_body.append(' VkResult result;') - ges_body.append(' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;') ges_body.append('') ges_body.append(' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */') ges_body.append(' if (!strncmp(pExtName, "%s", strlen("%s")))' % (layer, layer)) @@ -207,7 +206,7 @@ class Subcommand(object): ges_body.append(' result = VK_SUCCESS;') ges_body.append(' } else if (nextTable.GetExtensionSupport != NULL)') ges_body.append(' {') - ges_body.append(' result = nextTable.GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName);') + ges_body.append(' result = nextTable.GetExtensionSupport(gpu, pExtName);') ges_body.append(' } else') ges_body.append(' {') ges_body.append(' result = VK_ERROR_INVALID_EXTENSION;') @@ -447,15 +446,13 @@ class GenericLayerSubcommand(Subcommand): if 'WsiX11AssociateConnection' == proto.name: funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)") if proto.name == "EnumerateLayers": - c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalGpu)gpuw->nextObject", 1) funcs.append('%s%s\n' '{\n' ' char str[1024];\n' ' if (gpu != NULL) {\n' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' ' sprintf(str, "At start of layered %s\\n");\n' ' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n' - ' pCurObj = gpuw;\n' + ' pCurObj = (VkBaseLayerObject *) gpu;\n' ' loader_platform_thread_once(&tabOnce, init%s);\n' ' %snextTable.%s;\n' ' sprintf(str, "Completed layered %s\\n");\n' @@ -470,29 +467,13 @@ class GenericLayerSubcommand(Subcommand): ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' ' return VK_SUCCESS;\n' ' }\n' - '}' % (qual, decl, proto.params[0].name, proto.name, self.layer_name, ret_val, c_call, proto.name, stmt, self.layer_name)) - elif proto.params[0].ty != "VkPhysicalGpu": - funcs.append('%s%s\n' - '{\n' - ' %snextTable.%s;\n' - '%s' - '}' % (qual, decl, ret_val, proto.c_call(), stmt)) + '}' % (qual, decl, proto.name, self.layer_name, ret_val, proto.c_call(), proto.name, stmt, self.layer_name)) else: - c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalGpu)gpuw->nextObject", 1) funcs.append('%s%s\n' '{\n' - ' char str[1024];' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' - ' sprintf(str, "At start of layered %s\\n");\n' - ' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n' - ' pCurObj = gpuw;\n' - ' loader_platform_thread_once(&tabOnce, init%s);\n' ' %snextTable.%s;\n' - ' sprintf(str, "Completed layered %s\\n");\n' - ' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n' - ' fflush(stdout);\n' '%s' - '}' % (qual, decl, proto.params[0].name, proto.name, self.layer_name, ret_val, c_call, proto.name, stmt)) + '}' % (qual, decl, ret_val, proto.c_call(), stmt)) if 'WsiX11QueuePresent' == proto.name: funcs.append("#endif") return "\n\n".join(funcs) @@ -738,8 +719,7 @@ class APIDumpSubcommand(Subcommand): '{\n' ' using namespace StreamControl;\n' ' if (gpu != NULL) {\n' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' - ' pCurObj = gpuw;\n' + ' pCurObj = (VkBaseLayerObject *) gpu;\n' ' loader_platform_thread_once(&tabOnce, init%s);\n' ' %snextTable.%s;\n' ' %s %s %s\n' @@ -752,12 +732,10 @@ class APIDumpSubcommand(Subcommand): ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' ' return VK_SUCCESS;\n' ' }\n' - '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, self.layer_name)) + '}' % (qual, decl, self.layer_name, ret_val, proto.c_call(),f_open, log_func, f_close, stmt, self.layer_name)) elif 'GetExtensionSupport' == proto.name: - c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalGpu)gpuw->nextObject", 1) funcs.append('%s%s\n' '{\n' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' ' VkResult result;\n' ' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */\n' ' if (!strncmp(pExtName, "%s", strlen("%s")))\n' @@ -772,23 +750,11 @@ class APIDumpSubcommand(Subcommand): ' result = VK_ERROR_INVALID_EXTENSION;\n' ' }\n' '%s' - '}' % (qual, decl, proto.params[0].name, self.layer_name, self.layer_name, c_call, f_open, log_func, f_close, stmt)) - elif proto.params[0].ty != "VkPhysicalGpu": - funcs.append('%s%s\n' - '{\n' - ' using namespace StreamControl;\n' - ' %snextTable.%s;\n' - ' %s%s%s\n' - '%s' - '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) + '}' % (qual, decl, self.layer_name, self.layer_name, proto.c_call(), f_open, log_func, f_close, stmt)) else: - c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalGpu)gpuw->nextObject", 1) funcs.append('%s%s\n' '{\n' ' using namespace StreamControl;\n' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' - ' pCurObj = gpuw;\n' - ' loader_platform_thread_once(&tabOnce, init%s);\n' ' %snextTable.%s;\n' ' %s%s%s\n' '%s' @@ -1396,13 +1362,11 @@ class ObjectTrackerSubcommand(Subcommand): if 'WsiX11AssociateConnection' == proto.name: funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)") if proto.name == "EnumerateLayers": - c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalGpu)gpuw->nextObject", 1) funcs.append('%s%s\n' '{\n' ' if (gpu != NULL) {\n' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' ' %s' - ' pCurObj = gpuw;\n' + ' pCurObj = (VkBaseLayerObject *) gpu;\n' ' loader_platform_thread_once(&tabOnce, init%s);\n' ' %snextTable.%s;\n' ' %s%s' @@ -1415,12 +1379,10 @@ class ObjectTrackerSubcommand(Subcommand): ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' ' return VK_SUCCESS;\n' ' }\n' - '}' % (qual, decl, proto.params[0].name, using_line, self.layer_name, ret_val, c_call, create_line, destroy_line, stmt, self.layer_name)) + '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, stmt, self.layer_name)) elif 'GetExtensionSupport' == proto.name: - c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalGpu)gpuw->nextObject", 1) funcs.append('%s%s\n' '{\n' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' ' VkResult result;\n' ' /* This entrypoint is NOT going to init its own dispatch table since loader calls this early */\n' ' if (!strncmp(pExtName, "%s", strlen("%s")) ||\n' @@ -1437,35 +1399,31 @@ class ObjectTrackerSubcommand(Subcommand): ' result = VK_ERROR_INVALID_EXTENSION;\n' ' }\n' '%s' - '}' % (qual, decl, proto.params[0].name, self.layer_name, self.layer_name, using_line, c_call, stmt)) - elif proto.params[0].ty != "VkPhysicalGpu": + '}' % (qual, decl, self.layer_name, self.layer_name, using_line, proto.c_call(), stmt)) + elif 'GetGpuInfo' in proto.name: + gpu_state = ' if (infoType == VK_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES) {\n' + gpu_state += ' if (pData != NULL) {\n' + gpu_state += ' setGpuQueueInfoState(pData);\n' + gpu_state += ' }\n' + gpu_state += ' }\n' funcs.append('%s%s\n' '{\n' '%s' + ' pCurObj = (VkBaseLayerObject *) gpu;\n' + ' loader_platform_thread_once(&tabOnce, init%s);\n' ' %snextTable.%s;\n' '%s%s' '%s' - '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt)) + '%s' + '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, gpu_state, stmt)) else: - c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalGpu)gpuw->nextObject", 1) - gpu_state = '' - if 'GetGpuInfo' in proto.name: - gpu_state = ' if (infoType == VK_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES) {\n' - gpu_state += ' if (pData != NULL) {\n' - gpu_state += ' setGpuQueueInfoState(pData);\n' - gpu_state += ' }\n' - gpu_state += ' }\n' funcs.append('%s%s\n' '{\n' - ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' '%s' - ' pCurObj = gpuw;\n' - ' loader_platform_thread_once(&tabOnce, init%s);\n' ' %snextTable.%s;\n' '%s%s' '%s' - '%s' - '}' % (qual, decl, proto.params[0].name, using_line, self.layer_name, ret_val, c_call, create_line, destroy_line, gpu_state, stmt)) + '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt)) if 'WsiX11QueuePresent' == proto.name: funcs.append("#endif") return "\n\n".join(funcs) -- 2.7.4