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 | |
| 83 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 84 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 85 | VkDevice* pDevice) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 86 | { |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 87 | VkLayerDispatchTable* pTable = tableMap1[gpu]; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 88 | printf("At start of multi1 layer vkCreateDevice()\n"); |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 89 | VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 90 | // create a mapping for the device object into the dispatch table |
| 91 | tableMap1.emplace(*pDevice, pTable); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 92 | printf("Completed multi1 layer vkCreateDevice()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 93 | return result; |
| 94 | } |
| 95 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 96 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, |
| 97 | VkPipeline* pPipeline) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 98 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 99 | VkLayerDispatchTable* pTable = tableMap1[device]; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 100 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 101 | printf("At start of multi1 layer vkCreateGraphicsPipeline()\n"); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 102 | VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 103 | // create a mapping for the pipeline object into the dispatch table |
| 104 | tableMap1.emplace(*pPipeline, pTable); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 105 | printf("Completed multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 106 | return result; |
| 107 | } |
| 108 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 109 | 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] | 110 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 111 | VkLayerDispatchTable* pTable = tableMap1[pipeline]; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 112 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 113 | printf("At start of multi1 layer vkStorePipeline()\n"); |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 114 | VkResult result = pTable->StorePipeline(device, pipeline, pDataSize, pData); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 115 | printf("Completed multi1 layer vkStorePipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 116 | return result; |
| 117 | } |
| 118 | |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 119 | VK_LAYER_EXPORT VkResult VKAPI multi1EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 120 | size_t* pLayerCount, char* const* pOutLayers, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 121 | void* pReserved) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 122 | { |
| 123 | if (gpu == NULL) |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 124 | return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 125 | |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 126 | VkLayerDispatchTable* pTable = tableMap1[gpu]; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 127 | printf("At start of multi1 layer vkEnumerateLayers()\n"); |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 128 | VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 129 | printf("Completed multi1 layer vkEnumerateLayers()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 130 | return result; |
| 131 | } |
| 132 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 133 | VK_LAYER_EXPORT void * VKAPI multi1GetProcAddr(VkPhysicalDevice gpu, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 134 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 135 | VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 136 | |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 137 | if (gpu == NULL) |
| 138 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 139 | |
| 140 | getLayer1Table(gpuw); |
| 141 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 142 | if (!strcmp("vkCreateDevice", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 143 | return (void *) multi1CreateDevice; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 144 | else if (!strcmp("vkEnumerateLayers", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 145 | return (void *) multi1EnumerateLayers; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 146 | else if (!strcmp("GetGlobalExtensionInfo", pName)) |
| 147 | return (void*) vkGetGlobalExtensionInfo; |
| 148 | else if (!strcmp("vkCreateGraphicsPipeline", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 149 | return (void *) multi1CreateGraphicsPipeline; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 150 | else if (!strcmp("vkStorePipeline", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 151 | return (void *) multi1StorePipeline; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 152 | else { |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 153 | if (gpuw->pGPA == NULL) |
| 154 | return NULL; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 155 | return gpuw->pGPA((VkObject) gpuw->nextObject, pName); |
| 156 | } |
| 157 | } |
| 158 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 159 | VK_LAYER_EXPORT void * VKAPI multi1GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 160 | { |
| 161 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 162 | |
| 163 | if (inst == NULL) |
| 164 | return NULL; |
| 165 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 166 | getLayer1InstanceTable(instw); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 167 | |
| 168 | if (!strcmp("vkCreateDevice", pName)) |
| 169 | return (void *) multi1CreateDevice; |
| 170 | else if (!strcmp("vkEnumerateLayers", pName)) |
| 171 | return (void *) multi1EnumerateLayers; |
| 172 | else if (!strcmp("GetGlobalExtensionInfo", pName)) |
| 173 | return (void*) vkGetGlobalExtensionInfo; |
| 174 | else { |
| 175 | if (instw->pGPA == NULL) |
| 176 | return NULL; |
| 177 | return instw->pGPA((VkObject) instw->nextObject, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 178 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 182 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2; |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 183 | static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap2; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 184 | static bool layer2_first_activated = false; |
| 185 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 186 | static VkLayerInstanceDispatchTable * getLayer2InstanceTable(const VkBaseLayerObject *instw) |
| 187 | { |
| 188 | VkLayerInstanceDispatchTable *pTable; |
| 189 | |
| 190 | assert(instw); |
| 191 | std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) instw->baseObject); |
| 192 | if (it == tableInstanceMap2.end()) |
| 193 | { |
| 194 | pTable = new VkLayerInstanceDispatchTable; |
| 195 | tableInstanceMap2[(void *) instw->baseObject] = pTable; |
| 196 | initLayerInstanceTable(instw, pTable, 2); |
| 197 | return pTable; |
| 198 | } else |
| 199 | { |
| 200 | return it->second; |
| 201 | } |
| 202 | } |
| 203 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 204 | static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 205 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 206 | VkLayerDispatchTable *pTable; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 207 | |
| 208 | assert(gpuw); |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 209 | 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] | 210 | if (it == tableMap2.end()) |
| 211 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 212 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 213 | tableMap2[(void *) gpuw->baseObject] = pTable; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 214 | initLayerTable(gpuw, pTable, 2); |
| 215 | return pTable; |
| 216 | } else |
| 217 | { |
| 218 | return it->second; |
| 219 | } |
| 220 | } |
| 221 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 222 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 223 | VkDevice* pDevice) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 224 | { |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 225 | VkLayerDispatchTable* pTable = tableMap2[gpu]; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 226 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 227 | printf("At start of multi2 vkCreateDevice()\n"); |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 228 | VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 229 | // create a mapping for the device object into the dispatch table for layer2 |
| 230 | tableMap2.emplace(*pDevice, pTable); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 231 | printf("Completed multi2 layer vkCreateDevice()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 232 | return result; |
| 233 | } |
| 234 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 235 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, |
| 236 | VkCmdBuffer* pCmdBuffer) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 237 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 238 | VkLayerDispatchTable* pTable = tableMap2[device]; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 239 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 240 | printf("At start of multi2 layer vkCreateCommandBuffer()\n"); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 241 | VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 242 | // create a mapping for CmdBuffer object into the dispatch table for layer 2 |
| 243 | tableMap2.emplace(*pCmdBuffer, pTable); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 244 | printf("Completed multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 245 | return result; |
| 246 | } |
| 247 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 248 | VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 249 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 250 | VkLayerDispatchTable* pTable = tableMap2[cmdBuffer]; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 251 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 252 | printf("At start of multi2 layer vkBeginCommandBuffer()\n"); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 253 | VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 254 | printf("Completed multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 255 | return result; |
| 256 | |
| 257 | } |
| 258 | |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 259 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 260 | size_t* pLayerCount, char* const* pOutLayers, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 261 | void* pReserved) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 262 | { |
| 263 | if (gpu == NULL) |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 264 | return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 265 | |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 266 | VkLayerDispatchTable* pTable = tableMap2[gpu]; |
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 vkEnumerateLayers()\n"); |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 269 | VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 270 | printf("Completed multi2 layer vkEnumerateLayers()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 271 | return result; |
| 272 | } |
| 273 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 274 | VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalDevice gpu, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 275 | { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 276 | VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 277 | |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 278 | if (gpu == NULL) |
| 279 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 280 | |
| 281 | getLayer2Table(gpuw); |
| 282 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 283 | if (!strcmp("vkCreateDevice", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 284 | return (void *) multi2CreateDevice; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 285 | else if (!strcmp("vkEnumerateLayers", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 286 | return (void *) multi2EnumerateLayers; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 287 | else if (!strcmp("GetGlobalExtensionInfo", pName)) |
| 288 | return (void*) vkGetGlobalExtensionInfo; |
| 289 | else if (!strcmp("vkCreateCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 290 | return (void *) multi2CreateCommandBuffer; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 291 | else if (!strcmp("vkBeginCommandBuffer", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 292 | return (void *) multi2BeginCommandBuffer; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 293 | else { |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 294 | if (gpuw->pGPA == NULL) |
| 295 | return NULL; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 296 | return gpuw->pGPA((VkObject) gpuw->nextObject, pName); |
| 297 | } |
| 298 | } |
| 299 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 300 | VK_LAYER_EXPORT void * VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 301 | { |
| 302 | VkBaseLayerObject* instw = (VkBaseLayerObject *) inst; |
| 303 | |
| 304 | if (inst == NULL) |
| 305 | return NULL; |
| 306 | |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 307 | getLayer2InstanceTable(instw); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 308 | |
| 309 | if (!strcmp("vkCreateDevice", pName)) |
| 310 | return (void *) multi2CreateDevice; |
| 311 | else if (!strcmp("vkEnumerateLayers", pName)) |
| 312 | return (void *) multi2EnumerateLayers; |
| 313 | else if (!strcmp("GetGlobalExtensionInfo", pName)) |
| 314 | return (void*) vkGetGlobalExtensionInfo; |
| 315 | else { |
| 316 | if (instw->pGPA == NULL) |
| 317 | return NULL; |
| 318 | return instw->pGPA((VkObject) instw->nextObject, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 319 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /********************************* Common functions ********************************/ |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 323 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 324 | size_t* pLayerCount, char* const* pOutLayers, |
| 325 | void* pReserved) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 326 | { |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 327 | 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] | 328 | return VK_ERROR_INVALID_POINTER; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 329 | |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 330 | if (*pLayerCount < 2) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 331 | return VK_ERROR_INITIALIZATION_FAILED; |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 332 | *pLayerCount = 2; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 333 | strncpy((char *) pOutLayers[0], "multi1", maxStringSize); |
| 334 | strncpy((char *) pOutLayers[1], "multi2", maxStringSize); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 335 | return VK_SUCCESS; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 338 | struct extProps { |
| 339 | uint32_t version; |
| 340 | const char * const name; |
| 341 | }; |
| 342 | |
| 343 | #define MULTI_LAYER_EXT_ARRAY_SIZE 2 |
| 344 | static const struct extProps multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = { |
| 345 | // TODO what is the version? |
| 346 | 0x10, "multi1", |
| 347 | 0x10, "multi2", |
| 348 | }; |
| 349 | |
| 350 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
| 351 | VkExtensionInfoType infoType, |
| 352 | uint32_t extensionIndex, |
| 353 | size_t* pDataSize, |
| 354 | void* pData) |
| 355 | { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 356 | /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */ |
| 357 | VkExtensionProperties *ext_props; |
| 358 | uint32_t *count; |
| 359 | |
| 360 | if (pDataSize == NULL) |
| 361 | return VK_ERROR_INVALID_POINTER; |
| 362 | |
| 363 | switch (infoType) { |
| 364 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 365 | *pDataSize = sizeof(uint32_t); |
| 366 | if (pData == NULL) |
| 367 | return VK_SUCCESS; |
| 368 | count = (uint32_t *) pData; |
| 369 | *count = MULTI_LAYER_EXT_ARRAY_SIZE; |
| 370 | break; |
| 371 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 372 | *pDataSize = sizeof(VkExtensionProperties); |
| 373 | if (pData == NULL) |
| 374 | return VK_SUCCESS; |
| 375 | if (extensionIndex >= MULTI_LAYER_EXT_ARRAY_SIZE) |
| 376 | return VK_ERROR_INVALID_VALUE; |
| 377 | ext_props = (VkExtensionProperties *) pData; |
| 378 | ext_props->version = multiExts[extensionIndex].version; |
| 379 | strncpy(ext_props->extName, multiExts[extensionIndex].name, |
| 380 | VK_MAX_EXTENSION_NAME); |
| 381 | ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0'; |
| 382 | break; |
| 383 | default: |
| 384 | return VK_ERROR_INVALID_VALUE; |
| 385 | }; |
| 386 | |
| 387 | return VK_SUCCESS; |
| 388 | } |
| 389 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 390 | VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 391 | { |
| 392 | // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr" |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 393 | if (!strcmp("multi1GetProcAddr", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 394 | return (void *) multi1GetProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 395 | else if (!strcmp("multi2GetProcAddr", pName)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 396 | return (void *) multi2GetProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 397 | else if (!strcmp("vkGetProcAddr", pName)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 398 | return (void *) vkGetProcAddr; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 399 | |
| 400 | // use first layer activated as GPA dispatch table activation happens in order |
| 401 | else if (layer1_first_activated) |
| 402 | return multi1GetProcAddr(gpu, pName); |
| 403 | else if (layer2_first_activated) |
| 404 | return multi2GetProcAddr(gpu, pName); |
| 405 | else |
| 406 | return NULL; |
| 407 | |
| 408 | } |
| 409 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 410 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* pName) |
| 411 | { |
| 412 | // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr" |
| 413 | if (!strcmp("multi1GetProcAddr", pName)) |
| 414 | return (void *) multi1GetProcAddr; |
| 415 | else if (!strcmp("multi2GetProcAddr", pName)) |
| 416 | return (void *) multi2GetProcAddr; |
| 417 | else if (!strcmp("vkGetProcAddr", pName)) |
| 418 | return (void *) vkGetProcAddr; |
| 419 | else if (!strcmp("multi1GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 420 | return (void *) multi1GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 421 | else if (!strcmp("multi2GetInstanceProcAddr", pName)) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 422 | return (void *) multi2GetInstanceProcAddr; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 423 | else if (!strcmp("vkGetInstanceProcAddr", pName)) |
| 424 | return (void *) vkGetProcAddr; |
| 425 | |
| 426 | // use first layer activated as GPA dispatch table activation happens in order |
| 427 | else if (layer1_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 428 | return multi1GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 429 | else if (layer2_first_activated) |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 430 | return multi2GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 431 | else |
| 432 | return NULL; |
| 433 | |
| 434 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 435 | #ifdef __cplusplus |
| 436 | } //extern "C" |
| 437 | #endif |
| 438 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 439 | static void initLayerTable(const VkBaseLayerObject *gpuw, VkLayerDispatchTable *pTable, const unsigned int layerNum) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 440 | { |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 441 | if (layerNum == 2 && layer1_first_activated == false) |
| 442 | layer2_first_activated = true; |
| 443 | if (layerNum == 1 && layer2_first_activated == false) |
| 444 | layer1_first_activated = true; |
| 445 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 446 | layer_initialize_dispatch_table(pTable, (PFN_vkGetProcAddr) gpuw->pGPA, (VkPhysicalDevice) gpuw->nextObject); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 447 | } |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame^] | 448 | |
| 449 | static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum) |
| 450 | { |
| 451 | if (layerNum == 2 && layer1_first_activated == false) |
| 452 | layer2_first_activated = true; |
| 453 | if (layerNum == 1 && layer2_first_activated == false) |
| 454 | layer1_first_activated = true; |
| 455 | |
| 456 | layer_init_instance_dispatch_table(pTable, (PFN_vkGetInstanceProcAddr) instw->pGPA, (VkInstance) instw->nextObject); |
| 457 | } |