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 | */ |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 24 | #include <string.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <assert.h> |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 27 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vk_dispatch_table_helper.h" |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 29 | #include "vk_layer.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 30 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 31 | #include "vk_layer_extension_utils.h" |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 32 | // The following is #included again to catch certain OS-specific functions |
| 33 | // being used: |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 34 | #include "vk_loader_platform.h" |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 35 | |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame^] | 36 | static const VkLayerProperties globalLayerProps[] = { |
| 37 | { |
| 38 | "Basic", |
| 39 | VK_API_VERSION, // specVersion |
| 40 | VK_MAKE_VERSION(0, 1, 0), // implVersion |
| 41 | "layer: Basic", |
| 42 | } |
| 43 | }; |
| 44 | |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 45 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 46 | VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device) |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 47 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 48 | printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device); |
| 49 | printf("vkLayerExtension1 returning SUCCESS\n"); |
| 50 | return VK_SUCCESS; |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 53 | static const VkLayerProperties basic_physicaldevice_layers[] = { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 54 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 55 | "Basic", |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 56 | VK_API_VERSION, |
| 57 | VK_MAKE_VERSION(0, 1, 0), |
| 58 | "Sample layer: Basic, implements vkLayerExtension1", |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 59 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 60 | }; |
| 61 | |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 62 | /* Must use Vulkan name so that loader finds it */ |
| 63 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties( |
| 64 | VkPhysicalDevice physicalDevice, |
| 65 | uint32_t* pCount, |
| 66 | VkLayerProperties* pProperties) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 67 | { |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 68 | /* Mem tracker's physical device layers are the same as global */ |
| 69 | return util_GetLayerProperties(ARRAY_SIZE(basic_physicaldevice_layers), basic_physicaldevice_layers, |
| 70 | pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 71 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 72 | |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 73 | static const VkExtensionProperties basic_physicaldevice_extensions[] = { |
| 74 | { |
| 75 | "vkLayerExtension1", |
| 76 | VK_MAKE_VERSION(0, 1, 0), |
| 77 | VK_API_VERSION |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties( |
| 82 | VkPhysicalDevice physicalDevice, |
| 83 | const char *pLayerName, |
| 84 | uint32_t *pCount, |
| 85 | VkExtensionProperties *pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 86 | { |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 87 | return util_GetExtensionProperties(ARRAY_SIZE(basic_physicaldevice_extensions), basic_physicaldevice_extensions, |
| 88 | pCount, pProperties); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 89 | } |
| 90 | |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 91 | VK_LAYER_EXPORT VkResult VKAPI basic_EnumeratePhysicalDevices( |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 92 | VkInstance instance, |
| 93 | uint32_t* pPhysicalDeviceCount, |
| 94 | VkPhysicalDevice* pPhysicalDevices) |
| 95 | { |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 96 | printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance); |
Jon Ashburn | 9eed289 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 97 | VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 98 | printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount); |
| 99 | return result; |
| 100 | } |
| 101 | |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 102 | VK_LAYER_EXPORT VkResult VKAPI basic_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 103 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu); |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 105 | VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 106 | printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice); |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 107 | return result; |
| 108 | } |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 109 | |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 110 | /* hook DestroyDevice to remove tableMap entry */ |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 111 | VK_LAYER_EXPORT VkResult VKAPI basic_DestroyDevice(VkDevice device) |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 112 | { |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 113 | dispatch_key key = get_dispatch_key(device); |
Jon Ashburn | 9eed289 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 114 | VkResult res = device_dispatch_table(device)->DestroyDevice(device); |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 115 | destroy_device_dispatch_table(key); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 116 | return res; |
| 117 | } |
| 118 | |
| 119 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 120 | VK_LAYER_EXPORT VkResult VKAPI basic_DestroyInstance(VkInstance instance) |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 121 | { |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 122 | dispatch_key key = get_dispatch_key(instance); |
Jon Ashburn | 9eed289 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 123 | VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance); |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 124 | destroy_instance_dispatch_table(key); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 125 | return res; |
| 126 | } |
| 127 | |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 128 | VK_LAYER_EXPORT VkResult VKAPI basic_GetPhysicalDeviceFormatInfo(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo) |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 129 | { |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 130 | printf("At start of wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu); |
| 131 | VkResult result = instance_dispatch_table(gpu)->GetPhysicalDeviceFormatInfo(gpu, format, pFormatInfo); |
| 132 | printf("Completed wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu); |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 133 | return result; |
| 134 | } |
| 135 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 136 | VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 137 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 138 | if (device == NULL) |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 139 | return NULL; |
Chia-I Wu | b665d94 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 140 | |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 141 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 142 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
Jon Ashburn | 9eed289 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 143 | initDeviceTable((const VkBaseLayerObject *) device); |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 144 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 145 | } |
| 146 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 147 | if (!strcmp("vkCreateDevice", pName)) |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 148 | return (void *) basic_CreateDevice; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 149 | if (!strcmp("vkDestroyDevice", pName)) |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 150 | return (void *) basic_DestroyDevice; |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 151 | if (!strcmp("vkLayerExtension1", pName)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 152 | return (void *) vkLayerExtension1; |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 153 | else |
| 154 | { |
Jon Ashburn | 9eed289 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 155 | if (device_dispatch_table(device)->GetDeviceProcAddr == NULL) |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 156 | return NULL; |
Jon Ashburn | 9eed289 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 157 | return device_dispatch_table(device)->GetDeviceProcAddr(device, pName); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName) |
| 162 | { |
| 163 | if (instance == NULL) |
| 164 | return NULL; |
| 165 | |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 166 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 167 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
Jon Ashburn | 9eed289 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 168 | initInstanceTable((const VkBaseLayerObject *) instance); |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 169 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 170 | } |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 171 | |
| 172 | if (!strcmp("vkGetPhysicalDeviceLayerProperties", pName)) |
| 173 | return (void *) vkGetPhysicalDeviceLayerProperties; |
| 174 | if (!strcmp("vkGetPhysicalDeviceExtensionProperties", pName)) |
| 175 | return (void *) vkGetPhysicalDeviceExtensionProperties; |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 176 | if (!strcmp("vkGetPhysicalDeviceFormatInfo", pName)) |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 177 | return (void *) basic_GetPhysicalDeviceFormatInfo; |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 178 | if (!strcmp("vkDestroyInstance", pName)) |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 179 | return (void *) basic_DestroyInstance; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 180 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 181 | return (void*) basic_EnumeratePhysicalDevices; |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 182 | |
Courtney Goeltzenleuchter | 842f842 | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 183 | if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL) |
| 184 | return NULL; |
| 185 | return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName); |
Jon Ashburn | 1fec424 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 186 | } |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame^] | 187 | |
| 188 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties) |
| 189 | { |
| 190 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 191 | } |
| 192 | |
| 193 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties) |
| 194 | { |
| 195 | return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties); |
| 196 | } |