blob: 910bc5bb3f0823b78a4ac1a52b14b631054ec44f [file] [log] [blame]
Jon Ashburn79113cc2014-12-01 14:22:40 -07001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 * Vulkan
Jon Ashburn79113cc2014-12-01 14:22:40 -07003 *
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 Elliott2d4ab1e2015-01-13 17:52:38 -070030#include "loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vkLayer.h"
Ian Elliott655cad72015-02-12 17:08:34 -070033// The following is #included again to catch certain OS-specific functions
34// being used:
35#include "loader_platform.h"
Jon Ashburn79113cc2014-12-01 14:22:40 -070036
Jon Ashburnbacb0f52015-04-06 10:58:22 -060037static void initLayerTable(const VkBaseLayerObject *gpuw, VkLayerDispatchTable *pTable, const unsigned int layerNum);
Jon Ashburn79113cc2014-12-01 14:22:40 -070038
39/******************************** Layer multi1 functions **************************/
Jon Ashburnbacb0f52015-04-06 10:58:22 -060040static std::unordered_map<void *, VkLayerDispatchTable *> tableMap1;
Jon Ashburn79113cc2014-12-01 14:22:40 -070041static bool layer1_first_activated = false;
42
Jon Ashburnbacb0f52015-04-06 10:58:22 -060043static VkLayerDispatchTable * getLayer1Table(const VkBaseLayerObject *gpuw)
Jon Ashburn79113cc2014-12-01 14:22:40 -070044{
Jon Ashburnbacb0f52015-04-06 10:58:22 -060045 VkLayerDispatchTable *pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -070046
47 assert(gpuw);
Jon Ashburn4d9f4652015-04-08 21:33:34 -060048 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap1.find((void *) gpuw->baseObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -070049 if (it == tableMap1.end())
50 {
Jon Ashburnbacb0f52015-04-06 10:58:22 -060051 pTable = new VkLayerDispatchTable;
Jon Ashburn4d9f4652015-04-08 21:33:34 -060052 tableMap1[(void *) gpuw->baseObject] = pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -070053 initLayerTable(gpuw, pTable, 1);
54 return pTable;
55 } else
56 {
57 return it->second;
58 }
59}
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060065VK_LAYER_EXPORT VkResult VKAPI multi1CreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo,
66 VkDevice* pDevice)
Jon Ashburn79113cc2014-12-01 14:22:40 -070067{
Jon Ashburn4d9f4652015-04-08 21:33:34 -060068 VkLayerDispatchTable* pTable = tableMap1[gpu];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060069 printf("At start of multi1 layer vkCreateDevice()\n");
Jon Ashburn4d9f4652015-04-08 21:33:34 -060070 VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice);
Jon Ashburn79113cc2014-12-01 14:22:40 -070071 // create a mapping for the device object into the dispatch table
72 tableMap1.emplace(*pDevice, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060073 printf("Completed multi1 layer vkCreateDevice()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070074 return result;
75}
76
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060077VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo,
78 VkPipeline* pPipeline)
Jon Ashburn79113cc2014-12-01 14:22:40 -070079{
Jon Ashburnbacb0f52015-04-06 10:58:22 -060080 VkLayerDispatchTable* pTable = tableMap1[device];
Jon Ashburn79113cc2014-12-01 14:22:40 -070081
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060082 printf("At start of multi1 layer vkCreateGraphicsPipeline()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060083 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Jon Ashburn79113cc2014-12-01 14:22:40 -070084 // create a mapping for the pipeline object into the dispatch table
85 tableMap1.emplace(*pPipeline, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060086 printf("Completed multi1 layer vkCreateGraphicsPipeline()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070087 return result;
88}
89
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060090VK_LAYER_EXPORT VkResult VKAPI multi1StorePipeline(VkPipeline pipeline, size_t* pDataSize, void* pData)
Jon Ashburn79113cc2014-12-01 14:22:40 -070091{
Jon Ashburnbacb0f52015-04-06 10:58:22 -060092 VkLayerDispatchTable* pTable = tableMap1[pipeline];
Jon Ashburn79113cc2014-12-01 14:22:40 -070093
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094 printf("At start of multi1 layer vkStorePipeline()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060095 VkResult result = pTable->StorePipeline(pipeline, pDataSize, pData);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060096 printf("Completed multi1 layer vkStorePipeline()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070097 return result;
98}
99
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600100VK_LAYER_EXPORT VkResult VKAPI multi1EnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount, size_t maxStringSize,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600101 size_t* pOutLayerCount, char* const* pOutLayers,
102 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700103{
104 if (gpu == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600105 return vkEnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700106
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600107 VkLayerDispatchTable* pTable = tableMap1[gpu];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600108 printf("At start of multi1 layer vkEnumerateLayers()\n");
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600109 VkResult result = pTable->EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600110 printf("Completed multi1 layer vkEnumerateLayers()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700111 return result;
112}
113
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600114VK_LAYER_EXPORT VkResult VKAPI multi1GetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
115{
116 VkResult result;
117
118 if (!tableMap1.empty() && (tableMap1.find(gpu) != tableMap1.end()))
119 {
120 VkLayerDispatchTable* pTable = tableMap1[gpu];
121 result = pTable->GetExtensionSupport(gpu, pExtName);
122 } else
123 {
124 result = VK_ERROR_INVALID_EXTENSION;
125 }
126 return result;
127}
128
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600129VK_LAYER_EXPORT void * VKAPI multi1GetProcAddr(VkPhysicalGpu gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700130{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600131 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wub665d942015-01-05 09:41:27 +0800132
Jon Ashburn79113cc2014-12-01 14:22:40 -0700133 if (gpu == NULL)
134 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800135
136 getLayer1Table(gpuw);
137
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600138 if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600139 return (void *) multi1CreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600140 else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600141 return (void *) multi1EnumerateLayers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600142 else if (!strncmp("vkCreateGraphicsPipeline", pName, sizeof ("vkCreateGraphicsPipeline")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600143 return (void *) multi1CreateGraphicsPipeline;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600144 else if (!strncmp("vkStorePipeline", pName, sizeof ("vkStorePipeline")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600145 return (void *) multi1StorePipeline;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600146 else if (!strncmp("vkGetExtensionSupport", pName, sizeof ("vkGetExtensionSupport")))
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600147 return (void *) multi1GetExtensionSupport;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700148 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700149 if (gpuw->pGPA == NULL)
150 return NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600151 return gpuw->pGPA((VkPhysicalGpu) gpuw->nextObject, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700152 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700153}
154
155/******************************** Layer multi2 functions **************************/
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600156static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700157static bool layer2_first_activated = false;
158
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600159static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700160{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600161 VkLayerDispatchTable *pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700162
163 assert(gpuw);
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600164 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) gpuw->baseObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700165 if (it == tableMap2.end())
166 {
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600167 pTable = new VkLayerDispatchTable;
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600168 tableMap2[(void *) gpuw->baseObject] = pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700169 initLayerTable(gpuw, pTable, 2);
170 return pTable;
171 } else
172 {
173 return it->second;
174 }
175}
176
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600177VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo,
178 VkDevice* pDevice)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700179{
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600180 VkLayerDispatchTable* pTable = tableMap2[gpu];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700181
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600182 printf("At start of multi2 vkCreateDevice()\n");
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600183 VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700184 // create a mapping for the device object into the dispatch table for layer2
185 tableMap2.emplace(*pDevice, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600186 printf("Completed multi2 layer vkCreateDevice()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700187 return result;
188}
189
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600190VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo,
191 VkCmdBuffer* pCmdBuffer)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700192{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600193 VkLayerDispatchTable* pTable = tableMap2[device];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700194
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600195 printf("At start of multi2 layer vkCreateCommandBuffer()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600196 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700197 // create a mapping for CmdBuffer object into the dispatch table for layer 2
198 tableMap2.emplace(*pCmdBuffer, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600199 printf("Completed multi2 layer vkCreateCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700200 return result;
201}
202
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600203VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700204{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600205 VkLayerDispatchTable* pTable = tableMap2[cmdBuffer];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700206
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600207 printf("At start of multi2 layer vkBeginCommandBuffer()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600208 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600209 printf("Completed multi2 layer vkBeginCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700210 return result;
211
212}
213
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600214VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount, size_t maxStringSize,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600215 size_t* pOutLayerCount, char* const* pOutLayers,
216 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700217{
218 if (gpu == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600219 return vkEnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700220
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600221 VkLayerDispatchTable* pTable = tableMap2[gpu];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700222
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600223 printf("At start of multi2 layer vkEnumerateLayers()\n");
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600224 VkResult result = pTable->EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600225 printf("Completed multi2 layer vkEnumerateLayers()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700226 return result;
227}
228
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600229VK_LAYER_EXPORT VkResult VKAPI multi2GetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
230{
231 VkResult result;
232
233 if (!tableMap2.empty() && (tableMap2.find(gpu) != tableMap2.end()))
234 {
235 VkLayerDispatchTable* pTable = tableMap2[gpu];
236 result = pTable->GetExtensionSupport(gpu, pExtName);
237 } else
238 {
239 result = VK_ERROR_INVALID_EXTENSION;
240 }
241 return result;
242}
243
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600244VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalGpu gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700245{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600246 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wub665d942015-01-05 09:41:27 +0800247
Jon Ashburn79113cc2014-12-01 14:22:40 -0700248 if (gpu == NULL)
249 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800250
251 getLayer2Table(gpuw);
252
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600253 if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600254 return (void *) multi2CreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600255 else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600256 return (void *) multi2EnumerateLayers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600257 else if (!strncmp("vkCreateCommandBuffer", pName, sizeof ("vkCreateCommandBuffer")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600258 return (void *) multi2CreateCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600259 else if (!strncmp("vkBeginCommandBuffer", pName, sizeof ("vkBeginCommandBuffer")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600260 return (void *) multi2BeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600261 else if (!strncmp("vkGetExtensionSupport", pName, sizeof ("vkGetExtensionSupport")))
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600262 return (void *) multi2GetExtensionSupport;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700263 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700264 if (gpuw->pGPA == NULL)
265 return NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600266 return gpuw->pGPA((VkPhysicalGpu) gpuw->nextObject, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700267 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700268}
269
270/********************************* Common functions ********************************/
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600271VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount, size_t maxStringSize,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600272 size_t* pOutLayerCount, char* const* pOutLayers,
273 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700274{
275 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600276 return VK_ERROR_INVALID_POINTER;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700277
278 if (maxLayerCount < 2)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600279 return VK_ERROR_INITIALIZATION_FAILED;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700280 *pOutLayerCount = 2;
281 strncpy((char *) pOutLayers[0], "multi1", maxStringSize);
282 strncpy((char *) pOutLayers[1], "multi2", maxStringSize);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600283 return VK_SUCCESS;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700284}
285
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600286VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600287{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600288 VkResult result;
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600289
290 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
291 if (!strncmp(pExtName, "multi1", strlen("multi1")))
292 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600293 result = VK_SUCCESS;
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600294 } else if (!strncmp(pExtName, "multi2", strlen("multi2")))
295 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600296 result = VK_SUCCESS;
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600297 } else if (!tableMap1.empty() && (tableMap1.find(gpu) != tableMap1.end()))
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600298 {
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600299 VkLayerDispatchTable* pTable = tableMap1[gpu];
300 result = pTable->GetExtensionSupport(gpu, pExtName);
301 } else if (!tableMap2.empty() && (tableMap2.find(gpu) != tableMap2.end()))
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600302 {
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600303 VkLayerDispatchTable* pTable = tableMap2[gpu];
304 result = pTable->GetExtensionSupport(gpu, pExtName);
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600305 } else
306 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600307 result = VK_ERROR_INVALID_EXTENSION;
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600308 }
309 return result;
310}
311
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600312VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700313{
314 // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr"
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800315 if (!strncmp("multi1GetProcAddr", pName, sizeof("multi1GetProcAddr")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600316 return (void *) multi1GetProcAddr;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800317 else if (!strncmp("multi2GetProcAddr", pName, sizeof("multi2GetProcAddr")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600318 return (void *) multi2GetProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600319 else if (!strncmp("vkGetProcAddr", pName, sizeof("vkGetProcAddr")))
320 return (void *) vkGetProcAddr;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700321
322 // use first layer activated as GPA dispatch table activation happens in order
323 else if (layer1_first_activated)
324 return multi1GetProcAddr(gpu, pName);
325 else if (layer2_first_activated)
326 return multi2GetProcAddr(gpu, pName);
327 else
328 return NULL;
329
330}
331
332#ifdef __cplusplus
333} //extern "C"
334#endif
335
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600336static void initLayerTable(const VkBaseLayerObject *gpuw, VkLayerDispatchTable *pTable, const unsigned int layerNum)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700337{
Jon Ashburn79113cc2014-12-01 14:22:40 -0700338 if (layerNum == 2 && layer1_first_activated == false)
339 layer2_first_activated = true;
340 if (layerNum == 1 && layer2_first_activated == false)
341 layer1_first_activated = true;
342
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600343 layer_initialize_dispatch_table(pTable, gpuw->pGPA, (VkPhysicalGpu) gpuw->nextObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700344}