forked from KhronosGroup/Vulkan-LoaderAndValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_tracker.h
198 lines (177 loc) · 8.62 KB
/
object_tracker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* Copyright (c) 2015-2017 The Khronos Group Inc.
* Copyright (c) 2015-2017 Valve Corporation
* Copyright (c) 2015-2017 LunarG, Inc.
* Copyright (C) 2015-2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Mark Lobodzinski <[email protected]>
* Author: Jon Ashburn <[email protected]>
* Author: Tobin Ehlis <[email protected]>
*/
#include <mutex>
#include "vk_enum_string_helper.h"
#include "vk_layer_extension_utils.h"
#include "vk_layer_table.h"
#include "vk_layer_utils.h"
#include "vulkan/vk_layer.h"
namespace object_tracker {
// Object Tracker ERROR codes
enum OBJECT_TRACK_ERROR {
OBJTRACK_NONE, // Used for INFO & other non-error messages
OBJTRACK_UNKNOWN_OBJECT, // Updating uses of object that's not in global object list
OBJTRACK_INTERNAL_ERROR, // Bug with data tracking within the layer
OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed
OBJTRACK_INVALID_OBJECT, // Object used that has never been created
OBJTRACK_DESCRIPTOR_POOL_MISMATCH, // Descriptor Pools specified incorrectly
OBJTRACK_COMMAND_POOL_MISMATCH, // Command Pools specified incorrectly
OBJTRACK_ALLOCATOR_MISMATCH, // Created with custom allocator but destroyed without
};
// Object Status -- used to track state of individual objects
typedef VkFlags ObjectStatusFlags;
enum ObjectStatusFlagBits {
OBJSTATUS_NONE = 0x00000000, // No status is set
OBJSTATUS_FENCE_IS_SUBMITTED = 0x00000001, // Fence has been submitted
OBJSTATUS_VIEWPORT_BOUND = 0x00000002, // Viewport state object has been bound
OBJSTATUS_RASTER_BOUND = 0x00000004, // Viewport state object has been bound
OBJSTATUS_COLOR_BLEND_BOUND = 0x00000008, // Viewport state object has been bound
OBJSTATUS_DEPTH_STENCIL_BOUND = 0x00000010, // Viewport state object has been bound
OBJSTATUS_GPU_MEM_MAPPED = 0x00000020, // Memory object is currently mapped
OBJSTATUS_COMMAND_BUFFER_SECONDARY = 0x00000040, // Command Buffer is of type SECONDARY
OBJSTATUS_CUSTOM_ALLOCATOR = 0x00000080, // Allocated with custom allocator
};
// Object and state information structure
struct OBJTRACK_NODE {
uint64_t handle; // Object handle (new)
VkDebugReportObjectTypeEXT object_type; // Object type identifier
ObjectStatusFlags status; // Object state
uint64_t parent_object; // Parent object
};
// Track Queue information
struct OT_QUEUE_INFO {
uint32_t queue_node_index;
VkQueue queue;
};
// Layer name string to be logged with validation messages.
const char LayerName[] = "ObjectTracker";
struct instance_extension_enables {
bool wsi_enabled;
bool xlib_enabled;
bool xcb_enabled;
bool wayland_enabled;
bool mir_enabled;
bool android_enabled;
bool win32_enabled;
bool display_enabled;
};
typedef std::unordered_map<uint64_t, OBJTRACK_NODE *> object_map_type;
struct layer_data {
VkInstance instance;
VkPhysicalDevice physical_device;
uint64_t num_objects[VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT + 1];
uint64_t num_total_objects;
debug_report_data *report_data;
std::vector<VkDebugReportCallbackEXT> logging_callback;
union device_extension_enables {
struct {
bool wsi : 1;
bool wsi_display_swapchain : 1;
bool wsi_display_extension : 1;
bool objtrack_extensions : 1;
bool khr_descriptor_update_template : 1;
bool khr_maintenance1 : 1;
bool khr_push_descriptor : 1;
bool khx_device_group : 1;
#ifdef VK_USE_PLATFORM_WIN32_KHR
bool khx_external_memory_win32 : 1;
#endif // VK_USE_PLATFORM_WIN32_KHR
bool khx_external_memory_fd : 1;
#ifdef VK_USE_PLATFORM_WIN32_KHR
bool khx_external_semaphore_win32 : 1;
#endif // VK_USE_PLATFORM_WIN32_KHR
bool khx_external_semaphore_fd : 1;
bool ext_display_control : 1;
bool ext_discard_rectangles : 1;
bool nv_clip_space_w_scaling : 1;
bool nvx_device_generated_commands : 1;
};
uint64_t padding[4];
} enables;
// The following are for keeping track of the temporary callbacks that can
// be used in vkCreateInstance and vkDestroyInstance:
uint32_t num_tmp_callbacks;
VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
VkDebugReportCallbackEXT *tmp_callbacks;
std::vector<VkQueueFamilyProperties> queue_family_properties;
// Vector of unordered_maps per object type to hold OBJTRACK_NODE info
std::vector<object_map_type> object_map;
// Special-case map for swapchain images
std::unordered_map<uint64_t, OBJTRACK_NODE *> swapchainImageMap;
// Map of queue information structures, one per queue
std::unordered_map<VkQueue, OT_QUEUE_INFO *> queue_info_map;
VkLayerDispatchTable dispatch_table;
// Default constructor
layer_data()
: instance(nullptr),
physical_device(nullptr),
num_objects{},
num_total_objects(0),
report_data(nullptr),
num_tmp_callbacks(0),
tmp_dbg_create_infos(nullptr),
tmp_callbacks(nullptr),
object_map{},
dispatch_table{} {
object_map.resize(VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT + 1);
memset(enables.padding, 0, sizeof(uint64_t) * 4);
}
};
static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap;
static std::unordered_map<void *, layer_data *> layer_data_map;
static device_table_map ot_device_table_map;
static instance_table_map ot_instance_table_map;
static std::mutex global_lock;
static uint64_t object_track_index = 0;
// Array of object name strings for OBJECT_TYPE enum conversion
static const char *object_name[VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT] = {
"Unknown", // VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN
"Instance", // VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT
"Physical Device", // VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT
"Device", // VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
"Queue", // VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT
"Semaphore", // VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT
"Command Buffer", // VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT
"Fence", // VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT
"Device Memory", // VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT
"Buffer", // VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT
"Image", // VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT
"Event", // VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT
"Query Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT
"Buffer View", // VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT
"Image View", // VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT
"Shader Module", // VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT
"Pipeline Cache", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT
"Pipeline Layout", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT
"Render Pass", // VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT
"Pipeline", // VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT
"Descriptor Set Layout", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT
"Sampler", // VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT
"Descriptor Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT
"Descriptor Set", // VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT
"Framebuffer", // VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT
"Command Pool", // VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT
"SurfaceKHR", // VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT
"SwapchainKHR", // VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT
"Debug Report"}; // VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT
#include "vk_dispatch_table_helper.h"
} // namespace object_tracker