Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 1 | /* |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 22 | * |
| 23 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 24 | * Author: Mike Stroyan <mike@LunarG.com> |
| 25 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | #include <unordered_map> |
| 32 | #include <memory> |
| 33 | |
| 34 | #include "vk_loader_platform.h" |
| 35 | #include "vk_dispatch_table_helper.h" |
| 36 | #include "vk_struct_string_helper_cpp.h" |
| 37 | #if defined(__GNUC__) |
| 38 | #pragma GCC diagnostic ignored "-Wwrite-strings" |
| 39 | #endif |
| 40 | #if defined(__GNUC__) |
| 41 | #pragma GCC diagnostic warning "-Wwrite-strings" |
| 42 | #endif |
| 43 | #include "vk_struct_size_helper.h" |
| 44 | #include "device_limits.h" |
| 45 | #include "vk_layer_config.h" |
| 46 | #include "vk_debug_marker_layer.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 47 | #include "vk_layer_table.h" |
| 48 | #include "vk_layer_debug_marker_table.h" |
| 49 | #include "vk_layer_data.h" |
| 50 | #include "vk_layer_logging.h" |
| 51 | #include "vk_layer_extension_utils.h" |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 52 | #include "vk_layer_utils.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 53 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 54 | struct devExts { |
| 55 | bool debug_marker_enabled; |
| 56 | }; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 57 | |
| 58 | // 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] | 59 | struct layer_data { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 60 | debug_report_data *report_data; |
Courtney Goeltzenleuchter | 107a0d2 | 2015-11-25 14:07:05 -0700 | [diff] [blame] | 61 | std::vector<VkDebugReportCallbackLUNARG> logging_callback; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 62 | VkLayerDispatchTable* device_dispatch_table; |
| 63 | VkLayerInstanceDispatchTable* instance_dispatch_table; |
| 64 | devExts device_extensions; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 65 | // Track state of each instance |
| 66 | unique_ptr<INSTANCE_STATE> instanceState; |
| 67 | unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState; |
| 68 | VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures; |
| 69 | VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures; |
Tony Barbour | 1088c40 | 2015-10-09 11:50:32 -0600 | [diff] [blame] | 70 | VkPhysicalDeviceProperties physicalDeviceProperties; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 71 | // Track physical device per logical device |
| 72 | VkPhysicalDevice physicalDevice; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 73 | // Vector indices correspond to queueFamilyIndex |
| 74 | vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 75 | |
| 76 | layer_data() : |
| 77 | report_data(nullptr), |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 78 | device_dispatch_table(nullptr), |
| 79 | instance_dispatch_table(nullptr), |
| 80 | device_extensions(), |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 81 | instanceState(nullptr), |
| 82 | physicalDeviceState(nullptr), |
Tony Barbour | 1088c40 | 2015-10-09 11:50:32 -0600 | [diff] [blame] | 83 | physicalDeviceProperties(), |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 84 | actualPhysicalDeviceFeatures(), |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 85 | requestedPhysicalDeviceFeatures(), |
| 86 | physicalDevice() |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 87 | {}; |
| 88 | }; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 89 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 90 | static unordered_map<void *, layer_data *> layer_data_map; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 91 | |
| 92 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce); |
| 93 | |
| 94 | // TODO : This can be much smarter, using separate locks for separate global data |
| 95 | static int globalLockInitialized = 0; |
| 96 | static loader_platform_thread_mutex globalLock; |
| 97 | |
| 98 | template layer_data *get_my_data_ptr<layer_data>( |
| 99 | void *data_key, |
| 100 | std::unordered_map<void *, layer_data *> &data_map); |
| 101 | |
Courtney Goeltzenleuchter | 6d8e818 | 2015-11-25 14:31:49 -0700 | [diff] [blame] | 102 | static void init_device_limits(layer_data *my_data, const VkAllocationCallbacks *pAllocator) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 103 | { |
| 104 | uint32_t report_flags = 0; |
| 105 | uint32_t debug_action = 0; |
| 106 | FILE *log_output = NULL; |
| 107 | const char *option_str; |
Courtney Goeltzenleuchter | 107a0d2 | 2015-11-25 14:07:05 -0700 | [diff] [blame] | 108 | VkDebugReportCallbackLUNARG callback; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 109 | // initialize DeviceLimits options |
| 110 | report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0); |
| 111 | getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action); |
| 112 | |
| 113 | if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
| 114 | { |
| 115 | option_str = getLayerOption("DeviceLimitsLogFilename"); |
Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 116 | log_output = getLayerLogOutput(option_str, "DeviceLimits"); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 117 | VkDebugReportCallbackCreateInfoLUNARG dbgCreateInfo; |
| 118 | memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo)); |
| 119 | dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_LUNARG; |
| 120 | dbgCreateInfo.flags = report_flags; |
| 121 | dbgCreateInfo.pfnCallback = log_callback; |
| 122 | dbgCreateInfo.pUserData = (void *) log_output; |
| 123 | layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback); |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 124 | my_data->logging_callback.push_back(callback); |
| 125 | } |
| 126 | |
| 127 | if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) { |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 128 | VkDebugReportCallbackCreateInfoLUNARG dbgCreateInfo; |
| 129 | memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo)); |
| 130 | dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_LUNARG; |
| 131 | dbgCreateInfo.flags = report_flags; |
| 132 | dbgCreateInfo.pfnCallback = win32_debug_output_msg; |
| 133 | dbgCreateInfo.pUserData = NULL; |
| 134 | layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback); |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 135 | my_data->logging_callback.push_back(callback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (!globalLockInitialized) |
| 139 | { |
| 140 | // TODO/TBD: Need to delete this mutex sometime. How??? One |
| 141 | // suggestion is to call this during vkCreateInstance(), and then we |
| 142 | // can clean it up during vkDestroyInstance(). However, that requires |
| 143 | // that the layer have per-instance locks. We need to come back and |
| 144 | // address this soon. |
| 145 | loader_platform_thread_create_mutex(&globalLock); |
| 146 | globalLockInitialized = 1; |
| 147 | } |
| 148 | } |
Tobin Ehlis | fd3843f | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 149 | /* DeviceLimits does not have any global extensions */ |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 150 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties( |
Tobin Ehlis | fd3843f | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 151 | const char *pLayerName, |
| 152 | uint32_t *pCount, |
| 153 | VkExtensionProperties* pProperties) |
| 154 | { |
| 155 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 156 | } |
| 157 | |
| 158 | static const VkLayerProperties dl_global_layers[] = { |
| 159 | { |
| 160 | "DeviceLimits", |
| 161 | VK_API_VERSION, |
| 162 | VK_MAKE_VERSION(0, 1, 0), |
| 163 | "Validation layer: Device Limits", |
| 164 | } |
| 165 | }; |
| 166 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 167 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( |
Tobin Ehlis | fd3843f | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 168 | uint32_t *pCount, |
| 169 | VkLayerProperties* pProperties) |
| 170 | { |
| 171 | return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers), |
| 172 | dl_global_layers, |
| 173 | pCount, pProperties); |
| 174 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 175 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 176 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 177 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 178 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 179 | VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 180 | VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 181 | |
| 182 | if (result == VK_SUCCESS) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 183 | my_data->report_data = debug_report_create_instance( |
| 184 | pTable, |
| 185 | *pInstance, |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 186 | pCreateInfo->enabledExtensionNameCount, |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 187 | pCreateInfo->ppEnabledExtensionNames); |
| 188 | |
Courtney Goeltzenleuchter | 6d8e818 | 2015-11-25 14:31:49 -0700 | [diff] [blame] | 189 | init_device_limits(my_data, pAllocator); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 190 | my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE()); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 191 | } |
| 192 | return result; |
| 193 | } |
| 194 | |
| 195 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 196 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 197 | { |
| 198 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 199 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 200 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 201 | pTable->DestroyInstance(instance, pAllocator); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 202 | |
| 203 | // Clean up logging callback, if any |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 204 | while (my_data->logging_callback.size() > 0) { |
Courtney Goeltzenleuchter | 107a0d2 | 2015-11-25 14:07:05 -0700 | [diff] [blame] | 205 | VkDebugReportCallbackLUNARG callback = my_data->logging_callback.back(); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 206 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 207 | my_data->logging_callback.pop_back(); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | layer_debug_report_destroy_instance(my_data->report_data); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 211 | delete my_data->instance_dispatch_table; |
| 212 | layer_data_map.erase(key); |
Tobin Ehlis | 0b63233 | 2015-10-07 09:38:40 -0600 | [diff] [blame] | 213 | if (layer_data_map.empty()) { |
| 214 | // Release mutex when destroying last instance. |
| 215 | loader_platform_thread_delete_mutex(&globalLock); |
| 216 | globalLockInitialized = 0; |
| 217 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 218 | } |
| 219 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 220 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 221 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 222 | VkBool32 skipCall = VK_FALSE; |
| 223 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 224 | if (my_data->instanceState) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 225 | // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS |
| 226 | if (NULL == pPhysicalDevices) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 227 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 228 | } else { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 229 | if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 230 | // Flag error here, shouldn't be calling this without having queried count |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 231 | skipCall |= log_msg(my_data->report_data, VK_DEBUG_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] | 232 | "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount."); |
| 233 | } // 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] | 234 | else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 235 | skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL", |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 236 | "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] | 237 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 238 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 239 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 240 | if (skipCall) |
| 241 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 242 | VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 243 | if (NULL == pPhysicalDevices) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 244 | my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 245 | } else { // Save physical devices |
| 246 | for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 247 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map); |
| 248 | phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE()); |
| 249 | // Init actual features for each physical device |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 250 | my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures)); |
Tony Barbour | 1088c40 | 2015-10-09 11:50:32 -0600 | [diff] [blame] | 251 | my_data->instance_dispatch_table->GetPhysicalDeviceProperties(pPhysicalDevices[i], &(phy_dev_data->physicalDeviceProperties)); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | return result; |
| 255 | } else { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 256 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 257 | "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", (uint64_t)instance); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 258 | } |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 259 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 260 | } |
| 261 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 262 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 263 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 264 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 265 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 266 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 267 | } |
| 268 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 269 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 270 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 271 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties( |
| 272 | physicalDevice, format, pFormatProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 273 | } |
| 274 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 275 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL 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] | 276 | { |
Chia-I Wu | 1724104 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 277 | return 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] | 278 | } |
| 279 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 280 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 281 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 282 | 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] | 283 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 284 | } |
| 285 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 286 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 287 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 288 | VkBool32 skipCall = VK_FALSE; |
| 289 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 290 | if (phy_dev_data->physicalDeviceState) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 291 | if (NULL == pQueueFamilyProperties) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 292 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 293 | } else { |
| 294 | // 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] | 295 | if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 296 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_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] | 297 | "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount."); |
| 298 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 299 | // Then verify that pCount that is passed in on second call matches what was returned |
| 300 | if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 301 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL", |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 302 | "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] | 303 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 304 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 305 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 306 | if (skipCall) |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 307 | return; |
| 308 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 309 | if (NULL == pQueueFamilyProperties) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 310 | phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 311 | } else { // Save queue family properties |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 312 | phy_dev_data->queueFamilyProperties.reserve(*pCount); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 313 | for (uint32_t i=0; i < *pCount; i++) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 314 | phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i])); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 315 | } |
| 316 | } |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 317 | return; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 318 | } else { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 319 | log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 320 | "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", (uint64_t)physicalDevice); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 324 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 325 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 326 | 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] | 327 | } |
| 328 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 329 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 330 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 331 | 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] | 332 | } |
| 333 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 334 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport( |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 335 | VkCommandBuffer commandBuffer, |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 336 | uint32_t viewportCount, |
| 337 | const VkViewport* pViewports) |
| 338 | { |
| 339 | VkBool32 skipCall = VK_FALSE; |
| 340 | /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */ |
| 341 | if (VK_FALSE == skipCall) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 342 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
| 343 | my_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports); |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 347 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor( |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 348 | VkCommandBuffer commandBuffer, |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 349 | uint32_t scissorCount, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 350 | const VkRect2D* pScissors) |
| 351 | { |
| 352 | VkBool32 skipCall = VK_FALSE; |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 353 | /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */ |
| 354 | /* TODO: viewportCount and scissorCount must match at draw time */ |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 355 | if (VK_FALSE == skipCall) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 356 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
| 357 | my_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors); |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 361 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 362 | { |
| 363 | uint32_t i; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 364 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 365 | my_data->device_extensions.debug_marker_enabled = false; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 366 | |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 367 | for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 368 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) { |
| 369 | /* Found a matching extension name, mark it enabled and init dispatch table*/ |
| 370 | initDebugMarkerTable(device); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 371 | my_data->device_extensions.debug_marker_enabled = true; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | } |
| 375 | } |
| 376 | |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 377 | // Verify that features have been queried and verify that requested features are available |
| 378 | static VkBool32 validate_features_request(layer_data *phy_dev_data) |
| 379 | { |
| 380 | VkBool32 skipCall = VK_FALSE; |
| 381 | // Verify that all of the requested features are available |
| 382 | // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid |
| 383 | VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures); |
| 384 | VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures); |
| 385 | // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues |
| 386 | // Need to provide the struct member name with the issue. To do that seems like we'll |
| 387 | // have to loop through each struct member which should be done w/ codegen to keep in synch. |
| 388 | uint32_t errors = 0; |
| 389 | uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32); |
| 390 | for (uint32_t i = 0; i < totalBools; i++) { |
| 391 | if (requested[i] > actual[i]) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 392 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL", |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 393 | "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i); |
| 394 | errors++; |
| 395 | } |
| 396 | } |
| 397 | if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) { |
| 398 | // If user didn't request features, notify them that they should |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 399 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL", |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 400 | "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures()."); |
| 401 | } |
Tobin Ehlis | 72b27cc | 2015-09-29 11:22:37 -0600 | [diff] [blame] | 402 | return skipCall; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 403 | } |
| 404 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 405 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 406 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 407 | VkBool32 skipCall = VK_FALSE; |
| 408 | 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] | 409 | // First check is app has actually requested queueFamilyProperties |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 410 | if (!phy_dev_data->physicalDeviceState) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 411 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_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] | 412 | "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices()."); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 413 | } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 414 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_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] | 415 | "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties()."); |
| 416 | } else { |
| 417 | // Check that the requested queue properties are valid |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 418 | for (uint32_t i=0; i<pCreateInfo->queueCreateInfoCount; i++) { |
| 419 | uint32_t requestedIndex = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 420 | if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 421 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_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] | 422 | "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex); |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 423 | } else if (pCreateInfo->pQueueCreateInfos[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 424 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 425 | "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->pQueueCreateInfos[i].queueCount); |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 426 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 427 | } |
| 428 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 429 | // Check that any requested features are available |
| 430 | if (pCreateInfo->pEnabledFeatures) { |
| 431 | phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures); |
| 432 | skipCall |= validate_features_request(phy_dev_data); |
| 433 | } |
| 434 | if (skipCall) |
| 435 | return VK_ERROR_VALIDATION_FAILED; |
| 436 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 437 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 438 | VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 439 | if (result == VK_SUCCESS) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 440 | 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] | 441 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 442 | my_device_data->physicalDevice = gpu; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 443 | } |
| 444 | return result; |
| 445 | } |
| 446 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 447 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 448 | { |
| 449 | // Free device lifetime allocations |
| 450 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 451 | layer_data *my_device_data = get_my_data_ptr(key, layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 452 | my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 453 | tableDebugMarkerMap.erase(key); |
| 454 | delete my_device_data->device_dispatch_table; |
| 455 | layer_data_map.erase(key); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 456 | } |
| 457 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 458 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 459 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 460 | // TODO : Verify that requested QueueFamilyIndex for this pool exists |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 461 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 462 | return result; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 463 | } |
| 464 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 465 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 466 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 467 | get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 468 | } |
| 469 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 470 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 471 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 472 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->ResetCommandPool(device, commandPool, flags); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 473 | return result; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 474 | } |
| 475 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 476 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 477 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 478 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 479 | return result; |
| 480 | } |
Mark Lobodzinski | fbb130e | 2015-10-06 11:59:54 -0600 | [diff] [blame] | 481 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 482 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer* pCommandBuffers) |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 483 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 484 | get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 485 | } |
| 486 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 487 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 488 | { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 489 | VkBool32 skipCall = VK_FALSE; |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 490 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 491 | VkPhysicalDevice gpu = dev_data->physicalDevice; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 492 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
| 493 | if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 494 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_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] | 495 | "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 496 | } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) { |
Courtney Goeltzenleuchter | fd4830c | 2015-11-25 10:30:56 -0700 | [diff] [blame] | 497 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 498 | "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] | 499 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 500 | if (skipCall) |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 501 | return; |
| 502 | dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 503 | } |
| 504 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 505 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer( |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 506 | VkCommandBuffer commandBuffer, |
| 507 | VkBuffer dstBuffer, |
| 508 | VkDeviceSize dstOffset, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 509 | VkDeviceSize dataSize, |
| 510 | const uint32_t* pData) |
| 511 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 512 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 513 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 514 | // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4. |
| 515 | if (dstOffset & 3) { |
| 516 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Courtney Goeltzenleuchter | b19042e | 2015-11-25 11:38:54 -0700 | [diff] [blame] | 517 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDebugReportObjectTypeLUNARG)0, 0, 0, 1, "DL", |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 518 | "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) { |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // dataSize is the number of bytes to update, which must be a multiple of 4. |
| 524 | if (dataSize & 3) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 525 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Courtney Goeltzenleuchter | b19042e | 2015-11-25 11:38:54 -0700 | [diff] [blame] | 526 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDebugReportObjectTypeLUNARG)0, 0, 0, 1, "DL", |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 527 | "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) { |
| 528 | return; |
| 529 | } |
| 530 | } |
| 531 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 532 | dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 533 | } |
| 534 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 535 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer( |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 536 | VkCommandBuffer commandBuffer, |
| 537 | VkBuffer dstBuffer, |
| 538 | VkDeviceSize dstOffset, |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 539 | VkDeviceSize size, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 540 | uint32_t data) |
| 541 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 542 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 543 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 544 | // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4. |
| 545 | if (dstOffset & 3) { |
| 546 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Courtney Goeltzenleuchter | b19042e | 2015-11-25 11:38:54 -0700 | [diff] [blame] | 547 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDebugReportObjectTypeLUNARG)0, 0, 0, 1, "DL", |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 548 | "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) { |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 549 | return; |
| 550 | } |
| 551 | } |
| 552 | |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 553 | // size is the number of bytes to fill, which must be a multiple of 4. |
| 554 | if (size & 3) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 555 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Courtney Goeltzenleuchter | b19042e | 2015-11-25 11:38:54 -0700 | [diff] [blame] | 556 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDebugReportObjectTypeLUNARG)0, 0, 0, 1, "DL", |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 557 | "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) { |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 558 | return; |
| 559 | } |
| 560 | } |
| 561 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 562 | dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 563 | } |
| 564 | |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 565 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackLUNARG( |
| 566 | VkInstance instance, |
| 567 | VkDebugReportCallbackCreateInfoLUNARG* pCreateInfo, |
| 568 | const VkAllocationCallbacks* pAllocator, |
| 569 | VkDebugReportCallbackLUNARG* pMsgCallback) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 570 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 571 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 572 | VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackLUNARG(instance, pCreateInfo, pAllocator, pMsgCallback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 573 | if (VK_SUCCESS == res) { |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 574 | res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 575 | } |
| 576 | return res; |
| 577 | } |
| 578 | |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 579 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackLUNARG( |
| 580 | VkInstance instance, |
| 581 | VkDebugReportCallbackLUNARG msgCallback, |
| 582 | const VkAllocationCallbacks* pAllocator) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 583 | { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 584 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame^] | 585 | my_data->instance_dispatch_table->DestroyDebugReportCallbackLUNARG(instance, msgCallback, pAllocator); |
| 586 | layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 587 | } |
| 588 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 589 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 590 | { |
| 591 | if (dev == NULL) |
| 592 | return NULL; |
| 593 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 594 | layer_data *my_data; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 595 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 596 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 597 | VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev; |
| 598 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map); |
| 599 | my_data->device_dispatch_table = new VkLayerDispatchTable; |
| 600 | layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 601 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
| 602 | } |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 603 | 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] | 604 | if (!strcmp(funcName, "vkCreateDevice")) |
| 605 | return (PFN_vkVoidFunction) vkCreateDevice; |
| 606 | if (!strcmp(funcName, "vkDestroyDevice")) |
| 607 | return (PFN_vkVoidFunction) vkDestroyDevice; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 608 | if (!strcmp(funcName, "vkGetDeviceQueue")) |
| 609 | return (PFN_vkVoidFunction) vkGetDeviceQueue; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 610 | if (!strcmp(funcName, "CreateCommandPool")) |
| 611 | return (PFN_vkVoidFunction) vkCreateCommandPool; |
| 612 | if (!strcmp(funcName, "DestroyCommandPool")) |
| 613 | return (PFN_vkVoidFunction) vkDestroyCommandPool; |
| 614 | if (!strcmp(funcName, "ResetCommandPool")) |
| 615 | return (PFN_vkVoidFunction) vkResetCommandPool; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 616 | if (!strcmp(funcName, "vkAllocateCommandBuffers")) |
| 617 | return (PFN_vkVoidFunction) vkAllocateCommandBuffers; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 618 | if (!strcmp(funcName, "vkFreeCommandBuffers")) |
| 619 | return (PFN_vkVoidFunction) vkFreeCommandBuffers; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 620 | if (!strcmp(funcName, "vkCmdUpdateBuffer")) |
| 621 | return (PFN_vkVoidFunction) vkCmdUpdateBuffer; |
| 622 | if (!strcmp(funcName, "vkCmdFillBuffer")) |
| 623 | return (PFN_vkVoidFunction) vkCmdFillBuffer; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 624 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 625 | VkLayerDispatchTable* pTable = my_data->device_dispatch_table; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 626 | { |
| 627 | if (pTable->GetDeviceProcAddr == NULL) |
| 628 | return NULL; |
| 629 | return pTable->GetDeviceProcAddr(dev, funcName); |
| 630 | } |
| 631 | } |
| 632 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 633 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 634 | { |
| 635 | PFN_vkVoidFunction fptr; |
| 636 | if (instance == NULL) |
| 637 | return NULL; |
| 638 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 639 | layer_data *my_data; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 640 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 641 | if (!strcmp(funcName, "vkGetInstanceProcAddr")) { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 642 | VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance; |
| 643 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map); |
| 644 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 645 | layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 646 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
| 647 | } |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 648 | 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] | 649 | if (!strcmp(funcName, "vkCreateInstance")) |
| 650 | return (PFN_vkVoidFunction) vkCreateInstance; |
| 651 | if (!strcmp(funcName, "vkDestroyInstance")) |
| 652 | return (PFN_vkVoidFunction) vkDestroyInstance; |
| 653 | if (!strcmp(funcName, "vkEnumeratePhysicalDevices")) |
| 654 | return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices; |
| 655 | if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures")) |
| 656 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures; |
| 657 | if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties")) |
| 658 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties; |
| 659 | if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties")) |
| 660 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties; |
| 661 | if (!strcmp(funcName, "vkGetPhysicalDeviceProperties")) |
| 662 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties; |
| 663 | if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties")) |
| 664 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties; |
| 665 | if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties")) |
| 666 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 667 | if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties")) |
| 668 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties; |
Tobin Ehlis | fd3843f | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 669 | if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties")) |
| 670 | return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties; |
| 671 | if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties")) |
| 672 | return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 673 | |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 674 | fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 675 | if (fptr) |
| 676 | return fptr; |
| 677 | |
| 678 | { |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 679 | VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 680 | if (pTable->GetInstanceProcAddr == NULL) |
| 681 | return NULL; |
| 682 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 683 | } |
| 684 | } |