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 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 124 | return (void *) multi1CreateDevice; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 125 | else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 126 | return (void *) multi1EnumerateLayers; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 127 | else if (!strncmp("vkCreateGraphicsPipeline", pName, sizeof ("vkCreateGraphicsPipeline"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 128 | return (void *) multi1CreateGraphicsPipeline; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 129 | else if (!strncmp("vkStorePipeline", pName, sizeof ("vkStorePipeline"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 130 | return (void *) multi1StorePipeline; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 131 | else { |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 132 | if (gpuw->pGPA == NULL) |
| 133 | return NULL; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 134 | return gpuw->pGPA((VkPhysicalDevice) gpuw->nextObject, pName); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 135 | } |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 139 | static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 140 | static bool layer2_first_activated = false; |
| 141 | |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 142 | static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 143 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 144 | VkLayerDispatchTable *pTable; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 145 | |
| 146 | assert(gpuw); |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 147 | 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] | 148 | if (it == tableMap2.end()) |
| 149 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 150 | pTable = new VkLayerDispatchTable; |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 151 | tableMap2[(void *) gpuw->baseObject] = pTable; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 152 | initLayerTable(gpuw, pTable, 2); |
| 153 | return pTable; |
| 154 | } else |
| 155 | { |
| 156 | return it->second; |
| 157 | } |
| 158 | } |
| 159 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 160 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 161 | VkDevice* pDevice) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 162 | { |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 163 | VkLayerDispatchTable* pTable = tableMap2[gpu]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 164 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 165 | printf("At start of multi2 vkCreateDevice()\n"); |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 166 | VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 167 | // create a mapping for the device object into the dispatch table for layer2 |
| 168 | tableMap2.emplace(*pDevice, pTable); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 169 | printf("Completed multi2 layer vkCreateDevice()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 170 | return result; |
| 171 | } |
| 172 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 173 | VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, |
| 174 | VkCmdBuffer* pCmdBuffer) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 175 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 176 | VkLayerDispatchTable* pTable = tableMap2[device]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 177 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 178 | printf("At start of multi2 layer vkCreateCommandBuffer()\n"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 179 | VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 180 | // create a mapping for CmdBuffer object into the dispatch table for layer 2 |
| 181 | tableMap2.emplace(*pCmdBuffer, pTable); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 182 | printf("Completed multi2 layer vkCreateCommandBuffer()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 183 | return result; |
| 184 | } |
| 185 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 186 | VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 187 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 188 | VkLayerDispatchTable* pTable = tableMap2[cmdBuffer]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 189 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 190 | printf("At start of multi2 layer vkBeginCommandBuffer()\n"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 191 | VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 192 | printf("Completed multi2 layer vkBeginCommandBuffer()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 193 | return result; |
| 194 | |
| 195 | } |
| 196 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 197 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 198 | size_t* pLayerCount, char* const* pOutLayers, |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 199 | void* pReserved) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 200 | { |
| 201 | if (gpu == NULL) |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 202 | return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 203 | |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 204 | VkLayerDispatchTable* pTable = tableMap2[gpu]; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 205 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 206 | printf("At start of multi2 layer vkEnumerateLayers()\n"); |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 207 | VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 208 | printf("Completed multi2 layer vkEnumerateLayers()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 209 | return result; |
| 210 | } |
| 211 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 212 | VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalDevice gpu, const char* pName) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 213 | { |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 214 | VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 215 | |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 216 | if (gpu == NULL) |
| 217 | return NULL; |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 218 | |
| 219 | getLayer2Table(gpuw); |
| 220 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 221 | if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 222 | return (void *) multi2CreateDevice; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 223 | else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 224 | return (void *) multi2EnumerateLayers; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 225 | else if (!strncmp("vkCreateCommandBuffer", pName, sizeof ("vkCreateCommandBuffer"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 226 | return (void *) multi2CreateCommandBuffer; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 227 | else if (!strncmp("vkBeginCommandBuffer", pName, sizeof ("vkBeginCommandBuffer"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 228 | return (void *) multi2BeginCommandBuffer; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 229 | else { |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 230 | if (gpuw->pGPA == NULL) |
| 231 | return NULL; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 232 | return gpuw->pGPA((VkPhysicalDevice) gpuw->nextObject, pName); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 233 | } |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /********************************* Common functions ********************************/ |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 237 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, |
| 238 | size_t* pLayerCount, char* const* pOutLayers, |
| 239 | void* pReserved) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 240 | { |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 241 | 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] | 242 | return VK_ERROR_INVALID_POINTER; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 243 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 244 | if (*pLayerCount < 2) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 245 | return VK_ERROR_INITIALIZATION_FAILED; |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 246 | *pLayerCount = 2; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 247 | strncpy((char *) pOutLayers[0], "multi1", maxStringSize); |
| 248 | strncpy((char *) pOutLayers[1], "multi2", maxStringSize); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 249 | return VK_SUCCESS; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 252 | struct extProps { |
| 253 | uint32_t version; |
| 254 | const char * const name; |
| 255 | }; |
| 256 | |
| 257 | #define MULTI_LAYER_EXT_ARRAY_SIZE 2 |
| 258 | static const struct extProps multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = { |
| 259 | // TODO what is the version? |
| 260 | 0x10, "multi1", |
| 261 | 0x10, "multi2", |
| 262 | }; |
| 263 | |
| 264 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
| 265 | VkExtensionInfoType infoType, |
| 266 | uint32_t extensionIndex, |
| 267 | size_t* pDataSize, |
| 268 | void* pData) |
| 269 | { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 270 | /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */ |
| 271 | VkExtensionProperties *ext_props; |
| 272 | uint32_t *count; |
| 273 | |
| 274 | if (pDataSize == NULL) |
| 275 | return VK_ERROR_INVALID_POINTER; |
| 276 | |
| 277 | switch (infoType) { |
| 278 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 279 | *pDataSize = sizeof(uint32_t); |
| 280 | if (pData == NULL) |
| 281 | return VK_SUCCESS; |
| 282 | count = (uint32_t *) pData; |
| 283 | *count = MULTI_LAYER_EXT_ARRAY_SIZE; |
| 284 | break; |
| 285 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 286 | *pDataSize = sizeof(VkExtensionProperties); |
| 287 | if (pData == NULL) |
| 288 | return VK_SUCCESS; |
| 289 | if (extensionIndex >= MULTI_LAYER_EXT_ARRAY_SIZE) |
| 290 | return VK_ERROR_INVALID_VALUE; |
| 291 | ext_props = (VkExtensionProperties *) pData; |
| 292 | ext_props->version = multiExts[extensionIndex].version; |
| 293 | strncpy(ext_props->extName, multiExts[extensionIndex].name, |
| 294 | VK_MAX_EXTENSION_NAME); |
| 295 | ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0'; |
| 296 | break; |
| 297 | default: |
| 298 | return VK_ERROR_INVALID_VALUE; |
| 299 | }; |
| 300 | |
| 301 | return VK_SUCCESS; |
| 302 | } |
| 303 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 304 | VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pName) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 305 | { |
| 306 | // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr" |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 307 | if (!strncmp("multi1GetProcAddr", pName, sizeof("multi1GetProcAddr"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 308 | return (void *) multi1GetProcAddr; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 309 | else if (!strncmp("multi2GetProcAddr", pName, sizeof("multi2GetProcAddr"))) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 310 | return (void *) multi2GetProcAddr; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 311 | else if (!strncmp("vkGetProcAddr", pName, sizeof("vkGetProcAddr"))) |
| 312 | return (void *) vkGetProcAddr; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 313 | |
| 314 | // use first layer activated as GPA dispatch table activation happens in order |
| 315 | else if (layer1_first_activated) |
| 316 | return multi1GetProcAddr(gpu, pName); |
| 317 | else if (layer2_first_activated) |
| 318 | return multi2GetProcAddr(gpu, pName); |
| 319 | else |
| 320 | return NULL; |
| 321 | |
| 322 | } |
| 323 | |
| 324 | #ifdef __cplusplus |
| 325 | } //extern "C" |
| 326 | #endif |
| 327 | |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 328 | static void initLayerTable(const VkBaseLayerObject *gpuw, VkLayerDispatchTable *pTable, const unsigned int layerNum) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 329 | { |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 330 | if (layerNum == 2 && layer1_first_activated == false) |
| 331 | layer2_first_activated = true; |
| 332 | if (layerNum == 1 && layer2_first_activated == false) |
| 333 | layer1_first_activated = true; |
| 334 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 335 | layer_initialize_dispatch_table(pTable, gpuw->pGPA, (VkPhysicalDevice) gpuw->nextObject); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 336 | } |