Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2017 Valve Corporation |
| 3 | * Copyright (c) 2015-2017 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2017 Google Inc. |
| 5 | * |
| 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 |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 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. |
| 17 | * |
| 18 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 19 | * Author: Jon Ashburn <jon@lunarg.com> |
| 20 | * Author: Tobin Ehlis <tobin@lunarg.com> |
| 21 | */ |
| 22 | |
| 23 | #include "object_tracker.h" |
| 24 | |
| 25 | namespace object_tracker { |
| 26 | |
| 27 | std::unordered_map<void *, layer_data *> layer_data_map; |
| 28 | device_table_map ot_device_table_map; |
| 29 | instance_table_map ot_instance_table_map; |
| 30 | std::mutex global_lock; |
| 31 | uint64_t object_track_index = 0; |
| 32 | uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 33 | |
| 34 | void InitObjectTracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 35 | layer_debug_report_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_object_tracker"); |
| 36 | layer_debug_messenger_actions(my_data->report_data, my_data->logging_messenger, pAllocator, "lunarg_object_tracker"); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | // Add new queue to head of global queue list |
| 40 | void AddQueueInfo(VkDevice device, uint32_t queue_node_index, VkQueue queue) { |
| 41 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 42 | auto queueItem = device_data->queue_info_map.find(queue); |
| 43 | if (queueItem == device_data->queue_info_map.end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 44 | ObjTrackQueueInfo *p_queue_info = new ObjTrackQueueInfo; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 45 | if (p_queue_info != NULL) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 46 | memset(p_queue_info, 0, sizeof(ObjTrackQueueInfo)); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 47 | p_queue_info->queue = queue; |
| 48 | p_queue_info->queue_node_index = queue_node_index; |
| 49 | device_data->queue_info_map[queue] = p_queue_info; |
| 50 | } else { |
| 51 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 52 | HandleToUint64(queue), OBJTRACK_INTERNAL_ERROR, |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 53 | "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information"); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // Destroy memRef lists and free all memory |
| 59 | void DestroyQueueDataStructures(VkDevice device) { |
| 60 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 61 | |
| 62 | for (auto queue_item : device_data->queue_info_map) { |
| 63 | delete queue_item.second; |
| 64 | } |
| 65 | device_data->queue_info_map.clear(); |
| 66 | |
| 67 | // Destroy the items in the queue map |
| 68 | auto queue = device_data->object_map[kVulkanObjectTypeQueue].begin(); |
| 69 | while (queue != device_data->object_map[kVulkanObjectTypeQueue].end()) { |
| 70 | uint32_t obj_index = queue->second->object_type; |
| 71 | assert(device_data->num_total_objects > 0); |
| 72 | device_data->num_total_objects--; |
| 73 | assert(device_data->num_objects[obj_index] > 0); |
| 74 | device_data->num_objects[obj_index]--; |
| 75 | log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 76 | queue->second->handle, OBJTRACK_NONE, |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 77 | "OBJ_STAT Destroy Queue obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " Queue objs).", |
| 78 | queue->second->handle, device_data->num_total_objects, device_data->num_objects[obj_index]); |
| 79 | delete queue->second; |
| 80 | queue = device_data->object_map[kVulkanObjectTypeQueue].erase(queue); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Check Queue type flags for selected queue operations |
| 85 | void ValidateQueueFlags(VkQueue queue, const char *function) { |
| 86 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map); |
| 87 | auto queue_item = device_data->queue_info_map.find(queue); |
| 88 | if (queue_item != device_data->queue_info_map.end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 89 | ObjTrackQueueInfo *pQueueInfo = queue_item->second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 90 | if (pQueueInfo != NULL) { |
| 91 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(device_data->physical_device), layer_data_map); |
| 92 | if ((instance_data->queue_family_properties[pQueueInfo->queue_node_index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) == |
| 93 | 0) { |
| 94 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 95 | HandleToUint64(queue), VALIDATION_ERROR_31600011, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 96 | "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set.", function); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 102 | // Look for this device object in any of the instance child devices lists. |
| 103 | // NOTE: This is of dubious value. In most circumstances Vulkan will die a flaming death if a dispatchable object is invalid. |
| 104 | // However, if this layer is loaded first and GetProcAddress is used to make API calls, it will detect bad DOs. |
| 105 | bool ValidateDeviceObject(uint64_t device_handle, enum UNIQUE_VALIDATION_ERROR_CODE invalid_handle_code, |
| 106 | enum UNIQUE_VALIDATION_ERROR_CODE wrong_device_code) { |
| 107 | VkInstance last_instance = nullptr; |
| 108 | for (auto layer_data : layer_data_map) { |
| 109 | for (auto object : layer_data.second->object_map[kVulkanObjectTypeDevice]) { |
| 110 | // Grab last instance to use for possible error message |
| 111 | last_instance = layer_data.second->instance; |
| 112 | if (object.second->handle == device_handle) return false; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(last_instance), layer_data_map); |
| 117 | return log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 118 | invalid_handle_code, "Invalid Device Object 0x%" PRIxLEAST64 ".", device_handle); |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 121 | void AllocateCommandBuffer(VkDevice device, const VkCommandPool command_pool, const VkCommandBuffer command_buffer, |
| 122 | VkCommandBufferLevel level) { |
| 123 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 124 | |
| 125 | log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 126 | HandleToUint64(command_buffer), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 127 | object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT", HandleToUint64(command_buffer)); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 128 | |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 129 | ObjTrackState *pNewObjNode = new ObjTrackState; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 130 | pNewObjNode->object_type = kVulkanObjectTypeCommandBuffer; |
| 131 | pNewObjNode->handle = HandleToUint64(command_buffer); |
| 132 | pNewObjNode->parent_object = HandleToUint64(command_pool); |
| 133 | if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 134 | pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY; |
| 135 | } else { |
| 136 | pNewObjNode->status = OBJSTATUS_NONE; |
| 137 | } |
| 138 | device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)] = pNewObjNode; |
| 139 | device_data->num_objects[kVulkanObjectTypeCommandBuffer]++; |
| 140 | device_data->num_total_objects++; |
| 141 | } |
| 142 | |
| 143 | bool ValidateCommandBuffer(VkDevice device, VkCommandPool command_pool, VkCommandBuffer command_buffer) { |
| 144 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 145 | bool skip = false; |
| 146 | uint64_t object_handle = HandleToUint64(command_buffer); |
| 147 | if (device_data->object_map[kVulkanObjectTypeCommandBuffer].find(object_handle) != |
| 148 | device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 149 | ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)]; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 150 | |
| 151 | if (pNode->parent_object != HandleToUint64(command_pool)) { |
| 152 | skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 153 | object_handle, VALIDATION_ERROR_28411407, |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 154 | "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 155 | " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").", |
| 156 | HandleToUint64(command_buffer), pNode->parent_object, HandleToUint64(command_pool)); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 157 | } |
| 158 | } else { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 159 | skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 160 | object_handle, VALIDATION_ERROR_28400060, "Invalid %s Object 0x%" PRIxLEAST64 ".", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 161 | object_string[kVulkanObjectTypeCommandBuffer], object_handle); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 162 | } |
| 163 | return skip; |
| 164 | } |
| 165 | |
| 166 | void AllocateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) { |
| 167 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 168 | |
| 169 | log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 170 | HandleToUint64(descriptor_set), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 171 | object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT", HandleToUint64(descriptor_set)); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 172 | |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 173 | ObjTrackState *pNewObjNode = new ObjTrackState; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 174 | pNewObjNode->object_type = kVulkanObjectTypeDescriptorSet; |
| 175 | pNewObjNode->status = OBJSTATUS_NONE; |
| 176 | pNewObjNode->handle = HandleToUint64(descriptor_set); |
| 177 | pNewObjNode->parent_object = HandleToUint64(descriptor_pool); |
| 178 | device_data->object_map[kVulkanObjectTypeDescriptorSet][HandleToUint64(descriptor_set)] = pNewObjNode; |
| 179 | device_data->num_objects[kVulkanObjectTypeDescriptorSet]++; |
| 180 | device_data->num_total_objects++; |
| 181 | } |
| 182 | |
| 183 | bool ValidateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) { |
| 184 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 185 | bool skip = false; |
| 186 | uint64_t object_handle = HandleToUint64(descriptor_set); |
| 187 | auto dsItem = device_data->object_map[kVulkanObjectTypeDescriptorSet].find(object_handle); |
| 188 | if (dsItem != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 189 | ObjTrackState *pNode = dsItem->second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 190 | |
| 191 | if (pNode->parent_object != HandleToUint64(descriptor_pool)) { |
| 192 | skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 193 | object_handle, VALIDATION_ERROR_28613007, |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 194 | "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 195 | " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").", |
| 196 | HandleToUint64(descriptor_set), pNode->parent_object, HandleToUint64(descriptor_pool)); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 197 | } |
| 198 | } else { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 199 | skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 200 | object_handle, VALIDATION_ERROR_2860026c, "Invalid %s Object 0x%" PRIxLEAST64 ".", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 201 | object_string[kVulkanObjectTypeDescriptorSet], object_handle); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 202 | } |
| 203 | return skip; |
| 204 | } |
| 205 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 206 | template <typename DispObj> |
Chris Forbes | 2c600e9 | 2017-10-20 11:13:20 -0700 | [diff] [blame] | 207 | static bool ValidateDescriptorWrite(DispObj disp, VkWriteDescriptorSet const *desc, bool isPush) { |
| 208 | bool skip = false; |
| 209 | |
| 210 | if (!isPush && desc->dstSet) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 211 | skip |= ValidateObject(disp, desc->dstSet, kVulkanObjectTypeDescriptorSet, false, VALIDATION_ERROR_15c00280, |
| 212 | VALIDATION_ERROR_15c00009); |
Chris Forbes | 2c600e9 | 2017-10-20 11:13:20 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) || |
| 216 | (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) { |
| 217 | for (uint32_t idx2 = 0; idx2 < desc->descriptorCount; ++idx2) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 218 | skip |= ValidateObject(disp, desc->pTexelBufferView[idx2], kVulkanObjectTypeBufferView, false, |
| 219 | VALIDATION_ERROR_15c00286, VALIDATION_ERROR_15c00009); |
Chris Forbes | 2c600e9 | 2017-10-20 11:13:20 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) || |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 224 | (desc->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) || |
Chris Forbes | 2c600e9 | 2017-10-20 11:13:20 -0700 | [diff] [blame] | 225 | (desc->descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) { |
| 226 | for (uint32_t idx3 = 0; idx3 < desc->descriptorCount; ++idx3) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 227 | skip |= ValidateObject(disp, desc->pImageInfo[idx3].imageView, kVulkanObjectTypeImageView, false, |
| 228 | VALIDATION_ERROR_15c0028c, VALIDATION_ERROR_04600009); |
Chris Forbes | 2c600e9 | 2017-10-20 11:13:20 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) || |
| 233 | (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) || |
| 234 | (desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) || |
| 235 | (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) { |
| 236 | for (uint32_t idx4 = 0; idx4 < desc->descriptorCount; ++idx4) { |
| 237 | if (desc->pBufferInfo[idx4].buffer) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 238 | skip |= ValidateObject(disp, desc->pBufferInfo[idx4].buffer, kVulkanObjectTypeBuffer, false, |
| 239 | VALIDATION_ERROR_04401a01, VALIDATION_ERROR_UNDEFINED); |
Chris Forbes | 2c600e9 | 2017-10-20 11:13:20 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | return skip; |
| 245 | } |
| 246 | |
Tony Barbour | 2fd0c2c | 2017-08-08 12:51:33 -0600 | [diff] [blame] | 247 | VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 248 | VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount, |
| 249 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 250 | bool skip = false; |
| 251 | { |
| 252 | std::lock_guard<std::mutex> lock(global_lock); |
| 253 | skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_1be02401, |
| 254 | VALIDATION_ERROR_1be00009); |
| 255 | skip |= ValidateObject(commandBuffer, layout, kVulkanObjectTypePipelineLayout, false, VALIDATION_ERROR_1be0be01, |
| 256 | VALIDATION_ERROR_1be00009); |
| 257 | if (pDescriptorWrites) { |
| 258 | for (uint32_t index0 = 0; index0 < descriptorWriteCount; ++index0) { |
Chris Forbes | a94b60b | 2017-10-20 11:28:02 -0700 | [diff] [blame] | 259 | skip |= ValidateDescriptorWrite(commandBuffer, &pDescriptorWrites[index0], true); |
Tony Barbour | 2fd0c2c | 2017-08-08 12:51:33 -0600 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | } |
| 263 | if (skip) return; |
| 264 | get_dispatch_table(ot_device_table_map, commandBuffer) |
| 265 | ->CmdPushDescriptorSetKHR(commandBuffer, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites); |
| 266 | } |
| 267 | |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 268 | void CreateQueue(VkDevice device, VkQueue vkObj) { |
| 269 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 270 | |
| 271 | log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 272 | HandleToUint64(vkObj), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 273 | object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT", HandleToUint64(vkObj)); |
| 274 | |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 275 | ObjTrackState *p_obj_node = NULL; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 276 | auto queue_item = device_data->object_map[kVulkanObjectTypeQueue].find(HandleToUint64(vkObj)); |
| 277 | if (queue_item == device_data->object_map[kVulkanObjectTypeQueue].end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 278 | p_obj_node = new ObjTrackState; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 279 | device_data->object_map[kVulkanObjectTypeQueue][HandleToUint64(vkObj)] = p_obj_node; |
| 280 | device_data->num_objects[kVulkanObjectTypeQueue]++; |
| 281 | device_data->num_total_objects++; |
| 282 | } else { |
| 283 | p_obj_node = queue_item->second; |
| 284 | } |
| 285 | p_obj_node->object_type = kVulkanObjectTypeQueue; |
| 286 | p_obj_node->status = OBJSTATUS_NONE; |
| 287 | p_obj_node->handle = HandleToUint64(vkObj); |
| 288 | } |
| 289 | |
| 290 | void CreateSwapchainImageObject(VkDevice dispatchable_object, VkImage swapchain_image, VkSwapchainKHR swapchain) { |
| 291 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map); |
| 292 | log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 293 | HandleToUint64(swapchain_image), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 294 | object_track_index++, "SwapchainImage", HandleToUint64(swapchain_image)); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 295 | |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 296 | ObjTrackState *pNewObjNode = new ObjTrackState; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 297 | pNewObjNode->object_type = kVulkanObjectTypeImage; |
| 298 | pNewObjNode->status = OBJSTATUS_NONE; |
| 299 | pNewObjNode->handle = HandleToUint64(swapchain_image); |
| 300 | pNewObjNode->parent_object = HandleToUint64(swapchain); |
| 301 | device_data->swapchainImageMap[HandleToUint64(swapchain_image)] = pNewObjNode; |
| 302 | } |
| 303 | |
| 304 | void DeviceReportUndestroyedObjects(VkDevice device, VulkanObjectType object_type, enum UNIQUE_VALIDATION_ERROR_CODE error_code) { |
| 305 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
GabrÃel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame^] | 306 | for (const auto &item : device_data->object_map[object_type]) { |
| 307 | const ObjTrackState *object_info = item.second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 308 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[object_type], object_info->handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 309 | error_code, "OBJ ERROR : For device 0x%" PRIxLEAST64 ", %s object 0x%" PRIxLEAST64 " has not been destroyed.", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 310 | HandleToUint64(device), object_string[object_type], object_info->handle); |
GabrÃel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame^] | 311 | } |
| 312 | } |
| 313 | |
| 314 | void DeviceDestroyUndestroyedObjects(VkDevice device, VulkanObjectType object_type) { |
| 315 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 316 | while (!device_data->object_map[object_type].empty()) { |
| 317 | auto item = device_data->object_map[object_type].begin(); |
| 318 | |
| 319 | ObjTrackState *object_info = item->second; |
| 320 | DestroyObjectSilently(device, object_info->handle, object_type); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
| 325 | std::unique_lock<std::mutex> lock(global_lock); |
| 326 | |
| 327 | dispatch_key key = get_dispatch_key(instance); |
| 328 | layer_data *instance_data = GetLayerDataPtr(key, layer_data_map); |
| 329 | |
| 330 | // Enable the temporary callback(s) here to catch cleanup issues: |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 331 | if (instance_data->num_tmp_debug_messengers > 0) { |
| 332 | layer_enable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers, |
| 333 | instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers); |
| 334 | } |
| 335 | if (instance_data->num_tmp_report_callbacks > 0) { |
| 336 | layer_enable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks, |
| 337 | instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | // TODO: The instance handle can not be validated here. The loader will likely have to validate it. |
| 341 | ValidateObject(instance, instance, kVulkanObjectTypeInstance, true, VALIDATION_ERROR_2580bc01, VALIDATION_ERROR_UNDEFINED); |
| 342 | |
| 343 | // Destroy physical devices |
| 344 | for (auto iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin(); |
| 345 | iit != instance_data->object_map[kVulkanObjectTypePhysicalDevice].end();) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 346 | ObjTrackState *pNode = iit->second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 347 | VkPhysicalDevice physical_device = reinterpret_cast<VkPhysicalDevice>(pNode->handle); |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 348 | |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 349 | DestroyObject(instance, physical_device, kVulkanObjectTypePhysicalDevice, nullptr, VALIDATION_ERROR_UNDEFINED, |
| 350 | VALIDATION_ERROR_UNDEFINED); |
| 351 | iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin(); |
| 352 | } |
| 353 | |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 354 | // Destroy child devices |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 355 | for (auto iit = instance_data->object_map[kVulkanObjectTypeDevice].begin(); |
| 356 | iit != instance_data->object_map[kVulkanObjectTypeDevice].end();) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 357 | ObjTrackState *pNode = iit->second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 358 | |
| 359 | VkDevice device = reinterpret_cast<VkDevice>(pNode->handle); |
| 360 | VkDebugReportObjectTypeEXT debug_object_type = get_debug_report_enum[pNode->object_type]; |
| 361 | |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 362 | log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, debug_object_type, pNode->handle, OBJTRACK_OBJECT_LEAK, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 363 | "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 364 | string_VkDebugReportObjectTypeEXT(debug_object_type), pNode->handle); |
| 365 | |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 366 | // Report any remaining objects in LL |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 367 | ReportUndestroyedObjects(device, VALIDATION_ERROR_258004ea); |
GabrÃel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame^] | 368 | DestroyUndestroyedObjects(device); |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 369 | |
| 370 | DestroyObject(instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_258004ec, VALIDATION_ERROR_258004ee); |
| 371 | iit = instance_data->object_map[kVulkanObjectTypeDevice].begin(); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 372 | } |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 373 | |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 374 | instance_data->object_map[kVulkanObjectTypeDevice].clear(); |
| 375 | |
| 376 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance); |
| 377 | pInstanceTable->DestroyInstance(instance, pAllocator); |
| 378 | |
| 379 | // Disable and cleanup the temporary callback(s): |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 380 | layer_disable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers, |
| 381 | instance_data->tmp_debug_messengers); |
| 382 | layer_disable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks, |
| 383 | instance_data->tmp_report_callbacks); |
| 384 | if (instance_data->num_tmp_debug_messengers > 0) { |
| 385 | layer_free_tmp_debug_messengers(instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers); |
| 386 | instance_data->num_tmp_debug_messengers = 0; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 387 | } |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 388 | if (instance_data->num_tmp_report_callbacks > 0) { |
| 389 | layer_free_tmp_report_callbacks(instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks); |
| 390 | instance_data->num_tmp_report_callbacks = 0; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | // Clean up logging callback, if any |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 394 | while (instance_data->logging_messenger.size() > 0) { |
| 395 | VkDebugUtilsMessengerEXT messenger = instance_data->logging_messenger.back(); |
| 396 | layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator); |
| 397 | instance_data->logging_messenger.pop_back(); |
| 398 | } |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 399 | while (instance_data->logging_callback.size() > 0) { |
| 400 | VkDebugReportCallbackEXT callback = instance_data->logging_callback.back(); |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 401 | layer_destroy_report_callback(instance_data->report_data, callback, pAllocator); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 402 | instance_data->logging_callback.pop_back(); |
| 403 | } |
| 404 | |
GabrÃel Arthúr Pétursson | 3de74ca | 2018-03-18 01:50:54 +0000 | [diff] [blame] | 405 | DestroyObject(instance, instance, kVulkanObjectTypeInstance, pAllocator, VALIDATION_ERROR_258004ec, VALIDATION_ERROR_258004ee); |
| 406 | |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 407 | layer_debug_utils_destroy_instance(instance_data->report_data); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 408 | FreeLayerDataPtr(key, layer_data_map); |
| 409 | |
| 410 | lock.unlock(); |
| 411 | ot_instance_table_map.erase(key); |
| 412 | delete pInstanceTable; |
| 413 | } |
| 414 | |
| 415 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 416 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 417 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 418 | ValidateObject(device, device, kVulkanObjectTypeDevice, true, VALIDATION_ERROR_24a05601, VALIDATION_ERROR_UNDEFINED); |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 419 | DestroyObject(device_data->instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_24a002f6, |
| 420 | VALIDATION_ERROR_24a002f8); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 421 | |
| 422 | // Report any remaining objects associated with this VkDevice object in LL |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 423 | ReportUndestroyedObjects(device, VALIDATION_ERROR_24a002f4); |
GabrÃel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame^] | 424 | DestroyUndestroyedObjects(device); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 425 | |
| 426 | // Clean up Queue's MemRef Linked Lists |
| 427 | DestroyQueueDataStructures(device); |
| 428 | |
| 429 | lock.unlock(); |
| 430 | |
| 431 | dispatch_key key = get_dispatch_key(device); |
| 432 | VkLayerDispatchTable *pDisp = get_dispatch_table(ot_device_table_map, device); |
| 433 | pDisp->DestroyDevice(device, pAllocator); |
| 434 | ot_device_table_map.erase(key); |
| 435 | delete pDisp; |
| 436 | |
| 437 | FreeLayerDataPtr(key, layer_data_map); |
| 438 | } |
| 439 | |
Mark Lobodzinski | 439645a | 2017-07-19 15:18:15 -0600 | [diff] [blame] | 440 | VKAPI_ATTR void VKAPI_CALL GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) { |
| 441 | std::unique_lock<std::mutex> lock(global_lock); |
| 442 | ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_29605601, VALIDATION_ERROR_UNDEFINED); |
| 443 | lock.unlock(); |
| 444 | |
| 445 | get_dispatch_table(ot_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
| 446 | |
| 447 | lock.lock(); |
| 448 | CreateQueue(device, *pQueue); |
| 449 | AddQueueInfo(device, queueFamilyIndex, *pQueue); |
| 450 | } |
| 451 | |
Yiwei Zhang | 991d88d | 2018-02-14 14:39:46 -0800 | [diff] [blame] | 452 | VKAPI_ATTR void VKAPI_CALL GetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) { |
| 453 | std::unique_lock<std::mutex> lock(global_lock); |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 454 | ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_43405601, VALIDATION_ERROR_UNDEFINED); |
Yiwei Zhang | 991d88d | 2018-02-14 14:39:46 -0800 | [diff] [blame] | 455 | lock.unlock(); |
| 456 | |
| 457 | get_dispatch_table(ot_device_table_map, device)->GetDeviceQueue2(device, pQueueInfo, pQueue); |
| 458 | |
| 459 | lock.lock(); |
| 460 | if (*pQueue != VK_NULL_HANDLE) { |
| 461 | CreateQueue(device, *pQueue); |
| 462 | AddQueueInfo(device, pQueueInfo->queueFamilyIndex, *pQueue); |
| 463 | } |
| 464 | } |
| 465 | |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 466 | VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, |
| 467 | const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount, |
| 468 | const VkCopyDescriptorSet *pDescriptorCopies) { |
| 469 | bool skip = false; |
| 470 | { |
| 471 | std::lock_guard<std::mutex> lock(global_lock); |
| 472 | skip |= |
| 473 | ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_33c05601, VALIDATION_ERROR_UNDEFINED); |
| 474 | if (pDescriptorCopies) { |
| 475 | for (uint32_t idx0 = 0; idx0 < descriptorCopyCount; ++idx0) { |
| 476 | if (pDescriptorCopies[idx0].dstSet) { |
| 477 | skip |= ValidateObject(device, pDescriptorCopies[idx0].dstSet, kVulkanObjectTypeDescriptorSet, false, |
| 478 | VALIDATION_ERROR_03207601, VALIDATION_ERROR_03200009); |
| 479 | } |
| 480 | if (pDescriptorCopies[idx0].srcSet) { |
| 481 | skip |= ValidateObject(device, pDescriptorCopies[idx0].srcSet, kVulkanObjectTypeDescriptorSet, false, |
| 482 | VALIDATION_ERROR_0322d201, VALIDATION_ERROR_03200009); |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | if (pDescriptorWrites) { |
| 487 | for (uint32_t idx1 = 0; idx1 < descriptorWriteCount; ++idx1) { |
Chris Forbes | 2c600e9 | 2017-10-20 11:13:20 -0700 | [diff] [blame] | 488 | skip |= ValidateDescriptorWrite(device, &pDescriptorWrites[idx1], false); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | } |
| 492 | if (skip) { |
| 493 | return; |
| 494 | } |
| 495 | get_dispatch_table(ot_device_table_map, device) |
| 496 | ->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies); |
| 497 | } |
| 498 | |
Mark Lobodzinski | 2d26c5f | 2017-07-19 12:37:04 -0600 | [diff] [blame] | 499 | VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 500 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 501 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) { |
| 502 | bool skip = VK_FALSE; |
| 503 | std::unique_lock<std::mutex> lock(global_lock); |
| 504 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_1f205601, VALIDATION_ERROR_UNDEFINED); |
| 505 | if (pCreateInfos) { |
| 506 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
| 507 | if (pCreateInfos[idx0].basePipelineHandle) { |
| 508 | skip |= ValidateObject(device, pCreateInfos[idx0].basePipelineHandle, kVulkanObjectTypePipeline, true, |
| 509 | VALIDATION_ERROR_03000572, VALIDATION_ERROR_03000009); |
| 510 | } |
| 511 | if (pCreateInfos[idx0].layout) { |
| 512 | skip |= ValidateObject(device, pCreateInfos[idx0].layout, kVulkanObjectTypePipelineLayout, false, |
| 513 | VALIDATION_ERROR_0300be01, VALIDATION_ERROR_03000009); |
| 514 | } |
| 515 | if (pCreateInfos[idx0].stage.module) { |
| 516 | skip |= ValidateObject(device, pCreateInfos[idx0].stage.module, kVulkanObjectTypeShaderModule, false, |
| 517 | VALIDATION_ERROR_1060d201, VALIDATION_ERROR_UNDEFINED); |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | if (pipelineCache) { |
| 522 | skip |= ValidateObject(device, pipelineCache, kVulkanObjectTypePipelineCache, true, VALIDATION_ERROR_1f228001, |
| 523 | VALIDATION_ERROR_1f228007); |
| 524 | } |
| 525 | lock.unlock(); |
| 526 | if (skip) { |
| 527 | for (uint32_t i = 0; i < createInfoCount; i++) { |
| 528 | pPipelines[i] = VK_NULL_HANDLE; |
| 529 | } |
| 530 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 531 | } |
| 532 | VkResult result = get_dispatch_table(ot_device_table_map, device) |
| 533 | ->CreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); |
| 534 | lock.lock(); |
| 535 | for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) { |
| 536 | if (pPipelines[idx1] != VK_NULL_HANDLE) { |
| 537 | CreateObject(device, pPipelines[idx1], kVulkanObjectTypePipeline, pAllocator); |
| 538 | } |
| 539 | } |
| 540 | lock.unlock(); |
| 541 | return result; |
| 542 | } |
| 543 | |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 544 | VKAPI_ATTR VkResult VKAPI_CALL ResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 545 | VkDescriptorPoolResetFlags flags) { |
| 546 | bool skip = false; |
| 547 | std::unique_lock<std::mutex> lock(global_lock); |
| 548 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 549 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_32a05601, VALIDATION_ERROR_UNDEFINED); |
| 550 | skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_32a04601, |
| 551 | VALIDATION_ERROR_32a04607); |
| 552 | if (skip) { |
| 553 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 554 | } |
| 555 | // A DescriptorPool's descriptor sets are implicitly deleted when the pool is reset. |
| 556 | // Remove this pool's descriptor sets from our descriptorSet map. |
| 557 | auto itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin(); |
| 558 | while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 559 | ObjTrackState *pNode = (*itr).second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 560 | auto del_itr = itr++; |
| 561 | if (pNode->parent_object == HandleToUint64(descriptorPool)) { |
| 562 | DestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet, nullptr, |
| 563 | VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 564 | } |
| 565 | } |
| 566 | lock.unlock(); |
| 567 | VkResult result = get_dispatch_table(ot_device_table_map, device)->ResetDescriptorPool(device, descriptorPool, flags); |
| 568 | return result; |
| 569 | } |
| 570 | |
| 571 | VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer command_buffer, const VkCommandBufferBeginInfo *begin_info) { |
| 572 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(command_buffer), layer_data_map); |
| 573 | bool skip = false; |
| 574 | { |
| 575 | std::lock_guard<std::mutex> lock(global_lock); |
| 576 | skip |= ValidateObject(command_buffer, command_buffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_16e02401, |
| 577 | VALIDATION_ERROR_UNDEFINED); |
| 578 | if (begin_info) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 579 | ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)]; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 580 | if ((begin_info->pInheritanceInfo) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY) && |
| 581 | (begin_info->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) { |
| 582 | skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->framebuffer, kVulkanObjectTypeFramebuffer, |
| 583 | true, VALIDATION_ERROR_0280006e, VALIDATION_ERROR_02a00009); |
| 584 | skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->renderPass, kVulkanObjectTypeRenderPass, false, |
| 585 | VALIDATION_ERROR_0280006a, VALIDATION_ERROR_02a00009); |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | if (skip) { |
| 590 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 591 | } |
| 592 | VkResult result = get_dispatch_table(ot_device_table_map, command_buffer)->BeginCommandBuffer(command_buffer, begin_info); |
| 593 | return result; |
| 594 | } |
| 595 | |
| 596 | VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance, |
| 597 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 598 | const VkAllocationCallbacks *pAllocator, |
| 599 | VkDebugReportCallbackEXT *pCallback) { |
| 600 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance); |
| 601 | VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback); |
| 602 | if (VK_SUCCESS == result) { |
| 603 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 604 | result = layer_create_report_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pCallback); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 605 | CreateObject(instance, *pCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator); |
| 606 | } |
| 607 | return result; |
| 608 | } |
| 609 | |
| 610 | VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, |
| 611 | const VkAllocationCallbacks *pAllocator) { |
| 612 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance); |
| 613 | pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
| 614 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 615 | layer_destroy_report_callback(instance_data->report_data, msgCallback, pAllocator); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 616 | DestroyObject(instance, msgCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator, VALIDATION_ERROR_242009b4, |
| 617 | VALIDATION_ERROR_242009b6); |
| 618 | } |
| 619 | |
| 620 | VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 621 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 622 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
| 623 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance); |
| 624 | pInstanceTable->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
| 625 | } |
| 626 | |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 627 | // VK_EXT_debug_utils commands |
| 628 | VKAPI_ATTR VkResult VKAPI_CALL SetDebugUtilsObjectNameEXT(VkDevice device, const VkDebugUtilsObjectNameInfoEXT *pNameInfo) { |
| 629 | bool skip = VK_FALSE; |
| 630 | std::unique_lock<std::mutex> lock(global_lock); |
| 631 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 632 | lock.unlock(); |
| 633 | if (skip) { |
| 634 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 635 | } |
| 636 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 637 | if (pNameInfo->pObjectName) { |
| 638 | dev_data->report_data->debugUtilsObjectNameMap->insert( |
| 639 | std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->objectHandle, pNameInfo->pObjectName)); |
| 640 | } else { |
| 641 | dev_data->report_data->debugUtilsObjectNameMap->erase(pNameInfo->objectHandle); |
| 642 | } |
| 643 | VkResult result = dev_data->dispatch_table.SetDebugUtilsObjectNameEXT(device, pNameInfo); |
| 644 | return result; |
| 645 | } |
| 646 | |
| 647 | VKAPI_ATTR VkResult VKAPI_CALL SetDebugUtilsObjectTagEXT(VkDevice device, const VkDebugUtilsObjectTagInfoEXT *pTagInfo) { |
| 648 | bool skip = VK_FALSE; |
| 649 | std::unique_lock<std::mutex> lock(global_lock); |
| 650 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 651 | lock.unlock(); |
| 652 | if (skip) { |
| 653 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 654 | } |
| 655 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 656 | VkResult result = dev_data->dispatch_table.SetDebugUtilsObjectTagEXT(device, pTagInfo); |
| 657 | return result; |
| 658 | } |
| 659 | |
| 660 | VKAPI_ATTR void VKAPI_CALL QueueBeginDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 661 | bool skip = VK_FALSE; |
| 662 | std::unique_lock<std::mutex> lock(global_lock); |
| 663 | skip |= ValidateObject(queue, queue, kVulkanObjectTypeQueue, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 664 | lock.unlock(); |
| 665 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map); |
| 666 | if (!skip) { |
| 667 | BeginQueueDebugUtilsLabel(dev_data->report_data, queue, pLabelInfo); |
| 668 | if (dev_data->dispatch_table.QueueBeginDebugUtilsLabelEXT) { |
| 669 | dev_data->dispatch_table.QueueBeginDebugUtilsLabelEXT(queue, pLabelInfo); |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | VKAPI_ATTR void VKAPI_CALL QueueEndDebugUtilsLabelEXT(VkQueue queue) { |
| 675 | bool skip = VK_FALSE; |
| 676 | std::unique_lock<std::mutex> lock(global_lock); |
| 677 | skip |= ValidateObject(queue, queue, kVulkanObjectTypeQueue, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 678 | lock.unlock(); |
| 679 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map); |
| 680 | if (!skip) { |
| 681 | if (dev_data->dispatch_table.QueueEndDebugUtilsLabelEXT) { |
| 682 | dev_data->dispatch_table.QueueEndDebugUtilsLabelEXT(queue); |
| 683 | } |
| 684 | EndQueueDebugUtilsLabel(dev_data->report_data, queue); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | VKAPI_ATTR void VKAPI_CALL QueueInsertDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 689 | bool skip = VK_FALSE; |
| 690 | std::unique_lock<std::mutex> lock(global_lock); |
| 691 | skip |= ValidateObject(queue, queue, kVulkanObjectTypeQueue, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 692 | lock.unlock(); |
| 693 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map); |
| 694 | if (!skip) { |
| 695 | InsertQueueDebugUtilsLabel(dev_data->report_data, queue, pLabelInfo); |
| 696 | if (dev_data->dispatch_table.QueueInsertDebugUtilsLabelEXT) { |
| 697 | dev_data->dispatch_table.QueueInsertDebugUtilsLabelEXT(queue, pLabelInfo); |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | VKAPI_ATTR void VKAPI_CALL CmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 703 | bool skip = VK_FALSE; |
| 704 | std::unique_lock<std::mutex> lock(global_lock); |
| 705 | skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_UNDEFINED, |
| 706 | VALIDATION_ERROR_UNDEFINED); |
| 707 | lock.unlock(); |
| 708 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map); |
| 709 | if (!skip) { |
| 710 | BeginCmdDebugUtilsLabel(dev_data->report_data, commandBuffer, pLabelInfo); |
| 711 | if (dev_data->dispatch_table.CmdBeginDebugUtilsLabelEXT) { |
| 712 | dev_data->dispatch_table.CmdBeginDebugUtilsLabelEXT(commandBuffer, pLabelInfo); |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | VKAPI_ATTR void VKAPI_CALL CmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) { |
| 718 | bool skip = VK_FALSE; |
| 719 | std::unique_lock<std::mutex> lock(global_lock); |
| 720 | skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_UNDEFINED, |
| 721 | VALIDATION_ERROR_UNDEFINED); |
| 722 | lock.unlock(); |
| 723 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map); |
| 724 | if (!skip) { |
| 725 | if (dev_data->dispatch_table.CmdEndDebugUtilsLabelEXT) { |
| 726 | dev_data->dispatch_table.CmdEndDebugUtilsLabelEXT(commandBuffer); |
| 727 | } |
| 728 | EndCmdDebugUtilsLabel(dev_data->report_data, commandBuffer); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | VKAPI_ATTR void VKAPI_CALL CmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 733 | bool skip = VK_FALSE; |
| 734 | std::unique_lock<std::mutex> lock(global_lock); |
| 735 | skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_UNDEFINED, |
| 736 | VALIDATION_ERROR_UNDEFINED); |
| 737 | lock.unlock(); |
| 738 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map); |
| 739 | if (!skip) { |
| 740 | InsertCmdDebugUtilsLabel(dev_data->report_data, commandBuffer, pLabelInfo); |
| 741 | if (dev_data->dispatch_table.CmdInsertDebugUtilsLabelEXT) { |
| 742 | dev_data->dispatch_table.CmdInsertDebugUtilsLabelEXT(commandBuffer, pLabelInfo); |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | VKAPI_ATTR VkResult VKAPI_CALL CreateDebugUtilsMessengerEXT(VkInstance instance, |
| 748 | const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, |
| 749 | const VkAllocationCallbacks *pAllocator, |
| 750 | VkDebugUtilsMessengerEXT *pMessenger) { |
| 751 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance); |
| 752 | VkResult result = pInstanceTable->CreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger); |
| 753 | if (VK_SUCCESS == result) { |
| 754 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
| 755 | result = layer_create_messenger_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMessenger); |
| 756 | CreateObject(instance, *pMessenger, kVulkanObjectTypeDebugUtilsMessengerEXT, pAllocator); |
| 757 | } |
| 758 | return result; |
| 759 | } |
| 760 | |
| 761 | VKAPI_ATTR void VKAPI_CALL DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, |
| 762 | const VkAllocationCallbacks *pAllocator) { |
| 763 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance); |
| 764 | pInstanceTable->DestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator); |
| 765 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
| 766 | layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator); |
| 767 | DestroyObject(instance, messenger, kVulkanObjectTypeDebugUtilsMessengerEXT, pAllocator, VALIDATION_ERROR_UNDEFINED, |
| 768 | VALIDATION_ERROR_UNDEFINED); |
| 769 | } |
| 770 | |
| 771 | VKAPI_ATTR void VKAPI_CALL SubmitDebugUtilsMessageEXT(VkInstance instance, VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, |
| 772 | VkDebugUtilsMessageTypeFlagsEXT messageTypes, |
| 773 | const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData) { |
| 774 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance); |
| 775 | pInstanceTable->SubmitDebugUtilsMessageEXT(instance, messageSeverity, messageTypes, pCallbackData); |
| 776 | } |
| 777 | |
| 778 | static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}, |
| 779 | {VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION}}; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 780 | |
| 781 | static const VkLayerProperties globalLayerProps = {"VK_LAYER_LUNARG_object_tracker", |
| 782 | VK_LAYER_API_VERSION, // specVersion |
| 783 | 1, // implementationVersion |
| 784 | "LunarG Validation Layer"}; |
| 785 | |
| 786 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
| 787 | return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties); |
| 788 | } |
| 789 | |
| 790 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 791 | VkLayerProperties *pProperties) { |
| 792 | return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties); |
| 793 | } |
| 794 | |
| 795 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 796 | VkExtensionProperties *pProperties) { |
| 797 | if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName)) |
| 798 | return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties); |
| 799 | |
| 800 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 801 | } |
| 802 | |
| 803 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 804 | uint32_t *pCount, VkExtensionProperties *pProperties) { |
| 805 | if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName)) |
| 806 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
| 807 | |
| 808 | assert(physicalDevice); |
| 809 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(ot_instance_table_map, physicalDevice); |
| 810 | return pTable->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
| 811 | } |
| 812 | |
| 813 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 814 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
| 815 | std::lock_guard<std::mutex> lock(global_lock); |
| 816 | bool skip = ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_1fc27a01, |
| 817 | VALIDATION_ERROR_UNDEFINED); |
| 818 | if (skip) return VK_ERROR_VALIDATION_FAILED_EXT; |
| 819 | |
| 820 | layer_data *phy_dev_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
| 821 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 822 | |
| 823 | assert(chain_info->u.pLayerInfo); |
| 824 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 825 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
| 826 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(phy_dev_data->instance, "vkCreateDevice"); |
| 827 | if (fpCreateDevice == NULL) { |
| 828 | return VK_ERROR_INITIALIZATION_FAILED; |
| 829 | } |
| 830 | |
| 831 | // Advance the link info for the next element on the chain |
| 832 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 833 | |
| 834 | VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); |
| 835 | if (result != VK_SUCCESS) { |
| 836 | return result; |
| 837 | } |
| 838 | |
| 839 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 840 | device_data->report_data = layer_debug_utils_create_device(phy_dev_data->report_data, *pDevice); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 841 | layer_init_device_dispatch_table(*pDevice, &device_data->dispatch_table, fpGetDeviceProcAddr); |
| 842 | |
| 843 | // Add link back to physDev |
| 844 | device_data->physical_device = physicalDevice; |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 845 | device_data->instance = phy_dev_data->instance; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 846 | |
| 847 | initDeviceTable(*pDevice, fpGetDeviceProcAddr, ot_device_table_map); |
| 848 | |
Mark Lobodzinski | 9bd8119 | 2017-11-13 09:38:23 -0700 | [diff] [blame] | 849 | CreateObject(phy_dev_data->instance, *pDevice, kVulkanObjectTypeDevice, pAllocator); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 850 | |
| 851 | return result; |
| 852 | } |
| 853 | |
Mark Lobodzinski | 216843a | 2017-07-21 13:23:13 -0600 | [diff] [blame] | 854 | VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| 855 | VkImage *pSwapchainImages) { |
Mark Lobodzinski | 09fa2d4 | 2017-07-21 10:16:53 -0600 | [diff] [blame] | 856 | bool skip = false; |
Mark Lobodzinski | 216843a | 2017-07-21 13:23:13 -0600 | [diff] [blame] | 857 | std::unique_lock<std::mutex> lock(global_lock); |
| 858 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_30805601, VALIDATION_ERROR_UNDEFINED); |
Mark Lobodzinski | 09fa2d4 | 2017-07-21 10:16:53 -0600 | [diff] [blame] | 859 | skip |= ValidateObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, false, VALIDATION_ERROR_3082f001, |
| 860 | VALIDATION_ERROR_UNDEFINED); |
Mark Lobodzinski | 216843a | 2017-07-21 13:23:13 -0600 | [diff] [blame] | 861 | lock.unlock(); |
Mark Lobodzinski | 09fa2d4 | 2017-07-21 10:16:53 -0600 | [diff] [blame] | 862 | if (skip) return VK_ERROR_VALIDATION_FAILED_EXT; |
| 863 | |
Mark Lobodzinski | 216843a | 2017-07-21 13:23:13 -0600 | [diff] [blame] | 864 | VkResult result = get_dispatch_table(ot_device_table_map, device) |
| 865 | ->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); |
| 866 | if (pSwapchainImages != NULL) { |
| 867 | lock.lock(); |
| 868 | for (uint32_t i = 0; i < *pSwapchainImageCount; i++) { |
| 869 | CreateSwapchainImageObject(device, pSwapchainImages[i], swapchain); |
| 870 | } |
| 871 | lock.unlock(); |
| 872 | } |
| 873 | return result; |
| 874 | } |
| 875 | |
Petr Kraus | 42f6f8d | 2017-12-17 17:37:33 +0100 | [diff] [blame] | 876 | VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo, |
| 877 | const VkAllocationCallbacks *pAllocator, |
| 878 | VkDescriptorSetLayout *pSetLayout) { |
| 879 | bool skip = false; |
| 880 | { |
| 881 | std::lock_guard<std::mutex> lock(global_lock); |
| 882 | skip |= |
| 883 | ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_1f805601, VALIDATION_ERROR_UNDEFINED); |
| 884 | if (pCreateInfo) { |
| 885 | if (pCreateInfo->pBindings) { |
| 886 | for (uint32_t binding_index = 0; binding_index < pCreateInfo->bindingCount; ++binding_index) { |
| 887 | const VkDescriptorSetLayoutBinding &binding = pCreateInfo->pBindings[binding_index]; |
| 888 | const bool is_sampler_type = binding.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || |
| 889 | binding.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 890 | if (binding.pImmutableSamplers && is_sampler_type) { |
| 891 | for (uint32_t index2 = 0; index2 < binding.descriptorCount; ++index2) { |
| 892 | const VkSampler sampler = binding.pImmutableSamplers[index2]; |
| 893 | skip |= ValidateObject(device, sampler, kVulkanObjectTypeSampler, false, VALIDATION_ERROR_04e00234, |
| 894 | VALIDATION_ERROR_UNDEFINED); |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | if (skip) return VK_ERROR_VALIDATION_FAILED_EXT; |
| 902 | VkResult result = |
| 903 | get_dispatch_table(ot_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout); |
| 904 | if (VK_SUCCESS == result) { |
| 905 | std::lock_guard<std::mutex> lock(global_lock); |
| 906 | CreateObject(device, *pSetLayout, kVulkanObjectTypeDescriptorSetLayout, pAllocator); |
| 907 | } |
| 908 | return result; |
| 909 | } |
| 910 | |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 911 | VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 912 | uint32_t *pQueueFamilyPropertyCount, |
| 913 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
| 914 | bool skip = false; |
| 915 | { |
| 916 | std::lock_guard<std::mutex> lock(global_lock); |
| 917 | skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_2da27a01, |
| 918 | VALIDATION_ERROR_UNDEFINED); |
| 919 | } |
| 920 | if (skip) { |
| 921 | return; |
| 922 | } |
| 923 | get_dispatch_table(ot_instance_table_map, physicalDevice) |
| 924 | ->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
| 925 | std::lock_guard<std::mutex> lock(global_lock); |
| 926 | if (pQueueFamilyProperties != NULL) { |
| 927 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
| 928 | if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) { |
| 929 | instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount); |
| 930 | } |
| 931 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) { |
| 932 | instance_data->queue_family_properties[i] = pQueueFamilyProperties[i]; |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 938 | VkInstance *pInstance) { |
| 939 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 940 | |
| 941 | assert(chain_info->u.pLayerInfo); |
| 942 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 943 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
| 944 | if (fpCreateInstance == NULL) { |
| 945 | return VK_ERROR_INITIALIZATION_FAILED; |
| 946 | } |
| 947 | |
| 948 | // Advance the link info for the next element on the chain |
| 949 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 950 | |
| 951 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 952 | if (result != VK_SUCCESS) { |
| 953 | return result; |
| 954 | } |
| 955 | |
| 956 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map); |
| 957 | instance_data->instance = *pInstance; |
| 958 | initInstanceTable(*pInstance, fpGetInstanceProcAddr, ot_instance_table_map); |
| 959 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, *pInstance); |
| 960 | |
| 961 | // Look for one or more debug report create info structures, and copy the |
| 962 | // callback(s) for each one found (for use by vkDestroyInstance) |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 963 | layer_copy_tmp_debug_messengers(pCreateInfo->pNext, &instance_data->num_tmp_debug_messengers, |
| 964 | &instance_data->tmp_messenger_create_infos, &instance_data->tmp_debug_messengers); |
| 965 | layer_copy_tmp_report_callbacks(pCreateInfo->pNext, &instance_data->num_tmp_report_callbacks, |
| 966 | &instance_data->tmp_report_create_infos, &instance_data->tmp_report_callbacks); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 967 | |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 968 | instance_data->report_data = debug_utils_create_instance(pInstanceTable, *pInstance, pCreateInfo->enabledExtensionCount, |
| 969 | pCreateInfo->ppEnabledExtensionNames); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 970 | |
| 971 | InitObjectTracker(instance_data, pAllocator); |
| 972 | |
| 973 | CreateObject(*pInstance, *pInstance, kVulkanObjectTypeInstance, pAllocator); |
| 974 | |
| 975 | return result; |
| 976 | } |
| 977 | |
| 978 | VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 979 | VkPhysicalDevice *pPhysicalDevices) { |
| 980 | bool skip = VK_FALSE; |
| 981 | std::unique_lock<std::mutex> lock(global_lock); |
| 982 | skip |= |
| 983 | ValidateObject(instance, instance, kVulkanObjectTypeInstance, false, VALIDATION_ERROR_2800bc01, VALIDATION_ERROR_UNDEFINED); |
| 984 | lock.unlock(); |
| 985 | if (skip) { |
| 986 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 987 | } |
| 988 | VkResult result = get_dispatch_table(ot_instance_table_map, instance) |
| 989 | ->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
| 990 | lock.lock(); |
| 991 | if (result == VK_SUCCESS) { |
| 992 | if (pPhysicalDevices) { |
| 993 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
| 994 | CreateObject(instance, pPhysicalDevices[i], kVulkanObjectTypePhysicalDevice, nullptr); |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | lock.unlock(); |
| 999 | return result; |
| 1000 | } |
| 1001 | |
| 1002 | VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, |
| 1003 | VkCommandBuffer *pCommandBuffers) { |
| 1004 | bool skip = VK_FALSE; |
| 1005 | std::unique_lock<std::mutex> lock(global_lock); |
| 1006 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_16805601, VALIDATION_ERROR_UNDEFINED); |
| 1007 | skip |= ValidateObject(device, pAllocateInfo->commandPool, kVulkanObjectTypeCommandPool, false, VALIDATION_ERROR_02602801, |
| 1008 | VALIDATION_ERROR_UNDEFINED); |
| 1009 | lock.unlock(); |
| 1010 | |
| 1011 | if (skip) { |
| 1012 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1013 | } |
| 1014 | |
| 1015 | VkResult result = |
| 1016 | get_dispatch_table(ot_device_table_map, device)->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers); |
| 1017 | |
| 1018 | lock.lock(); |
| 1019 | for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) { |
| 1020 | AllocateCommandBuffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], pAllocateInfo->level); |
| 1021 | } |
| 1022 | lock.unlock(); |
| 1023 | |
| 1024 | return result; |
| 1025 | } |
| 1026 | |
| 1027 | VKAPI_ATTR VkResult VKAPI_CALL AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 1028 | VkDescriptorSet *pDescriptorSets) { |
| 1029 | bool skip = VK_FALSE; |
| 1030 | std::unique_lock<std::mutex> lock(global_lock); |
| 1031 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_16a05601, VALIDATION_ERROR_UNDEFINED); |
| 1032 | skip |= ValidateObject(device, pAllocateInfo->descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_04c04601, |
| 1033 | VALIDATION_ERROR_04c00009); |
| 1034 | for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { |
| 1035 | skip |= ValidateObject(device, pAllocateInfo->pSetLayouts[i], kVulkanObjectTypeDescriptorSetLayout, false, |
| 1036 | VALIDATION_ERROR_04c22c01, VALIDATION_ERROR_04c00009); |
| 1037 | } |
| 1038 | lock.unlock(); |
| 1039 | if (skip) { |
| 1040 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1041 | } |
| 1042 | |
| 1043 | VkResult result = |
| 1044 | get_dispatch_table(ot_device_table_map, device)->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets); |
| 1045 | |
| 1046 | if (VK_SUCCESS == result) { |
| 1047 | lock.lock(); |
| 1048 | for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { |
| 1049 | AllocateDescriptorSet(device, pAllocateInfo->descriptorPool, pDescriptorSets[i]); |
| 1050 | } |
| 1051 | lock.unlock(); |
| 1052 | } |
| 1053 | |
| 1054 | return result; |
| 1055 | } |
| 1056 | |
| 1057 | VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, |
| 1058 | const VkCommandBuffer *pCommandBuffers) { |
| 1059 | bool skip = false; |
| 1060 | std::unique_lock<std::mutex> lock(global_lock); |
| 1061 | ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_28405601, VALIDATION_ERROR_UNDEFINED); |
| 1062 | ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, false, VALIDATION_ERROR_28402801, VALIDATION_ERROR_28402807); |
| 1063 | for (uint32_t i = 0; i < commandBufferCount; i++) { |
| 1064 | if (pCommandBuffers[i] != VK_NULL_HANDLE) { |
| 1065 | skip |= ValidateCommandBuffer(device, commandPool, pCommandBuffers[i]); |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | for (uint32_t i = 0; i < commandBufferCount; i++) { |
| 1070 | DestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer, nullptr, VALIDATION_ERROR_UNDEFINED, |
| 1071 | VALIDATION_ERROR_UNDEFINED); |
| 1072 | } |
| 1073 | |
| 1074 | lock.unlock(); |
| 1075 | if (!skip) { |
| 1076 | get_dispatch_table(ot_device_table_map, device) |
| 1077 | ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | VKAPI_ATTR void VKAPI_CALL DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) { |
| 1082 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 1083 | std::unique_lock<std::mutex> lock(global_lock); |
| 1084 | // A swapchain's images are implicitly deleted when the swapchain is deleted. |
| 1085 | // Remove this swapchain's images from our map of such images. |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 1086 | std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->swapchainImageMap.begin(); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1087 | while (itr != device_data->swapchainImageMap.end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 1088 | ObjTrackState *pNode = (*itr).second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1089 | if (pNode->parent_object == HandleToUint64(swapchain)) { |
| 1090 | delete pNode; |
| 1091 | auto delete_item = itr++; |
| 1092 | device_data->swapchainImageMap.erase(delete_item); |
| 1093 | } else { |
| 1094 | ++itr; |
| 1095 | } |
| 1096 | } |
| 1097 | DestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, pAllocator, VALIDATION_ERROR_26e00a06, |
| 1098 | VALIDATION_ERROR_26e00a08); |
| 1099 | lock.unlock(); |
| 1100 | |
| 1101 | get_dispatch_table(ot_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator); |
| 1102 | } |
| 1103 | |
| 1104 | VKAPI_ATTR VkResult VKAPI_CALL FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, |
| 1105 | const VkDescriptorSet *pDescriptorSets) { |
| 1106 | bool skip = false; |
| 1107 | VkResult result = VK_ERROR_VALIDATION_FAILED_EXT; |
| 1108 | std::unique_lock<std::mutex> lock(global_lock); |
| 1109 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_28605601, VALIDATION_ERROR_UNDEFINED); |
| 1110 | skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_28604601, |
| 1111 | VALIDATION_ERROR_28604607); |
| 1112 | for (uint32_t i = 0; i < descriptorSetCount; i++) { |
| 1113 | if (pDescriptorSets[i] != VK_NULL_HANDLE) { |
| 1114 | skip |= ValidateDescriptorSet(device, descriptorPool, pDescriptorSets[i]); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | for (uint32_t i = 0; i < descriptorSetCount; i++) { |
| 1119 | DestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet, nullptr, VALIDATION_ERROR_UNDEFINED, |
| 1120 | VALIDATION_ERROR_UNDEFINED); |
| 1121 | } |
| 1122 | |
| 1123 | lock.unlock(); |
| 1124 | if (!skip) { |
| 1125 | result = get_dispatch_table(ot_device_table_map, device) |
| 1126 | ->FreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets); |
| 1127 | } |
| 1128 | return result; |
| 1129 | } |
| 1130 | |
| 1131 | VKAPI_ATTR void VKAPI_CALL DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 1132 | const VkAllocationCallbacks *pAllocator) { |
| 1133 | bool skip = VK_FALSE; |
| 1134 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 1135 | std::unique_lock<std::mutex> lock(global_lock); |
| 1136 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_24405601, VALIDATION_ERROR_UNDEFINED); |
| 1137 | skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, true, VALIDATION_ERROR_24404601, |
| 1138 | VALIDATION_ERROR_24404607); |
| 1139 | lock.unlock(); |
| 1140 | if (skip) { |
| 1141 | return; |
| 1142 | } |
| 1143 | // A DescriptorPool's descriptor sets are implicitly deleted when the pool is deleted. |
| 1144 | // Remove this pool's descriptor sets from our descriptorSet map. |
| 1145 | lock.lock(); |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 1146 | std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin(); |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1147 | while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 1148 | ObjTrackState *pNode = (*itr).second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1149 | auto del_itr = itr++; |
| 1150 | if (pNode->parent_object == HandleToUint64(descriptorPool)) { |
| 1151 | DestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet, nullptr, |
| 1152 | VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 1153 | } |
| 1154 | } |
| 1155 | DestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, pAllocator, VALIDATION_ERROR_24400260, |
| 1156 | VALIDATION_ERROR_24400262); |
| 1157 | lock.unlock(); |
| 1158 | get_dispatch_table(ot_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator); |
| 1159 | } |
| 1160 | |
| 1161 | VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) { |
| 1162 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 1163 | bool skip = false; |
| 1164 | std::unique_lock<std::mutex> lock(global_lock); |
| 1165 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_24005601, VALIDATION_ERROR_UNDEFINED); |
| 1166 | skip |= ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, true, VALIDATION_ERROR_24002801, |
| 1167 | VALIDATION_ERROR_24002807); |
| 1168 | lock.unlock(); |
| 1169 | if (skip) { |
| 1170 | return; |
| 1171 | } |
| 1172 | lock.lock(); |
| 1173 | // A CommandPool's command buffers are implicitly deleted when the pool is deleted. |
| 1174 | // Remove this pool's cmdBuffers from our cmd buffer map. |
| 1175 | auto itr = device_data->object_map[kVulkanObjectTypeCommandBuffer].begin(); |
| 1176 | auto del_itr = itr; |
| 1177 | while (itr != device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) { |
Mark Lobodzinski | efc6439 | 2017-07-18 13:15:47 -0600 | [diff] [blame] | 1178 | ObjTrackState *pNode = (*itr).second; |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1179 | del_itr = itr++; |
| 1180 | if (pNode->parent_object == HandleToUint64(commandPool)) { |
| 1181 | skip |= ValidateCommandBuffer(device, commandPool, reinterpret_cast<VkCommandBuffer>((*del_itr).first)); |
| 1182 | DestroyObject(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first), kVulkanObjectTypeCommandBuffer, nullptr, |
| 1183 | VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED); |
| 1184 | } |
| 1185 | } |
| 1186 | DestroyObject(device, commandPool, kVulkanObjectTypeCommandPool, pAllocator, VALIDATION_ERROR_24000054, |
| 1187 | VALIDATION_ERROR_24000056); |
| 1188 | lock.unlock(); |
| 1189 | get_dispatch_table(ot_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator); |
| 1190 | } |
| 1191 | |
Mark Lobodzinski | 14ddc19 | 2017-10-25 16:57:04 -0600 | [diff] [blame] | 1192 | // Note: This is the core version of this routine. The extension version is below. |
| 1193 | VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 1194 | uint32_t *pQueueFamilyPropertyCount, |
| 1195 | VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 1196 | bool skip = false; |
| 1197 | { |
| 1198 | std::lock_guard<std::mutex> lock(global_lock); |
| 1199 | skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_UNDEFINED, |
| 1200 | VALIDATION_ERROR_UNDEFINED); |
| 1201 | } |
| 1202 | if (skip) { |
| 1203 | return; |
| 1204 | } |
| 1205 | get_dispatch_table(ot_instance_table_map, physicalDevice) |
| 1206 | ->GetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
| 1207 | std::lock_guard<std::mutex> lock(global_lock); |
| 1208 | if (pQueueFamilyProperties != NULL) { |
| 1209 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
| 1210 | if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) { |
| 1211 | instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount); |
| 1212 | } |
| 1213 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) { |
| 1214 | instance_data->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties; |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | // Note: This is the extension version of this routine. The core version is above. |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1220 | VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, |
| 1221 | uint32_t *pQueueFamilyPropertyCount, |
| 1222 | VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 1223 | bool skip = false; |
| 1224 | { |
| 1225 | std::lock_guard<std::mutex> lock(global_lock); |
| 1226 | skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_UNDEFINED, |
| 1227 | VALIDATION_ERROR_UNDEFINED); |
| 1228 | } |
| 1229 | if (skip) { |
| 1230 | return; |
| 1231 | } |
| 1232 | get_dispatch_table(ot_instance_table_map, physicalDevice) |
| 1233 | ->GetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
| 1234 | std::lock_guard<std::mutex> lock(global_lock); |
| 1235 | if (pQueueFamilyProperties != NULL) { |
| 1236 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
| 1237 | if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) { |
| 1238 | instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount); |
| 1239 | } |
| 1240 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) { |
| 1241 | instance_data->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties; |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
Mark Lobodzinski | dfe5e17 | 2017-07-19 13:03:22 -0600 | [diff] [blame] | 1246 | VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) { |
Mark Lobodzinski | b2de97f | 2017-07-06 15:28:11 -0600 | [diff] [blame] | 1247 | bool skip = VK_FALSE; |
| 1248 | std::unique_lock<std::mutex> lock(global_lock); |
| 1249 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 1250 | if (pNameInfo->pObjectName) { |
| 1251 | dev_data->report_data->debugObjectNameMap->insert( |
| 1252 | std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName)); |
| 1253 | } else { |
| 1254 | dev_data->report_data->debugObjectNameMap->erase(pNameInfo->object); |
| 1255 | } |
| 1256 | skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_23605601, VALIDATION_ERROR_UNDEFINED); |
| 1257 | lock.unlock(); |
| 1258 | if (skip) { |
| 1259 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1260 | } |
| 1261 | VkResult result = dev_data->dispatch_table.DebugMarkerSetObjectNameEXT(device, pNameInfo); |
| 1262 | return result; |
| 1263 | } |
| 1264 | |
| 1265 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { |
| 1266 | assert(instance); |
| 1267 | |
| 1268 | if (get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr == NULL) { |
| 1269 | return NULL; |
| 1270 | } |
| 1271 | return get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr(instance, funcName); |
| 1272 | } |
| 1273 | |
| 1274 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| 1275 | const auto item = name_to_funcptr_map.find(funcName); |
| 1276 | if (item != name_to_funcptr_map.end()) { |
| 1277 | return reinterpret_cast<PFN_vkVoidFunction>(item->second); |
| 1278 | } |
| 1279 | |
| 1280 | auto table = get_dispatch_table(ot_device_table_map, device); |
| 1281 | if (!table->GetDeviceProcAddr) return NULL; |
| 1282 | return table->GetDeviceProcAddr(device, funcName); |
| 1283 | } |
| 1284 | |
| 1285 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| 1286 | const auto item = name_to_funcptr_map.find(funcName); |
| 1287 | if (item != name_to_funcptr_map.end()) { |
| 1288 | return reinterpret_cast<PFN_vkVoidFunction>(item->second); |
| 1289 | } |
| 1290 | |
| 1291 | auto table = get_dispatch_table(ot_instance_table_map, instance); |
| 1292 | if (!table->GetInstanceProcAddr) return nullptr; |
| 1293 | return table->GetInstanceProcAddr(instance, funcName); |
| 1294 | } |
| 1295 | |
| 1296 | } // namespace object_tracker |
| 1297 | |
| 1298 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 1299 | VkExtensionProperties *pProperties) { |
| 1300 | return object_tracker::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
| 1301 | } |
| 1302 | |
| 1303 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, |
| 1304 | VkLayerProperties *pProperties) { |
| 1305 | return object_tracker::EnumerateInstanceLayerProperties(pCount, pProperties); |
| 1306 | } |
| 1307 | |
| 1308 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 1309 | VkLayerProperties *pProperties) { |
| 1310 | // The layer command handles VK_NULL_HANDLE just fine internally |
| 1311 | assert(physicalDevice == VK_NULL_HANDLE); |
| 1312 | return object_tracker::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
| 1313 | } |
| 1314 | |
| 1315 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { |
| 1316 | return object_tracker::GetDeviceProcAddr(dev, funcName); |
| 1317 | } |
| 1318 | |
| 1319 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| 1320 | return object_tracker::GetInstanceProcAddr(instance, funcName); |
| 1321 | } |
| 1322 | |
| 1323 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 1324 | const char *pLayerName, uint32_t *pCount, |
| 1325 | VkExtensionProperties *pProperties) { |
| 1326 | // The layer command handles VK_NULL_HANDLE just fine internally |
| 1327 | assert(physicalDevice == VK_NULL_HANDLE); |
| 1328 | return object_tracker::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
| 1329 | } |
| 1330 | |
| 1331 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, |
| 1332 | const char *funcName) { |
| 1333 | return object_tracker::GetPhysicalDeviceProcAddr(instance, funcName); |
| 1334 | } |
| 1335 | |
| 1336 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { |
| 1337 | assert(pVersionStruct != NULL); |
| 1338 | assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); |
| 1339 | |
| 1340 | // Fill in the function pointers if our version is at least capable of having the structure contain them. |
| 1341 | if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { |
| 1342 | pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 1343 | pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 1344 | pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; |
| 1345 | } |
| 1346 | |
| 1347 | if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1348 | object_tracker::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion; |
| 1349 | } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1350 | pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 1351 | } |
| 1352 | |
| 1353 | return VK_SUCCESS; |
| 1354 | } |