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