Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1 | /* |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | 8a17da5 | 2015-10-29 13:50:34 -0600 | [diff] [blame^] | 3 | * Copyright (C) 2015 Valve Corporation |
Michael Lentine | 9268944 | 2015-09-09 12:39:13 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015 Google Inc. |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 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 | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 24 | #include <string.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <assert.h> |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 27 | #include "vk_dispatch_table_helper.h" |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 28 | #include "vk_layer.h" |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 29 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 30 | #include "vk_layer_extension_utils.h" |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 31 | |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 32 | static const VkLayerProperties globalLayerProps[] = { |
| 33 | { |
| 34 | "Basic", |
| 35 | VK_API_VERSION, // specVersion |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 36 | VK_MAKE_VERSION(0, 1, 0), // implementationVersion |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 37 | "layer: Basic", |
| 38 | } |
| 39 | }; |
| 40 | |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 41 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 42 | VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 43 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 44 | printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device); |
| 45 | printf("vkLayerExtension1 returning SUCCESS\n"); |
| 46 | return VK_SUCCESS; |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 49 | static const VkLayerProperties basic_physicaldevice_layers[] = { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 50 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 51 | "Basic", |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 52 | VK_API_VERSION, |
| 53 | VK_MAKE_VERSION(0, 1, 0), |
| 54 | "Sample layer: Basic, implements vkLayerExtension1", |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 55 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 56 | }; |
| 57 | |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 58 | /* Must use Vulkan name so that loader finds it */ |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 59 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties( |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 60 | VkPhysicalDevice physicalDevice, |
| 61 | uint32_t* pCount, |
| 62 | VkLayerProperties* pProperties) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 63 | { |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 64 | /* Mem tracker's physical device layers are the same as global */ |
| 65 | return util_GetLayerProperties(ARRAY_SIZE(basic_physicaldevice_layers), basic_physicaldevice_layers, |
| 66 | pCount, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 67 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 68 | |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 69 | static const VkExtensionProperties basic_physicaldevice_extensions[] = { |
| 70 | { |
| 71 | "vkLayerExtension1", |
| 72 | VK_MAKE_VERSION(0, 1, 0), |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 73 | } |
| 74 | }; |
| 75 | |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 76 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties( |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 77 | VkPhysicalDevice physicalDevice, |
| 78 | const char *pLayerName, |
| 79 | uint32_t *pCount, |
| 80 | VkExtensionProperties *pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 81 | { |
Jon Ashburn | aff81ff | 2015-11-02 17:37:20 -0700 | [diff] [blame] | 82 | if (pLayerName == NULL) { |
| 83 | return instance_dispatch_table(physicalDevice)->EnumerateDeviceExtensionProperties( |
| 84 | physicalDevice, |
| 85 | NULL, |
| 86 | pCount, |
| 87 | pProperties); |
| 88 | } else { |
| 89 | return util_GetExtensionProperties(ARRAY_SIZE(basic_physicaldevice_extensions), |
| 90 | basic_physicaldevice_extensions, |
| 91 | pCount, pProperties); |
| 92 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 93 | } |
| 94 | |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 95 | VK_LAYER_EXPORT VkResult VKAPI basic_EnumeratePhysicalDevices( |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 96 | VkInstance instance, |
| 97 | uint32_t* pPhysicalDeviceCount, |
| 98 | VkPhysicalDevice* pPhysicalDevices) |
| 99 | { |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 100 | printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 101 | VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 102 | printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount); |
| 103 | return result; |
| 104 | } |
| 105 | |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 106 | VK_LAYER_EXPORT VkResult VKAPI basic_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 107 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 108 | printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu); |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 109 | VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 110 | printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice); |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 111 | return result; |
| 112 | } |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 113 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 114 | /* hook DestroyDevice to remove tableMap entry */ |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 115 | VK_LAYER_EXPORT void VKAPI basic_DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 116 | { |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 117 | dispatch_key key = get_dispatch_key(device); |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 118 | device_dispatch_table(device)->DestroyDevice(device, pAllocator); |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 119 | destroy_device_dispatch_table(key); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 123 | VK_LAYER_EXPORT void VKAPI basic_DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 124 | { |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 125 | dispatch_key key = get_dispatch_key(instance); |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 126 | instance_dispatch_table(instance)->DestroyInstance(instance, pAllocator); |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 127 | destroy_instance_dispatch_table(key); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 128 | } |
| 129 | |
Courtney Goeltzenleuchter | 01d2ae1 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 130 | VK_LAYER_EXPORT void VKAPI basic_GetPhysicalDeviceFormatProperties(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 131 | { |
Courtney Goeltzenleuchter | ab36aa6 | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 132 | printf("At start of wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu); |
Courtney Goeltzenleuchter | 01d2ae1 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 133 | instance_dispatch_table(gpu)->GetPhysicalDeviceFormatProperties(gpu, format, pFormatInfo); |
Courtney Goeltzenleuchter | ab36aa6 | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 134 | printf("Completed wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu); |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 137 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 138 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 139 | if (device == NULL) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 140 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 141 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 142 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 143 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 144 | initDeviceTable((const VkBaseLayerObject *) device); |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 145 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 146 | } |
| 147 | |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 148 | if (!strcmp("vkCreateDevice", pName)) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 149 | return (PFN_vkVoidFunction) basic_CreateDevice; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 150 | if (!strcmp("vkDestroyDevice", pName)) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 151 | return (PFN_vkVoidFunction) basic_DestroyDevice; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 152 | if (!strcmp("vkLayerExtension1", pName)) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 153 | return (PFN_vkVoidFunction) vkLayerExtension1; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 154 | else |
| 155 | { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 156 | if (device_dispatch_table(device)->GetDeviceProcAddr == NULL) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 157 | return NULL; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 158 | return device_dispatch_table(device)->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 162 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 163 | { |
| 164 | if (instance == NULL) |
| 165 | return NULL; |
| 166 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 167 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 168 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 169 | initInstanceTable((const VkBaseLayerObject *) instance); |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 170 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 171 | } |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 172 | |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 173 | if (!strcmp("vkEnumerateDeviceLayerProperties", pName)) |
| 174 | return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties; |
| 175 | if (!strcmp("vkEnumerateDeviceExtensionProperties", pName)) |
| 176 | return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties; |
Courtney Goeltzenleuchter | ab36aa6 | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 177 | if (!strcmp("vkGetPhysicalDeviceFormatProperties", pName)) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 178 | return (PFN_vkVoidFunction) basic_GetPhysicalDeviceFormatProperties; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 179 | if (!strcmp("vkDestroyInstance", pName)) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 180 | return (PFN_vkVoidFunction) basic_DestroyInstance; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 181 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 182 | return (PFN_vkVoidFunction) basic_EnumeratePhysicalDevices; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 183 | |
Courtney Goeltzenleuchter | 326075a | 2015-07-05 11:10:06 -0600 | [diff] [blame] | 184 | if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL) |
| 185 | return NULL; |
| 186 | return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName); |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 187 | } |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 188 | |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 189 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties) |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 190 | { |
| 191 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 192 | } |
| 193 | |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 194 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties) |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 195 | { |
| 196 | return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties); |
| 197 | } |