Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <assert.h> |
| 29 | #include <unordered_map> |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 30 | #include "loader_platform.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | #include "vk_dispatch_table_helper.h" |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame^] | 32 | #include "vk_layer.h" |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 33 | // The following is #included again to catch certain OS-specific functions |
| 34 | // being used: |
| 35 | #include "loader_platform.h" |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 36 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 37 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 38 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 39 | /* Various dispatchable objects will use the same underlying dispatch table if they |
| 40 | * are created from that "parent" object. Thus use pointer to dispatch table |
| 41 | * as the key to table maps (tableMap1, tableInstanceMap1, tableMap2, tableInstanceMap2. |
| 42 | * Instance -> PhysicalDevice |
| 43 | * Device -> CmdBuffer or Queue |
| 44 | * If use the object themselves as key to map then implies Create entrypoints have to be intercepted |
| 45 | * and a new key inserted into map */ |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 46 | /******************************** Layer multi1 functions **************************/ |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 47 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap1; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 48 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap1; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 49 | static bool layer1_first_activated = false; |
| 50 | |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 51 | // Map lookup must be thread safe |
| 52 | static inline VkLayerDispatchTable *device_dispatch_table1(VkObject object) |
| 53 | { |
| 54 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; |
| 55 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap1.find((void *) pDisp); |
| 56 | assert(it != tableMap1.end() && "Not able to find device dispatch entry"); |
| 57 | return it->second; |
| 58 | } |
| 59 | |
| 60 | static inline VkLayerInstanceDispatchTable *instance_dispatch_table1(VkObject object) |
| 61 | { |
| 62 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; |
| 63 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap1.find((void *) pDisp); |
| 64 | assert(it != tableInstanceMap1.end() && "Not able to find instance dispatch entry"); |
| 65 | return it->second; |
| 66 | } |
| 67 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 68 | static VkLayerDispatchTable *getLayer1Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 69 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 70 | VkLayerDispatchTable *pTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 71 | assert(devw); |
| 72 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 73 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 74 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap1.find((void *) *ppDisp); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 75 | if (it == tableMap1.end()) |
| 76 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 77 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 78 | tableMap1[(void *) *ppDisp] = pTable; |
| 79 | initLayerTable(devw, pTable, 1); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 80 | return pTable; |
| 81 | } else |
| 82 | { |
| 83 | return it->second; |
| 84 | } |
| 85 | } |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 86 | static VkLayerInstanceDispatchTable *getLayer1InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 87 | { |
| 88 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 89 | assert(instw); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 90 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 91 | |
| 92 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap1.find((void *) *ppDisp); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 93 | if (it == tableInstanceMap1.end()) |
| 94 | { |
| 95 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 96 | tableInstanceMap1[(void *) *ppDisp] = pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 97 | initLayerInstanceTable(instw, pTable, 1); |
| 98 | return pTable; |
| 99 | } else |
| 100 | { |
| 101 | return it->second; |
| 102 | } |
| 103 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 104 | #ifdef __cplusplus |
| 105 | extern "C" { |
| 106 | #endif |
| 107 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 108 | /* hook DextroyDevice to remove tableMap entry */ |
| 109 | VK_LAYER_EXPORT VkResult VKAPI multi1DestroyDevice(VkDevice device) |
| 110 | { |
| 111 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 112 | VkResult res = device_dispatch_table1(device)->DestroyDevice(device); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 113 | tableMap1.erase(pDisp); |
| 114 | return res; |
| 115 | } |
| 116 | |
| 117 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 118 | VK_LAYER_EXPORT VkResult VKAPI multi1DestroyInstance(VkInstance instance) |
| 119 | { |
| 120 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 121 | VkResult res = instance_dispatch_table1(instance)->DestroyInstance(instance); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 122 | tableInstanceMap1.erase(pDisp); |
| 123 | return res; |
| 124 | } |
| 125 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 126 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 127 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 128 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 129 | |
| 130 | printf("At start of multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 131 | VkResult result = device_dispatch_table1(device)->CreateSampler(device, pCreateInfo, pSampler); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 132 | printf("Completed multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 133 | return result; |
| 134 | } |
| 135 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 136 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, |
| 137 | VkPipeline* pPipeline) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 138 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 139 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 140 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 141 | printf("At start of multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 142 | VkResult result = device_dispatch_table1(device)->CreateGraphicsPipeline(device, pCreateInfo, pPipeline); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 143 | printf("Completed multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 144 | return result; |
| 145 | } |
| 146 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 147 | VK_LAYER_EXPORT VkResult VKAPI multi1StorePipeline(VkDevice device, VkPipeline pipeline, size_t* pDataSize, void* pData) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 148 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 149 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 150 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 151 | printf("At start of multi1 layer vkStorePipeline()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 152 | VkResult result = device_dispatch_table1(device)->StorePipeline(device, pipeline, pDataSize, pData); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 153 | printf("Completed multi1 layer vkStorePipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 154 | return result; |
| 155 | } |
| 156 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 157 | VK_LAYER_EXPORT void * VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 158 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 159 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 160 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 161 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 162 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 163 | |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 164 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 165 | |
| 166 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
| 167 | getLayer1Table(devw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 168 | return (void *) multi1GetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 169 | } |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 170 | if (!strcmp("vkDestroyDevice", pName)) |
| 171 | return (void *) multi1DestroyDevice; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 172 | if (!strcmp("vkCreateSampler", pName)) |
| 173 | return (void *) multi1CreateSampler; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 174 | if (!strcmp("vkCreateGraphicsPipeline", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 175 | return (void *) multi1CreateGraphicsPipeline; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 176 | if (!strcmp("vkStorePipeline", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 177 | return (void *) multi1StorePipeline; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 178 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 179 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 180 | VkLayerDispatchTable* pTable = device_dispatch_table1(device); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 181 | if (pTable->GetDeviceProcAddr == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 182 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 183 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 187 | VK_LAYER_EXPORT void * VKAPI multi1GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 188 | { |
| 189 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 190 | |
| 191 | if (inst == NULL) |
| 192 | return NULL; |
| 193 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 194 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 195 | |
| 196 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
| 197 | getLayer1InstanceTable(instw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 198 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 199 | } |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 200 | if (!strcmp("vkDestroyInstance", pName)) |
| 201 | return (void *) multi1DestroyInstance; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 202 | if (!strcmp("GetGlobalExtensionProperties", pName)) |
| 203 | return (void*) vkGetGlobalExtensionProperties; |
| 204 | if (!strcmp("GetGlobalExtensionCount", pName)) |
| 205 | return (void*) vkGetGlobalExtensionCount; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 206 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 207 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 208 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table1(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 209 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 210 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 211 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 212 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 216 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 217 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap2; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 218 | static bool layer2_first_activated = false; |
| 219 | |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 220 | // Map lookup must be thread safe |
| 221 | static inline VkLayerDispatchTable *device_dispatch_table2(VkObject object) |
| 222 | { |
| 223 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; |
| 224 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) pDisp); |
| 225 | assert(it != tableMap2.end() && "Not able to find device dispatch entry"); |
| 226 | return it->second; |
| 227 | } |
| 228 | |
| 229 | static inline VkLayerInstanceDispatchTable *instance_dispatch_table2(VkObject object) |
| 230 | { |
| 231 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; |
| 232 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) pDisp); |
| 233 | assert(it != tableInstanceMap2.end() && "Not able to find instance dispatch entry"); |
| 234 | return it->second; |
| 235 | } |
| 236 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 237 | static VkLayerInstanceDispatchTable *getLayer2InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 238 | { |
| 239 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 240 | assert(instw); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 241 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 242 | |
| 243 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) *ppDisp); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 244 | if (it == tableInstanceMap2.end()) |
| 245 | { |
| 246 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 247 | tableInstanceMap2[(void *) *ppDisp] = pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 248 | initLayerInstanceTable(instw, pTable, 2); |
| 249 | return pTable; |
| 250 | } else |
| 251 | { |
| 252 | return it->second; |
| 253 | } |
| 254 | } |
| 255 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 256 | static VkLayerDispatchTable *getLayer2Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 257 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 258 | VkLayerDispatchTable *pTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 259 | assert(devw); |
| 260 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 261 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 262 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) *ppDisp); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 263 | if (it == tableMap2.end()) |
| 264 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 265 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 266 | tableMap2[(void *) *ppDisp] = pTable; |
| 267 | initLayerTable(devw, pTable, 2); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 268 | return pTable; |
| 269 | } else |
| 270 | { |
| 271 | return it->second; |
| 272 | } |
| 273 | } |
| 274 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 275 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices( |
| 276 | VkInstance instance, |
| 277 | uint32_t* pPhysicalDeviceCount, |
| 278 | VkPhysicalDevice* pPhysicalDevices) |
| 279 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 280 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 281 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 282 | printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 283 | VkResult result = instance_dispatch_table2(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 284 | printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); |
| 285 | return result; |
| 286 | } |
| 287 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 288 | /* hook DextroyDevice to remove tableMap entry */ |
| 289 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyDevice(VkDevice device) |
| 290 | { |
| 291 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 292 | VkResult res = device_dispatch_table2(device)->DestroyDevice(device); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 293 | tableMap2.erase(pDisp); |
| 294 | return res; |
| 295 | } |
| 296 | |
| 297 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 298 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyInstance(VkInstance instance) |
| 299 | { |
| 300 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 301 | VkResult res = instance_dispatch_table2(instance)->DestroyInstance(instance); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 302 | tableInstanceMap2.erase(pDisp); |
| 303 | return res; |
| 304 | } |
| 305 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 306 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 307 | VkDevice* pDevice) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 308 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 309 | printf("At start of multi2 vkCreateDevice()\n"); |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 310 | VkResult result = device_dispatch_table2(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 311 | printf("Completed multi2 layer vkCreateDevice()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 312 | return result; |
| 313 | } |
| 314 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 315 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, |
| 316 | VkCmdBuffer* pCmdBuffer) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 317 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 318 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 319 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 320 | printf("At start of multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 321 | VkResult result = device_dispatch_table2(device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 322 | printf("Completed multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 323 | return result; |
| 324 | } |
| 325 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 326 | VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 327 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 328 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) cmdBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 329 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 330 | printf("At start of multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 331 | VkResult result = device_dispatch_table2(cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 332 | printf("Completed multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 333 | return result; |
| 334 | |
| 335 | } |
| 336 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 337 | VK_LAYER_EXPORT void * VKAPI multi2GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 338 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 339 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 340 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 341 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 342 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 343 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 344 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
| 345 | getLayer2Table(devw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 346 | return (void *) multi2GetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 347 | } |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 348 | if (!strcmp("vkCreateDevice", pName)) |
| 349 | return (void *) multi2CreateDevice; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 350 | if (!strcmp("vkDestroyDevice", pName)) |
| 351 | return (void *) multi2DestroyDevice; |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 352 | if (!strcmp("vkCreateCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 353 | return (void *) multi2CreateCommandBuffer; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 354 | else if (!strcmp("vkBeginCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 355 | return (void *) multi2BeginCommandBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 356 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 357 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 358 | VkLayerDispatchTable* pTable = device_dispatch_table2(device); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 359 | if (pTable->GetDeviceProcAddr == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 360 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 361 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 365 | VK_LAYER_EXPORT void * VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 366 | { |
| 367 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 368 | |
| 369 | if (inst == NULL) |
| 370 | return NULL; |
| 371 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 372 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
| 373 | getLayer2InstanceTable(instw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 374 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 375 | } |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 376 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
| 377 | return (void *) multi2EnumeratePhysicalDevices; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 378 | if (!strcmp("vkDestroyInstance", pName)) |
| 379 | return (void *) multi2DestroyInstance; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 380 | else if (!strcmp("GetGlobalExtensionProperties", pName)) |
| 381 | return (void*) vkGetGlobalExtensionProperties; |
| 382 | else if (!strcmp("GetGlobalExtensionCount", pName)) |
| 383 | return (void*) vkGetGlobalExtensionCount; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 384 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 385 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 386 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table2(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 387 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 388 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 389 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 390 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /********************************* Common functions ********************************/ |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 394 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 395 | struct extProps { |
| 396 | uint32_t version; |
| 397 | const char * const name; |
| 398 | }; |
| 399 | |
| 400 | #define MULTI_LAYER_EXT_ARRAY_SIZE 2 |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 401 | static const VkExtensionProperties multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = { |
| 402 | { |
| 403 | VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 404 | "multi1", |
| 405 | 0x10, |
| 406 | "Sample layer: multi", |
| 407 | // 0, |
| 408 | // NULL, |
| 409 | }, |
| 410 | { |
| 411 | VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 412 | "multi2", |
| 413 | 0x10, |
| 414 | "Sample layer: multi", |
| 415 | // 0, |
| 416 | // NULL, |
| 417 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 418 | }; |
| 419 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 420 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionCount( |
| 421 | uint32_t* pCount) |
| 422 | { |
| 423 | *pCount = MULTI_LAYER_EXT_ARRAY_SIZE; |
| 424 | return VK_SUCCESS; |
| 425 | } |
| 426 | |
| 427 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 428 | uint32_t extensionIndex, |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 429 | VkExtensionProperties* pProperties) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 430 | { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 431 | /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */ |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 432 | if (extensionIndex >= MULTI_LAYER_EXT_ARRAY_SIZE) |
| 433 | return VK_ERROR_INVALID_VALUE; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 434 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 435 | memcpy(pProperties, &multiExts[extensionIndex], sizeof(VkExtensionProperties)); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 436 | |
| 437 | return VK_SUCCESS; |
| 438 | } |
| 439 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 440 | VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 441 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 442 | // to find each layers GPA routine Loader will search via "<layerName>GetDeviceProcAddr" |
| 443 | if (!strcmp("multi1GetDeviceProcAddr", pName)) |
| 444 | return (void *) multi1GetDeviceProcAddr; |
| 445 | else if (!strcmp("multi2GetDeviceProcAddr", pName)) |
| 446 | return (void *) multi2GetDeviceProcAddr; |
| 447 | else if (!strcmp("vkGetDeviceProcAddr", pName)) |
| 448 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 449 | |
| 450 | // use first layer activated as GPA dispatch table activation happens in order |
| 451 | else if (layer1_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 452 | return multi1GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 453 | else if (layer2_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 454 | return multi2GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 455 | else |
| 456 | return NULL; |
| 457 | |
| 458 | } |
| 459 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 460 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* pName) |
| 461 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 462 | // to find each layers GPA routine Loader will search via "<layerName>GetInstanceProcAddr" |
| 463 | if (!strcmp("multi1GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 464 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 465 | else if (!strcmp("multi2GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 466 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 467 | else if (!strcmp("vkGetInstanceProcAddr", pName)) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 468 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 469 | |
| 470 | // use first layer activated as GPA dispatch table activation happens in order |
| 471 | else if (layer1_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 472 | return multi1GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 473 | else if (layer2_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 474 | return multi2GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 475 | else |
| 476 | return NULL; |
| 477 | |
| 478 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 479 | #ifdef __cplusplus |
| 480 | } //extern "C" |
| 481 | #endif |
| 482 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 483 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 484 | { |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 485 | if (layerNum == 2 && layer1_first_activated == false) |
| 486 | layer2_first_activated = true; |
| 487 | if (layerNum == 1 && layer2_first_activated == false) |
| 488 | layer1_first_activated = true; |
| 489 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 490 | layer_initialize_dispatch_table(pTable, devw); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 491 | } |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 492 | |
| 493 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum) |
| 494 | { |
| 495 | if (layerNum == 2 && layer1_first_activated == false) |
| 496 | layer2_first_activated = true; |
| 497 | if (layerNum == 1 && layer2_first_activated == false) |
| 498 | layer1_first_activated = true; |
| 499 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 500 | layer_init_instance_dispatch_table(pTable, instw); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 501 | } |