Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
Tobin Ehlis | acab888 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 5 | * |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Tobin Ehlis | acab888 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tobin Ehlis | acab888 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 17 | * |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 18 | * Author: Mark Lobodzinski <mark@lunarg.com> |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 19 | * Author: Jon Ashburn <jon@lunarg.com> |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 20 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Tobin Ehlis | acab888 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
Jeremy Hayes | 241a2db | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 23 | #include <mutex> |
| 24 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 25 | #include "vk_enum_string_helper.h" |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 26 | #include "vk_layer_extension_utils.h" |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 27 | #include "vk_layer_table.h" |
Mark Lobodzinski | d11c4ee | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 28 | #include "vk_layer_utils.h" |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 29 | #include "vulkan/vk_layer.h" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 30 | |
Chia-I Wu | 1c0b731 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 31 | namespace object_tracker { |
| 32 | |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 33 | // Object Tracker ERROR codes |
Mark Lobodzinski | 6cb97f9 | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 34 | enum OBJECT_TRACK_ERROR { |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 35 | OBJTRACK_NONE, // Used for INFO & other non-error messages |
| 36 | OBJTRACK_UNKNOWN_OBJECT, // Updating uses of object that's not in global object list |
| 37 | OBJTRACK_INTERNAL_ERROR, // Bug with data tracking within the layer |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 38 | OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 39 | OBJTRACK_INVALID_OBJECT, // Object used that has never been created |
| 40 | OBJTRACK_DESCRIPTOR_POOL_MISMATCH, // Descriptor Pools specified incorrectly |
| 41 | OBJTRACK_COMMAND_POOL_MISMATCH, // Command Pools specified incorrectly |
Chris Forbes | c8a0b73 | 2016-09-29 13:51:10 +1300 | [diff] [blame] | 42 | OBJTRACK_ALLOCATOR_MISMATCH, // Created with custom allocator but destroyed without |
Mark Lobodzinski | 6cb97f9 | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 43 | }; |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 44 | |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 45 | // Object Status -- used to track state of individual objects |
Mark Lobodzinski | 7d2d5ac | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 46 | typedef VkFlags ObjectStatusFlags; |
Mark Lobodzinski | 6cb97f9 | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 47 | enum ObjectStatusFlagBits { |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 48 | OBJSTATUS_NONE = 0x00000000, // No status is set |
| 49 | OBJSTATUS_FENCE_IS_SUBMITTED = 0x00000001, // Fence has been submitted |
| 50 | OBJSTATUS_VIEWPORT_BOUND = 0x00000002, // Viewport state object has been bound |
| 51 | OBJSTATUS_RASTER_BOUND = 0x00000004, // Viewport state object has been bound |
| 52 | OBJSTATUS_COLOR_BLEND_BOUND = 0x00000008, // Viewport state object has been bound |
| 53 | OBJSTATUS_DEPTH_STENCIL_BOUND = 0x00000010, // Viewport state object has been bound |
| 54 | OBJSTATUS_GPU_MEM_MAPPED = 0x00000020, // Memory object is currently mapped |
| 55 | OBJSTATUS_COMMAND_BUFFER_SECONDARY = 0x00000040, // Command Buffer is of type SECONDARY |
Chris Forbes | c8a0b73 | 2016-09-29 13:51:10 +1300 | [diff] [blame] | 56 | OBJSTATUS_CUSTOM_ALLOCATOR = 0x00000080, // Allocated with custom allocator |
Mark Lobodzinski | 6cb97f9 | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 57 | }; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 58 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 59 | // Object and state information structure |
Mark Lobodzinski | 6cb97f9 | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 60 | struct OBJTRACK_NODE { |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 61 | uint64_t handle; // Object handle (new) |
| 62 | VkDebugReportObjectTypeEXT object_type; // Object type identifier |
| 63 | ObjectStatusFlags status; // Object state |
| 64 | uint64_t parent_object; // Parent object |
Mark Lobodzinski | 6cb97f9 | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 65 | }; |
Mark Lobodzinski | e1d3f0c | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 66 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 67 | // Track Queue information |
| 68 | struct OT_QUEUE_INFO { |
| 69 | uint32_t queue_node_index; |
| 70 | VkQueue queue; |
Cody Northrop | 73bb657 | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 71 | }; |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 72 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 73 | // Layer name string to be logged with validation messages. |
| 74 | const char LayerName[] = "ObjectTracker"; |
| 75 | |
Mark Lobodzinski | 61d505e | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 76 | struct instance_extension_enables { |
Jon Ashburn | de4f110 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 77 | bool wsi_enabled; |
Mark Lobodzinski | 61d505e | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 78 | bool xlib_enabled; |
| 79 | bool xcb_enabled; |
| 80 | bool wayland_enabled; |
| 81 | bool mir_enabled; |
| 82 | bool android_enabled; |
| 83 | bool win32_enabled; |
Norbert Nopper | 6f2ed66 | 2016-11-25 07:55:13 +0100 | [diff] [blame] | 84 | bool display_enabled; |
Jon Ashburn | de4f110 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 85 | }; |
| 86 | |
Tobin Ehlis | 5c4c68c | 2016-08-02 10:50:29 -0600 | [diff] [blame] | 87 | typedef std::unordered_map<uint64_t, OBJTRACK_NODE *> object_map_type; |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 88 | struct layer_data { |
| 89 | VkInstance instance; |
| 90 | VkPhysicalDevice physical_device; |
Mark Lobodzinski | dc87a3f | 2015-11-24 15:50:44 -0700 | [diff] [blame] | 91 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 92 | uint64_t num_objects[VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT + 1]; |
| 93 | uint64_t num_total_objects; |
Mark Lobodzinski | 61d505e | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 94 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 95 | debug_report_data *report_data; |
| 96 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
| 97 | bool wsi_enabled; |
Mark Young | 19ab93c | 2016-09-08 12:28:38 -0600 | [diff] [blame] | 98 | bool wsi_display_swapchain_enabled; |
Mark Lobodzinski | dfb417d | 2016-11-14 10:00:41 -0700 | [diff] [blame] | 99 | bool wsi_display_extension_enabled; |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 100 | bool objtrack_extensions_enabled; |
Mark Young | b5f087a | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 101 | bool nvx_device_generated_commands_enabled; |
| 102 | bool ext_display_control_enabled; |
Mark Lobodzinski | 61d505e | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 103 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 104 | // The following are for keeping track of the temporary callbacks that can |
| 105 | // be used in vkCreateInstance and vkDestroyInstance: |
| 106 | uint32_t num_tmp_callbacks; |
| 107 | VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos; |
| 108 | VkDebugReportCallbackEXT *tmp_callbacks; |
Jon Ashburn | de4f110 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 109 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 110 | std::vector<VkQueueFamilyProperties> queue_family_properties; |
| 111 | |
Tobin Ehlis | 5c4c68c | 2016-08-02 10:50:29 -0600 | [diff] [blame] | 112 | // Vector of unordered_maps per object type to hold OBJTRACK_NODE info |
| 113 | std::vector<object_map_type> object_map; |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 114 | // Special-case map for swapchain images |
| 115 | std::unordered_map<uint64_t, OBJTRACK_NODE *> swapchainImageMap; |
| 116 | // Map of queue information structures, one per queue |
| 117 | std::unordered_map<VkQueue, OT_QUEUE_INFO *> queue_info_map; |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 118 | |
Tobin Ehlis | 7b0f9d7 | 2016-12-01 09:37:56 -0700 | [diff] [blame] | 119 | VkLayerDispatchTable dispatch_table; |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 120 | // Default constructor |
| 121 | layer_data() |
| 122 | : instance(nullptr), physical_device(nullptr), num_objects{}, num_total_objects(0), report_data(nullptr), |
Mark Lobodzinski | dfb417d | 2016-11-14 10:00:41 -0700 | [diff] [blame] | 123 | wsi_enabled(false), wsi_display_swapchain_enabled(false), wsi_display_extension_enabled(false), |
| 124 | objtrack_extensions_enabled(false), num_tmp_callbacks(0), tmp_dbg_create_infos(nullptr), tmp_callbacks(nullptr), |
| 125 | object_map{}, dispatch_table{} { |
Tobin Ehlis | 5c4c68c | 2016-08-02 10:50:29 -0600 | [diff] [blame] | 126 | object_map.resize(VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT + 1); |
| 127 | } |
Mark Lobodzinski | 6cb97f9 | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 128 | }; |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 129 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 130 | static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap; |
| 131 | static std::unordered_map<void *, layer_data *> layer_data_map; |
| 132 | static device_table_map ot_device_table_map; |
| 133 | static instance_table_map ot_instance_table_map; |
| 134 | static std::mutex global_lock; |
| 135 | static uint64_t object_track_index = 0; |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 136 | |
Mark Lobodzinski | 2faa214 | 2016-07-01 10:53:31 -0600 | [diff] [blame] | 137 | // Array of object name strings for OBJECT_TYPE enum conversion |
| 138 | static const char *object_name[VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT] = { |
| 139 | "Unknown", // VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN |
| 140 | "Instance", // VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT |
| 141 | "Physical Device", // VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT |
| 142 | "Device", // VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT |
| 143 | "Queue", // VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT |
| 144 | "Semaphore", // VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT |
| 145 | "Command Buffer", // VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT |
| 146 | "Fence", // VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT |
| 147 | "Device Memory", // VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT |
| 148 | "Buffer", // VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT |
| 149 | "Image", // VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT |
| 150 | "Event", // VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT |
| 151 | "Query Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT |
| 152 | "Buffer View", // VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT |
| 153 | "Image View", // VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT |
| 154 | "Shader Module", // VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT |
| 155 | "Pipeline Cache", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT |
| 156 | "Pipeline Layout", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT |
| 157 | "Render Pass", // VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT |
| 158 | "Pipeline", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT |
| 159 | "Descriptor Set Layout", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT |
| 160 | "Sampler", // VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT |
| 161 | "Descriptor Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT |
| 162 | "Descriptor Set", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT |
| 163 | "Framebuffer", // VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT |
| 164 | "Command Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT |
| 165 | "SurfaceKHR", // VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT |
| 166 | "SwapchainKHR", // VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT |
Mark Lobodzinski | bc9caa5 | 2017-01-26 12:16:30 -0700 | [diff] [blame^] | 167 | "Debug Report"}; // VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 168 | |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 169 | #include "vk_dispatch_table_helper.h" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 170 | |
Chia-I Wu | 1c0b731 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 171 | } // namespace object_tracker |