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 | */ |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 24 | #include <string.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <assert.h> |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 27 | #include "loader_platform.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vk_dispatch_table_helper.h" |
| 29 | #include "vkLayer.h" |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 30 | #include "layers_table.h" |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 31 | // The following is #included again to catch certain OS-specific functions |
| 32 | // being used: |
| 33 | #include "loader_platform.h" |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 34 | |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 35 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 36 | VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 37 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 38 | printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device); |
| 39 | printf("vkLayerExtension1 returning SUCCESS\n"); |
| 40 | return VK_SUCCESS; |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 43 | #define BASIC_LAYER_EXT_ARRAY_SIZE 2 |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 44 | |
| 45 | static const VkExtensionProperties basicExts[BASIC_LAYER_EXT_ARRAY_SIZE] = { |
| 46 | { |
| 47 | VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 48 | "Basic", |
| 49 | 0x10, |
| 50 | "Sample layer: Basic ", |
| 51 | // 0, |
| 52 | // NULL, |
| 53 | }, |
| 54 | { |
| 55 | VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 56 | "vkLayerExtension1", |
| 57 | 0x10, |
| 58 | "Sample layer: Basic", |
| 59 | // 0, |
| 60 | // NULL, |
| 61 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
| 65 | VkExtensionInfoType infoType, |
| 66 | uint32_t extensionIndex, |
| 67 | size_t* pDataSize, |
| 68 | void* pData) |
| 69 | { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 70 | /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */ |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 71 | uint32_t *count; |
| 72 | |
| 73 | if (pDataSize == NULL) |
| 74 | return VK_ERROR_INVALID_POINTER; |
| 75 | |
| 76 | switch (infoType) { |
| 77 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 78 | *pDataSize = sizeof(uint32_t); |
| 79 | if (pData == NULL) |
| 80 | return VK_SUCCESS; |
| 81 | count = (uint32_t *) pData; |
| 82 | *count = BASIC_LAYER_EXT_ARRAY_SIZE; |
| 83 | break; |
| 84 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 85 | *pDataSize = sizeof(VkExtensionProperties); |
| 86 | if (pData == NULL) |
| 87 | return VK_SUCCESS; |
| 88 | if (extensionIndex >= BASIC_LAYER_EXT_ARRAY_SIZE) |
| 89 | return VK_ERROR_INVALID_VALUE; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 90 | memcpy((VkExtensionProperties *) pData, &basicExts[extensionIndex], sizeof(VkExtensionProperties)); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 91 | break; |
| 92 | default: |
| 93 | return VK_ERROR_INVALID_VALUE; |
| 94 | }; |
| 95 | |
| 96 | return VK_SUCCESS; |
| 97 | } |
| 98 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 99 | VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices( |
| 100 | VkInstance instance, |
| 101 | uint32_t* pPhysicalDeviceCount, |
| 102 | VkPhysicalDevice* pPhysicalDevices) |
| 103 | { |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 104 | 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] | 105 | VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 106 | printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount); |
| 107 | return result; |
| 108 | } |
| 109 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 110 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 111 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 112 | printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 113 | VkResult result = instance_dispatch_table(gpu)->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 114 | 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] | 115 | return result; |
| 116 | } |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 117 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 118 | /* hook DestroyDevice to remove tableMap entry */ |
| 119 | VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) |
| 120 | { |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 121 | dispatch_key key = get_dispatch_key(device); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 122 | VkResult res = device_dispatch_table(device)->DestroyDevice(device); |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 123 | destroy_device_dispatch_table(key); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 124 | return res; |
| 125 | } |
| 126 | |
| 127 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 128 | VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance) |
| 129 | { |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 130 | dispatch_key key = get_dispatch_key(instance); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 131 | VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance); |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 132 | destroy_instance_dispatch_table(key); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 133 | return res; |
| 134 | } |
| 135 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 136 | VK_LAYER_EXPORT VkResult VKAPI vkGetFormatInfo(VkDevice device, VkFormat format, VkFormatInfoType infoType, size_t* pDataSize, void* pData) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 137 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 138 | printf("At start of wrapped vkGetFormatInfo() call w/ device: %p\n", (void*)device); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 139 | VkResult result = device_dispatch_table(device)->GetFormatInfo(device, format, infoType, pDataSize, pData); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 140 | printf("Completed wrapped vkGetFormatInfo() call w/ device: %p\n", (void*)device); |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 141 | return result; |
| 142 | } |
| 143 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 144 | VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 145 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 146 | if (device == NULL) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 147 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 148 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 149 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 150 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 151 | initDeviceTable((const VkBaseLayerObject *) device); |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 152 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 153 | } |
| 154 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 155 | if (!strcmp("vkGetFormatInfo", pName)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 156 | return (void *) vkGetFormatInfo; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 157 | if (!strcmp("vkDestroyDevice", pName)) |
| 158 | return (void *) vkDestroyDevice; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 159 | if (!strcmp("vkLayerExtension1", pName)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 160 | return (void *) vkLayerExtension1; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 161 | else |
| 162 | { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 163 | if (device_dispatch_table(device)->GetDeviceProcAddr == NULL) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 164 | return NULL; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 165 | return device_dispatch_table(device)->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName) |
| 170 | { |
| 171 | if (instance == NULL) |
| 172 | return NULL; |
| 173 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 174 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 175 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 176 | initInstanceTable((const VkBaseLayerObject *) instance); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 177 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 178 | } |
| 179 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 180 | if (!strcmp("vkDestroyInstance", pName)) |
| 181 | return (void *) vkDestroyInstance; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 182 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
| 183 | return (void*) vkEnumeratePhysicalDevices; |
| 184 | if (!strcmp("vkGetGlobalExtensionInfo", pName)) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 185 | return (void*) vkGetGlobalExtensionInfo; |
| 186 | if (!strcmp("vkCreateDevice", pName)) |
| 187 | return (void *) vkCreateDevice; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 188 | else |
| 189 | { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 190 | if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 191 | return NULL; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 192 | return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName); |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 193 | } |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 194 | |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 195 | } |