blob: 957f347e0cccd7d8c26455ac609a7e0e60ac0d78 [file] [log] [blame]
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
4 * Copyright (C) 2015-2017 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@lunarg.com>
19 * Author: Jon Ashburn <jon@lunarg.com>
20 * Author: Tobin Ehlis <tobin@lunarg.com>
21 */
22
23#include "object_tracker.h"
24
25namespace object_tracker {
26
27std::unordered_map<void *, layer_data *> layer_data_map;
28device_table_map ot_device_table_map;
29instance_table_map ot_instance_table_map;
30std::mutex global_lock;
31uint64_t object_track_index = 0;
32uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
33
34void InitObjectTracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
35 layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_object_tracker");
36}
37
38// Add new queue to head of global queue list
39void AddQueueInfo(VkDevice device, uint32_t queue_node_index, VkQueue queue) {
40 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
41 auto queueItem = device_data->queue_info_map.find(queue);
42 if (queueItem == device_data->queue_info_map.end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -060043 ObjTrackQueueInfo *p_queue_info = new ObjTrackQueueInfo;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060044 if (p_queue_info != NULL) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -060045 memset(p_queue_info, 0, sizeof(ObjTrackQueueInfo));
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060046 p_queue_info->queue = queue;
47 p_queue_info->queue_node_index = queue_node_index;
48 device_data->queue_info_map[queue] = p_queue_info;
49 } else {
50 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
51 HandleToUint64(queue), __LINE__, OBJTRACK_INTERNAL_ERROR, LayerName,
52 "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");
53 }
54 }
55}
56
57// Destroy memRef lists and free all memory
58void DestroyQueueDataStructures(VkDevice device) {
59 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
60
61 for (auto queue_item : device_data->queue_info_map) {
62 delete queue_item.second;
63 }
64 device_data->queue_info_map.clear();
65
66 // Destroy the items in the queue map
67 auto queue = device_data->object_map[kVulkanObjectTypeQueue].begin();
68 while (queue != device_data->object_map[kVulkanObjectTypeQueue].end()) {
69 uint32_t obj_index = queue->second->object_type;
70 assert(device_data->num_total_objects > 0);
71 device_data->num_total_objects--;
72 assert(device_data->num_objects[obj_index] > 0);
73 device_data->num_objects[obj_index]--;
74 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
75 queue->second->handle, __LINE__, OBJTRACK_NONE, LayerName,
76 "OBJ_STAT Destroy Queue obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " Queue objs).",
77 queue->second->handle, device_data->num_total_objects, device_data->num_objects[obj_index]);
78 delete queue->second;
79 queue = device_data->object_map[kVulkanObjectTypeQueue].erase(queue);
80 }
81}
82
83// Check Queue type flags for selected queue operations
84void ValidateQueueFlags(VkQueue queue, const char *function) {
85 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
86 auto queue_item = device_data->queue_info_map.find(queue);
87 if (queue_item != device_data->queue_info_map.end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -060088 ObjTrackQueueInfo *pQueueInfo = queue_item->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060089 if (pQueueInfo != NULL) {
90 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(device_data->physical_device), layer_data_map);
91 if ((instance_data->queue_family_properties[pQueueInfo->queue_node_index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) ==
92 0) {
93 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
94 HandleToUint64(queue), __LINE__, VALIDATION_ERROR_31600011, LayerName,
95 "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set. %s",
96 function, validation_error_map[VALIDATION_ERROR_31600011]);
97 }
98 }
99 }
100}
101
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700102// Look for this device object in any of the instance child devices lists.
103// NOTE: This is of dubious value. In most circumstances Vulkan will die a flaming death if a dispatchable object is invalid.
104// However, if this layer is loaded first and GetProcAddress is used to make API calls, it will detect bad DOs.
105bool ValidateDeviceObject(uint64_t device_handle, enum UNIQUE_VALIDATION_ERROR_CODE invalid_handle_code,
106 enum UNIQUE_VALIDATION_ERROR_CODE wrong_device_code) {
107 VkInstance last_instance = nullptr;
108 for (auto layer_data : layer_data_map) {
109 for (auto object : layer_data.second->object_map[kVulkanObjectTypeDevice]) {
110 // Grab last instance to use for possible error message
111 last_instance = layer_data.second->instance;
112 if (object.second->handle == device_handle) return false;
113 }
114 }
115
116 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(last_instance), layer_data_map);
117 return log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device_handle,
118 __LINE__, invalid_handle_code, LayerName, "Invalid Device Object 0x%" PRIxLEAST64 ". %s", device_handle,
119 validation_error_map[invalid_handle_code]);
120}
121
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600122void AllocateCommandBuffer(VkDevice device, const VkCommandPool command_pool, const VkCommandBuffer command_buffer,
123 VkCommandBufferLevel level) {
124 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
125
126 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
127 HandleToUint64(command_buffer), __LINE__, OBJTRACK_NONE, LayerName,
128 "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
129 "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT", HandleToUint64(command_buffer));
130
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600131 ObjTrackState *pNewObjNode = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600132 pNewObjNode->object_type = kVulkanObjectTypeCommandBuffer;
133 pNewObjNode->handle = HandleToUint64(command_buffer);
134 pNewObjNode->parent_object = HandleToUint64(command_pool);
135 if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
136 pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY;
137 } else {
138 pNewObjNode->status = OBJSTATUS_NONE;
139 }
140 device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)] = pNewObjNode;
141 device_data->num_objects[kVulkanObjectTypeCommandBuffer]++;
142 device_data->num_total_objects++;
143}
144
145bool ValidateCommandBuffer(VkDevice device, VkCommandPool command_pool, VkCommandBuffer command_buffer) {
146 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
147 bool skip = false;
148 uint64_t object_handle = HandleToUint64(command_buffer);
149 if (device_data->object_map[kVulkanObjectTypeCommandBuffer].find(object_handle) !=
150 device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600151 ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)];
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600152
153 if (pNode->parent_object != HandleToUint64(command_pool)) {
154 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
155 object_handle, __LINE__, VALIDATION_ERROR_28411407, LayerName,
156 "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64
157 " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 "). %s",
158 HandleToUint64(command_buffer), pNode->parent_object, HandleToUint64(command_pool),
159 validation_error_map[VALIDATION_ERROR_28411407]);
160 }
161 } else {
162 skip |=
163 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
164 object_handle, __LINE__, VALIDATION_ERROR_28400060, LayerName, "Invalid %s Object 0x%" PRIxLEAST64 ". %s",
165 object_string[kVulkanObjectTypeCommandBuffer], object_handle, validation_error_map[VALIDATION_ERROR_28400060]);
166 }
167 return skip;
168}
169
170void AllocateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
171 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
172
173 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
174 HandleToUint64(descriptor_set), __LINE__, OBJTRACK_NONE, LayerName,
175 "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
176 "VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT", HandleToUint64(descriptor_set));
177
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600178 ObjTrackState *pNewObjNode = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600179 pNewObjNode->object_type = kVulkanObjectTypeDescriptorSet;
180 pNewObjNode->status = OBJSTATUS_NONE;
181 pNewObjNode->handle = HandleToUint64(descriptor_set);
182 pNewObjNode->parent_object = HandleToUint64(descriptor_pool);
183 device_data->object_map[kVulkanObjectTypeDescriptorSet][HandleToUint64(descriptor_set)] = pNewObjNode;
184 device_data->num_objects[kVulkanObjectTypeDescriptorSet]++;
185 device_data->num_total_objects++;
186}
187
188bool ValidateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
189 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
190 bool skip = false;
191 uint64_t object_handle = HandleToUint64(descriptor_set);
192 auto dsItem = device_data->object_map[kVulkanObjectTypeDescriptorSet].find(object_handle);
193 if (dsItem != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600194 ObjTrackState *pNode = dsItem->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600195
196 if (pNode->parent_object != HandleToUint64(descriptor_pool)) {
197 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
198 object_handle, __LINE__, VALIDATION_ERROR_28613007, LayerName,
199 "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64
200 " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 "). %s",
201 HandleToUint64(descriptor_set), pNode->parent_object, HandleToUint64(descriptor_pool),
202 validation_error_map[VALIDATION_ERROR_28613007]);
203 }
204 } else {
205 skip |=
206 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
207 object_handle, __LINE__, VALIDATION_ERROR_2860026c, LayerName, "Invalid %s Object 0x%" PRIxLEAST64 ". %s",
208 object_string[kVulkanObjectTypeDescriptorSet], object_handle, validation_error_map[VALIDATION_ERROR_2860026c]);
209 }
210 return skip;
211}
212
Dave Houltona9df0ce2018-02-07 10:51:23 -0700213template <typename DispObj>
Chris Forbes2c600e92017-10-20 11:13:20 -0700214static bool ValidateDescriptorWrite(DispObj disp, VkWriteDescriptorSet const *desc, bool isPush) {
215 bool skip = false;
216
217 if (!isPush && desc->dstSet) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700218 skip |= ValidateObject(disp, desc->dstSet, kVulkanObjectTypeDescriptorSet, false, VALIDATION_ERROR_15c00280,
219 VALIDATION_ERROR_15c00009);
Chris Forbes2c600e92017-10-20 11:13:20 -0700220 }
221
222 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
223 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
224 for (uint32_t idx2 = 0; idx2 < desc->descriptorCount; ++idx2) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700225 skip |= ValidateObject(disp, desc->pTexelBufferView[idx2], kVulkanObjectTypeBufferView, false,
226 VALIDATION_ERROR_15c00286, VALIDATION_ERROR_15c00009);
Chris Forbes2c600e92017-10-20 11:13:20 -0700227 }
228 }
229
230 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
Dave Houltona9df0ce2018-02-07 10:51:23 -0700231 (desc->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
Chris Forbes2c600e92017-10-20 11:13:20 -0700232 (desc->descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
233 for (uint32_t idx3 = 0; idx3 < desc->descriptorCount; ++idx3) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700234 skip |= ValidateObject(disp, desc->pImageInfo[idx3].imageView, kVulkanObjectTypeImageView, false,
235 VALIDATION_ERROR_15c0028c, VALIDATION_ERROR_04600009);
Chris Forbes2c600e92017-10-20 11:13:20 -0700236 }
237 }
238
239 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
240 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
241 (desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
242 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
243 for (uint32_t idx4 = 0; idx4 < desc->descriptorCount; ++idx4) {
244 if (desc->pBufferInfo[idx4].buffer) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700245 skip |= ValidateObject(disp, desc->pBufferInfo[idx4].buffer, kVulkanObjectTypeBuffer, false,
246 VALIDATION_ERROR_04401a01, VALIDATION_ERROR_UNDEFINED);
Chris Forbes2c600e92017-10-20 11:13:20 -0700247 }
248 }
249 }
250
251 return skip;
252}
253
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600254VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
255 VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount,
256 const VkWriteDescriptorSet *pDescriptorWrites) {
257 bool skip = false;
258 {
259 std::lock_guard<std::mutex> lock(global_lock);
260 skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_1be02401,
261 VALIDATION_ERROR_1be00009);
262 skip |= ValidateObject(commandBuffer, layout, kVulkanObjectTypePipelineLayout, false, VALIDATION_ERROR_1be0be01,
263 VALIDATION_ERROR_1be00009);
264 if (pDescriptorWrites) {
265 for (uint32_t index0 = 0; index0 < descriptorWriteCount; ++index0) {
Chris Forbesa94b60b2017-10-20 11:28:02 -0700266 skip |= ValidateDescriptorWrite(commandBuffer, &pDescriptorWrites[index0], true);
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600267 }
268 }
269 }
270 if (skip) return;
271 get_dispatch_table(ot_device_table_map, commandBuffer)
272 ->CmdPushDescriptorSetKHR(commandBuffer, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites);
273}
274
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600275void CreateQueue(VkDevice device, VkQueue vkObj) {
276 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
277
278 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
279 HandleToUint64(vkObj), __LINE__, OBJTRACK_NONE, LayerName, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
280 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT", HandleToUint64(vkObj));
281
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600282 ObjTrackState *p_obj_node = NULL;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600283 auto queue_item = device_data->object_map[kVulkanObjectTypeQueue].find(HandleToUint64(vkObj));
284 if (queue_item == device_data->object_map[kVulkanObjectTypeQueue].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600285 p_obj_node = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600286 device_data->object_map[kVulkanObjectTypeQueue][HandleToUint64(vkObj)] = p_obj_node;
287 device_data->num_objects[kVulkanObjectTypeQueue]++;
288 device_data->num_total_objects++;
289 } else {
290 p_obj_node = queue_item->second;
291 }
292 p_obj_node->object_type = kVulkanObjectTypeQueue;
293 p_obj_node->status = OBJSTATUS_NONE;
294 p_obj_node->handle = HandleToUint64(vkObj);
295}
296
297void CreateSwapchainImageObject(VkDevice dispatchable_object, VkImage swapchain_image, VkSwapchainKHR swapchain) {
298 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map);
299 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
300 HandleToUint64(swapchain_image), __LINE__, OBJTRACK_NONE, LayerName,
301 "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, "SwapchainImage",
302 HandleToUint64(swapchain_image));
303
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600304 ObjTrackState *pNewObjNode = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600305 pNewObjNode->object_type = kVulkanObjectTypeImage;
306 pNewObjNode->status = OBJSTATUS_NONE;
307 pNewObjNode->handle = HandleToUint64(swapchain_image);
308 pNewObjNode->parent_object = HandleToUint64(swapchain);
309 device_data->swapchainImageMap[HandleToUint64(swapchain_image)] = pNewObjNode;
310}
311
312void DeviceReportUndestroyedObjects(VkDevice device, VulkanObjectType object_type, enum UNIQUE_VALIDATION_ERROR_CODE error_code) {
313 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
314 for (auto item = device_data->object_map[object_type].begin(); item != device_data->object_map[object_type].end();) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600315 ObjTrackState *object_info = item->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600316 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[object_type], object_info->handle,
317 __LINE__, error_code, LayerName,
318 "OBJ ERROR : For device 0x%" PRIxLEAST64 ", %s object 0x%" PRIxLEAST64 " has not been destroyed. %s",
319 HandleToUint64(device), object_string[object_type], object_info->handle, validation_error_map[error_code]);
320 item = device_data->object_map[object_type].erase(item);
321 }
322}
323
324VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
325 std::unique_lock<std::mutex> lock(global_lock);
326
327 dispatch_key key = get_dispatch_key(instance);
328 layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
329
330 // Enable the temporary callback(s) here to catch cleanup issues:
331 bool callback_setup = false;
332 if (instance_data->num_tmp_callbacks > 0) {
333 if (!layer_enable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks,
334 instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks)) {
335 callback_setup = true;
336 }
337 }
338
339 // TODO: The instance handle can not be validated here. The loader will likely have to validate it.
340 ValidateObject(instance, instance, kVulkanObjectTypeInstance, true, VALIDATION_ERROR_2580bc01, VALIDATION_ERROR_UNDEFINED);
341
342 // Destroy physical devices
343 for (auto iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
344 iit != instance_data->object_map[kVulkanObjectTypePhysicalDevice].end();) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600345 ObjTrackState *pNode = iit->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600346 VkPhysicalDevice physical_device = reinterpret_cast<VkPhysicalDevice>(pNode->handle);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700347
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600348 DestroyObject(instance, physical_device, kVulkanObjectTypePhysicalDevice, nullptr, VALIDATION_ERROR_UNDEFINED,
349 VALIDATION_ERROR_UNDEFINED);
350 iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
351 }
352
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700353 // Destroy child devices
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600354 for (auto iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
355 iit != instance_data->object_map[kVulkanObjectTypeDevice].end();) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600356 ObjTrackState *pNode = iit->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600357
358 VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
359 VkDebugReportObjectTypeEXT debug_object_type = get_debug_report_enum[pNode->object_type];
360
361 log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, debug_object_type, pNode->handle, __LINE__,
362 OBJTRACK_OBJECT_LEAK, LayerName, "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.",
363 string_VkDebugReportObjectTypeEXT(debug_object_type), pNode->handle);
364
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700365 // Report any remaining objects in LL
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600366 ReportUndestroyedObjects(device, VALIDATION_ERROR_258004ea);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700367
368 DestroyObject(instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_258004ec, VALIDATION_ERROR_258004ee);
369 iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600370 }
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700371
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600372 instance_data->object_map[kVulkanObjectTypeDevice].clear();
373
374 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
375 pInstanceTable->DestroyInstance(instance, pAllocator);
376
377 // Disable and cleanup the temporary callback(s):
378 if (callback_setup) {
379 layer_disable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, instance_data->tmp_callbacks);
380 }
381 if (instance_data->num_tmp_callbacks > 0) {
382 layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks);
383 instance_data->num_tmp_callbacks = 0;
384 }
385
386 // Clean up logging callback, if any
387 while (instance_data->logging_callback.size() > 0) {
388 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
389 layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator);
390 instance_data->logging_callback.pop_back();
391 }
392
393 layer_debug_report_destroy_instance(instance_data->report_data);
394 FreeLayerDataPtr(key, layer_data_map);
395
396 lock.unlock();
397 ot_instance_table_map.erase(key);
398 delete pInstanceTable;
399}
400
401VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
402 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700403 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600404 ValidateObject(device, device, kVulkanObjectTypeDevice, true, VALIDATION_ERROR_24a05601, VALIDATION_ERROR_UNDEFINED);
Dave Houltona9df0ce2018-02-07 10:51:23 -0700405 DestroyObject(device_data->instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_24a002f6,
406 VALIDATION_ERROR_24a002f8);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600407
408 // Report any remaining objects associated with this VkDevice object in LL
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600409 ReportUndestroyedObjects(device, VALIDATION_ERROR_24a002f4);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600410
411 // Clean up Queue's MemRef Linked Lists
412 DestroyQueueDataStructures(device);
413
414 lock.unlock();
415
416 dispatch_key key = get_dispatch_key(device);
417 VkLayerDispatchTable *pDisp = get_dispatch_table(ot_device_table_map, device);
418 pDisp->DestroyDevice(device, pAllocator);
419 ot_device_table_map.erase(key);
420 delete pDisp;
421
422 FreeLayerDataPtr(key, layer_data_map);
423}
424
Mark Lobodzinski439645a2017-07-19 15:18:15 -0600425VKAPI_ATTR void VKAPI_CALL GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
426 std::unique_lock<std::mutex> lock(global_lock);
427 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_29605601, VALIDATION_ERROR_UNDEFINED);
428 lock.unlock();
429
430 get_dispatch_table(ot_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
431
432 lock.lock();
433 CreateQueue(device, *pQueue);
434 AddQueueInfo(device, queueFamilyIndex, *pQueue);
435}
436
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600437VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
438 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
439 const VkCopyDescriptorSet *pDescriptorCopies) {
440 bool skip = false;
441 {
442 std::lock_guard<std::mutex> lock(global_lock);
443 skip |=
444 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_33c05601, VALIDATION_ERROR_UNDEFINED);
445 if (pDescriptorCopies) {
446 for (uint32_t idx0 = 0; idx0 < descriptorCopyCount; ++idx0) {
447 if (pDescriptorCopies[idx0].dstSet) {
448 skip |= ValidateObject(device, pDescriptorCopies[idx0].dstSet, kVulkanObjectTypeDescriptorSet, false,
449 VALIDATION_ERROR_03207601, VALIDATION_ERROR_03200009);
450 }
451 if (pDescriptorCopies[idx0].srcSet) {
452 skip |= ValidateObject(device, pDescriptorCopies[idx0].srcSet, kVulkanObjectTypeDescriptorSet, false,
453 VALIDATION_ERROR_0322d201, VALIDATION_ERROR_03200009);
454 }
455 }
456 }
457 if (pDescriptorWrites) {
458 for (uint32_t idx1 = 0; idx1 < descriptorWriteCount; ++idx1) {
Chris Forbes2c600e92017-10-20 11:13:20 -0700459 skip |= ValidateDescriptorWrite(device, &pDescriptorWrites[idx1], false);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600460 }
461 }
462 }
463 if (skip) {
464 return;
465 }
466 get_dispatch_table(ot_device_table_map, device)
467 ->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
468}
469
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600470VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
471 const VkComputePipelineCreateInfo *pCreateInfos,
472 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) {
473 bool skip = VK_FALSE;
474 std::unique_lock<std::mutex> lock(global_lock);
475 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_1f205601, VALIDATION_ERROR_UNDEFINED);
476 if (pCreateInfos) {
477 for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
478 if (pCreateInfos[idx0].basePipelineHandle) {
479 skip |= ValidateObject(device, pCreateInfos[idx0].basePipelineHandle, kVulkanObjectTypePipeline, true,
480 VALIDATION_ERROR_03000572, VALIDATION_ERROR_03000009);
481 }
482 if (pCreateInfos[idx0].layout) {
483 skip |= ValidateObject(device, pCreateInfos[idx0].layout, kVulkanObjectTypePipelineLayout, false,
484 VALIDATION_ERROR_0300be01, VALIDATION_ERROR_03000009);
485 }
486 if (pCreateInfos[idx0].stage.module) {
487 skip |= ValidateObject(device, pCreateInfos[idx0].stage.module, kVulkanObjectTypeShaderModule, false,
488 VALIDATION_ERROR_1060d201, VALIDATION_ERROR_UNDEFINED);
489 }
490 }
491 }
492 if (pipelineCache) {
493 skip |= ValidateObject(device, pipelineCache, kVulkanObjectTypePipelineCache, true, VALIDATION_ERROR_1f228001,
494 VALIDATION_ERROR_1f228007);
495 }
496 lock.unlock();
497 if (skip) {
498 for (uint32_t i = 0; i < createInfoCount; i++) {
499 pPipelines[i] = VK_NULL_HANDLE;
500 }
501 return VK_ERROR_VALIDATION_FAILED_EXT;
502 }
503 VkResult result = get_dispatch_table(ot_device_table_map, device)
504 ->CreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
505 lock.lock();
506 for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) {
507 if (pPipelines[idx1] != VK_NULL_HANDLE) {
508 CreateObject(device, pPipelines[idx1], kVulkanObjectTypePipeline, pAllocator);
509 }
510 }
511 lock.unlock();
512 return result;
513}
514
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600515VKAPI_ATTR VkResult VKAPI_CALL ResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
516 VkDescriptorPoolResetFlags flags) {
517 bool skip = false;
518 std::unique_lock<std::mutex> lock(global_lock);
519 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
520 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_32a05601, VALIDATION_ERROR_UNDEFINED);
521 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_32a04601,
522 VALIDATION_ERROR_32a04607);
523 if (skip) {
524 return VK_ERROR_VALIDATION_FAILED_EXT;
525 }
526 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is reset.
527 // Remove this pool's descriptor sets from our descriptorSet map.
528 auto itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
529 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600530 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600531 auto del_itr = itr++;
532 if (pNode->parent_object == HandleToUint64(descriptorPool)) {
533 DestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet, nullptr,
534 VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
535 }
536 }
537 lock.unlock();
538 VkResult result = get_dispatch_table(ot_device_table_map, device)->ResetDescriptorPool(device, descriptorPool, flags);
539 return result;
540}
541
542VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer command_buffer, const VkCommandBufferBeginInfo *begin_info) {
543 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(command_buffer), layer_data_map);
544 bool skip = false;
545 {
546 std::lock_guard<std::mutex> lock(global_lock);
547 skip |= ValidateObject(command_buffer, command_buffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_16e02401,
548 VALIDATION_ERROR_UNDEFINED);
549 if (begin_info) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600550 ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)];
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600551 if ((begin_info->pInheritanceInfo) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY) &&
552 (begin_info->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
553 skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->framebuffer, kVulkanObjectTypeFramebuffer,
554 true, VALIDATION_ERROR_0280006e, VALIDATION_ERROR_02a00009);
555 skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->renderPass, kVulkanObjectTypeRenderPass, false,
556 VALIDATION_ERROR_0280006a, VALIDATION_ERROR_02a00009);
557 }
558 }
559 }
560 if (skip) {
561 return VK_ERROR_VALIDATION_FAILED_EXT;
562 }
563 VkResult result = get_dispatch_table(ot_device_table_map, command_buffer)->BeginCommandBuffer(command_buffer, begin_info);
564 return result;
565}
566
567VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance,
568 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
569 const VkAllocationCallbacks *pAllocator,
570 VkDebugReportCallbackEXT *pCallback) {
571 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
572 VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);
573 if (VK_SUCCESS == result) {
574 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
575 result = layer_create_msg_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pCallback);
576 CreateObject(instance, *pCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator);
577 }
578 return result;
579}
580
581VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
582 const VkAllocationCallbacks *pAllocator) {
583 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
584 pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
585 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
586 layer_destroy_msg_callback(instance_data->report_data, msgCallback, pAllocator);
587 DestroyObject(instance, msgCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator, VALIDATION_ERROR_242009b4,
588 VALIDATION_ERROR_242009b6);
589}
590
591VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags,
592 VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location,
593 int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
594 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
595 pInstanceTable->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
596}
597
598static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
599
600static const VkLayerProperties globalLayerProps = {"VK_LAYER_LUNARG_object_tracker",
601 VK_LAYER_API_VERSION, // specVersion
602 1, // implementationVersion
603 "LunarG Validation Layer"};
604
605VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
606 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
607}
608
609VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
610 VkLayerProperties *pProperties) {
611 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
612}
613
614VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
615 VkExtensionProperties *pProperties) {
616 if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))
617 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
618
619 return VK_ERROR_LAYER_NOT_PRESENT;
620}
621
622VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
623 uint32_t *pCount, VkExtensionProperties *pProperties) {
624 if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))
625 return util_GetExtensionProperties(0, nullptr, pCount, pProperties);
626
627 assert(physicalDevice);
628 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(ot_instance_table_map, physicalDevice);
629 return pTable->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);
630}
631
632VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
633 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
634 std::lock_guard<std::mutex> lock(global_lock);
635 bool skip = ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_1fc27a01,
636 VALIDATION_ERROR_UNDEFINED);
637 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
638
639 layer_data *phy_dev_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
640 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
641
642 assert(chain_info->u.pLayerInfo);
643 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
644 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
645 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(phy_dev_data->instance, "vkCreateDevice");
646 if (fpCreateDevice == NULL) {
647 return VK_ERROR_INITIALIZATION_FAILED;
648 }
649
650 // Advance the link info for the next element on the chain
651 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
652
653 VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
654 if (result != VK_SUCCESS) {
655 return result;
656 }
657
658 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
659 device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
660 layer_init_device_dispatch_table(*pDevice, &device_data->dispatch_table, fpGetDeviceProcAddr);
661
662 // Add link back to physDev
663 device_data->physical_device = physicalDevice;
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700664 device_data->instance = phy_dev_data->instance;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600665
666 initDeviceTable(*pDevice, fpGetDeviceProcAddr, ot_device_table_map);
667
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700668 CreateObject(phy_dev_data->instance, *pDevice, kVulkanObjectTypeDevice, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600669
670 return result;
671}
672
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600673VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
674 VkImage *pSwapchainImages) {
Mark Lobodzinski09fa2d42017-07-21 10:16:53 -0600675 bool skip = false;
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600676 std::unique_lock<std::mutex> lock(global_lock);
677 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_30805601, VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinski09fa2d42017-07-21 10:16:53 -0600678 skip |= ValidateObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, false, VALIDATION_ERROR_3082f001,
679 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600680 lock.unlock();
Mark Lobodzinski09fa2d42017-07-21 10:16:53 -0600681 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
682
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600683 VkResult result = get_dispatch_table(ot_device_table_map, device)
684 ->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
685 if (pSwapchainImages != NULL) {
686 lock.lock();
687 for (uint32_t i = 0; i < *pSwapchainImageCount; i++) {
688 CreateSwapchainImageObject(device, pSwapchainImages[i], swapchain);
689 }
690 lock.unlock();
691 }
692 return result;
693}
694
Petr Kraus42f6f8d2017-12-17 17:37:33 +0100695VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
696 const VkAllocationCallbacks *pAllocator,
697 VkDescriptorSetLayout *pSetLayout) {
698 bool skip = false;
699 {
700 std::lock_guard<std::mutex> lock(global_lock);
701 skip |=
702 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_1f805601, VALIDATION_ERROR_UNDEFINED);
703 if (pCreateInfo) {
704 if (pCreateInfo->pBindings) {
705 for (uint32_t binding_index = 0; binding_index < pCreateInfo->bindingCount; ++binding_index) {
706 const VkDescriptorSetLayoutBinding &binding = pCreateInfo->pBindings[binding_index];
707 const bool is_sampler_type = binding.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
708 binding.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
709 if (binding.pImmutableSamplers && is_sampler_type) {
710 for (uint32_t index2 = 0; index2 < binding.descriptorCount; ++index2) {
711 const VkSampler sampler = binding.pImmutableSamplers[index2];
712 skip |= ValidateObject(device, sampler, kVulkanObjectTypeSampler, false, VALIDATION_ERROR_04e00234,
713 VALIDATION_ERROR_UNDEFINED);
714 }
715 }
716 }
717 }
718 }
719 }
720 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
721 VkResult result =
722 get_dispatch_table(ot_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
723 if (VK_SUCCESS == result) {
724 std::lock_guard<std::mutex> lock(global_lock);
725 CreateObject(device, *pSetLayout, kVulkanObjectTypeDescriptorSetLayout, pAllocator);
726 }
727 return result;
728}
729
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600730VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
731 uint32_t *pQueueFamilyPropertyCount,
732 VkQueueFamilyProperties *pQueueFamilyProperties) {
733 bool skip = false;
734 {
735 std::lock_guard<std::mutex> lock(global_lock);
736 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_2da27a01,
737 VALIDATION_ERROR_UNDEFINED);
738 }
739 if (skip) {
740 return;
741 }
742 get_dispatch_table(ot_instance_table_map, physicalDevice)
743 ->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
744 std::lock_guard<std::mutex> lock(global_lock);
745 if (pQueueFamilyProperties != NULL) {
746 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
747 if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) {
748 instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount);
749 }
750 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
751 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i];
752 }
753 }
754}
755
756VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
757 VkInstance *pInstance) {
758 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
759
760 assert(chain_info->u.pLayerInfo);
761 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
762 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
763 if (fpCreateInstance == NULL) {
764 return VK_ERROR_INITIALIZATION_FAILED;
765 }
766
767 // Advance the link info for the next element on the chain
768 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
769
770 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
771 if (result != VK_SUCCESS) {
772 return result;
773 }
774
775 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map);
776 instance_data->instance = *pInstance;
777 initInstanceTable(*pInstance, fpGetInstanceProcAddr, ot_instance_table_map);
778 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, *pInstance);
779
780 // Look for one or more debug report create info structures, and copy the
781 // callback(s) for each one found (for use by vkDestroyInstance)
782 layer_copy_tmp_callbacks(pCreateInfo->pNext, &instance_data->num_tmp_callbacks, &instance_data->tmp_dbg_create_infos,
783 &instance_data->tmp_callbacks);
784
785 instance_data->report_data = debug_report_create_instance(pInstanceTable, *pInstance, pCreateInfo->enabledExtensionCount,
786 pCreateInfo->ppEnabledExtensionNames);
787
788 InitObjectTracker(instance_data, pAllocator);
789
790 CreateObject(*pInstance, *pInstance, kVulkanObjectTypeInstance, pAllocator);
791
792 return result;
793}
794
795VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
796 VkPhysicalDevice *pPhysicalDevices) {
797 bool skip = VK_FALSE;
798 std::unique_lock<std::mutex> lock(global_lock);
799 skip |=
800 ValidateObject(instance, instance, kVulkanObjectTypeInstance, false, VALIDATION_ERROR_2800bc01, VALIDATION_ERROR_UNDEFINED);
801 lock.unlock();
802 if (skip) {
803 return VK_ERROR_VALIDATION_FAILED_EXT;
804 }
805 VkResult result = get_dispatch_table(ot_instance_table_map, instance)
806 ->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
807 lock.lock();
808 if (result == VK_SUCCESS) {
809 if (pPhysicalDevices) {
810 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
811 CreateObject(instance, pPhysicalDevices[i], kVulkanObjectTypePhysicalDevice, nullptr);
812 }
813 }
814 }
815 lock.unlock();
816 return result;
817}
818
819VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
820 VkCommandBuffer *pCommandBuffers) {
821 bool skip = VK_FALSE;
822 std::unique_lock<std::mutex> lock(global_lock);
823 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_16805601, VALIDATION_ERROR_UNDEFINED);
824 skip |= ValidateObject(device, pAllocateInfo->commandPool, kVulkanObjectTypeCommandPool, false, VALIDATION_ERROR_02602801,
825 VALIDATION_ERROR_UNDEFINED);
826 lock.unlock();
827
828 if (skip) {
829 return VK_ERROR_VALIDATION_FAILED_EXT;
830 }
831
832 VkResult result =
833 get_dispatch_table(ot_device_table_map, device)->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
834
835 lock.lock();
836 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
837 AllocateCommandBuffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], pAllocateInfo->level);
838 }
839 lock.unlock();
840
841 return result;
842}
843
844VKAPI_ATTR VkResult VKAPI_CALL AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
845 VkDescriptorSet *pDescriptorSets) {
846 bool skip = VK_FALSE;
847 std::unique_lock<std::mutex> lock(global_lock);
848 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_16a05601, VALIDATION_ERROR_UNDEFINED);
849 skip |= ValidateObject(device, pAllocateInfo->descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_04c04601,
850 VALIDATION_ERROR_04c00009);
851 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
852 skip |= ValidateObject(device, pAllocateInfo->pSetLayouts[i], kVulkanObjectTypeDescriptorSetLayout, false,
853 VALIDATION_ERROR_04c22c01, VALIDATION_ERROR_04c00009);
854 }
855 lock.unlock();
856 if (skip) {
857 return VK_ERROR_VALIDATION_FAILED_EXT;
858 }
859
860 VkResult result =
861 get_dispatch_table(ot_device_table_map, device)->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
862
863 if (VK_SUCCESS == result) {
864 lock.lock();
865 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
866 AllocateDescriptorSet(device, pAllocateInfo->descriptorPool, pDescriptorSets[i]);
867 }
868 lock.unlock();
869 }
870
871 return result;
872}
873
874VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
875 const VkCommandBuffer *pCommandBuffers) {
876 bool skip = false;
877 std::unique_lock<std::mutex> lock(global_lock);
878 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_28405601, VALIDATION_ERROR_UNDEFINED);
879 ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, false, VALIDATION_ERROR_28402801, VALIDATION_ERROR_28402807);
880 for (uint32_t i = 0; i < commandBufferCount; i++) {
881 if (pCommandBuffers[i] != VK_NULL_HANDLE) {
882 skip |= ValidateCommandBuffer(device, commandPool, pCommandBuffers[i]);
883 }
884 }
885
886 for (uint32_t i = 0; i < commandBufferCount; i++) {
887 DestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer, nullptr, VALIDATION_ERROR_UNDEFINED,
888 VALIDATION_ERROR_UNDEFINED);
889 }
890
891 lock.unlock();
892 if (!skip) {
893 get_dispatch_table(ot_device_table_map, device)
894 ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
895 }
896}
897
898VKAPI_ATTR void VKAPI_CALL DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
899 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
900 std::unique_lock<std::mutex> lock(global_lock);
901 // A swapchain's images are implicitly deleted when the swapchain is deleted.
902 // Remove this swapchain's images from our map of such images.
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600903 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->swapchainImageMap.begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600904 while (itr != device_data->swapchainImageMap.end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600905 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600906 if (pNode->parent_object == HandleToUint64(swapchain)) {
907 delete pNode;
908 auto delete_item = itr++;
909 device_data->swapchainImageMap.erase(delete_item);
910 } else {
911 ++itr;
912 }
913 }
914 DestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, pAllocator, VALIDATION_ERROR_26e00a06,
915 VALIDATION_ERROR_26e00a08);
916 lock.unlock();
917
918 get_dispatch_table(ot_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator);
919}
920
921VKAPI_ATTR VkResult VKAPI_CALL FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
922 const VkDescriptorSet *pDescriptorSets) {
923 bool skip = false;
924 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
925 std::unique_lock<std::mutex> lock(global_lock);
926 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_28605601, VALIDATION_ERROR_UNDEFINED);
927 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_28604601,
928 VALIDATION_ERROR_28604607);
929 for (uint32_t i = 0; i < descriptorSetCount; i++) {
930 if (pDescriptorSets[i] != VK_NULL_HANDLE) {
931 skip |= ValidateDescriptorSet(device, descriptorPool, pDescriptorSets[i]);
932 }
933 }
934
935 for (uint32_t i = 0; i < descriptorSetCount; i++) {
936 DestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet, nullptr, VALIDATION_ERROR_UNDEFINED,
937 VALIDATION_ERROR_UNDEFINED);
938 }
939
940 lock.unlock();
941 if (!skip) {
942 result = get_dispatch_table(ot_device_table_map, device)
943 ->FreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets);
944 }
945 return result;
946}
947
948VKAPI_ATTR void VKAPI_CALL DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
949 const VkAllocationCallbacks *pAllocator) {
950 bool skip = VK_FALSE;
951 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
952 std::unique_lock<std::mutex> lock(global_lock);
953 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_24405601, VALIDATION_ERROR_UNDEFINED);
954 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, true, VALIDATION_ERROR_24404601,
955 VALIDATION_ERROR_24404607);
956 lock.unlock();
957 if (skip) {
958 return;
959 }
960 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is deleted.
961 // Remove this pool's descriptor sets from our descriptorSet map.
962 lock.lock();
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600963 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600964 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600965 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600966 auto del_itr = itr++;
967 if (pNode->parent_object == HandleToUint64(descriptorPool)) {
968 DestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet, nullptr,
969 VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
970 }
971 }
972 DestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, pAllocator, VALIDATION_ERROR_24400260,
973 VALIDATION_ERROR_24400262);
974 lock.unlock();
975 get_dispatch_table(ot_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator);
976}
977
978VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
979 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
980 bool skip = false;
981 std::unique_lock<std::mutex> lock(global_lock);
982 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_24005601, VALIDATION_ERROR_UNDEFINED);
983 skip |= ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, true, VALIDATION_ERROR_24002801,
984 VALIDATION_ERROR_24002807);
985 lock.unlock();
986 if (skip) {
987 return;
988 }
989 lock.lock();
990 // A CommandPool's command buffers are implicitly deleted when the pool is deleted.
991 // Remove this pool's cmdBuffers from our cmd buffer map.
992 auto itr = device_data->object_map[kVulkanObjectTypeCommandBuffer].begin();
993 auto del_itr = itr;
994 while (itr != device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600995 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600996 del_itr = itr++;
997 if (pNode->parent_object == HandleToUint64(commandPool)) {
998 skip |= ValidateCommandBuffer(device, commandPool, reinterpret_cast<VkCommandBuffer>((*del_itr).first));
999 DestroyObject(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first), kVulkanObjectTypeCommandBuffer, nullptr,
1000 VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1001 }
1002 }
1003 DestroyObject(device, commandPool, kVulkanObjectTypeCommandPool, pAllocator, VALIDATION_ERROR_24000054,
1004 VALIDATION_ERROR_24000056);
1005 lock.unlock();
1006 get_dispatch_table(ot_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator);
1007}
1008
1009VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice,
1010 uint32_t *pQueueFamilyPropertyCount,
1011 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
1012 bool skip = false;
1013 {
1014 std::lock_guard<std::mutex> lock(global_lock);
1015 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_UNDEFINED,
1016 VALIDATION_ERROR_UNDEFINED);
1017 }
1018 if (skip) {
1019 return;
1020 }
1021 get_dispatch_table(ot_instance_table_map, physicalDevice)
1022 ->GetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
1023 std::lock_guard<std::mutex> lock(global_lock);
1024 if (pQueueFamilyProperties != NULL) {
1025 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1026 if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) {
1027 instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount);
1028 }
1029 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
1030 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties;
1031 }
1032 }
1033}
1034
Mark Lobodzinskidfe5e172017-07-19 13:03:22 -06001035VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001036 bool skip = VK_FALSE;
1037 std::unique_lock<std::mutex> lock(global_lock);
1038 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1039 if (pNameInfo->pObjectName) {
1040 dev_data->report_data->debugObjectNameMap->insert(
1041 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
1042 } else {
1043 dev_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
1044 }
1045 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_23605601, VALIDATION_ERROR_UNDEFINED);
1046 lock.unlock();
1047 if (skip) {
1048 return VK_ERROR_VALIDATION_FAILED_EXT;
1049 }
1050 VkResult result = dev_data->dispatch_table.DebugMarkerSetObjectNameEXT(device, pNameInfo);
1051 return result;
1052}
1053
1054VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
1055 assert(instance);
1056
1057 if (get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr == NULL) {
1058 return NULL;
1059 }
1060 return get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr(instance, funcName);
1061}
1062
1063VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) {
1064 const auto item = name_to_funcptr_map.find(funcName);
1065 if (item != name_to_funcptr_map.end()) {
1066 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
1067 }
1068
1069 auto table = get_dispatch_table(ot_device_table_map, device);
1070 if (!table->GetDeviceProcAddr) return NULL;
1071 return table->GetDeviceProcAddr(device, funcName);
1072}
1073
1074VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) {
1075 const auto item = name_to_funcptr_map.find(funcName);
1076 if (item != name_to_funcptr_map.end()) {
1077 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
1078 }
1079
1080 auto table = get_dispatch_table(ot_instance_table_map, instance);
1081 if (!table->GetInstanceProcAddr) return nullptr;
1082 return table->GetInstanceProcAddr(instance, funcName);
1083}
1084
1085} // namespace object_tracker
1086
1087VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
1088 VkExtensionProperties *pProperties) {
1089 return object_tracker::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
1090}
1091
1092VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
1093 VkLayerProperties *pProperties) {
1094 return object_tracker::EnumerateInstanceLayerProperties(pCount, pProperties);
1095}
1096
1097VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
1098 VkLayerProperties *pProperties) {
1099 // The layer command handles VK_NULL_HANDLE just fine internally
1100 assert(physicalDevice == VK_NULL_HANDLE);
1101 return object_tracker::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
1102}
1103
1104VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
1105 return object_tracker::GetDeviceProcAddr(dev, funcName);
1106}
1107
1108VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
1109 return object_tracker::GetInstanceProcAddr(instance, funcName);
1110}
1111
1112VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
1113 const char *pLayerName, uint32_t *pCount,
1114 VkExtensionProperties *pProperties) {
1115 // The layer command handles VK_NULL_HANDLE just fine internally
1116 assert(physicalDevice == VK_NULL_HANDLE);
1117 return object_tracker::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
1118}
1119
1120VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
1121 const char *funcName) {
1122 return object_tracker::GetPhysicalDeviceProcAddr(instance, funcName);
1123}
1124
1125VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
1126 assert(pVersionStruct != NULL);
1127 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
1128
1129 // Fill in the function pointers if our version is at least capable of having the structure contain them.
1130 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
1131 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
1132 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
1133 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
1134 }
1135
1136 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
1137 object_tracker::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
1138 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
1139 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
1140 }
1141
1142 return VK_SUCCESS;
1143}