blob: f4f148db9254b06b5248b35d2b7f6e3a6201cea8 [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
Chris Forbes2c600e92017-10-20 11:13:20 -0700213template<typename DispObj>
214static bool ValidateDescriptorWrite(DispObj disp, VkWriteDescriptorSet const *desc, bool isPush) {
215 bool skip = false;
216
217 if (!isPush && desc->dstSet) {
218 skip |= ValidateObject(disp, desc->dstSet, kVulkanObjectTypeDescriptorSet, false,
219 VALIDATION_ERROR_15c00280, VALIDATION_ERROR_15c00009);
220 }
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) {
225 skip |= ValidateObject(disp, desc->pTexelBufferView[idx2], kVulkanObjectTypeBufferView,
226 false, VALIDATION_ERROR_15c00286, VALIDATION_ERROR_15c00009);
227 }
228 }
229
230 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
231 (desc->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
232 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
233 (desc->descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
234 for (uint32_t idx3 = 0; idx3 < desc->descriptorCount; ++idx3) {
235 skip |=
236 ValidateObject(disp, desc->pImageInfo[idx3].imageView, kVulkanObjectTypeImageView,
237 false, VALIDATION_ERROR_15c0028c, VALIDATION_ERROR_04600009);
238 }
239 }
240
241 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
242 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
243 (desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
244 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
245 for (uint32_t idx4 = 0; idx4 < desc->descriptorCount; ++idx4) {
246 if (desc->pBufferInfo[idx4].buffer) {
247 skip |=
248 ValidateObject(disp, desc->pBufferInfo[idx4].buffer, kVulkanObjectTypeBuffer,
249 false, VALIDATION_ERROR_04401a01, VALIDATION_ERROR_UNDEFINED);
250 }
251 }
252 }
253
254 return skip;
255}
256
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600257VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
258 VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount,
259 const VkWriteDescriptorSet *pDescriptorWrites) {
260 bool skip = false;
261 {
262 std::lock_guard<std::mutex> lock(global_lock);
263 skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_1be02401,
264 VALIDATION_ERROR_1be00009);
265 skip |= ValidateObject(commandBuffer, layout, kVulkanObjectTypePipelineLayout, false, VALIDATION_ERROR_1be0be01,
266 VALIDATION_ERROR_1be00009);
267 if (pDescriptorWrites) {
268 for (uint32_t index0 = 0; index0 < descriptorWriteCount; ++index0) {
Chris Forbesa94b60b2017-10-20 11:28:02 -0700269 skip |= ValidateDescriptorWrite(commandBuffer, &pDescriptorWrites[index0], true);
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600270 }
271 }
272 }
273 if (skip) return;
274 get_dispatch_table(ot_device_table_map, commandBuffer)
275 ->CmdPushDescriptorSetKHR(commandBuffer, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites);
276}
277
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600278void CreateQueue(VkDevice device, VkQueue vkObj) {
279 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
280
281 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
282 HandleToUint64(vkObj), __LINE__, OBJTRACK_NONE, LayerName, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
283 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT", HandleToUint64(vkObj));
284
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600285 ObjTrackState *p_obj_node = NULL;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600286 auto queue_item = device_data->object_map[kVulkanObjectTypeQueue].find(HandleToUint64(vkObj));
287 if (queue_item == device_data->object_map[kVulkanObjectTypeQueue].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600288 p_obj_node = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600289 device_data->object_map[kVulkanObjectTypeQueue][HandleToUint64(vkObj)] = p_obj_node;
290 device_data->num_objects[kVulkanObjectTypeQueue]++;
291 device_data->num_total_objects++;
292 } else {
293 p_obj_node = queue_item->second;
294 }
295 p_obj_node->object_type = kVulkanObjectTypeQueue;
296 p_obj_node->status = OBJSTATUS_NONE;
297 p_obj_node->handle = HandleToUint64(vkObj);
298}
299
300void CreateSwapchainImageObject(VkDevice dispatchable_object, VkImage swapchain_image, VkSwapchainKHR swapchain) {
301 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map);
302 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
303 HandleToUint64(swapchain_image), __LINE__, OBJTRACK_NONE, LayerName,
304 "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, "SwapchainImage",
305 HandleToUint64(swapchain_image));
306
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600307 ObjTrackState *pNewObjNode = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600308 pNewObjNode->object_type = kVulkanObjectTypeImage;
309 pNewObjNode->status = OBJSTATUS_NONE;
310 pNewObjNode->handle = HandleToUint64(swapchain_image);
311 pNewObjNode->parent_object = HandleToUint64(swapchain);
312 device_data->swapchainImageMap[HandleToUint64(swapchain_image)] = pNewObjNode;
313}
314
315void DeviceReportUndestroyedObjects(VkDevice device, VulkanObjectType object_type, enum UNIQUE_VALIDATION_ERROR_CODE error_code) {
316 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
317 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 -0600318 ObjTrackState *object_info = item->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600319 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[object_type], object_info->handle,
320 __LINE__, error_code, LayerName,
321 "OBJ ERROR : For device 0x%" PRIxLEAST64 ", %s object 0x%" PRIxLEAST64 " has not been destroyed. %s",
322 HandleToUint64(device), object_string[object_type], object_info->handle, validation_error_map[error_code]);
323 item = device_data->object_map[object_type].erase(item);
324 }
325}
326
327VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
328 std::unique_lock<std::mutex> lock(global_lock);
329
330 dispatch_key key = get_dispatch_key(instance);
331 layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
332
333 // Enable the temporary callback(s) here to catch cleanup issues:
334 bool callback_setup = false;
335 if (instance_data->num_tmp_callbacks > 0) {
336 if (!layer_enable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks,
337 instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks)) {
338 callback_setup = true;
339 }
340 }
341
342 // TODO: The instance handle can not be validated here. The loader will likely have to validate it.
343 ValidateObject(instance, instance, kVulkanObjectTypeInstance, true, VALIDATION_ERROR_2580bc01, VALIDATION_ERROR_UNDEFINED);
344
345 // Destroy physical devices
346 for (auto iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
347 iit != instance_data->object_map[kVulkanObjectTypePhysicalDevice].end();) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600348 ObjTrackState *pNode = iit->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600349 VkPhysicalDevice physical_device = reinterpret_cast<VkPhysicalDevice>(pNode->handle);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700350
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600351 DestroyObject(instance, physical_device, kVulkanObjectTypePhysicalDevice, nullptr, VALIDATION_ERROR_UNDEFINED,
352 VALIDATION_ERROR_UNDEFINED);
353 iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
354 }
355
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700356 // Destroy child devices
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600357 for (auto iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
358 iit != instance_data->object_map[kVulkanObjectTypeDevice].end();) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600359 ObjTrackState *pNode = iit->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600360
361 VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
362 VkDebugReportObjectTypeEXT debug_object_type = get_debug_report_enum[pNode->object_type];
363
364 log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, debug_object_type, pNode->handle, __LINE__,
365 OBJTRACK_OBJECT_LEAK, LayerName, "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.",
366 string_VkDebugReportObjectTypeEXT(debug_object_type), pNode->handle);
367
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700368 // Report any remaining objects in LL
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600369 ReportUndestroyedObjects(device, VALIDATION_ERROR_258004ea);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700370
371 DestroyObject(instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_258004ec, VALIDATION_ERROR_258004ee);
372 iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600373 }
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700374
375
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600376 instance_data->object_map[kVulkanObjectTypeDevice].clear();
377
378 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
379 pInstanceTable->DestroyInstance(instance, pAllocator);
380
381 // Disable and cleanup the temporary callback(s):
382 if (callback_setup) {
383 layer_disable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, instance_data->tmp_callbacks);
384 }
385 if (instance_data->num_tmp_callbacks > 0) {
386 layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks);
387 instance_data->num_tmp_callbacks = 0;
388 }
389
390 // Clean up logging callback, if any
391 while (instance_data->logging_callback.size() > 0) {
392 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
393 layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator);
394 instance_data->logging_callback.pop_back();
395 }
396
397 layer_debug_report_destroy_instance(instance_data->report_data);
398 FreeLayerDataPtr(key, layer_data_map);
399
400 lock.unlock();
401 ot_instance_table_map.erase(key);
402 delete pInstanceTable;
403}
404
405VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
406 std::unique_lock<std::mutex> lock(global_lock);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700407 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600408 ValidateObject(device, device, kVulkanObjectTypeDevice, true, VALIDATION_ERROR_24a05601, VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700409 DestroyObject(device_data->instance, device, kVulkanObjectTypeDevice, pAllocator, VALIDATION_ERROR_24a002f6, VALIDATION_ERROR_24a002f8);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600410
411 // Report any remaining objects associated with this VkDevice object in LL
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600412 ReportUndestroyedObjects(device, VALIDATION_ERROR_24a002f4);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600413
414 // Clean up Queue's MemRef Linked Lists
415 DestroyQueueDataStructures(device);
416
417 lock.unlock();
418
419 dispatch_key key = get_dispatch_key(device);
420 VkLayerDispatchTable *pDisp = get_dispatch_table(ot_device_table_map, device);
421 pDisp->DestroyDevice(device, pAllocator);
422 ot_device_table_map.erase(key);
423 delete pDisp;
424
425 FreeLayerDataPtr(key, layer_data_map);
426}
427
Mark Lobodzinski439645a2017-07-19 15:18:15 -0600428VKAPI_ATTR void VKAPI_CALL GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
429 std::unique_lock<std::mutex> lock(global_lock);
430 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_29605601, VALIDATION_ERROR_UNDEFINED);
431 lock.unlock();
432
433 get_dispatch_table(ot_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
434
435 lock.lock();
436 CreateQueue(device, *pQueue);
437 AddQueueInfo(device, queueFamilyIndex, *pQueue);
438}
439
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600440VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
441 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
442 const VkCopyDescriptorSet *pDescriptorCopies) {
443 bool skip = false;
444 {
445 std::lock_guard<std::mutex> lock(global_lock);
446 skip |=
447 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_33c05601, VALIDATION_ERROR_UNDEFINED);
448 if (pDescriptorCopies) {
449 for (uint32_t idx0 = 0; idx0 < descriptorCopyCount; ++idx0) {
450 if (pDescriptorCopies[idx0].dstSet) {
451 skip |= ValidateObject(device, pDescriptorCopies[idx0].dstSet, kVulkanObjectTypeDescriptorSet, false,
452 VALIDATION_ERROR_03207601, VALIDATION_ERROR_03200009);
453 }
454 if (pDescriptorCopies[idx0].srcSet) {
455 skip |= ValidateObject(device, pDescriptorCopies[idx0].srcSet, kVulkanObjectTypeDescriptorSet, false,
456 VALIDATION_ERROR_0322d201, VALIDATION_ERROR_03200009);
457 }
458 }
459 }
460 if (pDescriptorWrites) {
461 for (uint32_t idx1 = 0; idx1 < descriptorWriteCount; ++idx1) {
Chris Forbes2c600e92017-10-20 11:13:20 -0700462 skip |= ValidateDescriptorWrite(device, &pDescriptorWrites[idx1], false);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600463 }
464 }
465 }
466 if (skip) {
467 return;
468 }
469 get_dispatch_table(ot_device_table_map, device)
470 ->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
471}
472
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600473VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
474 const VkComputePipelineCreateInfo *pCreateInfos,
475 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) {
476 bool skip = VK_FALSE;
477 std::unique_lock<std::mutex> lock(global_lock);
478 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_1f205601, VALIDATION_ERROR_UNDEFINED);
479 if (pCreateInfos) {
480 for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
481 if (pCreateInfos[idx0].basePipelineHandle) {
482 skip |= ValidateObject(device, pCreateInfos[idx0].basePipelineHandle, kVulkanObjectTypePipeline, true,
483 VALIDATION_ERROR_03000572, VALIDATION_ERROR_03000009);
484 }
485 if (pCreateInfos[idx0].layout) {
486 skip |= ValidateObject(device, pCreateInfos[idx0].layout, kVulkanObjectTypePipelineLayout, false,
487 VALIDATION_ERROR_0300be01, VALIDATION_ERROR_03000009);
488 }
489 if (pCreateInfos[idx0].stage.module) {
490 skip |= ValidateObject(device, pCreateInfos[idx0].stage.module, kVulkanObjectTypeShaderModule, false,
491 VALIDATION_ERROR_1060d201, VALIDATION_ERROR_UNDEFINED);
492 }
493 }
494 }
495 if (pipelineCache) {
496 skip |= ValidateObject(device, pipelineCache, kVulkanObjectTypePipelineCache, true, VALIDATION_ERROR_1f228001,
497 VALIDATION_ERROR_1f228007);
498 }
499 lock.unlock();
500 if (skip) {
501 for (uint32_t i = 0; i < createInfoCount; i++) {
502 pPipelines[i] = VK_NULL_HANDLE;
503 }
504 return VK_ERROR_VALIDATION_FAILED_EXT;
505 }
506 VkResult result = get_dispatch_table(ot_device_table_map, device)
507 ->CreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
508 lock.lock();
509 for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) {
510 if (pPipelines[idx1] != VK_NULL_HANDLE) {
511 CreateObject(device, pPipelines[idx1], kVulkanObjectTypePipeline, pAllocator);
512 }
513 }
514 lock.unlock();
515 return result;
516}
517
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600518VKAPI_ATTR VkResult VKAPI_CALL ResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
519 VkDescriptorPoolResetFlags flags) {
520 bool skip = false;
521 std::unique_lock<std::mutex> lock(global_lock);
522 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
523 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_32a05601, VALIDATION_ERROR_UNDEFINED);
524 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_32a04601,
525 VALIDATION_ERROR_32a04607);
526 if (skip) {
527 return VK_ERROR_VALIDATION_FAILED_EXT;
528 }
529 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is reset.
530 // Remove this pool's descriptor sets from our descriptorSet map.
531 auto itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
532 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600533 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600534 auto del_itr = itr++;
535 if (pNode->parent_object == HandleToUint64(descriptorPool)) {
536 DestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet, nullptr,
537 VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
538 }
539 }
540 lock.unlock();
541 VkResult result = get_dispatch_table(ot_device_table_map, device)->ResetDescriptorPool(device, descriptorPool, flags);
542 return result;
543}
544
545VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer command_buffer, const VkCommandBufferBeginInfo *begin_info) {
546 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(command_buffer), layer_data_map);
547 bool skip = false;
548 {
549 std::lock_guard<std::mutex> lock(global_lock);
550 skip |= ValidateObject(command_buffer, command_buffer, kVulkanObjectTypeCommandBuffer, false, VALIDATION_ERROR_16e02401,
551 VALIDATION_ERROR_UNDEFINED);
552 if (begin_info) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600553 ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)];
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600554 if ((begin_info->pInheritanceInfo) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY) &&
555 (begin_info->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
556 skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->framebuffer, kVulkanObjectTypeFramebuffer,
557 true, VALIDATION_ERROR_0280006e, VALIDATION_ERROR_02a00009);
558 skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->renderPass, kVulkanObjectTypeRenderPass, false,
559 VALIDATION_ERROR_0280006a, VALIDATION_ERROR_02a00009);
560 }
561 }
562 }
563 if (skip) {
564 return VK_ERROR_VALIDATION_FAILED_EXT;
565 }
566 VkResult result = get_dispatch_table(ot_device_table_map, command_buffer)->BeginCommandBuffer(command_buffer, begin_info);
567 return result;
568}
569
570VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance,
571 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
572 const VkAllocationCallbacks *pAllocator,
573 VkDebugReportCallbackEXT *pCallback) {
574 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
575 VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);
576 if (VK_SUCCESS == result) {
577 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
578 result = layer_create_msg_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pCallback);
579 CreateObject(instance, *pCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator);
580 }
581 return result;
582}
583
584VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
585 const VkAllocationCallbacks *pAllocator) {
586 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
587 pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
588 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
589 layer_destroy_msg_callback(instance_data->report_data, msgCallback, pAllocator);
590 DestroyObject(instance, msgCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator, VALIDATION_ERROR_242009b4,
591 VALIDATION_ERROR_242009b6);
592}
593
594VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags,
595 VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location,
596 int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
597 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
598 pInstanceTable->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
599}
600
601static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
602
603static const VkLayerProperties globalLayerProps = {"VK_LAYER_LUNARG_object_tracker",
604 VK_LAYER_API_VERSION, // specVersion
605 1, // implementationVersion
606 "LunarG Validation Layer"};
607
608VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
609 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
610}
611
612VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
613 VkLayerProperties *pProperties) {
614 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
615}
616
617VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
618 VkExtensionProperties *pProperties) {
619 if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))
620 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
621
622 return VK_ERROR_LAYER_NOT_PRESENT;
623}
624
625VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
626 uint32_t *pCount, VkExtensionProperties *pProperties) {
627 if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))
628 return util_GetExtensionProperties(0, nullptr, pCount, pProperties);
629
630 assert(physicalDevice);
631 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(ot_instance_table_map, physicalDevice);
632 return pTable->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);
633}
634
635VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
636 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
637 std::lock_guard<std::mutex> lock(global_lock);
638 bool skip = ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_1fc27a01,
639 VALIDATION_ERROR_UNDEFINED);
640 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
641
642 layer_data *phy_dev_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
643 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
644
645 assert(chain_info->u.pLayerInfo);
646 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
647 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
648 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(phy_dev_data->instance, "vkCreateDevice");
649 if (fpCreateDevice == NULL) {
650 return VK_ERROR_INITIALIZATION_FAILED;
651 }
652
653 // Advance the link info for the next element on the chain
654 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
655
656 VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
657 if (result != VK_SUCCESS) {
658 return result;
659 }
660
661 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
662 device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
663 layer_init_device_dispatch_table(*pDevice, &device_data->dispatch_table, fpGetDeviceProcAddr);
664
665 // Add link back to physDev
666 device_data->physical_device = physicalDevice;
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700667 device_data->instance = phy_dev_data->instance;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600668
669 initDeviceTable(*pDevice, fpGetDeviceProcAddr, ot_device_table_map);
670
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700671 CreateObject(phy_dev_data->instance, *pDevice, kVulkanObjectTypeDevice, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600672
673 return result;
674}
675
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600676VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
677 VkImage *pSwapchainImages) {
Mark Lobodzinski09fa2d42017-07-21 10:16:53 -0600678 bool skip = false;
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600679 std::unique_lock<std::mutex> lock(global_lock);
680 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_30805601, VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinski09fa2d42017-07-21 10:16:53 -0600681 skip |= ValidateObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, false, VALIDATION_ERROR_3082f001,
682 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600683 lock.unlock();
Mark Lobodzinski09fa2d42017-07-21 10:16:53 -0600684 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
685
Mark Lobodzinski216843a2017-07-21 13:23:13 -0600686 VkResult result = get_dispatch_table(ot_device_table_map, device)
687 ->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
688 if (pSwapchainImages != NULL) {
689 lock.lock();
690 for (uint32_t i = 0; i < *pSwapchainImageCount; i++) {
691 CreateSwapchainImageObject(device, pSwapchainImages[i], swapchain);
692 }
693 lock.unlock();
694 }
695 return result;
696}
697
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600698VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
699 uint32_t *pQueueFamilyPropertyCount,
700 VkQueueFamilyProperties *pQueueFamilyProperties) {
701 bool skip = false;
702 {
703 std::lock_guard<std::mutex> lock(global_lock);
704 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_2da27a01,
705 VALIDATION_ERROR_UNDEFINED);
706 }
707 if (skip) {
708 return;
709 }
710 get_dispatch_table(ot_instance_table_map, physicalDevice)
711 ->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
712 std::lock_guard<std::mutex> lock(global_lock);
713 if (pQueueFamilyProperties != NULL) {
714 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
715 if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) {
716 instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount);
717 }
718 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
719 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i];
720 }
721 }
722}
723
724VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
725 VkInstance *pInstance) {
726 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
727
728 assert(chain_info->u.pLayerInfo);
729 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
730 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
731 if (fpCreateInstance == NULL) {
732 return VK_ERROR_INITIALIZATION_FAILED;
733 }
734
735 // Advance the link info for the next element on the chain
736 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
737
738 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
739 if (result != VK_SUCCESS) {
740 return result;
741 }
742
743 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map);
744 instance_data->instance = *pInstance;
745 initInstanceTable(*pInstance, fpGetInstanceProcAddr, ot_instance_table_map);
746 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, *pInstance);
747
748 // Look for one or more debug report create info structures, and copy the
749 // callback(s) for each one found (for use by vkDestroyInstance)
750 layer_copy_tmp_callbacks(pCreateInfo->pNext, &instance_data->num_tmp_callbacks, &instance_data->tmp_dbg_create_infos,
751 &instance_data->tmp_callbacks);
752
753 instance_data->report_data = debug_report_create_instance(pInstanceTable, *pInstance, pCreateInfo->enabledExtensionCount,
754 pCreateInfo->ppEnabledExtensionNames);
755
756 InitObjectTracker(instance_data, pAllocator);
757
758 CreateObject(*pInstance, *pInstance, kVulkanObjectTypeInstance, pAllocator);
759
760 return result;
761}
762
763VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
764 VkPhysicalDevice *pPhysicalDevices) {
765 bool skip = VK_FALSE;
766 std::unique_lock<std::mutex> lock(global_lock);
767 skip |=
768 ValidateObject(instance, instance, kVulkanObjectTypeInstance, false, VALIDATION_ERROR_2800bc01, VALIDATION_ERROR_UNDEFINED);
769 lock.unlock();
770 if (skip) {
771 return VK_ERROR_VALIDATION_FAILED_EXT;
772 }
773 VkResult result = get_dispatch_table(ot_instance_table_map, instance)
774 ->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
775 lock.lock();
776 if (result == VK_SUCCESS) {
777 if (pPhysicalDevices) {
778 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
779 CreateObject(instance, pPhysicalDevices[i], kVulkanObjectTypePhysicalDevice, nullptr);
780 }
781 }
782 }
783 lock.unlock();
784 return result;
785}
786
787VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
788 VkCommandBuffer *pCommandBuffers) {
789 bool skip = VK_FALSE;
790 std::unique_lock<std::mutex> lock(global_lock);
791 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_16805601, VALIDATION_ERROR_UNDEFINED);
792 skip |= ValidateObject(device, pAllocateInfo->commandPool, kVulkanObjectTypeCommandPool, false, VALIDATION_ERROR_02602801,
793 VALIDATION_ERROR_UNDEFINED);
794 lock.unlock();
795
796 if (skip) {
797 return VK_ERROR_VALIDATION_FAILED_EXT;
798 }
799
800 VkResult result =
801 get_dispatch_table(ot_device_table_map, device)->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
802
803 lock.lock();
804 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
805 AllocateCommandBuffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], pAllocateInfo->level);
806 }
807 lock.unlock();
808
809 return result;
810}
811
812VKAPI_ATTR VkResult VKAPI_CALL AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
813 VkDescriptorSet *pDescriptorSets) {
814 bool skip = VK_FALSE;
815 std::unique_lock<std::mutex> lock(global_lock);
816 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_16a05601, VALIDATION_ERROR_UNDEFINED);
817 skip |= ValidateObject(device, pAllocateInfo->descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_04c04601,
818 VALIDATION_ERROR_04c00009);
819 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
820 skip |= ValidateObject(device, pAllocateInfo->pSetLayouts[i], kVulkanObjectTypeDescriptorSetLayout, false,
821 VALIDATION_ERROR_04c22c01, VALIDATION_ERROR_04c00009);
822 }
823 lock.unlock();
824 if (skip) {
825 return VK_ERROR_VALIDATION_FAILED_EXT;
826 }
827
828 VkResult result =
829 get_dispatch_table(ot_device_table_map, device)->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
830
831 if (VK_SUCCESS == result) {
832 lock.lock();
833 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
834 AllocateDescriptorSet(device, pAllocateInfo->descriptorPool, pDescriptorSets[i]);
835 }
836 lock.unlock();
837 }
838
839 return result;
840}
841
842VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
843 const VkCommandBuffer *pCommandBuffers) {
844 bool skip = false;
845 std::unique_lock<std::mutex> lock(global_lock);
846 ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_28405601, VALIDATION_ERROR_UNDEFINED);
847 ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, false, VALIDATION_ERROR_28402801, VALIDATION_ERROR_28402807);
848 for (uint32_t i = 0; i < commandBufferCount; i++) {
849 if (pCommandBuffers[i] != VK_NULL_HANDLE) {
850 skip |= ValidateCommandBuffer(device, commandPool, pCommandBuffers[i]);
851 }
852 }
853
854 for (uint32_t i = 0; i < commandBufferCount; i++) {
855 DestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer, nullptr, VALIDATION_ERROR_UNDEFINED,
856 VALIDATION_ERROR_UNDEFINED);
857 }
858
859 lock.unlock();
860 if (!skip) {
861 get_dispatch_table(ot_device_table_map, device)
862 ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
863 }
864}
865
866VKAPI_ATTR void VKAPI_CALL DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
867 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
868 std::unique_lock<std::mutex> lock(global_lock);
869 // A swapchain's images are implicitly deleted when the swapchain is deleted.
870 // Remove this swapchain's images from our map of such images.
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600871 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->swapchainImageMap.begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600872 while (itr != device_data->swapchainImageMap.end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600873 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600874 if (pNode->parent_object == HandleToUint64(swapchain)) {
875 delete pNode;
876 auto delete_item = itr++;
877 device_data->swapchainImageMap.erase(delete_item);
878 } else {
879 ++itr;
880 }
881 }
882 DestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, pAllocator, VALIDATION_ERROR_26e00a06,
883 VALIDATION_ERROR_26e00a08);
884 lock.unlock();
885
886 get_dispatch_table(ot_device_table_map, device)->DestroySwapchainKHR(device, swapchain, pAllocator);
887}
888
889VKAPI_ATTR VkResult VKAPI_CALL FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
890 const VkDescriptorSet *pDescriptorSets) {
891 bool skip = false;
892 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
893 std::unique_lock<std::mutex> lock(global_lock);
894 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_28605601, VALIDATION_ERROR_UNDEFINED);
895 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false, VALIDATION_ERROR_28604601,
896 VALIDATION_ERROR_28604607);
897 for (uint32_t i = 0; i < descriptorSetCount; i++) {
898 if (pDescriptorSets[i] != VK_NULL_HANDLE) {
899 skip |= ValidateDescriptorSet(device, descriptorPool, pDescriptorSets[i]);
900 }
901 }
902
903 for (uint32_t i = 0; i < descriptorSetCount; i++) {
904 DestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet, nullptr, VALIDATION_ERROR_UNDEFINED,
905 VALIDATION_ERROR_UNDEFINED);
906 }
907
908 lock.unlock();
909 if (!skip) {
910 result = get_dispatch_table(ot_device_table_map, device)
911 ->FreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets);
912 }
913 return result;
914}
915
916VKAPI_ATTR void VKAPI_CALL DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
917 const VkAllocationCallbacks *pAllocator) {
918 bool skip = VK_FALSE;
919 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
920 std::unique_lock<std::mutex> lock(global_lock);
921 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_24405601, VALIDATION_ERROR_UNDEFINED);
922 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, true, VALIDATION_ERROR_24404601,
923 VALIDATION_ERROR_24404607);
924 lock.unlock();
925 if (skip) {
926 return;
927 }
928 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is deleted.
929 // Remove this pool's descriptor sets from our descriptorSet map.
930 lock.lock();
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600931 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600932 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600933 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600934 auto del_itr = itr++;
935 if (pNode->parent_object == HandleToUint64(descriptorPool)) {
936 DestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet, nullptr,
937 VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
938 }
939 }
940 DestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, pAllocator, VALIDATION_ERROR_24400260,
941 VALIDATION_ERROR_24400262);
942 lock.unlock();
943 get_dispatch_table(ot_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool, pAllocator);
944}
945
946VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
947 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
948 bool skip = false;
949 std::unique_lock<std::mutex> lock(global_lock);
950 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_24005601, VALIDATION_ERROR_UNDEFINED);
951 skip |= ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, true, VALIDATION_ERROR_24002801,
952 VALIDATION_ERROR_24002807);
953 lock.unlock();
954 if (skip) {
955 return;
956 }
957 lock.lock();
958 // A CommandPool's command buffers are implicitly deleted when the pool is deleted.
959 // Remove this pool's cmdBuffers from our cmd buffer map.
960 auto itr = device_data->object_map[kVulkanObjectTypeCommandBuffer].begin();
961 auto del_itr = itr;
962 while (itr != device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600963 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600964 del_itr = itr++;
965 if (pNode->parent_object == HandleToUint64(commandPool)) {
966 skip |= ValidateCommandBuffer(device, commandPool, reinterpret_cast<VkCommandBuffer>((*del_itr).first));
967 DestroyObject(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first), kVulkanObjectTypeCommandBuffer, nullptr,
968 VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
969 }
970 }
971 DestroyObject(device, commandPool, kVulkanObjectTypeCommandPool, pAllocator, VALIDATION_ERROR_24000054,
972 VALIDATION_ERROR_24000056);
973 lock.unlock();
974 get_dispatch_table(ot_device_table_map, device)->DestroyCommandPool(device, commandPool, pAllocator);
975}
976
977VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice,
978 uint32_t *pQueueFamilyPropertyCount,
979 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
980 bool skip = false;
981 {
982 std::lock_guard<std::mutex> lock(global_lock);
983 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false, VALIDATION_ERROR_UNDEFINED,
984 VALIDATION_ERROR_UNDEFINED);
985 }
986 if (skip) {
987 return;
988 }
989 get_dispatch_table(ot_instance_table_map, physicalDevice)
990 ->GetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
991 std::lock_guard<std::mutex> lock(global_lock);
992 if (pQueueFamilyProperties != NULL) {
993 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
994 if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) {
995 instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount);
996 }
997 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
998 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties;
999 }
1000 }
1001}
1002
Mark Lobodzinskidfe5e172017-07-19 13:03:22 -06001003VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001004 bool skip = VK_FALSE;
1005 std::unique_lock<std::mutex> lock(global_lock);
1006 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1007 if (pNameInfo->pObjectName) {
1008 dev_data->report_data->debugObjectNameMap->insert(
1009 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
1010 } else {
1011 dev_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
1012 }
1013 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, VALIDATION_ERROR_23605601, VALIDATION_ERROR_UNDEFINED);
1014 lock.unlock();
1015 if (skip) {
1016 return VK_ERROR_VALIDATION_FAILED_EXT;
1017 }
1018 VkResult result = dev_data->dispatch_table.DebugMarkerSetObjectNameEXT(device, pNameInfo);
1019 return result;
1020}
1021
1022VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
1023 assert(instance);
1024
1025 if (get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr == NULL) {
1026 return NULL;
1027 }
1028 return get_dispatch_table(ot_instance_table_map, instance)->GetPhysicalDeviceProcAddr(instance, funcName);
1029}
1030
1031VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) {
1032 const auto item = name_to_funcptr_map.find(funcName);
1033 if (item != name_to_funcptr_map.end()) {
1034 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
1035 }
1036
1037 auto table = get_dispatch_table(ot_device_table_map, device);
1038 if (!table->GetDeviceProcAddr) return NULL;
1039 return table->GetDeviceProcAddr(device, funcName);
1040}
1041
1042VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) {
1043 const auto item = name_to_funcptr_map.find(funcName);
1044 if (item != name_to_funcptr_map.end()) {
1045 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
1046 }
1047
1048 auto table = get_dispatch_table(ot_instance_table_map, instance);
1049 if (!table->GetInstanceProcAddr) return nullptr;
1050 return table->GetInstanceProcAddr(instance, funcName);
1051}
1052
1053} // namespace object_tracker
1054
1055VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
1056 VkExtensionProperties *pProperties) {
1057 return object_tracker::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
1058}
1059
1060VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
1061 VkLayerProperties *pProperties) {
1062 return object_tracker::EnumerateInstanceLayerProperties(pCount, pProperties);
1063}
1064
1065VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
1066 VkLayerProperties *pProperties) {
1067 // The layer command handles VK_NULL_HANDLE just fine internally
1068 assert(physicalDevice == VK_NULL_HANDLE);
1069 return object_tracker::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
1070}
1071
1072VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
1073 return object_tracker::GetDeviceProcAddr(dev, funcName);
1074}
1075
1076VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
1077 return object_tracker::GetInstanceProcAddr(instance, funcName);
1078}
1079
1080VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
1081 const char *pLayerName, uint32_t *pCount,
1082 VkExtensionProperties *pProperties) {
1083 // The layer command handles VK_NULL_HANDLE just fine internally
1084 assert(physicalDevice == VK_NULL_HANDLE);
1085 return object_tracker::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
1086}
1087
1088VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
1089 const char *funcName) {
1090 return object_tracker::GetPhysicalDeviceProcAddr(instance, funcName);
1091}
1092
1093VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
1094 assert(pVersionStruct != NULL);
1095 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
1096
1097 // Fill in the function pointers if our version is at least capable of having the structure contain them.
1098 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
1099 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
1100 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
1101 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
1102 }
1103
1104 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
1105 object_tracker::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
1106 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
1107 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
1108 }
1109
1110 return VK_SUCCESS;
1111}