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> |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 30 | #include "vk_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: |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 35 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 36 | #include "vk_layer_extension_utils.h" |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 37 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 38 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 39 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 40 | /* Various dispatchable objects will use the same underlying dispatch table if they |
| 41 | * are created from that "parent" object. Thus use pointer to dispatch table |
| 42 | * as the key to table maps (tableMap1, tableInstanceMap1, tableMap2, tableInstanceMap2. |
| 43 | * Instance -> PhysicalDevice |
| 44 | * Device -> CmdBuffer or Queue |
| 45 | * If use the object themselves as key to map then implies Create entrypoints have to be intercepted |
| 46 | * and a new key inserted into map */ |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 47 | /******************************** Layer multi1 functions **************************/ |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 48 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap1; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 49 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap1; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 50 | static bool layer1_first_activated = false; |
| 51 | |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 52 | // Map lookup must be thread safe |
| 53 | static inline VkLayerDispatchTable *device_dispatch_table1(VkObject object) |
| 54 | { |
| 55 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; |
| 56 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap1.find((void *) pDisp); |
| 57 | assert(it != tableMap1.end() && "Not able to find device dispatch entry"); |
| 58 | return it->second; |
| 59 | } |
| 60 | |
| 61 | static inline VkLayerInstanceDispatchTable *instance_dispatch_table1(VkObject object) |
| 62 | { |
| 63 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; |
| 64 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap1.find((void *) pDisp); |
| 65 | assert(it != tableInstanceMap1.end() && "Not able to find instance dispatch entry"); |
| 66 | return it->second; |
| 67 | } |
| 68 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 69 | static VkLayerDispatchTable *getLayer1Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 70 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 71 | VkLayerDispatchTable *pTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 72 | assert(devw); |
| 73 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 74 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 75 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap1.find((void *) *ppDisp); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 76 | if (it == tableMap1.end()) |
| 77 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 78 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 79 | tableMap1[(void *) *ppDisp] = pTable; |
| 80 | initLayerTable(devw, pTable, 1); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 81 | return pTable; |
| 82 | } else |
| 83 | { |
| 84 | return it->second; |
| 85 | } |
| 86 | } |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 87 | static VkLayerInstanceDispatchTable *getLayer1InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 88 | { |
| 89 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 90 | assert(instw); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 91 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 92 | |
| 93 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap1.find((void *) *ppDisp); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 94 | if (it == tableInstanceMap1.end()) |
| 95 | { |
| 96 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 97 | tableInstanceMap1[(void *) *ppDisp] = pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 98 | initLayerInstanceTable(instw, pTable, 1); |
| 99 | return pTable; |
| 100 | } else |
| 101 | { |
| 102 | return it->second; |
| 103 | } |
| 104 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 105 | #ifdef __cplusplus |
| 106 | extern "C" { |
| 107 | #endif |
| 108 | |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 109 | /* hook DestroyDevice to remove tableMap entry */ |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 110 | VK_LAYER_EXPORT VkResult VKAPI multi1DestroyDevice(VkDevice device) |
| 111 | { |
| 112 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 113 | VkResult res = device_dispatch_table1(device)->DestroyDevice(device); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 114 | tableMap1.erase(pDisp); |
| 115 | return res; |
| 116 | } |
| 117 | |
| 118 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 119 | VK_LAYER_EXPORT VkResult VKAPI multi1DestroyInstance(VkInstance instance) |
| 120 | { |
| 121 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 122 | VkResult res = instance_dispatch_table1(instance)->DestroyInstance(instance); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 123 | tableInstanceMap1.erase(pDisp); |
| 124 | return res; |
| 125 | } |
| 126 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 127 | 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] | 128 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 129 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 130 | |
| 131 | printf("At start of multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 132 | VkResult result = device_dispatch_table1(device)->CreateSampler(device, pCreateInfo, pSampler); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 133 | printf("Completed multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 134 | return result; |
| 135 | } |
| 136 | |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 137 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipelines( |
| 138 | VkDevice device, |
| 139 | VkPipelineCache pipelineCache, |
| 140 | uint32_t count, |
| 141 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 142 | VkPipeline* pPipelines) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 143 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 144 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 145 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 146 | printf("At start of multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 147 | VkResult result = device_dispatch_table1(device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 148 | printf("Completed multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 149 | return result; |
| 150 | } |
| 151 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 152 | VK_LAYER_EXPORT void * VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 153 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 154 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 155 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 156 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 157 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 158 | |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 159 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 160 | |
| 161 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
| 162 | getLayer1Table(devw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 163 | return (void *) multi1GetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 164 | } |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 165 | if (!strcmp("vkDestroyDevice", pName)) |
| 166 | return (void *) multi1DestroyDevice; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 167 | if (!strcmp("vkCreateSampler", pName)) |
| 168 | return (void *) multi1CreateSampler; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 169 | if (!strcmp("vkCreateGraphicsPipelines", pName)) |
| 170 | return (void *) multi1CreateGraphicsPipelines; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 171 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 172 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 173 | VkLayerDispatchTable* pTable = device_dispatch_table1(device); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 174 | if (pTable->GetDeviceProcAddr == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 175 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 176 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame^] | 180 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi1GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 181 | { |
| 182 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 183 | |
| 184 | if (inst == NULL) |
| 185 | return NULL; |
| 186 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 187 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 188 | |
| 189 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
| 190 | getLayer1InstanceTable(instw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 191 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 192 | } |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 193 | if (!strcmp("vkDestroyInstance", pName)) |
| 194 | return (void *) multi1DestroyInstance; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 195 | if (!strcmp("GetGlobalExtensionProperties", pName)) |
| 196 | return (void*) vkGetGlobalExtensionProperties; |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 197 | if (!strcmp("GetGlobalLayerProperties", pName)) |
| 198 | return (void*) vkGetGlobalLayerProperties; |
| 199 | if (!strcmp("GetPhysicalDeviceExtensionProperties", pName)) |
| 200 | return (void*) vkGetPhysicalDeviceExtensionProperties; |
| 201 | if (!strcmp("GetPhysicalDeviceLayerProperties", pName)) |
| 202 | return (void*) vkGetPhysicalDeviceLayerProperties; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 203 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 204 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 205 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table1(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 206 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 207 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 208 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 209 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 213 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 214 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap2; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 215 | static bool layer2_first_activated = false; |
| 216 | |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 217 | // Map lookup must be thread safe |
| 218 | static inline VkLayerDispatchTable *device_dispatch_table2(VkObject object) |
| 219 | { |
| 220 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; |
| 221 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) pDisp); |
| 222 | assert(it != tableMap2.end() && "Not able to find device dispatch entry"); |
| 223 | return it->second; |
| 224 | } |
| 225 | |
| 226 | static inline VkLayerInstanceDispatchTable *instance_dispatch_table2(VkObject object) |
| 227 | { |
| 228 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; |
| 229 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) pDisp); |
| 230 | assert(it != tableInstanceMap2.end() && "Not able to find instance dispatch entry"); |
| 231 | return it->second; |
| 232 | } |
| 233 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 234 | static VkLayerInstanceDispatchTable *getLayer2InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 235 | { |
| 236 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 237 | assert(instw); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 238 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 239 | |
| 240 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) *ppDisp); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 241 | if (it == tableInstanceMap2.end()) |
| 242 | { |
| 243 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 244 | tableInstanceMap2[(void *) *ppDisp] = pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 245 | initLayerInstanceTable(instw, pTable, 2); |
| 246 | return pTable; |
| 247 | } else |
| 248 | { |
| 249 | return it->second; |
| 250 | } |
| 251 | } |
| 252 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 253 | static VkLayerDispatchTable *getLayer2Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 254 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 255 | VkLayerDispatchTable *pTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 256 | assert(devw); |
| 257 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 258 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 259 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) *ppDisp); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 260 | if (it == tableMap2.end()) |
| 261 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 262 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 263 | tableMap2[(void *) *ppDisp] = pTable; |
| 264 | initLayerTable(devw, pTable, 2); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 265 | return pTable; |
| 266 | } else |
| 267 | { |
| 268 | return it->second; |
| 269 | } |
| 270 | } |
| 271 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 272 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices( |
| 273 | VkInstance instance, |
| 274 | uint32_t* pPhysicalDeviceCount, |
| 275 | VkPhysicalDevice* pPhysicalDevices) |
| 276 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 277 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 278 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 279 | printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 280 | VkResult result = instance_dispatch_table2(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 281 | printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); |
| 282 | return result; |
| 283 | } |
| 284 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 285 | /* hook DextroyDevice to remove tableMap entry */ |
| 286 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyDevice(VkDevice device) |
| 287 | { |
| 288 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 289 | VkResult res = device_dispatch_table2(device)->DestroyDevice(device); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 290 | tableMap2.erase(pDisp); |
| 291 | return res; |
| 292 | } |
| 293 | |
| 294 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 295 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyInstance(VkInstance instance) |
| 296 | { |
| 297 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 298 | VkResult res = instance_dispatch_table2(instance)->DestroyInstance(instance); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 299 | tableInstanceMap2.erase(pDisp); |
| 300 | return res; |
| 301 | } |
| 302 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 303 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 304 | VkDevice* pDevice) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 305 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 306 | printf("At start of multi2 vkCreateDevice()\n"); |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 307 | VkResult result = device_dispatch_table2(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | printf("Completed multi2 layer vkCreateDevice()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 309 | return result; |
| 310 | } |
| 311 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 312 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, |
| 313 | VkCmdBuffer* pCmdBuffer) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 314 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 315 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 316 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 317 | printf("At start of multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 318 | VkResult result = device_dispatch_table2(device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 319 | printf("Completed multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 320 | return result; |
| 321 | } |
| 322 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 323 | VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 324 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 325 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) cmdBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 326 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | printf("At start of multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 328 | VkResult result = device_dispatch_table2(cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 329 | printf("Completed multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 330 | return result; |
| 331 | |
| 332 | } |
| 333 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame^] | 334 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi2GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 335 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 336 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 337 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 338 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 339 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 340 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 341 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
| 342 | getLayer2Table(devw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 343 | return (void *) multi2GetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 344 | } |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 345 | if (!strcmp("vkCreateDevice", pName)) |
| 346 | return (void *) multi2CreateDevice; |
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 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame^] | 362 | VK_LAYER_EXPORT PFN_vkVoidFunction 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; |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 377 | if (!strcmp("GetGlobalExtensionProperties", pName)) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 378 | return (void*) vkGetGlobalExtensionProperties; |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 379 | if (!strcmp("GetGlobalLayerProperties", pName)) |
| 380 | return (void*) vkGetGlobalLayerProperties; |
| 381 | if (!strcmp("GetPhysicalDeviceExtensionProperties", pName)) |
| 382 | return (void*) vkGetPhysicalDeviceExtensionProperties; |
| 383 | if (!strcmp("GetPhysicalDeviceLayerProperties", pName)) |
| 384 | return (void*) vkGetPhysicalDeviceLayerProperties; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 385 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 386 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 387 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table2(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 388 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 389 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 390 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 391 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /********************************* Common functions ********************************/ |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 395 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 396 | struct extProps { |
| 397 | uint32_t version; |
| 398 | const char * const name; |
| 399 | }; |
| 400 | |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 401 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
| 402 | const char *pLayerName, |
| 403 | uint32_t *pCount, |
| 404 | VkExtensionProperties* pProperties) |
| 405 | { |
| 406 | /* multi does not have any global extensions */ |
| 407 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 408 | } |
| 409 | |
| 410 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties( |
| 411 | uint32_t *pCount, |
| 412 | VkLayerProperties* pProperties) |
| 413 | { |
| 414 | /* multi does not have any global layers */ |
| 415 | return util_GetLayerProperties(0, NULL, pCount, pProperties); |
| 416 | } |
| 417 | |
| 418 | #define MULTI_LAYER_ARRAY_SIZE 1 |
| 419 | static const VkLayerProperties multi_device_layers[MULTI_LAYER_ARRAY_SIZE] = { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 420 | { |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 421 | "Multi1", |
| 422 | VK_API_VERSION, |
| 423 | VK_MAKE_VERSION(0, 1, 0), |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 424 | "Sample layer: multi", |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 425 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 426 | }; |
| 427 | |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 428 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties( |
| 429 | VkPhysicalDevice physicalDevice, |
| 430 | const char* pLayerName, |
| 431 | uint32_t* pCount, |
| 432 | VkExtensionProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 433 | { |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 434 | /* Multi does not have any physical device extensions */ |
| 435 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 436 | } |
| 437 | |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 438 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties( |
| 439 | VkPhysicalDevice physicalDevice, |
| 440 | uint32_t* pCount, |
| 441 | VkLayerProperties* pProperties) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 442 | { |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 443 | return util_GetLayerProperties(MULTI_LAYER_ARRAY_SIZE, multi_device_layers, |
| 444 | pCount, pProperties); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 445 | } |
| 446 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame^] | 447 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 448 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 449 | // to find each layers GPA routine Loader will search via "<layerName>GetDeviceProcAddr" |
| 450 | if (!strcmp("multi1GetDeviceProcAddr", pName)) |
| 451 | return (void *) multi1GetDeviceProcAddr; |
| 452 | else if (!strcmp("multi2GetDeviceProcAddr", pName)) |
| 453 | return (void *) multi2GetDeviceProcAddr; |
| 454 | else if (!strcmp("vkGetDeviceProcAddr", pName)) |
| 455 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 456 | |
| 457 | // use first layer activated as GPA dispatch table activation happens in order |
| 458 | else if (layer1_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 459 | return multi1GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 460 | else if (layer2_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 461 | return multi2GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 462 | else |
| 463 | return NULL; |
| 464 | |
| 465 | } |
| 466 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 467 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* pName) |
| 468 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 469 | // to find each layers GPA routine Loader will search via "<layerName>GetInstanceProcAddr" |
| 470 | if (!strcmp("multi1GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 471 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 472 | else if (!strcmp("multi2GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 473 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 474 | else if (!strcmp("vkGetInstanceProcAddr", pName)) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 475 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 476 | |
| 477 | // use first layer activated as GPA dispatch table activation happens in order |
| 478 | else if (layer1_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 479 | return multi1GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 480 | else if (layer2_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 481 | return multi2GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 482 | else |
| 483 | return NULL; |
| 484 | |
| 485 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 486 | #ifdef __cplusplus |
| 487 | } //extern "C" |
| 488 | #endif |
| 489 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 490 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 491 | { |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 492 | if (layerNum == 2 && layer1_first_activated == false) |
| 493 | layer2_first_activated = true; |
| 494 | if (layerNum == 1 && layer2_first_activated == false) |
| 495 | layer1_first_activated = true; |
| 496 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 497 | layer_initialize_dispatch_table(pTable, devw); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 498 | } |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 499 | |
| 500 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum) |
| 501 | { |
| 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 | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 507 | layer_init_instance_dispatch_table(pTable, instw); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 508 | } |