Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1 | /* |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 4 | * |
| 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 Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * Author: Jon Ashburn <jon@lunarg.com> |
| 24 | * |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include <string.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <assert.h> |
| 30 | #include <unordered_map> |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 31 | #include "vk_loader_platform.h" |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 32 | #include "vulkan/vk_layer.h" |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 33 | #include "vk_layer_table.h" |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 34 | |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 39 | |
| 40 | static device_table_map multi1_device_table_map; |
| 41 | /******************************** Layer multi1 functions **************************/ |
| 42 | |
Courtney Goeltzenleuchter | 75337d9 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 43 | /* hook DestroyDevice to remove tableMap entry */ |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 44 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi1DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 45 | { |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 46 | VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device); |
| 47 | dispatch_key key = get_dispatch_key(device); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 48 | |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 49 | printf("At start of multi1 layer vkDestroyDevice()\n"); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 50 | pDisp->DestroyDevice(device, pAllocator); |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 51 | multi1_device_table_map.erase(key); |
| 52 | printf("Completed multi1 layer vkDestroyDevice()\n"); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 53 | } |
| 54 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 55 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 56 | { |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 57 | VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 58 | |
| 59 | printf("At start of multi1 layer vkCreateSampler()\n"); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 60 | VkResult result = pDisp->CreateSampler(device, pCreateInfo, pAllocator, pSampler); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 61 | printf("Completed multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 62 | return result; |
| 63 | } |
| 64 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 65 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL multi1CreateGraphicsPipelines( |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 66 | VkDevice device, |
| 67 | VkPipelineCache pipelineCache, |
| 68 | uint32_t count, |
| 69 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 70 | const VkAllocationCallbacks* pAllocator, |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 71 | VkPipeline* pPipelines) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 72 | { |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 73 | VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 74 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 75 | printf("At start of multi1 layer vkCreateGraphicsPipeline()\n"); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 76 | VkResult result = pDisp->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 77 | printf("Completed multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 78 | return result; |
| 79 | } |
| 80 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 81 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL multi1GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 82 | { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 83 | if (!strcmp(pName, "multi1GetDeviceProcAddr") || !strcmp(pName, "vkGetDeviceProcAddr")) |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 84 | return (PFN_vkVoidFunction) multi1GetDeviceProcAddr; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 85 | if (!strcmp("vkDestroyDevice", pName)) |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 86 | return (PFN_vkVoidFunction) multi1DestroyDevice; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 87 | if (!strcmp("vkCreateSampler", pName)) |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 88 | return (PFN_vkVoidFunction) multi1CreateSampler; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 89 | if (!strcmp("vkCreateGraphicsPipelines", pName)) |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 90 | return (PFN_vkVoidFunction) multi1CreateGraphicsPipelines; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 91 | |
| 92 | if (device == NULL) |
| 93 | return NULL; |
| 94 | |
| 95 | VkLayerDispatchTable *pTable = get_dispatch_table(multi1_device_table_map, device); |
| 96 | if (pTable->GetDeviceProcAddr == NULL) |
| 97 | return NULL; |
| 98 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 99 | } |
| 100 | |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 101 | |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 102 | static instance_table_map multi2_instance_table_map; |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 103 | /******************************** Layer multi2 functions **************************/ |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 104 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL multi2EnumeratePhysicalDevices( |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 105 | VkInstance instance, |
| 106 | uint32_t* pPhysicalDeviceCount, |
| 107 | VkPhysicalDevice* pPhysicalDevices) |
| 108 | { |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 109 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance); |
Jon Ashburn | fe7ff9c | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 110 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 111 | printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 112 | VkResult result = pDisp->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 113 | printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); |
| 114 | return result; |
| 115 | } |
| 116 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 117 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi2GetPhysicalDeviceProperties( |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 118 | VkPhysicalDevice physicalDevice, |
| 119 | VkPhysicalDeviceProperties* pProperties) |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 120 | { |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 121 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, physicalDevice); |
| 122 | printf("At start of wrapped multi2 vkGetPhysicalDeviceProperties()\n"); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 123 | pDisp->GetPhysicalDeviceProperties(physicalDevice, pProperties); |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 124 | printf("Completed multi2 layer vkGetPhysicalDeviceProperties()\n"); |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 125 | } |
| 126 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 127 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi2GetPhysicalDeviceFeatures( |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 128 | VkPhysicalDevice physicalDevice, |
| 129 | VkPhysicalDeviceFeatures* pFeatures) |
| 130 | { |
| 131 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, physicalDevice); |
| 132 | printf("At start of wrapped multi2 vkGetPhysicalDeviceFeatures()\n"); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 133 | pDisp->GetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 134 | printf("Completed multi2 layer vkGetPhysicalDeviceFeatures()\n"); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 138 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL multi2DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 139 | { |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 140 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance); |
| 141 | dispatch_key key = get_dispatch_key(instance); |
| 142 | |
| 143 | printf("At start of wrapped multi2 vkDestroyInstance()\n"); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 144 | pDisp->DestroyInstance(instance, pAllocator); |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 145 | multi2_instance_table_map.erase(key); |
| 146 | printf("Completed multi2 layer vkDestroyInstance()\n"); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 147 | } |
| 148 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 149 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL multi2GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 150 | { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 151 | if (!strcmp(pName, "multi2GetInstanceProcAddr") || !strcmp(pName, "vkGetInstanceProcAddr")) |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 152 | return (PFN_vkVoidFunction) multi2GetInstanceProcAddr; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 153 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 154 | return (PFN_vkVoidFunction) multi2EnumeratePhysicalDevices; |
| 155 | if (!strcmp("GetPhysicalDeviceProperties", pName)) |
| 156 | return (PFN_vkVoidFunction) multi2GetPhysicalDeviceProperties; |
| 157 | if (!strcmp("GetPhysicalDeviceFeatures", pName)) |
| 158 | return (PFN_vkVoidFunction) multi2GetPhysicalDeviceFeatures; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 159 | if (!strcmp("vkDestroyInstance", pName)) |
Jon Ashburn | 1e41a44 | 2015-08-12 16:43:01 -0600 | [diff] [blame] | 160 | return (PFN_vkVoidFunction) multi2DestroyInstance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 161 | |
| 162 | if (inst == NULL) |
| 163 | return NULL; |
| 164 | |
| 165 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(multi2_instance_table_map, inst); |
| 166 | if (pTable->GetInstanceProcAddr == NULL) |
| 167 | return NULL; |
| 168 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 171 | #ifdef __cplusplus |
| 172 | } //extern "C" |
| 173 | #endif |
| 174 | |