blob: a4856eb0d66a32b552d59202c8ae7c969eb3fdca [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
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060037static void initLayerTable(const VK_BASE_LAYER_OBJECT *gpuw, VK_LAYER_DISPATCH_TABLE *pTable, const unsigned int layerNum);
Jon Ashburn79113cc2014-12-01 14:22:40 -070038
39/******************************** Layer multi1 functions **************************/
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060040static std::unordered_map<void *, VK_LAYER_DISPATCH_TABLE *> tableMap1;
Jon Ashburn79113cc2014-12-01 14:22:40 -070041static bool layer1_first_activated = false;
42
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060043static VK_LAYER_DISPATCH_TABLE * getLayer1Table(const VK_BASE_LAYER_OBJECT *gpuw)
Jon Ashburn79113cc2014-12-01 14:22:40 -070044{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060045 VK_LAYER_DISPATCH_TABLE *pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -070046
47 assert(gpuw);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060048 std::unordered_map<void *, VK_LAYER_DISPATCH_TABLE *>::const_iterator it = tableMap1.find((void *) gpuw);
Jon Ashburn79113cc2014-12-01 14:22:40 -070049 if (it == tableMap1.end())
50 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060051 pTable = new VK_LAYER_DISPATCH_TABLE;
Mark Lobodzinski17caf572015-01-29 08:55:56 -060052 tableMap1[(void *) gpuw] = 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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060065VK_LAYER_EXPORT VK_RESULT VKAPI multi1CreateDevice(VK_PHYSICAL_GPU gpu, const VK_DEVICE_CREATE_INFO* pCreateInfo,
66 VK_DEVICE* pDevice)
Jon Ashburn79113cc2014-12-01 14:22:40 -070067{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060068 VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu;
69 VK_LAYER_DISPATCH_TABLE* pTable = getLayer1Table(gpuw);
Jon Ashburn79113cc2014-12-01 14:22:40 -070070
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060071 printf("At start of multi1 layer vkCreateDevice()\n");
72 VK_RESULT result = pTable->CreateDevice((VK_PHYSICAL_GPU)gpuw->nextObject, pCreateInfo, pDevice);
Jon Ashburn79113cc2014-12-01 14:22:40 -070073 // create a mapping for the device object into the dispatch table
74 tableMap1.emplace(*pDevice, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060075 printf("Completed multi1 layer vkCreateDevice()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070076 return result;
77}
78
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060079VK_LAYER_EXPORT VK_RESULT VKAPI multi1CreateGraphicsPipeline(VK_DEVICE device, const VK_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
80 VK_PIPELINE* pPipeline)
Jon Ashburn79113cc2014-12-01 14:22:40 -070081{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060082 VK_LAYER_DISPATCH_TABLE* pTable = tableMap1[device];
Jon Ashburn79113cc2014-12-01 14:22:40 -070083
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060084 printf("At start of multi1 layer vkCreateGraphicsPipeline()\n");
85 VK_RESULT result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Jon Ashburn79113cc2014-12-01 14:22:40 -070086 // create a mapping for the pipeline object into the dispatch table
87 tableMap1.emplace(*pPipeline, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060088 printf("Completed multi1 layer vkCreateGraphicsPipeline()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070089 return result;
90}
91
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060092VK_LAYER_EXPORT VK_RESULT VKAPI multi1StorePipeline(VK_PIPELINE pipeline, size_t* pDataSize, void* pData)
Jon Ashburn79113cc2014-12-01 14:22:40 -070093{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094 VK_LAYER_DISPATCH_TABLE* pTable = tableMap1[pipeline];
Jon Ashburn79113cc2014-12-01 14:22:40 -070095
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060096 printf("At start of multi1 layer vkStorePipeline()\n");
97 VK_RESULT result = pTable->StorePipeline(pipeline, pDataSize, pData);
98 printf("Completed multi1 layer vkStorePipeline()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070099 return result;
100}
101
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600102VK_LAYER_EXPORT VK_RESULT VKAPI multi1EnumerateLayers(VK_PHYSICAL_GPU gpu, size_t maxLayerCount, size_t maxStringSize,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600103 size_t* pOutLayerCount, char* const* pOutLayers,
104 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700105{
106 if (gpu == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600107 return vkEnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700108
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600109 VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu;
110 VK_LAYER_DISPATCH_TABLE* pTable = getLayer1Table(gpuw);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700111
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600112 printf("At start of multi1 layer vkEnumerateLayers()\n");
113 VK_RESULT result = pTable->EnumerateLayers((VK_PHYSICAL_GPU)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
114 printf("Completed multi1 layer vkEnumerateLayers()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700115 return result;
116}
117
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600118VK_LAYER_EXPORT void * VKAPI multi1GetProcAddr(VK_PHYSICAL_GPU gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700119{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600120 VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu;
Chia-I Wub665d942015-01-05 09:41:27 +0800121
Jon Ashburn79113cc2014-12-01 14:22:40 -0700122 if (gpu == NULL)
123 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800124
125 getLayer1Table(gpuw);
126
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600127 if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600128 return (void *) multi1CreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600129 else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600130 return (void *) multi1EnumerateLayers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600131 else if (!strncmp("vkCreateGraphicsPipeline", pName, sizeof ("vkCreateGraphicsPipeline")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600132 return (void *) multi1CreateGraphicsPipeline;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600133 else if (!strncmp("vkStorePipeline", pName, sizeof ("vkStorePipeline")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600134 return (void *) multi1StorePipeline;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600135 else if (!strncmp("vkGetExtensionSupport", pName, sizeof ("vkGetExtensionSupport")))
136 return (void *) vkGetExtensionSupport;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700137 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700138 if (gpuw->pGPA == NULL)
139 return NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600140 return gpuw->pGPA((VK_PHYSICAL_GPU) gpuw->nextObject, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700141 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700142}
143
144/******************************** Layer multi2 functions **************************/
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600145static std::unordered_map<void *, VK_LAYER_DISPATCH_TABLE *> tableMap2;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700146static bool layer2_first_activated = false;
147
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600148static VK_LAYER_DISPATCH_TABLE * getLayer2Table(const VK_BASE_LAYER_OBJECT *gpuw)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700149{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600150 VK_LAYER_DISPATCH_TABLE *pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700151
152 assert(gpuw);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600153 std::unordered_map<void *, VK_LAYER_DISPATCH_TABLE *>::const_iterator it = tableMap2.find((void *) gpuw);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700154 if (it == tableMap2.end())
155 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600156 pTable = new VK_LAYER_DISPATCH_TABLE;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600157 tableMap2[(void *) gpuw] = pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700158 initLayerTable(gpuw, pTable, 2);
159 return pTable;
160 } else
161 {
162 return it->second;
163 }
164}
165
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600166VK_LAYER_EXPORT VK_RESULT VKAPI multi2CreateDevice(VK_PHYSICAL_GPU gpu, const VK_DEVICE_CREATE_INFO* pCreateInfo,
167 VK_DEVICE* pDevice)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700168{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600169 VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu;
170 VK_LAYER_DISPATCH_TABLE* pTable = getLayer2Table(gpuw);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700171
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600172 printf("At start of multi2 vkCreateDevice()\n");
173 VK_RESULT result = pTable->CreateDevice((VK_PHYSICAL_GPU)gpuw->nextObject, pCreateInfo, pDevice);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700174 // create a mapping for the device object into the dispatch table for layer2
175 tableMap2.emplace(*pDevice, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600176 printf("Completed multi2 layer vkCreateDevice()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700177 return result;
178}
179
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600180VK_LAYER_EXPORT VK_RESULT VKAPI multi2CreateCommandBuffer(VK_DEVICE device, const VK_CMD_BUFFER_CREATE_INFO* pCreateInfo,
181 VK_CMD_BUFFER* pCmdBuffer)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700182{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600183 VK_LAYER_DISPATCH_TABLE* pTable = tableMap2[device];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700184
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600185 printf("At start of multi2 layer vkCreateCommandBuffer()\n");
186 VK_RESULT result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700187 // create a mapping for CmdBuffer object into the dispatch table for layer 2
188 tableMap2.emplace(*pCmdBuffer, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189 printf("Completed multi2 layer vkCreateCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700190 return result;
191}
192
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600193VK_LAYER_EXPORT VK_RESULT VKAPI multi2BeginCommandBuffer(VK_CMD_BUFFER cmdBuffer, const VK_CMD_BUFFER_BEGIN_INFO* pBeginInfo)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700194{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600195 VK_LAYER_DISPATCH_TABLE* pTable = tableMap2[cmdBuffer];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700196
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600197 printf("At start of multi2 layer vkBeginCommandBuffer()\n");
198 VK_RESULT result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
199 printf("Completed multi2 layer vkBeginCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700200 return result;
201
202}
203
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600204VK_LAYER_EXPORT VK_RESULT VKAPI multi2EnumerateLayers(VK_PHYSICAL_GPU gpu, size_t maxLayerCount, size_t maxStringSize,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600205 size_t* pOutLayerCount, char* const* pOutLayers,
206 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700207{
208 if (gpu == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600209 return vkEnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700210
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600211 VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu;
212 VK_LAYER_DISPATCH_TABLE* pTable = getLayer2Table(gpuw);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700213
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600214 printf("At start of multi2 layer vkEnumerateLayers()\n");
215 VK_RESULT result = pTable->EnumerateLayers((VK_PHYSICAL_GPU)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
216 printf("Completed multi2 layer vkEnumerateLayers()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700217 return result;
218}
219
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600220VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VK_PHYSICAL_GPU gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700221{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600222 VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu;
Chia-I Wub665d942015-01-05 09:41:27 +0800223
Jon Ashburn79113cc2014-12-01 14:22:40 -0700224 if (gpu == NULL)
225 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800226
227 getLayer2Table(gpuw);
228
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600229 if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600230 return (void *) multi2CreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600231 else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600232 return (void *) multi2EnumerateLayers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600233 else if (!strncmp("vkCreateCommandBuffer", pName, sizeof ("vkCreateCommandBuffer")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600234 return (void *) multi2CreateCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600235 else if (!strncmp("vkBeginCommandBuffer", pName, sizeof ("vkBeginCommandBuffer")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600236 return (void *) multi2BeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600237 else if (!strncmp("vkGetExtensionSupport", pName, sizeof ("vkGetExtensionSupport")))
238 return (void *) vkGetExtensionSupport;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700239 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700240 if (gpuw->pGPA == NULL)
241 return NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600242 return gpuw->pGPA((VK_PHYSICAL_GPU) gpuw->nextObject, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700243 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700244}
245
246/********************************* Common functions ********************************/
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600247VK_LAYER_EXPORT VK_RESULT VKAPI vkEnumerateLayers(VK_PHYSICAL_GPU gpu, size_t maxLayerCount, size_t maxStringSize,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600248 size_t* pOutLayerCount, char* const* pOutLayers,
249 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700250{
251 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600252 return VK_ERROR_INVALID_POINTER;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700253
254 if (maxLayerCount < 2)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600255 return VK_ERROR_INITIALIZATION_FAILED;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700256 *pOutLayerCount = 2;
257 strncpy((char *) pOutLayers[0], "multi1", maxStringSize);
258 strncpy((char *) pOutLayers[1], "multi2", maxStringSize);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600259 return VK_SUCCESS;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700260}
261
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600262VK_LAYER_EXPORT VK_RESULT VKAPI vkGetExtensionSupport(VK_PHYSICAL_GPU gpu, const char* pExtName)
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600263{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600264 VK_RESULT result;
265 VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu;
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600266
267 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
268 if (!strncmp(pExtName, "multi1", strlen("multi1")))
269 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600270 result = VK_SUCCESS;
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600271 } else if (!strncmp(pExtName, "multi2", strlen("multi2")))
272 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600273 result = VK_SUCCESS;
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600274 } else if (!tableMap1.empty() && (tableMap1.find(gpuw) != tableMap1.end()))
275 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600276 VK_LAYER_DISPATCH_TABLE* pTable = tableMap1[gpuw];
277 result = pTable->GetExtensionSupport((VK_PHYSICAL_GPU)gpuw->nextObject, pExtName);
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600278 } else if (!tableMap2.empty() && (tableMap2.find(gpuw) != tableMap2.end()))
279 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600280 VK_LAYER_DISPATCH_TABLE* pTable = tableMap2[gpuw];
281 result = pTable->GetExtensionSupport((VK_PHYSICAL_GPU)gpuw->nextObject, pExtName);
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600282 } else
283 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600284 result = VK_ERROR_INVALID_EXTENSION;
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600285 }
286 return result;
287}
288
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600289VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VK_PHYSICAL_GPU gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700290{
291 // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr"
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800292 if (!strncmp("multi1GetProcAddr", pName, sizeof("multi1GetProcAddr")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600293 return (void *) multi1GetProcAddr;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800294 else if (!strncmp("multi2GetProcAddr", pName, sizeof("multi2GetProcAddr")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600295 return (void *) multi2GetProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600296 else if (!strncmp("vkGetProcAddr", pName, sizeof("vkGetProcAddr")))
297 return (void *) vkGetProcAddr;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700298
299 // use first layer activated as GPA dispatch table activation happens in order
300 else if (layer1_first_activated)
301 return multi1GetProcAddr(gpu, pName);
302 else if (layer2_first_activated)
303 return multi2GetProcAddr(gpu, pName);
304 else
305 return NULL;
306
307}
308
309#ifdef __cplusplus
310} //extern "C"
311#endif
312
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600313static void initLayerTable(const VK_BASE_LAYER_OBJECT *gpuw, VK_LAYER_DISPATCH_TABLE *pTable, const unsigned int layerNum)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700314{
Jon Ashburn79113cc2014-12-01 14:22:40 -0700315 if (layerNum == 2 && layer1_first_activated == false)
316 layer2_first_activated = true;
317 if (layerNum == 1 && layer2_first_activated == false)
318 layer1_first_activated = true;
319
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600320 layer_initialize_dispatch_table(pTable, gpuw->pGPA, (VK_PHYSICAL_GPU) gpuw->nextObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700321}