diff options
| author | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-06-13 21:18:30 -0600 |
|---|---|---|
| committer | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-06-18 10:22:56 -0600 |
| commit | 03b7c7b58b4c6d3be53804e68eb94dcbcbef4a75 (patch) | |
| tree | 9aa6dfe01e5539d814de84460313bf3ba8cc3fb3 | |
| parent | 5f661feae9c4957a61a9a6b355d86232987a42b1 (diff) | |
| download | usermoji-03b7c7b58b4c6d3be53804e68eb94dcbcbef4a75.tar.xz | |
layers: utilities for layer storage
Have defined tableMap and tableInstanceMap as
static here to prevent layers from accidentally using
a common map. Moved all the access functions here as well
to be able to access the static maps.
Added destroy functions to eliminate last of references
to tableMap and tableInstanceMap maps outside this file.
| -rw-r--r-- | layers/layers_table.cpp | 96 | ||||
| -rw-r--r-- | layers/layers_table.h | 42 |
2 files changed, 100 insertions, 38 deletions
diff --git a/layers/layers_table.cpp b/layers/layers_table.cpp index da28be98..43450174 100644 --- a/layers/layers_table.cpp +++ b/layers/layers_table.cpp @@ -26,10 +26,96 @@ #include "vk_dispatch_table_helper.h" #include "vkLayer.h" #include "layers_table.h" -device_table_map tableMap; -instance_table_map tableInstanceMap; +static device_table_map tableMap; +static instance_table_map tableInstanceMap; +// Map lookup must be thread safe +VkLayerDispatchTable *device_dispatch_table(VkObject object) +{ +// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; + dispatch_key key = get_dispatch_key(object); + device_table_map::const_iterator it = tableMap.find((void *) key); + assert(it != tableMap.end() && "Not able to find device dispatch entry"); + return it->second; +} + +VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object) +{ +// VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; + dispatch_key key = get_dispatch_key(object); + instance_table_map::const_iterator it = tableInstanceMap.find((void *) key); + if (it != tableInstanceMap.end()) { + fprintf(stderr, "instance_dispatch_table: map: %p, object: %p, key: %p, table: %p\n", &tableInstanceMap, object, key, it->second); + } else { + fprintf(stderr, "instance_dispatch_table: map: %p, object: %p, key: %p, table: UNKNOWN\n", &tableInstanceMap, object, key); + } + assert(it != tableInstanceMap.end() && "Not able to find instance dispatch entry"); + return it->second; +} + +void destroy_dispatch_table(device_table_map &map, dispatch_key key) +{ + device_table_map::const_iterator it = map.find((void *) key); + if (it != map.end()) { + fprintf(stderr, "destroy device dispatch_table: map: %p, key: %p, table: %p\n", &map, key, it->second); + } else { + fprintf(stderr, "destroy device dispatch table: map: %p, key: %p, table: UNKNOWN\n", &map, key); + assert(it != map.end()); + } + map.erase(key); +} + +void destroy_dispatch_table(instance_table_map &map, dispatch_key key) +{ + instance_table_map::const_iterator it = map.find((void *) key); + if (it != map.end()) { + fprintf(stderr, "destroy instance dispatch_table: map: %p, key: %p, table: %p\n", &map, key, it->second); + } else { + fprintf(stderr, "destroy instance dispatch table: map: %p, key: %p, table: UNKNOWN\n", &map, key); + assert(it != map.end()); + } + map.erase(key); +} + +void destroy_device_dispatch_table(dispatch_key key) +{ + destroy_dispatch_table(tableMap, key); +} + +void destroy_instance_dispatch_table(dispatch_key key) +{ + destroy_dispatch_table(tableInstanceMap, key); +} + +VkLayerDispatchTable *get_dispatch_table(device_table_map &map, VkObject object) +{ +// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; + dispatch_key key = get_dispatch_key(object); + device_table_map::const_iterator it = map.find((void *) key); + if (it != map.end()) { + fprintf(stderr, "instance_dispatch_table: map: %p, object: %p, key: %p, table: %p\n", &tableInstanceMap, object, key, it->second); + } else { + fprintf(stderr, "instance_dispatch_table: map: %p, object: %p, key: %p, table: UNKNOWN\n", &tableInstanceMap, object, key); + } + assert(it != map.end() && "Not able to find device dispatch entry"); + return it->second; +} + +VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, VkObject object) +{ +// VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; + dispatch_key key = get_dispatch_key(object); + instance_table_map::const_iterator it = map.find((void *) key); + if (it != map.end()) { + fprintf(stderr, "instance_dispatch_table: map: %p, object: %p, key: %p, table: %p\n", &tableInstanceMap, object, key, it->second); + } else { + fprintf(stderr, "instance_dispatch_table: map: %p, object: %p, key: %p, table: UNKNOWN\n", &tableInstanceMap, object, key); + } + assert(it != map.end() && "Not able to find instance dispatch entry"); + return it->second; +} + /* 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. @@ -48,8 +134,11 @@ VkLayerInstanceDispatchTable * initInstanceTable(instance_table_map &map, const { pTable = new VkLayerInstanceDispatchTable; map[(void *) *ppDisp] = pTable; + fprintf(stderr, "New, Instance: map: %p, base object: %p, key: %p, table: %p\n", &map, instancew, *ppDisp, pTable); + assert(map.size() <= 1 && "Instance dispatch table map has more than one entry"); } else { + fprintf(stderr, "Instance: map: %p, base object: %p, key: %p, table: %p\n", &map, instancew, *ppDisp, it->second); return it->second; } @@ -75,9 +164,10 @@ VkLayerDispatchTable * initDeviceTable(device_table_map &map, const VkBaseLayerO { layer_device_table = new VkLayerDispatchTable; map[(void *) base_device_table] = layer_device_table; - fprintf(stderr, "initDeviceTable(%p): %p => %p\n", devw, base_device_table, layer_device_table); + fprintf(stderr, "New, Device: map: %p, base object: %p, key: %p, table: %p\n", &map, devw, *ppDisp, layer_device_table); } else { + fprintf(stderr, "Device: map: %p, base object: %p, key: %p, table: %p\n", &map, devw, *ppDisp, it->second); return it->second; } diff --git a/layers/layers_table.h b/layers/layers_table.h index cae3d6e6..24f0bd4e 100644 --- a/layers/layers_table.h +++ b/layers/layers_table.h @@ -27,8 +27,6 @@ typedef std::unordered_map<void *, VkLayerDispatchTable *> device_table_map; typedef std::unordered_map<void *, VkLayerInstanceDispatchTable *> instance_table_map; -extern device_table_map tableMap; -extern instance_table_map tableInstanceMap; VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw); VkLayerDispatchTable * initDeviceTable(device_table_map &map, const VkBaseLayerObject *devw); VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instancew); @@ -41,39 +39,13 @@ static inline dispatch_key get_dispatch_key(VkObject object) return (dispatch_key) *(VkLayerDispatchTable **) object; } -// Map lookup must be thread safe -static inline VkLayerDispatchTable *device_dispatch_table(VkObject object) -{ -// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; - dispatch_key key = get_dispatch_key(object); - device_table_map::const_iterator it = tableMap.find((void *) key); - assert(it != tableMap.end() && "Not able to find device dispatch entry"); - return it->second; -} +VkLayerDispatchTable *device_dispatch_table(VkObject object); -static inline VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object) -{ -// VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; - dispatch_key key = get_dispatch_key(object); - instance_table_map::const_iterator it = tableInstanceMap.find((void *) key); - assert(it != tableInstanceMap.end() && "Not able to find instance dispatch entry"); - return it->second; -} +VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object); -static inline VkLayerDispatchTable *get_dispatch_table(device_table_map &map, VkObject object) -{ -// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; - dispatch_key key = get_dispatch_key(object); - device_table_map::const_iterator it = map.find((void *) key); - assert(it != map.end() && "Not able to find device dispatch entry"); - return it->second; -} +VkLayerDispatchTable *get_dispatch_table(device_table_map &map, VkObject object); -static inline VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, VkObject object) -{ -// VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; - dispatch_key key = get_dispatch_key(object); - instance_table_map::const_iterator it = map.find((void *) key); - assert(it != map.end() && "Not able to find instance dispatch entry"); - return it->second; -} +VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, VkObject object); + +void destroy_device_dispatch_table(dispatch_key key); +void destroy_instance_dispatch_table(dispatch_key key); |
