Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan |
| 3 | * |
| 4 | * Copyright (C) 2015 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 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <unordered_map> |
| 29 | #include <memory> |
| 30 | |
| 31 | #include "vk_loader_platform.h" |
| 32 | #include "vk_dispatch_table_helper.h" |
| 33 | #include "vk_struct_string_helper_cpp.h" |
| 34 | #if defined(__GNUC__) |
| 35 | #pragma GCC diagnostic ignored "-Wwrite-strings" |
| 36 | #endif |
| 37 | #if defined(__GNUC__) |
| 38 | #pragma GCC diagnostic warning "-Wwrite-strings" |
| 39 | #endif |
| 40 | #include "vk_struct_size_helper.h" |
| 41 | #include "device_limits.h" |
| 42 | #include "vk_layer_config.h" |
| 43 | #include "vk_debug_marker_layer.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 44 | #include "vk_layer_table.h" |
| 45 | #include "vk_layer_debug_marker_table.h" |
| 46 | #include "vk_layer_data.h" |
| 47 | #include "vk_layer_logging.h" |
| 48 | #include "vk_layer_extension_utils.h" |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 49 | #include "vk_layer_utils.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 50 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 51 | struct devExts { |
| 52 | bool debug_marker_enabled; |
| 53 | }; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 54 | |
| 55 | // This struct will be stored in a map hashed by the dispatchable object |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 56 | struct layer_data { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 57 | debug_report_data *report_data; |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 58 | std::vector<VkDbgMsgCallback> logging_callback; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 59 | VkLayerDispatchTable* device_dispatch_table; |
| 60 | VkLayerInstanceDispatchTable* instance_dispatch_table; |
| 61 | devExts device_extensions; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 62 | // Track state of each instance |
| 63 | unique_ptr<INSTANCE_STATE> instanceState; |
| 64 | unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState; |
| 65 | VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures; |
| 66 | VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures; |
Tony Barbour | 1088c40 | 2015-10-09 11:50:32 -0600 | [diff] [blame] | 67 | VkPhysicalDeviceProperties physicalDeviceProperties; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 68 | // Track physical device per logical device |
| 69 | VkPhysicalDevice physicalDevice; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 70 | // Vector indices correspond to queueFamilyIndex |
| 71 | vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 72 | |
| 73 | layer_data() : |
| 74 | report_data(nullptr), |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 75 | device_dispatch_table(nullptr), |
| 76 | instance_dispatch_table(nullptr), |
| 77 | device_extensions(), |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 78 | instanceState(nullptr), |
| 79 | physicalDeviceState(nullptr), |
Tony Barbour | 1088c40 | 2015-10-09 11:50:32 -0600 | [diff] [blame] | 80 | physicalDeviceProperties(), |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 81 | actualPhysicalDeviceFeatures(), |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 82 | requestedPhysicalDeviceFeatures(), |
| 83 | physicalDevice() |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 84 | {}; |
| 85 | }; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 86 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 87 | static unordered_map<void *, layer_data *> layer_data_map; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 88 | |
| 89 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce); |
| 90 | |
| 91 | // TODO : This can be much smarter, using separate locks for separate global data |
| 92 | static int globalLockInitialized = 0; |
| 93 | static loader_platform_thread_mutex globalLock; |
| 94 | |
| 95 | template layer_data *get_my_data_ptr<layer_data>( |
| 96 | void *data_key, |
| 97 | std::unordered_map<void *, layer_data *> &data_map); |
| 98 | |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 99 | static void init_device_limits(layer_data *my_data) |
| 100 | { |
| 101 | uint32_t report_flags = 0; |
| 102 | uint32_t debug_action = 0; |
| 103 | FILE *log_output = NULL; |
| 104 | const char *option_str; |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 105 | VkDbgMsgCallback callback; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 106 | // initialize DeviceLimits options |
| 107 | report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0); |
| 108 | getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action); |
| 109 | |
| 110 | if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
| 111 | { |
| 112 | option_str = getLayerOption("DeviceLimitsLogFilename"); |
Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 113 | log_output = getLayerLogOutput(option_str, "DeviceLimits"); |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 114 | layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &callback); |
| 115 | my_data->logging_callback.push_back(callback); |
| 116 | } |
| 117 | |
| 118 | if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) { |
| 119 | layer_create_msg_callback(my_data->report_data, report_flags, win32_debug_output_msg, NULL, &callback); |
| 120 | my_data->logging_callback.push_back(callback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | if (!globalLockInitialized) |
| 124 | { |
| 125 | // TODO/TBD: Need to delete this mutex sometime. How??? One |
| 126 | // suggestion is to call this during vkCreateInstance(), and then we |
| 127 | // can clean it up during vkDestroyInstance(). However, that requires |
| 128 | // that the layer have per-instance locks. We need to come back and |
| 129 | // address this soon. |
| 130 | loader_platform_thread_create_mutex(&globalLock); |
| 131 | globalLockInitialized = 1; |
| 132 | } |
| 133 | } |
Tobin Ehlis | fd3843f | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 134 | /* DeviceLimits does not have any global extensions */ |
| 135 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties( |
| 136 | const char *pLayerName, |
| 137 | uint32_t *pCount, |
| 138 | VkExtensionProperties* pProperties) |
| 139 | { |
| 140 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 141 | } |
| 142 | |
| 143 | static const VkLayerProperties dl_global_layers[] = { |
| 144 | { |
| 145 | "DeviceLimits", |
| 146 | VK_API_VERSION, |
| 147 | VK_MAKE_VERSION(0, 1, 0), |
| 148 | "Validation layer: Device Limits", |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties( |
| 153 | uint32_t *pCount, |
| 154 | VkLayerProperties* pProperties) |
| 155 | { |
| 156 | return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers), |
| 157 | dl_global_layers, |
| 158 | pCount, pProperties); |
| 159 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 160 | |
| 161 | VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance) |
| 162 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 163 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 164 | VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 165 | VkResult result = pTable->CreateInstance(pCreateInfo, pInstance); |
| 166 | |
| 167 | if (result == VK_SUCCESS) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 168 | my_data->report_data = debug_report_create_instance( |
| 169 | pTable, |
| 170 | *pInstance, |
| 171 | pCreateInfo->extensionCount, |
| 172 | pCreateInfo->ppEnabledExtensionNames); |
| 173 | |
| 174 | init_device_limits(my_data); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 175 | my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE()); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 176 | } |
| 177 | return result; |
| 178 | } |
| 179 | |
| 180 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 181 | VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 182 | { |
| 183 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 184 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 185 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 186 | pTable->DestroyInstance(instance); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 187 | |
| 188 | // Clean up logging callback, if any |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 189 | while (my_data->logging_callback.size() > 0) { |
| 190 | VkDbgMsgCallback callback = my_data->logging_callback.back(); |
| 191 | layer_destroy_msg_callback(my_data->report_data, callback); |
| 192 | my_data->logging_callback.pop_back(); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | layer_debug_report_destroy_instance(my_data->report_data); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 196 | delete my_data->instance_dispatch_table; |
| 197 | layer_data_map.erase(key); |
Tobin Ehlis | 0b63233 | 2015-10-07 09:38:40 -0600 | [diff] [blame] | 198 | if (layer_data_map.empty()) { |
| 199 | // Release mutex when destroying last instance. |
| 200 | loader_platform_thread_delete_mutex(&globalLock); |
| 201 | globalLockInitialized = 0; |
| 202 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) |
| 206 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 207 | VkBool32 skipCall = VK_FALSE; |
| 208 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 209 | if (my_data->instanceState) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 210 | // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS |
| 211 | if (NULL == pPhysicalDevices) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 212 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 213 | } else { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 214 | if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 215 | // Flag error here, shouldn't be calling this without having queried count |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 216 | skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL", |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 217 | "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount."); |
| 218 | } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 219 | else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) { |
| 220 | skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL", |
| 221 | "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count supported by this instance is %u.", *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 222 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 223 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 224 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 225 | if (skipCall) |
| 226 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 227 | VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 228 | if (NULL == pPhysicalDevices) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 229 | my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 230 | } else { // Save physical devices |
| 231 | for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 232 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map); |
| 233 | phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE()); |
| 234 | // Init actual features for each physical device |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 235 | my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures)); |
Tony Barbour | 1088c40 | 2015-10-09 11:50:32 -0600 | [diff] [blame] | 236 | my_data->instance_dispatch_table->GetPhysicalDeviceProperties(pPhysicalDevices[i], &(phy_dev_data->physicalDeviceProperties)); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | return result; |
| 240 | } else { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 241 | log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL", |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 242 | "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance); |
| 243 | } |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 244 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 245 | } |
| 246 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 247 | VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 248 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 249 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 250 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 251 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 252 | } |
| 253 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 254 | VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 255 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 256 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties( |
| 257 | physicalDevice, format, pFormatProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 258 | } |
| 259 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 260 | VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 261 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 262 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 263 | } |
| 264 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 265 | VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 266 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 267 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 268 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 269 | } |
| 270 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 271 | VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 272 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 273 | VkBool32 skipCall = VK_FALSE; |
| 274 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 275 | if (phy_dev_data->physicalDeviceState) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 276 | if (NULL == pQueueFamilyProperties) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 277 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 278 | } else { |
| 279 | // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 280 | if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 281 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL", |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 282 | "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount."); |
| 283 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 284 | // Then verify that pCount that is passed in on second call matches what was returned |
| 285 | if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) { |
| 286 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL", |
| 287 | "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 288 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 289 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 290 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 291 | if (skipCall) |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 292 | return; |
| 293 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 294 | if (NULL == pQueueFamilyProperties) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 295 | phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 296 | } else { // Save queue family properties |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 297 | phy_dev_data->queueFamilyProperties.reserve(*pCount); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 298 | for (uint32_t i=0; i < *pCount; i++) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 299 | phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i])); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 300 | } |
| 301 | } |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 302 | return; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 303 | } else { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 304 | log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL", |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 305 | "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice); |
| 306 | } |
| 307 | } |
| 308 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 309 | VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 310 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 311 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 312 | } |
| 313 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 314 | VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 315 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 316 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 317 | } |
| 318 | |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 319 | VK_LAYER_EXPORT void VKAPI vkCmdSetViewport( |
| 320 | VkCmdBuffer cmdBuffer, |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 321 | uint32_t viewportCount, |
| 322 | const VkViewport* pViewports) |
| 323 | { |
| 324 | VkBool32 skipCall = VK_FALSE; |
| 325 | /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */ |
| 326 | if (VK_FALSE == skipCall) { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 327 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 328 | my_data->device_dispatch_table->CmdSetViewport(cmdBuffer, viewportCount, pViewports); |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | VK_LAYER_EXPORT void VKAPI vkCmdSetScissor( |
| 333 | VkCmdBuffer cmdBuffer, |
| 334 | uint32_t scissorCount, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 335 | const VkRect2D* pScissors) |
| 336 | { |
| 337 | VkBool32 skipCall = VK_FALSE; |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 338 | /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */ |
| 339 | /* TODO: viewportCount and scissorCount must match at draw time */ |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 340 | if (VK_FALSE == skipCall) { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 341 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 342 | my_data->device_dispatch_table->CmdSetScissor(cmdBuffer, scissorCount, pScissors); |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 346 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 347 | { |
| 348 | uint32_t i; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 349 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 350 | my_data->device_extensions.debug_marker_enabled = false; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 351 | |
| 352 | for (i = 0; i < pCreateInfo->extensionCount; i++) { |
| 353 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) { |
| 354 | /* Found a matching extension name, mark it enabled and init dispatch table*/ |
| 355 | initDebugMarkerTable(device); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 356 | my_data->device_extensions.debug_marker_enabled = true; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | } |
| 360 | } |
| 361 | |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 362 | // Verify that features have been queried and verify that requested features are available |
| 363 | static VkBool32 validate_features_request(layer_data *phy_dev_data) |
| 364 | { |
| 365 | VkBool32 skipCall = VK_FALSE; |
| 366 | // Verify that all of the requested features are available |
| 367 | // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid |
| 368 | VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures); |
| 369 | VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures); |
| 370 | // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues |
| 371 | // Need to provide the struct member name with the issue. To do that seems like we'll |
| 372 | // have to loop through each struct member which should be done w/ codegen to keep in synch. |
| 373 | uint32_t errors = 0; |
| 374 | uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32); |
| 375 | for (uint32_t i = 0; i < totalBools; i++) { |
| 376 | if (requested[i] > actual[i]) { |
| 377 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL", |
| 378 | "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i); |
| 379 | errors++; |
| 380 | } |
| 381 | } |
| 382 | if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) { |
| 383 | // If user didn't request features, notify them that they should |
| 384 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL", |
| 385 | "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures()."); |
| 386 | } |
Tobin Ehlis | 72b27cc | 2015-09-29 11:22:37 -0600 | [diff] [blame] | 387 | return skipCall; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 388 | } |
| 389 | |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 390 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) |
| 391 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 392 | VkBool32 skipCall = VK_FALSE; |
| 393 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 394 | // First check is app has actually requested queueFamilyProperties |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 395 | if (!phy_dev_data->physicalDeviceState) { |
| 396 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL", |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 397 | "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices()."); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 398 | } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 399 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 400 | "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties()."); |
| 401 | } else { |
| 402 | // Check that the requested queue properties are valid |
Courtney Goeltzenleuchter | 7831e96 | 2015-10-15 16:58:44 -0600 | [diff] [blame] | 403 | for (uint32_t i=0; i<pCreateInfo->requestedQueueCount; i++) { |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 404 | uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 405 | if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device |
| 406 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 407 | "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 408 | } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) { |
| 409 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
| 410 | "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but requested queueCount is %u.", requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount, pCreateInfo->pRequestedQueues[i].queueCount); |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 411 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 412 | } |
| 413 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 414 | // Check that any requested features are available |
| 415 | if (pCreateInfo->pEnabledFeatures) { |
| 416 | phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures); |
| 417 | skipCall |= validate_features_request(phy_dev_data); |
| 418 | } |
| 419 | if (skipCall) |
| 420 | return VK_ERROR_VALIDATION_FAILED; |
| 421 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 422 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 423 | VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pDevice); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 424 | if (result == VK_SUCCESS) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 425 | my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 426 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 427 | my_device_data->physicalDevice = gpu; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 428 | } |
| 429 | return result; |
| 430 | } |
| 431 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 432 | VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 433 | { |
| 434 | // Free device lifetime allocations |
| 435 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 436 | layer_data *my_device_data = get_my_data_ptr(key, layer_data_map); |
| 437 | my_device_data->device_dispatch_table->DestroyDevice(device); |
| 438 | tableDebugMarkerMap.erase(key); |
| 439 | delete my_device_data->device_dispatch_table; |
| 440 | layer_data_map.erase(key); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 441 | } |
| 442 | |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 443 | VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 444 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 445 | // TODO : Verify that requested QueueFamilyIndex for this pool exists |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 446 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pCmdPool); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 447 | return result; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 448 | } |
| 449 | |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 450 | VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 451 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 452 | get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, cmdPool); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 453 | } |
| 454 | |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 455 | VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 456 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 457 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->ResetCommandPool(device, cmdPool, flags); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 458 | return result; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 459 | } |
| 460 | |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame^] | 461 | VK_LAYER_EXPORT VkResult VKAPI vkAllocCommandBuffers(VkDevice device, const VkCmdBufferAllocInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 462 | { |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame^] | 463 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->AllocCommandBuffers(device, pCreateInfo, pCmdBuffer); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 464 | return result; |
| 465 | } |
Mark Lobodzinski | fbb130e | 2015-10-06 11:59:54 -0600 | [diff] [blame] | 466 | |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame^] | 467 | VK_LAYER_EXPORT void VKAPI vkFreeCommandBuffers(VkDevice device, VkCmdPool cmdPool, uint32_t count, const VkCmdBuffer* pCommandBuffers) |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 468 | { |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame^] | 469 | get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->FreeCommandBuffers(device, cmdPool, count, pCommandBuffers); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 470 | } |
| 471 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 472 | VK_LAYER_EXPORT void VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 473 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 474 | VkBool32 skipCall = VK_FALSE; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 475 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 476 | VkPhysicalDevice gpu = dev_data->physicalDevice; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 477 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
| 478 | if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device |
| 479 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 480 | "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 481 | } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) { |
| 482 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
| 483 | "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 484 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 485 | if (skipCall) |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 486 | return; |
| 487 | dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 488 | } |
| 489 | |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 490 | VK_LAYER_EXPORT VkResult VKAPI vkCreateImage( |
| 491 | VkDevice device, |
| 492 | const VkImageCreateInfo *pCreateInfo, |
| 493 | VkImage *pImage) |
| 494 | { |
| 495 | VkBool32 skipCall = VK_FALSE; |
| 496 | VkResult result = VK_ERROR_VALIDATION_FAILED; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 497 | VkImageFormatProperties ImageFormatProperties = {0}; |
| 498 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 499 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 500 | VkPhysicalDevice physicalDevice = dev_data->physicalDevice; |
| 501 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 502 | // Internal call to get format info. Still goes through layers, could potentially go directly to ICD. |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 503 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties( |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 504 | physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, |
| 505 | pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties); |
Mark Lobodzinski | fbb130e | 2015-10-06 11:59:54 -0600 | [diff] [blame] | 506 | |
Tony Barbour | 1088c40 | 2015-10-09 11:50:32 -0600 | [diff] [blame] | 507 | VkDeviceSize imageGranularity = phy_dev_data->physicalDeviceProperties.limits.bufferImageGranularity; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 508 | imageGranularity = imageGranularity == 1 ? 0 : imageGranularity; |
| 509 | |
| 510 | if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) || |
| 511 | (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) || |
| 512 | (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) { |
Mark Lobodzinski | fbb130e | 2015-10-06 11:59:54 -0600 | [diff] [blame] | 513 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0, |
| 514 | DEVLIMITS_LIMITS_VIOLATION, "DL", |
| 515 | "CreateImage extents exceed allowable limits for format: " |
| 516 | "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.", |
| 517 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
| 518 | ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth, |
| 519 | string_VkFormat(pCreateInfo->format)); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 520 | |
| 521 | } |
| 522 | |
| 523 | uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * |
| 524 | (uint64_t)pCreateInfo->extent.height * |
| 525 | (uint64_t)pCreateInfo->extent.depth * |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 526 | (uint64_t)pCreateInfo->arrayLayers * |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 527 | (uint64_t)pCreateInfo->samples * |
| 528 | (uint64_t)vk_format_get_size(pCreateInfo->format) + |
| 529 | (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity; |
| 530 | |
| 531 | if (totalSize > ImageFormatProperties.maxResourceSize) { |
Mark Lobodzinski | fbb130e | 2015-10-06 11:59:54 -0600 | [diff] [blame] | 532 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0, |
| 533 | DEVLIMITS_LIMITS_VIOLATION, "DL", |
| 534 | "CreateImage resource size exceeds allowable maximum " |
| 535 | "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ", |
| 536 | totalSize, ImageFormatProperties.maxResourceSize); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 537 | } |
| 538 | if (VK_FALSE == skipCall) { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 539 | result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pImage); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 540 | } |
| 541 | return result; |
| 542 | } |
| 543 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 544 | VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer( |
| 545 | VkCmdBuffer cmdBuffer, |
| 546 | VkBuffer destBuffer, |
| 547 | VkDeviceSize destOffset, |
| 548 | VkDeviceSize dataSize, |
| 549 | const uint32_t* pData) |
| 550 | { |
| 551 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 552 | |
| 553 | // destOffset is the byte offset into the buffer to start updating and must be a multiple of 4. |
| 554 | if (destOffset & 3) { |
| 555 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 556 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL", |
| 557 | "vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) { |
| 558 | return; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // dataSize is the number of bytes to update, which must be a multiple of 4. |
| 563 | if (dataSize & 3) { |
| 564 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 565 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL", |
| 566 | "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) { |
| 567 | return; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | dev_data->device_dispatch_table->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData); |
| 572 | } |
| 573 | |
| 574 | VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer( |
| 575 | VkCmdBuffer cmdBuffer, |
| 576 | VkBuffer destBuffer, |
| 577 | VkDeviceSize destOffset, |
| 578 | VkDeviceSize fillSize, |
| 579 | uint32_t data) |
| 580 | { |
| 581 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 582 | |
| 583 | // destOffset is the byte offset into the buffer to start filling and must be a multiple of 4. |
| 584 | if (destOffset & 3) { |
| 585 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 586 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL", |
| 587 | "vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) { |
| 588 | return; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | // fillSize is the number of bytes to fill, which must be a multiple of 4. |
| 593 | if (fillSize & 3) { |
| 594 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map); |
| 595 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL", |
| 596 | "vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4")) { |
| 597 | return; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | dev_data->device_dispatch_table->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data); |
| 602 | } |
| 603 | |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 604 | VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback( |
| 605 | VkInstance instance, |
| 606 | VkFlags msgFlags, |
| 607 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
| 608 | void* pUserData, |
| 609 | VkDbgMsgCallback* pMsgCallback) |
| 610 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 611 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 612 | VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 613 | if (VK_SUCCESS == res) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 614 | res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 615 | } |
| 616 | return res; |
| 617 | } |
| 618 | |
| 619 | VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback( |
| 620 | VkInstance instance, |
| 621 | VkDbgMsgCallback msgCallback) |
| 622 | { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 623 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 624 | VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 625 | layer_destroy_msg_callback(my_data->report_data, msgCallback); |
| 626 | return res; |
| 627 | } |
| 628 | |
| 629 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName) |
| 630 | { |
| 631 | if (dev == NULL) |
| 632 | return NULL; |
| 633 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 634 | layer_data *my_data; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 635 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 636 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 637 | VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev; |
| 638 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map); |
| 639 | my_data->device_dispatch_table = new VkLayerDispatchTable; |
| 640 | layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 641 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
| 642 | } |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 643 | my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 644 | if (!strcmp(funcName, "vkCreateDevice")) |
| 645 | return (PFN_vkVoidFunction) vkCreateDevice; |
| 646 | if (!strcmp(funcName, "vkDestroyDevice")) |
| 647 | return (PFN_vkVoidFunction) vkDestroyDevice; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 648 | if (!strcmp(funcName, "vkGetDeviceQueue")) |
| 649 | return (PFN_vkVoidFunction) vkGetDeviceQueue; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 650 | if (!strcmp(funcName, "vkCreateImage")) |
| 651 | return (PFN_vkVoidFunction) vkCreateImage; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 652 | if (!strcmp(funcName, "CreateCommandPool")) |
| 653 | return (PFN_vkVoidFunction) vkCreateCommandPool; |
| 654 | if (!strcmp(funcName, "DestroyCommandPool")) |
| 655 | return (PFN_vkVoidFunction) vkDestroyCommandPool; |
| 656 | if (!strcmp(funcName, "ResetCommandPool")) |
| 657 | return (PFN_vkVoidFunction) vkResetCommandPool; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame^] | 658 | if (!strcmp(funcName, "vkAllocCommandBuffers")) |
| 659 | return (PFN_vkVoidFunction) vkAllocCommandBuffers; |
| 660 | if (!strcmp(funcName, "vkFreeCommandBuffers")) |
| 661 | return (PFN_vkVoidFunction) vkFreeCommandBuffers; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 662 | if (!strcmp(funcName, "vkCmdUpdateBuffer")) |
| 663 | return (PFN_vkVoidFunction) vkCmdUpdateBuffer; |
| 664 | if (!strcmp(funcName, "vkCmdFillBuffer")) |
| 665 | return (PFN_vkVoidFunction) vkCmdFillBuffer; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 666 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 667 | VkLayerDispatchTable* pTable = my_data->device_dispatch_table; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 668 | { |
| 669 | if (pTable->GetDeviceProcAddr == NULL) |
| 670 | return NULL; |
| 671 | return pTable->GetDeviceProcAddr(dev, funcName); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
| 676 | { |
| 677 | PFN_vkVoidFunction fptr; |
| 678 | if (instance == NULL) |
| 679 | return NULL; |
| 680 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 681 | layer_data *my_data; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 682 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 683 | if (!strcmp(funcName, "vkGetInstanceProcAddr")) { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 684 | VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance; |
| 685 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map); |
| 686 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 687 | layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 688 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
| 689 | } |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 690 | my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 691 | if (!strcmp(funcName, "vkCreateInstance")) |
| 692 | return (PFN_vkVoidFunction) vkCreateInstance; |
| 693 | if (!strcmp(funcName, "vkDestroyInstance")) |
| 694 | return (PFN_vkVoidFunction) vkDestroyInstance; |
| 695 | if (!strcmp(funcName, "vkEnumeratePhysicalDevices")) |
| 696 | return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices; |
| 697 | if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures")) |
| 698 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures; |
| 699 | if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties")) |
| 700 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties; |
| 701 | if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties")) |
| 702 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties; |
| 703 | if (!strcmp(funcName, "vkGetPhysicalDeviceProperties")) |
| 704 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties; |
| 705 | if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties")) |
| 706 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties; |
| 707 | if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties")) |
| 708 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 709 | if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties")) |
| 710 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties; |
Tobin Ehlis | fd3843f | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 711 | if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties")) |
| 712 | return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties; |
| 713 | if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties")) |
| 714 | return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 715 | |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 716 | fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 717 | if (fptr) |
| 718 | return fptr; |
| 719 | |
| 720 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 721 | VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 722 | if (pTable->GetInstanceProcAddr == NULL) |
| 723 | return NULL; |
| 724 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 725 | } |
| 726 | } |