blob: 54d2cb65bad0d57abb70755f7215c6290f2666fb [file] [log] [blame]
Dave Houltonb817a872018-06-26 13:22:01 -06001/* Copyright (c) 2015-2018 The Khronos Group Inc.
2 * Copyright (c) 2015-2018 Valve Corporation
3 * Copyright (c) 2015-2018 LunarG, Inc.
4 * Copyright (C) 2015-2018 Google Inc.
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06005 *
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;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060028std::mutex global_lock;
29uint64_t object_track_index = 0;
30uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
31
32void InitObjectTracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
Mark Young6ba8abe2017-11-09 10:37:04 -070033 layer_debug_messenger_actions(my_data->report_data, my_data->logging_messenger, pAllocator, "lunarg_object_tracker");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060034}
35
36// Add new queue to head of global queue list
37void AddQueueInfo(VkDevice device, uint32_t queue_node_index, VkQueue queue) {
38 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
39 auto queueItem = device_data->queue_info_map.find(queue);
40 if (queueItem == device_data->queue_info_map.end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -060041 ObjTrackQueueInfo *p_queue_info = new ObjTrackQueueInfo;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060042 if (p_queue_info != NULL) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -060043 memset(p_queue_info, 0, sizeof(ObjTrackQueueInfo));
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060044 p_queue_info->queue = queue;
45 p_queue_info->queue_node_index = queue_node_index;
46 device_data->queue_info_map[queue] = p_queue_info;
47 } else {
48 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
Dave Houltonb817a872018-06-26 13:22:01 -060049 HandleToUint64(queue), kVUID_ObjectTracker_InternalError,
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060050 "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");
51 }
52 }
53}
54
55// Destroy memRef lists and free all memory
56void DestroyQueueDataStructures(VkDevice device) {
57 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
58
59 for (auto queue_item : device_data->queue_info_map) {
60 delete queue_item.second;
61 }
62 device_data->queue_info_map.clear();
63
64 // Destroy the items in the queue map
65 auto queue = device_data->object_map[kVulkanObjectTypeQueue].begin();
66 while (queue != device_data->object_map[kVulkanObjectTypeQueue].end()) {
67 uint32_t obj_index = queue->second->object_type;
68 assert(device_data->num_total_objects > 0);
69 device_data->num_total_objects--;
70 assert(device_data->num_objects[obj_index] > 0);
71 device_data->num_objects[obj_index]--;
72 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
Dave Houltonb817a872018-06-26 13:22:01 -060073 queue->second->handle, kVUID_ObjectTracker_Info,
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060074 "OBJ_STAT Destroy Queue obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " Queue objs).",
75 queue->second->handle, device_data->num_total_objects, device_data->num_objects[obj_index]);
76 delete queue->second;
77 queue = device_data->object_map[kVulkanObjectTypeQueue].erase(queue);
78 }
79}
80
81// Check Queue type flags for selected queue operations
82void ValidateQueueFlags(VkQueue queue, const char *function) {
83 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
84 auto queue_item = device_data->queue_info_map.find(queue);
85 if (queue_item != device_data->queue_info_map.end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -060086 ObjTrackQueueInfo *pQueueInfo = queue_item->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060087 if (pQueueInfo != NULL) {
88 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(device_data->physical_device), layer_data_map);
89 if ((instance_data->queue_family_properties[pQueueInfo->queue_node_index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) ==
90 0) {
91 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
Dave Houlton57ae22f2018-05-18 16:20:52 -060092 HandleToUint64(queue), "VUID-vkQueueBindSparse-queuetype",
Mark Lobodzinski487a0d12018-03-30 10:09:03 -060093 "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set.", function);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -060094 }
95 }
96 }
97}
98
Mark Lobodzinski9bd81192017-11-13 09:38:23 -070099// Look for this device object in any of the instance child devices lists.
100// NOTE: This is of dubious value. In most circumstances Vulkan will die a flaming death if a dispatchable object is invalid.
101// However, if this layer is loaded first and GetProcAddress is used to make API calls, it will detect bad DOs.
Dave Houlton379f1422018-05-23 12:47:07 -0600102bool ValidateDeviceObject(uint64_t device_handle, const std::string &invalid_handle_code, const std::string &wrong_device_code) {
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700103 VkInstance last_instance = nullptr;
104 for (auto layer_data : layer_data_map) {
105 for (auto object : layer_data.second->object_map[kVulkanObjectTypeDevice]) {
106 // Grab last instance to use for possible error message
107 last_instance = layer_data.second->instance;
108 if (object.second->handle == device_handle) return false;
109 }
110 }
111
112 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(last_instance), layer_data_map);
113 return log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600114 invalid_handle_code, "Invalid Device Object 0x%" PRIxLEAST64 ".", device_handle);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700115}
116
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600117void AllocateCommandBuffer(VkDevice device, const VkCommandPool command_pool, const VkCommandBuffer command_buffer,
118 VkCommandBufferLevel level) {
119 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
120
121 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Dave Houltonb817a872018-06-26 13:22:01 -0600122 HandleToUint64(command_buffer), kVUID_ObjectTracker_Info, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600123 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT", HandleToUint64(command_buffer));
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600124
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600125 ObjTrackState *pNewObjNode = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600126 pNewObjNode->object_type = kVulkanObjectTypeCommandBuffer;
127 pNewObjNode->handle = HandleToUint64(command_buffer);
128 pNewObjNode->parent_object = HandleToUint64(command_pool);
129 if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
130 pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY;
131 } else {
132 pNewObjNode->status = OBJSTATUS_NONE;
133 }
134 device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)] = pNewObjNode;
135 device_data->num_objects[kVulkanObjectTypeCommandBuffer]++;
136 device_data->num_total_objects++;
137}
138
139bool ValidateCommandBuffer(VkDevice device, VkCommandPool command_pool, VkCommandBuffer command_buffer) {
140 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
141 bool skip = false;
142 uint64_t object_handle = HandleToUint64(command_buffer);
143 if (device_data->object_map[kVulkanObjectTypeCommandBuffer].find(object_handle) !=
144 device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600145 ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)];
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600146
147 if (pNode->parent_object != HandleToUint64(command_pool)) {
148 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600149 object_handle, "VUID-vkFreeCommandBuffers-pCommandBuffers-parent",
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600150 "FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600151 " belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
152 HandleToUint64(command_buffer), pNode->parent_object, HandleToUint64(command_pool));
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600153 }
154 } else {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600155 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600156 object_handle, "VUID-vkFreeCommandBuffers-pCommandBuffers-00048", "Invalid %s Object 0x%" PRIxLEAST64 ".",
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600157 object_string[kVulkanObjectTypeCommandBuffer], object_handle);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600158 }
159 return skip;
160}
161
162void AllocateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
163 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
164
165 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Dave Houltonb817a872018-06-26 13:22:01 -0600166 HandleToUint64(descriptor_set), kVUID_ObjectTracker_Info, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600167 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT", HandleToUint64(descriptor_set));
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600168
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600169 ObjTrackState *pNewObjNode = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600170 pNewObjNode->object_type = kVulkanObjectTypeDescriptorSet;
171 pNewObjNode->status = OBJSTATUS_NONE;
172 pNewObjNode->handle = HandleToUint64(descriptor_set);
173 pNewObjNode->parent_object = HandleToUint64(descriptor_pool);
174 device_data->object_map[kVulkanObjectTypeDescriptorSet][HandleToUint64(descriptor_set)] = pNewObjNode;
175 device_data->num_objects[kVulkanObjectTypeDescriptorSet]++;
176 device_data->num_total_objects++;
177}
178
179bool ValidateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
180 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
181 bool skip = false;
182 uint64_t object_handle = HandleToUint64(descriptor_set);
183 auto dsItem = device_data->object_map[kVulkanObjectTypeDescriptorSet].find(object_handle);
184 if (dsItem != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600185 ObjTrackState *pNode = dsItem->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600186
187 if (pNode->parent_object != HandleToUint64(descriptor_pool)) {
188 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600189 object_handle, "VUID-vkFreeDescriptorSets-pDescriptorSets-parent",
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600190 "FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600191 " belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 ").",
192 HandleToUint64(descriptor_set), pNode->parent_object, HandleToUint64(descriptor_pool));
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600193 }
194 } else {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600195 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600196 object_handle, "VUID-vkFreeDescriptorSets-pDescriptorSets-00310", "Invalid %s Object 0x%" PRIxLEAST64 ".",
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600197 object_string[kVulkanObjectTypeDescriptorSet], object_handle);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600198 }
199 return skip;
200}
201
Dave Houltona9df0ce2018-02-07 10:51:23 -0700202template <typename DispObj>
Chris Forbes2c600e92017-10-20 11:13:20 -0700203static bool ValidateDescriptorWrite(DispObj disp, VkWriteDescriptorSet const *desc, bool isPush) {
204 bool skip = false;
205
206 if (!isPush && desc->dstSet) {
Dave Houlton57ae22f2018-05-18 16:20:52 -0600207 skip |= ValidateObject(disp, desc->dstSet, kVulkanObjectTypeDescriptorSet, false, "VUID-VkWriteDescriptorSet-dstSet-00320",
208 "VUID-VkWriteDescriptorSet-commonparent");
Chris Forbes2c600e92017-10-20 11:13:20 -0700209 }
210
211 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
212 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
213 for (uint32_t idx2 = 0; idx2 < desc->descriptorCount; ++idx2) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700214 skip |= ValidateObject(disp, desc->pTexelBufferView[idx2], kVulkanObjectTypeBufferView, false,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600215 "VUID-VkWriteDescriptorSet-descriptorType-00323", "VUID-VkWriteDescriptorSet-commonparent");
Chris Forbes2c600e92017-10-20 11:13:20 -0700216 }
217 }
218
219 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
Dave Houltona9df0ce2018-02-07 10:51:23 -0700220 (desc->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
Chris Forbes2c600e92017-10-20 11:13:20 -0700221 (desc->descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
222 for (uint32_t idx3 = 0; idx3 < desc->descriptorCount; ++idx3) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700223 skip |= ValidateObject(disp, desc->pImageInfo[idx3].imageView, kVulkanObjectTypeImageView, false,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600224 "VUID-VkWriteDescriptorSet-descriptorType-00326", "VUID-VkDescriptorImageInfo-commonparent");
Chris Forbes2c600e92017-10-20 11:13:20 -0700225 }
226 }
227
228 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
229 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
230 (desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
231 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
232 for (uint32_t idx4 = 0; idx4 < desc->descriptorCount; ++idx4) {
233 if (desc->pBufferInfo[idx4].buffer) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700234 skip |= ValidateObject(disp, desc->pBufferInfo[idx4].buffer, kVulkanObjectTypeBuffer, false,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600235 "VUID-VkDescriptorBufferInfo-buffer-parameter", kVUIDUndefined);
Chris Forbes2c600e92017-10-20 11:13:20 -0700236 }
237 }
238 }
239
240 return skip;
241}
242
Mark Lobodzinski34f5ea62018-09-14 09:51:43 -0600243static bool PreCallValidateCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
244 VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount,
245 const VkWriteDescriptorSet *pDescriptorWrites) {
246 bool skip = false;
247 skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false,
248 "VUID-vkCmdPushDescriptorSetKHR-commandBuffer-parameter", "VUID-vkCmdPushDescriptorSetKHR-commonparent");
249 skip |= ValidateObject(commandBuffer, layout, kVulkanObjectTypePipelineLayout, false,
250 "VUID-vkCmdPushDescriptorSetKHR-layout-parameter", "VUID-vkCmdPushDescriptorSetKHR-commonparent");
251 if (pDescriptorWrites) {
252 for (uint32_t index0 = 0; index0 < descriptorWriteCount; ++index0) {
253 skip |= ValidateDescriptorWrite(commandBuffer, &pDescriptorWrites[index0], true);
254 }
255 }
256 return skip;
257}
258
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600259VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
260 VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount,
261 const VkWriteDescriptorSet *pDescriptorWrites) {
262 bool skip = false;
263 {
264 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinski34f5ea62018-09-14 09:51:43 -0600265 skip |= PreCallValidateCmdPushDescriptorSetKHR(commandBuffer, pipelineBindPoint, layout, set, descriptorWriteCount,
266 pDescriptorWrites);
267 if (skip) return;
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600268 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600269 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
270 device_data->device_dispatch_table.CmdPushDescriptorSetKHR(commandBuffer, pipelineBindPoint, layout, set, descriptorWriteCount,
271 pDescriptorWrites);
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600272}
273
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600274void CreateQueue(VkDevice device, VkQueue vkObj) {
275 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
276
277 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
Dave Houltonb817a872018-06-26 13:22:01 -0600278 HandleToUint64(vkObj), kVUID_ObjectTracker_Info, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600279 object_track_index++, "VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT", HandleToUint64(vkObj));
280
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600281 ObjTrackState *p_obj_node = NULL;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600282 auto queue_item = device_data->object_map[kVulkanObjectTypeQueue].find(HandleToUint64(vkObj));
283 if (queue_item == device_data->object_map[kVulkanObjectTypeQueue].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600284 p_obj_node = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600285 device_data->object_map[kVulkanObjectTypeQueue][HandleToUint64(vkObj)] = p_obj_node;
286 device_data->num_objects[kVulkanObjectTypeQueue]++;
287 device_data->num_total_objects++;
288 } else {
289 p_obj_node = queue_item->second;
290 }
291 p_obj_node->object_type = kVulkanObjectTypeQueue;
292 p_obj_node->status = OBJSTATUS_NONE;
293 p_obj_node->handle = HandleToUint64(vkObj);
294}
295
296void CreateSwapchainImageObject(VkDevice dispatchable_object, VkImage swapchain_image, VkSwapchainKHR swapchain) {
297 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map);
298 log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Dave Houltonb817a872018-06-26 13:22:01 -0600299 HandleToUint64(swapchain_image), kVUID_ObjectTracker_Info, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600300 object_track_index++, "SwapchainImage", HandleToUint64(swapchain_image));
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600301
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600302 ObjTrackState *pNewObjNode = new ObjTrackState;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600303 pNewObjNode->object_type = kVulkanObjectTypeImage;
304 pNewObjNode->status = OBJSTATUS_NONE;
305 pNewObjNode->handle = HandleToUint64(swapchain_image);
306 pNewObjNode->parent_object = HandleToUint64(swapchain);
307 device_data->swapchainImageMap[HandleToUint64(swapchain_image)] = pNewObjNode;
308}
309
Mark Lobodzinski5183a032018-09-13 14:44:28 -0600310bool DeviceReportUndestroyedObjects(VkDevice device, VulkanObjectType object_type, const std::string &error_code) {
311 bool skip = false;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600312 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000313 for (const auto &item : device_data->object_map[object_type]) {
314 const ObjTrackState *object_info = item.second;
Mark Lobodzinski5183a032018-09-13 14:44:28 -0600315 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[object_type],
316 object_info->handle, error_code,
317 "OBJ ERROR : For device 0x%" PRIxLEAST64 ", %s object 0x%" PRIxLEAST64 " has not been destroyed.",
318 HandleToUint64(device), object_string[object_type], object_info->handle);
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000319 }
Mark Lobodzinski5183a032018-09-13 14:44:28 -0600320 return skip;
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000321}
322
323void DeviceDestroyUndestroyedObjects(VkDevice device, VulkanObjectType object_type) {
324 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
325 while (!device_data->object_map[object_type].empty()) {
326 auto item = device_data->object_map[object_type].begin();
327
328 ObjTrackState *object_info = item->second;
329 DestroyObjectSilently(device, object_info->handle, object_type);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600330 }
331}
332
Mark Lobodzinski34f5ea62018-09-14 09:51:43 -0600333static bool PreCallValidateDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
334 dispatch_key key = get_dispatch_key(instance);
335 layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
336 bool skip = false;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600337
Mark Lobodzinski34f5ea62018-09-14 09:51:43 -0600338 // We validate here for coverage, though we'd not have made it this for with a bad instance.
339 skip |= ValidateObject(instance, instance, kVulkanObjectTypeInstance, true, "VUID-vkDestroyInstance-instance-parameter",
340 kVUIDUndefined);
341
342 // Validate that child devices have been destroyed
343 for (const auto &iit : instance_data->object_map[kVulkanObjectTypeDevice]) {
344 ObjTrackState *pNode = iit.second;
345
346 VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
347 VkDebugReportObjectTypeEXT debug_object_type = get_debug_report_enum[pNode->object_type];
348
349 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, debug_object_type, pNode->handle,
350 kVUID_ObjectTracker_ObjectLeak, "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.",
351 string_VkDebugReportObjectTypeEXT(debug_object_type), pNode->handle);
352
353 // Report any remaining objects in LL
354 skip |= ReportUndestroyedObjects(device, "VUID-vkDestroyInstance-instance-00629");
355
356 skip |= ValidateDestroyObject(instance, device, kVulkanObjectTypeDevice, pAllocator,
357 "VUID-vkDestroyInstance-instance-00630", "VUID-vkDestroyInstance-instance-00631");
358 }
359
360 ValidateDestroyObject(instance, instance, kVulkanObjectTypeInstance, pAllocator, "VUID-vkDestroyInstance-instance-00630",
361 "VUID-vkDestroyInstance-instance-00631");
362
363 return skip;
364}
365
366static void PreCallRecordDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600367 dispatch_key key = get_dispatch_key(instance);
368 layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
369
370 // Enable the temporary callback(s) here to catch cleanup issues:
Mark Young6ba8abe2017-11-09 10:37:04 -0700371 if (instance_data->num_tmp_debug_messengers > 0) {
372 layer_enable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers,
373 instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers);
374 }
375 if (instance_data->num_tmp_report_callbacks > 0) {
376 layer_enable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks,
377 instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600378 }
379
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600380 // Destroy physical devices
381 for (auto iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
382 iit != instance_data->object_map[kVulkanObjectTypePhysicalDevice].end();) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600383 ObjTrackState *pNode = iit->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600384 VkPhysicalDevice physical_device = reinterpret_cast<VkPhysicalDevice>(pNode->handle);
Mark Lobodzinskieedd7672018-09-12 18:09:49 -0600385 RecordDestroyObject(instance, physical_device, kVulkanObjectTypePhysicalDevice);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600386 iit = instance_data->object_map[kVulkanObjectTypePhysicalDevice].begin();
387 }
388
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700389 // Destroy child devices
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600390 for (auto iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
391 iit != instance_data->object_map[kVulkanObjectTypeDevice].end();) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600392 ObjTrackState *pNode = iit->second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600393 VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000394 DestroyUndestroyedObjects(device);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700395
Mark Lobodzinskieedd7672018-09-12 18:09:49 -0600396 RecordDestroyObject(instance, device, kVulkanObjectTypeDevice);
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700397 iit = instance_data->object_map[kVulkanObjectTypeDevice].begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600398 }
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700399
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600400 instance_data->object_map[kVulkanObjectTypeDevice].clear();
Mark Lobodzinski34f5ea62018-09-14 09:51:43 -0600401}
402
403static void PostCallRecordDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
404 dispatch_key key = get_dispatch_key(instance);
405 layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600406
407 // Disable and cleanup the temporary callback(s):
Mark Young6ba8abe2017-11-09 10:37:04 -0700408 layer_disable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers,
409 instance_data->tmp_debug_messengers);
410 layer_disable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks,
411 instance_data->tmp_report_callbacks);
412 if (instance_data->num_tmp_debug_messengers > 0) {
413 layer_free_tmp_debug_messengers(instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers);
414 instance_data->num_tmp_debug_messengers = 0;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600415 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700416 if (instance_data->num_tmp_report_callbacks > 0) {
417 layer_free_tmp_report_callbacks(instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks);
418 instance_data->num_tmp_report_callbacks = 0;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600419 }
420
421 // Clean up logging callback, if any
Mark Young6ba8abe2017-11-09 10:37:04 -0700422 while (instance_data->logging_messenger.size() > 0) {
423 VkDebugUtilsMessengerEXT messenger = instance_data->logging_messenger.back();
424 layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator);
425 instance_data->logging_messenger.pop_back();
426 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600427 while (instance_data->logging_callback.size() > 0) {
428 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
Mark Young6ba8abe2017-11-09 10:37:04 -0700429 layer_destroy_report_callback(instance_data->report_data, callback, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600430 instance_data->logging_callback.pop_back();
431 }
432
Mark Lobodzinskieedd7672018-09-12 18:09:49 -0600433 RecordDestroyObject(instance, instance, kVulkanObjectTypeInstance);
Gabríel Arthúr Pétursson3de74ca2018-03-18 01:50:54 +0000434
Mark Young6ba8abe2017-11-09 10:37:04 -0700435 layer_debug_utils_destroy_instance(instance_data->report_data);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600436 FreeLayerDataPtr(key, layer_data_map);
Mark Lobodzinski34f5ea62018-09-14 09:51:43 -0600437}
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600438
Mark Lobodzinski34f5ea62018-09-14 09:51:43 -0600439VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
440 dispatch_key key = get_dispatch_key(instance);
441 layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
442 {
443 std::lock_guard<std::mutex> lock(global_lock);
444 bool skip = PreCallValidateDestroyInstance(instance, pAllocator);
445 if (skip) return;
446 PreCallRecordDestroyInstance(instance, pAllocator);
447 }
448 instance_data->instance_dispatch_table.DestroyInstance(instance, pAllocator);
449 {
450 std::lock_guard<std::mutex> lock(global_lock);
451 PostCallRecordDestroyInstance(instance, pAllocator);
452 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600453}
454
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600455static bool PreCallValidateDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski9bd81192017-11-13 09:38:23 -0700456 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600457 bool skip = false;
458 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, true, "VUID-vkDestroyDevice-device-parameter", kVUIDUndefined);
459 skip |= ValidateDestroyObject(device_data->instance, device, kVulkanObjectTypeDevice, pAllocator,
460 "VUID-vkDestroyDevice-device-00379", "VUID-vkDestroyDevice-device-00380");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600461 // Report any remaining objects associated with this VkDevice object in LL
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600462 skip |= ReportUndestroyedObjects(device, "VUID-vkDestroyDevice-device-00378");
463
464 return skip;
465}
466
467static void PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
468 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
469 RecordDestroyObject(device_data->instance, device, kVulkanObjectTypeDevice);
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000470 DestroyUndestroyedObjects(device);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600471
472 // Clean up Queue's MemRef Linked Lists
473 DestroyQueueDataStructures(device);
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600474}
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600475
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600476VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
477 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
478 {
479 bool skip = false;
480 std::lock_guard<std::mutex> lock(global_lock);
481 skip = PreCallValidateDestroyDevice(device, pAllocator);
482 // Skipping down-chain destroydevice calls will hose any upstream validation layers
483 PreCallRecordDestroyDevice(device, pAllocator);
484 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600485 dispatch_key key = get_dispatch_key(device);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600486 device_data->device_dispatch_table.DestroyDevice(device, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600487 FreeLayerDataPtr(key, layer_data_map);
488}
489
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600490static bool PreCallValidateGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
491 bool skip = false;
492 skip |=
493 ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkGetDeviceQueue-device-parameter", kVUIDUndefined);
494 return skip;
495}
Mark Lobodzinski439645a2017-07-19 15:18:15 -0600496
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600497static void PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
Mark Lobodzinski439645a2017-07-19 15:18:15 -0600498 CreateQueue(device, *pQueue);
499 AddQueueInfo(device, queueFamilyIndex, *pQueue);
500}
501
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600502VKAPI_ATTR void VKAPI_CALL GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
503 {
504 std::lock_guard<std::mutex> lock(global_lock);
505 bool skip = PreCallValidateGetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
506 if (skip) return;
507 }
508 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
509 device_data->device_dispatch_table.GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
510 {
511 if (*pQueue != VK_NULL_HANDLE) {
512 std::lock_guard<std::mutex> lock(global_lock);
513 PostCallRecordGetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
514 }
515 }
516}
Yiwei Zhang991d88d2018-02-14 14:39:46 -0800517
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600518static bool PreCallValidateGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
519 bool skip = false;
520 skip |=
521 ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkGetDeviceQueue2-device-parameter", kVUIDUndefined);
522 return skip;
523}
524
525static void PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
526 CreateQueue(device, *pQueue);
527 AddQueueInfo(device, pQueueInfo->queueFamilyIndex, *pQueue);
528}
529
530VKAPI_ATTR void VKAPI_CALL GetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
531 {
532 std::lock_guard<std::mutex> lock(global_lock);
533 bool skip = PreCallValidateGetDeviceQueue2(device, pQueueInfo, pQueue);
534 if (skip) return;
535 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600536 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
537 device_data->device_dispatch_table.GetDeviceQueue2(device, pQueueInfo, pQueue);
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600538 {
539 if (*pQueue != VK_NULL_HANDLE) {
540 std::lock_guard<std::mutex> lock(global_lock);
541 PostCallRecordGetDeviceQueue2(device, pQueueInfo, pQueue);
542 }
Yiwei Zhang991d88d2018-02-14 14:39:46 -0800543 }
544}
545
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600546static bool PreCallValidateUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
547 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
548 const VkCopyDescriptorSet *pDescriptorCopies) {
549 bool skip = false;
550 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkUpdateDescriptorSets-device-parameter",
551 kVUIDUndefined);
552 if (pDescriptorCopies) {
553 for (uint32_t idx0 = 0; idx0 < descriptorCopyCount; ++idx0) {
554 if (pDescriptorCopies[idx0].dstSet) {
555 skip |= ValidateObject(device, pDescriptorCopies[idx0].dstSet, kVulkanObjectTypeDescriptorSet, false,
556 "VUID-VkCopyDescriptorSet-dstSet-parameter", "VUID-VkCopyDescriptorSet-commonparent");
557 }
558 if (pDescriptorCopies[idx0].srcSet) {
559 skip |= ValidateObject(device, pDescriptorCopies[idx0].srcSet, kVulkanObjectTypeDescriptorSet, false,
560 "VUID-VkCopyDescriptorSet-srcSet-parameter", "VUID-VkCopyDescriptorSet-commonparent");
561 }
562 }
563 }
564 if (pDescriptorWrites) {
565 for (uint32_t idx1 = 0; idx1 < descriptorWriteCount; ++idx1) {
566 skip |= ValidateDescriptorWrite(device, &pDescriptorWrites[idx1], false);
567 }
568 }
569 return skip;
570}
571
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600572VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
573 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
574 const VkCopyDescriptorSet *pDescriptorCopies) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600575 {
576 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600577 bool skip = PreCallValidateUpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
578 pDescriptorCopies);
579 if (skip) return;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600580 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600581 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
582 device_data->device_dispatch_table.UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
583 pDescriptorCopies);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600584}
585
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600586static bool PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
587 const VkComputePipelineCreateInfo *pCreateInfos,
588 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) {
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600589 bool skip = VK_FALSE;
Dave Houlton379f1422018-05-23 12:47:07 -0600590 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkCreateComputePipelines-device-parameter",
591 kVUIDUndefined);
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600592 if (pCreateInfos) {
593 for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
594 if (pCreateInfos[idx0].basePipelineHandle) {
Dave Houlton379f1422018-05-23 12:47:07 -0600595 skip |=
596 ValidateObject(device, pCreateInfos[idx0].basePipelineHandle, kVulkanObjectTypePipeline, true,
597 "VUID-VkComputePipelineCreateInfo-flags-00697", "VUID-VkComputePipelineCreateInfo-commonparent");
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600598 }
599 if (pCreateInfos[idx0].layout) {
600 skip |= ValidateObject(device, pCreateInfos[idx0].layout, kVulkanObjectTypePipelineLayout, false,
Dave Houlton379f1422018-05-23 12:47:07 -0600601 "VUID-VkComputePipelineCreateInfo-layout-parameter",
602 "VUID-VkComputePipelineCreateInfo-commonparent");
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600603 }
604 if (pCreateInfos[idx0].stage.module) {
605 skip |= ValidateObject(device, pCreateInfos[idx0].stage.module, kVulkanObjectTypeShaderModule, false,
Dave Houlton57ae22f2018-05-18 16:20:52 -0600606 "VUID-VkPipelineShaderStageCreateInfo-module-parameter", kVUIDUndefined);
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600607 }
608 }
609 }
610 if (pipelineCache) {
Dave Houlton379f1422018-05-23 12:47:07 -0600611 skip |= ValidateObject(device, pipelineCache, kVulkanObjectTypePipelineCache, true,
612 "VUID-vkCreateComputePipelines-pipelineCache-parameter",
Dave Houlton57ae22f2018-05-18 16:20:52 -0600613 "VUID-vkCreateComputePipelines-pipelineCache-parent");
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600614 }
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600615 if (skip) {
616 for (uint32_t i = 0; i < createInfoCount; i++) {
617 pPipelines[i] = VK_NULL_HANDLE;
618 }
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600619 }
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600620 return skip;
621}
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600622
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600623static void PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
624 const VkComputePipelineCreateInfo *pCreateInfos,
625 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) {
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600626 for (uint32_t idx1 = 0; idx1 < createInfoCount; ++idx1) {
627 if (pPipelines[idx1] != VK_NULL_HANDLE) {
628 CreateObject(device, pPipelines[idx1], kVulkanObjectTypePipeline, pAllocator);
629 }
630 }
Mark Lobodzinskib58fe782018-09-14 11:50:27 -0600631}
632
633VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
634 const VkComputePipelineCreateInfo *pCreateInfos,
635 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) {
636 {
637 std::lock_guard<std::mutex> lock(global_lock);
638 bool skip =
639 PreCallValidateCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
640 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
641 }
642 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
643 VkResult result = device_data->device_dispatch_table.CreateComputePipelines(device, pipelineCache, createInfoCount,
644 pCreateInfos, pAllocator, pPipelines);
645 {
646 std::lock_guard<std::mutex> lock(global_lock);
647 PostCallRecordCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
648 }
Mark Lobodzinski2d26c5f2017-07-19 12:37:04 -0600649 return result;
650}
651
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600652static bool PreCallValidateResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600653 bool skip = false;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600654 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600655
Dave Houlton379f1422018-05-23 12:47:07 -0600656 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkResetDescriptorPool-device-parameter",
657 kVUIDUndefined);
658 skip |=
659 ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false,
660 "VUID-vkResetDescriptorPool-descriptorPool-parameter", "VUID-vkResetDescriptorPool-descriptorPool-parent");
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600661 for (const auto &itr : device_data->object_map[kVulkanObjectTypeDescriptorSet]) {
662 if (itr.second->parent_object == HandleToUint64(descriptorPool)) {
663 skip |= ValidateDestroyObject(device, (VkDescriptorSet)(itr.first), kVulkanObjectTypeDescriptorSet, nullptr,
664 kVUIDUndefined, kVUIDUndefined);
665 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600666 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600667 return skip;
668}
669
670static void PreCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags) {
671 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
672
673 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is reset. Remove this pool's descriptor sets from
674 // our descriptorSet map.
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600675 auto itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
676 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -0600677 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600678 auto del_itr = itr++;
679 if (pNode->parent_object == HandleToUint64(descriptorPool)) {
Mark Lobodzinskieedd7672018-09-12 18:09:49 -0600680 RecordDestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600681 }
682 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600683}
684
685VKAPI_ATTR VkResult VKAPI_CALL ResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
686 VkDescriptorPoolResetFlags flags) {
687 {
688 std::lock_guard<std::mutex> lock(global_lock);
689 bool skip = PreCallValidateResetDescriptorPool(device, descriptorPool, flags);
690 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
691 PreCallRecordResetDescriptorPool(device, descriptorPool, flags);
692 }
693 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600694 VkResult result = device_data->device_dispatch_table.ResetDescriptorPool(device, descriptorPool, flags);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600695 return result;
696}
697
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600698static bool PreCallValidateBeginCommandBuffer(VkCommandBuffer command_buffer, const VkCommandBufferBeginInfo *begin_info) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600699 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(command_buffer), layer_data_map);
700 bool skip = false;
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600701 skip |= ValidateObject(command_buffer, command_buffer, kVulkanObjectTypeCommandBuffer, false,
702 "VUID-vkBeginCommandBuffer-commandBuffer-parameter", kVUIDUndefined);
703 if (begin_info) {
704 ObjTrackState *pNode = device_data->object_map[kVulkanObjectTypeCommandBuffer][HandleToUint64(command_buffer)];
705 if ((begin_info->pInheritanceInfo) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY) &&
706 (begin_info->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
707 skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->framebuffer, kVulkanObjectTypeFramebuffer, true,
Dave Houlton379f1422018-05-23 12:47:07 -0600708 "VUID-VkCommandBufferBeginInfo-flags-00055", "VUID-VkCommandBufferInheritanceInfo-commonparent");
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600709 skip |= ValidateObject(command_buffer, begin_info->pInheritanceInfo->renderPass, kVulkanObjectTypeRenderPass, false,
Dave Houlton379f1422018-05-23 12:47:07 -0600710 "VUID-VkCommandBufferBeginInfo-flags-00053", "VUID-VkCommandBufferInheritanceInfo-commonparent");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600711 }
712 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600713 return skip;
714}
715
716VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer command_buffer, const VkCommandBufferBeginInfo *begin_info) {
717 {
718 std::lock_guard<std::mutex> lock(global_lock);
719 bool skip = PreCallValidateBeginCommandBuffer(command_buffer, begin_info);
720 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600721 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600722 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(command_buffer), layer_data_map);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600723 VkResult result = device_data->device_dispatch_table.BeginCommandBuffer(command_buffer, begin_info);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600724 return result;
725}
726
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600727static void PostCallRecordCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
728 const VkAllocationCallbacks *pAllocator,
729 VkDebugReportCallbackEXT *pCallback) {
730 CreateObject(instance, *pCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator);
731}
732
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600733VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance,
734 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
735 const VkAllocationCallbacks *pAllocator,
736 VkDebugReportCallbackEXT *pCallback) {
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600737 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
738 VkResult result =
739 instance_data->instance_dispatch_table.CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600740 if (VK_SUCCESS == result) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700741 result = layer_create_report_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pCallback);
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600742 PostCallRecordCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600743 }
744 return result;
745}
746
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600747static bool PreCallValidateDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
748 const VkAllocationCallbacks *pAllocator) {
749 bool skip = ValidateDestroyObject(instance, msgCallback, kVulkanObjectTypeDebugReportCallbackEXT, pAllocator,
750 "VUID-vkDestroyDebugReportCallbackEXT-instance-01242",
751 "VUID-vkDestroyDebugReportCallbackEXT-instance-01243");
752 return skip;
753}
754
755static void PreCallRecordDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
756 const VkAllocationCallbacks *pAllocator) {
757 RecordDestroyObject(instance, msgCallback, kVulkanObjectTypeDebugReportCallbackEXT);
758}
759
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600760VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
761 const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600762 {
763 std::lock_guard<std::mutex> lock(global_lock);
764 bool skip = PreCallValidateDestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
765 if (skip) return;
766 PreCallRecordDestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
767 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600768 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
769 instance_data->instance_dispatch_table.DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Mark Young6ba8abe2017-11-09 10:37:04 -0700770 layer_destroy_report_callback(instance_data->report_data, msgCallback, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600771}
772
773VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags,
774 VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location,
775 int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600776 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
777 instance_data->instance_dispatch_table.DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix,
778 pMsg);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -0600779}
780
Mark Young6ba8abe2017-11-09 10:37:04 -0700781// VK_EXT_debug_utils commands
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600782
783static bool PreCallValidateSetDebugUtilsObjectNameEXT(VkDevice device, const VkDebugUtilsObjectNameInfoEXT *pNameInfo) {
784 return ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkSetDebugUtilsObjectNameEXT-device-parameter",
785 kVUIDUndefined);
786}
787
Mark Young6ba8abe2017-11-09 10:37:04 -0700788VKAPI_ATTR VkResult VKAPI_CALL SetDebugUtilsObjectNameEXT(VkDevice device, const VkDebugUtilsObjectNameInfoEXT *pNameInfo) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600789 {
790 std::lock_guard<std::mutex> lock(global_lock);
791 bool skip = PreCallValidateSetDebugUtilsObjectNameEXT(device, pNameInfo);
792 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Young6ba8abe2017-11-09 10:37:04 -0700793 }
794 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
795 if (pNameInfo->pObjectName) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600796 std::lock_guard<std::mutex> lock(global_lock);
Mark Young6ba8abe2017-11-09 10:37:04 -0700797 dev_data->report_data->debugUtilsObjectNameMap->insert(
798 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->objectHandle, pNameInfo->pObjectName));
799 } else {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600800 std::lock_guard<std::mutex> lock(global_lock);
Mark Young6ba8abe2017-11-09 10:37:04 -0700801 dev_data->report_data->debugUtilsObjectNameMap->erase(pNameInfo->objectHandle);
802 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600803 VkResult result = dev_data->device_dispatch_table.SetDebugUtilsObjectNameEXT(device, pNameInfo);
Mark Young6ba8abe2017-11-09 10:37:04 -0700804 return result;
805}
806
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600807static bool PreCallValidateSetDebugUtilsObjectTagEXT(VkDevice device, const VkDebugUtilsObjectTagInfoEXT *pTagInfo) {
808 return ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkSetDebugUtilsObjectTagEXT-device-parameter",
809 kVUIDUndefined);
810}
811
Mark Young6ba8abe2017-11-09 10:37:04 -0700812VKAPI_ATTR VkResult VKAPI_CALL SetDebugUtilsObjectTagEXT(VkDevice device, const VkDebugUtilsObjectTagInfoEXT *pTagInfo) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600813 {
814 std::lock_guard<std::mutex> lock(global_lock);
815 bool skip = PreCallValidateSetDebugUtilsObjectTagEXT(device, pTagInfo);
816 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Young6ba8abe2017-11-09 10:37:04 -0700817 }
818 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600819 VkResult result = dev_data->device_dispatch_table.SetDebugUtilsObjectTagEXT(device, pTagInfo);
Mark Young6ba8abe2017-11-09 10:37:04 -0700820 return result;
821}
822
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600823static bool PreCallValidateQueueBeginDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT *pLabelInfo) {
824 return ValidateObject(queue, queue, kVulkanObjectTypeQueue, false, "VUID-vkQueueBeginDebugUtilsLabelEXT-queue-parameter",
825 kVUIDUndefined);
826}
827
Mark Young6ba8abe2017-11-09 10:37:04 -0700828VKAPI_ATTR void VKAPI_CALL QueueBeginDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT *pLabelInfo) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700829 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600830 {
831 std::lock_guard<std::mutex> lock(global_lock);
832 bool skip = PreCallValidateQueueBeginDebugUtilsLabelEXT(queue, pLabelInfo);
833 if (skip) return;
Mark Young6ba8abe2017-11-09 10:37:04 -0700834 BeginQueueDebugUtilsLabel(dev_data->report_data, queue, pLabelInfo);
Mark Young6ba8abe2017-11-09 10:37:04 -0700835 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600836 dev_data->device_dispatch_table.QueueBeginDebugUtilsLabelEXT(queue, pLabelInfo);
837}
838
839static bool PreCallValidateQueueEndDebugUtilsLabelEXT(VkQueue queue) {
840 return ValidateObject(queue, queue, kVulkanObjectTypeQueue, false, "VUID-vkQueueEndDebugUtilsLabelEXT-queue-parameter",
841 kVUIDUndefined);
Mark Young6ba8abe2017-11-09 10:37:04 -0700842}
843
844VKAPI_ATTR void VKAPI_CALL QueueEndDebugUtilsLabelEXT(VkQueue queue) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600845 {
846 std::lock_guard<std::mutex> lock(global_lock);
847 bool skip = PreCallValidateQueueEndDebugUtilsLabelEXT(queue);
848 if (skip) return;
Mark Young6ba8abe2017-11-09 10:37:04 -0700849 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600850 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
851 dev_data->device_dispatch_table.QueueEndDebugUtilsLabelEXT(queue);
852 {
853 std::lock_guard<std::mutex> lock(global_lock);
854 EndQueueDebugUtilsLabel(dev_data->report_data, queue);
855 }
856}
857
858static bool PreCallValidateQueueInsertDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT *pLabelInfo) {
859 return ValidateObject(queue, queue, kVulkanObjectTypeQueue, false, "VUID-vkQueueInsertDebugUtilsLabelEXT-queue-parameter",
860 kVUIDUndefined);
Mark Young6ba8abe2017-11-09 10:37:04 -0700861}
862
863VKAPI_ATTR void VKAPI_CALL QueueInsertDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT *pLabelInfo) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600864 {
865 std::lock_guard<std::mutex> lock(global_lock);
866 bool skip = PreCallValidateQueueInsertDebugUtilsLabelEXT(queue, pLabelInfo);
867 if (skip) return;
Mark Young6ba8abe2017-11-09 10:37:04 -0700868 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600869 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
870 {
871 std::lock_guard<std::mutex> lock(global_lock);
872 InsertQueueDebugUtilsLabel(dev_data->report_data, queue, pLabelInfo);
873 }
874 dev_data->device_dispatch_table.QueueInsertDebugUtilsLabelEXT(queue, pLabelInfo);
875}
876
877static bool PreCallValidateCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) {
878 return ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false,
879 "VUID-vkCmdBeginDebugUtilsLabelEXT-commandBuffer-parameter", kVUIDUndefined);
Mark Young6ba8abe2017-11-09 10:37:04 -0700880}
881
882VKAPI_ATTR void VKAPI_CALL CmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600883 {
884 std::lock_guard<std::mutex> lock(global_lock);
885 bool skip = PreCallValidateCmdBeginDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
886 if (skip) return;
Mark Young6ba8abe2017-11-09 10:37:04 -0700887 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600888 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
889 {
890 std::lock_guard<std::mutex> lock(global_lock);
891 BeginCmdDebugUtilsLabel(dev_data->report_data, commandBuffer, pLabelInfo);
892 }
893 dev_data->device_dispatch_table.CmdBeginDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
894}
895
896static bool PreCallValidateCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
897 return ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false,
898 "VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-parameter", kVUIDUndefined);
Mark Young6ba8abe2017-11-09 10:37:04 -0700899}
900
901VKAPI_ATTR void VKAPI_CALL CmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600902 {
903 std::lock_guard<std::mutex> lock(global_lock);
904 bool skip = PreCallValidateCmdEndDebugUtilsLabelEXT(commandBuffer);
905 if (skip) return;
906 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700907 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600908 dev_data->device_dispatch_table.CmdEndDebugUtilsLabelEXT(commandBuffer);
909 {
910 std::lock_guard<std::mutex> lock(global_lock);
Mark Young6ba8abe2017-11-09 10:37:04 -0700911 EndCmdDebugUtilsLabel(dev_data->report_data, commandBuffer);
912 }
913}
914
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600915static bool PreCallValidateCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) {
916 return ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false,
917 "VUID-vkCmdInsertDebugUtilsLabelEXT-commandBuffer-parameter", kVUIDUndefined);
918}
919
Mark Young6ba8abe2017-11-09 10:37:04 -0700920VKAPI_ATTR void VKAPI_CALL CmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600921 {
922 std::lock_guard<std::mutex> lock(global_lock);
923 bool skip = PreCallValidateCmdInsertDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
924 if (skip) return;
Mark Young6ba8abe2017-11-09 10:37:04 -0700925 }
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600926 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
927 {
928 std::lock_guard<std::mutex> lock(global_lock);
929 InsertCmdDebugUtilsLabel(dev_data->report_data, commandBuffer, pLabelInfo);
930 }
931 dev_data->device_dispatch_table.CmdInsertDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
932}
933
934static bool PreCallValidateCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
935 const VkAllocationCallbacks *pAllocator,
936 VkDebugUtilsMessengerEXT *pMessenger) {
937 return ValidateObject(instance, instance, kVulkanObjectTypeInstance, false,
938 "VUID-vkCreateDebugUtilsMessengerEXT-instance-parameter", kVUIDUndefined);
939}
940
941static void PostCallRecordCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
942 const VkAllocationCallbacks *pAllocator,
943 VkDebugUtilsMessengerEXT *pMessenger) {
944 CreateObject(instance, *pMessenger, kVulkanObjectTypeDebugUtilsMessengerEXT, pAllocator);
Mark Young6ba8abe2017-11-09 10:37:04 -0700945}
946
947VKAPI_ATTR VkResult VKAPI_CALL CreateDebugUtilsMessengerEXT(VkInstance instance,
948 const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
949 const VkAllocationCallbacks *pAllocator,
950 VkDebugUtilsMessengerEXT *pMessenger) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600951 {
952 std::lock_guard<std::mutex> lock(global_lock);
953 bool skip = PreCallValidateCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
954 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
955 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600956 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
957 VkResult result =
958 instance_data->instance_dispatch_table.CreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
Mark Young6ba8abe2017-11-09 10:37:04 -0700959 if (VK_SUCCESS == result) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700960 result = layer_create_messenger_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMessenger);
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600961 PostCallRecordCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
Mark Young6ba8abe2017-11-09 10:37:04 -0700962 }
963 return result;
964}
965
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600966static bool PreCallValidateDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
967 const VkAllocationCallbacks *pAllocator) {
968 bool skip = false;
969 skip |= ValidateObject(instance, instance, kVulkanObjectTypeInstance, false,
970 "VUID-vkDestroyDebugUtilsMessengerEXT-instance-parameter", kVUIDUndefined);
971 skip |= ValidateObject(instance, messenger, kVulkanObjectTypeDebugUtilsMessengerEXT, false,
972 "VUID-vkDestroyDebugUtilsMessengerEXT-messenger-parameter",
973 "VUID-vkDestroyDebugUtilsMessengerEXT-messenger-parent");
974 skip |= ValidateDestroyObject(instance, messenger, kVulkanObjectTypeDebugUtilsMessengerEXT, pAllocator,
975 "VUID-vkDestroyDebugUtilsMessengerEXT-messenger-01915",
976 "VUID-vkDestroyDebugUtilsMessengerEXT-messenger-01916");
977 return skip;
978}
979
980static void PreCallRecordDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
981 const VkAllocationCallbacks *pAllocator) {
982 RecordDestroyObject(instance, messenger, kVulkanObjectTypeDebugUtilsMessengerEXT);
983}
984
Mark Young6ba8abe2017-11-09 10:37:04 -0700985VKAPI_ATTR void VKAPI_CALL DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
986 const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600987 {
988 std::lock_guard<std::mutex> lock(global_lock);
989 bool skip = PreCallValidateDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
990 if (skip) return;
991 PreCallRecordDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
992 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -0600993 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
994 instance_data->instance_dispatch_table.DestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
Mark Young6ba8abe2017-11-09 10:37:04 -0700995 layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator);
Mark Lobodzinski0de500d2018-09-14 15:14:01 -0600996}
997
998static bool PreCallValidateSubmitDebugUtilsMessageEXT(VkInstance instance, VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
999 VkDebugUtilsMessageTypeFlagsEXT messageTypes,
1000 const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData) {
1001 bool skip = false;
1002 skip |= ValidateObject(instance, instance, kVulkanObjectTypeInstance, false,
1003 "VUID-vkeSubmitDebugUtilsMessageEXT-instance-parameter", kVUIDUndefined);
1004 return skip;
Mark Young6ba8abe2017-11-09 10:37:04 -07001005}
1006
1007VKAPI_ATTR void VKAPI_CALL SubmitDebugUtilsMessageEXT(VkInstance instance, VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
1008 VkDebugUtilsMessageTypeFlagsEXT messageTypes,
1009 const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData) {
Mark Lobodzinski0de500d2018-09-14 15:14:01 -06001010 {
1011 std::lock_guard<std::mutex> lock(global_lock);
1012 bool skip = PreCallValidateSubmitDebugUtilsMessageEXT(instance, messageSeverity, messageTypes, pCallbackData);
1013 if (skip) return;
1014 }
1015
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001016 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
1017 instance_data->instance_dispatch_table.SubmitDebugUtilsMessageEXT(instance, messageSeverity, messageTypes, pCallbackData);
Mark Young6ba8abe2017-11-09 10:37:04 -07001018}
1019
1020static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION},
1021 {VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION}};
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001022
1023static const VkLayerProperties globalLayerProps = {"VK_LAYER_LUNARG_object_tracker",
1024 VK_LAYER_API_VERSION, // specVersion
1025 1, // implementationVersion
1026 "LunarG Validation Layer"};
1027
1028VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
1029 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
1030}
1031
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001032static bool PreCallValidateEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
1033 VkLayerProperties *pProperties) {
1034 // Set null_allowed to true here to cover for the lame loader-layer interface wrapper calls
1035 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, true,
1036 "VUID-vkEnumerateDeviceLayerProperties-physicalDevice-parameter", kVUIDUndefined);
1037}
1038
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001039VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
1040 VkLayerProperties *pProperties) {
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001041 {
1042 std::lock_guard<std::mutex> lock(global_lock);
1043 bool skip = PreCallValidateEnumerateDeviceLayerProperties(physicalDevice, pCount, pProperties);
1044 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1045 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001046 return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);
1047}
1048
1049VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
1050 VkExtensionProperties *pProperties) {
1051 if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))
1052 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
1053
1054 return VK_ERROR_LAYER_NOT_PRESENT;
1055}
1056
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001057static bool PreCallValidateEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
1058 uint32_t *pCount, VkExtensionProperties *pProperties) {
1059 // Set null_allowed to true here to cover for the lame loader-layer interface wrapper calls
1060 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, true,
1061 "VUID-vkEnumerateDeviceExtensionProperties-physicalDevice-parameter", kVUIDUndefined);
1062}
1063
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001064VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
1065 uint32_t *pCount, VkExtensionProperties *pProperties) {
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001066 {
1067 std::lock_guard<std::mutex> lock(global_lock);
1068 bool skip = PreCallValidateEnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pCount, pProperties);
1069 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1070 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001071 if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))
1072 return util_GetExtensionProperties(0, nullptr, pCount, pProperties);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001073 auto instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1074 return instance_data->instance_dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001075}
1076
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001077static bool PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
1078 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
1079 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1080 "VUID-vkCreateDevice-physicalDevice-parameter", kVUIDUndefined);
1081}
1082
1083static void PostCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
1084 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
1085 layer_data *phy_dev_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1086 CreateObject(phy_dev_data->instance, *pDevice, kVulkanObjectTypeDevice, pAllocator);
1087}
1088
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001089VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
1090 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
1091 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001092 bool skip = PreCallValidateCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001093 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1094
1095 layer_data *phy_dev_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1096 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1097
1098 assert(chain_info->u.pLayerInfo);
1099 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1100 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1101 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(phy_dev_data->instance, "vkCreateDevice");
1102 if (fpCreateDevice == NULL) {
1103 return VK_ERROR_INITIALIZATION_FAILED;
1104 }
1105
1106 // Advance the link info for the next element on the chain
1107 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1108
1109 VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
1110 if (result != VK_SUCCESS) {
1111 return result;
1112 }
1113
1114 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
Mark Young6ba8abe2017-11-09 10:37:04 -07001115 device_data->report_data = layer_debug_utils_create_device(phy_dev_data->report_data, *pDevice);
John Zulauf9b777302018-10-08 11:15:51 -06001116 layer_init_device_dispatch_table(*pDevice, &device_data->device_dispatch_table, fpGetDeviceProcAddr);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001117
Mark Lobodzinskif42ced62018-07-02 12:59:27 -06001118 // Save pCreateInfo device extension list for GetDeviceProcAddr()
1119 for (uint32_t extn = 0; extn < pCreateInfo->enabledExtensionCount; extn++) {
1120 device_data->device_extension_set.insert(pCreateInfo->ppEnabledExtensionNames[extn]);
1121 }
1122
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001123 // Add link back to physDev
1124 device_data->physical_device = physicalDevice;
Mark Lobodzinski9bd81192017-11-13 09:38:23 -07001125 device_data->instance = phy_dev_data->instance;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001126
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001127 PostCallRecordCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001128
1129 return result;
1130}
1131
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001132static bool PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
1133 VkImage *pSwapchainImages) {
1134 bool skip = false;
1135 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkGetSwapchainImagesKHR-device-parameter",
1136 "VUID-vkGetSwapchainImagesKHR-commonparent");
1137 skip |= ValidateObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, false,
1138 "VUID-vkGetSwapchainImagesKHR-swapchain-parameter", "VUID-vkGetSwapchainImagesKHR-commonparent");
1139 return skip;
1140}
1141
1142static void PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
1143 VkImage *pSwapchainImages) {
1144 if (pSwapchainImages != NULL) {
1145 for (uint32_t i = 0; i < *pSwapchainImageCount; i++) {
1146 CreateSwapchainImageObject(device, pSwapchainImages[i], swapchain);
1147 }
1148 }
1149}
1150
Mark Lobodzinski216843a2017-07-21 13:23:13 -06001151VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
1152 VkImage *pSwapchainImages) {
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001153 {
1154 std::lock_guard<std::mutex> lock(global_lock);
1155 bool skip = PreCallValidateGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
1156 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1157 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001158 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1159 VkResult result =
1160 device_data->device_dispatch_table.GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001161 {
1162 std::lock_guard<std::mutex> lock(global_lock);
1163 PostCallRecordGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
Mark Lobodzinski216843a2017-07-21 13:23:13 -06001164 }
1165 return result;
1166}
1167
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001168static bool PreCallValidateCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1169 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
Petr Kraus42f6f8d2017-12-17 17:37:33 +01001170 bool skip = false;
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001171 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkCreateDescriptorSetLayout-device-parameter",
1172 kVUIDUndefined);
1173 if (pCreateInfo) {
1174 if (pCreateInfo->pBindings) {
1175 for (uint32_t binding_index = 0; binding_index < pCreateInfo->bindingCount; ++binding_index) {
1176 const VkDescriptorSetLayoutBinding &binding = pCreateInfo->pBindings[binding_index];
1177 const bool is_sampler_type = binding.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
1178 binding.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
1179 if (binding.pImmutableSamplers && is_sampler_type) {
1180 for (uint32_t index2 = 0; index2 < binding.descriptorCount; ++index2) {
1181 const VkSampler sampler = binding.pImmutableSamplers[index2];
1182 skip |= ValidateObject(device, sampler, kVulkanObjectTypeSampler, false,
1183 "VUID-VkDescriptorSetLayoutBinding-descriptorType-00282", kVUIDUndefined);
Petr Kraus42f6f8d2017-12-17 17:37:33 +01001184 }
1185 }
1186 }
1187 }
1188 }
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001189 return skip;
1190}
1191
1192static void PostCallRecordCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1193 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1194 CreateObject(device, *pSetLayout, kVulkanObjectTypeDescriptorSetLayout, pAllocator);
1195}
1196
1197VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1198 const VkAllocationCallbacks *pAllocator,
1199 VkDescriptorSetLayout *pSetLayout) {
1200 {
1201 std::lock_guard<std::mutex> lock(global_lock);
1202 bool skip = PreCallValidateCreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
1203 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1204 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001205 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1206 VkResult result = device_data->device_dispatch_table.CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Petr Kraus42f6f8d2017-12-17 17:37:33 +01001207 if (VK_SUCCESS == result) {
1208 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskibe4b3452018-09-14 16:14:33 -06001209 PostCallRecordCreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Petr Kraus42f6f8d2017-12-17 17:37:33 +01001210 }
1211 return result;
1212}
1213
Mark Lobodzinski88a1a662018-07-02 14:09:39 -06001214static inline bool ValidateSamplerObjects(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo) {
1215 bool skip = false;
1216 if (pCreateInfo->pBindings) {
1217 for (uint32_t index1 = 0; index1 < pCreateInfo->bindingCount; ++index1) {
1218 for (uint32_t index2 = 0; index2 < pCreateInfo->pBindings[index1].descriptorCount; ++index2) {
1219 if (pCreateInfo->pBindings[index1].pImmutableSamplers) {
1220 skip |=
1221 ValidateObject(device, pCreateInfo->pBindings[index1].pImmutableSamplers[index2], kVulkanObjectTypeSampler,
1222 true, "VUID-VkDescriptorSetLayoutBinding-descriptorType-00282", kVUIDUndefined);
1223 }
1224 }
1225 }
1226 }
1227 return skip;
1228}
1229
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001230static bool PreCallValidateGetDescriptorSetLayoutSupport(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1231 VkDescriptorSetLayoutSupport *pSupport) {
1232 bool skip = ValidateObject(device, device, kVulkanObjectTypeDevice, false,
1233 "VUID-vkGetDescriptorSetLayoutSupport-device-parameter", kVUIDUndefined);
1234 if (pCreateInfo) {
1235 skip |= ValidateSamplerObjects(device, pCreateInfo);
1236 }
1237 return skip;
1238}
1239
Mark Lobodzinski5a1c8d22018-07-02 10:28:12 -06001240VKAPI_ATTR void VKAPI_CALL GetDescriptorSetLayoutSupport(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1241 VkDescriptorSetLayoutSupport *pSupport) {
1242 bool skip = false;
1243 {
1244 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001245 skip = PreCallValidateGetDescriptorSetLayoutSupport(device, pCreateInfo, pSupport);
Mark Lobodzinski5a1c8d22018-07-02 10:28:12 -06001246 }
1247 if (skip) return;
1248 GetLayerDataPtr(get_dispatch_key(device), layer_data_map)
1249 ->device_dispatch_table.GetDescriptorSetLayoutSupport(device, pCreateInfo, pSupport);
1250}
1251
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001252static bool PreCallValidateGetDescriptorSetLayoutSupportKHR(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1253 VkDescriptorSetLayoutSupport *pSupport) {
1254 bool skip = ValidateObject(device, device, kVulkanObjectTypeDevice, false,
1255 "VUID-vkGetDescriptorSetLayoutSupportKHR-device-parameter", kVUIDUndefined);
1256 if (pCreateInfo) {
1257 skip |= ValidateSamplerObjects(device, pCreateInfo);
1258 }
1259 return skip;
1260}
1261
Mark Lobodzinski5a1c8d22018-07-02 10:28:12 -06001262VKAPI_ATTR void VKAPI_CALL GetDescriptorSetLayoutSupportKHR(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1263 VkDescriptorSetLayoutSupport *pSupport) {
1264 bool skip = false;
1265 {
1266 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001267 skip = PreCallValidateGetDescriptorSetLayoutSupport(device, pCreateInfo, pSupport);
Mark Lobodzinski5a1c8d22018-07-02 10:28:12 -06001268 }
1269 if (skip) return;
1270 GetLayerDataPtr(get_dispatch_key(device), layer_data_map)
1271 ->device_dispatch_table.GetDescriptorSetLayoutSupportKHR(device, pCreateInfo, pSupport);
1272}
1273
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001274static bool PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
1275 uint32_t *pQueueFamilyPropertyCount,
1276 VkQueueFamilyProperties *pQueueFamilyProperties) {
1277 bool skip = ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1278 "VUID-vkGetPhysicalDeviceQueueFamilyProperties-physicalDevice-parameter", kVUIDUndefined);
1279 return skip;
1280}
1281static void PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001282 uint32_t *pQueueFamilyPropertyCount,
1283 VkQueueFamilyProperties *pQueueFamilyProperties) {
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001284 if (pQueueFamilyProperties != NULL) {
1285 auto instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1286 if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) {
1287 instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount);
1288 }
1289 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
1290 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i];
1291 }
1292 }
1293}
1294
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001295VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
1296 uint32_t *pQueueFamilyPropertyCount,
1297 VkQueueFamilyProperties *pQueueFamilyProperties) {
1298 bool skip = false;
1299 {
1300 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001301 skip |= PreCallValidateGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount,
1302 pQueueFamilyProperties);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001303 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001304 if (skip) return;
1305
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001306 auto instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1307 instance_data->instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount,
1308 pQueueFamilyProperties);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001309 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001310 PostCallRecordGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
1311}
1312
1313static void PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1314 VkInstance *pInstance) {
1315 CreateObject(*pInstance, *pInstance, kVulkanObjectTypeInstance, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001316}
1317
1318VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1319 VkInstance *pInstance) {
1320 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1321
1322 assert(chain_info->u.pLayerInfo);
1323 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1324 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
1325 if (fpCreateInstance == NULL) {
1326 return VK_ERROR_INITIALIZATION_FAILED;
1327 }
1328
1329 // Advance the link info for the next element on the chain
1330 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1331
1332 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1333 if (result != VK_SUCCESS) {
1334 return result;
1335 }
1336
1337 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map);
1338 instance_data->instance = *pInstance;
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001339 layer_init_instance_dispatch_table(*pInstance, &instance_data->instance_dispatch_table, fpGetInstanceProcAddr);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001340
1341 // Look for one or more debug report create info structures, and copy the
1342 // callback(s) for each one found (for use by vkDestroyInstance)
Mark Young6ba8abe2017-11-09 10:37:04 -07001343 layer_copy_tmp_debug_messengers(pCreateInfo->pNext, &instance_data->num_tmp_debug_messengers,
1344 &instance_data->tmp_messenger_create_infos, &instance_data->tmp_debug_messengers);
1345 layer_copy_tmp_report_callbacks(pCreateInfo->pNext, &instance_data->num_tmp_report_callbacks,
1346 &instance_data->tmp_report_create_infos, &instance_data->tmp_report_callbacks);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001347
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001348 instance_data->report_data =
1349 debug_utils_create_instance(&instance_data->instance_dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount,
1350 pCreateInfo->ppEnabledExtensionNames);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001351
1352 InitObjectTracker(instance_data, pAllocator);
1353
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001354 PostCallRecordCreateInstance(pCreateInfo, pAllocator, pInstance);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001355
1356 return result;
1357}
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001358static bool PreCallValidateEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
1359 VkPhysicalDevice *pPhysicalDevices) {
1360 bool skip = ValidateObject(instance, instance, kVulkanObjectTypeInstance, false,
1361 "VUID-vkEnumeratePhysicalDevices-instance-parameter", kVUIDUndefined);
1362 return skip;
1363}
1364static void PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
1365 VkPhysicalDevice *pPhysicalDevices) {
1366 if (pPhysicalDevices) {
1367 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
1368 CreateObject(instance, pPhysicalDevices[i], kVulkanObjectTypePhysicalDevice, nullptr);
1369 }
1370 }
1371}
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001372
1373VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
1374 VkPhysicalDevice *pPhysicalDevices) {
1375 bool skip = VK_FALSE;
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001376 {
1377 std::lock_guard<std::mutex> lock(global_lock);
1378 skip |= PreCallValidateEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001379 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001380 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1381
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001382 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
1383 VkResult result =
1384 instance_data->instance_dispatch_table.EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001385
Tony-LunarG2b0915e2018-10-31 16:02:40 -06001386 if (result == VK_SUCCESS || result == VK_INCOMPLETE) {
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001387 std::lock_guard<std::mutex> lock(global_lock);
1388 PostCallRecordEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001389 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001390 return result;
1391}
1392
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001393static bool PreCallValidateAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
1394 VkCommandBuffer *pCommandBuffers) {
1395 bool skip = false;
1396 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkAllocateCommandBuffers-device-parameter",
1397 kVUIDUndefined);
1398 skip |= ValidateObject(device, pAllocateInfo->commandPool, kVulkanObjectTypeCommandPool, false,
1399 "VUID-VkCommandBufferAllocateInfo-commandPool-parameter", kVUIDUndefined);
1400 return skip;
1401}
1402
1403static void PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
1404 VkCommandBuffer *pCommandBuffers) {
1405 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
1406 AllocateCommandBuffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], pAllocateInfo->level);
1407 }
1408}
1409
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001410VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
1411 VkCommandBuffer *pCommandBuffers) {
1412 bool skip = VK_FALSE;
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001413 {
1414 std::unique_lock<std::mutex> lock(global_lock);
1415 skip = PreCallValidateAllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001416 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001417 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001418
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001419 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1420 VkResult result = device_data->device_dispatch_table.AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001421 if (VK_SUCCESS == result) {
1422 std::unique_lock<std::mutex> lock(global_lock);
1423 PostCallRecordAllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001424 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001425
1426 return result;
1427}
1428
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001429static bool PreCallValidateAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
1430 VkDescriptorSet *pDescriptorSets) {
1431 bool skip = false;
Dave Houlton379f1422018-05-23 12:47:07 -06001432 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkAllocateDescriptorSets-device-parameter",
1433 kVUIDUndefined);
1434 skip |= ValidateObject(device, pAllocateInfo->descriptorPool, kVulkanObjectTypeDescriptorPool, false,
1435 "VUID-VkDescriptorSetAllocateInfo-descriptorPool-parameter",
Dave Houlton57ae22f2018-05-18 16:20:52 -06001436 "VUID-VkDescriptorSetAllocateInfo-commonparent");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001437 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
1438 skip |= ValidateObject(device, pAllocateInfo->pSetLayouts[i], kVulkanObjectTypeDescriptorSetLayout, false,
Dave Houlton379f1422018-05-23 12:47:07 -06001439 "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-parameter",
1440 "VUID-VkDescriptorSetAllocateInfo-commonparent");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001441 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001442 return skip;
1443}
1444
1445static void PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
1446 VkDescriptorSet *pDescriptorSets) {
1447 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
1448 AllocateDescriptorSet(device, pAllocateInfo->descriptorPool, pDescriptorSets[i]);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001449 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001450}
1451
1452VKAPI_ATTR VkResult VKAPI_CALL AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
1453 VkDescriptorSet *pDescriptorSets) {
1454 bool skip = VK_FALSE;
1455 {
1456 std::unique_lock<std::mutex> lock(global_lock);
1457 skip = PreCallValidateAllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
1458 }
1459 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001460
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001461 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1462 VkResult result = device_data->device_dispatch_table.AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001463
1464 if (VK_SUCCESS == result) {
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001465 std::unique_lock<std::mutex> lock(global_lock);
1466 PostCallRecordAllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001467 }
1468
1469 return result;
1470}
1471
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001472static bool PreCallValidateFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001473 const VkCommandBuffer *pCommandBuffers) {
1474 bool skip = false;
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001475 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkFreeCommandBuffers-device-parameter",
1476 kVUIDUndefined);
1477 skip |= ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, false,
1478 "VUID-vkFreeCommandBuffers-commandPool-parameter", "VUID-vkFreeCommandBuffers-commandPool-parent");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001479 for (uint32_t i = 0; i < commandBufferCount; i++) {
1480 if (pCommandBuffers[i] != VK_NULL_HANDLE) {
1481 skip |= ValidateCommandBuffer(device, commandPool, pCommandBuffers[i]);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001482 skip |= ValidateDestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer, nullptr, kVUIDUndefined,
1483 kVUIDUndefined);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001484 }
1485 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001486 return skip;
1487}
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001488
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001489static void PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
1490 const VkCommandBuffer *pCommandBuffers) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001491 for (uint32_t i = 0; i < commandBufferCount; i++) {
Mark Lobodzinskieedd7672018-09-12 18:09:49 -06001492 RecordDestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001493 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001494}
1495
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001496VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
1497 const VkCommandBuffer *pCommandBuffers) {
1498 bool skip = false;
1499 {
1500 std::unique_lock<std::mutex> lock(global_lock);
1501 skip = PreCallValidateFreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
1502 if (skip) return;
1503 PreCallRecordFreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
1504 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001505 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001506 device_data->device_dispatch_table.FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
1507}
1508
1509static bool PreCallValidateDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
1510 return ValidateDestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, pAllocator,
1511 "VUID-vkDestroySwapchainKHR-swapchain-01283", "VUID-vkDestroySwapchainKHR-swapchain-01284");
1512}
1513
1514static void PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
1515 RecordDestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR);
1516 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskiefc64392017-07-18 13:15:47 -06001517 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->swapchainImageMap.begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001518 while (itr != device_data->swapchainImageMap.end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -06001519 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001520 if (pNode->parent_object == HandleToUint64(swapchain)) {
1521 delete pNode;
1522 auto delete_item = itr++;
1523 device_data->swapchainImageMap.erase(delete_item);
1524 } else {
1525 ++itr;
1526 }
1527 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001528}
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001529
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001530VKAPI_ATTR void VKAPI_CALL DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
1531 bool skip = false;
1532 {
1533 std::unique_lock<std::mutex> lock(global_lock);
1534 skip = PreCallValidateDestroySwapchainKHR(device, swapchain, pAllocator);
1535 if (skip) return;
1536 PreCallRecordDestroySwapchainKHR(device, swapchain, pAllocator);
1537 }
1538 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001539 device_data->device_dispatch_table.DestroySwapchainKHR(device, swapchain, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001540}
1541
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001542static bool PreCallValidateFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001543 const VkDescriptorSet *pDescriptorSets) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001544 bool skip = false;
Dave Houlton379f1422018-05-23 12:47:07 -06001545 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkFreeDescriptorSets-device-parameter",
1546 kVUIDUndefined);
1547 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false,
1548 "VUID-vkFreeDescriptorSets-descriptorPool-parameter", "VUID-vkFreeDescriptorSets-descriptorPool-parent");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001549 for (uint32_t i = 0; i < descriptorSetCount; i++) {
1550 if (pDescriptorSets[i] != VK_NULL_HANDLE) {
1551 skip |= ValidateDescriptorSet(device, descriptorPool, pDescriptorSets[i]);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001552 skip |= ValidateDestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet, nullptr, kVUIDUndefined,
1553 kVUIDUndefined);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001554 }
1555 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001556 return skip;
1557}
1558static void PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001559 const VkDescriptorSet *pDescriptorSets) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001560 for (uint32_t i = 0; i < descriptorSetCount; i++) {
Mark Lobodzinskieedd7672018-09-12 18:09:49 -06001561 RecordDestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001562 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001563}
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001564
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001565VKAPI_ATTR VkResult VKAPI_CALL FreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1566 const VkDescriptorSet *pDescriptorSets) {
1567 bool skip = false;
1568 {
1569 std::unique_lock<std::mutex> lock(global_lock);
1570 skip = PreCallValidateFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets);
1571 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1572 PreCallRecordFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001573 }
Mark Lobodzinski1c7fa372018-09-17 11:35:00 -06001574 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1575 return device_data->device_dispatch_table.FreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001576}
1577
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001578static bool PreCallValidateDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001579 const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001580 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001581 bool skip = false;
Dave Houlton379f1422018-05-23 12:47:07 -06001582 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkDestroyDescriptorPool-device-parameter",
1583 kVUIDUndefined);
1584 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, true,
1585 "VUID-vkDestroyDescriptorPool-descriptorPool-parameter",
Dave Houlton57ae22f2018-05-18 16:20:52 -06001586 "VUID-vkDestroyDescriptorPool-descriptorPool-parent");
Mark Lobodzinskiefc64392017-07-18 13:15:47 -06001587 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001588 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -06001589 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001590 auto del_itr = itr++;
1591 if (pNode->parent_object == HandleToUint64(descriptorPool)) {
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001592 skip |= ValidateDestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet, nullptr,
1593 kVUIDUndefined, kVUIDUndefined);
1594 }
1595 }
1596 skip |= ValidateDestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, pAllocator,
1597 "VUID-vkDestroyDescriptorPool-descriptorPool-00304",
1598 "VUID-vkDestroyDescriptorPool-descriptorPool-00305");
1599 return skip;
1600}
1601static void PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1602 const VkAllocationCallbacks *pAllocator) {
1603 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1604 std::unordered_map<uint64_t, ObjTrackState *>::iterator itr = device_data->object_map[kVulkanObjectTypeDescriptorSet].begin();
1605 while (itr != device_data->object_map[kVulkanObjectTypeDescriptorSet].end()) {
1606 ObjTrackState *pNode = (*itr).second;
1607 auto del_itr = itr++;
1608 if (pNode->parent_object == HandleToUint64(descriptorPool)) {
Mark Lobodzinskieedd7672018-09-12 18:09:49 -06001609 RecordDestroyObject(device, (VkDescriptorSet)((*del_itr).first), kVulkanObjectTypeDescriptorSet);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001610 }
1611 }
Mark Lobodzinskieedd7672018-09-12 18:09:49 -06001612 RecordDestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001613}
1614
1615VKAPI_ATTR void VKAPI_CALL DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1616 const VkAllocationCallbacks *pAllocator) {
1617 bool skip = false;
1618 {
1619 std::unique_lock<std::mutex> lock(global_lock);
1620 skip = PreCallValidateDestroyDescriptorPool(device, descriptorPool, pAllocator);
1621 if (skip) return;
1622 PreCallRecordDestroyDescriptorPool(device, descriptorPool, pAllocator);
1623 }
1624 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001625 device_data->device_dispatch_table.DestroyDescriptorPool(device, descriptorPool, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001626}
1627
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001628static bool PreCallValidateDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001629 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1630 bool skip = false;
Dave Houlton379f1422018-05-23 12:47:07 -06001631 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkDestroyCommandPool-device-parameter",
1632 kVUIDUndefined);
1633 skip |= ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, true,
1634 "VUID-vkDestroyCommandPool-commandPool-parameter", "VUID-vkDestroyCommandPool-commandPool-parent");
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001635 auto itr = device_data->object_map[kVulkanObjectTypeCommandBuffer].begin();
1636 auto del_itr = itr;
1637 while (itr != device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) {
Mark Lobodzinskiefc64392017-07-18 13:15:47 -06001638 ObjTrackState *pNode = (*itr).second;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001639 del_itr = itr++;
1640 if (pNode->parent_object == HandleToUint64(commandPool)) {
1641 skip |= ValidateCommandBuffer(device, commandPool, reinterpret_cast<VkCommandBuffer>((*del_itr).first));
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001642 skip |= ValidateDestroyObject(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first),
1643 kVulkanObjectTypeCommandBuffer, nullptr, kVUIDUndefined, kVUIDUndefined);
1644 }
1645 }
1646 skip |= ValidateDestroyObject(device, commandPool, kVulkanObjectTypeCommandPool, pAllocator,
1647 "VUID-vkDestroyCommandPool-commandPool-00042", "VUID-vkDestroyCommandPool-commandPool-00043");
1648 return skip;
1649}
1650
1651static void PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
1652 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1653 auto itr = device_data->object_map[kVulkanObjectTypeCommandBuffer].begin();
1654 auto del_itr = itr;
1655 // A CommandPool's cmd buffers are implicitly deleted when pool is deleted. Remove this pool's cmdBuffers from cmd buffer map.
1656 while (itr != device_data->object_map[kVulkanObjectTypeCommandBuffer].end()) {
1657 ObjTrackState *pNode = (*itr).second;
1658 del_itr = itr++;
1659 if (pNode->parent_object == HandleToUint64(commandPool)) {
Mark Lobodzinskieedd7672018-09-12 18:09:49 -06001660 RecordDestroyObject(device, reinterpret_cast<VkCommandBuffer>((*del_itr).first), kVulkanObjectTypeCommandBuffer);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001661 }
1662 }
Mark Lobodzinskieedd7672018-09-12 18:09:49 -06001663 RecordDestroyObject(device, commandPool, kVulkanObjectTypeCommandPool);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001664}
1665
1666VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
1667 bool skip = false;
1668 {
1669 std::unique_lock<std::mutex> lock(global_lock);
1670 skip = PreCallValidateDestroyCommandPool(device, commandPool, pAllocator);
1671 if (skip) return;
1672 PreCallRecordDestroyCommandPool(device, commandPool, pAllocator);
1673 }
1674 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001675 device_data->device_dispatch_table.DestroyCommandPool(device, commandPool, pAllocator);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001676}
1677
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001678static bool PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
1679 uint32_t *pQueueFamilyPropertyCount,
1680 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
1681 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1682 "VUID-vkGetPhysicalDeviceQueueFamilyProperties2-physicalDevice-parameter", kVUIDUndefined);
1683}
1684
1685static void PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
1686 uint32_t *pQueueFamilyPropertyCount,
1687 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
1688 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1689 if (pQueueFamilyProperties != NULL) {
1690 if (instance_data->queue_family_properties.size() < *pQueueFamilyPropertyCount) {
1691 instance_data->queue_family_properties.resize(*pQueueFamilyPropertyCount);
1692 }
1693 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; i++) {
1694 instance_data->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties;
1695 }
1696 }
1697}
1698
Mark Lobodzinski14ddc192017-10-25 16:57:04 -06001699VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
1700 uint32_t *pQueueFamilyPropertyCount,
1701 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
1702 bool skip = false;
1703 {
1704 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001705 skip |= PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount,
1706 pQueueFamilyProperties);
Mark Lobodzinski14ddc192017-10-25 16:57:04 -06001707 }
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001708 if (skip) return;
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001709 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1710 instance_data->instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount,
1711 pQueueFamilyProperties);
Mark Lobodzinski14ddc192017-10-25 16:57:04 -06001712 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001713 PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
Mark Lobodzinski14ddc192017-10-25 16:57:04 -06001714}
1715
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001716VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice,
1717 uint32_t *pQueueFamilyPropertyCount,
1718 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
1719 bool skip = false;
1720 {
1721 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001722 skip |= PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount,
1723 pQueueFamilyProperties);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001724 }
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001725 if (skip) return;
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001726 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001727 instance_data->instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount,
1728 pQueueFamilyProperties);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001729 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001730 PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
1731}
1732
1733static bool PreCallValidateGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1734 VkDisplayPropertiesKHR *pProperties) {
1735 bool skip = ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1736 "VUID-vkGetPhysicalDeviceDisplayPropertiesKHR-physicalDevice-parameter", kVUIDUndefined);
1737 return skip;
1738}
1739
1740static void PostCallRecordGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1741 VkDisplayPropertiesKHR *pProperties) {
1742 if (pProperties) {
1743 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
1744 CreateObject(physicalDevice, pProperties[i].display, kVulkanObjectTypeDisplayKHR, nullptr);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001745 }
1746 }
1747}
1748
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001749VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1750 VkDisplayPropertiesKHR *pProperties) {
1751 bool skip = false;
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001752 {
1753 std::lock_guard<std::mutex> lock(global_lock);
1754 skip |= PreCallValidateGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties);
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001755 }
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001756 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1757
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001758 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1759 VkResult result =
1760 instance_data->instance_dispatch_table.GetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties);
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001761
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001762 if (result == VK_SUCCESS || result == VK_INCOMPLETE) {
1763 std::lock_guard<std::mutex> lock(global_lock);
1764 PostCallRecordGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties);
1765 }
1766 return result;
1767}
1768
1769static bool PreCallValidateGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1770 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
1771 bool skip = false;
1772 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1773 "VUID-vkGetDisplayModePropertiesKHR-physicalDevice-parameter", kVUIDUndefined);
1774 skip |= ValidateObject(physicalDevice, display, kVulkanObjectTypeDisplayKHR, false,
1775 "VUID-vkGetDisplayModePropertiesKHR-display-parameter", kVUIDUndefined);
1776
1777 return skip;
1778}
1779
1780static void PostCallRecordGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1781 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
1782 if (pProperties) {
Tony-LunarGcd0c6b02018-10-26 14:56:44 -06001783 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001784 CreateObject(physicalDevice, pProperties[i].displayMode, kVulkanObjectTypeDisplayModeKHR, nullptr);
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001785 }
1786 }
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001787}
1788
1789VKAPI_ATTR VkResult VKAPI_CALL GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1790 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
1791 bool skip = false;
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001792 {
1793 std::unique_lock<std::mutex> lock(global_lock);
1794 skip |= PreCallValidateGetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties);
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001795 }
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001796 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1797
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001798 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1799 VkResult result =
1800 instance_data->instance_dispatch_table.GetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties);
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001801
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001802 if (result == VK_SUCCESS || result == VK_INCOMPLETE) {
1803 if (pProperties) {
1804 std::unique_lock<std::mutex> lock(global_lock);
1805 PostCallRecordGetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties);
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001806 }
1807 }
Shannon McPherson9d5167f2018-05-02 15:24:37 -06001808 return result;
1809}
1810
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001811static bool PreCallValidateDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
1812 return ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkDebugMarkerSetObjectNameEXT-device-parameter",
1813 kVUIDUndefined);
1814}
1815
Mark Lobodzinskidfe5e172017-07-19 13:03:22 -06001816VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001817 bool skip = VK_FALSE;
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001818 layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001819 {
1820 std::unique_lock<std::mutex> lock(global_lock);
1821 skip |= PreCallValidateDebugMarkerSetObjectNameEXT(device, pNameInfo);
1822 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1823 if (pNameInfo->pObjectName) {
1824 dev_data->report_data->debugObjectNameMap->insert(
1825 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
1826 } else {
1827 dev_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
1828 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001829 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001830 VkResult result = dev_data->device_dispatch_table.DebugMarkerSetObjectNameEXT(device, pNameInfo);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001831 return result;
1832}
1833
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001834// This is not a Vulkan API, but is part of the loader-layer interface.
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001835VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001836 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
1837 if (instance_data->instance_dispatch_table.GetPhysicalDeviceProcAddr == NULL) {
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001838 return NULL;
1839 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001840 return instance_data->instance_dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001841}
1842
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001843static bool PreCallValidateGetDeviceProcAddr(VkDevice device, const char *funcName) {
1844 return ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkGetDeviceProcAddr-device-parameter",
1845 kVUIDUndefined);
1846}
1847
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001848VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) {
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001849 {
1850 std::unique_lock<std::mutex> lock(global_lock);
1851 bool skip = PreCallValidateGetDeviceProcAddr(device, funcName);
1852 if (skip) return nullptr;
1853 }
Mark Lobodzinskif42ced62018-07-02 12:59:27 -06001854 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1855 if (!ApiParentExtensionEnabled(funcName, device_data->device_extension_set)) {
1856 return nullptr;
1857 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001858 const auto item = name_to_funcptr_map.find(funcName);
1859 if (item != name_to_funcptr_map.end()) {
1860 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
1861 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001862 if (!device_data->device_dispatch_table.GetDeviceProcAddr) return NULL;
1863 return device_data->device_dispatch_table.GetDeviceProcAddr(device, funcName);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001864}
1865
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001866static bool PreCallValidateGetInstanceProcAddr(VkInstance instance, const char *funcName) {
1867 return ValidateObject(instance, instance, kVulkanObjectTypeInstance, false, "VUID-vkGetInstanceProcAddr-instance-parameter",
1868 kVUIDUndefined);
1869}
1870
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001871VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) {
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001872 if (instance != nullptr) {
1873 std::unique_lock<std::mutex> lock(global_lock);
1874 bool skip = PreCallValidateGetInstanceProcAddr(instance, funcName);
1875 if (skip) return nullptr;
1876 }
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001877 const auto item = name_to_funcptr_map.find(funcName);
1878 if (item != name_to_funcptr_map.end()) {
1879 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
1880 }
Mark Lobodzinski17de5fd2018-06-22 15:09:53 -06001881 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
1882 if (!instance_data->instance_dispatch_table.GetInstanceProcAddr) return nullptr;
1883 return instance_data->instance_dispatch_table.GetInstanceProcAddr(instance, funcName);
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001884}
1885
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001886static bool PreCallValidateGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1887 VkDisplayProperties2KHR *pProperties) {
1888 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1889 "VUID-vkGetPhysicalDeviceDisplayProperties2KHR-physicalDevice-parameter", kVUIDUndefined);
1890}
1891
1892static void PostCallRecordGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1893 VkDisplayProperties2KHR *pProperties) {
1894 for (uint32_t index = 0; index < *pPropertyCount; ++index) {
1895 CreateObject(physicalDevice, pProperties[index].displayProperties.display, kVulkanObjectTypeDisplayKHR, nullptr);
1896 }
1897}
1898
Piers Daniell16c253f2018-05-30 14:34:05 -06001899VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1900 VkDisplayProperties2KHR *pProperties) {
Piers Daniell16c253f2018-05-30 14:34:05 -06001901 {
1902 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001903 bool skip = PreCallValidateGetPhysicalDeviceDisplayProperties2KHR(physicalDevice, pPropertyCount, pProperties);
1904 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Piers Daniell16c253f2018-05-30 14:34:05 -06001905 }
Mark Lobodzinski72ec0d72018-06-26 08:55:40 -06001906 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1907 VkResult result =
1908 instance_data->instance_dispatch_table.GetPhysicalDeviceDisplayProperties2KHR(physicalDevice, pPropertyCount, pProperties);
Piers Daniell16c253f2018-05-30 14:34:05 -06001909 if (pProperties && (VK_SUCCESS == result || VK_INCOMPLETE == result)) {
1910 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001911 PostCallRecordGetPhysicalDeviceDisplayProperties2KHR(physicalDevice, pPropertyCount, pProperties);
Piers Daniell16c253f2018-05-30 14:34:05 -06001912 }
1913
1914 return result;
1915}
1916
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001917static bool PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1918 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
1919 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1920 "VUID-vkGetDisplayPlaneSupportedDisplaysKHR-physicalDevice-parameter", kVUIDUndefined);
1921}
1922
1923static void PostCallRecordGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1924 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
1925 for (uint32_t index = 0; index < *pDisplayCount; ++index) {
1926 CreateObject(physicalDevice, pDisplays[index], kVulkanObjectTypeDisplayKHR, nullptr);
1927 }
1928}
1929
Piers Daniell16c253f2018-05-30 14:34:05 -06001930VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1931 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
Piers Daniell16c253f2018-05-30 14:34:05 -06001932 {
1933 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001934 bool skip = PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, pDisplays);
1935 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Piers Daniell16c253f2018-05-30 14:34:05 -06001936 }
Mark Lobodzinski72ec0d72018-06-26 08:55:40 -06001937 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1938 VkResult result = instance_data->instance_dispatch_table.GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex,
1939 pDisplayCount, pDisplays);
Piers Daniell16c253f2018-05-30 14:34:05 -06001940 if (pDisplays && (VK_SUCCESS == result || VK_INCOMPLETE == result)) {
1941 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001942 PostCallRecordGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, pDisplays);
Piers Daniell16c253f2018-05-30 14:34:05 -06001943 }
Piers Daniell16c253f2018-05-30 14:34:05 -06001944 return result;
1945}
1946
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001947static bool PreCallValidateGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1948 uint32_t *pPropertyCount, VkDisplayModeProperties2KHR *pProperties) {
1949 bool skip = false;
1950 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
1951 "VUID-vkGetDisplayModeProperties2KHR-physicalDevice-parameter", kVUIDUndefined);
1952 skip |= ValidateObject(physicalDevice, display, kVulkanObjectTypeDisplayKHR, false,
1953 "VUID-vkGetDisplayModeProperties2KHR-display-parameter", kVUIDUndefined);
1954 return skip;
1955}
1956
1957static void PostCallRecordGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1958 uint32_t *pPropertyCount, VkDisplayModeProperties2KHR *pProperties) {
1959 for (uint32_t index = 0; index < *pPropertyCount; ++index) {
1960 CreateObject(physicalDevice, pProperties[index].displayModeProperties.displayMode, kVulkanObjectTypeDisplayModeKHR,
1961 nullptr);
1962 }
1963}
1964
Piers Daniell16c253f2018-05-30 14:34:05 -06001965VKAPI_ATTR VkResult VKAPI_CALL GetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1966 uint32_t *pPropertyCount, VkDisplayModeProperties2KHR *pProperties) {
Piers Daniell16c253f2018-05-30 14:34:05 -06001967 {
1968 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001969 bool skip = PreCallValidateGetDisplayModeProperties2KHR(physicalDevice, display, pPropertyCount, pProperties);
1970 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
Piers Daniell16c253f2018-05-30 14:34:05 -06001971 }
Mark Lobodzinski72ec0d72018-06-26 08:55:40 -06001972 layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map);
1973 VkResult result =
1974 instance_data->instance_dispatch_table.GetDisplayModeProperties2KHR(physicalDevice, display, pPropertyCount, pProperties);
Piers Daniell16c253f2018-05-30 14:34:05 -06001975 if (pProperties && (VK_SUCCESS == result || VK_INCOMPLETE == result)) {
1976 std::lock_guard<std::mutex> lock(global_lock);
Mark Lobodzinskia2e97362018-09-17 13:58:32 -06001977 PostCallRecordGetDisplayModeProperties2KHR(physicalDevice, display, pPropertyCount, pProperties);
Piers Daniell16c253f2018-05-30 14:34:05 -06001978 }
Piers Daniell16c253f2018-05-30 14:34:05 -06001979 return result;
1980}
1981
Mark Lobodzinskib2de97f2017-07-06 15:28:11 -06001982} // namespace object_tracker
1983
1984VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
1985 VkExtensionProperties *pProperties) {
1986 return object_tracker::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
1987}
1988
1989VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
1990 VkLayerProperties *pProperties) {
1991 return object_tracker::EnumerateInstanceLayerProperties(pCount, pProperties);
1992}
1993
1994VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
1995 VkLayerProperties *pProperties) {
1996 // The layer command handles VK_NULL_HANDLE just fine internally
1997 assert(physicalDevice == VK_NULL_HANDLE);
1998 return object_tracker::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
1999}
2000
2001VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2002 return object_tracker::GetDeviceProcAddr(dev, funcName);
2003}
2004
2005VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2006 return object_tracker::GetInstanceProcAddr(instance, funcName);
2007}
2008
2009VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2010 const char *pLayerName, uint32_t *pCount,
2011 VkExtensionProperties *pProperties) {
2012 // The layer command handles VK_NULL_HANDLE just fine internally
2013 assert(physicalDevice == VK_NULL_HANDLE);
2014 return object_tracker::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2015}
2016
2017VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2018 const char *funcName) {
2019 return object_tracker::GetPhysicalDeviceProcAddr(instance, funcName);
2020}
2021
2022VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2023 assert(pVersionStruct != NULL);
2024 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2025
2026 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2027 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2028 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2029 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2030 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2031 }
2032
2033 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2034 object_tracker::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
2035 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2036 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
2037 }
2038
2039 return VK_SUCCESS;
2040}