blob: b26e67dbb4995ea85e8371db49fa5ba143d569dd [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
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600123 if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600124 return (void *) multi1CreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600125 else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600126 return (void *) multi1EnumerateLayers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600127 else if (!strncmp("vkCreateGraphicsPipeline", pName, sizeof ("vkCreateGraphicsPipeline")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600128 return (void *) multi1CreateGraphicsPipeline;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600129 else if (!strncmp("vkStorePipeline", pName, sizeof ("vkStorePipeline")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600130 return (void *) multi1StorePipeline;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700131 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700132 if (gpuw->pGPA == NULL)
133 return NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -0600134 return gpuw->pGPA((VkPhysicalDevice) gpuw->nextObject, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700135 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700136}
137
138/******************************** Layer multi2 functions **************************/
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600139static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700140static bool layer2_first_activated = false;
141
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600142static VkLayerDispatchTable * getLayer2Table(const VkBaseLayerObject *gpuw)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700143{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600144 VkLayerDispatchTable *pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700145
146 assert(gpuw);
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600147 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) gpuw->baseObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700148 if (it == tableMap2.end())
149 {
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600150 pTable = new VkLayerDispatchTable;
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600151 tableMap2[(void *) gpuw->baseObject] = pTable;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700152 initLayerTable(gpuw, pTable, 2);
153 return pTable;
154 } else
155 {
156 return it->second;
157 }
158}
159
Tony Barbourd1c35722015-04-16 15:59:00 -0600160VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600161 VkDevice* pDevice)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700162{
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600163 VkLayerDispatchTable* pTable = tableMap2[gpu];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700164
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600165 printf("At start of multi2 vkCreateDevice()\n");
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600166 VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700167 // create a mapping for the device object into the dispatch table for layer2
168 tableMap2.emplace(*pDevice, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600169 printf("Completed multi2 layer vkCreateDevice()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700170 return result;
171}
172
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600173VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo,
174 VkCmdBuffer* pCmdBuffer)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700175{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600176 VkLayerDispatchTable* pTable = tableMap2[device];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700177
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600178 printf("At start of multi2 layer vkCreateCommandBuffer()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600179 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700180 // create a mapping for CmdBuffer object into the dispatch table for layer 2
181 tableMap2.emplace(*pCmdBuffer, pTable);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600182 printf("Completed multi2 layer vkCreateCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700183 return result;
184}
185
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600186VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700187{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600188 VkLayerDispatchTable* pTable = tableMap2[cmdBuffer];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700189
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600190 printf("At start of multi2 layer vkBeginCommandBuffer()\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600191 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600192 printf("Completed multi2 layer vkBeginCommandBuffer()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700193 return result;
194
195}
196
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600197VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
198 size_t* pLayerCount, char* const* pOutLayers,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600199 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700200{
201 if (gpu == NULL)
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600202 return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700203
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600204 VkLayerDispatchTable* pTable = tableMap2[gpu];
Jon Ashburn79113cc2014-12-01 14:22:40 -0700205
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600206 printf("At start of multi2 layer vkEnumerateLayers()\n");
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600207 VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600208 printf("Completed multi2 layer vkEnumerateLayers()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -0700209 return result;
210}
211
Tony Barbourd1c35722015-04-16 15:59:00 -0600212VK_LAYER_EXPORT void * VKAPI multi2GetProcAddr(VkPhysicalDevice gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700213{
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600214 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wub665d942015-01-05 09:41:27 +0800215
Jon Ashburn79113cc2014-12-01 14:22:40 -0700216 if (gpu == NULL)
217 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800218
219 getLayer2Table(gpuw);
220
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600221 if (!strncmp("vkCreateDevice", pName, sizeof ("vkCreateDevice")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600222 return (void *) multi2CreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600223 else if (!strncmp("vkEnumerateLayers", pName, sizeof ("vkEnumerateLayers")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600224 return (void *) multi2EnumerateLayers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600225 else if (!strncmp("vkCreateCommandBuffer", pName, sizeof ("vkCreateCommandBuffer")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600226 return (void *) multi2CreateCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600227 else if (!strncmp("vkBeginCommandBuffer", pName, sizeof ("vkBeginCommandBuffer")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600228 return (void *) multi2BeginCommandBuffer;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700229 else {
Jon Ashburn79113cc2014-12-01 14:22:40 -0700230 if (gpuw->pGPA == NULL)
231 return NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -0600232 return gpuw->pGPA((VkPhysicalDevice) gpuw->nextObject, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700233 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700234}
235
236/********************************* Common functions ********************************/
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600237VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
238 size_t* pLayerCount, char* const* pOutLayers,
239 void* pReserved)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700240{
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600241 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600242 return VK_ERROR_INVALID_POINTER;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700243
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600244 if (*pLayerCount < 2)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600245 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600246 *pLayerCount = 2;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700247 strncpy((char *) pOutLayers[0], "multi1", maxStringSize);
248 strncpy((char *) pOutLayers[1], "multi2", maxStringSize);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600249 return VK_SUCCESS;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700250}
251
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600252struct extProps {
253 uint32_t version;
254 const char * const name;
255};
256
257#define MULTI_LAYER_EXT_ARRAY_SIZE 2
258static const struct extProps multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = {
259 // TODO what is the version?
260 0x10, "multi1",
261 0x10, "multi2",
262};
263
264VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
265 VkExtensionInfoType infoType,
266 uint32_t extensionIndex,
267 size_t* pDataSize,
268 void* pData)
269{
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600270 /* 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 Barbourd1c35722015-04-16 15:59:00 -0600304VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700305{
306 // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr"
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800307 if (!strncmp("multi1GetProcAddr", pName, sizeof("multi1GetProcAddr")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600308 return (void *) multi1GetProcAddr;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800309 else if (!strncmp("multi2GetProcAddr", pName, sizeof("multi2GetProcAddr")))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600310 return (void *) multi2GetProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600311 else if (!strncmp("vkGetProcAddr", pName, sizeof("vkGetProcAddr")))
312 return (void *) vkGetProcAddr;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700313
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 Ashburnbacb0f52015-04-06 10:58:22 -0600328static void initLayerTable(const VkBaseLayerObject *gpuw, VkLayerDispatchTable *pTable, const unsigned int layerNum)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700329{
Jon Ashburn79113cc2014-12-01 14:22:40 -0700330 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 Barbourd1c35722015-04-16 15:59:00 -0600335 layer_initialize_dispatch_table(pTable, gpuw->pGPA, (VkPhysicalDevice) gpuw->nextObject);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700336}