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" |
| 32 | #include "vkLayer.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; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 202 | if (!strcmp("GetGlobalExtensionInfo", pName)) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 203 | return (void*) vkGetGlobalExtensionInfo; |
| 204 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 205 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 206 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table1(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 207 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 208 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 209 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 210 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 214 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 215 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap2; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 216 | static bool layer2_first_activated = false; |
| 217 | |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 218 | // Map lookup must be thread safe |
| 219 | static inline VkLayerDispatchTable *device_dispatch_table2(VkObject object) |
| 220 | { |
| 221 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; |
| 222 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) pDisp); |
| 223 | assert(it != tableMap2.end() && "Not able to find device dispatch entry"); |
| 224 | return it->second; |
| 225 | } |
| 226 | |
| 227 | static inline VkLayerInstanceDispatchTable *instance_dispatch_table2(VkObject object) |
| 228 | { |
| 229 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; |
| 230 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) pDisp); |
| 231 | assert(it != tableInstanceMap2.end() && "Not able to find instance dispatch entry"); |
| 232 | return it->second; |
| 233 | } |
| 234 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 235 | static VkLayerInstanceDispatchTable *getLayer2InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 236 | { |
| 237 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 238 | assert(instw); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 239 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 240 | |
| 241 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) *ppDisp); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 242 | if (it == tableInstanceMap2.end()) |
| 243 | { |
| 244 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 245 | tableInstanceMap2[(void *) *ppDisp] = pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 246 | initLayerInstanceTable(instw, pTable, 2); |
| 247 | return pTable; |
| 248 | } else |
| 249 | { |
| 250 | return it->second; |
| 251 | } |
| 252 | } |
| 253 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 254 | static VkLayerDispatchTable *getLayer2Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 255 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 256 | VkLayerDispatchTable *pTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 257 | assert(devw); |
| 258 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 259 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 260 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) *ppDisp); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 261 | if (it == tableMap2.end()) |
| 262 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 263 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 264 | tableMap2[(void *) *ppDisp] = pTable; |
| 265 | initLayerTable(devw, pTable, 2); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 266 | return pTable; |
| 267 | } else |
| 268 | { |
| 269 | return it->second; |
| 270 | } |
| 271 | } |
| 272 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 273 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices( |
| 274 | VkInstance instance, |
| 275 | uint32_t* pPhysicalDeviceCount, |
| 276 | VkPhysicalDevice* pPhysicalDevices) |
| 277 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 278 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 279 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 280 | printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 281 | VkResult result = instance_dispatch_table2(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 282 | printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); |
| 283 | return result; |
| 284 | } |
| 285 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 286 | /* hook DextroyDevice to remove tableMap entry */ |
| 287 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyDevice(VkDevice device) |
| 288 | { |
| 289 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 290 | VkResult res = device_dispatch_table2(device)->DestroyDevice(device); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 291 | tableMap2.erase(pDisp); |
| 292 | return res; |
| 293 | } |
| 294 | |
| 295 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 296 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyInstance(VkInstance instance) |
| 297 | { |
| 298 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 299 | VkResult res = instance_dispatch_table2(instance)->DestroyInstance(instance); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 300 | tableInstanceMap2.erase(pDisp); |
| 301 | return res; |
| 302 | } |
| 303 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 304 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 305 | VkDevice* pDevice) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 306 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 307 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | printf("At start of multi2 vkCreateDevice()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 309 | VkResult result = instance_dispatch_table2(gpu)->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 310 | printf("Completed multi2 layer vkCreateDevice()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 311 | return result; |
| 312 | } |
| 313 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 314 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, |
| 315 | VkCmdBuffer* pCmdBuffer) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 316 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 317 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 318 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 319 | printf("At start of multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 320 | VkResult result = device_dispatch_table2(device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 321 | printf("Completed multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 322 | return result; |
| 323 | } |
| 324 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 325 | VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 326 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 327 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) cmdBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 328 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 329 | printf("At start of multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 330 | VkResult result = device_dispatch_table2(cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 331 | printf("Completed multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 332 | return result; |
| 333 | |
| 334 | } |
| 335 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 336 | VK_LAYER_EXPORT void * VKAPI multi2GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 337 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 338 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 339 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 340 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 341 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 342 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 343 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
| 344 | getLayer2Table(devw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 345 | return (void *) multi2GetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 346 | } |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 347 | if (!strcmp("vkDestroyDevice", pName)) |
| 348 | return (void *) multi2DestroyDevice; |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 349 | if (!strcmp("vkCreateCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 350 | return (void *) multi2CreateCommandBuffer; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 351 | else if (!strcmp("vkBeginCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 352 | return (void *) multi2BeginCommandBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 353 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 354 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 355 | VkLayerDispatchTable* pTable = device_dispatch_table2(device); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 356 | if (pTable->GetDeviceProcAddr == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 357 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 358 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 362 | VK_LAYER_EXPORT void * VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 363 | { |
| 364 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 365 | |
| 366 | if (inst == NULL) |
| 367 | return NULL; |
| 368 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 369 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
| 370 | getLayer2InstanceTable(instw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 371 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 372 | } |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 373 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
| 374 | return (void *) multi2EnumeratePhysicalDevices; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 375 | if (!strcmp("vkDestroyInstance", pName)) |
| 376 | return (void *) multi2DestroyInstance; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 377 | if (!strcmp("vkCreateDevice", pName)) |
| 378 | return (void *) multi2CreateDevice; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 379 | else if (!strcmp("GetGlobalExtensionInfo", pName)) |
| 380 | return (void*) vkGetGlobalExtensionInfo; |
| 381 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 382 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame^] | 383 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table2(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 384 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 385 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 386 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 387 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /********************************* Common functions ********************************/ |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 391 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 392 | struct extProps { |
| 393 | uint32_t version; |
| 394 | const char * const name; |
| 395 | }; |
| 396 | |
| 397 | #define MULTI_LAYER_EXT_ARRAY_SIZE 2 |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 398 | static const VkExtensionProperties multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = { |
| 399 | { |
| 400 | VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 401 | "multi1", |
| 402 | 0x10, |
| 403 | "Sample layer: multi", |
| 404 | // 0, |
| 405 | // NULL, |
| 406 | }, |
| 407 | { |
| 408 | VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 409 | "multi2", |
| 410 | 0x10, |
| 411 | "Sample layer: multi", |
| 412 | // 0, |
| 413 | // NULL, |
| 414 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 418 | VkExtensionInfoType infoType, |
| 419 | uint32_t extensionIndex, |
| 420 | size_t* pDataSize, |
| 421 | void* pData) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 422 | { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 423 | /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */ |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 424 | uint32_t *count; |
| 425 | |
| 426 | if (pDataSize == NULL) |
| 427 | return VK_ERROR_INVALID_POINTER; |
| 428 | |
| 429 | switch (infoType) { |
| 430 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 431 | *pDataSize = sizeof(uint32_t); |
| 432 | if (pData == NULL) |
| 433 | return VK_SUCCESS; |
| 434 | count = (uint32_t *) pData; |
| 435 | *count = MULTI_LAYER_EXT_ARRAY_SIZE; |
| 436 | break; |
| 437 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 438 | *pDataSize = sizeof(VkExtensionProperties); |
| 439 | if (pData == NULL) |
| 440 | return VK_SUCCESS; |
| 441 | if (extensionIndex >= MULTI_LAYER_EXT_ARRAY_SIZE) |
| 442 | return VK_ERROR_INVALID_VALUE; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 443 | memcpy((VkExtensionProperties *) pData, &multiExts[extensionIndex], sizeof(VkExtensionProperties)); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 444 | break; |
| 445 | default: |
| 446 | return VK_ERROR_INVALID_VALUE; |
| 447 | }; |
| 448 | |
| 449 | return VK_SUCCESS; |
| 450 | } |
| 451 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 452 | VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 453 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 454 | // to find each layers GPA routine Loader will search via "<layerName>GetDeviceProcAddr" |
| 455 | if (!strcmp("multi1GetDeviceProcAddr", pName)) |
| 456 | return (void *) multi1GetDeviceProcAddr; |
| 457 | else if (!strcmp("multi2GetDeviceProcAddr", pName)) |
| 458 | return (void *) multi2GetDeviceProcAddr; |
| 459 | else if (!strcmp("vkGetDeviceProcAddr", pName)) |
| 460 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 461 | |
| 462 | // use first layer activated as GPA dispatch table activation happens in order |
| 463 | else if (layer1_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 464 | return multi1GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 465 | else if (layer2_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 466 | return multi2GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 467 | else |
| 468 | return NULL; |
| 469 | |
| 470 | } |
| 471 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 472 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* pName) |
| 473 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 474 | // to find each layers GPA routine Loader will search via "<layerName>GetInstanceProcAddr" |
| 475 | if (!strcmp("multi1GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 476 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 477 | else if (!strcmp("multi2GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 478 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 479 | else if (!strcmp("vkGetInstanceProcAddr", pName)) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 480 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 481 | |
| 482 | // use first layer activated as GPA dispatch table activation happens in order |
| 483 | else if (layer1_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 484 | return multi1GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 485 | else if (layer2_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 486 | return multi2GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 487 | else |
| 488 | return NULL; |
| 489 | |
| 490 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 491 | #ifdef __cplusplus |
| 492 | } //extern "C" |
| 493 | #endif |
| 494 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 495 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 496 | { |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 497 | if (layerNum == 2 && layer1_first_activated == false) |
| 498 | layer2_first_activated = true; |
| 499 | if (layerNum == 1 && layer2_first_activated == false) |
| 500 | layer1_first_activated = true; |
| 501 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 502 | layer_initialize_dispatch_table(pTable, devw); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 503 | } |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 504 | |
| 505 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum) |
| 506 | { |
| 507 | if (layerNum == 2 && layer1_first_activated == false) |
| 508 | layer2_first_activated = true; |
| 509 | if (layerNum == 1 && layer2_first_activated == false) |
| 510 | layer1_first_activated = true; |
| 511 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 512 | layer_init_instance_dispatch_table(pTable, instw); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 513 | } |