Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 17 | * |
| 18 | * Author: Mark Lobodzinski <mark@lunarg.com> |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 19 | * Author: Mike Stroyan <mike@LunarG.com> |
| 20 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <unordered_map> |
| 27 | #include <memory> |
| 28 | |
| 29 | #include "vk_loader_platform.h" |
| 30 | #include "vk_dispatch_table_helper.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 31 | #if defined(__GNUC__) |
| 32 | #pragma GCC diagnostic ignored "-Wwrite-strings" |
| 33 | #endif |
| 34 | #if defined(__GNUC__) |
| 35 | #pragma GCC diagnostic warning "-Wwrite-strings" |
| 36 | #endif |
| 37 | #include "vk_struct_size_helper.h" |
| 38 | #include "device_limits.h" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 39 | #include "vulkan/vk_layer.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 40 | #include "vk_layer_config.h" |
Michael Lentine | 5d8ad0a | 2016-01-28 15:03:46 -0600 | [diff] [blame] | 41 | #include "vk_enum_validate_helper.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 42 | #include "vk_layer_table.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 43 | #include "vk_layer_data.h" |
| 44 | #include "vk_layer_logging.h" |
| 45 | #include "vk_layer_extension_utils.h" |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 46 | #include "vk_layer_utils.h" |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 47 | |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 48 | namespace device_limits { |
| 49 | |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 50 | // This struct will be stored in a map hashed by the dispatchable object |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 51 | struct layer_data { |
Chia-I Wu | 50c4ad9 | 2016-04-28 16:04:15 +0800 | [diff] [blame^] | 52 | VkInstance instance; |
| 53 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 54 | debug_report_data *report_data; |
| 55 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
| 56 | VkLayerDispatchTable *device_dispatch_table; |
| 57 | VkLayerInstanceDispatchTable *instance_dispatch_table; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 58 | // Track state of each instance |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 59 | unique_ptr<INSTANCE_STATE> instanceState; |
| 60 | unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState; |
| 61 | VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures; |
| 62 | VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures; |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 63 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 64 | // Track physical device per logical device |
| 65 | VkPhysicalDevice physicalDevice; |
Dustin Graves | a97c394 | 2016-03-31 18:01:37 -0600 | [diff] [blame] | 66 | VkPhysicalDeviceProperties physicalDeviceProperties; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 67 | // Vector indices correspond to queueFamilyIndex |
| 68 | vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 69 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 70 | layer_data() |
| 71 | : report_data(nullptr), device_dispatch_table(nullptr), instance_dispatch_table(nullptr), instanceState(nullptr), |
| 72 | physicalDeviceState(nullptr), actualPhysicalDeviceFeatures(), requestedPhysicalDeviceFeatures(), physicalDevice(){}; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 73 | }; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 74 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 75 | static unordered_map<void *, layer_data *> layer_data_map; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 76 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 77 | // TODO : This can be much smarter, using separate locks for separate global data |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 78 | static int globalLockInitialized = 0; |
| 79 | static loader_platform_thread_mutex globalLock; |
| 80 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 81 | static void init_device_limits(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 82 | |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 83 | layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_device_limits"); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 84 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 85 | if (!globalLockInitialized) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 86 | // TODO/TBD: Need to delete this mutex sometime. How??? One |
| 87 | // suggestion is to call this during vkCreateInstance(), and then we |
| 88 | // can clean it up during vkDestroyInstance(). However, that requires |
| 89 | // that the layer have per-instance locks. We need to come back and |
| 90 | // address this soon. |
| 91 | loader_platform_thread_create_mutex(&globalLock); |
| 92 | globalLockInitialized = 1; |
| 93 | } |
| 94 | } |
Courtney Goeltzenleuchter | 20c3501 | 2015-11-30 12:14:06 -0700 | [diff] [blame] | 95 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 96 | static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}}; |
Courtney Goeltzenleuchter | 20c3501 | 2015-11-30 12:14:06 -0700 | [diff] [blame] | 97 | |
Chia-I Wu | cc0aa7a | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 98 | static const VkLayerProperties global_layer = { |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 99 | "VK_LAYER_LUNARG_device_limits", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer", |
Chia-I Wu | cc0aa7a | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 100 | }; |
Tobin Ehlis | fd3843f | 2015-09-29 12:26:00 -0600 | [diff] [blame] | 101 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 102 | VKAPI_ATTR VkResult VKAPI_CALL |
| 103 | CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 104 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 105 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 106 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 107 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 108 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 109 | if (fpCreateInstance == NULL) { |
| 110 | return VK_ERROR_INITIALIZATION_FAILED; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 111 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 112 | |
| 113 | // Advance the link info for the next element on the chain |
| 114 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 115 | |
| 116 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 117 | if (result != VK_SUCCESS) |
| 118 | return result; |
| 119 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 120 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
Chia-I Wu | 50c4ad9 | 2016-04-28 16:04:15 +0800 | [diff] [blame^] | 121 | my_data->instance = *pInstance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 122 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 123 | layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 124 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 125 | my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance, |
| 126 | pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 127 | |
| 128 | init_device_limits(my_data, pAllocator); |
| 129 | my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE()); |
| 130 | |
| 131 | return VK_SUCCESS; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 135 | VKAPI_ATTR void VKAPI_CALL |
| 136 | DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 137 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 138 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 139 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 140 | pTable->DestroyInstance(instance, pAllocator); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 141 | |
| 142 | // Clean up logging callback, if any |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 143 | while (my_data->logging_callback.size() > 0) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 144 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 145 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
Courtney Goeltzenleuchter | d6fce63 | 2015-10-05 14:51:41 -0600 | [diff] [blame] | 146 | my_data->logging_callback.pop_back(); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | layer_debug_report_destroy_instance(my_data->report_data); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 150 | delete my_data->instance_dispatch_table; |
| 151 | layer_data_map.erase(key); |
Tobin Ehlis | 0b63233 | 2015-10-07 09:38:40 -0600 | [diff] [blame] | 152 | if (layer_data_map.empty()) { |
| 153 | // Release mutex when destroying last instance. |
| 154 | loader_platform_thread_delete_mutex(&globalLock); |
| 155 | globalLockInitialized = 0; |
| 156 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 157 | } |
| 158 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 159 | VKAPI_ATTR VkResult VKAPI_CALL |
| 160 | EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 161 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 162 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 163 | if (my_data->instanceState) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 164 | // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 165 | if (NULL == pPhysicalDevices) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 166 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 167 | } else { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 168 | if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) { |
| 169 | // Flag error here, shouldn't be calling this without having queried count |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 170 | skipCall |= |
| 171 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0, |
| 172 | __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL", |
| 173 | "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first " |
| 174 | "call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 175 | } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state |
| 176 | else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) { |
| 177 | // TODO: Having actual count match count from app is not a requirement, so this can be a warning |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 178 | skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 179 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL", |
| 180 | "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count " |
| 181 | "supported by this instance is %u.", |
| 182 | *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 183 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 184 | my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 185 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 186 | if (skipCall) |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 187 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 188 | VkResult result = |
| 189 | my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 190 | if (NULL == pPhysicalDevices) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 191 | my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 192 | } else { // Save physical devices |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 193 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 194 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map); |
| 195 | phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE()); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 196 | // Init actual features for each physical device |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 197 | my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], |
| 198 | &(phy_dev_data->actualPhysicalDeviceFeatures)); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | return result; |
| 202 | } else { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 203 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0, __LINE__, |
| 204 | DEVLIMITS_INVALID_INSTANCE, "DL", "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", |
| 205 | (uint64_t)instance); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 206 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 207 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 208 | } |
| 209 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 210 | VKAPI_ATTR void VKAPI_CALL |
| 211 | GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 212 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 213 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 214 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 215 | } |
| 216 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 217 | VKAPI_ATTR void VKAPI_CALL |
| 218 | GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties *pFormatProperties) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 219 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map) |
| 220 | ->instance_dispatch_table->GetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 221 | } |
| 222 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 223 | VKAPI_ATTR VkResult VKAPI_CALL |
| 224 | GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, |
| 225 | VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 226 | VkImageFormatProperties *pImageFormatProperties) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 227 | return get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map) |
| 228 | ->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, |
| 229 | pImageFormatProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 230 | } |
| 231 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 232 | VKAPI_ATTR void VKAPI_CALL |
| 233 | GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 234 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 235 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 236 | } |
| 237 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 238 | VKAPI_ATTR void VKAPI_CALL |
| 239 | GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 240 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 241 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 242 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 243 | if (phy_dev_data->physicalDeviceState) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 244 | if (NULL == pQueueFamilyProperties) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 245 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 246 | } else { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 247 | // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to |
| 248 | // get count |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 249 | if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 250 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 251 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL", |
| 252 | "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL " |
| 253 | "pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ " |
| 254 | "NULL pQueueFamilyProperties to query pCount."); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 255 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 256 | // Then verify that pCount that is passed in on second call matches what was returned |
| 257 | if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 258 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 259 | // TODO: this is not a requirement of the Valid Usage section for vkGetPhysicalDeviceQueueFamilyProperties, so |
| 260 | // provide as warning |
| 261 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 262 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL", |
| 263 | "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count " |
| 264 | "supported by this physicalDevice is %u.", |
| 265 | *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 266 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 267 | phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 268 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 269 | if (skipCall) |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 270 | return; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 271 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, |
| 272 | pQueueFamilyProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 273 | if (NULL == pQueueFamilyProperties) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 274 | phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 275 | } else { // Save queue family properties |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 276 | phy_dev_data->queueFamilyProperties.reserve(*pCount); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 277 | for (uint32_t i = 0; i < *pCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 278 | phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i])); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 279 | } |
| 280 | } |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 281 | return; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 282 | } else { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 283 | log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, |
| 284 | __LINE__, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL", |
| 285 | "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", |
| 286 | (uint64_t)physicalDevice); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 290 | VKAPI_ATTR void VKAPI_CALL |
| 291 | GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties *pMemoryProperties) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 292 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map) |
| 293 | ->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 294 | } |
| 295 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 296 | VKAPI_ATTR void VKAPI_CALL |
| 297 | GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 298 | VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, |
| 299 | uint32_t *pNumProperties, VkSparseImageFormatProperties *pProperties) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 300 | get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map) |
| 301 | ->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, |
| 302 | tiling, pNumProperties, pProperties); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 303 | } |
| 304 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 305 | VKAPI_ATTR void VKAPI_CALL |
| 306 | CmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 307 | bool skipCall = false; |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 308 | /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */ |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 309 | if (!skipCall) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 310 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
| 311 | my_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports); |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 315 | VKAPI_ATTR void VKAPI_CALL |
| 316 | CmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 317 | bool skipCall = false; |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 318 | /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */ |
| 319 | /* TODO: viewportCount and scissorCount must match at draw time */ |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 320 | if (!skipCall) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 321 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
| 322 | my_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors); |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 326 | // Verify that features have been queried and verify that requested features are available |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 327 | static bool validate_features_request(layer_data *phy_dev_data) { |
| 328 | bool skipCall = false; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 329 | // Verify that all of the requested features are available |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 330 | // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 331 | VkBool32 *actual = (VkBool32 *)&(phy_dev_data->actualPhysicalDeviceFeatures); |
| 332 | VkBool32 *requested = (VkBool32 *)&(phy_dev_data->requestedPhysicalDeviceFeatures); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 333 | // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues |
| 334 | // Need to provide the struct member name with the issue. To do that seems like we'll |
| 335 | // have to loop through each struct member which should be done w/ codegen to keep in synch. |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 336 | uint32_t errors = 0; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 337 | uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 338 | for (uint32_t i = 0; i < totalBools; i++) { |
| 339 | if (requested[i] > actual[i]) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 340 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 341 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED, |
| 342 | "DL", "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, " |
| 343 | "which is not available on this device.", |
| 344 | i); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 345 | errors++; |
| 346 | } |
| 347 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 348 | if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 349 | // If user didn't request features, notify them that they should |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 350 | // TODO: Verify this against the spec. I believe this is an invalid use of the API and should return an error |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 351 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 352 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL", |
| 353 | "You requested features that are unavailable on this device. You should first query feature " |
| 354 | "availability by calling vkGetPhysicalDeviceFeatures()."); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 355 | } |
Tobin Ehlis | 72b27cc | 2015-09-29 11:22:37 -0600 | [diff] [blame] | 356 | return skipCall; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 357 | } |
| 358 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 359 | VKAPI_ATTR VkResult VKAPI_CALL |
| 360 | CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 361 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 362 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 363 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 364 | // First check is app has actually requested queueFamilyProperties |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 365 | if (!phy_dev_data->physicalDeviceState) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 366 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 367 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL", |
| 368 | "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices()."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 369 | } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 370 | // TODO: This is not called out as an invalid use in the spec so make more informative recommendation. |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 371 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 372 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, |
| 373 | "DL", "Call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties()."); |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 374 | } else { |
| 375 | // Check that the requested queue properties are valid |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 376 | for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 377 | uint32_t requestedIndex = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 378 | if (phy_dev_data->queueFamilyProperties.size() <= |
| 379 | requestedIndex) { // requested index is out of bounds for this physical device |
| 380 | skipCall |= log_msg( |
| 381 | phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, |
| 382 | __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 383 | "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 384 | } else if (pCreateInfo->pQueueCreateInfos[i].queueCount > |
| 385 | phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) { |
| 386 | skipCall |= |
| 387 | log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 388 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, |
| 389 | "DL", "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but " |
| 390 | "requested queueCount is %u.", |
| 391 | requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount, |
| 392 | pCreateInfo->pQueueCreateInfos[i].queueCount); |
Tobin Ehlis | 54a6c18 | 2015-09-22 14:00:58 -0600 | [diff] [blame] | 393 | } |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 394 | } |
| 395 | } |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 396 | // Check that any requested features are available |
| 397 | if (pCreateInfo->pEnabledFeatures) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 398 | phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 399 | skipCall |= validate_features_request(phy_dev_data); |
| 400 | } |
| 401 | if (skipCall) |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 402 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 403 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 404 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 405 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 406 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 407 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 408 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Chia-I Wu | 50c4ad9 | 2016-04-28 16:04:15 +0800 | [diff] [blame^] | 409 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(phy_dev_data->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 410 | if (fpCreateDevice == NULL) { |
| 411 | return VK_ERROR_INITIALIZATION_FAILED; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 412 | } |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 413 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 414 | // Advance the link info for the next element on the chain |
| 415 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 416 | |
| 417 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 418 | if (result != VK_SUCCESS) { |
| 419 | return result; |
| 420 | } |
| 421 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 422 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 423 | my_device_data->device_dispatch_table = new VkLayerDispatchTable; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 424 | layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); |
Dustin Graves | a97c394 | 2016-03-31 18:01:37 -0600 | [diff] [blame] | 425 | my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 426 | my_device_data->physicalDevice = gpu; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 427 | |
| 428 | // Get physical device properties for this device |
Dustin Graves | a97c394 | 2016-03-31 18:01:37 -0600 | [diff] [blame] | 429 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_device_data->physicalDeviceProperties)); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 430 | return result; |
| 431 | } |
| 432 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 433 | VKAPI_ATTR void VKAPI_CALL |
| 434 | DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 435 | // Free device lifetime allocations |
| 436 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 437 | layer_data *my_device_data = get_my_data_ptr(key, layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 438 | my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 439 | delete my_device_data->device_dispatch_table; |
| 440 | layer_data_map.erase(key); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 441 | } |
| 442 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 443 | VKAPI_ATTR VkResult VKAPI_CALL |
| 444 | CreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, |
| 445 | const VkAllocationCallbacks *pAllocator, |
| 446 | VkRenderPass *pRenderPass) { |
Michael Lentine | 20e4c19 | 2016-04-06 17:40:22 -0500 | [diff] [blame] | 447 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 448 | bool skip_call = false; |
| 449 | uint32_t max_color_attachments = dev_data->physicalDeviceProperties.limits.maxColorAttachments; |
| 450 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 451 | if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) { |
| 452 | skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 453 | reinterpret_cast<uint64_t>(device), __LINE__, DEVLIMITS_INVALID_ATTACHMENT_COUNT, "DL", |
| 454 | "Cannot create a render pass with %d color attachments. Max is %d.", |
| 455 | pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments); |
| 456 | } |
| 457 | } |
| 458 | if (skip_call) { |
| 459 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 460 | } |
| 461 | return dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass); |
| 462 | } |
| 463 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 464 | VKAPI_ATTR VkResult VKAPI_CALL |
| 465 | CreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, |
| 466 | const VkAllocationCallbacks *pAllocator, |
| 467 | VkCommandPool *pCommandPool) { |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 468 | // TODO : Verify that requested QueueFamilyIndex for this pool exists |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 469 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map) |
| 470 | ->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 471 | return result; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 472 | } |
| 473 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 474 | VKAPI_ATTR void VKAPI_CALL |
| 475 | DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 476 | get_my_data_ptr(get_dispatch_key(device), layer_data_map) |
| 477 | ->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 478 | } |
| 479 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 480 | VKAPI_ATTR VkResult VKAPI_CALL |
| 481 | ResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 482 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map) |
| 483 | ->device_dispatch_table->ResetCommandPool(device, commandPool, flags); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 484 | return result; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 485 | } |
| 486 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 487 | VKAPI_ATTR VkResult VKAPI_CALL |
| 488 | AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, VkCommandBuffer *pCommandBuffer) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 489 | VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map) |
| 490 | ->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer); |
Tobin Ehlis | 9da6500 | 2015-09-24 15:25:16 -0600 | [diff] [blame] | 491 | return result; |
| 492 | } |
Mark Lobodzinski | fbb130e | 2015-10-06 11:59:54 -0600 | [diff] [blame] | 493 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 494 | VKAPI_ATTR void VKAPI_CALL |
| 495 | FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 496 | get_my_data_ptr(get_dispatch_key(device), layer_data_map) |
| 497 | ->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 498 | } |
| 499 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 500 | VKAPI_ATTR VkResult VKAPI_CALL |
| 501 | BeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) { |
Michael Lentine | 09853ef | 2016-01-28 14:20:46 -0600 | [diff] [blame] | 502 | bool skipCall = false; |
| 503 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Tony Barbour | e24b8e3 | 2016-03-25 13:04:20 -0600 | [diff] [blame] | 504 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(dev_data->physicalDevice), layer_data_map); |
Michael Lentine | 09853ef | 2016-01-28 14:20:46 -0600 | [diff] [blame] | 505 | const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo; |
Tony Barbour | e24b8e3 | 2016-03-25 13:04:20 -0600 | [diff] [blame] | 506 | if (phy_dev_data->actualPhysicalDeviceFeatures.inheritedQueries == VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 507 | skipCall |= log_msg( |
| 508 | dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 509 | reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL", |
| 510 | "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support inheritedQueries."); |
Michael Lentine | 09853ef | 2016-01-28 14:20:46 -0600 | [diff] [blame] | 511 | } |
Tony Barbour | e24b8e3 | 2016-03-25 13:04:20 -0600 | [diff] [blame] | 512 | if (phy_dev_data->actualPhysicalDeviceFeatures.inheritedQueries != VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE && |
Michael Lentine | 5d8ad0a | 2016-01-28 15:03:46 -0600 | [diff] [blame] | 513 | !validate_VkQueryControlFlagBits(VkQueryControlFlagBits(pInfo->queryFlags))) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 514 | skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 515 | reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL", |
| 516 | "Cannot enable in occlusion queries in vkBeginCommandBuffer() and set queryFlags to %d which is not a " |
| 517 | "valid combination of VkQueryControlFlagBits.", |
Michael Lentine | 5d8ad0a | 2016-01-28 15:03:46 -0600 | [diff] [blame] | 518 | pInfo->queryFlags); |
| 519 | } |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 520 | VkResult result = VK_ERROR_VALIDATION_FAILED_EXT; |
Michael Lentine | 09853ef | 2016-01-28 14:20:46 -0600 | [diff] [blame] | 521 | if (!skipCall) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 522 | result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo); |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 523 | return result; |
Michael Lentine | 09853ef | 2016-01-28 14:20:46 -0600 | [diff] [blame] | 524 | } |
| 525 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 526 | VKAPI_ATTR void VKAPI_CALL |
| 527 | GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 528 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 529 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 530 | VkPhysicalDevice gpu = dev_data->physicalDevice; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 531 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 532 | if (queueFamilyIndex >= |
| 533 | phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device |
| 534 | skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 535 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, |
| 536 | "DL", "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 537 | } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 538 | skipCall |= log_msg( |
| 539 | phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, |
| 540 | DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL", |
| 541 | "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", |
| 542 | queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 543 | } |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 544 | if (!skipCall) |
| 545 | dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 546 | } |
| 547 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 548 | VKAPI_ATTR void VKAPI_CALL |
| 549 | UpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 550 | uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) { |
| 551 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 552 | bool skipCall = false; |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 553 | |
Mark Young | ee3f3a2 | 2016-01-25 12:18:32 -0700 | [diff] [blame] | 554 | for (uint32_t i = 0; i < descriptorWriteCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 555 | if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) || |
| 556 | (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) { |
Dustin Graves | a97c394 | 2016-03-31 18:01:37 -0600 | [diff] [blame] | 557 | VkDeviceSize uniformAlignment = dev_data->physicalDeviceProperties.limits.minUniformBufferOffsetAlignment; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 558 | for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) { |
| 559 | if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 560 | skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 561 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, |
| 562 | DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL", |
| 563 | "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64 |
| 564 | ") must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64, |
| 565 | i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment); |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 568 | } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) || |
| 569 | (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) { |
Dustin Graves | a97c394 | 2016-03-31 18:01:37 -0600 | [diff] [blame] | 570 | VkDeviceSize storageAlignment = dev_data->physicalDeviceProperties.limits.minStorageBufferOffsetAlignment; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 571 | for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) { |
| 572 | if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 573 | skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 574 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, |
| 575 | DEVLIMITS_INVALID_STORAGE_BUFFER_OFFSET, "DL", |
| 576 | "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64 |
| 577 | ") must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64, |
| 578 | i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment); |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | } |
| 582 | } |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 583 | if (!skipCall) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 584 | dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, |
| 585 | pDescriptorCopies); |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 589 | VKAPI_ATTR void VKAPI_CALL |
| 590 | CmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, |
| 591 | VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t *pData) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 592 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 593 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 594 | // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4. |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 595 | if (dstOffset & 3) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 596 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Chris Forbes | 4550168 | 2016-04-07 12:00:33 +1200 | [diff] [blame] | 597 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__, |
| 598 | DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL", |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 599 | "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) { |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 600 | return; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | // dataSize is the number of bytes to update, which must be a multiple of 4. |
| 605 | if (dataSize & 3) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 606 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Chris Forbes | 4550168 | 2016-04-07 12:00:33 +1200 | [diff] [blame] | 607 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__, |
| 608 | DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL", |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 609 | "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) { |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 610 | return; |
| 611 | } |
| 612 | } |
| 613 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 614 | dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 615 | } |
| 616 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 617 | VKAPI_ATTR void VKAPI_CALL |
| 618 | CmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 619 | layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 620 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 621 | // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4. |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 622 | if (dstOffset & 3) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 623 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Chris Forbes | 4550168 | 2016-04-07 12:00:33 +1200 | [diff] [blame] | 624 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__, |
| 625 | DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL", |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 626 | "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) { |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 627 | return; |
| 628 | } |
| 629 | } |
| 630 | |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 631 | // size is the number of bytes to fill, which must be a multiple of 4. |
| 632 | if (size & 3) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 633 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Chris Forbes | 4550168 | 2016-04-07 12:00:33 +1200 | [diff] [blame] | 634 | if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__, |
| 635 | DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL", |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 636 | "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) { |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 637 | return; |
| 638 | } |
| 639 | } |
| 640 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 641 | dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 642 | } |
| 643 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 644 | VKAPI_ATTR VkResult VKAPI_CALL |
| 645 | CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 646 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 647 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 648 | VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 649 | if (VK_SUCCESS == res) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 650 | res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 651 | } |
| 652 | return res; |
| 653 | } |
| 654 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 655 | VKAPI_ATTR void VKAPI_CALL |
| 656 | DestroyDebugReportCallbackEXT(VkInstance instance, |
| 657 | VkDebugReportCallbackEXT msgCallback, |
| 658 | const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 659 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 660 | my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 661 | layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 662 | } |
| 663 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 664 | VKAPI_ATTR void VKAPI_CALL |
| 665 | DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, |
| 666 | size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 667 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 668 | my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, |
| 669 | pMsg); |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 672 | VKAPI_ATTR VkResult VKAPI_CALL |
| 673 | EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 674 | const char *pLayerName, uint32_t *pCount, |
| 675 | VkExtensionProperties *pProperties) { |
Chia-I Wu | c83c083 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 676 | if (pLayerName && !strcmp(pLayerName, global_layer.layerName)) |
Chia-I Wu | 16489ac | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 677 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
Chia-I Wu | c83c083 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 678 | |
| 679 | assert(physicalDevice); |
| 680 | |
| 681 | dispatch_key key = get_dispatch_key(physicalDevice); |
| 682 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 683 | return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pCount, pProperties); |
Chia-I Wu | 16489ac | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 684 | } |
| 685 | |
Chia-I Wu | afe4244 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 686 | static PFN_vkVoidFunction |
Chia-I Wu | 2b8c6e6 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 687 | intercept_core_instance_command(const char *name); |
| 688 | |
| 689 | static PFN_vkVoidFunction |
Chia-I Wu | afe4244 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 690 | intercept_core_device_command(const char *name); |
| 691 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 692 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
| 693 | GetDeviceProcAddr(VkDevice dev, const char *funcName) { |
Chia-I Wu | afe4244 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 694 | PFN_vkVoidFunction proc = intercept_core_device_command(funcName); |
| 695 | if (proc) |
| 696 | return proc; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 697 | |
Chia-I Wu | afe4244 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 698 | assert(dev); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 699 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 700 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 701 | VkLayerDispatchTable *pTable = my_data->device_dispatch_table; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 702 | { |
| 703 | if (pTable->GetDeviceProcAddr == NULL) |
| 704 | return NULL; |
| 705 | return pTable->GetDeviceProcAddr(dev, funcName); |
| 706 | } |
| 707 | } |
| 708 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 709 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
| 710 | GetInstanceProcAddr(VkInstance instance, const char *funcName) { |
Chia-I Wu | 2b8c6e6 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 711 | PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); |
Chia-I Wu | 79d1c8d | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 712 | if (!proc) |
| 713 | intercept_core_device_command(funcName); |
Chia-I Wu | 2b8c6e6 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 714 | if (proc) |
| 715 | return proc; |
| 716 | |
Tobin Ehlis | 1cb7f57 | 2015-10-06 09:09:24 -0600 | [diff] [blame] | 717 | layer_data *my_data; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 718 | |
Chia-I Wu | 79d1c8d | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 719 | assert(instance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 720 | my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 721 | |
Chia-I Wu | 79d1c8d | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 722 | proc = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 723 | if (proc) |
| 724 | return proc; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 725 | |
| 726 | { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 727 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Tobin Ehlis | b5fc4fb | 2015-09-03 09:50:06 -0600 | [diff] [blame] | 728 | if (pTable->GetInstanceProcAddr == NULL) |
| 729 | return NULL; |
| 730 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 731 | } |
| 732 | } |
Chia-I Wu | 16489ac | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 733 | |
Chia-I Wu | afe4244 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 734 | static PFN_vkVoidFunction |
Chia-I Wu | 2b8c6e6 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 735 | intercept_core_instance_command(const char *name) { |
| 736 | static const struct { |
| 737 | const char *name; |
| 738 | PFN_vkVoidFunction proc; |
| 739 | } core_instance_commands[] = { |
| 740 | { "vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr) }, |
| 741 | { "vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr) }, |
| 742 | { "vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance) }, |
| 743 | { "vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance) }, |
| 744 | { "vkCreateDevice", reinterpret_cast<PFN_vkVoidFunction>(CreateDevice) }, |
| 745 | { "vkEnumeratePhysicalDevices", reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices) }, |
| 746 | { "vkGetPhysicalDeviceFeatures", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFeatures) }, |
| 747 | { "vkGetPhysicalDeviceFormatProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFormatProperties) }, |
| 748 | { "vkGetPhysicalDeviceImageFormatProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceImageFormatProperties) }, |
| 749 | { "vkGetPhysicalDeviceProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties) }, |
| 750 | { "vkGetPhysicalDeviceQueueFamilyProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties) }, |
| 751 | { "vkGetPhysicalDeviceMemoryProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMemoryProperties) }, |
| 752 | { "vkGetPhysicalDeviceSparseImageFormatProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSparseImageFormatProperties) }, |
Chia-I Wu | dfe8e6c | 2016-04-28 15:17:27 +0800 | [diff] [blame] | 753 | { "vkEnumerateDeviceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties) }, |
Chia-I Wu | 2b8c6e6 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 754 | }; |
| 755 | |
Chia-I Wu | 79d1c8d | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 756 | // we should never be queried for these commands |
| 757 | assert(strcmp(name, "vkEnumerateInstanceLayerProperties") && |
| 758 | strcmp(name, "vkEnumerateInstanceExtensionProperties") && |
| 759 | strcmp(name, "vkEnumerateDeviceLayerProperties")); |
| 760 | |
Chia-I Wu | 2b8c6e6 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 761 | for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) { |
| 762 | if (!strcmp(core_instance_commands[i].name, name)) |
| 763 | return core_instance_commands[i].proc; |
| 764 | } |
| 765 | |
| 766 | return nullptr; |
| 767 | } |
| 768 | |
| 769 | static PFN_vkVoidFunction |
Chia-I Wu | afe4244 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 770 | intercept_core_device_command(const char *name) { |
| 771 | static const struct { |
| 772 | const char *name; |
| 773 | PFN_vkVoidFunction proc; |
| 774 | } core_device_commands[] = { |
| 775 | { "vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr) }, |
| 776 | { "vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice) }, |
| 777 | { "vkGetDeviceQueue", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue) }, |
| 778 | { "vkCreateRenderPass", reinterpret_cast<PFN_vkVoidFunction>(CreateRenderPass) }, |
| 779 | { "vkCreateCommandPool", reinterpret_cast<PFN_vkVoidFunction>(CreateCommandPool) }, |
| 780 | { "vkDestroyCommandPool", reinterpret_cast<PFN_vkVoidFunction>(DestroyCommandPool) }, |
| 781 | { "vkResetCommandPool", reinterpret_cast<PFN_vkVoidFunction>(ResetCommandPool) }, |
| 782 | { "vkAllocateCommandBuffers", reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers) }, |
| 783 | { "vkFreeCommandBuffers", reinterpret_cast<PFN_vkVoidFunction>(FreeCommandBuffers) }, |
| 784 | { "vkBeginCommandBuffer", reinterpret_cast<PFN_vkVoidFunction>(BeginCommandBuffer) }, |
| 785 | { "vkCmdUpdateBuffer", reinterpret_cast<PFN_vkVoidFunction>(CmdUpdateBuffer) }, |
| 786 | { "vkUpdateDescriptorSets", reinterpret_cast<PFN_vkVoidFunction>(UpdateDescriptorSets) }, |
| 787 | { "vkCmdFillBuffer", reinterpret_cast<PFN_vkVoidFunction>(CmdFillBuffer) }, |
Chia-I Wu | fa5e51c | 2016-04-28 14:44:08 +0800 | [diff] [blame] | 788 | { "vkCmdSetScissor", reinterpret_cast<PFN_vkVoidFunction>(CmdSetScissor) }, |
| 789 | { "vkCmdSetViewport", reinterpret_cast<PFN_vkVoidFunction>(CmdSetViewport) }, |
Chia-I Wu | afe4244 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 790 | }; |
| 791 | |
| 792 | for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) { |
| 793 | if (!strcmp(core_device_commands[i].name, name)) |
| 794 | return core_device_commands[i].proc; |
| 795 | } |
| 796 | |
| 797 | return nullptr; |
| 798 | } |
| 799 | |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 800 | } // namespace device_limits |
| 801 | |
| 802 | // vk_layer_logging.h expects these to be defined |
| 803 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 804 | VKAPI_ATTR VkResult VKAPI_CALL |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 805 | vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 806 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) { |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 807 | return device_limits::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 808 | } |
| 809 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 810 | VKAPI_ATTR void VKAPI_CALL |
| 811 | vkDestroyDebugReportCallbackEXT(VkInstance instance, |
| 812 | VkDebugReportCallbackEXT msgCallback, |
| 813 | const VkAllocationCallbacks *pAllocator) { |
| 814 | device_limits::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 815 | } |
| 816 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 817 | VKAPI_ATTR void VKAPI_CALL |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 818 | vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, |
| 819 | size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 820 | device_limits::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | // loader-layer interface v0 |
| 824 | |
Chia-I Wu | 16489ac | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 825 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 826 | vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | cc0aa7a | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 827 | return util_GetLayerProperties(1, &device_limits::global_layer, pCount, pProperties); |
Chia-I Wu | 16489ac | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 831 | vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | cc0aa7a | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 832 | return util_GetLayerProperties(1, &device_limits::global_layer, pCount, pProperties); |
Chia-I Wu | 16489ac | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 836 | vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 837 | return util_GetExtensionProperties(1, device_limits::instance_extensions, pCount, pProperties); |
| 838 | } |
| 839 | |
| 840 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 841 | const char *pLayerName, uint32_t *pCount, |
| 842 | VkExtensionProperties *pProperties) { |
Chia-I Wu | c83c083 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 843 | // the layer command handles VK_NULL_HANDLE just fine |
| 844 | return device_limits::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 848 | return device_limits::GetDeviceProcAddr(dev, funcName); |
Chia-I Wu | 080cb7a | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
Chia-I Wu | 79d1c8d | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 852 | if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties")) |
| 853 | return reinterpret_cast<PFN_vkVoidFunction>(vkEnumerateInstanceLayerProperties); |
| 854 | if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties")) |
| 855 | return reinterpret_cast<PFN_vkVoidFunction>(vkEnumerateDeviceLayerProperties); |
| 856 | if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties")) |
| 857 | return reinterpret_cast<PFN_vkVoidFunction>(vkEnumerateInstanceExtensionProperties); |
| 858 | if (!strcmp(funcName, "vkGetInstanceProcAddr")) |
| 859 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetInstanceProcAddr); |
| 860 | |
Chia-I Wu | 9986020 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 861 | return device_limits::GetInstanceProcAddr(instance, funcName); |
Chia-I Wu | 16489ac | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 862 | } |