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