blob: 0d70bec222b1f3b28992b37f6ff39d4771a7e6e5 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* 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 Ehlis42586532014-11-14 13:01:02 -07005 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * 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 Ehlis42586532014-11-14 13:01:02 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlis42586532014-11-14 13:01:02 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * 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 Goeltzenleuchter05559522015-10-30 11:14:30 -060017 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060018 * Author: Mark Lobodzinski <mark@lunarg.com>
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060019 * Author: Jon Ashburn <jon@lunarg.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060020 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlis42586532014-11-14 13:01:02 -070021 */
22
Jeremy Hayes2f065b12016-04-13 10:54:17 -060023#include <mutex>
24
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060025#include "vk_enum_string_helper.h"
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060026#include "vk_layer_extension_utils.h"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -070027#include "vk_layer_table.h"
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -060028#include "vk_layer_utils.h"
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060029#include "vulkan/vk_layer.h"
Mark Lobodzinskifae78852015-06-23 11:35:12 -060030
Chia-I Wucdb70962016-05-13 14:07:36 +080031namespace object_tracker {
32
Tobin Ehlisca915872014-11-18 11:28:33 -070033// Object Tracker ERROR codes
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060034enum OBJECT_TRACK_ERROR {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070035 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 Ashburn5484e0c2016-03-08 17:48:44 -070038 OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed
Jon Ashburn5484e0c2016-03-08 17:48:44 -070039 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
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060042};
Tobin Ehlisca915872014-11-18 11:28:33 -070043
Tobin Ehlis91ce77e2015-01-16 08:56:30 -070044// Object Status -- used to track state of individual objects
Mark Lobodzinski38f0db22015-05-20 17:33:47 -050045typedef VkFlags ObjectStatusFlags;
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060046enum ObjectStatusFlagBits {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070047 OBJSTATUS_NONE = 0x00000000, // No status is set
48 OBJSTATUS_FENCE_IS_SUBMITTED = 0x00000001, // Fence has been submitted
49 OBJSTATUS_VIEWPORT_BOUND = 0x00000002, // Viewport state object has been bound
50 OBJSTATUS_RASTER_BOUND = 0x00000004, // Viewport state object has been bound
51 OBJSTATUS_COLOR_BLEND_BOUND = 0x00000008, // Viewport state object has been bound
52 OBJSTATUS_DEPTH_STENCIL_BOUND = 0x00000010, // Viewport state object has been bound
53 OBJSTATUS_GPU_MEM_MAPPED = 0x00000020, // Memory object is currently mapped
54 OBJSTATUS_COMMAND_BUFFER_SECONDARY = 0x00000040, // Command Buffer is of type SECONDARY
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060055};
Chia-I Wuf8693382015-04-16 22:02:10 +080056
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060057// Object and state information structure
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060058struct OBJTRACK_NODE {
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060059 uint64_t handle; // Object handle (new)
60 VkDebugReportObjectTypeEXT object_type; // Object type identifier
61 ObjectStatusFlags status; // Object state
62 uint64_t parent_object; // Parent object
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060063};
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -060064
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060065// Track Queue information
66struct OT_QUEUE_INFO {
67 uint32_t queue_node_index;
68 VkQueue queue;
Cody Northrop55443ef2015-09-28 15:09:32 -060069};
Mark Lobodzinskifae78852015-06-23 11:35:12 -060070
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060071// Layer name string to be logged with validation messages.
72const char LayerName[] = "ObjectTracker";
73
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060074struct instance_extension_enables {
Jon Ashburn3dc39382015-09-17 10:00:32 -060075 bool wsi_enabled;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060076 bool xlib_enabled;
77 bool xcb_enabled;
78 bool wayland_enabled;
79 bool mir_enabled;
80 bool android_enabled;
81 bool win32_enabled;
Jon Ashburn3dc39382015-09-17 10:00:32 -060082};
83
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060084struct layer_data {
85 VkInstance instance;
86 VkPhysicalDevice physical_device;
Mark Lobodzinskie86e1382015-11-24 15:50:44 -070087
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060088 uint64_t num_objects[VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT + 1];
89 uint64_t num_total_objects;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060090
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060091 debug_report_data *report_data;
92 std::vector<VkDebugReportCallbackEXT> logging_callback;
93 bool wsi_enabled;
94 bool objtrack_extensions_enabled;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060095
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060096 // The following are for keeping track of the temporary callbacks that can
97 // be used in vkCreateInstance and vkDestroyInstance:
98 uint32_t num_tmp_callbacks;
99 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
100 VkDebugReportCallbackEXT *tmp_callbacks;
Jon Ashburn3dc39382015-09-17 10:00:32 -0600101
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600102 std::vector<VkQueueFamilyProperties> queue_family_properties;
103
104 // Array of unordered_maps per object type to hold OBJTRACK_NODE info
105 std::unordered_map<uint64_t, OBJTRACK_NODE *> object_map[VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT + 1];
106 // Special-case map for swapchain images
107 std::unordered_map<uint64_t, OBJTRACK_NODE *> swapchainImageMap;
108 // Map of queue information structures, one per queue
109 std::unordered_map<VkQueue, OT_QUEUE_INFO *> queue_info_map;
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600110
111 // Default constructor
112 layer_data()
113 : instance(nullptr), physical_device(nullptr), num_objects{}, num_total_objects(0), report_data(nullptr),
114 wsi_enabled(false), objtrack_extensions_enabled(false), num_tmp_callbacks(0), tmp_dbg_create_infos(nullptr),
115 tmp_callbacks(nullptr), object_map{} {}
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600116};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600117
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600118
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600119static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap;
120static std::unordered_map<void *, layer_data *> layer_data_map;
121static device_table_map ot_device_table_map;
122static instance_table_map ot_instance_table_map;
123static std::mutex global_lock;
124static uint64_t object_track_index = 0;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600125
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600126// Array of object name strings for OBJECT_TYPE enum conversion
127static const char *object_name[VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT] = {
128 "Unknown", // VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN
129 "Instance", // VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT
130 "Physical Device", // VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT
131 "Device", // VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
132 "Queue", // VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT
133 "Semaphore", // VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT
134 "Command Buffer", // VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT
135 "Fence", // VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT
136 "Device Memory", // VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT
137 "Buffer", // VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT
138 "Image", // VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT
139 "Event", // VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT
140 "Query Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT
141 "Buffer View", // VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT
142 "Image View", // VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT
143 "Shader Module", // VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT
144 "Pipeline Cache", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT
145 "Pipeline Layout", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT
146 "Render Pass", // VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT
147 "Pipeline", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT
148 "Descriptor Set Layout", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT
149 "Sampler", // VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT
150 "Descriptor Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT
151 "Descriptor Set", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT
152 "Framebuffer", // VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT
153 "Command Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT
154 "SurfaceKHR", // VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT
155 "SwapchainKHR", // VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT
156 "Debug Report" }; // VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600157
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600158#include "vk_dispatch_table_helper.h"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600159
Chia-I Wucdb70962016-05-13 14:07:36 +0800160} // namespace object_tracker