blob: a20760f412ce9de37c4c197d5d7057a2dcb4b6f2 [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 *
18 * Author: Jon Ashburn <jon@lunarg.com>
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * 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
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include "vulkan/vk_layer.h"
Courtney Goeltzenleuchterfce8cd22015-07-05 22:13:43 -060026#include "vk_layer_extension_utils.h"
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060027#include "vk_enum_string_helper.h"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -070028#include "vk_layer_table.h"
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -060029#include "vk_layer_utils.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 Lobodzinskibd1fecd2016-05-19 17:06:56 -060057struct OBJTRACK_NODE {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070058 uint64_t vkObj; // Object handle
59 VkDebugReportObjectTypeEXT objType; // Object type identifier
60 ObjectStatusFlags status; // Object state
61 uint64_t parentObj; // Parent object
62 uint64_t belongsTo; // Object Scope -- owning device/instance
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060063};
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -060064
Tobin Ehlis42586532014-11-14 13:01:02 -070065// prototype for extension functions
Mark Lobodzinskifae78852015-06-23 11:35:12 -060066uint64_t objTrackGetObjectCount(VkDevice device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070067uint64_t objTrackGetObjectsOfTypeCount(VkDevice, VkDebugReportObjectTypeEXT type);
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -060068
Tobin Ehlisca915872014-11-18 11:28:33 -070069// Func ptr typedefs
Mark Lobodzinskifae78852015-06-23 11:35:12 -060070typedef uint64_t (*OBJ_TRACK_GET_OBJECT_COUNT)(VkDevice);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070071typedef uint64_t (*OBJ_TRACK_GET_OBJECTS_OF_TYPE_COUNT)(VkDevice, VkDebugReportObjectTypeEXT);
Mark Lobodzinskifae78852015-06-23 11:35:12 -060072
Cody Northrop55443ef2015-09-28 15:09:32 -060073struct layer_data {
Chia-I Wu1ad50f42016-05-17 07:57:15 +080074 VkInstance instance;
75
Mark Lobodzinskifae78852015-06-23 11:35:12 -060076 debug_report_data *report_data;
Cody Northrop9c93ec52016-04-28 09:55:08 -060077 // TODO: put instance data here
78 std::vector<VkDebugReportCallbackEXT> logging_callback;
79 bool wsi_enabled;
80 bool objtrack_extensions_enabled;
Ian Elliotted6b5ac2016-04-28 09:08:13 -060081 // The following are for keeping track of the temporary callbacks that can
82 // be used in vkCreateInstance and vkDestroyInstance:
83 uint32_t num_tmp_callbacks;
84 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
85 VkDebugReportCallbackEXT *tmp_callbacks;
Cody Northrop55443ef2015-09-28 15:09:32 -060086
Ian Elliotted6b5ac2016-04-28 09:08:13 -060087 layer_data()
88 : report_data(nullptr), wsi_enabled(false), objtrack_extensions_enabled(false), num_tmp_callbacks(0),
89 tmp_dbg_create_infos(nullptr), tmp_callbacks(nullptr){};
Cody Northrop55443ef2015-09-28 15:09:32 -060090};
Mark Lobodzinskifae78852015-06-23 11:35:12 -060091
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060092struct instance_extension_enables {
Jon Ashburn3dc39382015-09-17 10:00:32 -060093 bool wsi_enabled;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060094 bool xlib_enabled;
95 bool xcb_enabled;
96 bool wayland_enabled;
97 bool mir_enabled;
98 bool android_enabled;
99 bool win32_enabled;
Jon Ashburn3dc39382015-09-17 10:00:32 -0600100};
101
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600102static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700103static std::unordered_map<void *, layer_data *> layer_data_map;
104static device_table_map object_tracker_device_table_map;
105static instance_table_map object_tracker_instance_table_map;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600106
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600107// We need additionally validate image usage using a separate map
108// of swapchain-created images
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600109static std::unordered_map<uint64_t, OBJTRACK_NODE *> swapchainImageMap;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600110
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600111static long long unsigned int object_track_index = 0;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600112static std::mutex global_lock;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600113
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700114#define NUM_OBJECT_TYPES (VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT + 1)
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600115
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700116static uint64_t numObjs[NUM_OBJECT_TYPES] = {0};
117static uint64_t numTotalObjs = 0;
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600118std::vector<VkQueueFamilyProperties> queue_family_properties;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600119
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600120//
121// Internal Object Tracker Functions
122//
123
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700124static void createDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700125 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
126 VkLayerDispatchTable *pDisp = get_dispatch_table(object_tracker_device_table_map, device);
Jon Ashburn8acd2332015-09-16 18:08:32 -0600127 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700128 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR)gpa(device, "vkCreateSwapchainKHR");
129 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR)gpa(device, "vkDestroySwapchainKHR");
130 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR)gpa(device, "vkGetSwapchainImagesKHR");
131 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR)gpa(device, "vkAcquireNextImageKHR");
132 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR)gpa(device, "vkQueuePresentKHR");
Ian Elliott1064fe32015-07-06 14:31:32 -0600133 my_device_data->wsi_enabled = false;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700134 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700135 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
Ian Elliott1064fe32015-07-06 14:31:32 -0600136 my_device_data->wsi_enabled = true;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600137
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700138 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], "OBJTRACK_EXTENSIONS") == 0)
Courtney Goeltzenleuchterfce8cd22015-07-05 22:13:43 -0600139 my_device_data->objtrack_extensions_enabled = true;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600140 }
141}
142
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700143static void createInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700144 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(object_tracker_instance_table_map, instance);
Jon Ashburn3dc39382015-09-17 10:00:32 -0600145 PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
Michael Lentine56512bb2016-03-02 17:28:55 -0600146
147 pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR)gpa(instance, "vkDestroySurfaceKHR");
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700148 pDisp->GetPhysicalDeviceSurfaceSupportKHR =
149 (PFN_vkGetPhysicalDeviceSurfaceSupportKHR)gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
150 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR =
151 (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR)gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
152 pDisp->GetPhysicalDeviceSurfaceFormatsKHR =
153 (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
154 pDisp->GetPhysicalDeviceSurfacePresentModesKHR =
155 (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR)gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Petros Bantolas2b40be72016-04-15 11:02:59 +0100156 pDisp->GetPhysicalDeviceDisplayPropertiesKHR =
157 (PFN_vkGetPhysicalDeviceDisplayPropertiesKHR)gpa(instance, "vkGetPhysicalDeviceDisplayPropertiesKHR");
158 pDisp->GetPhysicalDeviceDisplayPlanePropertiesKHR =
159 (PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR)gpa(instance, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR");
160 pDisp->GetDisplayPlaneSupportedDisplaysKHR =
161 (PFN_vkGetDisplayPlaneSupportedDisplaysKHR)gpa(instance, "vkGetDisplayPlaneSupportedDisplaysKHR");
162 pDisp->GetDisplayModePropertiesKHR =
163 (PFN_vkGetDisplayModePropertiesKHR)gpa(instance, "vkGetDisplayModePropertiesKHR");
164 pDisp->CreateDisplayModeKHR =
165 (PFN_vkCreateDisplayModeKHR)gpa(instance, "vkCreateDisplayModeKHR");
166 pDisp->GetDisplayPlaneCapabilitiesKHR =
167 (PFN_vkGetDisplayPlaneCapabilitiesKHR)gpa(instance, "vkGetDisplayPlaneCapabilitiesKHR");
168 pDisp->CreateDisplayPlaneSurfaceKHR =
169 (PFN_vkCreateDisplayPlaneSurfaceKHR)gpa(instance, "vkCreateDisplayPlaneSurfaceKHR");
Mark Lobodzinskie86e1382015-11-24 15:50:44 -0700170
171#if VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700172 pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)gpa(instance, "vkCreateWin32SurfaceKHR");
173 pDisp->GetPhysicalDeviceWin32PresentationSupportKHR =
174 (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700175#endif // VK_USE_PLATFORM_WIN32_KHR
176#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700177 pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR)gpa(instance, "vkCreateXcbSurfaceKHR");
178 pDisp->GetPhysicalDeviceXcbPresentationSupportKHR =
179 (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700180#endif // VK_USE_PLATFORM_XCB_KHR
181#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700182 pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR)gpa(instance, "vkCreateXlibSurfaceKHR");
183 pDisp->GetPhysicalDeviceXlibPresentationSupportKHR =
184 (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700185#endif // VK_USE_PLATFORM_XLIB_KHR
186#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700187 pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR)gpa(instance, "vkCreateMirSurfaceKHR");
188 pDisp->GetPhysicalDeviceMirPresentationSupportKHR =
189 (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR");
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700190#endif // VK_USE_PLATFORM_MIR_KHR
191#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700192 pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR)gpa(instance, "vkCreateWaylandSurfaceKHR");
193 pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR =
194 (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR");
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700195#endif // VK_USE_PLATFORM_WAYLAND_KHR
196#ifdef VK_USE_PLATFORM_ANDROID_KHR
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700197 pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)gpa(instance, "vkCreateAndroidSurfaceKHR");
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700198#endif // VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinskie86e1382015-11-24 15:50:44 -0700199
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600200 instanceExtMap[pDisp] = {};
201
202 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
203 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Jon Ashburn3dc39382015-09-17 10:00:32 -0600204 instanceExtMap[pDisp].wsi_enabled = true;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600205 }
206#ifdef VK_USE_PLATFORM_XLIB_KHR
207 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
208 instanceExtMap[pDisp].xlib_enabled = true;
209 }
210#endif
211#ifdef VK_USE_PLATFORM_XCB_KHR
212 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
213 instanceExtMap[pDisp].xcb_enabled = true;
214 }
215#endif
216#ifdef VK_USE_PLATFORM_WAYLAND_KHR
217 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
218 instanceExtMap[pDisp].wayland_enabled = true;
219 }
220#endif
221#ifdef VK_USE_PLATFORM_MIR_KHR
222 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
223 instanceExtMap[pDisp].mir_enabled = true;
224 }
225#endif
226#ifdef VK_USE_PLATFORM_ANDROID_KHR
227 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
228 instanceExtMap[pDisp].android_enabled = true;
229 }
230#endif
231#ifdef VK_USE_PLATFORM_WIN32_KHR
232 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
233 instanceExtMap[pDisp].win32_enabled = true;
234 }
235#endif
Jon Ashburn3dc39382015-09-17 10:00:32 -0600236 }
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600237
Jon Ashburn3dc39382015-09-17 10:00:32 -0600238}
239
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600240// Indicate device or instance dispatch table type
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600241enum DispTableType {
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600242 DISP_TBL_TYPE_INSTANCE,
243 DISP_TBL_TYPE_DEVICE,
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600244};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600245
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700246debug_report_data *mdd(const void *object) {
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600247 dispatch_key key = get_dispatch_key(object);
248 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600249 return my_data->report_data;
250}
251
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700252debug_report_data *mid(VkInstance object) {
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600253 dispatch_key key = get_dispatch_key(object);
254 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600255 return my_data->report_data;
256}
257
258// For each Queue's doubly linked-list of mem refs
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600259struct OT_MEM_INFO {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700260 VkDeviceMemory mem;
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600261 OT_MEM_INFO *pNextMI;
262 OT_MEM_INFO *pPrevMI;
263};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600264
265// Track Queue information
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600266struct OT_QUEUE_INFO {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700267 OT_MEM_INFO *pMemRefList;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700268 uint32_t queueNodeIndex;
269 VkQueue queue;
270 uint32_t refCount;
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600271};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600272
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600273// Global map of structures, one per queue
274std::unordered_map<VkQueue, OT_QUEUE_INFO *> queue_info_map;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600275
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600276#include "vk_dispatch_table_helper.h"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600277
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600278static void init_object_tracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
279
280 layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_object_tracker");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600281}
282
Tony Barboura05dbaa2015-07-09 17:31:46 -0600283//
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700284// Forward declarations
Tony Barboura05dbaa2015-07-09 17:31:46 -0600285//
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600286
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700287static void create_physical_device(VkInstance dispatchable_object, VkPhysicalDevice vkObj, VkDebugReportObjectTypeEXT objType);
288static void create_instance(VkInstance dispatchable_object, VkInstance object, VkDebugReportObjectTypeEXT objType);
289static void create_device(VkDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700290static void create_device(VkPhysicalDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700291static void create_queue(VkDevice dispatchable_object, VkQueue vkObj, VkDebugReportObjectTypeEXT objType);
Jon Ashburn5e026df2016-06-15 08:19:07 -0600292static void create_display_khr(VkPhysicalDevice dispatchable_object, VkDisplayKHR vkObj, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600293static bool validate_image(VkQueue dispatchable_object, VkImage object, VkDebugReportObjectTypeEXT objType, bool null_allowed);
294static bool validate_instance(VkInstance dispatchable_object, VkInstance object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700295 bool null_allowed);
Jon Ashburn5e026df2016-06-15 08:19:07 -0600296static bool validate_physical_device(VkPhysicalDevice dispatchable_object, VkPhysicalDevice object, VkDebugReportObjectTypeEXT objType, bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600297static bool validate_device(VkDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700298 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600299static bool validate_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700300 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600301static bool validate_descriptor_set_layout(VkDevice dispatchable_object, VkDescriptorSetLayout object,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700302 VkDebugReportObjectTypeEXT objType, bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600303static bool validate_command_pool(VkDevice dispatchable_object, VkCommandPool object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700304 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600305static bool validate_buffer(VkQueue dispatchable_object, VkBuffer object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700306 bool null_allowed);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700307static void create_pipeline(VkDevice dispatchable_object, VkPipeline vkObj, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600308static bool validate_pipeline_cache(VkDevice dispatchable_object, VkPipelineCache object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700309 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600310static bool validate_render_pass(VkDevice dispatchable_object, VkRenderPass object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700311 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600312static bool validate_shader_module(VkDevice dispatchable_object, VkShaderModule object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700313 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600314static bool validate_pipeline_layout(VkDevice dispatchable_object, VkPipelineLayout object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700315 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600316static bool validate_pipeline(VkDevice dispatchable_object, VkPipeline object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700317 bool null_allowed);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700318static void destroy_command_pool(VkDevice dispatchable_object, VkCommandPool object);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700319static void destroy_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object);
320static void destroy_descriptor_set(VkDevice dispatchable_object, VkDescriptorSet object);
321static void destroy_device_memory(VkDevice dispatchable_object, VkDeviceMemory object);
322static void destroy_swapchain_khr(VkDevice dispatchable_object, VkSwapchainKHR object);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600323static bool set_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700324 ObjectStatusFlags status_flag);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600325static bool reset_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700326 ObjectStatusFlags status_flag);
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600327static void destroy_queue(VkQueue dispatchable_object, VkQueue object);
328
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600329extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkPhysicalDeviceMap;
330extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkDeviceMap;
331extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkImageMap;
332extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkQueueMap;
333extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkDescriptorSetMap;
334extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkBufferMap;
335extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkFenceMap;
336extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSemaphoreMap;
337extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkCommandPoolMap;
338extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkCommandBufferMap;
339extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSwapchainKHRMap;
340extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSurfaceKHRMap;
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600341extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkQueueMap;
Tony Barboura05dbaa2015-07-09 17:31:46 -0600342
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600343// Convert an object type enum to an object type array index
344static uint32_t objTypeToIndex(uint32_t objType) {
345 uint32_t index = objType;
346 return index;
347}
348
349// Add new queue to head of global queue list
350static void addQueueInfo(uint32_t queueNodeIndex, VkQueue queue) {
351 auto queueItem = queue_info_map.find(queue);
352 if (queueItem == queue_info_map.end()) {
353 OT_QUEUE_INFO *p_queue_info = new OT_QUEUE_INFO;
354 if (p_queue_info != NULL) {
355 memset(p_queue_info, 0, sizeof(OT_QUEUE_INFO));
356 p_queue_info->queue = queue;
357 p_queue_info->queueNodeIndex = queueNodeIndex;
358 queue_info_map[queue] = p_queue_info;
359 } else {
360 log_msg(mdd(queue), VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
361 reinterpret_cast<uint64_t>(queue), __LINE__, OBJTRACK_INTERNAL_ERROR, "OBJTRACK",
362 "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");
363 }
364 }
365}
366
367// Destroy memRef lists and free all memory
368static void destroyQueueMemRefLists() {
369 for (auto queue_item : queue_info_map) {
370 OT_MEM_INFO *p_mem_info = queue_item.second->pMemRefList;
371 while (p_mem_info != NULL) {
372 OT_MEM_INFO *p_del_mem_info = p_mem_info;
373 p_mem_info = p_mem_info->pNextMI;
374 delete p_del_mem_info;
375 }
376 delete queue_item.second;
377 }
378 queue_info_map.clear();
379
380 // Destroy the items in the queue map
381 auto queue = VkQueueMap.begin();
382 while (queue != VkQueueMap.end()) {
383 uint32_t obj_index = objTypeToIndex(queue->second->objType);
384 assert(numTotalObjs > 0);
385 numTotalObjs--;
386 assert(numObjs[obj_index] > 0);
387 numObjs[obj_index]--;
388 log_msg(mdd(reinterpret_cast<VkQueue>(queue->second->vkObj)), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, queue->second->objType,
389 queue->second->vkObj, __LINE__, OBJTRACK_NONE, "OBJTRACK",
390 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",
391 string_VkDebugReportObjectTypeEXT(queue->second->objType), queue->second->vkObj, numTotalObjs, numObjs[obj_index],
392 string_VkDebugReportObjectTypeEXT(queue->second->objType));
393 delete queue->second;
394 queue = VkQueueMap.erase(queue);
395 }
396}
397
398// Check Queue type flags for selected queue operations
399static void validateQueueFlags(VkQueue queue, const char *function) {
400
401 auto queue_item = queue_info_map.find(queue);
402 if (queue_item != queue_info_map.end()) {
403 OT_QUEUE_INFO *pQueueInfo = queue_item->second;
404 if (pQueueInfo != NULL) {
405 if ((queue_family_properties[pQueueInfo->queueNodeIndex].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) == 0) {
406 log_msg(mdd(queue), VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
407 reinterpret_cast<uint64_t>(queue), __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",
408 "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set", function);
409 }
410 }
411 }
412}
413
414static void create_physical_device(VkInstance instance, VkPhysicalDevice vkObj, VkDebugReportObjectTypeEXT objType) {
415 log_msg(mdd(instance), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700416 OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
417 string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj));
Tobin Ehlisec598302015-09-15 15:02:17 -0600418
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600419 uint64_t physical_device_handle = reinterpret_cast<uint64_t>(vkObj);
420 auto pd_item = VkPhysicalDeviceMap.find(physical_device_handle);
421 if (pd_item == VkPhysicalDeviceMap.end()) {
422 OBJTRACK_NODE *p_new_obj_node = new OBJTRACK_NODE;
423 p_new_obj_node->objType = objType;
424 p_new_obj_node->belongsTo = reinterpret_cast<uint64_t>(instance);
425 p_new_obj_node->status = OBJSTATUS_NONE;
426 p_new_obj_node->vkObj = physical_device_handle;
427 VkPhysicalDeviceMap[physical_device_handle] = p_new_obj_node;
428 uint32_t objIndex = objTypeToIndex(objType);
429 numObjs[objIndex]++;
430 numTotalObjs++;
431 }
Tobin Ehlisec598302015-09-15 15:02:17 -0600432}
433
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700434static void create_surface_khr(VkInstance dispatchable_object, VkSurfaceKHR vkObj, VkDebugReportObjectTypeEXT objType) {
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -0700435 // TODO: Add tracking of surface objects
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700436 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE,
437 "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
438 string_VkDebugReportObjectTypeEXT(objType), (uint64_t)(vkObj));
Tobin Ehlis86684f92016-01-05 10:33:58 -0700439
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700440 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
Tobin Ehlis86684f92016-01-05 10:33:58 -0700441 pNewObjNode->objType = objType;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700442 pNewObjNode->belongsTo = (uint64_t)dispatchable_object;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700443 pNewObjNode->status = OBJSTATUS_NONE;
444 pNewObjNode->vkObj = (uint64_t)(vkObj);
Tobin Ehlis86684f92016-01-05 10:33:58 -0700445 VkSurfaceKHRMap[(uint64_t)vkObj] = pNewObjNode;
446 uint32_t objIndex = objTypeToIndex(objType);
447 numObjs[objIndex]++;
448 numTotalObjs++;
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -0700449}
450
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700451static void destroy_surface_khr(VkInstance dispatchable_object, VkSurfaceKHR object) {
Mark Young93ecb1d2016-01-13 13:47:16 -0700452 uint64_t object_handle = (uint64_t)(object);
Tobin Ehlis86684f92016-01-05 10:33:58 -0700453 if (VkSurfaceKHRMap.find(object_handle) != VkSurfaceKHRMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700454 OBJTRACK_NODE *pNode = VkSurfaceKHRMap[(uint64_t)object];
Tobin Ehlis86684f92016-01-05 10:33:58 -0700455 uint32_t objIndex = objTypeToIndex(pNode->objType);
456 assert(numTotalObjs > 0);
457 numTotalObjs--;
458 assert(numObjs[objIndex] > 0);
459 numObjs[objIndex]--;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700460 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, object_handle, __LINE__,
461 OBJTRACK_NONE, "OBJTRACK",
Mark Muelleraab36502016-05-03 13:17:29 -0600462 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (0x%" PRIx64 " total objs remain & 0x%" PRIx64 " %s objs).",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700463 string_VkDebugReportObjectTypeEXT(pNode->objType), (uint64_t)(object), numTotalObjs, numObjs[objIndex],
464 string_VkDebugReportObjectTypeEXT(pNode->objType));
Tobin Ehlis86684f92016-01-05 10:33:58 -0700465 delete pNode;
466 VkSurfaceKHRMap.erase(object_handle);
467 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700468 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__,
469 OBJTRACK_NONE, "OBJTRACK",
470 "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle);
Tobin Ehlis86684f92016-01-05 10:33:58 -0700471 }
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -0700472}
473
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700474static void alloc_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer vkObj,
475 VkDebugReportObjectTypeEXT objType, VkCommandBufferLevel level) {
476 log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__, OBJTRACK_NONE,
477 "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
478 string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj));
Tony Barboura05dbaa2015-07-09 17:31:46 -0600479
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700480 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
481 pNewObjNode->objType = objType;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700482 pNewObjNode->belongsTo = (uint64_t)device;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700483 pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj);
484 pNewObjNode->parentObj = (uint64_t)commandPool;
Mark Lobodzinski2fba0322016-01-23 18:31:23 -0700485 if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
486 pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY;
487 } else {
488 pNewObjNode->status = OBJSTATUS_NONE;
489 }
Michael Lentine13803dc2015-11-04 14:35:12 -0800490 VkCommandBufferMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode;
Tony Barboura05dbaa2015-07-09 17:31:46 -0600491 uint32_t objIndex = objTypeToIndex(objType);
492 numObjs[objIndex]++;
493 numTotalObjs++;
494}
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700495
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600496static bool validate_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer commandBuffer) {
497 bool skipCall = false;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700498 uint64_t object_handle = reinterpret_cast<uint64_t>(commandBuffer);
499 if (VkCommandBufferMap.find(object_handle) != VkCommandBufferMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700500 OBJTRACK_NODE *pNode = VkCommandBufferMap[(uint64_t)commandBuffer];
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700501
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700502 if (pNode->parentObj != (uint64_t)(commandPool)) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600503 skipCall |= log_msg(
504 mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, object_handle, __LINE__, OBJTRACK_COMMAND_POOL_MISMATCH,
505 "OBJTRACK", "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64
506 " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600507 reinterpret_cast<uint64_t>(commandBuffer), pNode->parentObj, reinterpret_cast<uint64_t &>(commandPool));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700508 }
509 } else {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600510 skipCall |= log_msg(
511 mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__, OBJTRACK_NONE,
512 "OBJTRACK", "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700513 }
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600514 return skipCall;
515}
516
517static bool free_command_buffer(VkDevice device, VkCommandBuffer commandBuffer) {
518 bool skipCall = false;
519 auto cbItem = VkCommandBufferMap.find(reinterpret_cast<uint64_t>(commandBuffer));
520 if (cbItem != VkCommandBufferMap.end()) {
521 OBJTRACK_NODE *pNode = cbItem->second;
522 uint32_t objIndex = objTypeToIndex(pNode->objType);
523 assert(numTotalObjs > 0);
524 numTotalObjs--;
525 assert(numObjs[objIndex] > 0);
526 numObjs[objIndex]--;
527 skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType,
528 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, OBJTRACK_NONE, "OBJTRACK",
529 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",
530 string_VkDebugReportObjectTypeEXT(pNode->objType), reinterpret_cast<uint64_t>(commandBuffer),
531 numTotalObjs, numObjs[objIndex], string_VkDebugReportObjectTypeEXT(pNode->objType));
532 delete pNode;
533 VkCommandBufferMap.erase(cbItem);
534 }
535 return skipCall;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700536}
537
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700538static void alloc_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet vkObj,
539 VkDebugReportObjectTypeEXT objType) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700540 log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, "OBJTRACK",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700541 "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, string_VkDebugReportObjectTypeEXT(objType),
542 (uint64_t)(vkObj));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700543
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700544 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
545 pNewObjNode->objType = objType;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700546 pNewObjNode->belongsTo = (uint64_t)device;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700547 pNewObjNode->status = OBJSTATUS_NONE;
548 pNewObjNode->vkObj = (uint64_t)(vkObj);
549 pNewObjNode->parentObj = (uint64_t)descriptorPool;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700550 VkDescriptorSetMap[(uint64_t)vkObj] = pNewObjNode;
551 uint32_t objIndex = objTypeToIndex(objType);
552 numObjs[objIndex]++;
553 numTotalObjs++;
554}
555
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600556static bool validate_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet descriptorSet) {
557 bool skipCall = false;
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600558 uint64_t object_handle = reinterpret_cast<uint64_t &>(descriptorSet);
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600559 auto dsItem = VkDescriptorSetMap.find(object_handle);
560 if (dsItem != VkDescriptorSetMap.end()) {
561 OBJTRACK_NODE *pNode = dsItem->second;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700562
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600563 if (pNode->parentObj != reinterpret_cast<uint64_t &>(descriptorPool)) {
564 skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, object_handle, __LINE__,
565 OBJTRACK_DESCRIPTOR_POOL_MISMATCH, "OBJTRACK",
566 "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64
567 " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
568 reinterpret_cast<uint64_t &>(descriptorSet), pNode->parentObj,
569 reinterpret_cast<uint64_t &>(descriptorPool));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700570 }
571 } else {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600572 skipCall |= log_msg(
573 mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__, OBJTRACK_NONE,
574 "OBJTRACK", "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700575 }
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600576 return skipCall;
577}
578
579static bool free_descriptor_set(VkDevice device, VkDescriptorSet descriptorSet) {
580 bool skipCall = false;
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600581 auto dsItem = VkDescriptorSetMap.find(reinterpret_cast<uint64_t &>(descriptorSet));
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600582 if (dsItem != VkDescriptorSetMap.end()) {
583 OBJTRACK_NODE *pNode = dsItem->second;
584 uint32_t objIndex = objTypeToIndex(pNode->objType);
585 assert(numTotalObjs > 0);
586 numTotalObjs--;
587 assert(numObjs[objIndex] > 0);
588 numObjs[objIndex]--;
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600589 skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType,
590 reinterpret_cast<uint64_t &>(descriptorSet), __LINE__, OBJTRACK_NONE, "OBJTRACK",
591 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",
592 string_VkDebugReportObjectTypeEXT(pNode->objType), reinterpret_cast<uint64_t &>(descriptorSet),
593 numTotalObjs, numObjs[objIndex], string_VkDebugReportObjectTypeEXT(pNode->objType));
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600594 delete pNode;
595 VkDescriptorSetMap.erase(dsItem);
596 }
597 return skipCall;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700598}
599
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600600static void create_queue(VkDevice device, VkQueue vkObj, VkDebugReportObjectTypeEXT objType) {
601
602 log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700603 OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
604 string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj));
Tobin Ehlisec598302015-09-15 15:02:17 -0600605
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600606 OBJTRACK_NODE *p_obj_node = NULL;
607 auto queue_item = VkQueueMap.find(reinterpret_cast<uint64_t>(vkObj));
608 if (queue_item == VkQueueMap.end()) {
609 p_obj_node = new OBJTRACK_NODE;
610 VkQueueMap[reinterpret_cast<uint64_t>(vkObj)] = p_obj_node;
611 uint32_t objIndex = objTypeToIndex(objType);
612 numObjs[objIndex]++;
613 numTotalObjs++;
614 } else {
615 p_obj_node = queue_item->second;
616 }
617 p_obj_node->objType = objType;
618 p_obj_node->belongsTo = reinterpret_cast<uint64_t>(device);
619 p_obj_node->status = OBJSTATUS_NONE;
620 p_obj_node->vkObj = reinterpret_cast<uint64_t>(vkObj);
Tobin Ehlisec598302015-09-15 15:02:17 -0600621}
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600622
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700623static void create_swapchain_image_obj(VkDevice dispatchable_object, VkImage vkObj, VkSwapchainKHR swapchain) {
624 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)vkObj,
625 __LINE__, OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
626 "SwapchainImage", (uint64_t)(vkObj));
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600627
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700628 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
629 pNewObjNode->belongsTo = (uint64_t)dispatchable_object;
630 pNewObjNode->objType = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT;
631 pNewObjNode->status = OBJSTATUS_NONE;
632 pNewObjNode->vkObj = (uint64_t)vkObj;
633 pNewObjNode->parentObj = (uint64_t)swapchain;
Mark Young93ecb1d2016-01-13 13:47:16 -0700634 swapchainImageMap[(uint64_t)(vkObj)] = pNewObjNode;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600635}
636
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700637static void create_device(VkInstance dispatchable_object, VkDevice vkObj, VkDebugReportObjectTypeEXT objType) {
638 log_msg(mid(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE,
639 "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
640 string_VkDebugReportObjectTypeEXT(objType), (uint64_t)(vkObj));
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700641
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700642 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700643 pNewObjNode->belongsTo = (uint64_t)dispatchable_object;
644 pNewObjNode->objType = objType;
645 pNewObjNode->status = OBJSTATUS_NONE;
646 pNewObjNode->vkObj = (uint64_t)(vkObj);
647 VkDeviceMap[(uint64_t)vkObj] = pNewObjNode;
648 uint32_t objIndex = objTypeToIndex(objType);
649 numObjs[objIndex]++;
650 numTotalObjs++;
651}
652
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600653//
654// Non-auto-generated API functions called by generated code
655//
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700656VkResult explicit_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
657 VkInstance *pInstance) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700658 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
David Pinedoc0fa1ab2015-07-31 10:46:25 -0600659
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700660 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700661 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700662 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700663 if (fpCreateInstance == NULL) {
664 return VK_ERROR_INITIALIZATION_FAILED;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600665 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700666
667 // Advance the link info for the next element on the chain
668 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
669
670 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
671 if (result != VK_SUCCESS) {
672 return result;
673 }
674
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700675 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Chia-I Wu1ad50f42016-05-17 07:57:15 +0800676 my_data->instance = *pInstance;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700677 initInstanceTable(*pInstance, fpGetInstanceProcAddr, object_tracker_instance_table_map);
678 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, *pInstance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700679
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600680 // Look for one or more debug report create info structures, and copy the
681 // callback(s) for each one found (for use by vkDestroyInstance)
682 layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos,
683 &my_data->tmp_callbacks);
684
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700685 my_data->report_data = debug_report_create_instance(pInstanceTable, *pInstance, pCreateInfo->enabledExtensionCount,
686 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700687
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600688 init_object_tracker(my_data, pAllocator);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700689 createInstanceRegisterExtensions(pCreateInfo, *pInstance);
690
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700691 create_instance(*pInstance, *pInstance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700692
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600693 return result;
694}
695
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700696void explicit_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice gpu, uint32_t *pCount, VkQueueFamilyProperties *pProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700697 get_dispatch_table(object_tracker_instance_table_map, gpu)->GetPhysicalDeviceQueueFamilyProperties(gpu, pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600698
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600699 std::lock_guard<std::mutex> lock(global_lock);
700 if (pProperties != NULL) {
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600701 for (uint32_t i = 0; i < *pCount; i++) {
702 queue_family_properties.emplace_back(pProperties[i]);
703 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600704 }
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600705}
706
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700707VkResult explicit_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
708 VkDevice *pDevice) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600709 std::lock_guard<std::mutex> lock(global_lock);
Chia-I Wu1ad50f42016-05-17 07:57:15 +0800710 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700711 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700712
713 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700714 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
715 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
Chia-I Wu1ad50f42016-05-17 07:57:15 +0800716 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700717 if (fpCreateDevice == NULL) {
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700718 return VK_ERROR_INITIALIZATION_FAILED;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600719 }
720
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700721 // Advance the link info for the next element on the chain
722 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
723
724 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
725 if (result != VK_SUCCESS) {
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700726 return result;
727 }
728
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700729 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
730 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700731
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700732 initDeviceTable(*pDevice, fpGetDeviceProcAddr, object_tracker_device_table_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700733
734 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
735
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700736 if (VkPhysicalDeviceMap.find((uint64_t)gpu) != VkPhysicalDeviceMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700737 OBJTRACK_NODE *pNewObjNode = VkPhysicalDeviceMap[(uint64_t)gpu];
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700738 create_device((VkInstance)pNewObjNode->belongsTo, *pDevice, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT);
739 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700740
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600741 return result;
742}
743
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700744VkResult explicit_EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
745 VkPhysicalDevice *pPhysicalDevices) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600746 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600747 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700748 skipCall |= validate_instance(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600749 lock.unlock();
Tobin Ehlisec598302015-09-15 15:02:17 -0600750 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700751 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700752 VkResult result = get_dispatch_table(object_tracker_instance_table_map, instance)
753 ->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600754 lock.lock();
Tobin Ehlisec598302015-09-15 15:02:17 -0600755 if (result == VK_SUCCESS) {
756 if (pPhysicalDevices) {
757 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700758 create_physical_device(instance, pPhysicalDevices[i], VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT);
Tobin Ehlisec598302015-09-15 15:02:17 -0600759 }
760 }
761 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600762 lock.unlock();
Tobin Ehlisec598302015-09-15 15:02:17 -0600763 return result;
764}
765
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700766void explicit_GetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue *pQueue) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600767 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700768 validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600769 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600770
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700771 get_dispatch_table(object_tracker_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600772
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600773 lock.lock();
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600774
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700775 create_queue(device, *pQueue, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT);
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600776 addQueueInfo(queueNodeIndex, *pQueue);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600777}
778
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700779VkResult explicit_MapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkFlags flags,
780 void **ppData) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600781 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600782 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700783 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600784 lock.unlock();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600785 if (skipCall == VK_TRUE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700786 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600787
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700788 VkResult result =
789 get_dispatch_table(object_tracker_device_table_map, device)->MapMemory(device, mem, offset, size, flags, ppData);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600790
791 return result;
792}
793
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700794void explicit_UnmapMemory(VkDevice device, VkDeviceMemory mem) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600795 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600796 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700797 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600798 lock.unlock();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600799 if (skipCall == VK_TRUE)
800 return;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600801
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700802 get_dispatch_table(object_tracker_device_table_map, device)->UnmapMemory(device, mem);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600803}
804
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700805VkResult explicit_QueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, VkFence fence) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600806 std::unique_lock<std::mutex> lock(global_lock);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800807 validateQueueFlags(queue, "QueueBindSparse");
808
809 for (uint32_t i = 0; i < bindInfoCount; i++) {
810 for (uint32_t j = 0; j < pBindInfo[i].bufferBindCount; j++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700811 validate_buffer(queue, pBindInfo[i].pBufferBinds[j].buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, false);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800812 for (uint32_t j = 0; j < pBindInfo[i].imageOpaqueBindCount; j++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700813 validate_image(queue, pBindInfo[i].pImageOpaqueBinds[j].image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800814 for (uint32_t j = 0; j < pBindInfo[i].imageBindCount; j++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700815 validate_image(queue, pBindInfo[i].pImageBinds[j].image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800816 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600817 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600818
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700819 VkResult result =
820 get_dispatch_table(object_tracker_device_table_map, queue)->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -0600821 return result;
822}
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600823
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700824VkResult explicit_AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
825 VkCommandBuffer *pCommandBuffers) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600826 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600827 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700828 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
829 skipCall |= validate_command_pool(device, pAllocateInfo->commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600830 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700831
832 if (skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700833 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700834 }
835
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700836 VkResult result =
837 get_dispatch_table(object_tracker_device_table_map, device)->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700838
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600839 lock.lock();
Jon Ashburnf19916e2016-01-11 13:12:43 -0700840 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700841 alloc_command_buffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
842 pAllocateInfo->level);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700843 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600844 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700845
846 return result;
847}
848
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700849VkResult explicit_AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
850 VkDescriptorSet *pDescriptorSets) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600851 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600852 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700853 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700854 skipCall |=
855 validate_descriptor_pool(device, pAllocateInfo->descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false);
Jon Ashburnf19916e2016-01-11 13:12:43 -0700856 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700857 skipCall |= validate_descriptor_set_layout(device, pAllocateInfo->pSetLayouts[i],
858 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, false);
Tobin Ehlisec598302015-09-15 15:02:17 -0600859 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600860 lock.unlock();
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600861 if (skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700862 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600863 }
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600864
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700865 VkResult result =
866 get_dispatch_table(object_tracker_device_table_map, device)->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600867
Chris Forbes539a87c2016-01-22 15:44:40 +1300868 if (VK_SUCCESS == result) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600869 lock.lock();
Chris Forbes539a87c2016-01-22 15:44:40 +1300870 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700871 alloc_descriptor_set(device, pAllocateInfo->descriptorPool, pDescriptorSets[i],
872 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT);
Chris Forbes539a87c2016-01-22 15:44:40 +1300873 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600874 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600875 }
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600876
877 return result;
878}
879
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700880void explicit_FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
881 const VkCommandBuffer *pCommandBuffers) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600882 bool skipCall = false;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600883 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700884 validate_command_pool(device, commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false);
885 validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600886 for (uint32_t i = 0; i < commandBufferCount; i++) {
887 skipCall |= validate_command_buffer(device, commandPool, pCommandBuffers[i]);
888 }
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700889
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600890 lock.unlock();
891 if (!skipCall) {
892 get_dispatch_table(object_tracker_device_table_map, device)
893 ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
894 }
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700895
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600896 lock.lock();
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700897 for (uint32_t i = 0; i < commandBufferCount; i++) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600898 free_command_buffer(device, pCommandBuffers[i]);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700899 }
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700900}
901
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700902void explicit_DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600903 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700904 // A swapchain's images are implicitly deleted when the swapchain is deleted.
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600905 // Remove this swapchain's images from our map of such images.
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600906 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = swapchainImageMap.begin();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600907 while (itr != swapchainImageMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700908 OBJTRACK_NODE *pNode = (*itr).second;
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600909 if (pNode->parentObj == reinterpret_cast<uint64_t &>(swapchain)) {
910 delete pNode;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700911 swapchainImageMap.erase(itr++);
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600912 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700913 ++itr;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600914 }
915 }
Tobin Ehlis86684f92016-01-05 10:33:58 -0700916 destroy_swapchain_khr(device, swapchain);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600917 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600918
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700919 get_dispatch_table(object_tracker_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600920}
921
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700922void explicit_FreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600923 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700924 validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600925 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600926
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700927 get_dispatch_table(object_tracker_device_table_map, device)->FreeMemory(device, mem, pAllocator);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600928
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600929 lock.lock();
Michael Lentine13803dc2015-11-04 14:35:12 -0800930 destroy_device_memory(device, mem);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600931}
Tony Barboura05dbaa2015-07-09 17:31:46 -0600932
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700933VkResult explicit_FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
934 const VkDescriptorSet *pDescriptorSets) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600935 bool skipCall = false;
936 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600937 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600938 skipCall |= validate_descriptor_pool(device, descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false);
939 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
940 for (uint32_t i = 0; i < count; i++) {
941 skipCall |= validate_descriptor_set(device, descriptorPool, pDescriptorSets[i]);
942 }
943
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600944 lock.unlock();
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600945 if (!skipCall) {
946 result = get_dispatch_table(object_tracker_device_table_map, device)
947 ->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
948 }
Tony Barbour770f80d2015-07-20 10:52:13 -0600949
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600950 lock.lock();
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700951 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600952 free_descriptor_set(device, pDescriptorSets[i]);
Tony Barbour770f80d2015-07-20 10:52:13 -0600953 }
Tony Barbour770f80d2015-07-20 10:52:13 -0600954 return result;
955}
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600956
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700957void explicit_DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600958 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600959 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700960 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
961 skipCall |= validate_descriptor_pool(device, descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600962 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700963 if (skipCall) {
964 return;
965 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700966 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is deleted.
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700967 // Remove this pool's descriptor sets from our descriptorSet map.
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600968 lock.lock();
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600969 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = VkDescriptorSetMap.begin();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700970 while (itr != VkDescriptorSetMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700971 OBJTRACK_NODE *pNode = (*itr).second;
Mark Lobodzinskib29731a2015-11-18 11:01:02 -0700972 auto del_itr = itr++;
Mark Young93ecb1d2016-01-13 13:47:16 -0700973 if (pNode->parentObj == (uint64_t)(descriptorPool)) {
974 destroy_descriptor_set(device, (VkDescriptorSet)((*del_itr).first));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700975 }
976 }
977 destroy_descriptor_pool(device, descriptorPool);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600978 lock.unlock();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700979 get_dispatch_table(object_tracker_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700980}
981
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700982void explicit_DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600983 bool skipCall = false;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600984 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700985 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
986 skipCall |= validate_command_pool(device, commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600987 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700988 if (skipCall) {
989 return;
990 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600991 lock.lock();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700992 // A CommandPool's command buffers are implicitly deleted when the pool is deleted.
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700993 // Remove this pool's cmdBuffers from our cmd buffer map.
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600994 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = VkCommandBufferMap.begin();
995 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator del_itr;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700996 while (itr != VkCommandBufferMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700997 OBJTRACK_NODE *pNode = (*itr).second;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700998 del_itr = itr++;
Mark Young93ecb1d2016-01-13 13:47:16 -0700999 if (pNode->parentObj == (uint64_t)(commandPool)) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -06001000 skipCall |= validate_command_buffer(device, commandPool, reinterpret_cast<VkCommandBuffer>((*del_itr).first));
1001 free_command_buffer(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -07001002 }
1003 }
1004 destroy_command_pool(device, commandPool);
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001005 lock.unlock();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001006 get_dispatch_table(object_tracker_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -07001007}
1008
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001009VkResult explicit_GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pCount, VkImage *pSwapchainImages) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001010 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001011 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001012 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001013 lock.unlock();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -06001014 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001015 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -06001016
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001017 VkResult result = get_dispatch_table(object_tracker_device_table_map, device)
1018 ->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -06001019
1020 if (pSwapchainImages != NULL) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001021 lock.lock();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -06001022 for (uint32_t i = 0; i < *pCount; i++) {
1023 create_swapchain_image_obj(device, pSwapchainImages[i], swapchain);
1024 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001025 lock.unlock();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -06001026 }
1027 return result;
1028}
1029
Jon Ashburn5e026df2016-06-15 08:19:07 -06001030VkResult VKAPI_CALL explicit_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t* pDisplayCount, VkDisplayKHR* pDisplays)
1031{
1032 bool skipCall = false;
1033 {
1034 std::lock_guard<std::mutex> lock(global_lock);
1035 skipCall |= validate_physical_device(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false);
1036 }
1037 if (skipCall)
1038 return VK_ERROR_VALIDATION_FAILED_EXT;
1039 VkResult result = get_dispatch_table(object_tracker_instance_table_map, physicalDevice)->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, pDisplays);
1040 {
1041 std::lock_guard<std::mutex> lock(global_lock);
1042 if (result == VK_SUCCESS) {
1043 for (uint32_t idx=0; idx<*pDisplayCount; ++idx) {
1044 create_display_khr(physicalDevice, pDisplays[idx], VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT);
1045 }
1046 }
1047 }
1048 return result;
1049}
1050
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001051// TODO: Add special case to codegen to cover validating all the pipelines instead of just the first
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001052VkResult explicit_CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1053 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1054 VkPipeline *pPipelines) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001055 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001056 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001057 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001058 if (pCreateInfos) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001059 for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001060 if (pCreateInfos[idx0].basePipelineHandle) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001061 skipCall |= validate_pipeline(device, pCreateInfos[idx0].basePipelineHandle,
1062 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, true);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001063 }
1064 if (pCreateInfos[idx0].layout) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001065 skipCall |= validate_pipeline_layout(device, pCreateInfos[idx0].layout,
1066 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001067 }
1068 if (pCreateInfos[idx0].pStages) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001069 for (uint32_t idx1 = 0; idx1 < pCreateInfos[idx0].stageCount; ++idx1) {
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001070 if (pCreateInfos[idx0].pStages[idx1].module) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001071 skipCall |= validate_shader_module(device, pCreateInfos[idx0].pStages[idx1].module,
1072 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001073 }
1074 }
1075 }
1076 if (pCreateInfos[idx0].renderPass) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001077 skipCall |=
1078 validate_render_pass(device, pCreateInfos[idx0].renderPass, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001079 }
1080 }
1081 }
1082 if (pipelineCache) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001083 skipCall |= validate_pipeline_cache(device, pipelineCache, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001084 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001085 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001086 if (skipCall)
1087 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001088 VkResult result = get_dispatch_table(object_tracker_device_table_map, device)
1089 ->CreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001090 lock.lock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001091 if (result == VK_SUCCESS) {
1092 for (uint32_t idx2 = 0; idx2 < createInfoCount; ++idx2) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001093 create_pipeline(device, pPipelines[idx2], VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001094 }
1095 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001096 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001097 return result;
1098}
1099
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001100// TODO: Add special case to codegen to cover validating all the pipelines instead of just the first
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001101VkResult explicit_CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1102 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1103 VkPipeline *pPipelines) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001104 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001105 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001106 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001107 if (pCreateInfos) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001108 for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001109 if (pCreateInfos[idx0].basePipelineHandle) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001110 skipCall |= validate_pipeline(device, pCreateInfos[idx0].basePipelineHandle,
1111 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, true);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001112 }
1113 if (pCreateInfos[idx0].layout) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001114 skipCall |= validate_pipeline_layout(device, pCreateInfos[idx0].layout,
1115 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001116 }
1117 if (pCreateInfos[idx0].stage.module) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001118 skipCall |= validate_shader_module(device, pCreateInfos[idx0].stage.module,
1119 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001120 }
1121 }
1122 }
1123 if (pipelineCache) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001124 skipCall |= validate_pipeline_cache(device, pipelineCache, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001125 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001126 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001127 if (skipCall)
1128 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001129 VkResult result = get_dispatch_table(object_tracker_device_table_map, device)
1130 ->CreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001131 lock.lock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001132 if (result == VK_SUCCESS) {
1133 for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001134 create_pipeline(device, pPipelines[idx1], VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001135 }
1136 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001137 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001138 return result;
1139}
Chia-I Wucdb70962016-05-13 14:07:36 +08001140
1141} // namespace object_tracker