blob: 5234462576fdd9da542a24bdbfa585fc8da844ff [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>
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Tobin Ehlis0c6f9ee2015-07-03 09:42:57 -060031#include "vk_layer.h"
Jon Ashburn1e41a442015-08-12 16:43:01 -060032#include "vk_layer_table.h"
Jon Ashburn79113cc2014-12-01 14:22:40 -070033
Jon Ashburn79113cc2014-12-01 14:22:40 -070034#ifdef __cplusplus
35extern "C" {
36#endif
37
Jon Ashburn1e41a442015-08-12 16:43:01 -060038
39static device_table_map multi1_device_table_map;
40/******************************** Layer multi1 functions **************************/
41
Courtney Goeltzenleuchter75337d92015-07-06 21:32:03 -060042/* hook DestroyDevice to remove tableMap entry */
Chia-I Wuf7458c52015-10-26 21:10:41 +080043VK_LAYER_EXPORT void VKAPI multi1DestroyDevice(VkDevice device, const VkAllocCallbacks* pAllocator)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -060044{
Jon Ashburn1e41a442015-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 Ashburn9a8a2e22015-05-19 16:34:53 -060047
Jon Ashburn1e41a442015-08-12 16:43:01 -060048 printf("At start of multi1 layer vkDestroyDevice()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +080049 pDisp->DestroyDevice(device, pAllocator);
Jon Ashburn1e41a442015-08-12 16:43:01 -060050 multi1_device_table_map.erase(key);
51 printf("Completed multi1 layer vkDestroyDevice()\n");
Jon Ashburn9a8a2e22015-05-19 16:34:53 -060052}
53
Chia-I Wuf7458c52015-10-26 21:10:41 +080054VK_LAYER_EXPORT VkResult VKAPI multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocCallbacks* pAllocator, VkSampler* pSampler)
Jon Ashburn79113cc2014-12-01 14:22:40 -070055{
Jon Ashburn1e41a442015-08-12 16:43:01 -060056 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn95a77ba2015-05-15 15:09:35 -060057
58 printf("At start of multi1 layer vkCreateSampler()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +080059 VkResult result = pDisp->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Jon Ashburn95a77ba2015-05-15 15:09:35 -060060 printf("Completed multi1 layer vkCreateSampler()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070061 return result;
62}
63
Jon Ashburnc669cc62015-07-09 15:02:25 -060064VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipelines(
65 VkDevice device,
66 VkPipelineCache pipelineCache,
67 uint32_t count,
68 const VkGraphicsPipelineCreateInfo* pCreateInfos,
Chia-I Wuf7458c52015-10-26 21:10:41 +080069 const VkAllocCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -060070 VkPipeline* pPipelines)
Jon Ashburn79113cc2014-12-01 14:22:40 -070071{
Jon Ashburn1e41a442015-08-12 16:43:01 -060072 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn79113cc2014-12-01 14:22:40 -070073
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060074 printf("At start of multi1 layer vkCreateGraphicsPipeline()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +080075 VkResult result = pDisp->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060076 printf("Completed multi1 layer vkCreateGraphicsPipeline()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070077 return result;
78}
79
Jon Ashburn1e41a442015-08-12 16:43:01 -060080VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -070081{
Chia-I Wub665d942015-01-05 09:41:27 +080082
Jon Ashburn8d1b0b52015-05-18 13:20:15 -060083 if (device == NULL)
Jon Ashburn79113cc2014-12-01 14:22:40 -070084 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +080085
Jon Ashburn1e41a442015-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 Ashburn8fd08252015-05-28 16:25:02 -060090 }
Jon Ashburn1e41a442015-08-12 16:43:01 -060091
Jon Ashburn9a8a2e22015-05-19 16:34:53 -060092 if (!strcmp("vkDestroyDevice", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -060093 return (PFN_vkVoidFunction) multi1DestroyDevice;
Jon Ashburn95a77ba2015-05-15 15:09:35 -060094 if (!strcmp("vkCreateSampler", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -060095 return (PFN_vkVoidFunction) multi1CreateSampler;
Jon Ashburnc669cc62015-07-09 15:02:25 -060096 if (!strcmp("vkCreateGraphicsPipelines", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -060097 return (PFN_vkVoidFunction) multi1CreateGraphicsPipelines;
Jon Ashburn79113cc2014-12-01 14:22:40 -070098 else {
Jon Ashburn1e41a442015-08-12 16:43:01 -060099 VkLayerDispatchTable *pTable = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn8fd08252015-05-28 16:25:02 -0600100 if (pTable->GetDeviceProcAddr == NULL)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700101 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600102 return pTable->GetDeviceProcAddr(device, pName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600103 }
104}
105
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600106
Jon Ashburn1e41a442015-08-12 16:43:01 -0600107static instance_table_map multi2_instance_table_map;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700108/******************************** Layer multi2 functions **************************/
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600109VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices(
110 VkInstance instance,
111 uint32_t* pPhysicalDeviceCount,
112 VkPhysicalDevice* pPhysicalDevices)
113{
Jon Ashburn1e41a442015-08-12 16:43:01 -0600114 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance);
Jon Ashburnfe7ff9c2015-05-15 16:40:25 -0600115
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600116 printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n");
Jon Ashburn1e41a442015-08-12 16:43:01 -0600117 VkResult result = pDisp->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600118 printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n");
119 return result;
120}
121
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600122VK_LAYER_EXPORT void VKAPI multi2GetPhysicalDeviceProperties(
Jon Ashburn1e41a442015-08-12 16:43:01 -0600123 VkPhysicalDevice physicalDevice,
124 VkPhysicalDeviceProperties* pProperties)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600125{
Jon Ashburn1e41a442015-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");
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600128 pDisp->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Jon Ashburn1e41a442015-08-12 16:43:01 -0600129 printf("Completed multi2 layer vkGetPhysicalDeviceProperties()\n");
Jon Ashburn1e41a442015-08-12 16:43:01 -0600130}
131
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600132VK_LAYER_EXPORT void VKAPI multi2GetPhysicalDeviceFeatures(
Jon Ashburn1e41a442015-08-12 16:43:01 -0600133 VkPhysicalDevice physicalDevice,
134 VkPhysicalDeviceFeatures* pFeatures)
135{
136 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, physicalDevice);
137 printf("At start of wrapped multi2 vkGetPhysicalDeviceFeatures()\n");
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600138 pDisp->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Jon Ashburn1e41a442015-08-12 16:43:01 -0600139 printf("Completed multi2 layer vkGetPhysicalDeviceFeatures()\n");
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600140}
141
142/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuf7458c52015-10-26 21:10:41 +0800143VK_LAYER_EXPORT void VKAPI multi2DestroyInstance(VkInstance instance, const VkAllocCallbacks* pAllocator)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600144{
Jon Ashburn1e41a442015-08-12 16:43:01 -0600145 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance);
146 dispatch_key key = get_dispatch_key(instance);
147
148 printf("At start of wrapped multi2 vkDestroyInstance()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +0800149 pDisp->DestroyInstance(instance, pAllocator);
Jon Ashburn1e41a442015-08-12 16:43:01 -0600150 multi2_instance_table_map.erase(key);
151 printf("Completed multi2 layer vkDestroyInstance()\n");
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600152}
153
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600154VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600155{
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600156 if (inst == NULL)
157 return NULL;
158
Jon Ashburn1e41a442015-08-12 16:43:01 -0600159 /* loader uses this to force layer initialization; device object is wrapped */
160 if (!strcmp(pName, "multi2GetInstanceProcAddr") || !strcmp(pName, "vkGetInstanceProcAddr")) {
161 initInstanceTable(multi2_instance_table_map, (const VkBaseLayerObject *) inst);
162 return (PFN_vkVoidFunction) multi2GetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600163 }
Jon Ashburn1e41a442015-08-12 16:43:01 -0600164
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600165 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -0600166 return (PFN_vkVoidFunction) multi2EnumeratePhysicalDevices;
167 if (!strcmp("GetPhysicalDeviceProperties", pName))
168 return (PFN_vkVoidFunction) multi2GetPhysicalDeviceProperties;
169 if (!strcmp("GetPhysicalDeviceFeatures", pName))
170 return (PFN_vkVoidFunction) multi2GetPhysicalDeviceFeatures;
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600171 if (!strcmp("vkDestroyInstance", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -0600172 return (PFN_vkVoidFunction) multi2DestroyInstance;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600173 else {
Jon Ashburn1e41a442015-08-12 16:43:01 -0600174 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(multi2_instance_table_map, inst);
Jon Ashburn8fd08252015-05-28 16:25:02 -0600175 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600176 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600177 return pTable->GetInstanceProcAddr(inst, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700178 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700179}
180
Jon Ashburn79113cc2014-12-01 14:22:40 -0700181#ifdef __cplusplus
182} //extern "C"
183#endif
184