blob: cd4e94f0604906584628698a6bc5d2d7720a2c61 [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>
Tobin Ehlis7a51d902015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Tobin Ehlis2d1d9702015-07-03 09:42:57 -060031#include "vk_layer.h"
Jon Ashburndf34bfd2015-08-12 16:43:01 -060032#include "vk_layer_table.h"
Jon Ashburn8d8dad02014-12-01 14:22:40 -070033
Jon Ashburn8d8dad02014-12-01 14:22:40 -070034#ifdef __cplusplus
35extern "C" {
36#endif
37
Jon Ashburndf34bfd2015-08-12 16:43:01 -060038
39static device_table_map multi1_device_table_map;
40/******************************** Layer multi1 functions **************************/
41
Courtney Goeltzenleuchter142c9c22015-07-06 21:32:03 -060042/* hook DestroyDevice to remove tableMap entry */
Jon Ashburn17f37372015-05-19 16:34:53 -060043VK_LAYER_EXPORT VkResult VKAPI multi1DestroyDevice(VkDevice device)
44{
Jon Ashburndf34bfd2015-08-12 16:43:01 -060045 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
46 dispatch_key key = get_dispatch_key(device);
Jon Ashburn17f37372015-05-19 16:34:53 -060047
Jon Ashburndf34bfd2015-08-12 16:43:01 -060048 printf("At start of multi1 layer vkDestroyDevice()\n");
49 VkResult res = pDisp->DestroyDevice(device);
50 multi1_device_table_map.erase(key);
51 printf("Completed multi1 layer vkDestroyDevice()\n");
Jon Ashburn17f37372015-05-19 16:34:53 -060052 return res;
53}
54
Jon Ashburn2666e2f2015-05-15 15:09:35 -060055VK_LAYER_EXPORT VkResult VKAPI multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Jon Ashburn8d8dad02014-12-01 14:22:40 -070056{
Jon Ashburndf34bfd2015-08-12 16:43:01 -060057 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn2666e2f2015-05-15 15:09:35 -060058
59 printf("At start of multi1 layer vkCreateSampler()\n");
Jon Ashburndf34bfd2015-08-12 16:43:01 -060060 VkResult result = pDisp->CreateSampler(device, pCreateInfo, pSampler);
Jon Ashburn2666e2f2015-05-15 15:09:35 -060061 printf("Completed multi1 layer vkCreateSampler()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -070062 return result;
63}
64
Jon Ashburn0d60d272015-07-09 15:02:25 -060065VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipelines(
66 VkDevice device,
67 VkPipelineCache pipelineCache,
68 uint32_t count,
69 const VkGraphicsPipelineCreateInfo* pCreateInfos,
70 VkPipeline* pPipelines)
Jon Ashburn8d8dad02014-12-01 14:22:40 -070071{
Jon Ashburndf34bfd2015-08-12 16:43:01 -060072 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn8d8dad02014-12-01 14:22:40 -070073
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060074 printf("At start of multi1 layer vkCreateGraphicsPipeline()\n");
Jon Ashburndf34bfd2015-08-12 16:43:01 -060075 VkResult result = pDisp->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060076 printf("Completed multi1 layer vkCreateGraphicsPipeline()\n");
Jon Ashburn8d8dad02014-12-01 14:22:40 -070077 return result;
78}
79
Jon Ashburndf34bfd2015-08-12 16:43:01 -060080VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -070081{
Chia-I Wue9ae3882015-01-05 09:41:27 +080082
Jon Ashburn1245cec2015-05-18 13:20:15 -060083 if (device == NULL)
Jon Ashburn8d8dad02014-12-01 14:22:40 -070084 return NULL;
Chia-I Wue9ae3882015-01-05 09:41:27 +080085
Jon Ashburndf34bfd2015-08-12 16:43:01 -060086 /* loader uses this to force layer initialization; device object is wrapped */
87 if (!strcmp(pName, "multi1GetDeviceProcAddr") || !strcmp(pName, "vkGetDeviceProcAddr")) {
88 initDeviceTable(multi1_device_table_map, (const VkBaseLayerObject *) device);
89 return (PFN_vkVoidFunction) multi1GetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -060090 }
Jon Ashburndf34bfd2015-08-12 16:43:01 -060091
Jon Ashburn17f37372015-05-19 16:34:53 -060092 if (!strcmp("vkDestroyDevice", pName))
Jon Ashburndf34bfd2015-08-12 16:43:01 -060093 return (PFN_vkVoidFunction) multi1DestroyDevice;
Jon Ashburn2666e2f2015-05-15 15:09:35 -060094 if (!strcmp("vkCreateSampler", pName))
Jon Ashburndf34bfd2015-08-12 16:43:01 -060095 return (PFN_vkVoidFunction) multi1CreateSampler;
Jon Ashburn0d60d272015-07-09 15:02:25 -060096 if (!strcmp("vkCreateGraphicsPipelines", pName))
Jon Ashburndf34bfd2015-08-12 16:43:01 -060097 return (PFN_vkVoidFunction) multi1CreateGraphicsPipelines;
Jon Ashburn8d8dad02014-12-01 14:22:40 -070098 else {
Jon Ashburndf34bfd2015-08-12 16:43:01 -060099 VkLayerDispatchTable *pTable = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600100 if (pTable->GetDeviceProcAddr == NULL)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700101 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600102 return pTable->GetDeviceProcAddr(device, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600103 }
104}
105
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600106
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600107static instance_table_map multi2_instance_table_map;
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700108/******************************** Layer multi2 functions **************************/
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600109VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices(
110 VkInstance instance,
111 uint32_t* pPhysicalDeviceCount,
112 VkPhysicalDevice* pPhysicalDevices)
113{
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600114 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance);
Jon Ashburnd25a78e2015-05-15 16:40:25 -0600115
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600116 printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n");
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600117 VkResult result = pDisp->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600118 printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n");
119 return result;
120}
121
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600122VK_LAYER_EXPORT VkResult VKAPI multi2GetPhysicalDeviceProperties(
123 VkPhysicalDevice physicalDevice,
124 VkPhysicalDeviceProperties* pProperties)
Jon Ashburn17f37372015-05-19 16:34:53 -0600125{
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600126 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, physicalDevice);
127 printf("At start of wrapped multi2 vkGetPhysicalDeviceProperties()\n");
128 VkResult result = pDisp->GetPhysicalDeviceProperties(physicalDevice, pProperties);
129 printf("Completed multi2 layer vkGetPhysicalDeviceProperties()\n");
130
131 return result;
132}
133
134VK_LAYER_EXPORT VkResult VKAPI multi2GetPhysicalDeviceFeatures(
135 VkPhysicalDevice physicalDevice,
136 VkPhysicalDeviceFeatures* pFeatures)
137{
138 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, physicalDevice);
139 printf("At start of wrapped multi2 vkGetPhysicalDeviceFeatures()\n");
140 VkResult result = pDisp->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
141 printf("Completed multi2 layer vkGetPhysicalDeviceFeatures()\n");
142
143 return result;
Jon Ashburn17f37372015-05-19 16:34:53 -0600144}
145
146/* hook DestroyInstance to remove tableInstanceMap entry */
147VK_LAYER_EXPORT VkResult VKAPI multi2DestroyInstance(VkInstance instance)
148{
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600149 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance);
150 dispatch_key key = get_dispatch_key(instance);
151
152 printf("At start of wrapped multi2 vkDestroyInstance()\n");
153 VkResult res = pDisp->DestroyInstance(instance);
154 multi2_instance_table_map.erase(key);
155 printf("Completed multi2 layer vkDestroyInstance()\n");
Jon Ashburn17f37372015-05-19 16:34:53 -0600156 return res;
157}
158
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600159VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600160{
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600161 if (inst == NULL)
162 return NULL;
163
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600164 /* loader uses this to force layer initialization; device object is wrapped */
165 if (!strcmp(pName, "multi2GetInstanceProcAddr") || !strcmp(pName, "vkGetInstanceProcAddr")) {
166 initInstanceTable(multi2_instance_table_map, (const VkBaseLayerObject *) inst);
167 return (PFN_vkVoidFunction) multi2GetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600168 }
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600169
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600170 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600171 return (PFN_vkVoidFunction) multi2EnumeratePhysicalDevices;
172 if (!strcmp("GetPhysicalDeviceProperties", pName))
173 return (PFN_vkVoidFunction) multi2GetPhysicalDeviceProperties;
174 if (!strcmp("GetPhysicalDeviceFeatures", pName))
175 return (PFN_vkVoidFunction) multi2GetPhysicalDeviceFeatures;
Jon Ashburn17f37372015-05-19 16:34:53 -0600176 if (!strcmp("vkDestroyInstance", pName))
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600177 return (PFN_vkVoidFunction) multi2DestroyInstance;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600178 else {
Jon Ashburndf34bfd2015-08-12 16:43:01 -0600179 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(multi2_instance_table_map, inst);
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600180 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600181 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600182 return pTable->GetInstanceProcAddr(inst, pName);
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700183 }
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700184}
185
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700186#ifdef __cplusplus
187} //extern "C"
188#endif
189