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