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.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Author: Mark Lobodzinski <mark@lunarg.com>
19 * Author: Jon Ashburn <jon@lunarg.com>
20 * Author: Tobin Ehlis <tobin@lunarg.com>
23 #include "object_tracker.h"
25 namespace object_tracker {
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;
34 void InitObjectTracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
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");
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()) {
44 ObjTrackQueueInfo *p_queue_info = new ObjTrackQueueInfo;
45 if (p_queue_info != NULL) {
46 memset(p_queue_info, 0, sizeof(ObjTrackQueueInfo));
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;
51 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
52 HandleToUint64(queue), OBJTRACK_INTERNAL_ERROR,
53 "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");
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);
62 for (auto queue_item : device_data->queue_info_map) {
63 delete queue_item.second;
65 device_data->queue_info_map.clear();
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,
76 queue->second->handle, OBJTRACK_NONE,
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]);
80 queue = device_data->object_map[kVulkanObjectTypeQueue].erase(queue);
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()) {
89 ObjTrackQueueInfo *pQueueInfo = queue_item->second;
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) ==
94 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
95 HandleToUint64(queue), VALIDATION_ERROR_31600011,
96 "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set.", function);
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;
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,
118 invalid_handle_code, "Invalid Device Object 0x%" PRIxLEAST64 ".", device_handle);
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);
125 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
126 HandleToUint64(command_buffer), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
127 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT", HandleToUint64(command_buffer));
129 ObjTrackState *pNewObjNode = new ObjTrackState;
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;
136 pNewObjNode->status = OBJSTATUS_NONE;
138 device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)] = pNewObjNode;
139 device_data->num_objects[kVulkanObjectTypeCommandBuffer]++;
140 device_data->num_total_objects++;
143 bool ValidateCommandBuffer(VkDevice device, VkCommandPool command_pool, VkCommandBuffer command_buffer) {
144 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
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()) {
149 ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)];
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,
153 object_handle, VALIDATION_ERROR_28411407,
154 "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64
155 " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
156 HandleToUint64(command_buffer), pNode->parent_object, HandleToUint64(command_pool));
159 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
160 object_handle, VALIDATION_ERROR_28400060, "Invalid %s Object 0x%" PRIxLEAST64 ".",
161 object_string[kVulkanObjectTypeCommandBuffer], object_handle);
166 void AllocateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
167 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
169 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
170 HandleToUint64(descriptor_set), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
171 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT", HandleToUint64(descriptor_set));
173 ObjTrackState *pNewObjNode = new ObjTrackState;
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++;
183 bool ValidateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
184 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
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()) {
189 ObjTrackState *pNode = dsItem->second;
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,
193 object_handle, VALIDATION_ERROR_28613007,
194 "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64
195 " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
196 HandleToUint64(descriptor_set), pNode->parent_object, HandleToUint64(descriptor_pool));
199 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
200 object_handle, VALIDATION_ERROR_2860026c, "Invalid %s Object 0x%" PRIxLEAST64 ".",
201 object_string[kVulkanObjectTypeDescriptorSet], object_handle);
206 template <typename DispObj>
207 static bool ValidateDescriptorWrite(DispObj disp, VkWriteDescriptorSet const *desc, bool isPush) {
210 if (!isPush && desc->dstSet) {
211 skip |= ValidateObject(disp, desc->dstSet, kVulkanObjectTypeDescriptorSet, false, VALIDATION_ERROR_15c00280,
212 VALIDATION_ERROR_15c00009);
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) {
218 skip |= ValidateObject(disp, desc->pTexelBufferView[idx2], kVulkanObjectTypeBufferView, false,
219 VALIDATION_ERROR_15c00286, VALIDATION_ERROR_15c00009);
223 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
224 (desc->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
225 (desc->descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
226 for (uint32_t idx3 = 0; idx3 < desc->descriptorCount; ++idx3) {
227 skip |= ValidateObject(disp, desc->pImageInfo[idx3].imageView, kVulkanObjectTypeImageView, false,
228 VALIDATION_ERROR_15c0028c, VALIDATION_ERROR_04600009);
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) {
238 skip |= ValidateObject(disp, desc->pBufferInfo[idx4].buffer, kVulkanObjectTypeBuffer, false,
239 VALIDATION_ERROR_04401a01, VALIDATION_ERROR_UNDEFINED);
247 VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
248 VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount,
249 const VkWriteDescriptorSet *pDescriptorWrites) {
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) {
259 skip |= ValidateDescriptorWrite(commandBuffer, &pDescriptorWrites[index0], true);
264 get_dispatch_table(ot_device_table_map, commandBuffer)
265 ->CmdPushDescriptorSetKHR(commandBuffer, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites);
268 void CreateQueue(VkDevice device, VkQueue vkObj) {
269 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
271 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
272 HandleToUint64(vkObj), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
273 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT", HandleToUint64(vkObj));
275 ObjTrackState *p_obj_node = NULL;
276 auto queue_item = device_data->object_map[kVulkanObjectTypeQueue].find(HandleToUint64(vkObj));
277 if (queue_item == device_data->object_map[kVulkanObjectTypeQueue].end()) {
278 p_obj_node = new ObjTrackState;
279 device_data->object_map[kVulkanObjectTypeQueue][HandleToUint64(vkObj)] = p_obj_node;
280 device_data->num_objects[kVulkanObjectTypeQueue]++;
281 device_data->num_total_objects++;
283 p_obj_node = queue_item->second;
285 p_obj_node->object_type = kVulkanObjectTypeQueue;
286 p_obj_node->status = OBJSTATUS_NONE;
287 p_obj_node->handle = HandleToUint64(vkObj);
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,
293 HandleToUint64(swapchain_image), OBJTRACK_NONE, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
294 object_track_index++, "SwapchainImage", HandleToUint64(swapchain_image));
296 ObjTrackState *pNewObjNode = new ObjTrackState;
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;
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);
306 for (const auto &item : device_data->object_map[object_type]) {
307 const ObjTrackState *object_info = item.second;
308 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[object_type], object_info->handle,
309 error_code, "OBJ ERROR : For device 0x%" PRIxLEAST64 ", %s object 0x%" PRIxLEAST64 " has not been destroyed.",
310 HandleToUint64(device), object_string[object_type], object_info->handle);
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();
319 ObjTrackState *object_info = item->second;
320 DestroyObjectSilently(device, object_info->handle, object_type);
324 VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
325 std::unique_lock<std::mutex> lock(global_lock);
327 dispatch_key key = get_dispatch_key(instance);
328 layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
330 // Enable the temporary callback(s) here to catch cleanup issues:
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);
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);
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);
343 // Destroy physical devices
344 for (auto iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
345 iit != instance_data->object_map[kVulkanObjectTypePhysicalDevice].end();) {
346 ObjTrackState *pNode = iit->second;
347 VkPhysicalDevice physical_device = reinterpret_cast<VkPhysicalDevice>(pNode->handle);
349 DestroyObject(instance, physical_device, kVulkanObjectTypePhysicalDevice, nullptr, VALIDATION_ERROR_UNDEFINED,
350 VALIDATION_ERROR_UNDEFINED);
351 iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
354 // Destroy child devices
355 for (auto iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
356 iit != instance_data->object_map[kVulkanObjectTypeDevice].end();) {
357 ObjTrackState *pNode = iit->second;
359 VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
360 VkDebugReportObjectTypeEXT debug_object_type = get_debug_report_enum[pNode->object_type];
362 log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, debug_object_type, pNode->handle, OBJTRACK_OBJECT_LEAK,
363 "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.",
364 string_VkDebugReportObjectTypeEXT(debug_object_type), pNode->handle);
366 // Report any remaining objects in LL
367 ReportUndestroyedObjects(device, VALIDATION_ERROR_258004ea);
368 DestroyUndestroyedObjects(device);
370 DestroyObject(instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_258004ec, VALIDATION_ERROR_258004ee);
371 iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
374 instance_data->object_map[kVulkanObjectTypeDevice].clear();
376 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
377 pInstanceTable->DestroyInstance(instance, pAllocator);
379 // Disable and cleanup the temporary callback(s):
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;
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;
393 // Clean up logging callback, if any
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();
399 while (instance_data->logging_callback.size() > 0) {
400 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
401 layer_destroy_report_callback(instance_data->report_data, callback, pAllocator);
402 instance_data->logging_callback.pop_back();
405 DestroyObject(instance, instance, kVulkanObjectTypeInstance, pAllocator, VALIDATION_ERROR_258004ec, VALIDATION_ERROR_258004ee);
407 layer_debug_utils_destroy_instance(instance_data->report_data);
408 FreeLayerDataPtr(key, layer_data_map);
411 ot_instance_table_map.erase(key);
412 delete pInstanceTable;
415 VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
416 std::unique_lock<std::mutex> lock(global_lock);
417 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
418 ValidateObject(device, device, kVulkanObjectTypeDevice, true, VALIDATION_ERROR_24a05601, VALIDATION_ERROR_UNDEFINED);
419 DestroyObject(device_data->instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_24a002f6,
420 VALIDATION_ERROR_24a002f8);
422 // Report any remaining objects associated with this VkDevice object in LL
423 ReportUndestroyedObjects(device, VALIDATION_ERROR_24a002f4);
424 DestroyUndestroyedObjects(device);
426 // Clean up Queue's MemRef Linked Lists
427 DestroyQueueDataStructures(device);
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);
437 FreeLayerDataPtr(key, layer_data_map);
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);
445 get_dispatch_table(ot_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
448 CreateQueue(device, *pQueue);
449 AddQueueInfo(device, queueFamilyIndex, *pQueue);
452 VKAPI_ATTR void VKAPI_CALL GetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
453 std::unique_lock<std::mutex> lock(global_lock);
454 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_43405601, VALIDATION_ERROR_UNDEFINED);
457 get_dispatch_table(ot_device_table_map, device)->GetDeviceQueue2(device, pQueueInfo, pQueue);
460 if (*pQueue != VK_NULL_HANDLE) {
461 CreateQueue(device, *pQueue);
462 AddQueueInfo(device, pQueueInfo->queueFamilyIndex, *pQueue);
466 VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
467 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
468 const VkCopyDescriptorSet *pDescriptorCopies) {
471 std::lock_guard<std::mutex> lock(global_lock);
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);
480 if (pDescriptorCopies[idx0].srcSet) {
481 skip |= ValidateObject(device, pDescriptorCopies[idx0].srcSet, kVulkanObjectTypeDescriptorSet, false,
482 VALIDATION_ERROR_0322d201, VALIDATION_ERROR_03200009);
486 if (pDescriptorWrites) {
487 for (uint32_t idx1 = 0; idx1 < descriptorWriteCount; ++idx1) {
488 skip |= ValidateDescriptorWrite(device, &pDescriptorWrites[idx1], false);
495 get_dispatch_table(ot_device_table_map, device)
496 ->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
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);
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);
511 if (pCreateInfos[idx0].layout) {
512 skip |= ValidateObject(device, pCreateInfos[idx0].layout, kVulkanObjectTypePipelineLayout, false,
513 VALIDATION_ERROR_0300be01, VALIDATION_ERROR_03000009);
515 if (pCreateInfos[idx0].stage.module) {
516 skip |= ValidateObject(device, pCreateInfos[idx0].stage.module, kVulkanObjectTypeShaderModule, false,
517 VALIDATION_ERROR_1060d201, VALIDATION_ERROR_UNDEFINED);
522 skip |= ValidateObject(device, pipelineCache, kVulkanObjectTypePipelineCache, true, VALIDATION_ERROR_1f228001,
523 VALIDATION_ERROR_1f228007);
527 for (uint32_t i = 0; i < createInfoCount; i++) {
528 pPipelines[i] = VK_NULL_HANDLE;
530 return VK_ERROR_VALIDATION_FAILED_EXT;
532 VkResult result = get_dispatch_table(ot_device_table_map, device)
533 ->CreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
535 for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) {
536 if (pPipelines[idx1] != VK_NULL_HANDLE) {
537 CreateObject(device, pPipelines[idx1], kVulkanObjectTypePipeline, pAllocator);
544 VKAPI_ATTR VkResult VKAPI_CALL ResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
545 VkDescriptorPoolResetFlags flags) {
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);
553 return VK_ERROR_VALIDATION_FAILED_EXT;
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()) {
559 ObjTrackState *pNode = (*itr).second;
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);
567 VkResult result = get_dispatch_table(ot_device_table_map, device)->ResetDescriptorPool(device, descriptorPool, flags);
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);
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);
579 ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)];
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);
590 return VK_ERROR_VALIDATION_FAILED_EXT;
592 VkResult result = get_dispatch_table(ot_device_table_map, command_buffer)->BeginCommandBuffer(command_buffer, begin_info);
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);
604 result = layer_create_report_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pCallback);
605 CreateObject(instance, *pCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator);
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);
615 layer_destroy_report_callback(instance_data->report_data, msgCallback, pAllocator);
616 DestroyObject(instance, msgCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator, VALIDATION_ERROR_242009b4,
617 VALIDATION_ERROR_242009b6);
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);
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);
634 return VK_ERROR_VALIDATION_FAILED_EXT;
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));
641 dev_data->report_data->debugUtilsObjectNameMap->erase(pNameInfo->objectHandle);
643 VkResult result = dev_data->dispatch_table.SetDebugUtilsObjectNameEXT(device, pNameInfo);
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);
653 return VK_ERROR_VALIDATION_FAILED_EXT;
655 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
656 VkResult result = dev_data->dispatch_table.SetDebugUtilsObjectTagEXT(device, pTagInfo);
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);
665 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
667 BeginQueueDebugUtilsLabel(dev_data->report_data, queue, pLabelInfo);
668 if (dev_data->dispatch_table.QueueBeginDebugUtilsLabelEXT) {
669 dev_data->dispatch_table.QueueBeginDebugUtilsLabelEXT(queue, pLabelInfo);
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);
679 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
681 if (dev_data->dispatch_table.QueueEndDebugUtilsLabelEXT) {
682 dev_data->dispatch_table.QueueEndDebugUtilsLabelEXT(queue);
684 EndQueueDebugUtilsLabel(dev_data->report_data, queue);
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);
693 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
695 InsertQueueDebugUtilsLabel(dev_data->report_data, queue, pLabelInfo);
696 if (dev_data->dispatch_table.QueueInsertDebugUtilsLabelEXT) {
697 dev_data->dispatch_table.QueueInsertDebugUtilsLabelEXT(queue, pLabelInfo);
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);
708 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
710 BeginCmdDebugUtilsLabel(dev_data->report_data, commandBuffer, pLabelInfo);
711 if (dev_data->dispatch_table.CmdBeginDebugUtilsLabelEXT) {
712 dev_data->dispatch_table.CmdBeginDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
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);
723 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
725 if (dev_data->dispatch_table.CmdEndDebugUtilsLabelEXT) {
726 dev_data->dispatch_table.CmdEndDebugUtilsLabelEXT(commandBuffer);
728 EndCmdDebugUtilsLabel(dev_data->report_data, commandBuffer);
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);
738 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
740 InsertCmdDebugUtilsLabel(dev_data->report_data, commandBuffer, pLabelInfo);
741 if (dev_data->dispatch_table.CmdInsertDebugUtilsLabelEXT) {
742 dev_data->dispatch_table.CmdInsertDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
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);
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);
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);
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}};
781 static const VkLayerProperties globalLayerProps = {"VK_LAYER_LUNARG_object_tracker",
782 VK_LAYER_API_VERSION, // specVersion
783 1, // implementationVersion
784 "LunarG Validation Layer"};
786 VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
787 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
790 VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
791 VkLayerProperties *pProperties) {
792 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
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);
800 return VK_ERROR_LAYER_NOT_PRESENT;
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);
808 assert(physicalDevice);
809 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(ot_instance_table_map, physicalDevice);
810 return pTable->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);
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;
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);
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;
831 // Advance the link info for the next element on the chain
832 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
834 VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
835 if (result != VK_SUCCESS) {
839 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
840 device_data->report_data = layer_debug_utils_create_device(phy_dev_data->report_data, *pDevice);
841 layer_init_device_dispatch_table(*pDevice, &device_data->dispatch_table, fpGetDeviceProcAddr);
843 // Add link back to physDev
844 device_data->physical_device = physicalDevice;
845 device_data->instance = phy_dev_data->instance;
847 initDeviceTable(*pDevice, fpGetDeviceProcAddr, ot_device_table_map);
849 CreateObject(phy_dev_data->instance, *pDevice, kVulkanObjectTypeDevice, pAllocator);
854 VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
855 VkImage *pSwapchainImages) {
857 std::unique_lock<std::mutex> lock(global_lock);
858 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_30805601, VALIDATION_ERROR_UNDEFINED);
859 skip |= ValidateObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, false, VALIDATION_ERROR_3082f001,
860 VALIDATION_ERROR_UNDEFINED);
862 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
864 VkResult result = get_dispatch_table(ot_device_table_map, device)
865 ->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
866 if (pSwapchainImages != NULL) {
868 for (uint32_t i = 0; i < *pSwapchainImageCount; i++) {
869 CreateSwapchainImageObject(device, pSwapchainImages[i], swapchain);
876 VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
877 const VkAllocationCallbacks *pAllocator,
878 VkDescriptorSetLayout *pSetLayout) {
881 std::lock_guard<std::mutex> lock(global_lock);
883 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_1f805601, VALIDATION_ERROR_UNDEFINED);
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);
901 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
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);
911 VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
912 uint32_t *pQueueFamilyPropertyCount,
913 VkQueueFamilyProperties *pQueueFamilyProperties) {
916 std::lock_guard<std::mutex> lock(global_lock);
917 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_2da27a01,
918 VALIDATION_ERROR_UNDEFINED);
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);
931 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
932 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i];
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);
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;
948 // Advance the link info for the next element on the chain
949 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
951 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
952 if (result != VK_SUCCESS) {
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);
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)
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);
968 instance_data->report_data = debug_utils_create_instance(pInstanceTable, *pInstance, pCreateInfo->enabledExtensionCount,
969 pCreateInfo->ppEnabledExtensionNames);
971 InitObjectTracker(instance_data, pAllocator);
973 CreateObject(*pInstance, *pInstance, kVulkanObjectTypeInstance, pAllocator);
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);
983 ValidateObject(instance, instance, kVulkanObjectTypeInstance, false, VALIDATION_ERROR_2800bc01, VALIDATION_ERROR_UNDEFINED);
986 return VK_ERROR_VALIDATION_FAILED_EXT;
988 VkResult result = get_dispatch_table(ot_instance_table_map, instance)
989 ->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
991 if (result == VK_SUCCESS) {
992 if (pPhysicalDevices) {
993 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
994 CreateObject(instance, pPhysicalDevices[i], kVulkanObjectTypePhysicalDevice, nullptr);
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);
1012 return VK_ERROR_VALIDATION_FAILED_EXT;
1016 get_dispatch_table(ot_device_table_map, device)->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
1019 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
1020 AllocateCommandBuffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], pAllocateInfo->level);
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);
1040 return VK_ERROR_VALIDATION_FAILED_EXT;
1044 get_dispatch_table(ot_device_table_map, device)->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
1046 if (VK_SUCCESS == result) {
1048 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
1049 AllocateDescriptorSet(device, pAllocateInfo->descriptorPool, pDescriptorSets[i]);
1057 VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
1058 const VkCommandBuffer *pCommandBuffers) {
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]);
1069 for (uint32_t i = 0; i < commandBufferCount; i++) {
1070 DestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer, nullptr, VALIDATION_ERROR_UNDEFINED,
1071 VALIDATION_ERROR_UNDEFINED);
1076 get_dispatch_table(ot_device_table_map, device)
1077 ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
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.
1086 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->swapchainImageMap.begin();
1087 while (itr != device_data->swapchainImageMap.end()) {
1088 ObjTrackState *pNode = (*itr).second;
1089 if (pNode->parent_object == HandleToUint64(swapchain)) {
1091 auto delete_item = itr++;
1092 device_data->swapchainImageMap.erase(delete_item);
1097 DestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, pAllocator, VALIDATION_ERROR_26e00a06,
1098 VALIDATION_ERROR_26e00a08);
1101 get_dispatch_table(ot_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator);
1104 VKAPI_ATTR VkResult VKAPI_CALL FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1105 const VkDescriptorSet *pDescriptorSets) {
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]);
1118 for (uint32_t i = 0; i < descriptorSetCount; i++) {
1119 DestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet, nullptr, VALIDATION_ERROR_UNDEFINED,
1120 VALIDATION_ERROR_UNDEFINED);
1125 result = get_dispatch_table(ot_device_table_map, device)
1126 ->FreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets);
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);
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.
1146 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
1147 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
1148 ObjTrackState *pNode = (*itr).second;
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);
1155 DestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, pAllocator, VALIDATION_ERROR_24400260,
1156 VALIDATION_ERROR_24400262);
1158 get_dispatch_table(ot_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator);
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);
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);
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();
1177 while (itr != device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) {
1178 ObjTrackState *pNode = (*itr).second;
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);
1186 DestroyObject(device, commandPool, kVulkanObjectTypeCommandPool, pAllocator, VALIDATION_ERROR_24000054,
1187 VALIDATION_ERROR_24000056);
1189 get_dispatch_table(ot_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator);
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) {
1198 std::lock_guard<std::mutex> lock(global_lock);
1199 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_UNDEFINED,
1200 VALIDATION_ERROR_UNDEFINED);
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);
1213 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
1214 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties;
1219 // Note: This is the extension version of this routine. The core version is above.
1220 VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice,
1221 uint32_t *pQueueFamilyPropertyCount,
1222 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
1225 std::lock_guard<std::mutex> lock(global_lock);
1226 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_UNDEFINED,
1227 VALIDATION_ERROR_UNDEFINED);
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);
1240 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
1241 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties;
1246 VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
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));
1254 dev_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
1256 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_23605601, VALIDATION_ERROR_UNDEFINED);
1259 return VK_ERROR_VALIDATION_FAILED_EXT;
1261 VkResult result = dev_data->dispatch_table.DebugMarkerSetObjectNameEXT(device, pNameInfo);
1265 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
1268 if (get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr == NULL) {
1271 return get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr(instance, funcName);
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);
1280 auto table = get_dispatch_table(ot_device_table_map, device);
1281 if (!table->GetDeviceProcAddr) return NULL;
1282 return table->GetDeviceProcAddr(device, funcName);
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);
1291 auto table = get_dispatch_table(ot_instance_table_map, instance);
1292 if (!table->GetInstanceProcAddr) return nullptr;
1293 return table->GetInstanceProcAddr(instance, funcName);
1296 } // namespace object_tracker
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);
1303 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
1304 VkLayerProperties *pProperties) {
1305 return object_tracker::EnumerateInstanceLayerProperties(pCount, pProperties);
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);
1315 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
1316 return object_tracker::GetDeviceProcAddr(dev, funcName);
1319 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
1320 return object_tracker::GetInstanceProcAddr(instance, funcName);
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);
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);
1336 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
1337 assert(pVersionStruct != NULL);
1338 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
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;
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;