blob: b315ba674fac9d3493ad66e27b639d095421815b [file] [log] [blame]
Mark Young0f183a82017-02-28 09:58:04 -07001/* 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.
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 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -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
38 OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed
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
42 OBJTRACK_ALLOCATOR_MISMATCH, // Created with custom allocator but destroyed without
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060043};
Tobin Ehlisca915872014-11-18 11:28:33 -070044
Tobin Ehlis91ce77e2015-01-16 08:56:30 -070045// Object Status -- used to track state of individual objects
Mark Lobodzinski38f0db22015-05-20 17:33:47 -050046typedef VkFlags ObjectStatusFlags;
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060047enum ObjectStatusFlagBits {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070048 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
56 OBJSTATUS_CUSTOM_ALLOCATOR = 0x00000080, // Allocated with custom allocator
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060057};
Chia-I Wuf8693382015-04-16 22:02:10 +080058
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060059// Object and state information structure
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060060struct OBJTRACK_NODE {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070061 uint64_t handle; // Object handle (new)
Mark Lobodzinski558d7cb2017-04-11 15:37:17 -060062 VulkanObjectType object_type; // Object type identifier
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070063 ObjectStatusFlags status; // Object state
64 uint64_t parent_object; // Parent object
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060065};
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -060066
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060067// Track Queue information
68struct OT_QUEUE_INFO {
69 uint32_t queue_node_index;
70 VkQueue queue;
Cody Northrop55443ef2015-09-28 15:09:32 -060071};
Mark Lobodzinskifae78852015-06-23 11:35:12 -060072
Mark Lobodzinski9bab8662016-07-01 10:53:31 -060073// Layer name string to be logged with validation messages.
74const char LayerName[] = "ObjectTracker";
75
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060076struct instance_extension_enables {
Jon Ashburn3dc39382015-09-17 10:00:32 -060077 bool wsi_enabled;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060078 bool xlib_enabled;
79 bool xcb_enabled;
80 bool wayland_enabled;
81 bool mir_enabled;
82 bool android_enabled;
83 bool win32_enabled;
Norbert Nopper1dec9a52016-11-25 07:55:13 +010084 bool display_enabled;
Jon Ashburn3dc39382015-09-17 10:00:32 -060085};
86
Mark Lobodzinski9ed13b62017-04-12 13:56:58 -060087struct device_extension_enables{
88 bool wsi;
89 bool wsi_display_swapchain;
90 bool wsi_display_extension;
91 bool objtrack_extensions;
92 bool khr_descriptor_update_template;
93 bool khr_maintenance1;
94 bool khr_push_descriptor;
95 bool khx_device_group;
96#ifdef VK_USE_PLATFORM_WIN32_KHR
97 bool khx_external_memory_win32;
98#endif // VK_USE_PLATFORM_WIN32_KHR
99 bool khx_external_memory_fd;
100#ifdef VK_USE_PLATFORM_WIN32_KHR
101 bool khx_external_semaphore_win32;
102#endif // VK_USE_PLATFORM_WIN32_KHR
103 bool khx_external_semaphore_fd;
104 bool ext_display_control;
105 bool ext_discard_rectangles;
106 bool nv_clip_space_w_scaling;
107 bool nvx_device_generated_commands;
Tobin Ehlis080c3d02017-04-24 14:46:25 -0600108 bool google_display_timing;
Mark Lobodzinski9ed13b62017-04-12 13:56:58 -0600109};
110
Tobin Ehlisb4dcca82016-08-02 10:50:29 -0600111typedef std::unordered_map<uint64_t, OBJTRACK_NODE *> object_map_type;
Mark Lobodzinski9ed13b62017-04-12 13:56:58 -0600112
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600113struct layer_data {
114 VkInstance instance;
115 VkPhysicalDevice physical_device;
Mark Lobodzinskie86e1382015-11-24 15:50:44 -0700116
Mark Lobodzinski558d7cb2017-04-11 15:37:17 -0600117 uint64_t num_objects[kVulkanObjectTypeMax + 1];
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600118 uint64_t num_total_objects;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600119
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600120 debug_report_data *report_data;
121 std::vector<VkDebugReportCallbackEXT> logging_callback;
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600122 // The following are for keeping track of the temporary callbacks that can
123 // be used in vkCreateInstance and vkDestroyInstance:
124 uint32_t num_tmp_callbacks;
125 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
126 VkDebugReportCallbackEXT *tmp_callbacks;
Jon Ashburn3dc39382015-09-17 10:00:32 -0600127
Mark Lobodzinski9ed13b62017-04-12 13:56:58 -0600128 device_extension_enables enables;
129
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600130 std::vector<VkQueueFamilyProperties> queue_family_properties;
131
Tobin Ehlisb4dcca82016-08-02 10:50:29 -0600132 // Vector of unordered_maps per object type to hold OBJTRACK_NODE info
133 std::vector<object_map_type> object_map;
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600134 // Special-case map for swapchain images
135 std::unordered_map<uint64_t, OBJTRACK_NODE *> swapchainImageMap;
136 // Map of queue information structures, one per queue
137 std::unordered_map<VkQueue, OT_QUEUE_INFO *> queue_info_map;
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600138
Tobin Ehlis8ad41932016-12-01 09:37:56 -0700139 VkLayerDispatchTable dispatch_table;
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600140 // Default constructor
141 layer_data()
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700142 : instance(nullptr),
143 physical_device(nullptr),
144 num_objects{},
145 num_total_objects(0),
146 report_data(nullptr),
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700147 num_tmp_callbacks(0),
148 tmp_dbg_create_infos(nullptr),
149 tmp_callbacks(nullptr),
150 object_map{},
151 dispatch_table{} {
Mark Lobodzinski558d7cb2017-04-11 15:37:17 -0600152 object_map.resize(kVulkanObjectTypeMax + 1);
Mark Lobodzinski9ed13b62017-04-12 13:56:58 -0600153 memset(&enables, 0, sizeof(enables));
Tobin Ehlisb4dcca82016-08-02 10:50:29 -0600154 }
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600155};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600156
Mark Lobodzinski9bab8662016-07-01 10:53:31 -0600157static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap;
158static std::unordered_map<void *, layer_data *> layer_data_map;
159static device_table_map ot_device_table_map;
160static instance_table_map ot_instance_table_map;
161static std::mutex global_lock;
162static uint64_t object_track_index = 0;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600163
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600164#include "vk_dispatch_table_helper.h"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600165
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700166} // namespace object_tracker