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