Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 17 | * |
| 18 | * Author: Jon Ashburn <jon@lunarg.com> |
| 19 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 20 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 23 | #include <mutex> |
| 24 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include "vulkan/vk_layer.h" |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 26 | #include "vk_layer_extension_utils.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 27 | #include "vk_enum_string_helper.h" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 28 | #include "vk_layer_table.h" |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 29 | #include "vk_layer_utils.h" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 30 | |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 31 | namespace object_tracker { |
| 32 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 33 | // Object Tracker ERROR codes |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 34 | enum OBJECT_TRACK_ERROR { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 35 | OBJTRACK_NONE, // Used for INFO & other non-error messages |
| 36 | OBJTRACK_UNKNOWN_OBJECT, // Updating uses of object that's not in global object list |
| 37 | OBJTRACK_INTERNAL_ERROR, // Bug with data tracking within the layer |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 38 | OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 39 | OBJTRACK_INVALID_OBJECT, // Object used that has never been created |
| 40 | OBJTRACK_DESCRIPTOR_POOL_MISMATCH, // Descriptor Pools specified incorrectly |
| 41 | OBJTRACK_COMMAND_POOL_MISMATCH, // Command Pools specified incorrectly |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 42 | }; |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 43 | |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 44 | // Object Status -- used to track state of individual objects |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 45 | typedef VkFlags ObjectStatusFlags; |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 46 | enum ObjectStatusFlagBits { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 47 | 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 Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 55 | }; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 56 | |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 57 | struct OBJTRACK_NODE { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 58 | 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 Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 63 | }; |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 64 | |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 65 | // prototype for extension functions |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 66 | uint64_t objTrackGetObjectCount(VkDevice device); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 67 | uint64_t objTrackGetObjectsOfTypeCount(VkDevice, VkDebugReportObjectTypeEXT type); |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 68 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 69 | // Func ptr typedefs |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 70 | typedef uint64_t (*OBJ_TRACK_GET_OBJECT_COUNT)(VkDevice); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 71 | typedef uint64_t (*OBJ_TRACK_GET_OBJECTS_OF_TYPE_COUNT)(VkDevice, VkDebugReportObjectTypeEXT); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 72 | |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 73 | struct layer_data { |
Chia-I Wu | 1ad50f4 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 74 | VkInstance instance; |
| 75 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 76 | debug_report_data *report_data; |
Cody Northrop | 9c93ec5 | 2016-04-28 09:55:08 -0600 | [diff] [blame] | 77 | // TODO: put instance data here |
| 78 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
| 79 | bool wsi_enabled; |
| 80 | bool objtrack_extensions_enabled; |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 81 | // 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 Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 86 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 87 | 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 Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 90 | }; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 91 | |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 92 | struct instance_extension_enables { |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 93 | bool wsi_enabled; |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 94 | bool xlib_enabled; |
| 95 | bool xcb_enabled; |
| 96 | bool wayland_enabled; |
| 97 | bool mir_enabled; |
| 98 | bool android_enabled; |
| 99 | bool win32_enabled; |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 100 | }; |
| 101 | |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 102 | static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 103 | static std::unordered_map<void *, layer_data *> layer_data_map; |
| 104 | static device_table_map object_tracker_device_table_map; |
| 105 | static instance_table_map object_tracker_instance_table_map; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 106 | |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 107 | // We need additionally validate image usage using a separate map |
| 108 | // of swapchain-created images |
Mark Lobodzinski | f93272b | 2016-05-02 12:08:24 -0600 | [diff] [blame] | 109 | static std::unordered_map<uint64_t, OBJTRACK_NODE *> swapchainImageMap; |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 110 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 111 | static long long unsigned int object_track_index = 0; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 112 | static std::mutex global_lock; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 113 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 114 | #define NUM_OBJECT_TYPES (VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT + 1) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 115 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 116 | static uint64_t numObjs[NUM_OBJECT_TYPES] = {0}; |
| 117 | static uint64_t numTotalObjs = 0; |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 118 | std::vector<VkQueueFamilyProperties> queue_family_properties; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 119 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 120 | // |
| 121 | // Internal Object Tracker Functions |
| 122 | // |
| 123 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 124 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 125 | 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 Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 127 | PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 128 | 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 Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 133 | my_device_data->wsi_enabled = false; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 134 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 135 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 136 | my_device_data->wsi_enabled = true; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 137 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 138 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], "OBJTRACK_EXTENSIONS") == 0) |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 139 | my_device_data->objtrack_extensions_enabled = true; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 143 | static void createInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 144 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(object_tracker_instance_table_map, instance); |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 145 | PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr; |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 146 | |
| 147 | pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR)gpa(instance, "vkDestroySurfaceKHR"); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 148 | 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"); |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 156 | #ifndef __ANDROID__ |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 157 | pDisp->GetPhysicalDeviceDisplayPropertiesKHR = |
| 158 | (PFN_vkGetPhysicalDeviceDisplayPropertiesKHR)gpa(instance, "vkGetPhysicalDeviceDisplayPropertiesKHR"); |
| 159 | pDisp->GetPhysicalDeviceDisplayPlanePropertiesKHR = |
| 160 | (PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR)gpa(instance, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); |
| 161 | pDisp->GetDisplayPlaneSupportedDisplaysKHR = |
| 162 | (PFN_vkGetDisplayPlaneSupportedDisplaysKHR)gpa(instance, "vkGetDisplayPlaneSupportedDisplaysKHR"); |
| 163 | pDisp->GetDisplayModePropertiesKHR = |
| 164 | (PFN_vkGetDisplayModePropertiesKHR)gpa(instance, "vkGetDisplayModePropertiesKHR"); |
| 165 | pDisp->CreateDisplayModeKHR = |
| 166 | (PFN_vkCreateDisplayModeKHR)gpa(instance, "vkCreateDisplayModeKHR"); |
| 167 | pDisp->GetDisplayPlaneCapabilitiesKHR = |
| 168 | (PFN_vkGetDisplayPlaneCapabilitiesKHR)gpa(instance, "vkGetDisplayPlaneCapabilitiesKHR"); |
| 169 | pDisp->CreateDisplayPlaneSurfaceKHR = |
| 170 | (PFN_vkCreateDisplayPlaneSurfaceKHR)gpa(instance, "vkCreateDisplayPlaneSurfaceKHR"); |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 171 | #endif |
Mark Lobodzinski | e86e138 | 2015-11-24 15:50:44 -0700 | [diff] [blame] | 172 | |
| 173 | #if VK_USE_PLATFORM_WIN32_KHR |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 174 | pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)gpa(instance, "vkCreateWin32SurfaceKHR"); |
| 175 | pDisp->GetPhysicalDeviceWin32PresentationSupportKHR = |
| 176 | (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR"); |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 177 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 178 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 179 | pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR)gpa(instance, "vkCreateXcbSurfaceKHR"); |
| 180 | pDisp->GetPhysicalDeviceXcbPresentationSupportKHR = |
| 181 | (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR"); |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 182 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 183 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 184 | pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR)gpa(instance, "vkCreateXlibSurfaceKHR"); |
| 185 | pDisp->GetPhysicalDeviceXlibPresentationSupportKHR = |
| 186 | (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR"); |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 187 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 188 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 189 | pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR)gpa(instance, "vkCreateMirSurfaceKHR"); |
| 190 | pDisp->GetPhysicalDeviceMirPresentationSupportKHR = |
| 191 | (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR"); |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 192 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 193 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 194 | pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR)gpa(instance, "vkCreateWaylandSurfaceKHR"); |
| 195 | pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR = |
| 196 | (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR"); |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 197 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 198 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 199 | pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)gpa(instance, "vkCreateAndroidSurfaceKHR"); |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 200 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | e86e138 | 2015-11-24 15:50:44 -0700 | [diff] [blame] | 201 | |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 202 | instanceExtMap[pDisp] = {}; |
| 203 | |
| 204 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 205 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) { |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 206 | instanceExtMap[pDisp].wsi_enabled = true; |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 207 | } |
| 208 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 209 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) { |
| 210 | instanceExtMap[pDisp].xlib_enabled = true; |
| 211 | } |
| 212 | #endif |
| 213 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 214 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) { |
| 215 | instanceExtMap[pDisp].xcb_enabled = true; |
| 216 | } |
| 217 | #endif |
| 218 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 219 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { |
| 220 | instanceExtMap[pDisp].wayland_enabled = true; |
| 221 | } |
| 222 | #endif |
| 223 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 224 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) { |
| 225 | instanceExtMap[pDisp].mir_enabled = true; |
| 226 | } |
| 227 | #endif |
| 228 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 229 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) { |
| 230 | instanceExtMap[pDisp].android_enabled = true; |
| 231 | } |
| 232 | #endif |
| 233 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 234 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) { |
| 235 | instanceExtMap[pDisp].win32_enabled = true; |
| 236 | } |
| 237 | #endif |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 238 | } |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 239 | |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 240 | } |
| 241 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 242 | // Indicate device or instance dispatch table type |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 243 | enum DispTableType { |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 244 | DISP_TBL_TYPE_INSTANCE, |
| 245 | DISP_TBL_TYPE_DEVICE, |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 246 | }; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 247 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 248 | debug_report_data *mdd(const void *object) { |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 249 | dispatch_key key = get_dispatch_key(object); |
| 250 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 251 | return my_data->report_data; |
| 252 | } |
| 253 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 254 | debug_report_data *mid(VkInstance object) { |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 255 | dispatch_key key = get_dispatch_key(object); |
| 256 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 257 | return my_data->report_data; |
| 258 | } |
| 259 | |
| 260 | // For each Queue's doubly linked-list of mem refs |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 261 | struct OT_MEM_INFO { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 262 | VkDeviceMemory mem; |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 263 | OT_MEM_INFO *pNextMI; |
| 264 | OT_MEM_INFO *pPrevMI; |
| 265 | }; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 266 | |
| 267 | // Track Queue information |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 268 | struct OT_QUEUE_INFO { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 269 | OT_MEM_INFO *pMemRefList; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 270 | uint32_t queueNodeIndex; |
| 271 | VkQueue queue; |
| 272 | uint32_t refCount; |
Mark Lobodzinski | bd1fecd | 2016-05-19 17:06:56 -0600 | [diff] [blame] | 273 | }; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 274 | |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 275 | // Global map of structures, one per queue |
| 276 | std::unordered_map<VkQueue, OT_QUEUE_INFO *> queue_info_map; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 277 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 278 | #include "vk_dispatch_table_helper.h" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 279 | |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 280 | static void init_object_tracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
| 281 | |
| 282 | layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_object_tracker"); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 283 | } |
| 284 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 285 | // |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 286 | // Forward declarations |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 287 | // |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 288 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 289 | static void create_physical_device(VkInstance dispatchable_object, VkPhysicalDevice vkObj, VkDebugReportObjectTypeEXT objType); |
| 290 | static void create_instance(VkInstance dispatchable_object, VkInstance object, VkDebugReportObjectTypeEXT objType); |
| 291 | static void create_device(VkDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType); |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 292 | static void create_device(VkPhysicalDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 293 | static void create_queue(VkDevice dispatchable_object, VkQueue vkObj, VkDebugReportObjectTypeEXT objType); |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 294 | static void create_display_khr(VkPhysicalDevice dispatchable_object, VkDisplayKHR vkObj, VkDebugReportObjectTypeEXT objType); |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 295 | static void create_display_mode_khr(VkPhysicalDevice dispatchable_object, VkDisplayModeKHR vkObj, VkDebugReportObjectTypeEXT objType); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 296 | static bool validate_image(VkQueue dispatchable_object, VkImage object, VkDebugReportObjectTypeEXT objType, bool null_allowed); |
| 297 | static bool validate_instance(VkInstance dispatchable_object, VkInstance object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 298 | bool null_allowed); |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 299 | static bool validate_physical_device(VkPhysicalDevice dispatchable_object, VkPhysicalDevice object, VkDebugReportObjectTypeEXT objType, bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 300 | static bool validate_device(VkDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 301 | bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 302 | static bool validate_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 303 | bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 304 | static bool validate_descriptor_set_layout(VkDevice dispatchable_object, VkDescriptorSetLayout object, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 305 | VkDebugReportObjectTypeEXT objType, bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 306 | static bool validate_command_pool(VkDevice dispatchable_object, VkCommandPool object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 307 | bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 308 | static bool validate_buffer(VkQueue dispatchable_object, VkBuffer object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 309 | bool null_allowed); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 310 | static void create_pipeline(VkDevice dispatchable_object, VkPipeline vkObj, VkDebugReportObjectTypeEXT objType); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 311 | static bool validate_pipeline_cache(VkDevice dispatchable_object, VkPipelineCache object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 312 | bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 313 | static bool validate_render_pass(VkDevice dispatchable_object, VkRenderPass object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 314 | bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 315 | static bool validate_shader_module(VkDevice dispatchable_object, VkShaderModule object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 316 | bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 317 | static bool validate_pipeline_layout(VkDevice dispatchable_object, VkPipelineLayout object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 318 | bool null_allowed); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 319 | static bool validate_pipeline(VkDevice dispatchable_object, VkPipeline object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 320 | bool null_allowed); |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 321 | static bool validate_display_khr(VkPhysicalDevice dispatchable_object, VkDisplayKHR object, VkDebugReportObjectTypeEXT objType, |
| 322 | bool null_allowed); |
| 323 | static bool validate_display_mode_khr(VkInstance dispatchable_object, VkDisplayModeKHR object, VkDebugReportObjectTypeEXT objType, |
| 324 | bool null_allowed); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 325 | static void destroy_command_pool(VkDevice dispatchable_object, VkCommandPool object); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 326 | static void destroy_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object); |
| 327 | static void destroy_descriptor_set(VkDevice dispatchable_object, VkDescriptorSet object); |
| 328 | static void destroy_device_memory(VkDevice dispatchable_object, VkDeviceMemory object); |
| 329 | static void destroy_swapchain_khr(VkDevice dispatchable_object, VkSwapchainKHR object); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 330 | static bool set_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 331 | ObjectStatusFlags status_flag); |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 332 | static bool reset_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDebugReportObjectTypeEXT objType, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 333 | ObjectStatusFlags status_flag); |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 334 | static void destroy_queue(VkQueue dispatchable_object, VkQueue object); |
| 335 | |
Mark Lobodzinski | f93272b | 2016-05-02 12:08:24 -0600 | [diff] [blame] | 336 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkPhysicalDeviceMap; |
| 337 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkDeviceMap; |
| 338 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkImageMap; |
| 339 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkQueueMap; |
| 340 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkDescriptorSetMap; |
| 341 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkBufferMap; |
| 342 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkFenceMap; |
| 343 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSemaphoreMap; |
| 344 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkCommandPoolMap; |
| 345 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkCommandBufferMap; |
| 346 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSwapchainKHRMap; |
| 347 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSurfaceKHRMap; |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 348 | extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkQueueMap; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 349 | |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 350 | // Convert an object type enum to an object type array index |
| 351 | static uint32_t objTypeToIndex(uint32_t objType) { |
| 352 | uint32_t index = objType; |
| 353 | return index; |
| 354 | } |
| 355 | |
| 356 | // Add new queue to head of global queue list |
| 357 | static void addQueueInfo(uint32_t queueNodeIndex, VkQueue queue) { |
| 358 | auto queueItem = queue_info_map.find(queue); |
| 359 | if (queueItem == queue_info_map.end()) { |
| 360 | OT_QUEUE_INFO *p_queue_info = new OT_QUEUE_INFO; |
| 361 | if (p_queue_info != NULL) { |
| 362 | memset(p_queue_info, 0, sizeof(OT_QUEUE_INFO)); |
| 363 | p_queue_info->queue = queue; |
| 364 | p_queue_info->queueNodeIndex = queueNodeIndex; |
| 365 | queue_info_map[queue] = p_queue_info; |
| 366 | } else { |
| 367 | log_msg(mdd(queue), VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, |
| 368 | reinterpret_cast<uint64_t>(queue), __LINE__, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", |
| 369 | "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information"); |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // Destroy memRef lists and free all memory |
| 375 | static void destroyQueueMemRefLists() { |
| 376 | for (auto queue_item : queue_info_map) { |
| 377 | OT_MEM_INFO *p_mem_info = queue_item.second->pMemRefList; |
| 378 | while (p_mem_info != NULL) { |
| 379 | OT_MEM_INFO *p_del_mem_info = p_mem_info; |
| 380 | p_mem_info = p_mem_info->pNextMI; |
| 381 | delete p_del_mem_info; |
| 382 | } |
| 383 | delete queue_item.second; |
| 384 | } |
| 385 | queue_info_map.clear(); |
| 386 | |
| 387 | // Destroy the items in the queue map |
| 388 | auto queue = VkQueueMap.begin(); |
| 389 | while (queue != VkQueueMap.end()) { |
| 390 | uint32_t obj_index = objTypeToIndex(queue->second->objType); |
| 391 | assert(numTotalObjs > 0); |
| 392 | numTotalObjs--; |
| 393 | assert(numObjs[obj_index] > 0); |
| 394 | numObjs[obj_index]--; |
| 395 | log_msg(mdd(reinterpret_cast<VkQueue>(queue->second->vkObj)), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, queue->second->objType, |
| 396 | queue->second->vkObj, __LINE__, OBJTRACK_NONE, "OBJTRACK", |
| 397 | "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).", |
| 398 | string_VkDebugReportObjectTypeEXT(queue->second->objType), queue->second->vkObj, numTotalObjs, numObjs[obj_index], |
| 399 | string_VkDebugReportObjectTypeEXT(queue->second->objType)); |
| 400 | delete queue->second; |
| 401 | queue = VkQueueMap.erase(queue); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | // Check Queue type flags for selected queue operations |
| 406 | static void validateQueueFlags(VkQueue queue, const char *function) { |
| 407 | |
| 408 | auto queue_item = queue_info_map.find(queue); |
| 409 | if (queue_item != queue_info_map.end()) { |
| 410 | OT_QUEUE_INFO *pQueueInfo = queue_item->second; |
| 411 | if (pQueueInfo != NULL) { |
| 412 | if ((queue_family_properties[pQueueInfo->queueNodeIndex].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) == 0) { |
| 413 | log_msg(mdd(queue), VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, |
| 414 | reinterpret_cast<uint64_t>(queue), __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", |
| 415 | "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set", function); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | static void create_physical_device(VkInstance instance, VkPhysicalDevice vkObj, VkDebugReportObjectTypeEXT objType) { |
| 422 | log_msg(mdd(instance), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 423 | OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, |
| 424 | string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj)); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 425 | |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 426 | uint64_t physical_device_handle = reinterpret_cast<uint64_t>(vkObj); |
| 427 | auto pd_item = VkPhysicalDeviceMap.find(physical_device_handle); |
| 428 | if (pd_item == VkPhysicalDeviceMap.end()) { |
| 429 | OBJTRACK_NODE *p_new_obj_node = new OBJTRACK_NODE; |
| 430 | p_new_obj_node->objType = objType; |
| 431 | p_new_obj_node->belongsTo = reinterpret_cast<uint64_t>(instance); |
| 432 | p_new_obj_node->status = OBJSTATUS_NONE; |
| 433 | p_new_obj_node->vkObj = physical_device_handle; |
| 434 | VkPhysicalDeviceMap[physical_device_handle] = p_new_obj_node; |
| 435 | uint32_t objIndex = objTypeToIndex(objType); |
| 436 | numObjs[objIndex]++; |
| 437 | numTotalObjs++; |
| 438 | } |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 439 | } |
| 440 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 441 | static void create_surface_khr(VkInstance dispatchable_object, VkSurfaceKHR vkObj, VkDebugReportObjectTypeEXT objType) { |
Mark Lobodzinski | b49b6e5 | 2015-11-26 10:59:58 -0700 | [diff] [blame] | 442 | // TODO: Add tracking of surface objects |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 443 | log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, |
| 444 | "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, |
| 445 | string_VkDebugReportObjectTypeEXT(objType), (uint64_t)(vkObj)); |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 446 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 447 | OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE; |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 448 | pNewObjNode->objType = objType; |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 449 | pNewObjNode->belongsTo = (uint64_t)dispatchable_object; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 450 | pNewObjNode->status = OBJSTATUS_NONE; |
| 451 | pNewObjNode->vkObj = (uint64_t)(vkObj); |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 452 | VkSurfaceKHRMap[(uint64_t)vkObj] = pNewObjNode; |
| 453 | uint32_t objIndex = objTypeToIndex(objType); |
| 454 | numObjs[objIndex]++; |
| 455 | numTotalObjs++; |
Mark Lobodzinski | b49b6e5 | 2015-11-26 10:59:58 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 458 | static void destroy_surface_khr(VkInstance dispatchable_object, VkSurfaceKHR object) { |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 459 | uint64_t object_handle = (uint64_t)(object); |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 460 | if (VkSurfaceKHRMap.find(object_handle) != VkSurfaceKHRMap.end()) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 461 | OBJTRACK_NODE *pNode = VkSurfaceKHRMap[(uint64_t)object]; |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 462 | uint32_t objIndex = objTypeToIndex(pNode->objType); |
| 463 | assert(numTotalObjs > 0); |
| 464 | numTotalObjs--; |
| 465 | assert(numObjs[objIndex] > 0); |
| 466 | numObjs[objIndex]--; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 467 | log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, object_handle, __LINE__, |
| 468 | OBJTRACK_NONE, "OBJTRACK", |
Mark Mueller | aab3650 | 2016-05-03 13:17:29 -0600 | [diff] [blame] | 469 | "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (0x%" PRIx64 " total objs remain & 0x%" PRIx64 " %s objs).", |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 470 | string_VkDebugReportObjectTypeEXT(pNode->objType), (uint64_t)(object), numTotalObjs, numObjs[objIndex], |
| 471 | string_VkDebugReportObjectTypeEXT(pNode->objType)); |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 472 | delete pNode; |
| 473 | VkSurfaceKHRMap.erase(object_handle); |
| 474 | } else { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 475 | log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__, |
| 476 | OBJTRACK_NONE, "OBJTRACK", |
| 477 | "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle); |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 478 | } |
Mark Lobodzinski | b49b6e5 | 2015-11-26 10:59:58 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 481 | static void alloc_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer vkObj, |
| 482 | VkDebugReportObjectTypeEXT objType, VkCommandBufferLevel level) { |
| 483 | log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__, OBJTRACK_NONE, |
| 484 | "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, |
| 485 | string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 486 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 487 | OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE; |
| 488 | pNewObjNode->objType = objType; |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 489 | pNewObjNode->belongsTo = (uint64_t)device; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 490 | pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj); |
| 491 | pNewObjNode->parentObj = (uint64_t)commandPool; |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 492 | if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 493 | pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY; |
| 494 | } else { |
| 495 | pNewObjNode->status = OBJSTATUS_NONE; |
| 496 | } |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 497 | VkCommandBufferMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 498 | uint32_t objIndex = objTypeToIndex(objType); |
| 499 | numObjs[objIndex]++; |
| 500 | numTotalObjs++; |
| 501 | } |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 502 | |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 503 | static bool validate_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer commandBuffer) { |
| 504 | bool skipCall = false; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 505 | uint64_t object_handle = reinterpret_cast<uint64_t>(commandBuffer); |
| 506 | if (VkCommandBufferMap.find(object_handle) != VkCommandBufferMap.end()) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 507 | OBJTRACK_NODE *pNode = VkCommandBufferMap[(uint64_t)commandBuffer]; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 508 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 509 | if (pNode->parentObj != (uint64_t)(commandPool)) { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 510 | skipCall |= log_msg( |
| 511 | mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, object_handle, __LINE__, OBJTRACK_COMMAND_POOL_MISMATCH, |
| 512 | "OBJTRACK", "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64 |
| 513 | " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").", |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 514 | reinterpret_cast<uint64_t>(commandBuffer), pNode->parentObj, reinterpret_cast<uint64_t &>(commandPool)); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 515 | } |
| 516 | } else { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 517 | skipCall |= log_msg( |
| 518 | mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__, OBJTRACK_NONE, |
| 519 | "OBJTRACK", "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 520 | } |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 521 | return skipCall; |
| 522 | } |
| 523 | |
| 524 | static bool free_command_buffer(VkDevice device, VkCommandBuffer commandBuffer) { |
| 525 | bool skipCall = false; |
| 526 | auto cbItem = VkCommandBufferMap.find(reinterpret_cast<uint64_t>(commandBuffer)); |
| 527 | if (cbItem != VkCommandBufferMap.end()) { |
| 528 | OBJTRACK_NODE *pNode = cbItem->second; |
| 529 | uint32_t objIndex = objTypeToIndex(pNode->objType); |
| 530 | assert(numTotalObjs > 0); |
| 531 | numTotalObjs--; |
| 532 | assert(numObjs[objIndex] > 0); |
| 533 | numObjs[objIndex]--; |
| 534 | skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, |
| 535 | reinterpret_cast<uint64_t>(commandBuffer), __LINE__, OBJTRACK_NONE, "OBJTRACK", |
| 536 | "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).", |
| 537 | string_VkDebugReportObjectTypeEXT(pNode->objType), reinterpret_cast<uint64_t>(commandBuffer), |
| 538 | numTotalObjs, numObjs[objIndex], string_VkDebugReportObjectTypeEXT(pNode->objType)); |
| 539 | delete pNode; |
| 540 | VkCommandBufferMap.erase(cbItem); |
| 541 | } |
| 542 | return skipCall; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 545 | static void alloc_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet vkObj, |
| 546 | VkDebugReportObjectTypeEXT objType) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 547 | log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, "OBJTRACK", |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 548 | "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, string_VkDebugReportObjectTypeEXT(objType), |
| 549 | (uint64_t)(vkObj)); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 550 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 551 | OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE; |
| 552 | pNewObjNode->objType = objType; |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 553 | pNewObjNode->belongsTo = (uint64_t)device; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 554 | pNewObjNode->status = OBJSTATUS_NONE; |
| 555 | pNewObjNode->vkObj = (uint64_t)(vkObj); |
| 556 | pNewObjNode->parentObj = (uint64_t)descriptorPool; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 557 | VkDescriptorSetMap[(uint64_t)vkObj] = pNewObjNode; |
| 558 | uint32_t objIndex = objTypeToIndex(objType); |
| 559 | numObjs[objIndex]++; |
| 560 | numTotalObjs++; |
| 561 | } |
| 562 | |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 563 | static bool validate_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet descriptorSet) { |
| 564 | bool skipCall = false; |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 565 | uint64_t object_handle = reinterpret_cast<uint64_t &>(descriptorSet); |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 566 | auto dsItem = VkDescriptorSetMap.find(object_handle); |
| 567 | if (dsItem != VkDescriptorSetMap.end()) { |
| 568 | OBJTRACK_NODE *pNode = dsItem->second; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 569 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 570 | if (pNode->parentObj != reinterpret_cast<uint64_t &>(descriptorPool)) { |
| 571 | skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, object_handle, __LINE__, |
| 572 | OBJTRACK_DESCRIPTOR_POOL_MISMATCH, "OBJTRACK", |
| 573 | "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64 |
| 574 | " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").", |
| 575 | reinterpret_cast<uint64_t &>(descriptorSet), pNode->parentObj, |
| 576 | reinterpret_cast<uint64_t &>(descriptorPool)); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 577 | } |
| 578 | } else { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 579 | skipCall |= log_msg( |
| 580 | mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__, OBJTRACK_NONE, |
| 581 | "OBJTRACK", "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 582 | } |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 583 | return skipCall; |
| 584 | } |
| 585 | |
| 586 | static bool free_descriptor_set(VkDevice device, VkDescriptorSet descriptorSet) { |
| 587 | bool skipCall = false; |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 588 | auto dsItem = VkDescriptorSetMap.find(reinterpret_cast<uint64_t &>(descriptorSet)); |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 589 | if (dsItem != VkDescriptorSetMap.end()) { |
| 590 | OBJTRACK_NODE *pNode = dsItem->second; |
| 591 | uint32_t objIndex = objTypeToIndex(pNode->objType); |
| 592 | assert(numTotalObjs > 0); |
| 593 | numTotalObjs--; |
| 594 | assert(numObjs[objIndex] > 0); |
| 595 | numObjs[objIndex]--; |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 596 | skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, |
| 597 | reinterpret_cast<uint64_t &>(descriptorSet), __LINE__, OBJTRACK_NONE, "OBJTRACK", |
| 598 | "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).", |
| 599 | string_VkDebugReportObjectTypeEXT(pNode->objType), reinterpret_cast<uint64_t &>(descriptorSet), |
| 600 | numTotalObjs, numObjs[objIndex], string_VkDebugReportObjectTypeEXT(pNode->objType)); |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 601 | delete pNode; |
| 602 | VkDescriptorSetMap.erase(dsItem); |
| 603 | } |
| 604 | return skipCall; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 607 | static void create_queue(VkDevice device, VkQueue vkObj, VkDebugReportObjectTypeEXT objType) { |
| 608 | |
| 609 | log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 610 | OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, |
| 611 | string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj)); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 612 | |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 613 | OBJTRACK_NODE *p_obj_node = NULL; |
| 614 | auto queue_item = VkQueueMap.find(reinterpret_cast<uint64_t>(vkObj)); |
| 615 | if (queue_item == VkQueueMap.end()) { |
| 616 | p_obj_node = new OBJTRACK_NODE; |
| 617 | VkQueueMap[reinterpret_cast<uint64_t>(vkObj)] = p_obj_node; |
| 618 | uint32_t objIndex = objTypeToIndex(objType); |
| 619 | numObjs[objIndex]++; |
| 620 | numTotalObjs++; |
| 621 | } else { |
| 622 | p_obj_node = queue_item->second; |
| 623 | } |
| 624 | p_obj_node->objType = objType; |
| 625 | p_obj_node->belongsTo = reinterpret_cast<uint64_t>(device); |
| 626 | p_obj_node->status = OBJSTATUS_NONE; |
| 627 | p_obj_node->vkObj = reinterpret_cast<uint64_t>(vkObj); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 628 | } |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 629 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 630 | static void create_swapchain_image_obj(VkDevice dispatchable_object, VkImage vkObj, VkSwapchainKHR swapchain) { |
| 631 | log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)vkObj, |
| 632 | __LINE__, OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, |
| 633 | "SwapchainImage", (uint64_t)(vkObj)); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 634 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 635 | OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE; |
| 636 | pNewObjNode->belongsTo = (uint64_t)dispatchable_object; |
| 637 | pNewObjNode->objType = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT; |
| 638 | pNewObjNode->status = OBJSTATUS_NONE; |
| 639 | pNewObjNode->vkObj = (uint64_t)vkObj; |
| 640 | pNewObjNode->parentObj = (uint64_t)swapchain; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 641 | swapchainImageMap[(uint64_t)(vkObj)] = pNewObjNode; |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 642 | } |
| 643 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 644 | static void create_device(VkInstance dispatchable_object, VkDevice vkObj, VkDebugReportObjectTypeEXT objType) { |
| 645 | log_msg(mid(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, |
| 646 | "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, |
| 647 | string_VkDebugReportObjectTypeEXT(objType), (uint64_t)(vkObj)); |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 648 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 649 | OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE; |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 650 | pNewObjNode->belongsTo = (uint64_t)dispatchable_object; |
| 651 | pNewObjNode->objType = objType; |
| 652 | pNewObjNode->status = OBJSTATUS_NONE; |
| 653 | pNewObjNode->vkObj = (uint64_t)(vkObj); |
| 654 | VkDeviceMap[(uint64_t)vkObj] = pNewObjNode; |
| 655 | uint32_t objIndex = objTypeToIndex(objType); |
| 656 | numObjs[objIndex]++; |
| 657 | numTotalObjs++; |
| 658 | } |
| 659 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 660 | // |
| 661 | // Non-auto-generated API functions called by generated code |
| 662 | // |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 663 | VkResult explicit_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 664 | VkInstance *pInstance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 665 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
David Pinedo | c0fa1ab | 2015-07-31 10:46:25 -0600 | [diff] [blame] | 666 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 667 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 668 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 669 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 670 | if (fpCreateInstance == NULL) { |
| 671 | return VK_ERROR_INITIALIZATION_FAILED; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 672 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 673 | |
| 674 | // Advance the link info for the next element on the chain |
| 675 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 676 | |
| 677 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 678 | if (result != VK_SUCCESS) { |
| 679 | return result; |
| 680 | } |
| 681 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 682 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
Chia-I Wu | 1ad50f4 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 683 | my_data->instance = *pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 684 | initInstanceTable(*pInstance, fpGetInstanceProcAddr, object_tracker_instance_table_map); |
| 685 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, *pInstance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 686 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 687 | // Look for one or more debug report create info structures, and copy the |
| 688 | // callback(s) for each one found (for use by vkDestroyInstance) |
| 689 | layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos, |
| 690 | &my_data->tmp_callbacks); |
| 691 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 692 | my_data->report_data = debug_report_create_instance(pInstanceTable, *pInstance, pCreateInfo->enabledExtensionCount, |
| 693 | pCreateInfo->ppEnabledExtensionNames); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 694 | |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 695 | init_object_tracker(my_data, pAllocator); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 696 | createInstanceRegisterExtensions(pCreateInfo, *pInstance); |
| 697 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 698 | create_instance(*pInstance, *pInstance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 699 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 700 | return result; |
| 701 | } |
| 702 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 703 | void explicit_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice gpu, uint32_t *pCount, VkQueueFamilyProperties *pProperties) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 704 | get_dispatch_table(object_tracker_instance_table_map, gpu)->GetPhysicalDeviceQueueFamilyProperties(gpu, pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 705 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 706 | std::lock_guard<std::mutex> lock(global_lock); |
| 707 | if (pProperties != NULL) { |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 708 | for (uint32_t i = 0; i < *pCount; i++) { |
| 709 | queue_family_properties.emplace_back(pProperties[i]); |
| 710 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 711 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 712 | } |
| 713 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 714 | VkResult explicit_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 715 | VkDevice *pDevice) { |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 716 | std::lock_guard<std::mutex> lock(global_lock); |
Chia-I Wu | 1ad50f4 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 717 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 718 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 719 | |
| 720 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 721 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 722 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Chia-I Wu | 1ad50f4 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 723 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 724 | if (fpCreateDevice == NULL) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 725 | return VK_ERROR_INITIALIZATION_FAILED; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 726 | } |
| 727 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 728 | // Advance the link info for the next element on the chain |
| 729 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 730 | |
| 731 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 732 | if (result != VK_SUCCESS) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 733 | return result; |
| 734 | } |
| 735 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 736 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 737 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 738 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 739 | initDeviceTable(*pDevice, fpGetDeviceProcAddr, object_tracker_device_table_map); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 740 | |
| 741 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
| 742 | |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 743 | if (VkPhysicalDeviceMap.find((uint64_t)gpu) != VkPhysicalDeviceMap.end()) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 744 | OBJTRACK_NODE *pNewObjNode = VkPhysicalDeviceMap[(uint64_t)gpu]; |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 745 | create_device((VkInstance)pNewObjNode->belongsTo, *pDevice, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT); |
| 746 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 747 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 748 | return result; |
| 749 | } |
| 750 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 751 | VkResult explicit_EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 752 | VkPhysicalDevice *pPhysicalDevices) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 753 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 754 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 755 | skipCall |= validate_instance(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 756 | lock.unlock(); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 757 | if (skipCall) |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 758 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 759 | VkResult result = get_dispatch_table(object_tracker_instance_table_map, instance) |
| 760 | ->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 761 | lock.lock(); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 762 | if (result == VK_SUCCESS) { |
| 763 | if (pPhysicalDevices) { |
| 764 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 765 | create_physical_device(instance, pPhysicalDevices[i], VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 769 | lock.unlock(); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 770 | return result; |
| 771 | } |
| 772 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 773 | void explicit_GetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue *pQueue) { |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 774 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 775 | validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 776 | lock.unlock(); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 777 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 778 | get_dispatch_table(object_tracker_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 779 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 780 | lock.lock(); |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 781 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 782 | create_queue(device, *pQueue, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT); |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 783 | addQueueInfo(queueNodeIndex, *pQueue); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 784 | } |
| 785 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 786 | VkResult explicit_MapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkFlags flags, |
| 787 | void **ppData) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 788 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 789 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 790 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 791 | lock.unlock(); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 792 | if (skipCall == VK_TRUE) |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 793 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 794 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 795 | VkResult result = |
| 796 | get_dispatch_table(object_tracker_device_table_map, device)->MapMemory(device, mem, offset, size, flags, ppData); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 797 | |
| 798 | return result; |
| 799 | } |
| 800 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 801 | void explicit_UnmapMemory(VkDevice device, VkDeviceMemory mem) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 802 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 803 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 804 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 805 | lock.unlock(); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 806 | if (skipCall == VK_TRUE) |
| 807 | return; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 808 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 809 | get_dispatch_table(object_tracker_device_table_map, device)->UnmapMemory(device, mem); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 810 | } |
| 811 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 812 | VkResult explicit_QueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, VkFence fence) { |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 813 | std::unique_lock<std::mutex> lock(global_lock); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 814 | validateQueueFlags(queue, "QueueBindSparse"); |
| 815 | |
| 816 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 817 | for (uint32_t j = 0; j < pBindInfo[i].bufferBindCount; j++) |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 818 | validate_buffer(queue, pBindInfo[i].pBufferBinds[j].buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, false); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 819 | for (uint32_t j = 0; j < pBindInfo[i].imageOpaqueBindCount; j++) |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 820 | validate_image(queue, pBindInfo[i].pImageOpaqueBinds[j].image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 821 | for (uint32_t j = 0; j < pBindInfo[i].imageBindCount; j++) |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 822 | validate_image(queue, pBindInfo[i].pImageBinds[j].image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 823 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 824 | lock.unlock(); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 825 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 826 | VkResult result = |
| 827 | get_dispatch_table(object_tracker_device_table_map, queue)->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence); |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 828 | return result; |
| 829 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 830 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 831 | VkResult explicit_AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, |
| 832 | VkCommandBuffer *pCommandBuffers) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 833 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 834 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 835 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
| 836 | skipCall |= validate_command_pool(device, pAllocateInfo->commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 837 | lock.unlock(); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 838 | |
| 839 | if (skipCall) { |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 840 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 843 | VkResult result = |
| 844 | get_dispatch_table(object_tracker_device_table_map, device)->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 845 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 846 | lock.lock(); |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 847 | for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 848 | alloc_command_buffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 849 | pAllocateInfo->level); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 850 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 851 | lock.unlock(); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 852 | |
| 853 | return result; |
| 854 | } |
| 855 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 856 | VkResult explicit_AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 857 | VkDescriptorSet *pDescriptorSets) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 858 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 859 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 860 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 861 | skipCall |= |
| 862 | validate_descriptor_pool(device, pAllocateInfo->descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false); |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 863 | for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 864 | skipCall |= validate_descriptor_set_layout(device, pAllocateInfo->pSetLayouts[i], |
| 865 | VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, false); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 866 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 867 | lock.unlock(); |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 868 | if (skipCall) { |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 869 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 870 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 871 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 872 | VkResult result = |
| 873 | get_dispatch_table(object_tracker_device_table_map, device)->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 874 | |
Chris Forbes | 539a87c | 2016-01-22 15:44:40 +1300 | [diff] [blame] | 875 | if (VK_SUCCESS == result) { |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 876 | lock.lock(); |
Chris Forbes | 539a87c | 2016-01-22 15:44:40 +1300 | [diff] [blame] | 877 | for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 878 | alloc_descriptor_set(device, pAllocateInfo->descriptorPool, pDescriptorSets[i], |
| 879 | VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT); |
Chris Forbes | 539a87c | 2016-01-22 15:44:40 +1300 | [diff] [blame] | 880 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 881 | lock.unlock(); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 882 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 883 | |
| 884 | return result; |
| 885 | } |
| 886 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 887 | void explicit_FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, |
| 888 | const VkCommandBuffer *pCommandBuffers) { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 889 | bool skipCall = false; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 890 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 891 | validate_command_pool(device, commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false); |
| 892 | validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 893 | for (uint32_t i = 0; i < commandBufferCount; i++) { |
| 894 | skipCall |= validate_command_buffer(device, commandPool, pCommandBuffers[i]); |
| 895 | } |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 896 | |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 897 | lock.unlock(); |
| 898 | if (!skipCall) { |
| 899 | get_dispatch_table(object_tracker_device_table_map, device) |
| 900 | ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); |
| 901 | } |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 902 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 903 | lock.lock(); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 904 | for (uint32_t i = 0; i < commandBufferCount; i++) { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 905 | free_command_buffer(device, pCommandBuffers[i]); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 906 | } |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 909 | void explicit_DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) { |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 910 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 911 | // A swapchain's images are implicitly deleted when the swapchain is deleted. |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 912 | // Remove this swapchain's images from our map of such images. |
Mark Lobodzinski | f93272b | 2016-05-02 12:08:24 -0600 | [diff] [blame] | 913 | std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = swapchainImageMap.begin(); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 914 | while (itr != swapchainImageMap.end()) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 915 | OBJTRACK_NODE *pNode = (*itr).second; |
Mark Lobodzinski | 7f53729 | 2016-05-12 15:14:07 -0600 | [diff] [blame] | 916 | if (pNode->parentObj == reinterpret_cast<uint64_t &>(swapchain)) { |
| 917 | delete pNode; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 918 | swapchainImageMap.erase(itr++); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 919 | } else { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 920 | ++itr; |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 921 | } |
| 922 | } |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 923 | destroy_swapchain_khr(device, swapchain); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 924 | lock.unlock(); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 925 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 926 | get_dispatch_table(object_tracker_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 927 | } |
| 928 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 929 | void explicit_FreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) { |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 930 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 931 | validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 932 | lock.unlock(); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 933 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 934 | get_dispatch_table(object_tracker_device_table_map, device)->FreeMemory(device, mem, pAllocator); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 935 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 936 | lock.lock(); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 937 | destroy_device_memory(device, mem); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 938 | } |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 939 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 940 | VkResult explicit_FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, |
| 941 | const VkDescriptorSet *pDescriptorSets) { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 942 | bool skipCall = false; |
| 943 | VkResult result = VK_ERROR_VALIDATION_FAILED_EXT; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 944 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 945 | skipCall |= validate_descriptor_pool(device, descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false); |
| 946 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
| 947 | for (uint32_t i = 0; i < count; i++) { |
| 948 | skipCall |= validate_descriptor_set(device, descriptorPool, pDescriptorSets[i]); |
| 949 | } |
| 950 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 951 | lock.unlock(); |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 952 | if (!skipCall) { |
| 953 | result = get_dispatch_table(object_tracker_device_table_map, device) |
| 954 | ->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets); |
| 955 | } |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 956 | |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 957 | lock.lock(); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 958 | for (uint32_t i = 0; i < count; i++) { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 959 | free_descriptor_set(device, pDescriptorSets[i]); |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 960 | } |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 961 | return result; |
| 962 | } |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 963 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 964 | void explicit_DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 965 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 966 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 967 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
| 968 | skipCall |= validate_descriptor_pool(device, descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 969 | lock.unlock(); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 970 | if (skipCall) { |
| 971 | return; |
| 972 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 973 | // A DescriptorPool's descriptor sets are implicitly deleted when the pool is deleted. |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 974 | // Remove this pool's descriptor sets from our descriptorSet map. |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 975 | lock.lock(); |
Mark Lobodzinski | f93272b | 2016-05-02 12:08:24 -0600 | [diff] [blame] | 976 | std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = VkDescriptorSetMap.begin(); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 977 | while (itr != VkDescriptorSetMap.end()) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 978 | OBJTRACK_NODE *pNode = (*itr).second; |
Mark Lobodzinski | b29731a | 2015-11-18 11:01:02 -0700 | [diff] [blame] | 979 | auto del_itr = itr++; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 980 | if (pNode->parentObj == (uint64_t)(descriptorPool)) { |
| 981 | destroy_descriptor_set(device, (VkDescriptorSet)((*del_itr).first)); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | destroy_descriptor_pool(device, descriptorPool); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 985 | lock.unlock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 986 | get_dispatch_table(object_tracker_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 989 | void explicit_DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 990 | bool skipCall = false; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 991 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 992 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
| 993 | skipCall |= validate_command_pool(device, commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 994 | lock.unlock(); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 995 | if (skipCall) { |
| 996 | return; |
| 997 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 998 | lock.lock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 999 | // A CommandPool's command buffers are implicitly deleted when the pool is deleted. |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1000 | // Remove this pool's cmdBuffers from our cmd buffer map. |
Mark Lobodzinski | f93272b | 2016-05-02 12:08:24 -0600 | [diff] [blame] | 1001 | std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = VkCommandBufferMap.begin(); |
| 1002 | std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator del_itr; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1003 | while (itr != VkCommandBufferMap.end()) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1004 | OBJTRACK_NODE *pNode = (*itr).second; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1005 | del_itr = itr++; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1006 | if (pNode->parentObj == (uint64_t)(commandPool)) { |
Mark Lobodzinski | 772cd3d | 2016-05-03 08:39:24 -0600 | [diff] [blame] | 1007 | skipCall |= validate_command_buffer(device, commandPool, reinterpret_cast<VkCommandBuffer>((*del_itr).first)); |
| 1008 | free_command_buffer(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first)); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | destroy_command_pool(device, commandPool); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1012 | lock.unlock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1013 | get_dispatch_table(object_tracker_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1016 | VkResult explicit_GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pCount, VkImage *pSwapchainImages) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1017 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1018 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1019 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1020 | lock.unlock(); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1021 | if (skipCall) |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1022 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1023 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1024 | VkResult result = get_dispatch_table(object_tracker_device_table_map, device) |
| 1025 | ->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1026 | |
| 1027 | if (pSwapchainImages != NULL) { |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1028 | lock.lock(); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1029 | for (uint32_t i = 0; i < *pCount; i++) { |
| 1030 | create_swapchain_image_obj(device, pSwapchainImages[i], swapchain); |
| 1031 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1032 | lock.unlock(); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1033 | } |
| 1034 | return result; |
| 1035 | } |
| 1036 | |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 1037 | #ifndef __ANDROID__ |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 1038 | VkResult explicit_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPropertiesKHR* pProperties) |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1039 | { |
| 1040 | bool skipCall = false; |
| 1041 | { |
| 1042 | std::lock_guard<std::mutex> lock(global_lock); |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 1043 | if (physicalDevice) { |
| 1044 | skipCall |= validate_physical_device(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false); |
| 1045 | } |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1046 | } |
| 1047 | if (skipCall) |
| 1048 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 1049 | VkResult result = get_dispatch_table(object_tracker_instance_table_map, physicalDevice)->GetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties); |
| 1050 | if (VK_SUCCESS == result && pProperties) { |
| 1051 | std::lock_guard<std::mutex> lock(global_lock); |
| 1052 | for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) { |
| 1053 | if (pProperties[idx0].display) { |
| 1054 | create_display_khr(physicalDevice, pProperties[idx0].display, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT); |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | return result; |
| 1059 | } |
| 1060 | |
| 1061 | VkResult explicit_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties) |
| 1062 | { |
| 1063 | bool skipCall = false; |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1064 | { |
| 1065 | std::lock_guard<std::mutex> lock(global_lock); |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 1066 | skipCall |= validate_display_khr(physicalDevice, display, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, false); |
| 1067 | if (physicalDevice) { |
| 1068 | skipCall |= validate_physical_device(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false); |
| 1069 | } |
| 1070 | } |
| 1071 | if (skipCall) |
| 1072 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1073 | VkResult result = get_dispatch_table(object_tracker_instance_table_map, physicalDevice)->GetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties); |
| 1074 | if (VK_SUCCESS == result && pProperties) { |
| 1075 | std::lock_guard<std::mutex> lock(global_lock); |
| 1076 | for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) { |
| 1077 | if (pProperties[idx0].displayMode) { |
| 1078 | create_display_mode_khr(physicalDevice, pProperties[idx0].displayMode, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT); |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | return result; |
| 1083 | } |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 1084 | #endif |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1085 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1086 | // TODO: Add special case to codegen to cover validating all the pipelines instead of just the first |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1087 | VkResult explicit_CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 1088 | const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator, |
| 1089 | VkPipeline *pPipelines) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1090 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1091 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1092 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1093 | if (pCreateInfos) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1094 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1095 | if (pCreateInfos[idx0].basePipelineHandle) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1096 | skipCall |= validate_pipeline(device, pCreateInfos[idx0].basePipelineHandle, |
| 1097 | VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, true); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1098 | } |
| 1099 | if (pCreateInfos[idx0].layout) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1100 | skipCall |= validate_pipeline_layout(device, pCreateInfos[idx0].layout, |
| 1101 | VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1102 | } |
| 1103 | if (pCreateInfos[idx0].pStages) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1104 | for (uint32_t idx1 = 0; idx1 < pCreateInfos[idx0].stageCount; ++idx1) { |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1105 | if (pCreateInfos[idx0].pStages[idx1].module) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1106 | skipCall |= validate_shader_module(device, pCreateInfos[idx0].pStages[idx1].module, |
| 1107 | VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | if (pCreateInfos[idx0].renderPass) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1112 | skipCall |= |
| 1113 | validate_render_pass(device, pCreateInfos[idx0].renderPass, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | if (pipelineCache) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1118 | skipCall |= validate_pipeline_cache(device, pipelineCache, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1119 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1120 | lock.unlock(); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1121 | if (skipCall) |
| 1122 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1123 | VkResult result = get_dispatch_table(object_tracker_device_table_map, device) |
| 1124 | ->CreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1125 | lock.lock(); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1126 | if (result == VK_SUCCESS) { |
| 1127 | for (uint32_t idx2 = 0; idx2 < createInfoCount; ++idx2) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1128 | create_pipeline(device, pPipelines[idx2], VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1129 | } |
| 1130 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1131 | lock.unlock(); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1132 | return result; |
| 1133 | } |
| 1134 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1135 | // TODO: Add special case to codegen to cover validating all the pipelines instead of just the first |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1136 | VkResult explicit_CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 1137 | const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator, |
| 1138 | VkPipeline *pPipelines) { |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1139 | bool skipCall = VK_FALSE; |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1140 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1141 | skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1142 | if (pCreateInfos) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1143 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1144 | if (pCreateInfos[idx0].basePipelineHandle) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1145 | skipCall |= validate_pipeline(device, pCreateInfos[idx0].basePipelineHandle, |
| 1146 | VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, true); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1147 | } |
| 1148 | if (pCreateInfos[idx0].layout) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1149 | skipCall |= validate_pipeline_layout(device, pCreateInfos[idx0].layout, |
| 1150 | VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1151 | } |
| 1152 | if (pCreateInfos[idx0].stage.module) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1153 | skipCall |= validate_shader_module(device, pCreateInfos[idx0].stage.module, |
| 1154 | VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | if (pipelineCache) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1159 | skipCall |= validate_pipeline_cache(device, pipelineCache, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, false); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1160 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1161 | lock.unlock(); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1162 | if (skipCall) |
| 1163 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1164 | VkResult result = get_dispatch_table(object_tracker_device_table_map, device) |
| 1165 | ->CreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1166 | lock.lock(); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1167 | if (result == VK_SUCCESS) { |
| 1168 | for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1169 | create_pipeline(device, pPipelines[idx1], VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1172 | lock.unlock(); |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1173 | return result; |
| 1174 | } |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 1175 | |
| 1176 | } // namespace object_tracker |