blob: 18d2cb20608b466238d751bc9959004dbd3de752 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
Tobin Ehlis42586532014-11-14 13:01:02 -07005 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
Tobin Ehlis42586532014-11-14 13:01:02 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlis42586532014-11-14 13:01:02 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060017 *
18 * Author: Jon Ashburn <jon@lunarg.com>
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlis42586532014-11-14 13:01:02 -070021 */
22
Jeremy Hayes2f065b12016-04-13 10:54:17 -060023#include <mutex>
24
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include "vulkan/vk_layer.h"
Courtney Goeltzenleuchterfce8cd22015-07-05 22:13:43 -060026#include "vk_layer_extension_utils.h"
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060027#include "vk_enum_string_helper.h"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -070028#include "vk_layer_table.h"
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -060029#include "vk_layer_utils.h"
Mark Lobodzinskifae78852015-06-23 11:35:12 -060030
Chia-I Wucdb70962016-05-13 14:07:36 +080031namespace object_tracker {
32
Tobin Ehlisca915872014-11-18 11:28:33 -070033// Object Tracker ERROR codes
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060034enum OBJECT_TRACK_ERROR {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070035 OBJTRACK_NONE, // Used for INFO & other non-error messages
36 OBJTRACK_UNKNOWN_OBJECT, // Updating uses of object that's not in global object list
37 OBJTRACK_INTERNAL_ERROR, // Bug with data tracking within the layer
Jon Ashburn5484e0c2016-03-08 17:48:44 -070038 OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed
Jon Ashburn5484e0c2016-03-08 17:48:44 -070039 OBJTRACK_INVALID_OBJECT, // Object used that has never been created
40 OBJTRACK_DESCRIPTOR_POOL_MISMATCH, // Descriptor Pools specified incorrectly
41 OBJTRACK_COMMAND_POOL_MISMATCH, // Command Pools specified incorrectly
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060042};
Tobin Ehlisca915872014-11-18 11:28:33 -070043
Tobin Ehlis91ce77e2015-01-16 08:56:30 -070044// Object Status -- used to track state of individual objects
Mark Lobodzinski38f0db22015-05-20 17:33:47 -050045typedef VkFlags ObjectStatusFlags;
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060046enum ObjectStatusFlagBits {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070047 OBJSTATUS_NONE = 0x00000000, // No status is set
48 OBJSTATUS_FENCE_IS_SUBMITTED = 0x00000001, // Fence has been submitted
49 OBJSTATUS_VIEWPORT_BOUND = 0x00000002, // Viewport state object has been bound
50 OBJSTATUS_RASTER_BOUND = 0x00000004, // Viewport state object has been bound
51 OBJSTATUS_COLOR_BLEND_BOUND = 0x00000008, // Viewport state object has been bound
52 OBJSTATUS_DEPTH_STENCIL_BOUND = 0x00000010, // Viewport state object has been bound
53 OBJSTATUS_GPU_MEM_MAPPED = 0x00000020, // Memory object is currently mapped
54 OBJSTATUS_COMMAND_BUFFER_SECONDARY = 0x00000040, // Command Buffer is of type SECONDARY
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060055};
Chia-I Wuf8693382015-04-16 22:02:10 +080056
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060057struct OBJTRACK_NODE {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070058 uint64_t vkObj; // Object handle
59 VkDebugReportObjectTypeEXT objType; // Object type identifier
60 ObjectStatusFlags status; // Object state
61 uint64_t parentObj; // Parent object
62 uint64_t belongsTo; // Object Scope -- owning device/instance
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -060063};
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -060064
Tobin Ehlis42586532014-11-14 13:01:02 -070065// prototype for extension functions
Mark Lobodzinskifae78852015-06-23 11:35:12 -060066uint64_t objTrackGetObjectCount(VkDevice device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070067uint64_t objTrackGetObjectsOfTypeCount(VkDevice, VkDebugReportObjectTypeEXT type);
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -060068
Tobin Ehlisca915872014-11-18 11:28:33 -070069// Func ptr typedefs
Mark Lobodzinskifae78852015-06-23 11:35:12 -060070typedef uint64_t (*OBJ_TRACK_GET_OBJECT_COUNT)(VkDevice);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070071typedef uint64_t (*OBJ_TRACK_GET_OBJECTS_OF_TYPE_COUNT)(VkDevice, VkDebugReportObjectTypeEXT);
Mark Lobodzinskifae78852015-06-23 11:35:12 -060072
Cody Northrop55443ef2015-09-28 15:09:32 -060073struct layer_data {
Chia-I Wu1ad50f42016-05-17 07:57:15 +080074 VkInstance instance;
75
Mark Lobodzinskifae78852015-06-23 11:35:12 -060076 debug_report_data *report_data;
Cody Northrop9c93ec52016-04-28 09:55:08 -060077 // TODO: put instance data here
78 std::vector<VkDebugReportCallbackEXT> logging_callback;
79 bool wsi_enabled;
80 bool objtrack_extensions_enabled;
Ian Elliotted6b5ac2016-04-28 09:08:13 -060081 // The following are for keeping track of the temporary callbacks that can
82 // be used in vkCreateInstance and vkDestroyInstance:
83 uint32_t num_tmp_callbacks;
84 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
85 VkDebugReportCallbackEXT *tmp_callbacks;
Cody Northrop55443ef2015-09-28 15:09:32 -060086
Ian Elliotted6b5ac2016-04-28 09:08:13 -060087 layer_data()
88 : report_data(nullptr), wsi_enabled(false), objtrack_extensions_enabled(false), num_tmp_callbacks(0),
89 tmp_dbg_create_infos(nullptr), tmp_callbacks(nullptr){};
Cody Northrop55443ef2015-09-28 15:09:32 -060090};
Mark Lobodzinskifae78852015-06-23 11:35:12 -060091
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060092struct instance_extension_enables {
Jon Ashburn3dc39382015-09-17 10:00:32 -060093 bool wsi_enabled;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060094 bool xlib_enabled;
95 bool xcb_enabled;
96 bool wayland_enabled;
97 bool mir_enabled;
98 bool android_enabled;
99 bool win32_enabled;
Jon Ashburn3dc39382015-09-17 10:00:32 -0600100};
101
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600102static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700103static std::unordered_map<void *, layer_data *> layer_data_map;
104static device_table_map object_tracker_device_table_map;
105static instance_table_map object_tracker_instance_table_map;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600106
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600107// We need additionally validate image usage using a separate map
108// of swapchain-created images
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600109static std::unordered_map<uint64_t, OBJTRACK_NODE *> swapchainImageMap;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600110
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600111static long long unsigned int object_track_index = 0;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600112static std::mutex global_lock;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600113
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700114#define NUM_OBJECT_TYPES (VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT + 1)
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600115
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700116static uint64_t numObjs[NUM_OBJECT_TYPES] = {0};
117static uint64_t numTotalObjs = 0;
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600118std::vector<VkQueueFamilyProperties> queue_family_properties;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600119
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600120//
121// Internal Object Tracker Functions
122//
123
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700124static void createDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700125 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngaa1aa3a2016-07-05 16:41:50 -0600126
Ian Elliott1064fe32015-07-06 14:31:32 -0600127 my_device_data->wsi_enabled = false;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700128 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700129 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
Ian Elliott1064fe32015-07-06 14:31:32 -0600130 my_device_data->wsi_enabled = true;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600131
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700132 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], "OBJTRACK_EXTENSIONS") == 0)
Courtney Goeltzenleuchterfce8cd22015-07-05 22:13:43 -0600133 my_device_data->objtrack_extensions_enabled = true;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600134 }
135}
136
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700137static void createInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700138 VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(object_tracker_instance_table_map, instance);
Mark Lobodzinskie86e1382015-11-24 15:50:44 -0700139
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600140 instanceExtMap[pDisp] = {};
141
142 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
143 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Jon Ashburn3dc39382015-09-17 10:00:32 -0600144 instanceExtMap[pDisp].wsi_enabled = true;
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600145 }
146#ifdef VK_USE_PLATFORM_XLIB_KHR
147 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
148 instanceExtMap[pDisp].xlib_enabled = true;
149 }
150#endif
151#ifdef VK_USE_PLATFORM_XCB_KHR
152 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
153 instanceExtMap[pDisp].xcb_enabled = true;
154 }
155#endif
156#ifdef VK_USE_PLATFORM_WAYLAND_KHR
157 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
158 instanceExtMap[pDisp].wayland_enabled = true;
159 }
160#endif
161#ifdef VK_USE_PLATFORM_MIR_KHR
162 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
163 instanceExtMap[pDisp].mir_enabled = true;
164 }
165#endif
166#ifdef VK_USE_PLATFORM_ANDROID_KHR
167 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
168 instanceExtMap[pDisp].android_enabled = true;
169 }
170#endif
171#ifdef VK_USE_PLATFORM_WIN32_KHR
172 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
173 instanceExtMap[pDisp].win32_enabled = true;
174 }
175#endif
Jon Ashburn3dc39382015-09-17 10:00:32 -0600176 }
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600177
Jon Ashburn3dc39382015-09-17 10:00:32 -0600178}
179
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600180// Indicate device or instance dispatch table type
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600181enum DispTableType {
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600182 DISP_TBL_TYPE_INSTANCE,
183 DISP_TBL_TYPE_DEVICE,
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600184};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600185
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700186debug_report_data *mdd(const void *object) {
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600187 dispatch_key key = get_dispatch_key(object);
188 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600189 return my_data->report_data;
190}
191
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700192debug_report_data *mid(VkInstance object) {
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600193 dispatch_key key = get_dispatch_key(object);
194 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600195 return my_data->report_data;
196}
197
198// For each Queue's doubly linked-list of mem refs
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600199struct OT_MEM_INFO {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700200 VkDeviceMemory mem;
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600201 OT_MEM_INFO *pNextMI;
202 OT_MEM_INFO *pPrevMI;
203};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600204
205// Track Queue information
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600206struct OT_QUEUE_INFO {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700207 OT_MEM_INFO *pMemRefList;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700208 uint32_t queueNodeIndex;
209 VkQueue queue;
210 uint32_t refCount;
Mark Lobodzinskibd1fecd2016-05-19 17:06:56 -0600211};
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600212
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600213// Global map of structures, one per queue
214std::unordered_map<VkQueue, OT_QUEUE_INFO *> queue_info_map;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600215
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600216#include "vk_dispatch_table_helper.h"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600217
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600218static void init_object_tracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
219
220 layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_object_tracker");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600221}
222
Tony Barboura05dbaa2015-07-09 17:31:46 -0600223//
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700224// Forward declarations
Tony Barboura05dbaa2015-07-09 17:31:46 -0600225//
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600226
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700227static void create_physical_device(VkInstance dispatchable_object, VkPhysicalDevice vkObj, VkDebugReportObjectTypeEXT objType);
228static void create_instance(VkInstance dispatchable_object, VkInstance object, VkDebugReportObjectTypeEXT objType);
229static void create_device(VkDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700230static void create_device(VkPhysicalDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700231static void create_queue(VkDevice dispatchable_object, VkQueue vkObj, VkDebugReportObjectTypeEXT objType);
Jon Ashburn5e026df2016-06-15 08:19:07 -0600232static void create_display_khr(VkPhysicalDevice dispatchable_object, VkDisplayKHR vkObj, VkDebugReportObjectTypeEXT objType);
Jon Ashburn665d1d52016-06-28 16:59:36 -0600233static void create_display_mode_khr(VkPhysicalDevice dispatchable_object, VkDisplayModeKHR vkObj, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600234static bool validate_image(VkQueue dispatchable_object, VkImage object, VkDebugReportObjectTypeEXT objType, bool null_allowed);
235static bool validate_instance(VkInstance dispatchable_object, VkInstance object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700236 bool null_allowed);
Jon Ashburn5e026df2016-06-15 08:19:07 -0600237static bool validate_physical_device(VkPhysicalDevice dispatchable_object, VkPhysicalDevice object, VkDebugReportObjectTypeEXT objType, bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600238static bool validate_device(VkDevice dispatchable_object, VkDevice object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700239 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600240static bool validate_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700241 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600242static bool validate_descriptor_set_layout(VkDevice dispatchable_object, VkDescriptorSetLayout object,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700243 VkDebugReportObjectTypeEXT objType, bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600244static bool validate_command_pool(VkDevice dispatchable_object, VkCommandPool object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700245 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600246static bool validate_buffer(VkQueue dispatchable_object, VkBuffer object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700247 bool null_allowed);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700248static void create_pipeline(VkDevice dispatchable_object, VkPipeline vkObj, VkDebugReportObjectTypeEXT objType);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600249static bool validate_pipeline_cache(VkDevice dispatchable_object, VkPipelineCache object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700250 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600251static bool validate_render_pass(VkDevice dispatchable_object, VkRenderPass object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700252 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600253static bool validate_shader_module(VkDevice dispatchable_object, VkShaderModule object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700254 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600255static bool validate_pipeline_layout(VkDevice dispatchable_object, VkPipelineLayout object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700256 bool null_allowed);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600257static bool validate_pipeline(VkDevice dispatchable_object, VkPipeline object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700258 bool null_allowed);
Jon Ashburn665d1d52016-06-28 16:59:36 -0600259static bool validate_display_khr(VkPhysicalDevice dispatchable_object, VkDisplayKHR object, VkDebugReportObjectTypeEXT objType,
260 bool null_allowed);
261static bool validate_display_mode_khr(VkInstance dispatchable_object, VkDisplayModeKHR object, VkDebugReportObjectTypeEXT objType,
262 bool null_allowed);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700263static void destroy_command_pool(VkDevice dispatchable_object, VkCommandPool object);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700264static void destroy_descriptor_pool(VkDevice dispatchable_object, VkDescriptorPool object);
265static void destroy_descriptor_set(VkDevice dispatchable_object, VkDescriptorSet object);
266static void destroy_device_memory(VkDevice dispatchable_object, VkDeviceMemory object);
267static void destroy_swapchain_khr(VkDevice dispatchable_object, VkSwapchainKHR object);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600268static bool set_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700269 ObjectStatusFlags status_flag);
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600270static bool reset_device_memory_status(VkDevice dispatchable_object, VkDeviceMemory object, VkDebugReportObjectTypeEXT objType,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700271 ObjectStatusFlags status_flag);
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600272static void destroy_queue(VkQueue dispatchable_object, VkQueue object);
273
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600274extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkPhysicalDeviceMap;
275extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkDeviceMap;
276extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkImageMap;
277extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkQueueMap;
278extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkDescriptorSetMap;
279extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkBufferMap;
280extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkFenceMap;
281extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSemaphoreMap;
282extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkCommandPoolMap;
283extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkCommandBufferMap;
284extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSwapchainKHRMap;
285extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkSurfaceKHRMap;
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600286extern std::unordered_map<uint64_t, OBJTRACK_NODE *> VkQueueMap;
Tony Barboura05dbaa2015-07-09 17:31:46 -0600287
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600288// Convert an object type enum to an object type array index
289static uint32_t objTypeToIndex(uint32_t objType) {
290 uint32_t index = objType;
291 return index;
292}
293
294// Add new queue to head of global queue list
295static void addQueueInfo(uint32_t queueNodeIndex, VkQueue queue) {
296 auto queueItem = queue_info_map.find(queue);
297 if (queueItem == queue_info_map.end()) {
298 OT_QUEUE_INFO *p_queue_info = new OT_QUEUE_INFO;
299 if (p_queue_info != NULL) {
300 memset(p_queue_info, 0, sizeof(OT_QUEUE_INFO));
301 p_queue_info->queue = queue;
302 p_queue_info->queueNodeIndex = queueNodeIndex;
303 queue_info_map[queue] = p_queue_info;
304 } else {
305 log_msg(mdd(queue), VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
306 reinterpret_cast<uint64_t>(queue), __LINE__, OBJTRACK_INTERNAL_ERROR, "OBJTRACK",
307 "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");
308 }
309 }
310}
311
312// Destroy memRef lists and free all memory
313static void destroyQueueMemRefLists() {
314 for (auto queue_item : queue_info_map) {
315 OT_MEM_INFO *p_mem_info = queue_item.second->pMemRefList;
316 while (p_mem_info != NULL) {
317 OT_MEM_INFO *p_del_mem_info = p_mem_info;
318 p_mem_info = p_mem_info->pNextMI;
319 delete p_del_mem_info;
320 }
321 delete queue_item.second;
322 }
323 queue_info_map.clear();
324
325 // Destroy the items in the queue map
326 auto queue = VkQueueMap.begin();
327 while (queue != VkQueueMap.end()) {
328 uint32_t obj_index = objTypeToIndex(queue->second->objType);
329 assert(numTotalObjs > 0);
330 numTotalObjs--;
331 assert(numObjs[obj_index] > 0);
332 numObjs[obj_index]--;
333 log_msg(mdd(reinterpret_cast<VkQueue>(queue->second->vkObj)), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, queue->second->objType,
334 queue->second->vkObj, __LINE__, OBJTRACK_NONE, "OBJTRACK",
335 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",
336 string_VkDebugReportObjectTypeEXT(queue->second->objType), queue->second->vkObj, numTotalObjs, numObjs[obj_index],
337 string_VkDebugReportObjectTypeEXT(queue->second->objType));
338 delete queue->second;
339 queue = VkQueueMap.erase(queue);
340 }
341}
342
343// Check Queue type flags for selected queue operations
344static void validateQueueFlags(VkQueue queue, const char *function) {
345
346 auto queue_item = queue_info_map.find(queue);
347 if (queue_item != queue_info_map.end()) {
348 OT_QUEUE_INFO *pQueueInfo = queue_item->second;
349 if (pQueueInfo != NULL) {
350 if ((queue_family_properties[pQueueInfo->queueNodeIndex].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) == 0) {
351 log_msg(mdd(queue), VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
352 reinterpret_cast<uint64_t>(queue), __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",
353 "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set", function);
354 }
355 }
356 }
357}
358
359static void create_physical_device(VkInstance instance, VkPhysicalDevice vkObj, VkDebugReportObjectTypeEXT objType) {
360 log_msg(mdd(instance), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700361 OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
362 string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj));
Tobin Ehlisec598302015-09-15 15:02:17 -0600363
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600364 uint64_t physical_device_handle = reinterpret_cast<uint64_t>(vkObj);
365 auto pd_item = VkPhysicalDeviceMap.find(physical_device_handle);
366 if (pd_item == VkPhysicalDeviceMap.end()) {
367 OBJTRACK_NODE *p_new_obj_node = new OBJTRACK_NODE;
368 p_new_obj_node->objType = objType;
369 p_new_obj_node->belongsTo = reinterpret_cast<uint64_t>(instance);
370 p_new_obj_node->status = OBJSTATUS_NONE;
371 p_new_obj_node->vkObj = physical_device_handle;
372 VkPhysicalDeviceMap[physical_device_handle] = p_new_obj_node;
373 uint32_t objIndex = objTypeToIndex(objType);
374 numObjs[objIndex]++;
375 numTotalObjs++;
376 }
Tobin Ehlisec598302015-09-15 15:02:17 -0600377}
378
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700379static void create_surface_khr(VkInstance dispatchable_object, VkSurfaceKHR vkObj, VkDebugReportObjectTypeEXT objType) {
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -0700380 // TODO: Add tracking of surface objects
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700381 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE,
382 "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
383 string_VkDebugReportObjectTypeEXT(objType), (uint64_t)(vkObj));
Tobin Ehlis86684f92016-01-05 10:33:58 -0700384
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700385 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
Tobin Ehlis86684f92016-01-05 10:33:58 -0700386 pNewObjNode->objType = objType;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700387 pNewObjNode->belongsTo = (uint64_t)dispatchable_object;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700388 pNewObjNode->status = OBJSTATUS_NONE;
389 pNewObjNode->vkObj = (uint64_t)(vkObj);
Tobin Ehlis86684f92016-01-05 10:33:58 -0700390 VkSurfaceKHRMap[(uint64_t)vkObj] = pNewObjNode;
391 uint32_t objIndex = objTypeToIndex(objType);
392 numObjs[objIndex]++;
393 numTotalObjs++;
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -0700394}
395
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700396static void destroy_surface_khr(VkInstance dispatchable_object, VkSurfaceKHR object) {
Mark Young93ecb1d2016-01-13 13:47:16 -0700397 uint64_t object_handle = (uint64_t)(object);
Tobin Ehlis86684f92016-01-05 10:33:58 -0700398 if (VkSurfaceKHRMap.find(object_handle) != VkSurfaceKHRMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700399 OBJTRACK_NODE *pNode = VkSurfaceKHRMap[(uint64_t)object];
Tobin Ehlis86684f92016-01-05 10:33:58 -0700400 uint32_t objIndex = objTypeToIndex(pNode->objType);
401 assert(numTotalObjs > 0);
402 numTotalObjs--;
403 assert(numObjs[objIndex] > 0);
404 numObjs[objIndex]--;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700405 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, object_handle, __LINE__,
406 OBJTRACK_NONE, "OBJTRACK",
Mark Muelleraab36502016-05-03 13:17:29 -0600407 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (0x%" PRIx64 " total objs remain & 0x%" PRIx64 " %s objs).",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700408 string_VkDebugReportObjectTypeEXT(pNode->objType), (uint64_t)(object), numTotalObjs, numObjs[objIndex],
409 string_VkDebugReportObjectTypeEXT(pNode->objType));
Tobin Ehlis86684f92016-01-05 10:33:58 -0700410 delete pNode;
411 VkSurfaceKHRMap.erase(object_handle);
412 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700413 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__,
414 OBJTRACK_NONE, "OBJTRACK",
415 "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle);
Tobin Ehlis86684f92016-01-05 10:33:58 -0700416 }
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -0700417}
418
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700419static void alloc_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer vkObj,
420 VkDebugReportObjectTypeEXT objType, VkCommandBufferLevel level) {
421 log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__, OBJTRACK_NONE,
422 "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
423 string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj));
Tony Barboura05dbaa2015-07-09 17:31:46 -0600424
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700425 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
426 pNewObjNode->objType = objType;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700427 pNewObjNode->belongsTo = (uint64_t)device;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700428 pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj);
429 pNewObjNode->parentObj = (uint64_t)commandPool;
Mark Lobodzinski2fba0322016-01-23 18:31:23 -0700430 if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
431 pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY;
432 } else {
433 pNewObjNode->status = OBJSTATUS_NONE;
434 }
Michael Lentine13803dc2015-11-04 14:35:12 -0800435 VkCommandBufferMap[reinterpret_cast<uint64_t>(vkObj)] = pNewObjNode;
Tony Barboura05dbaa2015-07-09 17:31:46 -0600436 uint32_t objIndex = objTypeToIndex(objType);
437 numObjs[objIndex]++;
438 numTotalObjs++;
439}
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700440
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600441static bool validate_command_buffer(VkDevice device, VkCommandPool commandPool, VkCommandBuffer commandBuffer) {
442 bool skipCall = false;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700443 uint64_t object_handle = reinterpret_cast<uint64_t>(commandBuffer);
444 if (VkCommandBufferMap.find(object_handle) != VkCommandBufferMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700445 OBJTRACK_NODE *pNode = VkCommandBufferMap[(uint64_t)commandBuffer];
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700446
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700447 if (pNode->parentObj != (uint64_t)(commandPool)) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600448 skipCall |= log_msg(
449 mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, object_handle, __LINE__, OBJTRACK_COMMAND_POOL_MISMATCH,
450 "OBJTRACK", "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64
451 " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600452 reinterpret_cast<uint64_t>(commandBuffer), pNode->parentObj, reinterpret_cast<uint64_t &>(commandPool));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700453 }
454 } else {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600455 skipCall |= log_msg(
456 mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__, OBJTRACK_NONE,
457 "OBJTRACK", "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700458 }
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600459 return skipCall;
460}
461
462static bool free_command_buffer(VkDevice device, VkCommandBuffer commandBuffer) {
463 bool skipCall = false;
464 auto cbItem = VkCommandBufferMap.find(reinterpret_cast<uint64_t>(commandBuffer));
465 if (cbItem != VkCommandBufferMap.end()) {
466 OBJTRACK_NODE *pNode = cbItem->second;
467 uint32_t objIndex = objTypeToIndex(pNode->objType);
468 assert(numTotalObjs > 0);
469 numTotalObjs--;
470 assert(numObjs[objIndex] > 0);
471 numObjs[objIndex]--;
472 skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType,
473 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, OBJTRACK_NONE, "OBJTRACK",
474 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",
475 string_VkDebugReportObjectTypeEXT(pNode->objType), reinterpret_cast<uint64_t>(commandBuffer),
476 numTotalObjs, numObjs[objIndex], string_VkDebugReportObjectTypeEXT(pNode->objType));
477 delete pNode;
478 VkCommandBufferMap.erase(cbItem);
479 }
480 return skipCall;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700481}
482
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700483static void alloc_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet vkObj,
484 VkDebugReportObjectTypeEXT objType) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700485 log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, "OBJTRACK",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700486 "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, string_VkDebugReportObjectTypeEXT(objType),
487 (uint64_t)(vkObj));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700488
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700489 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
490 pNewObjNode->objType = objType;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700491 pNewObjNode->belongsTo = (uint64_t)device;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700492 pNewObjNode->status = OBJSTATUS_NONE;
493 pNewObjNode->vkObj = (uint64_t)(vkObj);
494 pNewObjNode->parentObj = (uint64_t)descriptorPool;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700495 VkDescriptorSetMap[(uint64_t)vkObj] = pNewObjNode;
496 uint32_t objIndex = objTypeToIndex(objType);
497 numObjs[objIndex]++;
498 numTotalObjs++;
499}
500
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600501static bool validate_descriptor_set(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet descriptorSet) {
502 bool skipCall = false;
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600503 uint64_t object_handle = reinterpret_cast<uint64_t &>(descriptorSet);
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600504 auto dsItem = VkDescriptorSetMap.find(object_handle);
505 if (dsItem != VkDescriptorSetMap.end()) {
506 OBJTRACK_NODE *pNode = dsItem->second;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700507
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600508 if (pNode->parentObj != reinterpret_cast<uint64_t &>(descriptorPool)) {
509 skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, object_handle, __LINE__,
510 OBJTRACK_DESCRIPTOR_POOL_MISMATCH, "OBJTRACK",
511 "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64
512 " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
513 reinterpret_cast<uint64_t &>(descriptorSet), pNode->parentObj,
514 reinterpret_cast<uint64_t &>(descriptorPool));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700515 }
516 } else {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600517 skipCall |= log_msg(
518 mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__, OBJTRACK_NONE,
519 "OBJTRACK", "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?", object_handle);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700520 }
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600521 return skipCall;
522}
523
524static bool free_descriptor_set(VkDevice device, VkDescriptorSet descriptorSet) {
525 bool skipCall = false;
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600526 auto dsItem = VkDescriptorSetMap.find(reinterpret_cast<uint64_t &>(descriptorSet));
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600527 if (dsItem != VkDescriptorSetMap.end()) {
528 OBJTRACK_NODE *pNode = dsItem->second;
529 uint32_t objIndex = objTypeToIndex(pNode->objType);
530 assert(numTotalObjs > 0);
531 numTotalObjs--;
532 assert(numObjs[objIndex] > 0);
533 numObjs[objIndex]--;
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600534 skipCall |= log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType,
535 reinterpret_cast<uint64_t &>(descriptorSet), __LINE__, OBJTRACK_NONE, "OBJTRACK",
536 "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",
537 string_VkDebugReportObjectTypeEXT(pNode->objType), reinterpret_cast<uint64_t &>(descriptorSet),
538 numTotalObjs, numObjs[objIndex], string_VkDebugReportObjectTypeEXT(pNode->objType));
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600539 delete pNode;
540 VkDescriptorSetMap.erase(dsItem);
541 }
542 return skipCall;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700543}
544
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600545static void create_queue(VkDevice device, VkQueue vkObj, VkDebugReportObjectTypeEXT objType) {
546
547 log_msg(mdd(device), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, reinterpret_cast<uint64_t>(vkObj), __LINE__,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700548 OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
549 string_VkDebugReportObjectTypeEXT(objType), reinterpret_cast<uint64_t>(vkObj));
Tobin Ehlisec598302015-09-15 15:02:17 -0600550
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600551 OBJTRACK_NODE *p_obj_node = NULL;
552 auto queue_item = VkQueueMap.find(reinterpret_cast<uint64_t>(vkObj));
553 if (queue_item == VkQueueMap.end()) {
554 p_obj_node = new OBJTRACK_NODE;
555 VkQueueMap[reinterpret_cast<uint64_t>(vkObj)] = p_obj_node;
556 uint32_t objIndex = objTypeToIndex(objType);
557 numObjs[objIndex]++;
558 numTotalObjs++;
559 } else {
560 p_obj_node = queue_item->second;
561 }
562 p_obj_node->objType = objType;
563 p_obj_node->belongsTo = reinterpret_cast<uint64_t>(device);
564 p_obj_node->status = OBJSTATUS_NONE;
565 p_obj_node->vkObj = reinterpret_cast<uint64_t>(vkObj);
Tobin Ehlisec598302015-09-15 15:02:17 -0600566}
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600567
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700568static void create_swapchain_image_obj(VkDevice dispatchable_object, VkImage vkObj, VkSwapchainKHR swapchain) {
569 log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)vkObj,
570 __LINE__, OBJTRACK_NONE, "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
571 "SwapchainImage", (uint64_t)(vkObj));
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600572
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700573 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
574 pNewObjNode->belongsTo = (uint64_t)dispatchable_object;
575 pNewObjNode->objType = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT;
576 pNewObjNode->status = OBJSTATUS_NONE;
577 pNewObjNode->vkObj = (uint64_t)vkObj;
578 pNewObjNode->parentObj = (uint64_t)swapchain;
Mark Young93ecb1d2016-01-13 13:47:16 -0700579 swapchainImageMap[(uint64_t)(vkObj)] = pNewObjNode;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600580}
581
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700582static void create_device(VkInstance dispatchable_object, VkDevice vkObj, VkDebugReportObjectTypeEXT objType) {
583 log_msg(mid(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType, (uint64_t)(vkObj), __LINE__, OBJTRACK_NONE,
584 "OBJTRACK", "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
585 string_VkDebugReportObjectTypeEXT(objType), (uint64_t)(vkObj));
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700586
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700587 OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700588 pNewObjNode->belongsTo = (uint64_t)dispatchable_object;
589 pNewObjNode->objType = objType;
590 pNewObjNode->status = OBJSTATUS_NONE;
591 pNewObjNode->vkObj = (uint64_t)(vkObj);
592 VkDeviceMap[(uint64_t)vkObj] = pNewObjNode;
593 uint32_t objIndex = objTypeToIndex(objType);
594 numObjs[objIndex]++;
595 numTotalObjs++;
596}
597
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600598//
599// Non-auto-generated API functions called by generated code
600//
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700601VkResult explicit_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
602 VkInstance *pInstance) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700603 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
David Pinedoc0fa1ab2015-07-31 10:46:25 -0600604
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700605 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700606 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700607 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700608 if (fpCreateInstance == NULL) {
609 return VK_ERROR_INITIALIZATION_FAILED;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600610 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700611
612 // Advance the link info for the next element on the chain
613 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
614
615 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
616 if (result != VK_SUCCESS) {
617 return result;
618 }
619
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700620 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Chia-I Wu1ad50f42016-05-17 07:57:15 +0800621 my_data->instance = *pInstance;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700622 initInstanceTable(*pInstance, fpGetInstanceProcAddr, object_tracker_instance_table_map);
623 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, *pInstance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700624
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600625 // Look for one or more debug report create info structures, and copy the
626 // callback(s) for each one found (for use by vkDestroyInstance)
627 layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos,
628 &my_data->tmp_callbacks);
629
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700630 my_data->report_data = debug_report_create_instance(pInstanceTable, *pInstance, pCreateInfo->enabledExtensionCount,
631 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700632
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600633 init_object_tracker(my_data, pAllocator);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700634 createInstanceRegisterExtensions(pCreateInfo, *pInstance);
635
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700636 create_instance(*pInstance, *pInstance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700637
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600638 return result;
639}
640
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700641void explicit_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice gpu, uint32_t *pCount, VkQueueFamilyProperties *pProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700642 get_dispatch_table(object_tracker_instance_table_map, gpu)->GetPhysicalDeviceQueueFamilyProperties(gpu, pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600643
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600644 std::lock_guard<std::mutex> lock(global_lock);
645 if (pProperties != NULL) {
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600646 for (uint32_t i = 0; i < *pCount; i++) {
647 queue_family_properties.emplace_back(pProperties[i]);
648 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600649 }
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600650}
651
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700652VkResult explicit_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
653 VkDevice *pDevice) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600654 std::lock_guard<std::mutex> lock(global_lock);
Chia-I Wu1ad50f42016-05-17 07:57:15 +0800655 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700656 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700657
658 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700659 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
660 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
Chia-I Wu1ad50f42016-05-17 07:57:15 +0800661 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700662 if (fpCreateDevice == NULL) {
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700663 return VK_ERROR_INITIALIZATION_FAILED;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600664 }
665
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700666 // Advance the link info for the next element on the chain
667 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
668
669 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
670 if (result != VK_SUCCESS) {
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700671 return result;
672 }
673
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700674 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
675 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700676
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700677 initDeviceTable(*pDevice, fpGetDeviceProcAddr, object_tracker_device_table_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700678
679 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
680
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700681 if (VkPhysicalDeviceMap.find((uint64_t)gpu) != VkPhysicalDeviceMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700682 OBJTRACK_NODE *pNewObjNode = VkPhysicalDeviceMap[(uint64_t)gpu];
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700683 create_device((VkInstance)pNewObjNode->belongsTo, *pDevice, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT);
684 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700685
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600686 return result;
687}
688
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700689VkResult explicit_EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
690 VkPhysicalDevice *pPhysicalDevices) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600691 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600692 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700693 skipCall |= validate_instance(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600694 lock.unlock();
Tobin Ehlisec598302015-09-15 15:02:17 -0600695 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700696 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700697 VkResult result = get_dispatch_table(object_tracker_instance_table_map, instance)
698 ->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600699 lock.lock();
Tobin Ehlisec598302015-09-15 15:02:17 -0600700 if (result == VK_SUCCESS) {
701 if (pPhysicalDevices) {
702 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700703 create_physical_device(instance, pPhysicalDevices[i], VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT);
Tobin Ehlisec598302015-09-15 15:02:17 -0600704 }
705 }
706 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600707 lock.unlock();
Tobin Ehlisec598302015-09-15 15:02:17 -0600708 return result;
709}
710
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700711void explicit_GetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue *pQueue) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600712 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700713 validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600714 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600715
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700716 get_dispatch_table(object_tracker_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600717
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600718 lock.lock();
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600719
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700720 create_queue(device, *pQueue, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT);
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600721 addQueueInfo(queueNodeIndex, *pQueue);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600722}
723
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700724VkResult explicit_MapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkFlags flags,
725 void **ppData) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600726 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600727 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700728 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600729 lock.unlock();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600730 if (skipCall == VK_TRUE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700731 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600732
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700733 VkResult result =
734 get_dispatch_table(object_tracker_device_table_map, device)->MapMemory(device, mem, offset, size, flags, ppData);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600735
736 return result;
737}
738
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700739void explicit_UnmapMemory(VkDevice device, VkDeviceMemory mem) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600740 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600741 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700742 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600743 lock.unlock();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600744 if (skipCall == VK_TRUE)
745 return;
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600746
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700747 get_dispatch_table(object_tracker_device_table_map, device)->UnmapMemory(device, mem);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600748}
749
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700750VkResult explicit_QueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, VkFence fence) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600751 std::unique_lock<std::mutex> lock(global_lock);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800752 validateQueueFlags(queue, "QueueBindSparse");
753
754 for (uint32_t i = 0; i < bindInfoCount; i++) {
755 for (uint32_t j = 0; j < pBindInfo[i].bufferBindCount; j++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700756 validate_buffer(queue, pBindInfo[i].pBufferBinds[j].buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, false);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800757 for (uint32_t j = 0; j < pBindInfo[i].imageOpaqueBindCount; j++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700758 validate_image(queue, pBindInfo[i].pImageOpaqueBinds[j].image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800759 for (uint32_t j = 0; j < pBindInfo[i].imageBindCount; j++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700760 validate_image(queue, pBindInfo[i].pImageBinds[j].image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false);
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +0800761 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600762 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600763
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700764 VkResult result =
765 get_dispatch_table(object_tracker_device_table_map, queue)->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -0600766 return result;
767}
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600768
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700769VkResult explicit_AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
770 VkCommandBuffer *pCommandBuffers) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600771 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600772 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700773 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
774 skipCall |= validate_command_pool(device, pAllocateInfo->commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600775 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700776
777 if (skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700778 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700779 }
780
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700781 VkResult result =
782 get_dispatch_table(object_tracker_device_table_map, device)->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700783
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600784 lock.lock();
Jon Ashburnf19916e2016-01-11 13:12:43 -0700785 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700786 alloc_command_buffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
787 pAllocateInfo->level);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700788 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600789 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700790
791 return result;
792}
793
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700794VkResult explicit_AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
795 VkDescriptorSet *pDescriptorSets) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600796 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600797 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700798 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700799 skipCall |=
800 validate_descriptor_pool(device, pAllocateInfo->descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false);
Jon Ashburnf19916e2016-01-11 13:12:43 -0700801 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700802 skipCall |= validate_descriptor_set_layout(device, pAllocateInfo->pSetLayouts[i],
803 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, false);
Tobin Ehlisec598302015-09-15 15:02:17 -0600804 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600805 lock.unlock();
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600806 if (skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700807 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600808 }
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600809
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700810 VkResult result =
811 get_dispatch_table(object_tracker_device_table_map, device)->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600812
Chris Forbes539a87c2016-01-22 15:44:40 +1300813 if (VK_SUCCESS == result) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600814 lock.lock();
Chris Forbes539a87c2016-01-22 15:44:40 +1300815 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700816 alloc_descriptor_set(device, pAllocateInfo->descriptorPool, pDescriptorSets[i],
817 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT);
Chris Forbes539a87c2016-01-22 15:44:40 +1300818 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600819 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600820 }
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600821
822 return result;
823}
824
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700825void explicit_FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
826 const VkCommandBuffer *pCommandBuffers) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600827 bool skipCall = false;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600828 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700829 validate_command_pool(device, commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false);
830 validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600831 for (uint32_t i = 0; i < commandBufferCount; i++) {
832 skipCall |= validate_command_buffer(device, commandPool, pCommandBuffers[i]);
833 }
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700834
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600835 lock.unlock();
836 if (!skipCall) {
837 get_dispatch_table(object_tracker_device_table_map, device)
838 ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
839 }
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700840
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600841 lock.lock();
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700842 for (uint32_t i = 0; i < commandBufferCount; i++) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600843 free_command_buffer(device, pCommandBuffers[i]);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700844 }
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700845}
846
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700847void explicit_DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600848 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700849 // A swapchain's images are implicitly deleted when the swapchain is deleted.
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600850 // Remove this swapchain's images from our map of such images.
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600851 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = swapchainImageMap.begin();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600852 while (itr != swapchainImageMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700853 OBJTRACK_NODE *pNode = (*itr).second;
Mark Lobodzinski7f537292016-05-12 15:14:07 -0600854 if (pNode->parentObj == reinterpret_cast<uint64_t &>(swapchain)) {
855 delete pNode;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700856 swapchainImageMap.erase(itr++);
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600857 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700858 ++itr;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600859 }
860 }
Tobin Ehlis86684f92016-01-05 10:33:58 -0700861 destroy_swapchain_khr(device, swapchain);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600862 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600863
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700864 get_dispatch_table(object_tracker_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600865}
866
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700867void explicit_FreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600868 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700869 validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600870 lock.unlock();
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600871
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700872 get_dispatch_table(object_tracker_device_table_map, device)->FreeMemory(device, mem, pAllocator);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600873
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600874 lock.lock();
Michael Lentine13803dc2015-11-04 14:35:12 -0800875 destroy_device_memory(device, mem);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600876}
Tony Barboura05dbaa2015-07-09 17:31:46 -0600877
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700878VkResult explicit_FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
879 const VkDescriptorSet *pDescriptorSets) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600880 bool skipCall = false;
881 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600882 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600883 skipCall |= validate_descriptor_pool(device, descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false);
884 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
885 for (uint32_t i = 0; i < count; i++) {
886 skipCall |= validate_descriptor_set(device, descriptorPool, pDescriptorSets[i]);
887 }
888
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600889 lock.unlock();
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600890 if (!skipCall) {
891 result = get_dispatch_table(object_tracker_device_table_map, device)
892 ->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
893 }
Tony Barbour770f80d2015-07-20 10:52:13 -0600894
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600895 lock.lock();
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700896 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600897 free_descriptor_set(device, pDescriptorSets[i]);
Tony Barbour770f80d2015-07-20 10:52:13 -0600898 }
Tony Barbour770f80d2015-07-20 10:52:13 -0600899 return result;
900}
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600901
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700902void explicit_DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600903 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600904 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700905 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
906 skipCall |= validate_descriptor_pool(device, descriptorPool, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600907 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700908 if (skipCall) {
909 return;
910 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700911 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is deleted.
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700912 // Remove this pool's descriptor sets from our descriptorSet map.
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600913 lock.lock();
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600914 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = VkDescriptorSetMap.begin();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700915 while (itr != VkDescriptorSetMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700916 OBJTRACK_NODE *pNode = (*itr).second;
Mark Lobodzinskib29731a2015-11-18 11:01:02 -0700917 auto del_itr = itr++;
Mark Young93ecb1d2016-01-13 13:47:16 -0700918 if (pNode->parentObj == (uint64_t)(descriptorPool)) {
919 destroy_descriptor_set(device, (VkDescriptorSet)((*del_itr).first));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700920 }
921 }
922 destroy_descriptor_pool(device, descriptorPool);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600923 lock.unlock();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700924 get_dispatch_table(object_tracker_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700925}
926
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700927void explicit_DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600928 bool skipCall = false;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600929 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700930 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
931 skipCall |= validate_command_pool(device, commandPool, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600932 lock.unlock();
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700933 if (skipCall) {
934 return;
935 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600936 lock.lock();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700937 // A CommandPool's command buffers are implicitly deleted when the pool is deleted.
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700938 // Remove this pool's cmdBuffers from our cmd buffer map.
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600939 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator itr = VkCommandBufferMap.begin();
940 std::unordered_map<uint64_t, OBJTRACK_NODE *>::iterator del_itr;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700941 while (itr != VkCommandBufferMap.end()) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700942 OBJTRACK_NODE *pNode = (*itr).second;
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700943 del_itr = itr++;
Mark Young93ecb1d2016-01-13 13:47:16 -0700944 if (pNode->parentObj == (uint64_t)(commandPool)) {
Mark Lobodzinski772cd3d2016-05-03 08:39:24 -0600945 skipCall |= validate_command_buffer(device, commandPool, reinterpret_cast<VkCommandBuffer>((*del_itr).first));
946 free_command_buffer(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first));
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700947 }
948 }
949 destroy_command_pool(device, commandPool);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600950 lock.unlock();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700951 get_dispatch_table(object_tracker_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator);
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700952}
953
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700954VkResult explicit_GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pCount, VkImage *pSwapchainImages) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600955 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600956 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700957 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600958 lock.unlock();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600959 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700960 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600961
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700962 VkResult result = get_dispatch_table(object_tracker_device_table_map, device)
963 ->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600964
965 if (pSwapchainImages != NULL) {
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600966 lock.lock();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600967 for (uint32_t i = 0; i < *pCount; i++) {
968 create_swapchain_image_obj(device, pSwapchainImages[i], swapchain);
969 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600970 lock.unlock();
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -0600971 }
972 return result;
973}
974
Jon Ashburnbd846452016-06-30 10:21:55 -0600975#ifndef __ANDROID__
Jon Ashburn665d1d52016-06-28 16:59:36 -0600976VkResult explicit_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPropertiesKHR* pProperties)
Jon Ashburn5e026df2016-06-15 08:19:07 -0600977{
978 bool skipCall = false;
979 {
980 std::lock_guard<std::mutex> lock(global_lock);
Jon Ashburn665d1d52016-06-28 16:59:36 -0600981 if (physicalDevice) {
982 skipCall |= validate_physical_device(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false);
983 }
Jon Ashburn5e026df2016-06-15 08:19:07 -0600984 }
985 if (skipCall)
986 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn665d1d52016-06-28 16:59:36 -0600987 VkResult result = get_dispatch_table(object_tracker_instance_table_map, physicalDevice)->GetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties);
988 if (VK_SUCCESS == result && pProperties) {
989 std::lock_guard<std::mutex> lock(global_lock);
990 for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) {
991 if (pProperties[idx0].display) {
992 create_display_khr(physicalDevice, pProperties[idx0].display, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT);
993 }
994 }
995 }
996 return result;
997}
998
999VkResult explicit_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties)
1000{
1001 bool skipCall = false;
Jon Ashburn5e026df2016-06-15 08:19:07 -06001002 {
1003 std::lock_guard<std::mutex> lock(global_lock);
Jon Ashburn665d1d52016-06-28 16:59:36 -06001004 skipCall |= validate_display_khr(physicalDevice, display, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, false);
1005 if (physicalDevice) {
1006 skipCall |= validate_physical_device(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false);
1007 }
1008 }
1009 if (skipCall)
1010 return VK_ERROR_VALIDATION_FAILED_EXT;
1011 VkResult result = get_dispatch_table(object_tracker_instance_table_map, physicalDevice)->GetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties);
1012 if (VK_SUCCESS == result && pProperties) {
1013 std::lock_guard<std::mutex> lock(global_lock);
1014 for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) {
1015 if (pProperties[idx0].displayMode) {
1016 create_display_mode_khr(physicalDevice, pProperties[idx0].displayMode, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT);
Jon Ashburn5e026df2016-06-15 08:19:07 -06001017 }
1018 }
1019 }
1020 return result;
1021}
Jon Ashburnbd846452016-06-30 10:21:55 -06001022#endif
Jon Ashburn5e026df2016-06-15 08:19:07 -06001023
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001024// TODO: Add special case to codegen to cover validating all the pipelines instead of just the first
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001025VkResult explicit_CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1026 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1027 VkPipeline *pPipelines) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001028 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001029 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001030 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001031 if (pCreateInfos) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001032 for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001033 if (pCreateInfos[idx0].basePipelineHandle) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001034 skipCall |= validate_pipeline(device, pCreateInfos[idx0].basePipelineHandle,
1035 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, true);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001036 }
1037 if (pCreateInfos[idx0].layout) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001038 skipCall |= validate_pipeline_layout(device, pCreateInfos[idx0].layout,
1039 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001040 }
1041 if (pCreateInfos[idx0].pStages) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001042 for (uint32_t idx1 = 0; idx1 < pCreateInfos[idx0].stageCount; ++idx1) {
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001043 if (pCreateInfos[idx0].pStages[idx1].module) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001044 skipCall |= validate_shader_module(device, pCreateInfos[idx0].pStages[idx1].module,
1045 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001046 }
1047 }
1048 }
1049 if (pCreateInfos[idx0].renderPass) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001050 skipCall |=
1051 validate_render_pass(device, pCreateInfos[idx0].renderPass, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001052 }
1053 }
1054 }
1055 if (pipelineCache) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001056 skipCall |= validate_pipeline_cache(device, pipelineCache, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001057 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001058 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001059 if (skipCall)
1060 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001061 VkResult result = get_dispatch_table(object_tracker_device_table_map, device)
1062 ->CreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001063 lock.lock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001064 if (result == VK_SUCCESS) {
1065 for (uint32_t idx2 = 0; idx2 < createInfoCount; ++idx2) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001066 create_pipeline(device, pPipelines[idx2], VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001067 }
1068 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001069 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001070 return result;
1071}
1072
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001073// TODO: Add special case to codegen to cover validating all the pipelines instead of just the first
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001074VkResult explicit_CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1075 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1076 VkPipeline *pPipelines) {
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001077 bool skipCall = VK_FALSE;
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001078 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001079 skipCall |= validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001080 if (pCreateInfos) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001081 for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001082 if (pCreateInfos[idx0].basePipelineHandle) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001083 skipCall |= validate_pipeline(device, pCreateInfos[idx0].basePipelineHandle,
1084 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, true);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001085 }
1086 if (pCreateInfos[idx0].layout) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001087 skipCall |= validate_pipeline_layout(device, pCreateInfos[idx0].layout,
1088 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001089 }
1090 if (pCreateInfos[idx0].stage.module) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001091 skipCall |= validate_shader_module(device, pCreateInfos[idx0].stage.module,
1092 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001093 }
1094 }
1095 }
1096 if (pipelineCache) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001097 skipCall |= validate_pipeline_cache(device, pipelineCache, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, false);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001098 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001099 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001100 if (skipCall)
1101 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -07001102 VkResult result = get_dispatch_table(object_tracker_device_table_map, device)
1103 ->CreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001104 lock.lock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001105 if (result == VK_SUCCESS) {
1106 for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001107 create_pipeline(device, pPipelines[idx1], VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001108 }
1109 }
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001110 lock.unlock();
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001111 return result;
1112}
Chia-I Wucdb70962016-05-13 14:07:36 +08001113
1114} // namespace object_tracker