From af4e8327f8319ab97bfbe71c907eaabd329704bc Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Sat, 13 Jun 2015 21:22:12 -0600 Subject: layers: Use static dispatch table maps Changes to use dispatch table access functions. --- layers/basic.cpp | 8 ++++---- layers/param_checker.cpp | 10 +++++----- layers/shader_checker.cpp | 12 ++++++------ vk-layer-generate.py | 30 ++++++++++++++++-------------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/layers/basic.cpp b/layers/basic.cpp index 81cdaa8b..d6ea963a 100644 --- a/layers/basic.cpp +++ b/layers/basic.cpp @@ -118,18 +118,18 @@ VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDevi /* hook DestroyDevice to remove tableMap entry */ VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) { - VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; + dispatch_key key = get_dispatch_key(device); VkResult res = device_dispatch_table(device)->DestroyDevice(device); - tableMap.erase(pDisp); + destroy_device_dispatch_table(key); return res; } /* hook DestroyInstance to remove tableInstanceMap entry */ VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance) { - VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; + dispatch_key key = get_dispatch_key(instance); VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance); - tableInstanceMap.erase(pDisp); + destroy_instance_dispatch_table(key); return res; } diff --git a/layers/param_checker.cpp b/layers/param_checker.cpp index c1a6fef5..0b13b65c 100644 --- a/layers/param_checker.cpp +++ b/layers/param_checker.cpp @@ -146,9 +146,9 @@ VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCre VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance) { - VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; + dispatch_key key = get_dispatch_key(instance); VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance); - tableInstanceMap.erase(pDisp); + destroy_instance_dispatch_table(key); return res; } @@ -267,8 +267,9 @@ VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDevi VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) { VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; + dispatch_key key = get_dispatch_key(device); VkResult result = device_dispatch_table(device)->DestroyDevice(device); - tableMap.erase(pDisp); + destroy_device_dispatch_table(key); tableDebugMarkerMap.erase(pDisp); deviceExtMap.erase(pDisp); return result; @@ -1878,8 +1879,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback( VkInstance instance, VkDbgMsgCallback msgCallback) { - VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; - VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp]; + VkLayerInstanceDispatchTable *pTable = instance_dispatch_table(instance); return layer_destroy_msg_callback(instance, pTable, msgCallback); } diff --git a/layers/shader_checker.cpp b/layers/shader_checker.cpp index 57aab4f0..c3323d7d 100644 --- a/layers/shader_checker.cpp +++ b/layers/shader_checker.cpp @@ -887,9 +887,9 @@ vkCreateGraphicsPipelineDerivative(VkDevice device, /* hook DextroyDevice to remove tableMap entry */ VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) { - VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; + dispatch_key key = get_dispatch_key(device); VkResult res = device_dispatch_table(device)->DestroyDevice(device); - tableMap.erase(pDisp); + destroy_device_dispatch_table(key); return res; } @@ -921,9 +921,9 @@ VkResult VKAPI vkCreateInstance( /* hook DestroyInstance to remove tableInstanceMap entry */ VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance) { - VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; + dispatch_key key = get_dispatch_key(instance); VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance); - tableInstanceMap.erase(pDisp); + destroy_instance_dispatch_table(key); return res; } @@ -934,7 +934,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback( void* pUserData, VkDbgMsgCallback* pMsgCallback) { - VkLayerInstanceDispatchTable *pTable = tableInstanceMap[(VkBaseLayerObject *)instance]; + VkLayerInstanceDispatchTable *pTable = instance_dispatch_table(instance); return layer_create_msg_callback(instance, pTable, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); } @@ -942,7 +942,7 @@ VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback( VkInstance instance, VkDbgMsgCallback msgCallback) { - VkLayerInstanceDispatchTable *pTable = tableInstanceMap[(VkBaseLayerObject *)instance]; + VkLayerInstanceDispatchTable *pTable = instance_dispatch_table(instance); return layer_destroy_msg_callback(instance, pTable, msgCallback); } diff --git a/vk-layer-generate.py b/vk-layer-generate.py index bc40f7a3..2f3d576e 100755 --- a/vk-layer-generate.py +++ b/vk-layer-generate.py @@ -564,17 +564,17 @@ class GenericLayerSubcommand(Subcommand): elif proto.name == "DestroyDevice": funcs.append('%s%s\n' '{\n' - ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' + ' dispatch_key key = get_dispatch_key(device);\n' ' VkResult res = device_dispatch_table(device)->DestroyDevice(device);\n' - ' tableMap.erase(pDisp);\n' + ' destroy_device_dispatch_table(key);\n' ' return res;\n' '}\n' % (qual, decl)) elif proto.name == "DestroyInstance": funcs.append('%s%s\n' '{\n' - ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' + ' dispatch_key key = get_dispatch_key(instance);\n' ' VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);\n' - ' tableInstanceMap.erase(pDisp);\n' + ' destroy_instance_dispatch_table(key);\n' ' return res;\n' '}\n' % (qual, decl)) else: @@ -881,9 +881,9 @@ class APIDumpSubcommand(Subcommand): funcs.append('%s%s\n' '{\n' ' using namespace StreamControl;\n' - ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' + ' dispatch_key key = get_dispatch_key(device);\n' ' %s%s_dispatch_table(%s)->%s;\n' - ' tableMap.erase(pDisp);\n' + ' destroy_device_dispatch_table(key);\n' ' %s%s%s\n' '%s' '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) @@ -891,9 +891,9 @@ class APIDumpSubcommand(Subcommand): funcs.append('%s%s\n' '{\n' ' using namespace StreamControl;\n' - ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' + ' dispatch_key key = get_dispatch_key(instance);\n' ' %s%s_dispatch_table(%s)->%s;\n' - ' tableInstanceMap.erase(pDisp);\n' + ' destroy_instance_dispatch_table(key);\n' ' %s%s%s\n' '%s' '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) @@ -1255,7 +1255,7 @@ class ObjectTrackerSubcommand(Subcommand): destroy_line += ' destroy_obj(%s);\n' % (proto.params[2].name) destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' elif 'DestroyDevice' in proto.name: - using_line = ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' + using_line = ' dispatch_key key = get_dispatch_key(device);\n' destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' destroy_line += ' destroy_obj(device);\n' destroy_line += ' // Report any remaining objects\n' @@ -1272,8 +1272,9 @@ class ObjectTrackerSubcommand(Subcommand): destroy_line += ' // Clean up Queue\'s MemRef Linked Lists\n' destroy_line += ' destroyQueueMemRefLists();\n' destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' + destroy_line += ' destroy_device_dispatch_table(key);\n' elif 'DestroyInstance' in proto.name: - using_line = ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' + using_line = ' dispatch_key key = get_dispatch_key(instance);\n' destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' destroy_line += ' destroy_obj(%s);\n' % (param0_name) destroy_line += ' // Report any remaining objects in LL\n' @@ -1287,6 +1288,7 @@ class ObjectTrackerSubcommand(Subcommand): destroy_line += ' }\n' destroy_line += ' }\n' destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' + destroy_line += ' destroy_instance_dispatch_table(key);\n' elif 'Free' in proto.name: destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' destroy_line += ' destroy_obj(%s);\n' % (proto.params[1].name) @@ -1496,18 +1498,18 @@ class ThreadingSubcommand(Subcommand): if proto.name == "DestroyDevice": funcs.append('%s%s\n' '{\n' - ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' + ' dispatch_key key = get_dispatch_key(device);\n' ' %s%s_dispatch_table(%s)->%s;\n' - ' tableMap.erase(pDisp);\n' + ' destroy_device_dispatch_table(key);\n' ' return result;\n' '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) return "\n".join(funcs); elif proto.name == "DestroyInstance": funcs.append('%s%s\n' '{\n' - ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' + ' dispatch_key key = get_dispatch_key(instance);\n' ' %s%s_dispatch_table(%s)->%s;\n' - ' tableInstanceMap.erase(pDisp);\n' + ' destroy_instance_dispatch_table(key);\n' ' return result;\n' '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) return "\n".join(funcs); -- cgit v1.2.3