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