Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Jon Ashburn | 79113cc | 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 | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 30 | #include "loader_platform.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | #include "vk_dispatch_table_helper.h" |
| 32 | #include "vkLayer.h" |
Ian Elliott | 655cad7 | 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 | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 36 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 37 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum); |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 38 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum); |
Jon Ashburn | fe7ff9c | 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 | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 46 | /******************************** Layer multi1 functions **************************/ |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 47 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap1; |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 48 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap1; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 49 | static bool layer1_first_activated = false; |
| 50 | |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 51 | static VkLayerDispatchTable *getLayer1Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 52 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 53 | VkLayerDispatchTable *pTable; |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 54 | assert(devw); |
| 55 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 56 | |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 57 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap1.find((void *) *ppDisp); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 58 | if (it == tableMap1.end()) |
| 59 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 60 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 61 | tableMap1[(void *) *ppDisp] = pTable; |
| 62 | initLayerTable(devw, pTable, 1); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 63 | return pTable; |
| 64 | } else |
| 65 | { |
| 66 | return it->second; |
| 67 | } |
| 68 | } |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 69 | static VkLayerInstanceDispatchTable *getLayer1InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 70 | { |
| 71 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 72 | assert(instw); |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 73 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 74 | |
| 75 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap1.find((void *) *ppDisp); |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 76 | if (it == tableInstanceMap1.end()) |
| 77 | { |
| 78 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 79 | tableInstanceMap1[(void *) *ppDisp] = pTable; |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 80 | initLayerInstanceTable(instw, pTable, 1); |
| 81 | return pTable; |
| 82 | } else |
| 83 | { |
| 84 | return it->second; |
| 85 | } |
| 86 | } |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 87 | #ifdef __cplusplus |
| 88 | extern "C" { |
| 89 | #endif |
| 90 | |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame^] | 91 | /* hook DextroyDevice to remove tableMap entry */ |
| 92 | VK_LAYER_EXPORT VkResult VKAPI multi1DestroyDevice(VkDevice device) |
| 93 | { |
| 94 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
| 95 | VkLayerDispatchTable *pTable = tableMap1[pDisp]; |
| 96 | VkResult res = pTable->DestroyDevice(device); |
| 97 | tableMap1.erase(pDisp); |
| 98 | return res; |
| 99 | } |
| 100 | |
| 101 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 102 | VK_LAYER_EXPORT VkResult VKAPI multi1DestroyInstance(VkInstance instance) |
| 103 | { |
| 104 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
| 105 | VkLayerInstanceDispatchTable *pTable = tableInstanceMap1[pDisp]; |
| 106 | VkResult res = pTable->DestroyInstance(instance); |
| 107 | tableInstanceMap1.erase(pDisp); |
| 108 | return res; |
| 109 | } |
| 110 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 111 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 112 | { |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 113 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
| 114 | VkLayerDispatchTable *pTable = tableMap1[*ppDisp]; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 115 | |
| 116 | printf("At start of multi1 layer vkCreateSampler()\n"); |
| 117 | VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler); |
| 118 | printf("Completed multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 119 | return result; |
| 120 | } |
| 121 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 122 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, |
| 123 | VkPipeline* pPipeline) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 124 | { |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 125 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
| 126 | VkLayerDispatchTable *pTable = tableMap1[*ppDisp]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 127 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 128 | printf("At start of multi1 layer vkCreateGraphicsPipeline()\n"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 129 | VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 130 | printf("Completed multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 131 | return result; |
| 132 | } |
| 133 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 134 | VK_LAYER_EXPORT VkResult VKAPI multi1StorePipeline(VkDevice device, VkPipeline pipeline, size_t* pDataSize, void* pData) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 135 | { |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 136 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
| 137 | VkLayerDispatchTable *pTable = tableMap1[*ppDisp]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 138 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 139 | printf("At start of multi1 layer vkStorePipeline()\n"); |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 140 | VkResult result = pTable->StorePipeline(device, pipeline, pDataSize, pData); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 141 | printf("Completed multi1 layer vkStorePipeline()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 142 | return result; |
| 143 | } |
| 144 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 145 | VK_LAYER_EXPORT VkResult VKAPI multi1EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 146 | size_t* pLayerCount, char* const* pOutLayers, |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 147 | void* pReserved) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 148 | { |
| 149 | if (gpu == NULL) |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 150 | return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 151 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 152 | VkLayerInstanceDispatchTable* pTable = tableInstanceMap1[gpu]; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 153 | printf("At start of multi1 layer vkEnumerateLayers()\n"); |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 154 | VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 155 | printf("Completed multi1 layer vkEnumerateLayers()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 156 | return result; |
| 157 | } |
| 158 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 159 | VK_LAYER_EXPORT void * VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 160 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 161 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 162 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 163 | if (device == NULL) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 164 | return NULL; |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 165 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 166 | getLayer1Table(devw); |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 167 | |
Jon Ashburn | 1c286bb | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 168 | if (!strcmp("vkGetDeviceProcAddr", pName)) |
| 169 | return (void *) multi1GetDeviceProcAddr; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame^] | 170 | if (!strcmp("vkDestroyDevice", pName)) |
| 171 | return (void *) multi1DestroyDevice; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 172 | if (!strcmp("vkCreateSampler", pName)) |
| 173 | return (void *) multi1CreateSampler; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 174 | else if (!strcmp("vkCreateGraphicsPipeline", pName)) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 175 | return (void *) multi1CreateGraphicsPipeline; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 176 | else if (!strcmp("vkStorePipeline", pName)) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 177 | return (void *) multi1StorePipeline; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 178 | else { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 179 | if (devw->pGPA == NULL) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 180 | return NULL; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 181 | return devw->pGPA((VkObject) devw->nextObject, pName); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 185 | VK_LAYER_EXPORT void * VKAPI multi1GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 186 | { |
| 187 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 188 | |
| 189 | if (inst == NULL) |
| 190 | return NULL; |
| 191 | |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 192 | getLayer1InstanceTable(instw); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 193 | |
Jon Ashburn | 1c286bb | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 194 | if (!strcmp("vkGetInstanceProcAddr", pName)) |
| 195 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame^] | 196 | if (!strcmp("vkDestroyInstance", pName)) |
| 197 | return (void *) multi1DestroyInstance; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 198 | if (!strcmp("vkEnumerateLayers", pName)) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 199 | return (void *) multi1EnumerateLayers; |
| 200 | else if (!strcmp("GetGlobalExtensionInfo", pName)) |
| 201 | return (void*) vkGetGlobalExtensionInfo; |
| 202 | else { |
| 203 | if (instw->pGPA == NULL) |
| 204 | return NULL; |
| 205 | return instw->pGPA((VkObject) instw->nextObject, pName); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 206 | } |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 210 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2; |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 211 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap2; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 212 | static bool layer2_first_activated = false; |
| 213 | |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 214 | static VkLayerInstanceDispatchTable *getLayer2InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 215 | { |
| 216 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 217 | assert(instw); |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 218 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 219 | |
| 220 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) *ppDisp); |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 221 | if (it == tableInstanceMap2.end()) |
| 222 | { |
| 223 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 224 | tableInstanceMap2[(void *) *ppDisp] = pTable; |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 225 | initLayerInstanceTable(instw, pTable, 2); |
| 226 | return pTable; |
| 227 | } else |
| 228 | { |
| 229 | return it->second; |
| 230 | } |
| 231 | } |
| 232 | |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 233 | static VkLayerDispatchTable *getLayer2Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 234 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 235 | VkLayerDispatchTable *pTable; |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 236 | assert(devw); |
| 237 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 238 | |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 239 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) *ppDisp); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 240 | if (it == tableMap2.end()) |
| 241 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 242 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 243 | tableMap2[(void *) *ppDisp] = pTable; |
| 244 | initLayerTable(devw, pTable, 2); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 245 | return pTable; |
| 246 | } else |
| 247 | { |
| 248 | return it->second; |
| 249 | } |
| 250 | } |
| 251 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 252 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices( |
| 253 | VkInstance instance, |
| 254 | uint32_t* pPhysicalDeviceCount, |
| 255 | VkPhysicalDevice* pPhysicalDevices) |
| 256 | { |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 257 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance; |
| 258 | VkLayerInstanceDispatchTable *pInstTable = tableInstanceMap2[*ppDisp]; |
| 259 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 260 | printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); |
| 261 | VkResult result = pInstTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 262 | printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); |
| 263 | return result; |
| 264 | } |
| 265 | |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame^] | 266 | /* hook DextroyDevice to remove tableMap entry */ |
| 267 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyDevice(VkDevice device) |
| 268 | { |
| 269 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
| 270 | VkLayerDispatchTable *pTable = tableMap2[pDisp]; |
| 271 | VkResult res = pTable->DestroyDevice(device); |
| 272 | tableMap2.erase(pDisp); |
| 273 | return res; |
| 274 | } |
| 275 | |
| 276 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 277 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyInstance(VkInstance instance) |
| 278 | { |
| 279 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
| 280 | VkLayerInstanceDispatchTable *pTable = tableInstanceMap2[pDisp]; |
| 281 | VkResult res = pTable->DestroyInstance(instance); |
| 282 | tableInstanceMap2.erase(pDisp); |
| 283 | return res; |
| 284 | } |
| 285 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 286 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 287 | VkDevice* pDevice) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 288 | { |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 289 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu; |
| 290 | VkLayerInstanceDispatchTable *pInstTable = tableInstanceMap2[*ppDisp]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 291 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 292 | printf("At start of multi2 vkCreateDevice()\n"); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 293 | VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 294 | printf("Completed multi2 layer vkCreateDevice()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 295 | return result; |
| 296 | } |
| 297 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 298 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, |
| 299 | VkCmdBuffer* pCmdBuffer) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 300 | { |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 301 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
| 302 | VkLayerDispatchTable *pTable = tableMap2[*ppDisp]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 303 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 304 | printf("At start of multi2 layer vkCreateCommandBuffer()\n"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 305 | VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 306 | printf("Completed multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 307 | return result; |
| 308 | } |
| 309 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 310 | VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 311 | { |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 312 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) cmdBuffer; |
| 313 | VkLayerDispatchTable *pTable = tableMap2[*ppDisp]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 314 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 315 | printf("At start of multi2 layer vkBeginCommandBuffer()\n"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 316 | VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 317 | printf("Completed multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 318 | return result; |
| 319 | |
| 320 | } |
| 321 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 322 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 323 | size_t* pLayerCount, char* const* pOutLayers, |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 324 | void* pReserved) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 325 | { |
| 326 | if (gpu == NULL) |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 327 | return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 328 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 329 | VkLayerInstanceDispatchTable* pTable = tableInstanceMap2[gpu]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 330 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 331 | printf("At start of multi2 layer vkEnumerateLayers()\n"); |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 332 | VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 333 | printf("Completed multi2 layer vkEnumerateLayers()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 334 | return result; |
| 335 | } |
| 336 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 337 | VK_LAYER_EXPORT void * VKAPI multi2GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 338 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 339 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 340 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 341 | if (device == NULL) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 342 | return NULL; |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 343 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 344 | getLayer2Table(devw); |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 345 | |
Jon Ashburn | 1c286bb | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 346 | if (!strcmp("vkGetDeviceProcAddr", pName)) |
| 347 | return (void *) multi2GetDeviceProcAddr; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame^] | 348 | if (!strcmp("vkDestroyDevice", pName)) |
| 349 | return (void *) multi2DestroyDevice; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 350 | if (!strcmp("vkCreateCommandBuffer", pName)) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 351 | return (void *) multi2CreateCommandBuffer; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 352 | else if (!strcmp("vkBeginCommandBuffer", pName)) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 353 | return (void *) multi2BeginCommandBuffer; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 354 | else { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 355 | if (devw->pGPA == NULL) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 356 | return NULL; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 357 | return devw->pGPA((VkObject) devw->nextObject, pName); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 361 | VK_LAYER_EXPORT void * VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 362 | { |
| 363 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 364 | |
| 365 | if (inst == NULL) |
| 366 | return NULL; |
| 367 | |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 368 | getLayer2InstanceTable(instw); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 369 | |
Jon Ashburn | 1c286bb | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 370 | if (!strcmp("vkGetInstanceProcAddr", pName)) |
| 371 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 372 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
| 373 | return (void *) multi2EnumeratePhysicalDevices; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame^] | 374 | if (!strcmp("vkDestroyInstance", pName)) |
| 375 | return (void *) multi2DestroyInstance; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 376 | if (!strcmp("vkCreateDevice", pName)) |
| 377 | return (void *) multi2CreateDevice; |
| 378 | else if (!strcmp("vkEnumerateLayers", pName)) |
| 379 | return (void *) multi2EnumerateLayers; |
| 380 | else if (!strcmp("GetGlobalExtensionInfo", pName)) |
| 381 | return (void*) vkGetGlobalExtensionInfo; |
| 382 | else { |
| 383 | if (instw->pGPA == NULL) |
| 384 | return NULL; |
| 385 | return instw->pGPA((VkObject) instw->nextObject, pName); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 386 | } |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /********************************* Common functions ********************************/ |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 390 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 391 | size_t* pLayerCount, char* const* pOutLayers, |
| 392 | void* pReserved) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 393 | { |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 394 | if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 395 | return VK_ERROR_INVALID_POINTER; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 396 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 397 | if (*pLayerCount < 2) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 398 | return VK_ERROR_INITIALIZATION_FAILED; |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 399 | *pLayerCount = 2; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 400 | strncpy((char *) pOutLayers[0], "multi1", maxStringSize); |
| 401 | strncpy((char *) pOutLayers[1], "multi2", maxStringSize); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 402 | return VK_SUCCESS; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 405 | struct extProps { |
| 406 | uint32_t version; |
| 407 | const char * const name; |
| 408 | }; |
| 409 | |
| 410 | #define MULTI_LAYER_EXT_ARRAY_SIZE 2 |
| 411 | static const struct extProps multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = { |
| 412 | // TODO what is the version? |
| 413 | 0x10, "multi1", |
| 414 | 0x10, "multi2", |
| 415 | }; |
| 416 | |
| 417 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
| 418 | VkExtensionInfoType infoType, |
| 419 | uint32_t extensionIndex, |
| 420 | size_t* pDataSize, |
| 421 | void* pData) |
| 422 | { |
Jon Ashburn | 9fd4cc4 | 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 */ |
| 424 | VkExtensionProperties *ext_props; |
| 425 | uint32_t *count; |
| 426 | |
| 427 | if (pDataSize == NULL) |
| 428 | return VK_ERROR_INVALID_POINTER; |
| 429 | |
| 430 | switch (infoType) { |
| 431 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 432 | *pDataSize = sizeof(uint32_t); |
| 433 | if (pData == NULL) |
| 434 | return VK_SUCCESS; |
| 435 | count = (uint32_t *) pData; |
| 436 | *count = MULTI_LAYER_EXT_ARRAY_SIZE; |
| 437 | break; |
| 438 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 439 | *pDataSize = sizeof(VkExtensionProperties); |
| 440 | if (pData == NULL) |
| 441 | return VK_SUCCESS; |
| 442 | if (extensionIndex >= MULTI_LAYER_EXT_ARRAY_SIZE) |
| 443 | return VK_ERROR_INVALID_VALUE; |
| 444 | ext_props = (VkExtensionProperties *) pData; |
| 445 | ext_props->version = multiExts[extensionIndex].version; |
| 446 | strncpy(ext_props->extName, multiExts[extensionIndex].name, |
| 447 | VK_MAX_EXTENSION_NAME); |
| 448 | ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0'; |
| 449 | break; |
| 450 | default: |
| 451 | return VK_ERROR_INVALID_VALUE; |
| 452 | }; |
| 453 | |
| 454 | return VK_SUCCESS; |
| 455 | } |
| 456 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 457 | VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 458 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 459 | // to find each layers GPA routine Loader will search via "<layerName>GetDeviceProcAddr" |
| 460 | if (!strcmp("multi1GetDeviceProcAddr", pName)) |
| 461 | return (void *) multi1GetDeviceProcAddr; |
| 462 | else if (!strcmp("multi2GetDeviceProcAddr", pName)) |
| 463 | return (void *) multi2GetDeviceProcAddr; |
| 464 | else if (!strcmp("vkGetDeviceProcAddr", pName)) |
| 465 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 466 | |
| 467 | // use first layer activated as GPA dispatch table activation happens in order |
| 468 | else if (layer1_first_activated) |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 469 | return multi1GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 470 | else if (layer2_first_activated) |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 471 | return multi2GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 472 | else |
| 473 | return NULL; |
| 474 | |
| 475 | } |
| 476 | |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 477 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* pName) |
| 478 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 479 | // to find each layers GPA routine Loader will search via "<layerName>GetInstanceProcAddr" |
| 480 | if (!strcmp("multi1GetInstanceProcAddr", pName)) |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 481 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 482 | else if (!strcmp("multi2GetInstanceProcAddr", pName)) |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 483 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 484 | else if (!strcmp("vkGetInstanceProcAddr", pName)) |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 485 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 486 | |
| 487 | // use first layer activated as GPA dispatch table activation happens in order |
| 488 | else if (layer1_first_activated) |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 489 | return multi1GetInstanceProcAddr(inst, pName); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 490 | else if (layer2_first_activated) |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 491 | return multi2GetInstanceProcAddr(inst, pName); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 492 | else |
| 493 | return NULL; |
| 494 | |
| 495 | } |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 496 | #ifdef __cplusplus |
| 497 | } //extern "C" |
| 498 | #endif |
| 499 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 500 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 501 | { |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 502 | if (layerNum == 2 && layer1_first_activated == false) |
| 503 | layer2_first_activated = true; |
| 504 | if (layerNum == 1 && layer2_first_activated == false) |
| 505 | layer1_first_activated = true; |
| 506 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 507 | layer_initialize_dispatch_table(pTable, (PFN_vkGetDeviceProcAddr) devw->pGPA, (VkDevice) devw->nextObject); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 508 | } |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 509 | |
| 510 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum) |
| 511 | { |
| 512 | if (layerNum == 2 && layer1_first_activated == false) |
| 513 | layer2_first_activated = true; |
| 514 | if (layerNum == 1 && layer2_first_activated == false) |
| 515 | layer1_first_activated = true; |
| 516 | |
| 517 | layer_init_instance_dispatch_table(pTable, (PFN_vkGetInstanceProcAddr) instw->pGPA, (VkInstance) instw->nextObject); |
| 518 | } |