blob: 78ee302f04916ab159e5f2219ea7d626abbb3bd5 [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
Tony Barbourd1c35722015-04-16 15:59:00 -060065VK_LAYER_EXPORT VkResult VKAPI multi1CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060066 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
Mike Stroyanb050c682015-04-17 12:36:38 -060090VK_LAYER_EXPORT VkResult VKAPI multi1StorePipeline(VkDevice device, 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");
Mike Stroyanb050c682015-04-17 12:36:38 -060095 VkResult result = pTable->StorePipeline(device, 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 Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600100VK_LAYER_EXPORT VkResult VKAPI multi1EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
101 size_t* pLayerCount, char* const* pOutLayers,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600102 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700103{
104 if (gpu == NULL)
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600105 return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, 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");
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600109 VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, 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
Tony Barbourd1c35722015-04-16 15:59:00 -0600114VK_LAYER_EXPORT void * VKAPI multi1GetProcAddr(VkPhysicalDevice gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700115{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600116 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wub665d942015-01-05 09:41:27 +0800117
Jon Ashburn79113cc2014-12-01 14:22:40 -0700118 if (gpu == NULL)
119 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800120
121 getLayer1Table(gpuw);
122
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600123 if (!strcmp("vkCreateDevice", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600124 return (void *) multi1CreateDevice;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600125 else if (!strcmp("vkEnumerateLayers", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600126 return (void *) multi1EnumerateLayers;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600127 else if (!strcmp("GetGlobalExtensionInfo", pName))
128 return (void*) vkGetGlobalExtensionInfo;
129 else if (!strcmp("vkCreateGraphicsPipeline", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600130 return (void *) multi1CreateGraphicsPipeline;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600131 else if (!strcmp("vkStorePipeline", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600132 return (void *) multi1StorePipeline;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700133 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700134 if (gpuw->pGPA == NULL)
135 return NULL;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600136 return gpuw->pGPA((VkObject) gpuw->nextObject, pName);
137 }
138}
139
140VK_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 Ashburn79113cc2014-12-01 14:22:40 -0700159 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700160}
161
162/******************************** Layer multi2 functions **************************/
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600163static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700164static bool layer2_first_activated = false;
165
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600166static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700167{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600168 VkLayerDispatchTable *pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700169
170 assert(gpuw);
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600171 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) gpuw->baseObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700172 if (it == tableMap2.end())
173 {
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600174 pTable = new VkLayerDispatchTable;
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600175 tableMap2[(void *) gpuw->baseObject] = pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700176 initLayerTable(gpuw, pTable, 2);
177 return pTable;
178 } else
179 {
180 return it->second;
181 }
182}
183
Tony Barbourd1c35722015-04-16 15:59:00 -0600184VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600185 VkDevice* pDevice)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700186{
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600187 VkLayerDispatchTable* pTable = tableMap2[gpu];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700188
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189 printf("At start of multi2 vkCreateDevice()\n");
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600190 VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700191 // create a mapping for the device object into the dispatch table for layer2
192 tableMap2.emplace(*pDevice, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600193 printf("Completed multi2 layer vkCreateDevice()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700194 return result;
195}
196
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600197VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo,
198 VkCmdBuffer* pCmdBuffer)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700199{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600200 VkLayerDispatchTable* pTable = tableMap2[device];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700201
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600202 printf("At start of multi2 layer vkCreateCommandBuffer()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600203 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700204 // create a mapping for CmdBuffer object into the dispatch table for layer 2
205 tableMap2.emplace(*pCmdBuffer, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600206 printf("Completed multi2 layer vkCreateCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700207 return result;
208}
209
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600210VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700211{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600212 VkLayerDispatchTable* pTable = tableMap2[cmdBuffer];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700213
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600214 printf("At start of multi2 layer vkBeginCommandBuffer()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600215 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600216 printf("Completed multi2 layer vkBeginCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700217 return result;
218
219}
220
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600221VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
222 size_t* pLayerCount, char* const* pOutLayers,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600223 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700224{
225 if (gpu == NULL)
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600226 return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700227
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600228 VkLayerDispatchTable* pTable = tableMap2[gpu];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700229
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600230 printf("At start of multi2 layer vkEnumerateLayers()\n");
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600231 VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600232 printf("Completed multi2 layer vkEnumerateLayers()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700233 return result;
234}
235
Tony Barbourd1c35722015-04-16 15:59:00 -0600236VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalDevice gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700237{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600238 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wub665d942015-01-05 09:41:27 +0800239
Jon Ashburn79113cc2014-12-01 14:22:40 -0700240 if (gpu == NULL)
241 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800242
243 getLayer2Table(gpuw);
244
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600245 if (!strcmp("vkCreateDevice", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600246 return (void *) multi2CreateDevice;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600247 else if (!strcmp("vkEnumerateLayers", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600248 return (void *) multi2EnumerateLayers;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600249 else if (!strcmp("GetGlobalExtensionInfo", pName))
250 return (void*) vkGetGlobalExtensionInfo;
251 else if (!strcmp("vkCreateCommandBuffer", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600252 return (void *) multi2CreateCommandBuffer;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600253 else if (!strcmp("vkBeginCommandBuffer", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600254 return (void *) multi2BeginCommandBuffer;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700255 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700256 if (gpuw->pGPA == NULL)
257 return NULL;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600258 return gpuw->pGPA((VkObject) gpuw->nextObject, pName);
259 }
260}
261
262VK_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 Ashburn79113cc2014-12-01 14:22:40 -0700281 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700282}
283
284/********************************* Common functions ********************************/
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600285VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
286 size_t* pLayerCount, char* const* pOutLayers,
287 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700288{
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600289 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600290 return VK_ERROR_INVALID_POINTER;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700291
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600292 if (*pLayerCount < 2)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600293 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600294 *pLayerCount = 2;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700295 strncpy((char *) pOutLayers[0], "multi1", maxStringSize);
296 strncpy((char *) pOutLayers[1], "multi2", maxStringSize);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600297 return VK_SUCCESS;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700298}
299
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600300struct extProps {
301 uint32_t version;
302 const char * const name;
303};
304
305#define MULTI_LAYER_EXT_ARRAY_SIZE 2
306static const struct extProps multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = {
307 // TODO what is the version?
308 0x10, "multi1",
309 0x10, "multi2",
310};
311
312VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
313 VkExtensionInfoType infoType,
314 uint32_t extensionIndex,
315 size_t* pDataSize,
316 void* pData)
317{
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600318 /* 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 Barbourd1c35722015-04-16 15:59:00 -0600352VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700353{
354 // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr"
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600355 if (!strcmp("multi1GetProcAddr", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600356 return (void *) multi1GetProcAddr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600357 else if (!strcmp("multi2GetProcAddr", pName))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600358 return (void *) multi2GetProcAddr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600359 else if (!strcmp("vkGetProcAddr", pName))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600360 return (void *) vkGetProcAddr;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700361
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 Ashburnf6b33db2015-05-05 14:22:52 -0600372VK_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 Ashburn79113cc2014-12-01 14:22:40 -0700397#ifdef __cplusplus
398} //extern "C"
399#endif
400
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600401static void initLayerTable(const VkBaseLayerObject *gpuw, VkLayerDispatchTable *pTable, const unsigned int layerNum)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700402{
Jon Ashburn79113cc2014-12-01 14:22:40 -0700403 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 Ashburnf6b33db2015-05-05 14:22:52 -0600408 layer_initialize_dispatch_table(pTable, (PFN_vkGetProcAddr) gpuw->pGPA, (VkPhysicalDevice) gpuw->nextObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700409}