blob: c5d9d1b55634d6ace68b9aeb5d3d987edb4af32b [file] [log] [blame]
Jon Ashburn79113cc2014-12-01 14:22:40 -07001/*
Jon Ashburn79113cc2014-12-01 14:22:40 -07002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Jon Ashburn79113cc2014-12-01 14:22:40 -07004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 * Author: Jon Ashburn <jon@lunarg.com>
24 *
Jon Ashburn79113cc2014-12-01 14:22:40 -070025 */
26
27#include <string.h>
28#include <stdlib.h>
29#include <assert.h>
30#include <unordered_map>
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060031#include "vk_loader_platform.h"
David Pinedo9316d3b2015-11-06 12:54:48 -070032#include "vulkan/vk_layer.h"
Jon Ashburn1e41a442015-08-12 16:43:01 -060033#include "vk_layer_table.h"
Jon Ashburn79113cc2014-12-01 14:22:40 -070034
Jon Ashburn79113cc2014-12-01 14:22:40 -070035#ifdef __cplusplus
36extern "C" {
37#endif
38
Jon Ashburn1e41a442015-08-12 16:43:01 -060039
40static device_table_map multi1_device_table_map;
41/******************************** Layer multi1 functions **************************/
42
Courtney Goeltzenleuchter75337d92015-07-06 21:32:03 -060043/* hook DestroyDevice to remove tableMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +080044VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi1DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -060045{
Jon Ashburn1e41a442015-08-12 16:43:01 -060046 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
47 dispatch_key key = get_dispatch_key(device);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -060048
Jon Ashburn1e41a442015-08-12 16:43:01 -060049 printf("At start of multi1 layer vkDestroyDevice()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +080050 pDisp->DestroyDevice(device, pAllocator);
Jon Ashburn1e41a442015-08-12 16:43:01 -060051 multi1_device_table_map.erase(key);
52 printf("Completed multi1 layer vkDestroyDevice()\n");
Jon Ashburn9a8a2e22015-05-19 16:34:53 -060053}
54
Chia-I Wu9ab61502015-11-06 06:42:02 +080055VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
Jon Ashburn79113cc2014-12-01 14:22:40 -070056{
Jon Ashburn1e41a442015-08-12 16:43:01 -060057 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn95a77ba2015-05-15 15:09:35 -060058
59 printf("At start of multi1 layer vkCreateSampler()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +080060 VkResult result = pDisp->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Jon Ashburn95a77ba2015-05-15 15:09:35 -060061 printf("Completed multi1 layer vkCreateSampler()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070062 return result;
63}
64
Chia-I Wu9ab61502015-11-06 06:42:02 +080065VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL multi1CreateGraphicsPipelines(
Jon Ashburnc669cc62015-07-09 15:02:25 -060066 VkDevice device,
67 VkPipelineCache pipelineCache,
68 uint32_t count,
69 const VkGraphicsPipelineCreateInfo* pCreateInfos,
Chia-I Wu3432a0c2015-10-27 18:04:07 +080070 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -060071 VkPipeline* pPipelines)
Jon Ashburn79113cc2014-12-01 14:22:40 -070072{
Jon Ashburn1e41a442015-08-12 16:43:01 -060073 VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn79113cc2014-12-01 14:22:40 -070074
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060075 printf("At start of multi1 layer vkCreateGraphicsPipeline()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +080076 VkResult result = pDisp->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060077 printf("Completed multi1 layer vkCreateGraphicsPipeline()\n");
Jon Ashburn79113cc2014-12-01 14:22:40 -070078 return result;
79}
80
Chia-I Wu9ab61502015-11-06 06:42:02 +080081VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL multi1GetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -070082{
Chia-I Wub665d942015-01-05 09:41:27 +080083
Jon Ashburn8d1b0b52015-05-18 13:20:15 -060084 if (device == NULL)
Jon Ashburn79113cc2014-12-01 14:22:40 -070085 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +080086
Jon Ashburn1e41a442015-08-12 16:43:01 -060087 /* loader uses this to force layer initialization; device object is wrapped */
88 if (!strcmp(pName, "multi1GetDeviceProcAddr") || !strcmp(pName, "vkGetDeviceProcAddr")) {
89 initDeviceTable(multi1_device_table_map, (const VkBaseLayerObject *) device);
90 return (PFN_vkVoidFunction) multi1GetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -060091 }
Jon Ashburn1e41a442015-08-12 16:43:01 -060092
Jon Ashburn9a8a2e22015-05-19 16:34:53 -060093 if (!strcmp("vkDestroyDevice", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -060094 return (PFN_vkVoidFunction) multi1DestroyDevice;
Jon Ashburn95a77ba2015-05-15 15:09:35 -060095 if (!strcmp("vkCreateSampler", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -060096 return (PFN_vkVoidFunction) multi1CreateSampler;
Jon Ashburnc669cc62015-07-09 15:02:25 -060097 if (!strcmp("vkCreateGraphicsPipelines", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -060098 return (PFN_vkVoidFunction) multi1CreateGraphicsPipelines;
Jon Ashburn79113cc2014-12-01 14:22:40 -070099 else {
Jon Ashburn1e41a442015-08-12 16:43:01 -0600100 VkLayerDispatchTable *pTable = get_dispatch_table(multi1_device_table_map, device);
Jon Ashburn8fd08252015-05-28 16:25:02 -0600101 if (pTable->GetDeviceProcAddr == NULL)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700102 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600103 return pTable->GetDeviceProcAddr(device, pName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600104 }
105}
106
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600107
Jon Ashburn1e41a442015-08-12 16:43:01 -0600108static instance_table_map multi2_instance_table_map;
Jon Ashburn79113cc2014-12-01 14:22:40 -0700109/******************************** Layer multi2 functions **************************/
Chia-I Wu9ab61502015-11-06 06:42:02 +0800110VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL multi2EnumeratePhysicalDevices(
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600111 VkInstance instance,
112 uint32_t* pPhysicalDeviceCount,
113 VkPhysicalDevice* pPhysicalDevices)
114{
Jon Ashburn1e41a442015-08-12 16:43:01 -0600115 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance);
Jon Ashburnfe7ff9c2015-05-15 16:40:25 -0600116
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600117 printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n");
Jon Ashburn1e41a442015-08-12 16:43:01 -0600118 VkResult result = pDisp->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600119 printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n");
120 return result;
121}
122
Chia-I Wu9ab61502015-11-06 06:42:02 +0800123VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi2GetPhysicalDeviceProperties(
Jon Ashburn1e41a442015-08-12 16:43:01 -0600124 VkPhysicalDevice physicalDevice,
125 VkPhysicalDeviceProperties* pProperties)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600126{
Jon Ashburn1e41a442015-08-12 16:43:01 -0600127 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, physicalDevice);
128 printf("At start of wrapped multi2 vkGetPhysicalDeviceProperties()\n");
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600129 pDisp->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Jon Ashburn1e41a442015-08-12 16:43:01 -0600130 printf("Completed multi2 layer vkGetPhysicalDeviceProperties()\n");
Jon Ashburn1e41a442015-08-12 16:43:01 -0600131}
132
Chia-I Wu9ab61502015-11-06 06:42:02 +0800133VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi2GetPhysicalDeviceFeatures(
Jon Ashburn1e41a442015-08-12 16:43:01 -0600134 VkPhysicalDevice physicalDevice,
135 VkPhysicalDeviceFeatures* pFeatures)
136{
137 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, physicalDevice);
138 printf("At start of wrapped multi2 vkGetPhysicalDeviceFeatures()\n");
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600139 pDisp->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Jon Ashburn1e41a442015-08-12 16:43:01 -0600140 printf("Completed multi2 layer vkGetPhysicalDeviceFeatures()\n");
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600141}
142
143/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +0800144VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi2DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600145{
Jon Ashburn1e41a442015-08-12 16:43:01 -0600146 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance);
147 dispatch_key key = get_dispatch_key(instance);
148
149 printf("At start of wrapped multi2 vkDestroyInstance()\n");
Chia-I Wuf7458c52015-10-26 21:10:41 +0800150 pDisp->DestroyInstance(instance, pAllocator);
Jon Ashburn1e41a442015-08-12 16:43:01 -0600151 multi2_instance_table_map.erase(key);
152 printf("Completed multi2 layer vkDestroyInstance()\n");
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600153}
154
Chia-I Wu9ab61502015-11-06 06:42:02 +0800155VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL multi2GetInstanceProcAddr(VkInstance inst, const char* pName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600156{
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600157 if (inst == NULL)
158 return NULL;
159
Jon Ashburn1e41a442015-08-12 16:43:01 -0600160 /* loader uses this to force layer initialization; device object is wrapped */
161 if (!strcmp(pName, "multi2GetInstanceProcAddr") || !strcmp(pName, "vkGetInstanceProcAddr")) {
162 initInstanceTable(multi2_instance_table_map, (const VkBaseLayerObject *) inst);
163 return (PFN_vkVoidFunction) multi2GetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600164 }
Jon Ashburn1e41a442015-08-12 16:43:01 -0600165
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600166 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -0600167 return (PFN_vkVoidFunction) multi2EnumeratePhysicalDevices;
168 if (!strcmp("GetPhysicalDeviceProperties", pName))
169 return (PFN_vkVoidFunction) multi2GetPhysicalDeviceProperties;
170 if (!strcmp("GetPhysicalDeviceFeatures", pName))
171 return (PFN_vkVoidFunction) multi2GetPhysicalDeviceFeatures;
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600172 if (!strcmp("vkDestroyInstance", pName))
Jon Ashburn1e41a442015-08-12 16:43:01 -0600173 return (PFN_vkVoidFunction) multi2DestroyInstance;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600174 else {
Jon Ashburn1e41a442015-08-12 16:43:01 -0600175 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(multi2_instance_table_map, inst);
Jon Ashburn8fd08252015-05-28 16:25:02 -0600176 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600177 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600178 return pTable->GetInstanceProcAddr(inst, pName);
Jon Ashburn79113cc2014-12-01 14:22:40 -0700179 }
Jon Ashburn79113cc2014-12-01 14:22:40 -0700180}
181
Jon Ashburn79113cc2014-12-01 14:22:40 -0700182#ifdef __cplusplus
183} //extern "C"
184#endif
185