blob: 33af2720bd2c52c9c04cb9ed608dfa057b750d8d [file] [log] [blame]
Jon Ashburn8d8dad02014-12-01 14:22:40 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Jon Ashburn8d8dad02014-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 Elliott81ac44c2015-01-13 17:52:38 -070030#include "loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vkLayer.h"
Ian Elliott20f06872015-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 Ashburn8d8dad02014-12-01 14:22:40 -070036
Jon Ashburn1245cec2015-05-18 13:20:15 -060037static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum);
Jon Ashburnd9564002015-05-07 10:27:37 -060038static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum);
Jon Ashburnd25a78e2015-05-15 16:40:25 -060039/* Various dispatchable objects will use the same underlying dispatch table if they
40 * are created from that "parent" object. Thus use pointer to dispatch table
41 * as the key to table maps (tableMap1, tableInstanceMap1, tableMap2, tableInstanceMap2.
42 * Instance -> PhysicalDevice
43 * Device -> CmdBuffer or Queue
44 * If use the object themselves as key to map then implies Create entrypoints have to be intercepted
45 * and a new key inserted into map */
Jon Ashburn8d8dad02014-12-01 14:22:40 -070046/******************************** Layer multi1 functions **************************/
Jon Ashburn301c5f02015-04-06 10:58:22 -060047static std::unordered_map<void *, VkLayerDispatchTable *> tableMap1;
Jon Ashburnd9564002015-05-07 10:27:37 -060048static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap1;
Jon Ashburn8d8dad02014-12-01 14:22:40 -070049static bool layer1_first_activated = false;
50
Jon Ashburnd25a78e2015-05-15 16:40:25 -060051static VkLayerDispatchTable *getLayer1Table(const VkBaseLayerObject *devw)
Jon Ashburn8d8dad02014-12-01 14:22:40 -070052{
Jon Ashburn301c5f02015-04-06 10:58:22 -060053 VkLayerDispatchTable *pTable;
Jon Ashburnd25a78e2015-05-15 16:40:25 -060054 assert(devw);
55 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject;
Jon Ashburn8d8dad02014-12-01 14:22:40 -070056
Jon Ashburnd25a78e2015-05-15 16:40:25 -060057 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap1.find((void *) *ppDisp);
Jon Ashburn8d8dad02014-12-01 14:22:40 -070058 if (it == tableMap1.end())
59 {
Jon Ashburn301c5f02015-04-06 10:58:22 -060060 pTable = new VkLayerDispatchTable;
Jon Ashburnd25a78e2015-05-15 16:40:25 -060061 tableMap1[(void *) *ppDisp] = pTable;
62 initLayerTable(devw, pTable, 1);
Jon Ashburn8d8dad02014-12-01 14:22:40 -070063 return pTable;
64 } else
65 {
66 return it->second;
67 }
68}
Jon Ashburnd25a78e2015-05-15 16:40:25 -060069static VkLayerInstanceDispatchTable *getLayer1InstanceTable(const VkBaseLayerObject *instw)
Jon Ashburnd9564002015-05-07 10:27:37 -060070{
71 VkLayerInstanceDispatchTable *pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -060072 assert(instw);
Jon Ashburnd25a78e2015-05-15 16:40:25 -060073 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;
74
75 std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap1.find((void *) *ppDisp);
Jon Ashburnd9564002015-05-07 10:27:37 -060076 if (it == tableInstanceMap1.end())
77 {
78 pTable = new VkLayerInstanceDispatchTable;
Jon Ashburnd25a78e2015-05-15 16:40:25 -060079 tableInstanceMap1[(void *) *ppDisp] = pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -060080 initLayerInstanceTable(instw, pTable, 1);
81 return pTable;
82 } else
83 {
84 return it->second;
85 }
86}
Jon Ashburn8d8dad02014-12-01 14:22:40 -070087#ifdef __cplusplus
88extern "C" {
89#endif
90
Jon Ashburn2666e2f2015-05-15 15:09:35 -060091VK_LAYER_EXPORT VkResult VKAPI multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Jon Ashburn8d8dad02014-12-01 14:22:40 -070092{
Jon Ashburnd25a78e2015-05-15 16:40:25 -060093 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device;
94 VkLayerDispatchTable *pTable = tableMap1[*ppDisp];
Jon Ashburn2666e2f2015-05-15 15:09:35 -060095
96 printf("At start of multi1 layer vkCreateSampler()\n");
97 VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler);
98 printf("Completed multi1 layer vkCreateSampler()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -070099 return result;
100}
101
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600102VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo,
103 VkPipeline* pPipeline)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700104{
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600105 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device;
106 VkLayerDispatchTable *pTable = tableMap1[*ppDisp];
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700107
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600108 printf("At start of multi1 layer vkCreateGraphicsPipeline()\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600109 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110 printf("Completed multi1 layer vkCreateGraphicsPipeline()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700111 return result;
112}
113
Mike Stroyan230e6252015-04-17 12:36:38 -0600114VK_LAYER_EXPORT VkResult VKAPI multi1StorePipeline(VkDevice device, VkPipeline pipeline, size_t* pDataSize, void* pData)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700115{
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600116 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device;
117 VkLayerDispatchTable *pTable = tableMap1[*ppDisp];
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700118
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600119 printf("At start of multi1 layer vkStorePipeline()\n");
Mike Stroyan230e6252015-04-17 12:36:38 -0600120 VkResult result = pTable->StorePipeline(device, pipeline, pDataSize, pData);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600121 printf("Completed multi1 layer vkStorePipeline()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700122 return result;
123}
124
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600125VK_LAYER_EXPORT VkResult VKAPI multi1EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
126 size_t* pLayerCount, char* const* pOutLayers,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600127 void* pReserved)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700128{
129 if (gpu == NULL)
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600130 return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700131
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600132 VkLayerInstanceDispatchTable* pTable = tableInstanceMap1[gpu];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600133 printf("At start of multi1 layer vkEnumerateLayers()\n");
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600134 VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600135 printf("Completed multi1 layer vkEnumerateLayers()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700136 return result;
137}
138
Jon Ashburn1245cec2015-05-18 13:20:15 -0600139VK_LAYER_EXPORT void * VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700140{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600141 VkBaseLayerObject* devw = (VkBaseLayerObject *) device;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800142
Jon Ashburn1245cec2015-05-18 13:20:15 -0600143 if (device == NULL)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700144 return NULL;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800145
Jon Ashburn1245cec2015-05-18 13:20:15 -0600146 getLayer1Table(devw);
Chia-I Wue9ae3882015-01-05 09:41:27 +0800147
Jon Ashburn7cb4e0e2015-05-19 10:05:54 -0600148 if (!strcmp("vkGetDeviceProcAddr", pName))
149 return (void *) multi1GetDeviceProcAddr;
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600150 if (!strcmp("vkCreateSampler", pName))
151 return (void *) multi1CreateSampler;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600152 else if (!strcmp("vkCreateGraphicsPipeline", pName))
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600153 return (void *) multi1CreateGraphicsPipeline;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600154 else if (!strcmp("vkStorePipeline", pName))
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600155 return (void *) multi1StorePipeline;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700156 else {
Jon Ashburn1245cec2015-05-18 13:20:15 -0600157 if (devw->pGPA == NULL)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700158 return NULL;
Jon Ashburn1245cec2015-05-18 13:20:15 -0600159 return devw->pGPA((VkObject) devw->nextObject, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600160 }
161}
162
Jon Ashburnd9564002015-05-07 10:27:37 -0600163VK_LAYER_EXPORT void * VKAPI multi1GetInstanceProcAddr(VkInstance inst, const char* pName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600164{
165 VkBaseLayerObject* instw = (VkBaseLayerObject *) inst;
166
167 if (inst == NULL)
168 return NULL;
169
Jon Ashburnd9564002015-05-07 10:27:37 -0600170 getLayer1InstanceTable(instw);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600171
Jon Ashburn7cb4e0e2015-05-19 10:05:54 -0600172 if (!strcmp("vkGetInstanceProcAddr", pName))
173 return (void *) multi1GetInstanceProcAddr;
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600174 if (!strcmp("vkEnumerateLayers", pName))
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600175 return (void *) multi1EnumerateLayers;
176 else if (!strcmp("GetGlobalExtensionInfo", pName))
177 return (void*) vkGetGlobalExtensionInfo;
178 else {
179 if (instw->pGPA == NULL)
180 return NULL;
181 return instw->pGPA((VkObject) instw->nextObject, pName);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700182 }
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700183}
184
185/******************************** Layer multi2 functions **************************/
Jon Ashburn301c5f02015-04-06 10:58:22 -0600186static std::unordered_map<void *, VkLayerDispatchTable *> tableMap2;
Jon Ashburnd9564002015-05-07 10:27:37 -0600187static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap2;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700188static bool layer2_first_activated = false;
189
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600190static VkLayerInstanceDispatchTable *getLayer2InstanceTable(const VkBaseLayerObject *instw)
Jon Ashburnd9564002015-05-07 10:27:37 -0600191{
192 VkLayerInstanceDispatchTable *pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -0600193 assert(instw);
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600194 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;
195
196 std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap2.find((void *) *ppDisp);
Jon Ashburnd9564002015-05-07 10:27:37 -0600197 if (it == tableInstanceMap2.end())
198 {
199 pTable = new VkLayerInstanceDispatchTable;
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600200 tableInstanceMap2[(void *) *ppDisp] = pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -0600201 initLayerInstanceTable(instw, pTable, 2);
202 return pTable;
203 } else
204 {
205 return it->second;
206 }
207}
208
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600209static VkLayerDispatchTable *getLayer2Table(const VkBaseLayerObject *devw)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700210{
Jon Ashburn301c5f02015-04-06 10:58:22 -0600211 VkLayerDispatchTable *pTable;
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600212 assert(devw);
213 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) devw->baseObject;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700214
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600215 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap2.find((void *) *ppDisp);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700216 if (it == tableMap2.end())
217 {
Jon Ashburn301c5f02015-04-06 10:58:22 -0600218 pTable = new VkLayerDispatchTable;
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600219 tableMap2[(void *) *ppDisp] = pTable;
220 initLayerTable(devw, pTable, 2);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700221 return pTable;
222 } else
223 {
224 return it->second;
225 }
226}
227
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600228VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices(
229 VkInstance instance,
230 uint32_t* pPhysicalDeviceCount,
231 VkPhysicalDevice* pPhysicalDevices)
232{
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600233 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
234 VkLayerInstanceDispatchTable *pInstTable = tableInstanceMap2[*ppDisp];
235
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600236 printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n");
237 VkResult result = pInstTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600238 printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n");
239 return result;
240}
241
Tony Barbour8205d902015-04-16 15:59:00 -0600242VK_LAYER_EXPORT VkResult VKAPI multi2CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600243 VkDevice* pDevice)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700244{
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600245 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu;
246 VkLayerInstanceDispatchTable *pInstTable = tableInstanceMap2[*ppDisp];
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700247
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600248 printf("At start of multi2 vkCreateDevice()\n");
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600249 VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250 printf("Completed multi2 layer vkCreateDevice()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700251 return result;
252}
253
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600254VK_LAYER_EXPORT VkResult VKAPI multi2CreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo,
255 VkCmdBuffer* pCmdBuffer)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700256{
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600257 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device;
258 VkLayerDispatchTable *pTable = tableMap2[*ppDisp];
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700259
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600260 printf("At start of multi2 layer vkCreateCommandBuffer()\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600261 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600262 printf("Completed multi2 layer vkCreateCommandBuffer()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700263 return result;
264}
265
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600266VK_LAYER_EXPORT VkResult VKAPI multi2BeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700267{
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600268 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) cmdBuffer;
269 VkLayerDispatchTable *pTable = tableMap2[*ppDisp];
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700270
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600271 printf("At start of multi2 layer vkBeginCommandBuffer()\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600272 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273 printf("Completed multi2 layer vkBeginCommandBuffer()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700274 return result;
275
276}
277
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600278VK_LAYER_EXPORT VkResult VKAPI multi2EnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
279 size_t* pLayerCount, char* const* pOutLayers,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600280 void* pReserved)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700281{
282 if (gpu == NULL)
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600283 return vkEnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700284
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600285 VkLayerInstanceDispatchTable* pTable = tableInstanceMap2[gpu];
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700286
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600287 printf("At start of multi2 layer vkEnumerateLayers()\n");
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600288 VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600289 printf("Completed multi2 layer vkEnumerateLayers()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700290 return result;
291}
292
Jon Ashburn1245cec2015-05-18 13:20:15 -0600293VK_LAYER_EXPORT void * VKAPI multi2GetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700294{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600295 VkBaseLayerObject* devw = (VkBaseLayerObject *) device;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800296
Jon Ashburn1245cec2015-05-18 13:20:15 -0600297 if (device == NULL)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700298 return NULL;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800299
Jon Ashburn1245cec2015-05-18 13:20:15 -0600300 getLayer2Table(devw);
Chia-I Wue9ae3882015-01-05 09:41:27 +0800301
Jon Ashburn7cb4e0e2015-05-19 10:05:54 -0600302 if (!strcmp("vkGetDeviceProcAddr", pName))
303 return (void *) multi2GetDeviceProcAddr;
Jon Ashburn1245cec2015-05-18 13:20:15 -0600304 if (!strcmp("vkCreateCommandBuffer", pName))
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600305 return (void *) multi2CreateCommandBuffer;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600306 else if (!strcmp("vkBeginCommandBuffer", pName))
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600307 return (void *) multi2BeginCommandBuffer;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700308 else {
Jon Ashburn1245cec2015-05-18 13:20:15 -0600309 if (devw->pGPA == NULL)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700310 return NULL;
Jon Ashburn1245cec2015-05-18 13:20:15 -0600311 return devw->pGPA((VkObject) devw->nextObject, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600312 }
313}
314
Jon Ashburnd9564002015-05-07 10:27:37 -0600315VK_LAYER_EXPORT void * VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600316{
317 VkBaseLayerObject* instw = (VkBaseLayerObject *) inst;
318
319 if (inst == NULL)
320 return NULL;
321
Jon Ashburnd9564002015-05-07 10:27:37 -0600322 getLayer2InstanceTable(instw);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600323
Jon Ashburn7cb4e0e2015-05-19 10:05:54 -0600324 if (!strcmp("vkGetInstanceProcAddr", pName))
325 return (void *) multi2GetInstanceProcAddr;
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600326 if (!strcmp("vkEnumeratePhysicalDevices", pName))
327 return (void *) multi2EnumeratePhysicalDevices;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600328 if (!strcmp("vkCreateDevice", pName))
329 return (void *) multi2CreateDevice;
330 else if (!strcmp("vkEnumerateLayers", pName))
331 return (void *) multi2EnumerateLayers;
332 else if (!strcmp("GetGlobalExtensionInfo", pName))
333 return (void*) vkGetGlobalExtensionInfo;
334 else {
335 if (instw->pGPA == NULL)
336 return NULL;
337 return instw->pGPA((VkObject) instw->nextObject, pName);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700338 }
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700339}
340
341/********************************* Common functions ********************************/
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600342VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize,
343 size_t* pLayerCount, char* const* pOutLayers,
344 void* pReserved)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700345{
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600346 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600347 return VK_ERROR_INVALID_POINTER;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700348
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600349 if (*pLayerCount < 2)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600350 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600351 *pLayerCount = 2;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700352 strncpy((char *) pOutLayers[0], "multi1", maxStringSize);
353 strncpy((char *) pOutLayers[1], "multi2", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600354 return VK_SUCCESS;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700355}
356
Jon Ashburneb2728b2015-04-10 14:33:07 -0600357struct extProps {
358 uint32_t version;
359 const char * const name;
360};
361
362#define MULTI_LAYER_EXT_ARRAY_SIZE 2
363static const struct extProps multiExts[MULTI_LAYER_EXT_ARRAY_SIZE] = {
364 // TODO what is the version?
365 0x10, "multi1",
366 0x10, "multi2",
367};
368
369VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
370 VkExtensionInfoType infoType,
371 uint32_t extensionIndex,
372 size_t* pDataSize,
373 void* pData)
374{
Jon Ashburneb2728b2015-04-10 14:33:07 -0600375 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
376 VkExtensionProperties *ext_props;
377 uint32_t *count;
378
379 if (pDataSize == NULL)
380 return VK_ERROR_INVALID_POINTER;
381
382 switch (infoType) {
383 case VK_EXTENSION_INFO_TYPE_COUNT:
384 *pDataSize = sizeof(uint32_t);
385 if (pData == NULL)
386 return VK_SUCCESS;
387 count = (uint32_t *) pData;
388 *count = MULTI_LAYER_EXT_ARRAY_SIZE;
389 break;
390 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
391 *pDataSize = sizeof(VkExtensionProperties);
392 if (pData == NULL)
393 return VK_SUCCESS;
394 if (extensionIndex >= MULTI_LAYER_EXT_ARRAY_SIZE)
395 return VK_ERROR_INVALID_VALUE;
396 ext_props = (VkExtensionProperties *) pData;
397 ext_props->version = multiExts[extensionIndex].version;
398 strncpy(ext_props->extName, multiExts[extensionIndex].name,
399 VK_MAX_EXTENSION_NAME);
400 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
401 break;
402 default:
403 return VK_ERROR_INVALID_VALUE;
404 };
405
406 return VK_SUCCESS;
407}
408
Jon Ashburn1245cec2015-05-18 13:20:15 -0600409VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700410{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600411 // to find each layers GPA routine Loader will search via "<layerName>GetDeviceProcAddr"
412 if (!strcmp("multi1GetDeviceProcAddr", pName))
413 return (void *) multi1GetDeviceProcAddr;
414 else if (!strcmp("multi2GetDeviceProcAddr", pName))
415 return (void *) multi2GetDeviceProcAddr;
416 else if (!strcmp("vkGetDeviceProcAddr", pName))
417 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700418
419 // use first layer activated as GPA dispatch table activation happens in order
420 else if (layer1_first_activated)
Jon Ashburn1245cec2015-05-18 13:20:15 -0600421 return multi1GetDeviceProcAddr(device, pName);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700422 else if (layer2_first_activated)
Jon Ashburn1245cec2015-05-18 13:20:15 -0600423 return multi2GetDeviceProcAddr(device, pName);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700424 else
425 return NULL;
426
427}
428
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600429VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance inst, const char* pName)
430{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600431 // to find each layers GPA routine Loader will search via "<layerName>GetInstanceProcAddr"
432 if (!strcmp("multi1GetInstanceProcAddr", pName))
Jon Ashburnd9564002015-05-07 10:27:37 -0600433 return (void *) multi1GetInstanceProcAddr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600434 else if (!strcmp("multi2GetInstanceProcAddr", pName))
Jon Ashburnd9564002015-05-07 10:27:37 -0600435 return (void *) multi2GetInstanceProcAddr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600436 else if (!strcmp("vkGetInstanceProcAddr", pName))
Jon Ashburn1245cec2015-05-18 13:20:15 -0600437 return (void *) vkGetInstanceProcAddr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600438
439 // use first layer activated as GPA dispatch table activation happens in order
440 else if (layer1_first_activated)
Jon Ashburnd9564002015-05-07 10:27:37 -0600441 return multi1GetInstanceProcAddr(inst, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600442 else if (layer2_first_activated)
Jon Ashburnd9564002015-05-07 10:27:37 -0600443 return multi2GetInstanceProcAddr(inst, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600444 else
445 return NULL;
446
447}
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700448#ifdef __cplusplus
449} //extern "C"
450#endif
451
Jon Ashburn1245cec2015-05-18 13:20:15 -0600452static void initLayerTable(const VkBaseLayerObject *devw, VkLayerDispatchTable *pTable, const unsigned int layerNum)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700453{
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700454 if (layerNum == 2 && layer1_first_activated == false)
455 layer2_first_activated = true;
456 if (layerNum == 1 && layer2_first_activated == false)
457 layer1_first_activated = true;
458
Jon Ashburn1245cec2015-05-18 13:20:15 -0600459 layer_initialize_dispatch_table(pTable, (PFN_vkGetDeviceProcAddr) devw->pGPA, (VkDevice) devw->nextObject);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700460}
Jon Ashburnd9564002015-05-07 10:27:37 -0600461
462static void initLayerInstanceTable(const VkBaseLayerObject *instw, VkLayerInstanceDispatchTable *pTable, const unsigned int layerNum)
463{
464 if (layerNum == 2 && layer1_first_activated == false)
465 layer2_first_activated = true;
466 if (layerNum == 1 && layer2_first_activated == false)
467 layer1_first_activated = true;
468
469 layer_init_instance_dispatch_table(pTable, (PFN_vkGetInstanceProcAddr) instw->pGPA, (VkInstance) instw->nextObject);
470}