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> |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame^] | 27 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vk_dispatch_table_helper.h" |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 29 | #include "vk_layer.h" |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 30 | #include "vk_layer_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: |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame^] | 33 | #include "vk_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 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 64 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 65 | uint32_t extensionIndex, |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 66 | VkExtensionProperties* pData) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 67 | { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 68 | /* 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] | 69 | uint32_t *count; |
| 70 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 71 | if (extensionIndex >= BASIC_LAYER_EXT_ARRAY_SIZE) |
| 72 | return VK_ERROR_INVALID_VALUE; |
| 73 | memcpy((VkExtensionProperties *) pData, &basicExts[extensionIndex], sizeof(VkExtensionProperties)); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 74 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 75 | return VK_SUCCESS; |
| 76 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 77 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 78 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionCount(uint32_t* pCount) |
| 79 | { |
| 80 | *pCount = BASIC_LAYER_EXT_ARRAY_SIZE; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 81 | return VK_SUCCESS; |
| 82 | } |
| 83 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 84 | VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices( |
| 85 | VkInstance instance, |
| 86 | uint32_t* pPhysicalDeviceCount, |
| 87 | VkPhysicalDevice* pPhysicalDevices) |
| 88 | { |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 89 | 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] | 90 | VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 91 | printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount); |
| 92 | return result; |
| 93 | } |
| 94 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 95 | 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] | 96 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 97 | printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu); |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 98 | VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 99 | 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] | 100 | return result; |
| 101 | } |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 102 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 103 | /* hook DestroyDevice to remove tableMap entry */ |
| 104 | VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) |
| 105 | { |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 106 | dispatch_key key = get_dispatch_key(device); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 107 | VkResult res = device_dispatch_table(device)->DestroyDevice(device); |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 108 | destroy_device_dispatch_table(key); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 109 | return res; |
| 110 | } |
| 111 | |
| 112 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
| 113 | VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance) |
| 114 | { |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 115 | dispatch_key key = get_dispatch_key(instance); |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 116 | VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance); |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 117 | destroy_instance_dispatch_table(key); |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 118 | return res; |
| 119 | } |
| 120 | |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 121 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatInfo(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 122 | { |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 123 | printf("At start of wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu); |
| 124 | VkResult result = instance_dispatch_table(gpu)->GetPhysicalDeviceFormatInfo(gpu, format, pFormatInfo); |
| 125 | printf("Completed wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu); |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 126 | return result; |
| 127 | } |
| 128 | |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 129 | VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName) |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 130 | { |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 131 | if (device == NULL) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 132 | return NULL; |
Chia-I Wu | e9ae388 | 2015-01-05 09:41:27 +0800 | [diff] [blame] | 133 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 134 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 135 | if (!strcmp("vkGetDeviceProcAddr", pName)) { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 136 | initDeviceTable((const VkBaseLayerObject *) device); |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 137 | return (void *) vkGetDeviceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 138 | } |
| 139 | |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 140 | if (!strcmp("vkCreateDevice", pName)) |
| 141 | return (void *) vkCreateDevice; |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 142 | if (!strcmp("vkDestroyDevice", pName)) |
| 143 | return (void *) vkDestroyDevice; |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 144 | if (!strcmp("vkLayerExtension1", pName)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 145 | return (void *) vkLayerExtension1; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 146 | else |
| 147 | { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 148 | if (device_dispatch_table(device)->GetDeviceProcAddr == NULL) |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 149 | return NULL; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 150 | return device_dispatch_table(device)->GetDeviceProcAddr(device, pName); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName) |
| 155 | { |
| 156 | if (instance == NULL) |
| 157 | return NULL; |
| 158 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 159 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 160 | if (!strcmp("vkGetInstanceProcAddr", pName)) { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 161 | initInstanceTable((const VkBaseLayerObject *) instance); |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 162 | return (void *) vkGetInstanceProcAddr; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 163 | } |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 164 | if (!strcmp("vkGetPhysicalDeviceFormatInfo", pName)) |
| 165 | return (void *) vkGetPhysicalDeviceFormatInfo; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 166 | |
Jon Ashburn | 17f3737 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 167 | if (!strcmp("vkDestroyInstance", pName)) |
| 168 | return (void *) vkDestroyInstance; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 169 | if (!strcmp("vkEnumeratePhysicalDevices", pName)) |
| 170 | return (void*) vkEnumeratePhysicalDevices; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 171 | if (!strcmp("vkGetGlobalExtensionCount", pName)) |
| 172 | return (void*) vkGetGlobalExtensionCount; |
| 173 | if (!strcmp("vkGetGlobalExtensionProperties", pName)) |
| 174 | return (void*) vkGetGlobalExtensionProperties; |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 175 | else |
| 176 | { |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 177 | if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 178 | return NULL; |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 179 | return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName); |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 180 | } |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 181 | |
Jon Ashburn | 227a942 | 2014-11-26 11:10:26 -0700 | [diff] [blame] | 182 | } |