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 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 137 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, |
| 138 | VkPipeline* pPipeline) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 139 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 140 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 141 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 142 | printf("At start of multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 143 | VkResult result = device_dispatch_table1(device)->CreateGraphicsPipeline(device, pCreateInfo, pPipeline); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 144 | printf("Completed multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 145 | return result; |
| 146 | } |
| 147 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 148 | 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] | 149 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 150 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 151 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 152 | printf("At start of multi1 layer vkStorePipeline()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 153 | VkResult result = device_dispatch_table1(device)->StorePipeline(device, pipeline, pDataSize, pData); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 154 | printf("Completed multi1 layer vkStorePipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 155 | return result; |
| 156 | } |
| 157 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 158 | VK_LAYER_EXPORT void * VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 159 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 160 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 161 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 162 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 163 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 164 | |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 165 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 166 | |
| 167 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
| 168 | getLayer1Table(devw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 169 | return (void *) multi1GetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 170 | } |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 171 | if (!strcmp("vkDestroyDevice", pName)) |
| 172 | return (void *) multi1DestroyDevice; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 173 | if (!strcmp("vkCreateSampler", pName)) |
| 174 | return (void *) multi1CreateSampler; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 175 | if (!strcmp("vkCreateGraphicsPipeline", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 176 | return (void *) multi1CreateGraphicsPipeline; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 177 | if (!strcmp("vkStorePipeline", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 178 | return (void *) multi1StorePipeline; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 179 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 180 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 181 | VkLayerDispatchTable* pTable = device_dispatch_table1(device); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 182 | if (pTable->GetDeviceProcAddr == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 183 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 184 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 188 | VK_LAYER_EXPORT void * VKAPI multi1GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 189 | { |
| 190 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 191 | |
| 192 | if (inst == NULL) |
| 193 | return NULL; |
| 194 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 195 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 196 | |
| 197 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
| 198 | getLayer1InstanceTable(instw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 199 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 200 | } |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 201 | if (!strcmp("vkDestroyInstance", pName)) |
| 202 | return (void *) multi1DestroyInstance; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 203 | if (!strcmp("GetGlobalExtensionProperties", pName)) |
| 204 | return (void*) vkGetGlobalExtensionProperties; |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 205 | if (!strcmp("GetGlobalLayerProperties", pName)) |
| 206 | return (void*) vkGetGlobalLayerProperties; |
| 207 | if (!strcmp("GetPhysicalDeviceExtensionProperties", pName)) |
| 208 | return (void*) vkGetPhysicalDeviceExtensionProperties; |
| 209 | if (!strcmp("GetPhysicalDeviceLayerProperties", pName)) |
| 210 | return (void*) vkGetPhysicalDeviceLayerProperties; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 211 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 212 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 213 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table1(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 214 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 215 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 216 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 217 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 221 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 222 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap2; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 223 | static bool layer2_first_activated = false; |
| 224 | |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 225 | // Map lookup must be thread safe |
| 226 | static inline VkLayerDispatchTable *device_dispatch_table2(VkObject object) |
| 227 | { |
| 228 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object; |
| 229 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) pDisp); |
| 230 | assert(it != tableMap2.end() && "Not able to find device dispatch entry"); |
| 231 | return it->second; |
| 232 | } |
| 233 | |
| 234 | static inline VkLayerInstanceDispatchTable *instance_dispatch_table2(VkObject object) |
| 235 | { |
| 236 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) object; |
| 237 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) pDisp); |
| 238 | assert(it != tableInstanceMap2.end() && "Not able to find instance dispatch entry"); |
| 239 | return it->second; |
| 240 | } |
| 241 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 242 | static VkLayerInstanceDispatchTable *getLayer2InstanceTable(const VkBaseLayerObject *instw) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 243 | { |
| 244 | VkLayerInstanceDispatchTable *pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 245 | assert(instw); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 246 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject; |
| 247 | |
| 248 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) *ppDisp); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 249 | if (it == tableInstanceMap2.end()) |
| 250 | { |
| 251 | pTable = new VkLayerInstanceDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 252 | tableInstanceMap2[(void *) *ppDisp] = pTable; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 253 | initLayerInstanceTable(instw, pTable, 2); |
| 254 | return pTable; |
| 255 | } else |
| 256 | { |
| 257 | return it->second; |
| 258 | } |
| 259 | } |
| 260 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 261 | static VkLayerDispatchTable *getLayer2Table(const VkBaseLayerObject *devw) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 262 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 263 | VkLayerDispatchTable *pTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 264 | assert(devw); |
| 265 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 266 | |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 267 | std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) *ppDisp); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 268 | if (it == tableMap2.end()) |
| 269 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 270 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 271 | tableMap2[(void *) *ppDisp] = pTable; |
| 272 | initLayerTable(devw, pTable, 2); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 273 | return pTable; |
| 274 | } else |
| 275 | { |
| 276 | return it->second; |
| 277 | } |
| 278 | } |
| 279 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 280 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices( |
| 281 | VkInstance instance, |
| 282 | uint32_t* pPhysicalDeviceCount, |
| 283 | VkPhysicalDevice* pPhysicalDevices) |
| 284 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 285 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 286 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 287 | printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 288 | VkResult result = instance_dispatch_table2(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 289 | printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); |
| 290 | return result; |
| 291 | } |
| 292 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 293 | /* hook DextroyDevice to remove tableMap entry */ |
| 294 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyDevice(VkDevice device) |
| 295 | { |
| 296 | VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 297 | VkResult res = device_dispatch_table2(device)->DestroyDevice(device); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 298 | tableMap2.erase(pDisp); |
| 299 | return res; |
| 300 | } |
| 301 | |
| 302 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 303 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyInstance(VkInstance instance) |
| 304 | { |
| 305 | VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 306 | VkResult res = instance_dispatch_table2(instance)->DestroyInstance(instance); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 307 | tableInstanceMap2.erase(pDisp); |
| 308 | return res; |
| 309 | } |
| 310 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 311 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 312 | VkDevice* pDevice) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 313 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 314 | printf("At start of multi2 vkCreateDevice()\n"); |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 315 | VkResult result = device_dispatch_table2(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 316 | printf("Completed multi2 layer vkCreateDevice()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 317 | return result; |
| 318 | } |
| 319 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 320 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, |
| 321 | VkCmdBuffer* pCmdBuffer) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 322 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 323 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 324 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 325 | printf("At start of multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 326 | VkResult result = device_dispatch_table2(device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | printf("Completed multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 328 | return result; |
| 329 | } |
| 330 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 331 | VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 332 | { |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 333 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) cmdBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 334 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 335 | printf("At start of multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 336 | VkResult result = device_dispatch_table2(cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 337 | printf("Completed multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 338 | return result; |
| 339 | |
| 340 | } |
| 341 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 342 | VK_LAYER_EXPORT void * VKAPI multi2GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 343 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 344 | VkBaseLayerObject* devw = (VkBaseLayerObject *) device; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 345 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 346 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 347 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 348 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 349 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
| 350 | getLayer2Table(devw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 351 | return (void *) multi2GetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 352 | } |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 353 | if (!strcmp("vkCreateDevice", pName)) |
| 354 | return (void *) multi2CreateDevice; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 355 | if (!strcmp("vkDestroyDevice", pName)) |
| 356 | return (void *) multi2DestroyDevice; |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 357 | if (!strcmp("vkCreateCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 358 | return (void *) multi2CreateCommandBuffer; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 359 | else if (!strcmp("vkBeginCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 360 | return (void *) multi2BeginCommandBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 361 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 362 | VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 363 | VkLayerDispatchTable* pTable = device_dispatch_table2(device); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 364 | if (pTable->GetDeviceProcAddr == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 365 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 366 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 370 | VK_LAYER_EXPORT void * VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 371 | { |
| 372 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 373 | |
| 374 | if (inst == NULL) |
| 375 | return NULL; |
| 376 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 377 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
| 378 | getLayer2InstanceTable(instw); |
Jon Ashburn | 7cb4e0e | 2015-05-19 10:05:54 -0600 | [diff] [blame] | 379 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 380 | } |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 381 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
| 382 | return (void *) multi2EnumeratePhysicalDevices; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 383 | if (!strcmp("vkDestroyInstance", pName)) |
| 384 | return (void *) multi2DestroyInstance; |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 385 | if (!strcmp("GetGlobalExtensionProperties", pName)) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 386 | return (void*) vkGetGlobalExtensionProperties; |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 387 | if (!strcmp("GetGlobalLayerProperties", pName)) |
| 388 | return (void*) vkGetGlobalLayerProperties; |
| 389 | if (!strcmp("GetPhysicalDeviceExtensionProperties", pName)) |
| 390 | return (void*) vkGetPhysicalDeviceExtensionProperties; |
| 391 | if (!strcmp("GetPhysicalDeviceLayerProperties", pName)) |
| 392 | return (void*) vkGetPhysicalDeviceLayerProperties; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 393 | else { |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 394 | VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) inst; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 395 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table2(inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 396 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 397 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 398 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 399 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /********************************* Common functions ********************************/ |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 403 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 404 | struct extProps { |
| 405 | uint32_t version; |
| 406 | const char * const name; |
| 407 | }; |
| 408 | |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 409 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
| 410 | const char *pLayerName, |
| 411 | uint32_t *pCount, |
| 412 | VkExtensionProperties* pProperties) |
| 413 | { |
| 414 | /* multi does not have any global extensions */ |
| 415 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 416 | } |
| 417 | |
| 418 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties( |
| 419 | uint32_t *pCount, |
| 420 | VkLayerProperties* pProperties) |
| 421 | { |
| 422 | /* multi does not have any global layers */ |
| 423 | return util_GetLayerProperties(0, NULL, pCount, pProperties); |
| 424 | } |
| 425 | |
| 426 | #define MULTI_LAYER_ARRAY_SIZE 1 |
| 427 | static const VkLayerProperties multi_device_layers[MULTI_LAYER_ARRAY_SIZE] = { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 428 | { |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 429 | "Multi1", |
| 430 | VK_API_VERSION, |
| 431 | VK_MAKE_VERSION(0, 1, 0), |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 432 | "Sample layer: multi", |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 433 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 434 | }; |
| 435 | |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 436 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties( |
| 437 | VkPhysicalDevice physicalDevice, |
| 438 | const char* pLayerName, |
| 439 | uint32_t* pCount, |
| 440 | VkExtensionProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 441 | { |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 442 | /* Multi does not have any physical device extensions */ |
| 443 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 444 | } |
| 445 | |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 446 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties( |
| 447 | VkPhysicalDevice physicalDevice, |
| 448 | uint32_t* pCount, |
| 449 | VkLayerProperties* pProperties) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 450 | { |
Courtney Goeltzenleuchter | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 451 | return util_GetLayerProperties(MULTI_LAYER_ARRAY_SIZE, multi_device_layers, |
| 452 | pCount, pProperties); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 453 | } |
| 454 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 455 | VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 456 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 457 | // to find each layers GPA routine Loader will search via "<layerName>GetDeviceProcAddr" |
| 458 | if (!strcmp("multi1GetDeviceProcAddr", pName)) |
| 459 | return (void *) multi1GetDeviceProcAddr; |
| 460 | else if (!strcmp("multi2GetDeviceProcAddr", pName)) |
| 461 | return (void *) multi2GetDeviceProcAddr; |
| 462 | else if (!strcmp("vkGetDeviceProcAddr", pName)) |
| 463 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 464 | |
| 465 | // use first layer activated as GPA dispatch table activation happens in order |
| 466 | else if (layer1_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 467 | return multi1GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 468 | else if (layer2_first_activated) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 469 | return multi2GetDeviceProcAddr(device, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 470 | else |
| 471 | return NULL; |
| 472 | |
| 473 | } |
| 474 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 475 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* pName) |
| 476 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 477 | // to find each layers GPA routine Loader will search via "<layerName>GetInstanceProcAddr" |
| 478 | if (!strcmp("multi1GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 479 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 480 | else if (!strcmp("multi2GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 481 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 482 | else if (!strcmp("vkGetInstanceProcAddr", pName)) |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 483 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 484 | |
| 485 | // use first layer activated as GPA dispatch table activation happens in order |
| 486 | else if (layer1_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 487 | return multi1GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 488 | else if (layer2_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 489 | return multi2GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 490 | else |
| 491 | return NULL; |
| 492 | |
| 493 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 494 | #ifdef __cplusplus |
| 495 | } //extern "C" |
| 496 | #endif |
| 497 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 498 | static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 499 | { |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 500 | if (layerNum == 2 && layer1_first_activated == false) |
| 501 | layer2_first_activated = true; |
| 502 | if (layerNum == 1 && layer2_first_activated == false) |
| 503 | layer1_first_activated = true; |
| 504 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 505 | layer_initialize_dispatch_table(pTable, devw); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 506 | } |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 507 | |
| 508 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum) |
| 509 | { |
| 510 | if (layerNum == 2 && layer1_first_activated == false) |
| 511 | layer2_first_activated = true; |
| 512 | if (layerNum == 1 && layer2_first_activated == false) |
| 513 | layer1_first_activated = true; |
| 514 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 515 | layer_init_instance_dispatch_table(pTable, instw); |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 516 | } |