/* * Vulkan * * Copyright (C) 2014 LunarG, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include "vk_dispatch_table_helper.h" #include "vkLayer.h" std::unordered_map tableMap; std::unordered_map tableInstanceMap; /* Various dispatchable objects will use the same underlying dispatch table if they * are created from that "parent" object. Thus use pointer to dispatch table * as the key to these table maps. * Instance -> PhysicalDevice * Device -> CmdBuffer or Queue * If use the object themselves as key to map then implies Create entrypoints have to be intercepted * and a new key inserted into map */ VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instancew) { VkLayerInstanceDispatchTable *pTable; assert(instancew); VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instancew->baseObject; std::unordered_map::const_iterator it = tableInstanceMap.find((void *) *ppDisp); if (it == tableInstanceMap.end()) { pTable = new VkLayerInstanceDispatchTable; tableInstanceMap[(void *) *ppDisp] = pTable; } else { return it->second; } layer_init_instance_dispatch_table(pTable, instancew); return pTable; } VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw) { VkLayerDispatchTable *pTable; assert(devw); VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject); std::unordered_map::const_iterator it = tableMap.find((void *) *ppDisp); if (it == tableMap.end()) { pTable = new VkLayerDispatchTable; tableMap[(void *) *ppDisp] = pTable; } else { return it->second; } layer_initialize_dispatch_table(pTable, devw); return pTable; }