Tobin Ehlis | c345b8b | 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" |
| 44 | // The following is #included again to catch certain OS-specific functions |
| 45 | // being used: |
| 46 | #include "vk_loader_platform.h" |
| 47 | #include "vk_layer_msg.h" |
| 48 | #include "vk_layer_table.h" |
| 49 | #include "vk_layer_debug_marker_table.h" |
| 50 | #include "vk_layer_data.h" |
| 51 | #include "vk_layer_logging.h" |
| 52 | #include "vk_layer_extension_utils.h" |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 53 | #include "vk_layer_utils.h" |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 54 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 55 | |
| 56 | // This struct will be stored in a map hashed by the dispatchable object |
Cody Northrop | 73bb657 | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 57 | struct layer_data { |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 58 | debug_report_data *report_data; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 59 | VkDbgMsgCallback logging_callback; |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 60 | // Track state of each instance |
| 61 | unique_ptr<INSTANCE_STATE> instanceState; |
| 62 | unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState; |
| 63 | VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures; |
| 64 | VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures; |
| 65 | unique_ptr<VkPhysicalDeviceProperties> physicalDeviceProperties; |
| 66 | // Vector indices correspond to queueFamilyIndex |
| 67 | vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties; |
Cody Northrop | 73bb657 | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 68 | |
| 69 | layer_data() : |
| 70 | report_data(nullptr), |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 71 | logging_callback(nullptr), |
| 72 | instanceState(nullptr), |
| 73 | physicalDeviceState(nullptr), |
| 74 | physicalDeviceProperties(nullptr), |
| 75 | actualPhysicalDeviceFeatures(), |
| 76 | requestedPhysicalDeviceFeatures() |
Cody Northrop | 73bb657 | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 77 | {}; |
| 78 | }; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 79 | |
| 80 | static std::unordered_map<void *, layer_data *> layer_data_map; |
| 81 | static device_table_map device_limits_device_table_map; |
| 82 | static instance_table_map device_limits_instance_table_map; |
| 83 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 84 | static unordered_map<VkDevice, VkPhysicalDevice> deviceMap; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 85 | |
| 86 | struct devExts { |
| 87 | bool debug_marker_enabled; |
| 88 | }; |
| 89 | |
| 90 | static std::unordered_map<void *, struct devExts> deviceExtMap; |
| 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 | |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 102 | static void init_device_limits(layer_data *my_data) |
| 103 | { |
| 104 | uint32_t report_flags = 0; |
| 105 | uint32_t debug_action = 0; |
| 106 | FILE *log_output = NULL; |
| 107 | const char *option_str; |
| 108 | // initialize DeviceLimits options |
| 109 | report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0); |
| 110 | getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action); |
| 111 | |
| 112 | if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
| 113 | { |
| 114 | option_str = getLayerOption("DeviceLimitsLogFilename"); |
Tobin Ehlis | b4b6e7c | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 115 | log_output = getLayerLogOutput(option_str, "DeviceLimits"); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 116 | layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback); |
| 117 | } |
| 118 | |
| 119 | if (!globalLockInitialized) |
| 120 | { |
| 121 | // TODO/TBD: Need to delete this mutex sometime. How??? One |
| 122 | // suggestion is to call this during vkCreateInstance(), and then we |
| 123 | // can clean it up during vkDestroyInstance(). However, that requires |
| 124 | // that the layer have per-instance locks. We need to come back and |
| 125 | // address this soon. |
| 126 | loader_platform_thread_create_mutex(&globalLock); |
| 127 | globalLockInitialized = 1; |
| 128 | } |
| 129 | } |
Tobin Ehlis | c95fa8d | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 130 | /* DeviceLimits does not have any global extensions */ |
| 131 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties( |
| 132 | const char *pLayerName, |
| 133 | uint32_t *pCount, |
| 134 | VkExtensionProperties* pProperties) |
| 135 | { |
| 136 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 137 | } |
| 138 | |
| 139 | static const VkLayerProperties dl_global_layers[] = { |
| 140 | { |
| 141 | "DeviceLimits", |
| 142 | VK_API_VERSION, |
| 143 | VK_MAKE_VERSION(0, 1, 0), |
| 144 | "Validation layer: Device Limits", |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties( |
| 149 | uint32_t *pCount, |
| 150 | VkLayerProperties* pProperties) |
| 151 | { |
| 152 | return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers), |
| 153 | dl_global_layers, |
| 154 | pCount, pProperties); |
| 155 | } |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 156 | |
| 157 | VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance) |
| 158 | { |
| 159 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map,*pInstance); |
| 160 | VkResult result = pTable->CreateInstance(pCreateInfo, pInstance); |
| 161 | |
| 162 | if (result == VK_SUCCESS) { |
| 163 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 164 | my_data->report_data = debug_report_create_instance( |
| 165 | pTable, |
| 166 | *pInstance, |
| 167 | pCreateInfo->extensionCount, |
| 168 | pCreateInfo->ppEnabledExtensionNames); |
| 169 | |
| 170 | init_device_limits(my_data); |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 171 | my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE()); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 172 | } |
| 173 | return result; |
| 174 | } |
| 175 | |
| 176 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 177 | VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance) |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 178 | { |
| 179 | dispatch_key key = get_dispatch_key(instance); |
| 180 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance); |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 181 | pTable->DestroyInstance(instance); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 182 | |
| 183 | // Clean up logging callback, if any |
| 184 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 185 | if (my_data->logging_callback) { |
| 186 | layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback); |
| 187 | } |
| 188 | |
| 189 | layer_debug_report_destroy_instance(my_data->report_data); |
| 190 | layer_data_map.erase(pTable); |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 191 | my_data->instanceState.release(); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 192 | device_limits_instance_table_map.erase(key); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) |
| 196 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 197 | VkBool32 skipCall = VK_FALSE; |
| 198 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 199 | if (my_data->instanceState) { |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 200 | // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS |
| 201 | if (NULL == pPhysicalDevices) { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 202 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 203 | } else { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 204 | if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) { |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 205 | // Flag error here, shouldn't be calling this without having queried count |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 206 | 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 | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 207 | "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount."); |
| 208 | } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 209 | else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) { |
| 210 | skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL", |
| 211 | "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count supported by this instance is %u.", *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 212 | } |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 213 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 214 | } |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 215 | if (skipCall) |
| 216 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 217 | VkResult result = get_dispatch_table(device_limits_instance_table_map,instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
| 218 | if (NULL == pPhysicalDevices) { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 219 | my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 220 | } else { // Save physical devices |
| 221 | for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 222 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map); |
| 223 | phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE()); |
| 224 | // Init actual features for each physical device |
| 225 | get_dispatch_table(device_limits_instance_table_map,instance)->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures)); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | return result; |
| 229 | } else { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 230 | log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL", |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 231 | "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) |
| 236 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 237 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 238 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 239 | VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 240 | return result; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties) |
| 244 | { |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 245 | VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFormatProperties( |
| 246 | physicalDevice, format, pFormatProperties); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 247 | return result; |
| 248 | } |
| 249 | |
Courtney Goeltzenleuchter | 83c95f8 | 2015-09-10 13:44:12 -0600 | [diff] [blame] | 250 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties) |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 251 | { |
Courtney Goeltzenleuchter | 83c95f8 | 2015-09-10 13:44:12 -0600 | [diff] [blame] | 252 | VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 253 | return result; |
| 254 | } |
| 255 | |
| 256 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties) |
| 257 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 258 | VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)-> |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 259 | GetPhysicalDeviceProperties(physicalDevice, pProperties); |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 260 | if (VK_SUCCESS == result) { |
| 261 | // Save Properties |
| 262 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 263 | phy_dev_data->physicalDeviceProperties = |
| 264 | unique_ptr<VkPhysicalDeviceProperties>(new VkPhysicalDeviceProperties(*pProperties)); |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 265 | } |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 266 | return result; |
| 267 | } |
| 268 | |
| 269 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties) |
| 270 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 271 | VkBool32 skipCall = VK_FALSE; |
| 272 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 273 | if (phy_dev_data->physicalDeviceState) { |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 274 | if (NULL == pQueueFamilyProperties) { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 275 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 276 | } else { |
| 277 | // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 278 | if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 279 | 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 | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 280 | "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount."); |
| 281 | } |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 282 | // Then verify that pCount that is passed in on second call matches what was returned |
| 283 | if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) { |
| 284 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL", |
| 285 | "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 286 | } |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 287 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 288 | } |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 289 | if (skipCall) |
| 290 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 291 | VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties); |
| 292 | if (NULL == pQueueFamilyProperties) { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 293 | phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 294 | } else { // Save queue family properties |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 295 | phy_dev_data->queueFamilyProperties.reserve(*pCount); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 296 | for (uint32_t i=0; i < *pCount; i++) { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 297 | phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i])); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | return result; |
| 301 | } else { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 302 | 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 | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 303 | "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties) |
| 308 | { |
| 309 | VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties); |
| 310 | return result; |
| 311 | } |
| 312 | |
| 313 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties) |
| 314 | { |
| 315 | VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties); |
| 316 | return result; |
| 317 | } |
| 318 | |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 319 | VK_LAYER_EXPORT void VKAPI vkCmdSetViewport( |
| 320 | VkCmdBuffer cmdBuffer, |
Courtney Goeltzenleuchter | 932cdb5 | 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) { |
| 327 | get_dispatch_table(device_limits_device_table_map, cmdBuffer)->CmdSetViewport(cmdBuffer, viewportCount, pViewports); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | VK_LAYER_EXPORT void VKAPI vkCmdSetScissor( |
| 332 | VkCmdBuffer cmdBuffer, |
| 333 | uint32_t scissorCount, |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 334 | const VkRect2D* pScissors) |
| 335 | { |
| 336 | VkBool32 skipCall = VK_FALSE; |
Courtney Goeltzenleuchter | 932cdb5 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 337 | /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */ |
| 338 | /* TODO: viewportCount and scissorCount must match at draw time */ |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 339 | if (VK_FALSE == skipCall) { |
Courtney Goeltzenleuchter | 932cdb5 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 340 | get_dispatch_table(device_limits_device_table_map, cmdBuffer)->CmdSetScissor(cmdBuffer, scissorCount, pScissors); |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 344 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 345 | { |
| 346 | uint32_t i; |
| 347 | VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device); |
| 348 | deviceExtMap[pDisp].debug_marker_enabled = false; |
| 349 | |
| 350 | for (i = 0; i < pCreateInfo->extensionCount; i++) { |
| 351 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) { |
| 352 | /* Found a matching extension name, mark it enabled and init dispatch table*/ |
| 353 | initDebugMarkerTable(device); |
| 354 | deviceExtMap[pDisp].debug_marker_enabled = true; |
| 355 | } |
| 356 | |
| 357 | } |
| 358 | } |
| 359 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 360 | // Verify that features have been queried and verify that requested features are available |
| 361 | static VkBool32 validate_features_request(layer_data *phy_dev_data) |
| 362 | { |
| 363 | VkBool32 skipCall = VK_FALSE; |
| 364 | // Verify that all of the requested features are available |
| 365 | // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid |
| 366 | VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures); |
| 367 | VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures); |
| 368 | // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues |
| 369 | // Need to provide the struct member name with the issue. To do that seems like we'll |
| 370 | // have to loop through each struct member which should be done w/ codegen to keep in synch. |
| 371 | uint32_t errors = 0; |
| 372 | uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32); |
| 373 | for (uint32_t i = 0; i < totalBools; i++) { |
| 374 | if (requested[i] > actual[i]) { |
| 375 | 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", |
| 376 | "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i); |
| 377 | errors++; |
| 378 | } |
| 379 | } |
| 380 | if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) { |
| 381 | // If user didn't request features, notify them that they should |
| 382 | 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", |
| 383 | "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures()."); |
| 384 | } |
Tobin Ehlis | 6454cd9 | 2015-09-29 11:22:37 -0600 | [diff] [blame] | 385 | return skipCall; |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 386 | } |
| 387 | |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 388 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) |
| 389 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 390 | VkBool32 skipCall = VK_FALSE; |
| 391 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
Tobin Ehlis | 7684384 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 392 | // First check is app has actually requested queueFamilyProperties |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 393 | if (!phy_dev_data->physicalDeviceState) { |
| 394 | 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 | 7684384 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 395 | "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices()."); |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 396 | } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 397 | 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 | 7684384 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 398 | "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties()."); |
| 399 | } else { |
| 400 | // Check that the requested queue properties are valid |
| 401 | for (uint32_t i=0; i<pCreateInfo->queueRecordCount; i++) { |
| 402 | uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex; |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 403 | if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device |
| 404 | 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 | 7684384 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 405 | "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex); |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 406 | } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) { |
| 407 | 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", |
| 408 | "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 | 7684384 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 409 | } |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 410 | } |
| 411 | } |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 412 | // Check that any requested features are available |
| 413 | if (pCreateInfo->pEnabledFeatures) { |
| 414 | phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures); |
| 415 | skipCall |= validate_features_request(phy_dev_data); |
| 416 | } |
| 417 | if (skipCall) |
| 418 | return VK_ERROR_VALIDATION_FAILED; |
| 419 | |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 420 | VkLayerDispatchTable *pDeviceTable = get_dispatch_table(device_limits_device_table_map, *pDevice); |
| 421 | VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice); |
| 422 | if (result == VK_SUCCESS) { |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 423 | VkLayerDispatchTable *pTable = get_dispatch_table(device_limits_device_table_map, *pDevice); |
| 424 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
Tobin Ehlis | 8a10b1b | 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 | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 426 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
| 427 | deviceMap[*pDevice] = gpu; |
| 428 | } |
| 429 | return result; |
| 430 | } |
| 431 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 432 | VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device) |
Tobin Ehlis | c345b8b | 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 | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 436 | VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device); |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 437 | pDisp->DestroyDevice(device); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 438 | deviceExtMap.erase(pDisp); |
| 439 | device_limits_device_table_map.erase(key); |
| 440 | tableDebugMarkerMap.erase(pDisp); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 441 | } |
| 442 | |
Tobin Ehlis | 8a10b1b | 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 | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 444 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 445 | // TODO : Verify that requested QueueFamilyIndex for this pool exists |
| 446 | VkResult result = get_dispatch_table(device_limits_device_table_map, device)->CreateCommandPool(device, pCreateInfo, pCmdPool); |
| 447 | return result; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 448 | } |
| 449 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 450 | VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool) |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 451 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 452 | get_dispatch_table(device_limits_device_table_map, device)->DestroyCommandPool(device, cmdPool); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 453 | } |
| 454 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 455 | VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags) |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 456 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 457 | VkResult result = get_dispatch_table(device_limits_device_table_map, device)->ResetCommandPool(device, cmdPool, flags); |
| 458 | return result; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 459 | } |
| 460 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 461 | VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer) |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 462 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 463 | VkResult result = get_dispatch_table(device_limits_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer); |
| 464 | return result; |
| 465 | } |
Mark Lobodzinski | 806aa6a | 2015-10-06 11:59:54 -0600 | [diff] [blame^] | 466 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 467 | VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer) |
| 468 | { |
| 469 | |
| 470 | get_dispatch_table(device_limits_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue) |
| 474 | { |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 475 | VkBool32 skipCall = VK_FALSE; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 476 | VkPhysicalDevice gpu = deviceMap[device]; |
Tobin Ehlis | 8a10b1b | 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 | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 480 | "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex); |
Tobin Ehlis | 8a10b1b | 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 | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 484 | } |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 485 | if (skipCall) |
| 486 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 487 | VkResult result = get_dispatch_table(device_limits_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
| 488 | return result; |
| 489 | } |
| 490 | |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 491 | VK_LAYER_EXPORT VkResult VKAPI vkCreateImage( |
| 492 | VkDevice device, |
| 493 | const VkImageCreateInfo *pCreateInfo, |
| 494 | VkImage *pImage) |
| 495 | { |
| 496 | VkBool32 skipCall = VK_FALSE; |
| 497 | VkResult result = VK_ERROR_VALIDATION_FAILED; |
| 498 | VkPhysicalDevice physicalDevice = deviceMap[device]; |
| 499 | VkImageType type; |
| 500 | VkImageFormatProperties ImageFormatProperties = {0}; |
| 501 | |
| 502 | // Internal call to get format info. Still goes through layers, could potentially go directly to ICD. |
| 503 | get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties( |
| 504 | physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, |
| 505 | pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties); |
| 506 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 507 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 508 | if (!phy_dev_data->physicalDeviceProperties) { |
Mark Lobodzinski | 806aa6a | 2015-10-06 11:59:54 -0600 | [diff] [blame^] | 509 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0, |
| 510 | DEVLIMITS_MUST_QUERY_PROPERTIES, "DL", |
| 511 | "CreateImage called before querying device properties "); |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 512 | } |
Mark Lobodzinski | 806aa6a | 2015-10-06 11:59:54 -0600 | [diff] [blame^] | 513 | |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 514 | uint32_t imageGranularity = phy_dev_data->physicalDeviceProperties->limits.bufferImageGranularity; |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 515 | imageGranularity = imageGranularity == 1 ? 0 : imageGranularity; |
| 516 | |
| 517 | if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) || |
| 518 | (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) || |
| 519 | (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) { |
Mark Lobodzinski | 806aa6a | 2015-10-06 11:59:54 -0600 | [diff] [blame^] | 520 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0, |
| 521 | DEVLIMITS_LIMITS_VIOLATION, "DL", |
| 522 | "CreateImage extents exceed allowable limits for format: " |
| 523 | "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.", |
| 524 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
| 525 | ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth, |
| 526 | string_VkFormat(pCreateInfo->format)); |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 527 | |
| 528 | } |
| 529 | |
| 530 | uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * |
| 531 | (uint64_t)pCreateInfo->extent.height * |
| 532 | (uint64_t)pCreateInfo->extent.depth * |
| 533 | (uint64_t)pCreateInfo->arraySize * |
| 534 | (uint64_t)pCreateInfo->samples * |
| 535 | (uint64_t)vk_format_get_size(pCreateInfo->format) + |
| 536 | (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity; |
| 537 | |
| 538 | if (totalSize > ImageFormatProperties.maxResourceSize) { |
Mark Lobodzinski | 806aa6a | 2015-10-06 11:59:54 -0600 | [diff] [blame^] | 539 | skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0, |
| 540 | DEVLIMITS_LIMITS_VIOLATION, "DL", |
| 541 | "CreateImage resource size exceeds allowable maximum " |
| 542 | "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ", |
| 543 | totalSize, ImageFormatProperties.maxResourceSize); |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 544 | } |
| 545 | if (VK_FALSE == skipCall) { |
| 546 | result = get_dispatch_table(device_limits_device_table_map, device)->CreateImage(device, pCreateInfo, pImage); |
| 547 | } |
| 548 | return result; |
| 549 | } |
| 550 | |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 551 | VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback( |
| 552 | VkInstance instance, |
| 553 | VkFlags msgFlags, |
| 554 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
| 555 | void* pUserData, |
| 556 | VkDbgMsgCallback* pMsgCallback) |
| 557 | { |
| 558 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance); |
| 559 | VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 560 | if (VK_SUCCESS == res) { |
| 561 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 562 | res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 563 | } |
| 564 | return res; |
| 565 | } |
| 566 | |
| 567 | VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback( |
| 568 | VkInstance instance, |
| 569 | VkDbgMsgCallback msgCallback) |
| 570 | { |
| 571 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance); |
| 572 | VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback); |
| 573 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 574 | layer_destroy_msg_callback(my_data->report_data, msgCallback); |
| 575 | return res; |
| 576 | } |
| 577 | |
| 578 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName) |
| 579 | { |
| 580 | if (dev == NULL) |
| 581 | return NULL; |
| 582 | |
| 583 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 584 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
| 585 | initDeviceTable(device_limits_device_table_map, (const VkBaseLayerObject *) dev); |
| 586 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
| 587 | } |
| 588 | if (!strcmp(funcName, "vkCreateDevice")) |
| 589 | return (PFN_vkVoidFunction) vkCreateDevice; |
| 590 | if (!strcmp(funcName, "vkDestroyDevice")) |
| 591 | return (PFN_vkVoidFunction) vkDestroyDevice; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 592 | if (!strcmp(funcName, "vkGetDeviceQueue")) |
| 593 | return (PFN_vkVoidFunction) vkGetDeviceQueue; |
Mark Lobodzinski | ddaecf8 | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 594 | if (!strcmp(funcName, "vkCreateImage")) |
| 595 | return (PFN_vkVoidFunction) vkCreateImage; |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 596 | if (!strcmp(funcName, "CreateCommandPool")) |
| 597 | return (PFN_vkVoidFunction) vkCreateCommandPool; |
| 598 | if (!strcmp(funcName, "DestroyCommandPool")) |
| 599 | return (PFN_vkVoidFunction) vkDestroyCommandPool; |
| 600 | if (!strcmp(funcName, "ResetCommandPool")) |
| 601 | return (PFN_vkVoidFunction) vkResetCommandPool; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 602 | if (!strcmp(funcName, "vkCreateCommandBuffer")) |
| 603 | return (PFN_vkVoidFunction) vkCreateCommandBuffer; |
Tobin Ehlis | 8a10b1b | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 604 | if (!strcmp(funcName, "vkDestroyCommandBuffer")) |
| 605 | return (PFN_vkVoidFunction) vkDestroyCommandBuffer; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 606 | |
| 607 | VkLayerDispatchTable* pTable = get_dispatch_table(device_limits_device_table_map, dev); |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 608 | { |
| 609 | if (pTable->GetDeviceProcAddr == NULL) |
| 610 | return NULL; |
| 611 | return pTable->GetDeviceProcAddr(dev, funcName); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
| 616 | { |
| 617 | PFN_vkVoidFunction fptr; |
| 618 | if (instance == NULL) |
| 619 | return NULL; |
| 620 | |
| 621 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 622 | if (!strcmp(funcName, "vkGetInstanceProcAddr")) { |
| 623 | initInstanceTable(device_limits_instance_table_map, (const VkBaseLayerObject *) instance); |
| 624 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
| 625 | } |
| 626 | if (!strcmp(funcName, "vkCreateInstance")) |
| 627 | return (PFN_vkVoidFunction) vkCreateInstance; |
| 628 | if (!strcmp(funcName, "vkDestroyInstance")) |
| 629 | return (PFN_vkVoidFunction) vkDestroyInstance; |
| 630 | if (!strcmp(funcName, "vkEnumeratePhysicalDevices")) |
| 631 | return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices; |
| 632 | if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures")) |
| 633 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures; |
| 634 | if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties")) |
| 635 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties; |
| 636 | if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties")) |
| 637 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties; |
| 638 | if (!strcmp(funcName, "vkGetPhysicalDeviceProperties")) |
| 639 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties; |
| 640 | if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties")) |
| 641 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties; |
| 642 | if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties")) |
| 643 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 644 | if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties")) |
| 645 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties; |
Tobin Ehlis | c95fa8d | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 646 | if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties")) |
| 647 | return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties; |
| 648 | if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties")) |
| 649 | return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties; |
Tobin Ehlis | c345b8b | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 650 | |
| 651 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 652 | fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 653 | if (fptr) |
| 654 | return fptr; |
| 655 | |
| 656 | { |
| 657 | VkLayerInstanceDispatchTable* pTable = get_dispatch_table(device_limits_instance_table_map, instance); |
| 658 | if (pTable->GetInstanceProcAddr == NULL) |
| 659 | return NULL; |
| 660 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 661 | } |
| 662 | } |