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