1 /* Copyright (c) 2015-2019 The Khronos Group Inc.
2 * Copyright (c) 2015-2019 Valve Corporation
3 * Copyright (c) 2015-2019 LunarG, Inc.
4 * Copyright (C) 2015-2019 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@lunarg.com>
19 * Author: Jon Ashburn <jon@lunarg.com>
20 * Author: Tobin Ehlis <tobin@lunarg.com>
21 */
22
23 #include "chassis.h"
24
25 #include "object_lifetime_validation.h"
26
27 uint64_t object_track_index = 0;
28
ObjTrackStateTypedHandle(const ObjTrackState & track_state)29 VulkanTypedHandle ObjTrackStateTypedHandle(const ObjTrackState &track_state) {
30 // TODO: Unify Typed Handle representation (i.e. VulkanTypedHandle everywhere there are handle/type pairs)
31 VulkanTypedHandle typed_handle;
32 typed_handle.handle = track_state.handle;
33 typed_handle.type = track_state.object_type;
34 return typed_handle;
35 }
36
37 // Destroy memRef lists and free all memory
DestroyQueueDataStructures(VkDevice device)38 void ObjectLifetimes::DestroyQueueDataStructures(VkDevice device) {
39 // Destroy the items in the queue map
40 auto snapshot = object_map[kVulkanObjectTypeQueue].snapshot();
41 for (const auto &queue : snapshot) {
42 uint32_t obj_index = queue.second->object_type;
43 assert(num_total_objects > 0);
44 num_total_objects--;
45 assert(num_objects[obj_index] > 0);
46 num_objects[obj_index]--;
47 object_map[kVulkanObjectTypeQueue].erase(queue.first);
48 }
49 }
50
51 // Look for this device object in any of the instance child devices lists.
52 // NOTE: This is of dubious value. In most circumstances Vulkan will die a flaming death if a dispatchable object is invalid.
53 // However, if this layer is loaded first and GetProcAddress is used to make API calls, it will detect bad DOs.
ValidateDeviceObject(const VulkanTypedHandle & device_typed,const char * invalid_handle_code,const char * wrong_device_code)54 bool ObjectLifetimes::ValidateDeviceObject(const VulkanTypedHandle &device_typed, const char *invalid_handle_code,
55 const char *wrong_device_code) {
56 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
57 auto instance_object_lifetime_data = GetObjectLifetimeData(instance_data->object_dispatch);
58 if (instance_object_lifetime_data->object_map[kVulkanObjectTypeDevice].contains(device_typed.handle)) {
59 return false;
60 }
61 return log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device_typed.handle,
62 invalid_handle_code, "Invalid %s.", report_data->FormatHandle(device_typed).c_str());
63 }
64
AllocateCommandBuffer(VkDevice device,const VkCommandPool command_pool,const VkCommandBuffer command_buffer,VkCommandBufferLevel level)65 void ObjectLifetimes::AllocateCommandBuffer(VkDevice device, const VkCommandPool command_pool, const VkCommandBuffer command_buffer,
66 VkCommandBufferLevel level) {
67 auto pNewObjNode = std::make_shared<ObjTrackState>();
68 pNewObjNode->object_type = kVulkanObjectTypeCommandBuffer;
69 pNewObjNode->handle = HandleToUint64(command_buffer);
70 pNewObjNode->parent_object = HandleToUint64(command_pool);
71 if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
72 pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY;
73 } else {
74 pNewObjNode->status = OBJSTATUS_NONE;
75 }
76 InsertObject(object_map[kVulkanObjectTypeCommandBuffer], HandleToUint64(command_buffer), kVulkanObjectTypeCommandBuffer,
77 pNewObjNode);
78 num_objects[kVulkanObjectTypeCommandBuffer]++;
79 num_total_objects++;
80 }
81
ValidateCommandBuffer(VkDevice device,VkCommandPool command_pool,VkCommandBuffer command_buffer)82 bool ObjectLifetimes::ValidateCommandBuffer(VkDevice device, VkCommandPool command_pool, VkCommandBuffer command_buffer) {
83 bool skip = false;
84 uint64_t object_handle = HandleToUint64(command_buffer);
85 auto iter = object_map[kVulkanObjectTypeCommandBuffer].find(object_handle);
86 if (iter != object_map[kVulkanObjectTypeCommandBuffer].end()) {
87 auto pNode = iter->second;
88
89 if (pNode->parent_object != HandleToUint64(command_pool)) {
90 // We know that the parent *must* be a command pool
91 const auto parent_pool = CastFromUint64<VkCommandPool>(pNode->parent_object);
92 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
93 object_handle, "VUID-vkFreeCommandBuffers-pCommandBuffers-parent",
94 "FreeCommandBuffers is attempting to free %s belonging to %s from %s).",
95 report_data->FormatHandle(command_buffer).c_str(), report_data->FormatHandle(parent_pool).c_str(),
96 report_data->FormatHandle(command_pool).c_str());
97 }
98 } else {
99 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, object_handle,
100 "VUID-vkFreeCommandBuffers-pCommandBuffers-00048", "Invalid %s.",
101 report_data->FormatHandle(command_buffer).c_str());
102 }
103 return skip;
104 }
105
AllocateDescriptorSet(VkDevice device,VkDescriptorPool descriptor_pool,VkDescriptorSet descriptor_set)106 void ObjectLifetimes::AllocateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
107 auto pNewObjNode = std::make_shared<ObjTrackState>();
108 pNewObjNode->object_type = kVulkanObjectTypeDescriptorSet;
109 pNewObjNode->status = OBJSTATUS_NONE;
110 pNewObjNode->handle = HandleToUint64(descriptor_set);
111 pNewObjNode->parent_object = HandleToUint64(descriptor_pool);
112 InsertObject(object_map[kVulkanObjectTypeDescriptorSet], HandleToUint64(descriptor_set), kVulkanObjectTypeDescriptorSet,
113 pNewObjNode);
114 num_objects[kVulkanObjectTypeDescriptorSet]++;
115 num_total_objects++;
116
117 auto itr = object_map[kVulkanObjectTypeDescriptorPool].find(HandleToUint64(descriptor_pool));
118 if (itr != object_map[kVulkanObjectTypeDescriptorPool].end()) {
119 itr->second->child_objects->insert(HandleToUint64(descriptor_set));
120 }
121 }
122
ValidateDescriptorSet(VkDevice device,VkDescriptorPool descriptor_pool,VkDescriptorSet descriptor_set)123 bool ObjectLifetimes::ValidateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
124 bool skip = false;
125 uint64_t object_handle = HandleToUint64(descriptor_set);
126 auto dsItem = object_map[kVulkanObjectTypeDescriptorSet].find(object_handle);
127 if (dsItem != object_map[kVulkanObjectTypeDescriptorSet].end()) {
128 if (dsItem->second->parent_object != HandleToUint64(descriptor_pool)) {
129 // We know that the parent *must* be a descriptor pool
130 const auto parent_pool = CastFromUint64<VkDescriptorPool>(dsItem->second->parent_object);
131 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
132 object_handle, "VUID-vkFreeDescriptorSets-pDescriptorSets-parent",
133 "FreeDescriptorSets is attempting to free %s"
134 " belonging to %s from %s).",
135 report_data->FormatHandle(descriptor_set).c_str(), report_data->FormatHandle(parent_pool).c_str(),
136 report_data->FormatHandle(descriptor_pool).c_str());
137 }
138 } else {
139 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, object_handle,
140 "VUID-vkFreeDescriptorSets-pDescriptorSets-00310", "Invalid %s.",
141 report_data->FormatHandle(descriptor_set).c_str());
142 }
143 return skip;
144 }
145
146 template <typename DispObj>
ValidateDescriptorWrite(DispObj disp,VkWriteDescriptorSet const * desc,bool isPush)147 bool ObjectLifetimes::ValidateDescriptorWrite(DispObj disp, VkWriteDescriptorSet const *desc, bool isPush) {
148 bool skip = false;
149
150 if (!isPush && desc->dstSet) {
151 skip |= ValidateObject(disp, desc->dstSet, kVulkanObjectTypeDescriptorSet, false, "VUID-VkWriteDescriptorSet-dstSet-00320",
152 "VUID-VkWriteDescriptorSet-commonparent");
153 }
154
155 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
156 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
157 for (uint32_t idx2 = 0; idx2 < desc->descriptorCount; ++idx2) {
158 skip |= ValidateObject(disp, desc->pTexelBufferView[idx2], kVulkanObjectTypeBufferView, false,
159 "VUID-VkWriteDescriptorSet-descriptorType-00323", "VUID-VkWriteDescriptorSet-commonparent");
160 }
161 }
162
163 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
164 (desc->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
165 (desc->descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
166 for (uint32_t idx3 = 0; idx3 < desc->descriptorCount; ++idx3) {
167 skip |= ValidateObject(disp, desc->pImageInfo[idx3].imageView, kVulkanObjectTypeImageView, false,
168 "VUID-VkWriteDescriptorSet-descriptorType-00326", "VUID-VkDescriptorImageInfo-commonparent");
169 }
170 }
171
172 if ((desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
173 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
174 (desc->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
175 (desc->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
176 for (uint32_t idx4 = 0; idx4 < desc->descriptorCount; ++idx4) {
177 if (desc->pBufferInfo[idx4].buffer) {
178 skip |= ValidateObject(disp, desc->pBufferInfo[idx4].buffer, kVulkanObjectTypeBuffer, false,
179 "VUID-VkDescriptorBufferInfo-buffer-parameter", kVUIDUndefined);
180 }
181 }
182 }
183
184 return skip;
185 }
186
PreCallValidateCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,VkPipelineBindPoint pipelineBindPoint,VkPipelineLayout layout,uint32_t set,uint32_t descriptorWriteCount,const VkWriteDescriptorSet * pDescriptorWrites)187 bool ObjectLifetimes::PreCallValidateCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
188 VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount,
189 const VkWriteDescriptorSet *pDescriptorWrites) {
190 bool skip = false;
191 skip |= ValidateObject(commandBuffer, commandBuffer, kVulkanObjectTypeCommandBuffer, false,
192 "VUID-vkCmdPushDescriptorSetKHR-commandBuffer-parameter", "VUID-vkCmdPushDescriptorSetKHR-commonparent");
193 skip |= ValidateObject(commandBuffer, layout, kVulkanObjectTypePipelineLayout, false,
194 "VUID-vkCmdPushDescriptorSetKHR-layout-parameter", "VUID-vkCmdPushDescriptorSetKHR-commonparent");
195 if (pDescriptorWrites) {
196 for (uint32_t index0 = 0; index0 < descriptorWriteCount; ++index0) {
197 skip |= ValidateDescriptorWrite(commandBuffer, &pDescriptorWrites[index0], true);
198 }
199 }
200 return skip;
201 }
202
CreateQueue(VkDevice device,VkQueue vkObj)203 void ObjectLifetimes::CreateQueue(VkDevice device, VkQueue vkObj) {
204 std::shared_ptr<ObjTrackState> p_obj_node = NULL;
205 auto queue_item = object_map[kVulkanObjectTypeQueue].find(HandleToUint64(vkObj));
206 if (queue_item == object_map[kVulkanObjectTypeQueue].end()) {
207 p_obj_node = std::make_shared<ObjTrackState>();
208 InsertObject(object_map[kVulkanObjectTypeQueue], HandleToUint64(vkObj), kVulkanObjectTypeQueue, p_obj_node);
209 num_objects[kVulkanObjectTypeQueue]++;
210 num_total_objects++;
211 } else {
212 p_obj_node = queue_item->second;
213 }
214 p_obj_node->object_type = kVulkanObjectTypeQueue;
215 p_obj_node->status = OBJSTATUS_NONE;
216 p_obj_node->handle = HandleToUint64(vkObj);
217 }
218
CreateSwapchainImageObject(VkDevice dispatchable_object,VkImage swapchain_image,VkSwapchainKHR swapchain)219 void ObjectLifetimes::CreateSwapchainImageObject(VkDevice dispatchable_object, VkImage swapchain_image, VkSwapchainKHR swapchain) {
220 if (!swapchainImageMap.contains(HandleToUint64(swapchain_image))) {
221 auto pNewObjNode = std::make_shared<ObjTrackState>();
222 pNewObjNode->object_type = kVulkanObjectTypeImage;
223 pNewObjNode->status = OBJSTATUS_NONE;
224 pNewObjNode->handle = HandleToUint64(swapchain_image);
225 pNewObjNode->parent_object = HandleToUint64(swapchain);
226 InsertObject(swapchainImageMap, HandleToUint64(swapchain_image), kVulkanObjectTypeImage, pNewObjNode);
227 }
228 }
229
DeviceReportUndestroyedObjects(VkDevice device,VulkanObjectType object_type,const std::string & error_code)230 bool ObjectLifetimes::DeviceReportUndestroyedObjects(VkDevice device, VulkanObjectType object_type, const std::string &error_code) {
231 bool skip = false;
232
233 auto snapshot = object_map[object_type].snapshot();
234 for (const auto &item : snapshot) {
235 const auto object_info = item.second;
236 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[object_type], object_info->handle,
237 error_code, "OBJ ERROR : For %s, %s has not been destroyed.", report_data->FormatHandle(device).c_str(),
238 report_data->FormatHandle(ObjTrackStateTypedHandle(*object_info)).c_str());
239 }
240 return skip;
241 }
242
DeviceDestroyUndestroyedObjects(VkDevice device,VulkanObjectType object_type)243 void ObjectLifetimes::DeviceDestroyUndestroyedObjects(VkDevice device, VulkanObjectType object_type) {
244 auto snapshot = object_map[object_type].snapshot();
245 for (const auto &item : snapshot) {
246 auto object_info = item.second;
247 DestroyObjectSilently(object_info->handle, object_type);
248 }
249 }
250
PreCallValidateDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)251 bool ObjectLifetimes::PreCallValidateDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
252 bool skip = false;
253
254 // We validate here for coverage, though we'd not have made it this for with a bad instance.
255 skip |= ValidateObject(instance, instance, kVulkanObjectTypeInstance, true, "VUID-vkDestroyInstance-instance-parameter",
256 kVUIDUndefined);
257
258 // Validate that child devices have been destroyed
259 auto snapshot = object_map[kVulkanObjectTypeDevice].snapshot();
260 for (const auto &iit : snapshot) {
261 auto pNode = iit.second;
262
263 VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
264 VkDebugReportObjectTypeEXT debug_object_type = get_debug_report_enum[pNode->object_type];
265
266 skip |=
267 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, debug_object_type, pNode->handle, kVUID_ObjectTracker_ObjectLeak,
268 "OBJ ERROR : %s object %s has not been destroyed.", string_VkDebugReportObjectTypeEXT(debug_object_type),
269 report_data->FormatHandle(ObjTrackStateTypedHandle(*pNode)).c_str());
270
271 // Report any remaining objects in LL
272 skip |= ReportUndestroyedObjects(device, "VUID-vkDestroyInstance-instance-00629");
273
274 skip |= ValidateDestroyObject(instance, device, kVulkanObjectTypeDevice, pAllocator,
275 "VUID-vkDestroyInstance-instance-00630", "VUID-vkDestroyInstance-instance-00631");
276 }
277
278 ValidateDestroyObject(instance, instance, kVulkanObjectTypeInstance, pAllocator, "VUID-vkDestroyInstance-instance-00630",
279 "VUID-vkDestroyInstance-instance-00631");
280
281 return skip;
282 }
283
PreCallValidateEnumeratePhysicalDevices(VkInstance instance,uint32_t * pPhysicalDeviceCount,VkPhysicalDevice * pPhysicalDevices)284 bool ObjectLifetimes::PreCallValidateEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
285 VkPhysicalDevice *pPhysicalDevices) {
286 bool skip = ValidateObject(instance, instance, kVulkanObjectTypeInstance, false,
287 "VUID-vkEnumeratePhysicalDevices-instance-parameter", kVUIDUndefined);
288 return skip;
289 }
290
PostCallRecordEnumeratePhysicalDevices(VkInstance instance,uint32_t * pPhysicalDeviceCount,VkPhysicalDevice * pPhysicalDevices,VkResult result)291 void ObjectLifetimes::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
292 VkPhysicalDevice *pPhysicalDevices, VkResult result) {
293 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
294 if (pPhysicalDevices) {
295 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
296 CreateObject(instance, pPhysicalDevices[i], kVulkanObjectTypePhysicalDevice, nullptr);
297 }
298 }
299 }
300
PreCallRecordDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)301 void ObjectLifetimes::PreCallRecordDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
302 // Destroy physical devices
303 auto snapshot = object_map[kVulkanObjectTypePhysicalDevice].snapshot();
304 for (const auto &iit : snapshot) {
305 auto pNode = iit.second;
306 VkPhysicalDevice physical_device = reinterpret_cast<VkPhysicalDevice>(pNode->handle);
307 RecordDestroyObject(instance, physical_device, kVulkanObjectTypePhysicalDevice);
308 }
309
310 // Destroy child devices
311 auto snapshot2 = object_map[kVulkanObjectTypeDevice].snapshot();
312 for (const auto &iit : snapshot2) {
313 auto pNode = iit.second;
314 VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
315 DestroyUndestroyedObjects(device);
316
317 RecordDestroyObject(instance, device, kVulkanObjectTypeDevice);
318 }
319 }
320
PostCallRecordDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)321 void ObjectLifetimes::PostCallRecordDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
322 RecordDestroyObject(instance, instance, kVulkanObjectTypeInstance);
323 }
324
PreCallValidateDestroyDevice(VkDevice device,const VkAllocationCallbacks * pAllocator)325 bool ObjectLifetimes::PreCallValidateDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
326 bool skip = false;
327 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, true, "VUID-vkDestroyDevice-device-parameter", kVUIDUndefined);
328 skip |= ValidateDestroyObject(physical_device, device, kVulkanObjectTypeDevice, pAllocator, "VUID-vkDestroyDevice-device-00379",
329 "VUID-vkDestroyDevice-device-00380");
330 // Report any remaining objects associated with this VkDevice object in LL
331 skip |= ReportUndestroyedObjects(device, "VUID-vkDestroyDevice-device-00378");
332
333 return skip;
334 }
335
PreCallRecordDestroyDevice(VkDevice device,const VkAllocationCallbacks * pAllocator)336 void ObjectLifetimes::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
337 auto instance_data = GetLayerDataPtr(get_dispatch_key(physical_device), layer_data_map);
338 ValidationObject *validation_data = GetValidationObject(instance_data->object_dispatch, LayerObjectTypeObjectTracker);
339 ObjectLifetimes *object_lifetimes = static_cast<ObjectLifetimes *>(validation_data);
340 object_lifetimes->RecordDestroyObject(physical_device, device, kVulkanObjectTypeDevice);
341 DestroyUndestroyedObjects(device);
342
343 // Clean up Queue's MemRef Linked Lists
344 DestroyQueueDataStructures(device);
345 }
346
PreCallValidateGetDeviceQueue(VkDevice device,uint32_t queueFamilyIndex,uint32_t queueIndex,VkQueue * pQueue)347 bool ObjectLifetimes::PreCallValidateGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
348 VkQueue *pQueue) {
349 bool skip = false;
350 skip |=
351 ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkGetDeviceQueue-device-parameter", kVUIDUndefined);
352 return skip;
353 }
354
PostCallRecordGetDeviceQueue(VkDevice device,uint32_t queueFamilyIndex,uint32_t queueIndex,VkQueue * pQueue)355 void ObjectLifetimes::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
356 VkQueue *pQueue) {
357 auto lock = write_shared_lock();
358 CreateQueue(device, *pQueue);
359 }
360
PreCallValidateGetDeviceQueue2(VkDevice device,const VkDeviceQueueInfo2 * pQueueInfo,VkQueue * pQueue)361 bool ObjectLifetimes::PreCallValidateGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
362 return ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkGetDeviceQueue2-device-parameter",
363 kVUIDUndefined);
364 }
365
PostCallRecordGetDeviceQueue2(VkDevice device,const VkDeviceQueueInfo2 * pQueueInfo,VkQueue * pQueue)366 void ObjectLifetimes::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
367 auto lock = write_shared_lock();
368 CreateQueue(device, *pQueue);
369 }
370
PreCallValidateUpdateDescriptorSets(VkDevice device,uint32_t descriptorWriteCount,const VkWriteDescriptorSet * pDescriptorWrites,uint32_t descriptorCopyCount,const VkCopyDescriptorSet * pDescriptorCopies)371 bool ObjectLifetimes::PreCallValidateUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
372 const VkWriteDescriptorSet *pDescriptorWrites,
373 uint32_t descriptorCopyCount,
374 const VkCopyDescriptorSet *pDescriptorCopies) {
375 bool skip = false;
376 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkUpdateDescriptorSets-device-parameter",
377 kVUIDUndefined);
378 if (pDescriptorCopies) {
379 for (uint32_t idx0 = 0; idx0 < descriptorCopyCount; ++idx0) {
380 if (pDescriptorCopies[idx0].dstSet) {
381 skip |= ValidateObject(device, pDescriptorCopies[idx0].dstSet, kVulkanObjectTypeDescriptorSet, false,
382 "VUID-VkCopyDescriptorSet-dstSet-parameter", "VUID-VkCopyDescriptorSet-commonparent");
383 }
384 if (pDescriptorCopies[idx0].srcSet) {
385 skip |= ValidateObject(device, pDescriptorCopies[idx0].srcSet, kVulkanObjectTypeDescriptorSet, false,
386 "VUID-VkCopyDescriptorSet-srcSet-parameter", "VUID-VkCopyDescriptorSet-commonparent");
387 }
388 }
389 }
390 if (pDescriptorWrites) {
391 for (uint32_t idx1 = 0; idx1 < descriptorWriteCount; ++idx1) {
392 skip |= ValidateDescriptorWrite(device, &pDescriptorWrites[idx1], false);
393 }
394 }
395 return skip;
396 }
397
PreCallValidateResetDescriptorPool(VkDevice device,VkDescriptorPool descriptorPool,VkDescriptorPoolResetFlags flags)398 bool ObjectLifetimes::PreCallValidateResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
399 VkDescriptorPoolResetFlags flags) {
400 bool skip = false;
401 auto lock = read_shared_lock();
402
403 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkResetDescriptorPool-device-parameter",
404 kVUIDUndefined);
405 skip |=
406 ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false,
407 "VUID-vkResetDescriptorPool-descriptorPool-parameter", "VUID-vkResetDescriptorPool-descriptorPool-parent");
408
409 auto itr = object_map[kVulkanObjectTypeDescriptorPool].find(HandleToUint64(descriptorPool));
410 if (itr != object_map[kVulkanObjectTypeDescriptorPool].end()) {
411 auto pPoolNode = itr->second;
412 for (auto set : *pPoolNode->child_objects) {
413 skip |= ValidateDestroyObject(device, (VkDescriptorSet)set, kVulkanObjectTypeDescriptorSet, nullptr, kVUIDUndefined,
414 kVUIDUndefined);
415 }
416 }
417 return skip;
418 }
419
PreCallRecordResetDescriptorPool(VkDevice device,VkDescriptorPool descriptorPool,VkDescriptorPoolResetFlags flags)420 void ObjectLifetimes::PreCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
421 VkDescriptorPoolResetFlags flags) {
422 auto lock = write_shared_lock();
423 // A DescriptorPool's descriptor sets are implicitly deleted when the pool is reset. Remove this pool's descriptor sets from
424 // our descriptorSet map.
425 auto itr = object_map[kVulkanObjectTypeDescriptorPool].find(HandleToUint64(descriptorPool));
426 if (itr != object_map[kVulkanObjectTypeDescriptorPool].end()) {
427 auto pPoolNode = itr->second;
428 for (auto set : *pPoolNode->child_objects) {
429 RecordDestroyObject(device, (VkDescriptorSet)set, kVulkanObjectTypeDescriptorSet);
430 }
431 pPoolNode->child_objects->clear();
432 }
433 }
434
PreCallValidateBeginCommandBuffer(VkCommandBuffer command_buffer,const VkCommandBufferBeginInfo * begin_info)435 bool ObjectLifetimes::PreCallValidateBeginCommandBuffer(VkCommandBuffer command_buffer,
436 const VkCommandBufferBeginInfo *begin_info) {
437 bool skip = false;
438 skip |= ValidateObject(command_buffer, command_buffer, kVulkanObjectTypeCommandBuffer, false,
439 "VUID-vkBeginCommandBuffer-commandBuffer-parameter", kVUIDUndefined);
440 if (begin_info) {
441 auto iter = object_map[kVulkanObjectTypeCommandBuffer].find(HandleToUint64(command_buffer));
442 if (iter != object_map[kVulkanObjectTypeCommandBuffer].end()) {
443 auto pNode = iter->second;
444 if ((begin_info->pInheritanceInfo) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY) &&
445 (begin_info->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
446 skip |=
447 ValidateObject(command_buffer, begin_info->pInheritanceInfo->framebuffer, kVulkanObjectTypeFramebuffer, true,
448 "VUID-VkCommandBufferBeginInfo-flags-00055", "VUID-VkCommandBufferInheritanceInfo-commonparent");
449 skip |=
450 ValidateObject(command_buffer, begin_info->pInheritanceInfo->renderPass, kVulkanObjectTypeRenderPass, false,
451 "VUID-VkCommandBufferBeginInfo-flags-00053", "VUID-VkCommandBufferInheritanceInfo-commonparent");
452 }
453 }
454 }
455 return skip;
456 }
457
PreCallValidateGetSwapchainImagesKHR(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pSwapchainImageCount,VkImage * pSwapchainImages)458 bool ObjectLifetimes::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
459 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) {
460 bool skip = false;
461 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkGetSwapchainImagesKHR-device-parameter",
462 "VUID-vkGetSwapchainImagesKHR-commonparent");
463 skip |= ValidateObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, false,
464 "VUID-vkGetSwapchainImagesKHR-swapchain-parameter", "VUID-vkGetSwapchainImagesKHR-commonparent");
465 return skip;
466 }
467
PostCallRecordGetSwapchainImagesKHR(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pSwapchainImageCount,VkImage * pSwapchainImages,VkResult result)468 void ObjectLifetimes::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
469 VkImage *pSwapchainImages, VkResult result) {
470 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
471 auto lock = write_shared_lock();
472 if (pSwapchainImages != NULL) {
473 for (uint32_t i = 0; i < *pSwapchainImageCount; i++) {
474 CreateSwapchainImageObject(device, pSwapchainImages[i], swapchain);
475 }
476 }
477 }
478
PreCallValidateCreateDescriptorSetLayout(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorSetLayout * pSetLayout)479 bool ObjectLifetimes::PreCallValidateCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
480 const VkAllocationCallbacks *pAllocator,
481 VkDescriptorSetLayout *pSetLayout) {
482 bool skip = false;
483 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkCreateDescriptorSetLayout-device-parameter",
484 kVUIDUndefined);
485 if (pCreateInfo) {
486 if (pCreateInfo->pBindings) {
487 for (uint32_t binding_index = 0; binding_index < pCreateInfo->bindingCount; ++binding_index) {
488 const VkDescriptorSetLayoutBinding &binding = pCreateInfo->pBindings[binding_index];
489 const bool is_sampler_type = binding.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
490 binding.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
491 if (binding.pImmutableSamplers && is_sampler_type) {
492 for (uint32_t index2 = 0; index2 < binding.descriptorCount; ++index2) {
493 const VkSampler sampler = binding.pImmutableSamplers[index2];
494 skip |= ValidateObject(device, sampler, kVulkanObjectTypeSampler, false,
495 "VUID-VkDescriptorSetLayoutBinding-descriptorType-00282", kVUIDUndefined);
496 }
497 }
498 }
499 }
500 }
501 return skip;
502 }
503
PostCallRecordCreateDescriptorSetLayout(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorSetLayout * pSetLayout,VkResult result)504 void ObjectLifetimes::PostCallRecordCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
505 const VkAllocationCallbacks *pAllocator,
506 VkDescriptorSetLayout *pSetLayout, VkResult result) {
507 if (result != VK_SUCCESS) return;
508 CreateObject(device, *pSetLayout, kVulkanObjectTypeDescriptorSetLayout, pAllocator);
509 }
510
ValidateSamplerObjects(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo)511 bool ObjectLifetimes::ValidateSamplerObjects(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo) {
512 bool skip = false;
513 if (pCreateInfo->pBindings) {
514 for (uint32_t index1 = 0; index1 < pCreateInfo->bindingCount; ++index1) {
515 for (uint32_t index2 = 0; index2 < pCreateInfo->pBindings[index1].descriptorCount; ++index2) {
516 if (pCreateInfo->pBindings[index1].pImmutableSamplers) {
517 skip |=
518 ValidateObject(device, pCreateInfo->pBindings[index1].pImmutableSamplers[index2], kVulkanObjectTypeSampler,
519 true, "VUID-VkDescriptorSetLayoutBinding-descriptorType-00282", kVUIDUndefined);
520 }
521 }
522 }
523 }
524 return skip;
525 }
526
PreCallValidateGetDescriptorSetLayoutSupport(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,VkDescriptorSetLayoutSupport * pSupport)527 bool ObjectLifetimes::PreCallValidateGetDescriptorSetLayoutSupport(VkDevice device,
528 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
529 VkDescriptorSetLayoutSupport *pSupport) {
530 bool skip = ValidateObject(device, device, kVulkanObjectTypeDevice, false,
531 "VUID-vkGetDescriptorSetLayoutSupport-device-parameter", kVUIDUndefined);
532 if (pCreateInfo) {
533 skip |= ValidateSamplerObjects(device, pCreateInfo);
534 }
535 return skip;
536 }
PreCallValidateGetDescriptorSetLayoutSupportKHR(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,VkDescriptorSetLayoutSupport * pSupport)537 bool ObjectLifetimes::PreCallValidateGetDescriptorSetLayoutSupportKHR(VkDevice device,
538 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
539 VkDescriptorSetLayoutSupport *pSupport) {
540 bool skip = ValidateObject(device, device, kVulkanObjectTypeDevice, false,
541 "VUID-vkGetDescriptorSetLayoutSupportKHR-device-parameter", kVUIDUndefined);
542 if (pCreateInfo) {
543 skip |= ValidateSamplerObjects(device, pCreateInfo);
544 }
545 return skip;
546 }
547
PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties)548 bool ObjectLifetimes::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
549 uint32_t *pQueueFamilyPropertyCount,
550 VkQueueFamilyProperties *pQueueFamilyProperties) {
551 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
552 "VUID-vkGetPhysicalDeviceQueueFamilyProperties-physicalDevice-parameter", kVUIDUndefined);
553 }
554
PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties)555 void ObjectLifetimes::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
556 uint32_t *pQueueFamilyPropertyCount,
557 VkQueueFamilyProperties *pQueueFamilyProperties) {}
558
PostCallRecordCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance,VkResult result)559 void ObjectLifetimes::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
560 VkInstance *pInstance, VkResult result) {
561 if (result != VK_SUCCESS) return;
562 CreateObject(*pInstance, *pInstance, kVulkanObjectTypeInstance, pAllocator);
563 }
564
PreCallValidateAllocateCommandBuffers(VkDevice device,const VkCommandBufferAllocateInfo * pAllocateInfo,VkCommandBuffer * pCommandBuffers)565 bool ObjectLifetimes::PreCallValidateAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
566 VkCommandBuffer *pCommandBuffers) {
567 bool skip = false;
568 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkAllocateCommandBuffers-device-parameter",
569 kVUIDUndefined);
570 skip |= ValidateObject(device, pAllocateInfo->commandPool, kVulkanObjectTypeCommandPool, false,
571 "VUID-VkCommandBufferAllocateInfo-commandPool-parameter", kVUIDUndefined);
572 return skip;
573 }
574
PostCallRecordAllocateCommandBuffers(VkDevice device,const VkCommandBufferAllocateInfo * pAllocateInfo,VkCommandBuffer * pCommandBuffers,VkResult result)575 void ObjectLifetimes::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
576 VkCommandBuffer *pCommandBuffers, VkResult result) {
577 if (result != VK_SUCCESS) return;
578 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
579 AllocateCommandBuffer(device, pAllocateInfo->commandPool, pCommandBuffers[i], pAllocateInfo->level);
580 }
581 }
582
PreCallValidateAllocateDescriptorSets(VkDevice device,const VkDescriptorSetAllocateInfo * pAllocateInfo,VkDescriptorSet * pDescriptorSets)583 bool ObjectLifetimes::PreCallValidateAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
584 VkDescriptorSet *pDescriptorSets) {
585 bool skip = false;
586 auto lock = read_shared_lock();
587 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkAllocateDescriptorSets-device-parameter",
588 kVUIDUndefined);
589 skip |= ValidateObject(device, pAllocateInfo->descriptorPool, kVulkanObjectTypeDescriptorPool, false,
590 "VUID-VkDescriptorSetAllocateInfo-descriptorPool-parameter",
591 "VUID-VkDescriptorSetAllocateInfo-commonparent");
592 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
593 skip |= ValidateObject(device, pAllocateInfo->pSetLayouts[i], kVulkanObjectTypeDescriptorSetLayout, false,
594 "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-parameter",
595 "VUID-VkDescriptorSetAllocateInfo-commonparent");
596 }
597 return skip;
598 }
599
PostCallRecordAllocateDescriptorSets(VkDevice device,const VkDescriptorSetAllocateInfo * pAllocateInfo,VkDescriptorSet * pDescriptorSets,VkResult result)600 void ObjectLifetimes::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
601 VkDescriptorSet *pDescriptorSets, VkResult result) {
602 if (result != VK_SUCCESS) return;
603 auto lock = write_shared_lock();
604 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
605 AllocateDescriptorSet(device, pAllocateInfo->descriptorPool, pDescriptorSets[i]);
606 }
607 }
608
PreCallValidateFreeCommandBuffers(VkDevice device,VkCommandPool commandPool,uint32_t commandBufferCount,const VkCommandBuffer * pCommandBuffers)609 bool ObjectLifetimes::PreCallValidateFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
610 const VkCommandBuffer *pCommandBuffers) {
611 bool skip = false;
612 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkFreeCommandBuffers-device-parameter",
613 kVUIDUndefined);
614 skip |= ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, false,
615 "VUID-vkFreeCommandBuffers-commandPool-parameter", "VUID-vkFreeCommandBuffers-commandPool-parent");
616 for (uint32_t i = 0; i < commandBufferCount; i++) {
617 if (pCommandBuffers[i] != VK_NULL_HANDLE) {
618 skip |= ValidateCommandBuffer(device, commandPool, pCommandBuffers[i]);
619 skip |= ValidateDestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer, nullptr, kVUIDUndefined,
620 kVUIDUndefined);
621 }
622 }
623 return skip;
624 }
625
PreCallRecordFreeCommandBuffers(VkDevice device,VkCommandPool commandPool,uint32_t commandBufferCount,const VkCommandBuffer * pCommandBuffers)626 void ObjectLifetimes::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
627 const VkCommandBuffer *pCommandBuffers) {
628 for (uint32_t i = 0; i < commandBufferCount; i++) {
629 RecordDestroyObject(device, pCommandBuffers[i], kVulkanObjectTypeCommandBuffer);
630 }
631 }
632
PreCallValidateDestroySwapchainKHR(VkDevice device,VkSwapchainKHR swapchain,const VkAllocationCallbacks * pAllocator)633 bool ObjectLifetimes::PreCallValidateDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
634 const VkAllocationCallbacks *pAllocator) {
635 return ValidateDestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR, pAllocator,
636 "VUID-vkDestroySwapchainKHR-swapchain-01283", "VUID-vkDestroySwapchainKHR-swapchain-01284");
637 }
638
PreCallRecordDestroySwapchainKHR(VkDevice device,VkSwapchainKHR swapchain,const VkAllocationCallbacks * pAllocator)639 void ObjectLifetimes::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
640 const VkAllocationCallbacks *pAllocator) {
641 RecordDestroyObject(device, swapchain, kVulkanObjectTypeSwapchainKHR);
642
643 auto snapshot = swapchainImageMap.snapshot(
644 [swapchain](std::shared_ptr<ObjTrackState> pNode) { return pNode->parent_object == HandleToUint64(swapchain); });
645 for (const auto &itr : snapshot) {
646 swapchainImageMap.erase(itr.first);
647 }
648 }
649
PreCallValidateFreeDescriptorSets(VkDevice device,VkDescriptorPool descriptorPool,uint32_t descriptorSetCount,const VkDescriptorSet * pDescriptorSets)650 bool ObjectLifetimes::PreCallValidateFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool,
651 uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets) {
652 auto lock = read_shared_lock();
653 bool skip = false;
654 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkFreeDescriptorSets-device-parameter",
655 kVUIDUndefined);
656 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, false,
657 "VUID-vkFreeDescriptorSets-descriptorPool-parameter", "VUID-vkFreeDescriptorSets-descriptorPool-parent");
658 for (uint32_t i = 0; i < descriptorSetCount; i++) {
659 if (pDescriptorSets[i] != VK_NULL_HANDLE) {
660 skip |= ValidateDescriptorSet(device, descriptorPool, pDescriptorSets[i]);
661 skip |= ValidateDestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet, nullptr, kVUIDUndefined,
662 kVUIDUndefined);
663 }
664 }
665 return skip;
666 }
PreCallRecordFreeDescriptorSets(VkDevice device,VkDescriptorPool descriptorPool,uint32_t descriptorSetCount,const VkDescriptorSet * pDescriptorSets)667 void ObjectLifetimes::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
668 const VkDescriptorSet *pDescriptorSets) {
669 auto lock = write_shared_lock();
670 std::shared_ptr<ObjTrackState> pPoolNode = nullptr;
671 auto itr = object_map[kVulkanObjectTypeDescriptorPool].find(HandleToUint64(descriptorPool));
672 if (itr != object_map[kVulkanObjectTypeDescriptorPool].end()) {
673 pPoolNode = itr->second;
674 }
675 for (uint32_t i = 0; i < descriptorSetCount; i++) {
676 RecordDestroyObject(device, pDescriptorSets[i], kVulkanObjectTypeDescriptorSet);
677 if (pPoolNode) {
678 pPoolNode->child_objects->erase(HandleToUint64(pDescriptorSets[i]));
679 }
680 }
681 }
682
PreCallValidateDestroyDescriptorPool(VkDevice device,VkDescriptorPool descriptorPool,const VkAllocationCallbacks * pAllocator)683 bool ObjectLifetimes::PreCallValidateDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
684 const VkAllocationCallbacks *pAllocator) {
685 auto lock = read_shared_lock();
686 bool skip = false;
687 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkDestroyDescriptorPool-device-parameter",
688 kVUIDUndefined);
689 skip |= ValidateObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, true,
690 "VUID-vkDestroyDescriptorPool-descriptorPool-parameter",
691 "VUID-vkDestroyDescriptorPool-descriptorPool-parent");
692
693 auto itr = object_map[kVulkanObjectTypeDescriptorPool].find(HandleToUint64(descriptorPool));
694 if (itr != object_map[kVulkanObjectTypeDescriptorPool].end()) {
695 auto pPoolNode = itr->second;
696 for (auto set : *pPoolNode->child_objects) {
697 skip |= ValidateDestroyObject(device, (VkDescriptorSet)set, kVulkanObjectTypeDescriptorSet, nullptr, kVUIDUndefined,
698 kVUIDUndefined);
699 }
700 }
701 skip |= ValidateDestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool, pAllocator,
702 "VUID-vkDestroyDescriptorPool-descriptorPool-00304",
703 "VUID-vkDestroyDescriptorPool-descriptorPool-00305");
704 return skip;
705 }
PreCallRecordDestroyDescriptorPool(VkDevice device,VkDescriptorPool descriptorPool,const VkAllocationCallbacks * pAllocator)706 void ObjectLifetimes::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
707 const VkAllocationCallbacks *pAllocator) {
708 auto lock = write_shared_lock();
709 auto itr = object_map[kVulkanObjectTypeDescriptorPool].find(HandleToUint64(descriptorPool));
710 if (itr != object_map[kVulkanObjectTypeDescriptorPool].end()) {
711 auto pPoolNode = itr->second;
712 for (auto set : *pPoolNode->child_objects) {
713 RecordDestroyObject(device, (VkDescriptorSet)set, kVulkanObjectTypeDescriptorSet);
714 }
715 pPoolNode->child_objects->clear();
716 }
717 RecordDestroyObject(device, descriptorPool, kVulkanObjectTypeDescriptorPool);
718 }
719
PreCallValidateDestroyCommandPool(VkDevice device,VkCommandPool commandPool,const VkAllocationCallbacks * pAllocator)720 bool ObjectLifetimes::PreCallValidateDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
721 const VkAllocationCallbacks *pAllocator) {
722 bool skip = false;
723 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkDestroyCommandPool-device-parameter",
724 kVUIDUndefined);
725 skip |= ValidateObject(device, commandPool, kVulkanObjectTypeCommandPool, true,
726 "VUID-vkDestroyCommandPool-commandPool-parameter", "VUID-vkDestroyCommandPool-commandPool-parent");
727
728 auto snapshot = object_map[kVulkanObjectTypeCommandBuffer].snapshot(
729 [commandPool](std::shared_ptr<ObjTrackState> pNode) { return pNode->parent_object == HandleToUint64(commandPool); });
730 for (const auto &itr : snapshot) {
731 auto pNode = itr.second;
732 skip |= ValidateCommandBuffer(device, commandPool, reinterpret_cast<VkCommandBuffer>(itr.first));
733 skip |= ValidateDestroyObject(device, reinterpret_cast<VkCommandBuffer>(itr.first), kVulkanObjectTypeCommandBuffer, nullptr,
734 kVUIDUndefined, kVUIDUndefined);
735 }
736 skip |= ValidateDestroyObject(device, commandPool, kVulkanObjectTypeCommandPool, pAllocator,
737 "VUID-vkDestroyCommandPool-commandPool-00042", "VUID-vkDestroyCommandPool-commandPool-00043");
738 return skip;
739 }
740
PreCallRecordDestroyCommandPool(VkDevice device,VkCommandPool commandPool,const VkAllocationCallbacks * pAllocator)741 void ObjectLifetimes::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
742 const VkAllocationCallbacks *pAllocator) {
743 auto snapshot = object_map[kVulkanObjectTypeCommandBuffer].snapshot(
744 [commandPool](std::shared_ptr<ObjTrackState> pNode) { return pNode->parent_object == HandleToUint64(commandPool); });
745 // A CommandPool's cmd buffers are implicitly deleted when pool is deleted. Remove this pool's cmdBuffers from cmd buffer map.
746 for (const auto &itr : snapshot) {
747 RecordDestroyObject(device, reinterpret_cast<VkCommandBuffer>(itr.first), kVulkanObjectTypeCommandBuffer);
748 }
749 RecordDestroyObject(device, commandPool, kVulkanObjectTypeCommandPool);
750 }
751
PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties2KHR * pQueueFamilyProperties)752 bool ObjectLifetimes::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
753 uint32_t *pQueueFamilyPropertyCount,
754 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
755 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
756 "VUID-vkGetPhysicalDeviceQueueFamilyProperties2-physicalDevice-parameter", kVUIDUndefined);
757 }
758
PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties2 * pQueueFamilyProperties)759 bool ObjectLifetimes::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice,
760 uint32_t *pQueueFamilyPropertyCount,
761 VkQueueFamilyProperties2 *pQueueFamilyProperties) {
762 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
763 "VUID-vkGetPhysicalDeviceQueueFamilyProperties2-physicalDevice-parameter", kVUIDUndefined);
764 }
765
PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties2KHR * pQueueFamilyProperties)766 void ObjectLifetimes::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
767 uint32_t *pQueueFamilyPropertyCount,
768 VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {}
769
PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties2KHR * pQueueFamilyProperties)770 void ObjectLifetimes::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
771 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {}
772
PreCallValidateGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPropertiesKHR * pProperties)773 bool ObjectLifetimes::PreCallValidateGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
774 uint32_t *pPropertyCount,
775 VkDisplayPropertiesKHR *pProperties) {
776 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
777 "VUID-vkGetPhysicalDeviceDisplayPropertiesKHR-physicalDevice-parameter", kVUIDUndefined);
778 }
779
PostCallRecordGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPropertiesKHR * pProperties,VkResult result)780 void ObjectLifetimes::PostCallRecordGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
781 VkDisplayPropertiesKHR *pProperties, VkResult result) {
782 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
783 if (pProperties) {
784 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
785 CreateObject(physicalDevice, pProperties[i].display, kVulkanObjectTypeDisplayKHR, nullptr);
786 }
787 }
788 }
789
PreCallValidateGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModePropertiesKHR * pProperties)790 bool ObjectLifetimes::PreCallValidateGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
791 uint32_t *pPropertyCount,
792 VkDisplayModePropertiesKHR *pProperties) {
793 bool skip = false;
794 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
795 "VUID-vkGetDisplayModePropertiesKHR-physicalDevice-parameter", kVUIDUndefined);
796 skip |= ValidateObject(physicalDevice, display, kVulkanObjectTypeDisplayKHR, false,
797 "VUID-vkGetDisplayModePropertiesKHR-display-parameter", kVUIDUndefined);
798
799 return skip;
800 }
801
PostCallRecordGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModePropertiesKHR * pProperties,VkResult result)802 void ObjectLifetimes::PostCallRecordGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
803 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties,
804 VkResult result) {
805 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
806 if (pProperties) {
807 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
808 CreateObject(physicalDevice, pProperties[i].displayMode, kVulkanObjectTypeDisplayModeKHR, nullptr);
809 }
810 }
811 }
812
PreCallValidateGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayProperties2KHR * pProperties)813 bool ObjectLifetimes::PreCallValidateGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
814 uint32_t *pPropertyCount,
815 VkDisplayProperties2KHR *pProperties) {
816 return ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
817 "VUID-vkGetPhysicalDeviceDisplayProperties2KHR-physicalDevice-parameter", kVUIDUndefined);
818 }
819
PostCallRecordGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayProperties2KHR * pProperties,VkResult result)820 void ObjectLifetimes::PostCallRecordGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
821 uint32_t *pPropertyCount,
822 VkDisplayProperties2KHR *pProperties, VkResult result) {
823 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
824 for (uint32_t index = 0; index < *pPropertyCount; ++index) {
825 CreateObject(physicalDevice, pProperties[index].displayProperties.display, kVulkanObjectTypeDisplayKHR, nullptr);
826 }
827 }
828
PreCallValidateGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModeProperties2KHR * pProperties)829 bool ObjectLifetimes::PreCallValidateGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
830 uint32_t *pPropertyCount,
831 VkDisplayModeProperties2KHR *pProperties) {
832 bool skip = false;
833 skip |= ValidateObject(physicalDevice, physicalDevice, kVulkanObjectTypePhysicalDevice, false,
834 "VUID-vkGetDisplayModeProperties2KHR-physicalDevice-parameter", kVUIDUndefined);
835 skip |= ValidateObject(physicalDevice, display, kVulkanObjectTypeDisplayKHR, false,
836 "VUID-vkGetDisplayModeProperties2KHR-display-parameter", kVUIDUndefined);
837
838 return skip;
839 }
840
PostCallRecordGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModeProperties2KHR * pProperties,VkResult result)841 void ObjectLifetimes::PostCallRecordGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
842 uint32_t *pPropertyCount, VkDisplayModeProperties2KHR *pProperties,
843 VkResult result) {
844 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
845 for (uint32_t index = 0; index < *pPropertyCount; ++index) {
846 CreateObject(physicalDevice, pProperties[index].displayModeProperties.displayMode, kVulkanObjectTypeDisplayModeKHR,
847 nullptr);
848 }
849 }
850
PreCallValidateAcquirePerformanceConfigurationINTEL(VkDevice device,const VkPerformanceConfigurationAcquireInfoINTEL * pAcquireInfo,VkPerformanceConfigurationINTEL * pConfiguration)851 bool ObjectLifetimes::PreCallValidateAcquirePerformanceConfigurationINTEL(
852 VkDevice device, const VkPerformanceConfigurationAcquireInfoINTEL *pAcquireInfo,
853 VkPerformanceConfigurationINTEL *pConfiguration) {
854 bool skip = false;
855 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false,
856 "VUID-vkAcquirePerformanceConfigurationINTEL-device-parameter", kVUIDUndefined);
857
858 return skip;
859 }
860
PreCallValidateReleasePerformanceConfigurationINTEL(VkDevice device,VkPerformanceConfigurationINTEL configuration)861 bool ObjectLifetimes::PreCallValidateReleasePerformanceConfigurationINTEL(VkDevice device,
862 VkPerformanceConfigurationINTEL configuration) {
863 bool skip = false;
864 skip |= ValidateObject(device, device, kVulkanObjectTypeDevice, false,
865 "VUID-vkReleasePerformanceConfigurationINTEL-device-parameter", kVUIDUndefined);
866
867 return skip;
868 }
869
PreCallValidateQueueSetPerformanceConfigurationINTEL(VkQueue queue,VkPerformanceConfigurationINTEL configuration)870 bool ObjectLifetimes::PreCallValidateQueueSetPerformanceConfigurationINTEL(VkQueue queue,
871 VkPerformanceConfigurationINTEL configuration) {
872 bool skip = false;
873 skip |=
874 ValidateObject(queue, queue, kVulkanObjectTypeQueue, false, "VUID-vkQueueSetPerformanceConfigurationINTEL-queue-parameter",
875 "VUID-vkQueueSetPerformanceConfigurationINTEL-commonparent");
876
877 return skip;
878 }
879
PreCallValidateCreateFramebuffer(VkDevice device,const VkFramebufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkFramebuffer * pFramebuffer)880 bool ObjectLifetimes::PreCallValidateCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
881 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer) {
882 bool skip = false;
883 skip |=
884 ValidateObject(device, device, kVulkanObjectTypeDevice, false, "VUID-vkCreateFramebuffer-device-parameter", kVUIDUndefined);
885 if (pCreateInfo) {
886 skip |= ValidateObject(device, pCreateInfo->renderPass, kVulkanObjectTypeRenderPass, false,
887 "VUID-VkFramebufferCreateInfo-renderPass-parameter", "VUID-VkFramebufferCreateInfo-commonparent");
888 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) == 0) {
889 for (uint32_t index1 = 0; index1 < pCreateInfo->attachmentCount; ++index1) {
890 skip |= ValidateObject(device, pCreateInfo->pAttachments[index1], kVulkanObjectTypeImageView, true, kVUIDUndefined,
891 "VUID-VkFramebufferCreateInfo-commonparent");
892 }
893 }
894 }
895
896 return skip;
897 }
898
PostCallRecordCreateFramebuffer(VkDevice device,const VkFramebufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkFramebuffer * pFramebuffer,VkResult result)899 void ObjectLifetimes::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
900 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
901 VkResult result) {
902 if (result != VK_SUCCESS) return;
903 CreateObject(device, *pFramebuffer, kVulkanObjectTypeFramebuffer, pAllocator);
904 }
905