Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 1 | /* |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 22 | * |
| 23 | * Author: Jon Ashburn <jon@lunarg.com> |
| 24 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 25 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 28 | #include "vulkan/vk_layer.h" |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 29 | #include "vk_layer_extension_utils.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 30 | #include "vk_enum_string_helper.h" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 31 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 32 | // Object Tracker ERROR codes |
| 33 | typedef enum _OBJECT_TRACK_ERROR |
| 34 | { |
Chia-I Wu | 09cf5f0 | 2015-01-05 14:33:42 +0800 | [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 |
| 38 | OBJTRACK_DESTROY_OBJECT_FAILED, // Couldn't find object to be destroyed |
Chia-I Wu | 09cf5f0 | 2015-01-05 14:33:42 +0800 | [diff] [blame] | 39 | OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed |
| 40 | OBJTRACK_OBJCOUNT_MAX_EXCEEDED, // Request for Object data in excess of max obj count |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 41 | OBJTRACK_INVALID_OBJECT, // Object used that has never been created |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 42 | OBJTRACK_DESCRIPTOR_POOL_MISMATCH, // Descriptor Pools specified incorrectly |
| 43 | OBJTRACK_COMMAND_POOL_MISMATCH, // Command Pools specified incorrectly |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 44 | } OBJECT_TRACK_ERROR; |
| 45 | |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 46 | // Object Status -- used to track state of individual objects |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 47 | typedef VkFlags ObjectStatusFlags; |
| 48 | typedef enum _ObjectStatusFlagBits |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 49 | { |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 50 | OBJSTATUS_NONE = 0x00000000, // No status is set |
| 51 | OBJSTATUS_FENCE_IS_SUBMITTED = 0x00000001, // Fence has been submitted |
| 52 | OBJSTATUS_VIEWPORT_BOUND = 0x00000002, // Viewport state object has been bound |
| 53 | OBJSTATUS_RASTER_BOUND = 0x00000004, // Viewport state object has been bound |
| 54 | OBJSTATUS_COLOR_BLEND_BOUND = 0x00000008, // Viewport state object has been bound |
| 55 | OBJSTATUS_DEPTH_STENCIL_BOUND = 0x00000010, // Viewport state object has been bound |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 56 | OBJSTATUS_GPU_MEM_MAPPED = 0x00000020, // Memory object is currently mapped |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 57 | } ObjectStatusFlagBits; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 58 | |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 59 | typedef struct _OBJTRACK_NODE { |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 60 | uint64_t vkObj; // Object handle |
| 61 | VkDbgObjectType objType; // Object type identifier |
| 62 | ObjectStatusFlags status; // Object state |
| 63 | uint64_t parentObj; // Parent object |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 64 | } OBJTRACK_NODE; |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 65 | |
Tobin Ehlis | 4258653 | 2014-11-14 13:01:02 -0700 | [diff] [blame] | 66 | // prototype for extension functions |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 67 | uint64_t objTrackGetObjectCount(VkDevice device); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 68 | uint64_t objTrackGetObjectsOfTypeCount(VkDevice, VkDbgObjectType type); |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 69 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 70 | // Func ptr typedefs |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 71 | typedef uint64_t (*OBJ_TRACK_GET_OBJECT_COUNT)(VkDevice); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 72 | typedef uint64_t (*OBJ_TRACK_GET_OBJECTS_OF_TYPE_COUNT)(VkDevice, VkDbgObjectType); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 73 | |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 74 | struct layer_data { |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 75 | debug_report_data *report_data; |
| 76 | //TODO: put instance data here |
| 77 | VkDbgMsgCallback logging_callback; |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 78 | bool wsi_enabled; |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 79 | bool objtrack_extensions_enabled; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 80 | |
| 81 | layer_data() : |
| 82 | report_data(nullptr), |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 83 | logging_callback(VK_NULL_HANDLE), |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 84 | wsi_enabled(false), |
| 85 | objtrack_extensions_enabled(false) |
| 86 | {}; |
| 87 | }; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 88 | |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 89 | struct instExts { |
| 90 | bool wsi_enabled; |
| 91 | }; |
| 92 | |
| 93 | static std::unordered_map<void *, struct instExts> instanceExtMap; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 94 | static std::unordered_map<void*, layer_data *> layer_data_map; |
| 95 | static device_table_map ObjectTracker_device_table_map; |
| 96 | static instance_table_map ObjectTracker_instance_table_map; |
| 97 | |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 98 | // We need additionally validate image usage using a separate map |
| 99 | // of swapchain-created images |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 100 | static unordered_map<uint64_t, OBJTRACK_NODE*> swapchainImageMap; |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 101 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 102 | static long long unsigned int object_track_index = 0; |
| 103 | static int objLockInitialized = 0; |
| 104 | static loader_platform_thread_mutex objLock; |
| 105 | |
| 106 | // Objects stored in a global map w/ struct containing basic info |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 107 | // unordered_map<const void*, OBJTRACK_NODE*> objMap; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 108 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 109 | #define NUM_OBJECT_TYPES VK_OBJECT_TYPE_NUM |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 110 | |
| 111 | static uint64_t numObjs[NUM_OBJECT_TYPES] = {0}; |
| 112 | static uint64_t numTotalObjs = 0; |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 113 | static VkQueueFamilyProperties *queueInfo = NULL; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 114 | static uint32_t queueCount = 0; |
| 115 | |
| 116 | template layer_data *get_my_data_ptr<layer_data>( |
| 117 | void *data_key, std::unordered_map<void *, layer_data *> &data_map); |
| 118 | |
Mark Lobodzinski | 2eeb3c6 | 2015-09-01 08:52:55 -0600 | [diff] [blame] | 119 | static inline const char* string_VkDbgObjectType(VkDbgObjectType input_value) |
| 120 | { |
| 121 | switch ((VkDbgObjectType)input_value) |
| 122 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 123 | case VK_OBJECT_TYPE_COMMAND_POOL: |
| 124 | return "VK_OBJECT_TYPE_COMMAND_POOL"; |
Mark Lobodzinski | 2eeb3c6 | 2015-09-01 08:52:55 -0600 | [diff] [blame] | 125 | case VK_OBJECT_TYPE_BUFFER: |
| 126 | return "VK_OBJECT_TYPE_BUFFER"; |
| 127 | case VK_OBJECT_TYPE_BUFFER_VIEW: |
| 128 | return "VK_OBJECT_TYPE_BUFFER_VIEW"; |
| 129 | case VK_OBJECT_TYPE_ATTACHMENT_VIEW: |
| 130 | return "VK_OBJECT_TYPE_ATTACHMENT_VIEW"; |
| 131 | case VK_OBJECT_TYPE_COMMAND_BUFFER: |
| 132 | return "VK_OBJECT_TYPE_COMMAND_BUFFER"; |
| 133 | case VK_OBJECT_TYPE_DESCRIPTOR_POOL: |
| 134 | return "VK_OBJECT_TYPE_DESCRIPTOR_POOL"; |
| 135 | case VK_OBJECT_TYPE_DESCRIPTOR_SET: |
| 136 | return "VK_OBJECT_TYPE_DESCRIPTOR_SET"; |
| 137 | case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT: |
| 138 | return "VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT"; |
| 139 | case VK_OBJECT_TYPE_DEVICE: |
| 140 | return "VK_OBJECT_TYPE_DEVICE"; |
| 141 | case VK_OBJECT_TYPE_DEVICE_MEMORY: |
| 142 | return "VK_OBJECT_TYPE_DEVICE_MEMORY"; |
Mark Lobodzinski | 2eeb3c6 | 2015-09-01 08:52:55 -0600 | [diff] [blame] | 143 | case VK_OBJECT_TYPE_EVENT: |
| 144 | return "VK_OBJECT_TYPE_EVENT"; |
| 145 | case VK_OBJECT_TYPE_FENCE: |
| 146 | return "VK_OBJECT_TYPE_FENCE"; |
| 147 | case VK_OBJECT_TYPE_FRAMEBUFFER: |
| 148 | return "VK_OBJECT_TYPE_FRAMEBUFFER"; |
| 149 | case VK_OBJECT_TYPE_IMAGE: |
| 150 | return "VK_OBJECT_TYPE_IMAGE"; |
| 151 | case VK_OBJECT_TYPE_IMAGE_VIEW: |
| 152 | return "VK_OBJECT_TYPE_IMAGE_VIEW"; |
| 153 | case VK_OBJECT_TYPE_INSTANCE: |
| 154 | return "VK_OBJECT_TYPE_INSTANCE"; |
| 155 | case VK_OBJECT_TYPE_PHYSICAL_DEVICE: |
| 156 | return "VK_OBJECT_TYPE_PHYSICAL_DEVICE"; |
| 157 | case VK_OBJECT_TYPE_PIPELINE: |
| 158 | return "VK_OBJECT_TYPE_PIPELINE"; |
| 159 | case VK_OBJECT_TYPE_PIPELINE_LAYOUT: |
| 160 | return "VK_OBJECT_TYPE_PIPELINE_LAYOUT"; |
| 161 | case VK_OBJECT_TYPE_PIPELINE_CACHE: |
| 162 | return "VK_OBJECT_TYPE_PIPELINE_CACHE"; |
| 163 | case VK_OBJECT_TYPE_QUERY_POOL: |
| 164 | return "VK_OBJECT_TYPE_QUERY_POOL"; |
| 165 | case VK_OBJECT_TYPE_QUEUE: |
| 166 | return "VK_OBJECT_TYPE_QUEUE"; |
| 167 | case VK_OBJECT_TYPE_RENDER_PASS: |
| 168 | return "VK_OBJECT_TYPE_RENDER_PASS"; |
| 169 | case VK_OBJECT_TYPE_SAMPLER: |
| 170 | return "VK_OBJECT_TYPE_SAMPLER"; |
| 171 | case VK_OBJECT_TYPE_SEMAPHORE: |
| 172 | return "VK_OBJECT_TYPE_SEMAPHORE"; |
| 173 | case VK_OBJECT_TYPE_SHADER: |
| 174 | return "VK_OBJECT_TYPE_SHADER"; |
| 175 | case VK_OBJECT_TYPE_SHADER_MODULE: |
| 176 | return "VK_OBJECT_TYPE_SHADER_MODULE"; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 177 | case VK_OBJECT_TYPE_SWAPCHAIN_KHR: |
| 178 | return "VK_OBJECT_TYPE_SWAPCHAIN_KHR"; |
Mark Lobodzinski | 2eeb3c6 | 2015-09-01 08:52:55 -0600 | [diff] [blame] | 179 | default: |
| 180 | return "Unhandled VkObjectType"; |
| 181 | } |
| 182 | } |
| 183 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 184 | // |
| 185 | // Internal Object Tracker Functions |
| 186 | // |
| 187 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 188 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 189 | { |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 190 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 191 | VkLayerDispatchTable *pDisp = get_dispatch_table(ObjectTracker_device_table_map, device); |
| 192 | PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr; |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 193 | pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR"); |
| 194 | pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR"); |
| 195 | pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR"); |
| 196 | pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR"); |
| 197 | pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR"); |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 198 | my_device_data->wsi_enabled = false; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 199 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 200 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 201 | my_device_data->wsi_enabled = true; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 202 | |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 203 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], "OBJTRACK_EXTENSIONS") == 0) |
| 204 | my_device_data->objtrack_extensions_enabled = true; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 208 | static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance) |
| 209 | { |
| 210 | uint32_t i; |
| 211 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(ObjectTracker_instance_table_map, instance); |
| 212 | PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr; |
| 213 | pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR"); |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 214 | pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"); |
| 215 | pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR"); |
| 216 | pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR"); |
Mark Lobodzinski | e86e138 | 2015-11-24 15:50:44 -0700 | [diff] [blame] | 217 | |
| 218 | #if VK_USE_PLATFORM_WIN32_KHR |
| 219 | pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(instance, "vkCreateWin32SurfaceKHR"); |
| 220 | pDisp->GetPhysicalDeviceWin32PresentationSupportKHR = (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR"); |
| 221 | #else // VK_USE_PLATFORM_XCB_KHR |
| 222 | pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(instance, "vkCreateXcbSurfaceKHR"); |
| 223 | pDisp->GetPhysicalDeviceXcbPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR"); |
| 224 | #endif |
| 225 | |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 226 | instanceExtMap[pDisp].wsi_enabled = false; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 227 | for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 228 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 229 | instanceExtMap[pDisp].wsi_enabled = true; |
| 230 | |
| 231 | } |
| 232 | } |
| 233 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 234 | // Indicate device or instance dispatch table type |
| 235 | typedef enum _DispTableType |
| 236 | { |
| 237 | DISP_TBL_TYPE_INSTANCE, |
| 238 | DISP_TBL_TYPE_DEVICE, |
| 239 | } DispTableType; |
| 240 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 241 | debug_report_data *mdd(const void* object) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 242 | { |
| 243 | dispatch_key key = get_dispatch_key(object); |
| 244 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 245 | return my_data->report_data; |
| 246 | } |
| 247 | |
| 248 | debug_report_data *mid(VkInstance object) |
| 249 | { |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 250 | dispatch_key key = get_dispatch_key(object); |
| 251 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 252 | return my_data->report_data; |
| 253 | } |
| 254 | |
| 255 | // For each Queue's doubly linked-list of mem refs |
| 256 | typedef struct _OT_MEM_INFO { |
| 257 | VkDeviceMemory mem; |
| 258 | struct _OT_MEM_INFO *pNextMI; |
| 259 | struct _OT_MEM_INFO *pPrevMI; |
| 260 | |
| 261 | } OT_MEM_INFO; |
| 262 | |
| 263 | // Track Queue information |
| 264 | typedef struct _OT_QUEUE_INFO { |
| 265 | OT_MEM_INFO *pMemRefList; |
| 266 | struct _OT_QUEUE_INFO *pNextQI; |
| 267 | uint32_t queueNodeIndex; |
| 268 | VkQueue queue; |
| 269 | uint32_t refCount; |
| 270 | } OT_QUEUE_INFO; |
| 271 | |
| 272 | // Global list of QueueInfo structures, one per queue |
| 273 | static OT_QUEUE_INFO *g_pQueueInfo = NULL; |
| 274 | |
| 275 | // Convert an object type enum to an object type array index |
| 276 | static uint32_t |
| 277 | objTypeToIndex( |
| 278 | uint32_t objType) |
| 279 | { |
| 280 | uint32_t index = objType; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 281 | return index; |
| 282 | } |
| 283 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 284 | // Add new queue to head of global queue list |
| 285 | static void |
| 286 | addQueueInfo( |
| 287 | uint32_t queueNodeIndex, |
| 288 | VkQueue queue) |
| 289 | { |
| 290 | OT_QUEUE_INFO *pQueueInfo = new OT_QUEUE_INFO; |
| 291 | |
| 292 | if (pQueueInfo != NULL) { |
| 293 | memset(pQueueInfo, 0, sizeof(OT_QUEUE_INFO)); |
| 294 | pQueueInfo->queue = queue; |
| 295 | pQueueInfo->queueNodeIndex = queueNodeIndex; |
| 296 | pQueueInfo->pNextQI = g_pQueueInfo; |
| 297 | g_pQueueInfo = pQueueInfo; |
| 298 | } |
| 299 | else { |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 300 | log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_QUEUE, reinterpret_cast<uint64_t>(queue), 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 301 | "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information"); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | // Destroy memRef lists and free all memory |
| 306 | static void |
| 307 | destroyQueueMemRefLists(void) |
| 308 | { |
| 309 | OT_QUEUE_INFO *pQueueInfo = g_pQueueInfo; |
| 310 | OT_QUEUE_INFO *pDelQueueInfo = NULL; |
| 311 | while (pQueueInfo != NULL) { |
| 312 | OT_MEM_INFO *pMemInfo = pQueueInfo->pMemRefList; |
| 313 | while (pMemInfo != NULL) { |
| 314 | OT_MEM_INFO *pDelMemInfo = pMemInfo; |
| 315 | pMemInfo = pMemInfo->pNextMI; |
| 316 | delete pDelMemInfo; |
| 317 | } |
| 318 | pDelQueueInfo = pQueueInfo; |
| 319 | pQueueInfo = pQueueInfo->pNextQI; |
| 320 | delete pDelQueueInfo; |
| 321 | } |
| 322 | g_pQueueInfo = pQueueInfo; |
| 323 | } |
| 324 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 325 | static void |
| 326 | setGpuQueueInfoState( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 327 | uint32_t count, |
| 328 | void *pData) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 329 | { |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 330 | queueCount = count; |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 331 | queueInfo = (VkQueueFamilyProperties*)realloc((void*)queueInfo, count * sizeof(VkQueueFamilyProperties)); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 332 | if (queueInfo != NULL) { |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 333 | memcpy(queueInfo, pData, count * sizeof(VkQueueFamilyProperties)); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
| 337 | // Check Queue type flags for selected queue operations |
| 338 | static void |
| 339 | validateQueueFlags( |
| 340 | VkQueue queue, |
| 341 | const char *function) |
| 342 | { |
| 343 | OT_QUEUE_INFO *pQueueInfo = g_pQueueInfo; |
| 344 | while ((pQueueInfo != NULL) && (pQueueInfo->queue != queue)) { |
| 345 | pQueueInfo = pQueueInfo->pNextQI; |
| 346 | } |
| 347 | if (pQueueInfo != NULL) { |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 348 | if ((queueInfo != NULL) && (queueInfo[pQueueInfo->queueNodeIndex].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) == 0) { |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 349 | log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_QUEUE, reinterpret_cast<uint64_t>(queue), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 350 | "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set", function); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 351 | } else { |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 352 | log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_QUEUE, reinterpret_cast<uint64_t>(queue), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 353 | "Attempting %s on a possibly non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not known", function); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 358 | /* TODO: Port to new type safety */ |
| 359 | #if 0 |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 360 | // Check object status for selected flag state |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 361 | static VkBool32 |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 362 | validate_status( |
| 363 | VkObject dispatchable_object, |
| 364 | VkObject vkObj, |
| 365 | VkObjectType objType, |
| 366 | ObjectStatusFlags status_mask, |
| 367 | ObjectStatusFlags status_flag, |
| 368 | VkFlags msg_flags, |
| 369 | OBJECT_TRACK_ERROR error_code, |
| 370 | const char *fail_msg) |
| 371 | { |
| 372 | if (objMap.find(vkObj) != objMap.end()) { |
| 373 | OBJTRACK_NODE* pNode = objMap[vkObj]; |
| 374 | if ((pNode->status & status_mask) != status_flag) { |
| 375 | char str[1024]; |
| 376 | log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", |
| 377 | "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkObjectType(objType), |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 378 | reinterpret_cast<uint64_t>(vkObj), fail_msg); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 379 | return VK_FALSE; |
| 380 | } |
| 381 | return VK_TRUE; |
| 382 | } |
| 383 | else { |
| 384 | // If we do not find it print an error |
| 385 | log_msg(mdd(dispatchable_object), msg_flags, (VkObjectType) 0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", |
| 386 | "Unable to obtain status for non-existent object 0x%" PRIxLEAST64 " of %s type", |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 387 | reinterpret_cast<uint64_t>(vkObj), string_VkObjectType(objType)); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 388 | return VK_FALSE; |
| 389 | } |
| 390 | } |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 391 | #endif |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 392 | |
| 393 | #include "vk_dispatch_table_helper.h" |
| 394 | static void |
| 395 | initObjectTracker( |
| 396 | layer_data *my_data) |
| 397 | { |
| 398 | uint32_t report_flags = 0; |
| 399 | uint32_t debug_action = 0; |
| 400 | FILE *log_output = NULL; |
| 401 | const char *option_str; |
| 402 | // initialize ObjectTracker options |
| 403 | report_flags = getLayerOptionFlags("ObjectTrackerReportFlags", 0); |
| 404 | getLayerOptionEnum("ObjectTrackerDebugAction", (uint32_t *) &debug_action); |
| 405 | |
| 406 | if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
| 407 | { |
| 408 | option_str = getLayerOption("ObjectTrackerLogFilename"); |
Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 409 | log_output = getLayerLogOutput(option_str, "ObjectTracker"); |
Mark Lobodzinski | b49b6e5 | 2015-11-26 10:59:58 -0700 | [diff] [blame] | 410 | layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &(my_data->logging_callback)); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | if (!objLockInitialized) |
| 414 | { |
| 415 | // TODO/TBD: Need to delete this mutex sometime. How??? One |
| 416 | // suggestion is to call this during vkCreateInstance(), and then we |
| 417 | // can clean it up during vkDestroyInstance(). However, that requires |
| 418 | // that the layer have per-instance locks. We need to come back and |
| 419 | // address this soon. |
| 420 | loader_platform_thread_create_mutex(&objLock); |
| 421 | objLockInitialized = 1; |
| 422 | } |
| 423 | } |
| 424 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 425 | // |
| 426 | // Forward declares of generated routines |
| 427 | // |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 428 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 429 | static void create_physical_device(VkInstance dispatchable_object, VkPhysicalDevice vkObj, VkDbgObjectType objType); |
| 430 | static void create_instance(VkInstance dispatchable_object, VkInstance object, VkDbgObjectType objType); |
| 431 | static void create_device(VkDevice dispatchable_object, VkDevice object, VkDbgObjectType objType); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 432 | static void create_queue(VkDevice dispatchable_object, VkQueue vkObj, VkDbgObjectType objType); |
| 433 | static VkBool32 validate_image(VkQueue dispatchable_object, VkImage object); |
| 434 | static VkBool32 validate_image(VkCommandBuffer dispatchable_object, VkImage object); |
| 435 | static VkBool32 validate_command_buffer(VkQueue dispatchable_object, VkCommandBuffer object); |
| 436 | static VkBool32 validate_descriptor_set(VkCommandBuffer dispatchable_object, VkDescriptorSet object); |
| 437 | static VkBool32 validate_instance(VkInstance dispatchable_object, VkInstance object); |
| 438 | static VkBool32 validate_device(VkDevice dispatchable_object, VkDevice object); |
| 439 | static VkBool32 validate_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object); |
| 440 | static VkBool32 validate_descriptor_set_layout(VkDevice dispatchable_object, VkDescriptorSetLayout object); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 441 | static VkBool32 validate_command_pool(VkDevice dispatchable_object, VkCommandPool object); |
| 442 | static void destroy_command_pool(VkDevice dispatchable_object, VkCommandPool object); |
| 443 | static void destroy_command_buffer(VkCommandBuffer dispatchable_object, VkCommandBuffer object); |
| 444 | static void destroy_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object); |
| 445 | static void destroy_descriptor_set(VkDevice dispatchable_object, VkDescriptorSet object); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 446 | static void destroy_instance(VkInstance dispatchable_object, VkInstance object); |
| 447 | static void destroy_device_memory(VkDevice dispatchable_object, VkDeviceMemory object); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 448 | static VkBool32 set_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDbgObjectType objType, ObjectStatusFlags status_flag); |
| 449 | static VkBool32 reset_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDbgObjectType objType, ObjectStatusFlags status_flag); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 450 | #if 0 |
| 451 | static VkBool32 validate_status(VkDevice dispatchable_object, VkFence object, VkDbgObjectType objType, |
| 452 | ObjectStatusFlags status_mask, ObjectStatusFlags status_flag, VkFlags msg_flags, OBJECT_TRACK_ERROR error_code, |
| 453 | const char *fail_msg); |
| 454 | #endif |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 455 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkPhysicalDeviceMap; |
| 456 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkImageMap; |
| 457 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkQueueMap; |
| 458 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkDescriptorSetMap; |
| 459 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkBufferMap; |
| 460 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkFenceMap; |
| 461 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkSemaphoreMap; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 462 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkCommandPoolMap; |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 463 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkCommandBufferMap; |
| 464 | extern unordered_map<uint64_t, OBJTRACK_NODE*> VkSwapchainKHRMap; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 465 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 466 | static VkBool32 validate_image(VkQueue dispatchable_object, VkImage object) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 467 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 468 | if ((VkImageMap.find(reinterpret_cast<uint64_t>(object)) == VkImageMap.end()) && |
| 469 | (swapchainImageMap.find(reinterpret_cast<uint64_t>(object)) == swapchainImageMap.end())) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 470 | return log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, (uint64_t) object, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 471 | "Invalid VkImage Object %" PRIu64, reinterpret_cast<uint64_t>(object)); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 472 | } |
| 473 | return VK_FALSE; |
| 474 | } |
| 475 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 476 | static VkBool32 validate_image(VkCommandBuffer dispatchable_object, VkImage object) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 477 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 478 | if ((VkImageMap.find(reinterpret_cast<uint64_t>(object)) == VkImageMap.end()) && |
| 479 | (swapchainImageMap.find(reinterpret_cast<uint64_t>(object)) == swapchainImageMap.end())) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 480 | return log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, (uint64_t) object, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 481 | "Invalid VkImage Object %" PRIu64, reinterpret_cast<uint64_t>(object)); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 482 | } |
| 483 | return VK_FALSE; |
| 484 | } |
| 485 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 486 | static VkBool32 validate_command_buffer(VkQueue dispatchable_object, VkCommandBuffer object) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 487 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 488 | if (VkCommandBufferMap.find(reinterpret_cast<uint64_t>(object)) == VkCommandBufferMap.end()) { |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 489 | return log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 490 | "Invalid VkCommandBuffer Object %" PRIu64, reinterpret_cast<uint64_t>(object)); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 491 | } |
| 492 | return VK_FALSE; |
| 493 | } |
| 494 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 495 | static VkBool32 validate_descriptor_set(VkCommandBuffer dispatchable_object, VkDescriptorSet object) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 496 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 497 | if (VkDescriptorSetMap.find(reinterpret_cast<uint64_t>(object)) == VkDescriptorSetMap.end()) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 498 | return log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, (uint64_t) object, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 499 | "Invalid VkDescriptorSet Object %" PRIu64, reinterpret_cast<uint64_t>(object)); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 500 | } |
| 501 | return VK_FALSE; |
| 502 | } |
| 503 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 504 | static VkBool32 validate_buffer(VkQueue dispatchable_object, VkBuffer object) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 505 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 506 | if (VkBufferMap.find(reinterpret_cast<uint64_t>(object)) != VkBufferMap.end()) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 507 | return log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, (uint64_t) object, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 508 | "Invalid VkBuffer Object %" PRIu64, reinterpret_cast<uint64_t>(object)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 509 | } |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 510 | return VK_FALSE; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 511 | } |
| 512 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 513 | static VkBool32 set_status(VkQueue dispatchable_object, VkFence object, VkDbgObjectType objType, ObjectStatusFlags status_flag) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 514 | { |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 515 | VkBool32 skipCall = VK_FALSE; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 516 | if (object != VK_NULL_HANDLE) { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 517 | if (VkFenceMap.find(reinterpret_cast<uint64_t>(object)) != VkFenceMap.end()) { |
| 518 | OBJTRACK_NODE* pNode = VkFenceMap[reinterpret_cast<uint64_t>(object)]; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 519 | pNode->status |= status_flag; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 520 | } |
| 521 | else { |
| 522 | // If we do not find it print an error |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 523 | skipCall |= log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, (uint64_t) object, 0, OBJTRACK_NONE, "OBJTRACK", |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 524 | "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type", |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 525 | reinterpret_cast<uint64_t>(object), string_VkDbgObjectType(objType)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 526 | } |
| 527 | } |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 528 | return skipCall; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 529 | } |
| 530 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 531 | static VkBool32 validate_semaphore(VkQueue dispatchable_object, VkSemaphore object) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 532 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 533 | if (VkSemaphoreMap.find(reinterpret_cast<uint64_t>(object)) == VkSemaphoreMap.end()) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 534 | return log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, (uint64_t) object, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 535 | "Invalid VkSemaphore Object %" PRIu64, reinterpret_cast<uint64_t>(object)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 536 | } |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 537 | return VK_FALSE; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 538 | } |
| 539 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 540 | static VkBool32 validate_command_buffer(VkDevice dispatchable_object, VkCommandBuffer object) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 541 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 542 | if (VkCommandBufferMap.find(reinterpret_cast<uint64_t>(object)) == VkCommandBufferMap.end()) { |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 543 | return log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 544 | "Invalid VkCommandBuffer Object %" PRIu64, reinterpret_cast<uint64_t>(object)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 545 | } |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 546 | return VK_FALSE; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 547 | } |
| 548 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 549 | static void create_physical_device(VkInstance dispatchable_object, VkPhysicalDevice vkObj, VkDbgObjectType objType) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 550 | { |
| 551 | log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, reinterpret_cast<uint64_t>(vkObj), 0, OBJTRACK_NONE, "OBJTRACK", |
| 552 | "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType), |
| 553 | reinterpret_cast<uint64_t>(vkObj)); |
| 554 | |
| 555 | OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE; |
| 556 | pNewObjNode->objType = objType; |
| 557 | pNewObjNode->status = OBJSTATUS_NONE; |
| 558 | pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 559 | VkPhysicalDeviceMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 560 | uint32_t objIndex = objTypeToIndex(objType); |
| 561 | numObjs[objIndex]++; |
| 562 | numTotalObjs++; |
| 563 | } |
| 564 | |
Mark Lobodzinski | b49b6e5 | 2015-11-26 10:59:58 -0700 | [diff] [blame] | 565 | static void create_surface_khr(VkInstance instance, VkSurfaceKHR surface, VkDbgObjectType objType) |
| 566 | { |
| 567 | // TODO: Add tracking of surface objects |
| 568 | } |
| 569 | |
| 570 | static void destroy_surface_khr(VkInstance instance, VkSurfaceKHR surface) |
| 571 | { |
| 572 | // TODO: Add tracking of surface objects |
| 573 | } |
| 574 | |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 575 | static void alloc_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer vkObj, VkDbgObjectType objType) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 576 | { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 577 | log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, objType, reinterpret_cast<uint64_t>(vkObj), 0, OBJTRACK_NONE, "OBJTRACK", |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 578 | "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType), |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 579 | reinterpret_cast<uint64_t>(vkObj)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 580 | |
| 581 | OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 582 | pNewObjNode->objType = objType; |
| 583 | pNewObjNode->status = OBJSTATUS_NONE; |
| 584 | pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj); |
| 585 | pNewObjNode->parentObj = (uint64_t) commandPool; |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 586 | VkCommandBufferMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 587 | uint32_t objIndex = objTypeToIndex(objType); |
| 588 | numObjs[objIndex]++; |
| 589 | numTotalObjs++; |
| 590 | } |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 591 | |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 592 | static void free_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer commandBuffer) |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 593 | { |
| 594 | uint64_t object_handle = reinterpret_cast<uint64_t>(commandBuffer); |
| 595 | if (VkCommandBufferMap.find(object_handle) != VkCommandBufferMap.end()) { |
| 596 | OBJTRACK_NODE* pNode = VkCommandBufferMap[(uint64_t)commandBuffer]; |
| 597 | |
| 598 | if (pNode->parentObj != reinterpret_cast<uint64_t>(commandPool)) { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 599 | log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, pNode->objType, object_handle, 0, OBJTRACK_COMMAND_POOL_MISMATCH, "OBJTRACK", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 600 | "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64 " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").", |
| 601 | reinterpret_cast<uint64_t>(commandBuffer), pNode->parentObj, reinterpret_cast<uint64_t>(commandPool)); |
| 602 | } else { |
| 603 | |
| 604 | uint32_t objIndex = objTypeToIndex(pNode->objType); |
| 605 | assert(numTotalObjs > 0); |
| 606 | numTotalObjs--; |
| 607 | assert(numObjs[objIndex] > 0); |
| 608 | numObjs[objIndex]--; |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 609 | log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, pNode->objType, object_handle, 0, OBJTRACK_NONE, "OBJTRACK", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 610 | "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).", |
| 611 | string_VkDbgObjectType(pNode->objType), reinterpret_cast<uint64_t>(commandBuffer), numTotalObjs, numObjs[objIndex], |
| 612 | string_VkDbgObjectType(pNode->objType)); |
| 613 | delete pNode; |
| 614 | VkCommandBufferMap.erase(object_handle); |
| 615 | } |
| 616 | } else { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 617 | log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object_handle, 0, OBJTRACK_NONE, "OBJTRACK", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 618 | "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", |
| 619 | object_handle); |
| 620 | } |
| 621 | } |
| 622 | |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 623 | static void alloc_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet vkObj, VkDbgObjectType objType) |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 624 | { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 625 | log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, objType, reinterpret_cast<uint64_t>(vkObj), 0, OBJTRACK_NONE, "OBJTRACK", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 626 | "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType), |
| 627 | reinterpret_cast<uint64_t>(vkObj)); |
| 628 | |
| 629 | OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE; |
| 630 | pNewObjNode->objType = objType; |
| 631 | pNewObjNode->status = OBJSTATUS_NONE; |
| 632 | pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj); |
| 633 | pNewObjNode->parentObj = (uint64_t) descriptorPool; |
| 634 | VkDescriptorSetMap[(uint64_t)vkObj] = pNewObjNode; |
| 635 | uint32_t objIndex = objTypeToIndex(objType); |
| 636 | numObjs[objIndex]++; |
| 637 | numTotalObjs++; |
| 638 | } |
| 639 | |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 640 | static void free_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet descriptorSet) |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 641 | { |
| 642 | uint64_t object_handle = reinterpret_cast<uint64_t>(descriptorSet); |
| 643 | if (VkDescriptorSetMap.find(object_handle) != VkDescriptorSetMap.end()) { |
| 644 | OBJTRACK_NODE* pNode = VkDescriptorSetMap[(uint64_t)descriptorSet]; |
| 645 | |
| 646 | if (pNode->parentObj != reinterpret_cast<uint64_t>(descriptorPool)) { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 647 | log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, pNode->objType, object_handle, 0, OBJTRACK_DESCRIPTOR_POOL_MISMATCH, "OBJTRACK", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 648 | "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64 " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").", |
| 649 | reinterpret_cast<uint64_t>(descriptorSet), pNode->parentObj, reinterpret_cast<uint64_t>(descriptorPool)); |
| 650 | } else { |
| 651 | uint32_t objIndex = objTypeToIndex(pNode->objType); |
| 652 | assert(numTotalObjs > 0); |
| 653 | numTotalObjs--; |
| 654 | assert(numObjs[objIndex] > 0); |
| 655 | numObjs[objIndex]--; |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 656 | log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, pNode->objType, object_handle, 0, OBJTRACK_NONE, "OBJTRACK", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 657 | "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).", |
| 658 | string_VkDbgObjectType(pNode->objType), reinterpret_cast<uint64_t>(descriptorSet), numTotalObjs, numObjs[objIndex], |
| 659 | string_VkDbgObjectType(pNode->objType)); |
| 660 | delete pNode; |
| 661 | VkDescriptorSetMap.erase(object_handle); |
| 662 | } |
| 663 | } else { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 664 | log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object_handle, 0, OBJTRACK_NONE, "OBJTRACK", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 665 | "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", |
| 666 | object_handle); |
| 667 | } |
| 668 | } |
| 669 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 670 | static void create_swapchain_khr(VkDevice dispatchable_object, VkSwapchainKHR vkObj, VkDbgObjectType objType) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 671 | { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 672 | log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, (uint64_t) vkObj, 0, OBJTRACK_NONE, "OBJTRACK", |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 673 | "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType), |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 674 | reinterpret_cast<uint64_t>(vkObj)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 675 | |
| 676 | OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE; |
| 677 | pNewObjNode->objType = objType; |
| 678 | pNewObjNode->status = OBJSTATUS_NONE; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 679 | pNewObjNode->vkObj = (uint64_t) vkObj; |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 680 | VkSwapchainKHRMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 681 | uint32_t objIndex = objTypeToIndex(objType); |
| 682 | numObjs[objIndex]++; |
| 683 | numTotalObjs++; |
| 684 | } |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 685 | static void create_queue(VkDevice dispatchable_object, VkQueue vkObj, VkDbgObjectType objType) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 686 | { |
| 687 | log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, reinterpret_cast<uint64_t>(vkObj), 0, OBJTRACK_NONE, "OBJTRACK", |
| 688 | "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType), |
| 689 | reinterpret_cast<uint64_t>(vkObj)); |
| 690 | |
| 691 | OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE; |
| 692 | pNewObjNode->objType = objType; |
| 693 | pNewObjNode->status = OBJSTATUS_NONE; |
| 694 | pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 695 | VkQueueMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 696 | uint32_t objIndex = objTypeToIndex(objType); |
| 697 | numObjs[objIndex]++; |
| 698 | numTotalObjs++; |
| 699 | } |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 700 | static void create_swapchain_image_obj(VkDevice dispatchable_object, VkImage vkObj, VkSwapchainKHR swapchain) |
| 701 | { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 702 | log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t) vkObj, 0, OBJTRACK_NONE, "OBJTRACK", |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 703 | "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, "SwapchainImage", |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 704 | reinterpret_cast<uint64_t>(vkObj)); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 705 | |
| 706 | OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE; |
| 707 | pNewObjNode->objType = VK_OBJECT_TYPE_IMAGE; |
| 708 | pNewObjNode->status = OBJSTATUS_NONE; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 709 | pNewObjNode->vkObj = (uint64_t) vkObj; |
| 710 | pNewObjNode->parentObj = (uint64_t) swapchain; |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 711 | swapchainImageMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode; |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 712 | } |
| 713 | |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 714 | static void destroy_swapchain(VkDevice dispatchable_object, VkSwapchainKHR object) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 715 | { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 716 | if (VkSwapchainKHRMap.find(reinterpret_cast<uint64_t>(object)) != VkSwapchainKHRMap.end()) { |
| 717 | OBJTRACK_NODE* pNode = VkSwapchainKHRMap[reinterpret_cast<uint64_t>(object)]; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 718 | uint32_t objIndex = objTypeToIndex(pNode->objType); |
| 719 | assert(numTotalObjs > 0); |
| 720 | numTotalObjs--; |
| 721 | assert(numObjs[objIndex] > 0); |
| 722 | numObjs[objIndex]--; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 723 | log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, pNode->objType, (uint64_t) object, 0, OBJTRACK_NONE, "OBJTRACK", |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 724 | "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).", |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 725 | string_VkDbgObjectType(pNode->objType), (uint64_t) object, numTotalObjs, numObjs[objIndex], |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 726 | string_VkDbgObjectType(pNode->objType)); |
| 727 | delete pNode; |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 728 | VkSwapchainKHRMap.erase(reinterpret_cast<uint64_t>(object)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 729 | } else { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 730 | log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, (uint64_t) object, 0, OBJTRACK_NONE, "OBJTRACK", |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 731 | "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 732 | reinterpret_cast<uint64_t>(object)); |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 733 | } |
| 734 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 735 | // |
| 736 | // Non-auto-generated API functions called by generated code |
| 737 | // |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 738 | VkResult |
| 739 | explicit_CreateInstance( |
| 740 | const VkInstanceCreateInfo *pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 741 | const VkAllocationCallbacks * pAllocator, |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 742 | VkInstance * pInstance) |
| 743 | { |
David Pinedo | c0fa1ab | 2015-07-31 10:46:25 -0600 | [diff] [blame] | 744 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 745 | VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ObjectTracker_instance_table_map, *pInstance); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 746 | VkResult result = pInstanceTable->CreateInstance(pCreateInfo, pAllocator, pInstance); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 747 | |
| 748 | if (result == VK_SUCCESS) { |
| 749 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 750 | my_data->report_data = debug_report_create_instance( |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 751 | pInstanceTable, |
| 752 | *pInstance, |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 753 | pCreateInfo->enabledExtensionNameCount, |
Courtney Goeltzenleuchter | fce8cd2 | 2015-07-05 22:13:43 -0600 | [diff] [blame] | 754 | pCreateInfo->ppEnabledExtensionNames); |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 755 | createInstanceRegisterExtensions(pCreateInfo, *pInstance); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 756 | |
| 757 | initObjectTracker(my_data); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 758 | create_instance(*pInstance, *pInstance, VK_OBJECT_TYPE_INSTANCE); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 759 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 760 | return result; |
| 761 | } |
| 762 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 763 | void |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 764 | explicit_GetPhysicalDeviceQueueFamilyProperties( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 765 | VkPhysicalDevice gpu, |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 766 | uint32_t* pCount, |
| 767 | VkQueueFamilyProperties* pProperties) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 768 | { |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 769 | get_dispatch_table(ObjectTracker_instance_table_map, gpu)->GetPhysicalDeviceQueueFamilyProperties(gpu, pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 770 | |
| 771 | loader_platform_thread_lock_mutex(&objLock); |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 772 | if (pProperties != NULL) |
| 773 | setGpuQueueInfoState(*pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 774 | loader_platform_thread_unlock_mutex(&objLock); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | VkResult |
| 778 | explicit_CreateDevice( |
| 779 | VkPhysicalDevice gpu, |
| 780 | const VkDeviceCreateInfo *pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 781 | const VkAllocationCallbacks *pAllocator, |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 782 | VkDevice *pDevice) |
| 783 | { |
| 784 | loader_platform_thread_lock_mutex(&objLock); |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 785 | // VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ObjectTracker_instance_table_map, gpu); |
| 786 | VkLayerDispatchTable *pDeviceTable = get_dispatch_table(ObjectTracker_device_table_map, *pDevice); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 787 | VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 788 | if (result == VK_SUCCESS) { |
| 789 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
| 790 | //// VkLayerDispatchTable *pTable = get_dispatch_table(ObjectTracker_device_table_map, *pDevice); |
| 791 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 792 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 793 | create_device(*pDevice, *pDevice, VK_OBJECT_TYPE_DEVICE); |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 794 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | loader_platform_thread_unlock_mutex(&objLock); |
| 798 | return result; |
| 799 | } |
| 800 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 801 | VkResult explicit_EnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) |
| 802 | { |
| 803 | VkBool32 skipCall = VK_FALSE; |
| 804 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 805 | skipCall |= validate_instance(instance, instance); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 806 | loader_platform_thread_unlock_mutex(&objLock); |
| 807 | if (skipCall) |
| 808 | return VK_ERROR_VALIDATION_FAILED; |
| 809 | VkResult result = get_dispatch_table(ObjectTracker_instance_table_map, instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
| 810 | loader_platform_thread_lock_mutex(&objLock); |
| 811 | if (result == VK_SUCCESS) { |
| 812 | if (pPhysicalDevices) { |
| 813 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 814 | create_physical_device(instance, pPhysicalDevices[i], VK_OBJECT_TYPE_PHYSICAL_DEVICE); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | } |
| 818 | loader_platform_thread_unlock_mutex(&objLock); |
| 819 | return result; |
| 820 | } |
| 821 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 822 | void |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 823 | explicit_GetDeviceQueue( |
| 824 | VkDevice device, |
| 825 | uint32_t queueNodeIndex, |
| 826 | uint32_t queueIndex, |
| 827 | VkQueue *pQueue) |
| 828 | { |
| 829 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 830 | validate_device(device, device); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 831 | loader_platform_thread_unlock_mutex(&objLock); |
| 832 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 833 | get_dispatch_table(ObjectTracker_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 834 | |
| 835 | loader_platform_thread_lock_mutex(&objLock); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 836 | addQueueInfo(queueNodeIndex, *pQueue); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 837 | create_queue(device, *pQueue, VK_OBJECT_TYPE_QUEUE); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 838 | loader_platform_thread_unlock_mutex(&objLock); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | VkResult |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 842 | explicit_MapMemory( |
| 843 | VkDevice device, |
| 844 | VkDeviceMemory mem, |
| 845 | VkDeviceSize offset, |
| 846 | VkDeviceSize size, |
| 847 | VkFlags flags, |
| 848 | void **ppData) |
| 849 | { |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 850 | VkBool32 skipCall = VK_FALSE; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 851 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 852 | skipCall |= set_device_memory_status(device, mem, VK_OBJECT_TYPE_DEVICE_MEMORY, OBJSTATUS_GPU_MEM_MAPPED); |
| 853 | skipCall |= validate_device(device, device); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 854 | loader_platform_thread_unlock_mutex(&objLock); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 855 | if (skipCall == VK_TRUE) |
| 856 | return VK_ERROR_VALIDATION_FAILED; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 857 | |
| 858 | VkResult result = get_dispatch_table(ObjectTracker_device_table_map, device)->MapMemory(device, mem, offset, size, flags, ppData); |
| 859 | |
| 860 | return result; |
| 861 | } |
| 862 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 863 | void |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 864 | explicit_UnmapMemory( |
| 865 | VkDevice device, |
| 866 | VkDeviceMemory mem) |
| 867 | { |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 868 | VkBool32 skipCall = VK_FALSE; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 869 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 870 | skipCall |= reset_device_memory_status(device, mem, VK_OBJECT_TYPE_DEVICE_MEMORY, OBJSTATUS_GPU_MEM_MAPPED); |
| 871 | skipCall |= validate_device(device, device); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 872 | loader_platform_thread_unlock_mutex(&objLock); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 873 | if (skipCall == VK_TRUE) |
| 874 | return; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 875 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 876 | get_dispatch_table(ObjectTracker_device_table_map, device)->UnmapMemory(device, mem); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | VkResult |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 880 | explicit_QueueBindSparse( |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 881 | VkQueue queue, |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 882 | uint32_t bindInfoCount, |
| 883 | const VkBindSparseInfo* pBindInfo, |
| 884 | VkFence fence) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 885 | { |
| 886 | loader_platform_thread_lock_mutex(&objLock); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 887 | validateQueueFlags(queue, "QueueBindSparse"); |
| 888 | |
| 889 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 890 | for (uint32_t j = 0; j < pBindInfo[i].bufferBindCount; j++) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 891 | validate_buffer(queue, pBindInfo[i].pBufferBinds[j].buffer); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 892 | for (uint32_t j = 0; j < pBindInfo[i].imageOpaqueBindCount; j++) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 893 | validate_image(queue, pBindInfo[i].pImageOpaqueBinds[j].image); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 894 | for (uint32_t j = 0; j < pBindInfo[i].imageBindCount; j++) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 895 | validate_image(queue, pBindInfo[i].pImageBinds[j].image); |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 896 | } |
| 897 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 898 | loader_platform_thread_unlock_mutex(&objLock); |
| 899 | |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 900 | VkResult result = get_dispatch_table(ObjectTracker_device_table_map, queue)->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence); |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 901 | return result; |
| 902 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 903 | |
| 904 | VkResult |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 905 | explicit_AllocateCommandBuffers( |
| 906 | VkDevice device, |
| 907 | const VkCommandBufferAllocateInfo *pAllocateInfo, |
| 908 | VkCommandBuffer* pCommandBuffers) |
| 909 | { |
| 910 | VkBool32 skipCall = VK_FALSE; |
| 911 | loader_platform_thread_lock_mutex(&objLock); |
| 912 | skipCall |= validate_device(device, device); |
| 913 | skipCall |= validate_command_pool(device, pAllocateInfo->commandPool); |
| 914 | loader_platform_thread_unlock_mutex(&objLock); |
| 915 | |
| 916 | if (skipCall) { |
| 917 | return VK_ERROR_VALIDATION_FAILED; |
| 918 | } |
| 919 | |
| 920 | VkResult result = get_dispatch_table(ObjectTracker_device_table_map, device)->AllocateCommandBuffers( |
| 921 | device, pAllocateInfo, pCommandBuffers); |
| 922 | |
| 923 | loader_platform_thread_lock_mutex(&objLock); |
| 924 | for (uint32_t i = 0; i < pAllocateInfo->bufferCount; i++) { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 925 | alloc_command_buffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], VK_OBJECT_TYPE_COMMAND_BUFFER); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 926 | } |
| 927 | loader_platform_thread_unlock_mutex(&objLock); |
| 928 | |
| 929 | return result; |
| 930 | } |
| 931 | |
| 932 | VkResult |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 933 | explicit_AllocateDescriptorSets( |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 934 | VkDevice device, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 935 | const VkDescriptorSetAllocateInfo *pAllocateInfo, |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 936 | VkDescriptorSet *pDescriptorSets) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 937 | { |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 938 | VkBool32 skipCall = VK_FALSE; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 939 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 940 | skipCall |= validate_device(device, device); |
| 941 | skipCall |= validate_descriptor_pool(device, pAllocateInfo->descriptorPool); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 942 | for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) { |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 943 | skipCall |= validate_descriptor_set_layout(device, pAllocateInfo->pSetLayouts[i]); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 944 | } |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 945 | loader_platform_thread_unlock_mutex(&objLock); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 946 | if (skipCall) |
| 947 | return VK_ERROR_VALIDATION_FAILED; |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 948 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 949 | VkResult result = get_dispatch_table(ObjectTracker_device_table_map, device)->AllocateDescriptorSets( |
| 950 | device, pAllocateInfo, pDescriptorSets); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 951 | |
| 952 | loader_platform_thread_lock_mutex(&objLock); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 953 | for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 954 | alloc_descriptor_set(device, pAllocateInfo->descriptorPool, pDescriptorSets[i], VK_OBJECT_TYPE_DESCRIPTOR_SET); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 955 | } |
| 956 | loader_platform_thread_unlock_mutex(&objLock); |
| 957 | |
| 958 | return result; |
| 959 | } |
| 960 | |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 961 | void |
| 962 | explicit_FreeCommandBuffers( |
| 963 | VkDevice device, |
| 964 | VkCommandPool commandPool, |
| 965 | uint32_t commandBufferCount, |
| 966 | const VkCommandBuffer *pCommandBuffers) |
| 967 | { |
| 968 | loader_platform_thread_lock_mutex(&objLock); |
| 969 | validate_command_pool(device, commandPool); |
| 970 | validate_device(device, device); |
| 971 | loader_platform_thread_unlock_mutex(&objLock); |
| 972 | |
| 973 | get_dispatch_table(ObjectTracker_device_table_map, device)->FreeCommandBuffers(device, |
| 974 | commandPool, commandBufferCount, pCommandBuffers); |
| 975 | |
| 976 | loader_platform_thread_lock_mutex(&objLock); |
| 977 | for (uint32_t i = 0; i < commandBufferCount; i++) |
| 978 | { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 979 | free_command_buffer(device, commandPool, *pCommandBuffers); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 980 | pCommandBuffers++; |
| 981 | } |
| 982 | loader_platform_thread_unlock_mutex(&objLock); |
| 983 | } |
| 984 | |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 985 | void |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 986 | explicit_DestroySwapchainKHR( |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 987 | VkDevice device, |
| 988 | VkSwapchainKHR swapchain, |
| 989 | const VkAllocationCallbacks *pAllocator) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 990 | { |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 991 | loader_platform_thread_lock_mutex(&objLock); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 992 | // A swapchain's images are implicitly deleted when the swapchain is deleted. |
| 993 | // Remove this swapchain's images from our map of such images. |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 994 | unordered_map<uint64_t, OBJTRACK_NODE*>::iterator itr = swapchainImageMap.begin(); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 995 | while (itr != swapchainImageMap.end()) { |
| 996 | OBJTRACK_NODE* pNode = (*itr).second; |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 997 | if (pNode->parentObj == reinterpret_cast<uint64_t>(swapchain)) { |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 998 | swapchainImageMap.erase(itr++); |
| 999 | } else { |
| 1000 | ++itr; |
| 1001 | } |
| 1002 | } |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1003 | destroy_swapchain(device, swapchain); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1004 | loader_platform_thread_unlock_mutex(&objLock); |
| 1005 | |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 1006 | get_dispatch_table(ObjectTracker_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1007 | } |
| 1008 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 1009 | void |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1010 | explicit_FreeMemory( |
| 1011 | VkDevice device, |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1012 | VkDeviceMemory mem, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1013 | const VkAllocationCallbacks* pAllocator) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1014 | { |
| 1015 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1016 | validate_device(device, device); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1017 | loader_platform_thread_unlock_mutex(&objLock); |
| 1018 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1019 | get_dispatch_table(ObjectTracker_device_table_map, device)->FreeMemory(device, mem, pAllocator); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1020 | |
| 1021 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1022 | destroy_device_memory(device, mem); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1023 | loader_platform_thread_unlock_mutex(&objLock); |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1024 | } |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1025 | |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1026 | VkResult |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1027 | explicit_FreeDescriptorSets( |
| 1028 | VkDevice device, |
| 1029 | VkDescriptorPool descriptorPool, |
| 1030 | uint32_t count, |
| 1031 | const VkDescriptorSet *pDescriptorSets) |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1032 | { |
| 1033 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1034 | validate_descriptor_pool(device, descriptorPool); |
| 1035 | validate_device(device, device); |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1036 | loader_platform_thread_unlock_mutex(&objLock); |
| 1037 | VkResult result = get_dispatch_table(ObjectTracker_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets); |
| 1038 | |
| 1039 | loader_platform_thread_lock_mutex(&objLock); |
Courtney Goeltzenleuchter | 7ebf121 | 2015-07-23 11:25:17 -0600 | [diff] [blame] | 1040 | for (uint32_t i=0; i<count; i++) |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1041 | { |
Michael Lentine | fc6aa76 | 2015-11-20 12:11:42 -0800 | [diff] [blame] | 1042 | free_descriptor_set(device, descriptorPool, *pDescriptorSets++); |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1043 | } |
| 1044 | loader_platform_thread_unlock_mutex(&objLock); |
| 1045 | return result; |
| 1046 | } |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1047 | |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1048 | void |
| 1049 | explicit_DestroyDescriptorPool( |
| 1050 | VkDevice device, |
| 1051 | VkDescriptorPool descriptorPool, |
| 1052 | const VkAllocationCallbacks *pAllocator) |
| 1053 | { |
| 1054 | VkBool32 skipCall = VK_FALSE; |
| 1055 | loader_platform_thread_lock_mutex(&objLock); |
| 1056 | skipCall |= validate_device(device, device); |
| 1057 | skipCall |= validate_descriptor_pool(device, descriptorPool); |
| 1058 | loader_platform_thread_unlock_mutex(&objLock); |
| 1059 | if (skipCall) { |
| 1060 | return; |
| 1061 | } |
| 1062 | // A DescriptorPool's descriptor sets are implicitly deleted when the pool is deleted. |
| 1063 | // Remove this pool's descriptor sets from our descriptorSet map. |
| 1064 | loader_platform_thread_lock_mutex(&objLock); |
| 1065 | unordered_map<uint64_t, OBJTRACK_NODE*>::iterator itr = VkDescriptorSetMap.begin(); |
| 1066 | while (itr != VkDescriptorSetMap.end()) { |
| 1067 | OBJTRACK_NODE* pNode = (*itr).second; |
Mark Lobodzinski | b29731a | 2015-11-18 11:01:02 -0700 | [diff] [blame] | 1068 | auto del_itr = itr++; |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1069 | if (pNode->parentObj == reinterpret_cast<uint64_t>(descriptorPool)) { |
Mark Lobodzinski | b29731a | 2015-11-18 11:01:02 -0700 | [diff] [blame] | 1070 | destroy_descriptor_set(device, reinterpret_cast<VkDescriptorSet>((*del_itr).first)); |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | destroy_descriptor_pool(device, descriptorPool); |
| 1074 | loader_platform_thread_unlock_mutex(&objLock); |
| 1075 | get_dispatch_table(ObjectTracker_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator); |
| 1076 | } |
| 1077 | |
| 1078 | void |
| 1079 | explicit_DestroyCommandPool( |
| 1080 | VkDevice device, |
| 1081 | VkCommandPool commandPool, |
| 1082 | const VkAllocationCallbacks *pAllocator) |
| 1083 | { |
| 1084 | VkBool32 skipCall = VK_FALSE; |
| 1085 | loader_platform_thread_lock_mutex(&objLock); |
| 1086 | skipCall |= validate_device(device, device); |
| 1087 | skipCall |= validate_command_pool(device, commandPool); |
| 1088 | loader_platform_thread_unlock_mutex(&objLock); |
| 1089 | if (skipCall) { |
| 1090 | return; |
| 1091 | } |
| 1092 | loader_platform_thread_lock_mutex(&objLock); |
| 1093 | // A CommandPool's command buffers are implicitly deleted when the pool is deleted. |
| 1094 | // Remove this pool's cmdBuffers from our cmd buffer map. |
| 1095 | unordered_map<uint64_t, OBJTRACK_NODE*>::iterator itr = VkCommandBufferMap.begin(); |
| 1096 | unordered_map<uint64_t, OBJTRACK_NODE*>::iterator del_itr; |
| 1097 | while (itr != VkCommandBufferMap.end()) { |
| 1098 | OBJTRACK_NODE* pNode = (*itr).second; |
| 1099 | del_itr = itr++; |
| 1100 | if (pNode->parentObj == reinterpret_cast<uint64_t>(commandPool)) { |
| 1101 | destroy_command_buffer(reinterpret_cast<VkCommandBuffer>((*del_itr).first), |
| 1102 | reinterpret_cast<VkCommandBuffer>((*del_itr).first)); |
| 1103 | } |
| 1104 | } |
| 1105 | destroy_command_pool(device, commandPool); |
| 1106 | loader_platform_thread_unlock_mutex(&objLock); |
| 1107 | get_dispatch_table(ObjectTracker_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator); |
| 1108 | } |
| 1109 | |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1110 | VkResult |
| 1111 | explicit_GetSwapchainImagesKHR( |
| 1112 | VkDevice device, |
| 1113 | VkSwapchainKHR swapchain, |
| 1114 | uint32_t *pCount, |
| 1115 | VkImage *pSwapchainImages) |
| 1116 | { |
| 1117 | VkBool32 skipCall = VK_FALSE; |
| 1118 | loader_platform_thread_lock_mutex(&objLock); |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1119 | skipCall |= validate_device(device, device); |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1120 | loader_platform_thread_unlock_mutex(&objLock); |
| 1121 | if (skipCall) |
| 1122 | return VK_ERROR_VALIDATION_FAILED; |
| 1123 | |
| 1124 | VkResult result = get_dispatch_table(ObjectTracker_device_table_map, device)->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages); |
| 1125 | |
| 1126 | if (pSwapchainImages != NULL) { |
| 1127 | loader_platform_thread_lock_mutex(&objLock); |
| 1128 | for (uint32_t i = 0; i < *pCount; i++) { |
| 1129 | create_swapchain_image_obj(device, pSwapchainImages[i], swapchain); |
| 1130 | } |
| 1131 | loader_platform_thread_unlock_mutex(&objLock); |
| 1132 | } |
| 1133 | return result; |
| 1134 | } |
| 1135 | |