Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Jon Ashburn | 8d8dad0 | 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 | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 30 | #include "vk_loader_platform.h" |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 31 | #include "vk_layer.h" |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 32 | #include "vk_layer_table.h" |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 33 | |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
Jon Ashburn | df34bfd | 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 | 142c9c2 | 2015-07-06 21:32:03 -0600 | [diff] [blame] | 42 | /* hook DestroyDevice to remove tableMap entry */ |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 43 | VK_LAYER_EXPORT VkResult VKAPI multi1DestroyDevice(VkDevice device) |
| 44 | { |
Jon Ashburn | df34bfd | 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 | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 47 | |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 48 | 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 Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 52 | return res; |
| 53 | } |
| 54 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 55 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 56 | { |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 57 | VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 58 | |
| 59 | printf("At start of multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 60 | VkResult result = pDisp->CreateSampler(device, pCreateInfo, pSampler); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 61 | printf("Completed multi1 layer vkCreateSampler()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 62 | return result; |
| 63 | } |
| 64 | |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 65 | VK_LAYER_EXPORT VkResult VKAPI multi1CreateGraphicsPipelines( |
| 66 | VkDevice device, |
| 67 | VkPipelineCache pipelineCache, |
| 68 | uint32_t count, |
| 69 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 70 | VkPipeline* pPipelines) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 71 | { |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 72 | VkLayerDispatchTable *pDisp = get_dispatch_table(multi1_device_table_map, device); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 73 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 74 | printf("At start of multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 75 | VkResult result = pDisp->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 76 | printf("Completed multi1 layer vkCreateGraphicsPipeline()\n"); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 77 | return result; |
| 78 | } |
| 79 | |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 80 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi1GetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 81 | { |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 82 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 83 | if (device == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 84 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 85 | |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 86 | /* 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 Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 90 | } |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 91 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 92 | if (!strcmp("vkDestroyDevice", pName)) |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 93 | return (PFN_vkVoidFunction) multi1DestroyDevice; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 94 | if (!strcmp("vkCreateSampler", pName)) |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 95 | return (PFN_vkVoidFunction) multi1CreateSampler; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 96 | if (!strcmp("vkCreateGraphicsPipelines", pName)) |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 97 | return (PFN_vkVoidFunction) multi1CreateGraphicsPipelines; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 98 | else { |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 99 | VkLayerDispatchTable *pTable = get_dispatch_table(multi1_device_table_map, device); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 100 | if (pTable->GetDeviceProcAddr == NULL) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 101 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 102 | return pTable->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 106 | |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 107 | static instance_table_map multi2_instance_table_map; |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 108 | /******************************** Layer multi2 functions **************************/ |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 109 | VK_LAYER_EXPORT VkResult VKAPI multi2EnumeratePhysicalDevices( |
| 110 | VkInstance instance, |
| 111 | uint32_t* pPhysicalDeviceCount, |
| 112 | VkPhysicalDevice* pPhysicalDevices) |
| 113 | { |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 114 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(multi2_instance_table_map, instance); |
Jon Ashburn | d25a78e | 2015-05-15 16:40:25 -0600 | [diff] [blame] | 115 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 116 | printf("At start of wrapped multi2 vkEnumeratePhysicalDevices()\n"); |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 117 | VkResult result = pDisp->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 118 | printf("Completed multi2 layer vkEnumeratePhysicalDevices()\n"); |
| 119 | return result; |
| 120 | } |
| 121 | |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 122 | VK_LAYER_EXPORT VkResult VKAPI multi2GetPhysicalDeviceProperties( |
| 123 | VkPhysicalDevice physicalDevice, |
| 124 | VkPhysicalDeviceProperties* pProperties) |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 125 | { |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 126 | 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 | |
| 134 | VK_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 Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 147 | VK_LAYER_EXPORT VkResult VKAPI multi2DestroyInstance(VkInstance instance) |
| 148 | { |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 149 | 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 Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 156 | return res; |
| 157 | } |
| 158 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 159 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI multi2GetInstanceProcAddr(VkInstance inst, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 160 | { |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 161 | if (inst == NULL) |
| 162 | return NULL; |
| 163 | |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 164 | /* 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 Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 168 | } |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 169 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 170 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 171 | 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 Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 176 | if (!strcmp("vkDestroyInstance", pName)) |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 177 | return (PFN_vkVoidFunction) multi2DestroyInstance; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 178 | else { |
Jon Ashburn | df34bfd | 2015-08-12 16:43:01 -0600 | [diff] [blame^] | 179 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(multi2_instance_table_map, inst); |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 180 | if (pTable->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 181 | return NULL; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 182 | return pTable->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 183 | } |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 186 | #ifdef __cplusplus |
| 187 | } //extern "C" |
| 188 | #endif |
| 189 | |