forked from KhronosGroup/Vulkan-LoaderAndValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_tracker.cpp
5742 lines (5341 loc) · 304 KB
/
object_tracker.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-2017 The Khronos Group Inc.
* Copyright (c) 2015-2017 Valve Corporation
* Copyright (c) 2015-2017 LunarG, Inc.
* Copyright (c) 2015-2017 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: Tobin Ehlis <[email protected]>
* Author: Courtney Goeltzenleuchter <[email protected]>
* Author: Jon Ashburn <[email protected]>
* Author: Mike Stroyan <[email protected]>
* Author: Tony Barbour <[email protected]>
*/
#include "vk_loader_platform.h"
#include "vulkan/vulkan.h"
#include <cinttypes>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include "vk_layer_config.h"
#include "vk_layer_data.h"
#include "vk_layer_logging.h"
#include "vk_layer_table.h"
#include "vulkan/vk_layer.h"
#include "object_tracker.h"
#include "vk_validation_error_messages.h"
namespace object_tracker {
static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
static void InitObjectTracker(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_object_tracker");
}
// Add new queue to head of global queue list
static void AddQueueInfo(VkDevice device, uint32_t queue_node_index, VkQueue queue) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
auto queueItem = device_data->queue_info_map.find(queue);
if (queueItem == device_data->queue_info_map.end()) {
OT_QUEUE_INFO *p_queue_info = new OT_QUEUE_INFO;
if (p_queue_info != NULL) {
memset(p_queue_info, 0, sizeof(OT_QUEUE_INFO));
p_queue_info->queue = queue;
p_queue_info->queue_node_index = queue_node_index;
device_data->queue_info_map[queue] = p_queue_info;
} else {
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
reinterpret_cast<uint64_t>(queue), __LINE__, OBJTRACK_INTERNAL_ERROR, LayerName,
"ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");
}
}
}
// Destroy memRef lists and free all memory
static void DestroyQueueDataStructures(VkDevice device) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
for (auto queue_item : device_data->queue_info_map) {
delete queue_item.second;
}
device_data->queue_info_map.clear();
// Destroy the items in the queue map
auto queue = device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT].begin();
while (queue != device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT].end()) {
uint32_t obj_index = queue->second->object_type;
assert(device_data->num_total_objects > 0);
device_data->num_total_objects--;
assert(device_data->num_objects[obj_index] > 0);
device_data->num_objects[obj_index]--;
log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, queue->second->object_type, queue->second->handle,
__LINE__, OBJTRACK_NONE, LayerName,
"OBJ_STAT Destroy Queue obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " Queue objs).",
queue->second->handle, device_data->num_total_objects, device_data->num_objects[obj_index]);
delete queue->second;
queue = device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT].erase(queue);
}
}
// Check Queue type flags for selected queue operations
static void ValidateQueueFlags(VkQueue queue, const char *function) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
auto queue_item = device_data->queue_info_map.find(queue);
if (queue_item != device_data->queue_info_map.end()) {
OT_QUEUE_INFO *pQueueInfo = queue_item->second;
if (pQueueInfo != NULL) {
layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(device_data->physical_device), layer_data_map);
if ((instance_data->queue_family_properties[pQueueInfo->queue_node_index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) ==
0) {
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT,
reinterpret_cast<uint64_t>(queue), __LINE__, VALIDATION_ERROR_01651, LayerName,
"Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_BINDING_BIT not set. %s",
function, validation_error_map[VALIDATION_ERROR_01651]);
}
}
}
}
static void AllocateCommandBuffer(VkDevice device, const VkCommandPool command_pool, const VkCommandBuffer command_buffer,
VkDebugReportObjectTypeEXT object_type, VkCommandBufferLevel level) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, object_type,
reinterpret_cast<const uint64_t>(command_buffer), __LINE__, OBJTRACK_NONE, LayerName,
"OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
string_VkDebugReportObjectTypeEXT(object_type), reinterpret_cast<const uint64_t>(command_buffer));
OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
pNewObjNode->object_type = object_type;
pNewObjNode->handle = reinterpret_cast<const uint64_t>(command_buffer);
pNewObjNode->parent_object = reinterpret_cast<const uint64_t &>(command_pool);
if (level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
pNewObjNode->status = OBJSTATUS_COMMAND_BUFFER_SECONDARY;
} else {
pNewObjNode->status = OBJSTATUS_NONE;
}
device_data->object_map[object_type][reinterpret_cast<const uint64_t>(command_buffer)] = pNewObjNode;
device_data->num_objects[object_type]++;
device_data->num_total_objects++;
}
static bool ValidateCommandBuffer(VkDevice device, VkCommandPool command_pool, VkCommandBuffer command_buffer) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
bool skip_call = false;
uint64_t object_handle = reinterpret_cast<uint64_t>(command_buffer);
if (device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT].find(object_handle) !=
device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT].end()) {
OBJTRACK_NODE *pNode =
device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT][reinterpret_cast<uint64_t>(command_buffer)];
if (pNode->parent_object != reinterpret_cast<uint64_t &>(command_pool)) {
skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->object_type, object_handle,
__LINE__, VALIDATION_ERROR_00102, LayerName,
"FreeCommandBuffers is attempting to free Command Buffer 0x%" PRIxLEAST64
" belonging to Command Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 "). %s",
reinterpret_cast<uint64_t>(command_buffer), pNode->parent_object,
reinterpret_cast<uint64_t &>(command_pool), validation_error_map[VALIDATION_ERROR_00102]);
}
} else {
skip_call |=
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
object_handle, __LINE__, VALIDATION_ERROR_00097, LayerName, "Invalid %s Object 0x%" PRIxLEAST64 ". %s",
object_name[VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT], object_handle,
validation_error_map[VALIDATION_ERROR_00097]);
}
return skip_call;
}
static void AllocateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set,
VkDebugReportObjectTypeEXT object_type) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, object_type,
reinterpret_cast<uint64_t &>(descriptor_set), __LINE__, OBJTRACK_NONE, LayerName,
"OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, object_name[object_type],
reinterpret_cast<uint64_t &>(descriptor_set));
OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
pNewObjNode->object_type = object_type;
pNewObjNode->status = OBJSTATUS_NONE;
pNewObjNode->handle = reinterpret_cast<uint64_t &>(descriptor_set);
pNewObjNode->parent_object = reinterpret_cast<uint64_t &>(descriptor_pool);
device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT][reinterpret_cast<uint64_t &>(descriptor_set)] =
pNewObjNode;
device_data->num_objects[object_type]++;
device_data->num_total_objects++;
}
static bool ValidateDescriptorSet(VkDevice device, VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
bool skip_call = false;
uint64_t object_handle = reinterpret_cast<uint64_t &>(descriptor_set);
auto dsItem = device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT].find(object_handle);
if (dsItem != device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT].end()) {
OBJTRACK_NODE *pNode = dsItem->second;
if (pNode->parent_object != reinterpret_cast<uint64_t &>(descriptor_pool)) {
skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->object_type, object_handle,
__LINE__, VALIDATION_ERROR_00927, LayerName,
"FreeDescriptorSets is attempting to free descriptorSet 0x%" PRIxLEAST64
" belonging to Descriptor Pool 0x%" PRIxLEAST64 " from pool 0x%" PRIxLEAST64 "). %s",
reinterpret_cast<uint64_t &>(descriptor_set), pNode->parent_object,
reinterpret_cast<uint64_t &>(descriptor_pool), validation_error_map[VALIDATION_ERROR_00927]);
}
} else {
skip_call |=
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
object_handle, __LINE__, VALIDATION_ERROR_00920, LayerName, "Invalid %s Object 0x%" PRIxLEAST64 ". %s",
object_name[VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT], object_handle,
validation_error_map[VALIDATION_ERROR_00920]);
}
return skip_call;
}
static void CreateQueue(VkDevice device, VkQueue vkObj, VkDebugReportObjectTypeEXT object_type) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, object_type, reinterpret_cast<uint64_t>(vkObj), __LINE__,
OBJTRACK_NONE, LayerName, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
object_name[object_type], reinterpret_cast<uint64_t>(vkObj));
OBJTRACK_NODE *p_obj_node = NULL;
auto queue_item = device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT].find(reinterpret_cast<uint64_t>(vkObj));
if (queue_item == device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT].end()) {
p_obj_node = new OBJTRACK_NODE;
device_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT][reinterpret_cast<uint64_t>(vkObj)] = p_obj_node;
device_data->num_objects[object_type]++;
device_data->num_total_objects++;
} else {
p_obj_node = queue_item->second;
}
p_obj_node->object_type = object_type;
p_obj_node->status = OBJSTATUS_NONE;
p_obj_node->handle = reinterpret_cast<uint64_t>(vkObj);
}
static void CreateSwapchainImageObject(VkDevice dispatchable_object, VkImage swapchain_image, VkSwapchainKHR swapchain) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map);
log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
reinterpret_cast<uint64_t &>(swapchain_image), __LINE__, OBJTRACK_NONE, LayerName,
"OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, "SwapchainImage",
reinterpret_cast<uint64_t &>(swapchain_image));
OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
pNewObjNode->object_type = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT;
pNewObjNode->status = OBJSTATUS_NONE;
pNewObjNode->handle = reinterpret_cast<uint64_t &>(swapchain_image);
pNewObjNode->parent_object = reinterpret_cast<uint64_t &>(swapchain);
device_data->swapchainImageMap[reinterpret_cast<uint64_t &>(swapchain_image)] = pNewObjNode;
}
template <typename T>
uint64_t handle_value(T handle) {
return reinterpret_cast<uint64_t &>(handle);
}
template <typename T>
uint64_t handle_value(T *handle) {
return reinterpret_cast<uint64_t>(handle);
}
template <typename T1, typename T2>
static void CreateObject(T1 dispatchable_object, T2 object, VkDebugReportObjectTypeEXT object_type,
const VkAllocationCallbacks *pAllocator) {
layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map);
auto object_handle = handle_value(object);
bool custom_allocator = pAllocator != nullptr;
if (!instance_data->object_map[object_type].count(object_handle)) {
log_msg(instance_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, object_type, object_handle, __LINE__,
OBJTRACK_NONE, LayerName, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
object_name[object_type], object_handle);
OBJTRACK_NODE *pNewObjNode = new OBJTRACK_NODE;
pNewObjNode->object_type = object_type;
pNewObjNode->status = custom_allocator ? OBJSTATUS_CUSTOM_ALLOCATOR : OBJSTATUS_NONE;
pNewObjNode->handle = object_handle;
instance_data->object_map[object_type][object_handle] = pNewObjNode;
instance_data->num_objects[object_type]++;
instance_data->num_total_objects++;
}
}
template <typename T1, typename T2>
static void DestroyObject(T1 dispatchable_object, T2 object, VkDebugReportObjectTypeEXT object_type,
const VkAllocationCallbacks *pAllocator, enum UNIQUE_VALIDATION_ERROR_CODE expected_custom_allocator_code,
enum UNIQUE_VALIDATION_ERROR_CODE expected_default_allocator_code) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map);
auto object_handle = handle_value(object);
bool custom_allocator = pAllocator != nullptr;
if (object_handle != VK_NULL_HANDLE) {
auto item = device_data->object_map[object_type].find(object_handle);
if (item != device_data->object_map[object_type].end()) {
OBJTRACK_NODE *pNode = item->second;
assert(device_data->num_total_objects > 0);
device_data->num_total_objects--;
assert(device_data->num_objects[pNode->object_type] > 0);
device_data->num_objects[pNode->object_type]--;
log_msg(device_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->object_type, object_handle, __LINE__,
OBJTRACK_NONE, LayerName,
"OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",
object_name[pNode->object_type], reinterpret_cast<uint64_t &>(object), device_data->num_total_objects,
device_data->num_objects[pNode->object_type], object_name[pNode->object_type]);
auto allocated_with_custom = (pNode->status & OBJSTATUS_CUSTOM_ALLOCATOR) ? true : false;
if (allocated_with_custom && !custom_allocator && expected_custom_allocator_code != VALIDATION_ERROR_UNDEFINED) {
// This check only verifies that custom allocation callbacks were provided to both Create and Destroy calls,
// it cannot verify that these allocation callbacks are compatible with each other.
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object_handle, __LINE__,
expected_custom_allocator_code, LayerName,
"Custom allocator not specified while destroying %s obj 0x%" PRIxLEAST64 " but specified at creation. %s",
object_name[object_type], object_handle, validation_error_map[expected_custom_allocator_code]);
} else if (!allocated_with_custom && custom_allocator &&
expected_default_allocator_code != VALIDATION_ERROR_UNDEFINED) {
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object_handle, __LINE__,
expected_default_allocator_code, LayerName,
"Custom allocator specified while destroying %s obj 0x%" PRIxLEAST64 " but not specified at creation. %s",
object_name[object_type], object_handle, validation_error_map[expected_default_allocator_code]);
}
delete pNode;
device_data->object_map[object_type].erase(item);
} else {
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, object_handle, __LINE__,
OBJTRACK_UNKNOWN_OBJECT, LayerName,
"Unable to remove %s obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",
object_name[object_type], object_handle);
}
}
}
template <typename T1, typename T2>
static bool ValidateObject(T1 dispatchable_object, T2 object, VkDebugReportObjectTypeEXT object_type, bool null_allowed,
enum UNIQUE_VALIDATION_ERROR_CODE invalid_handle_code,
enum UNIQUE_VALIDATION_ERROR_CODE wrong_device_code) {
if (null_allowed && (object == VK_NULL_HANDLE)) {
return false;
}
auto object_handle = handle_value(object);
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map);
// Look for object in device object map
if (device_data->object_map[object_type].find(object_handle) == device_data->object_map[object_type].end()) {
// If object is an image, also look for it in the swapchain image map
if ((object_type != VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT) ||
(device_data->swapchainImageMap.find(object_handle) == device_data->swapchainImageMap.end())) {
// Object not found, look for it in other device object maps
for (auto other_device_data : layer_data_map) {
if (other_device_data.second != device_data)
{
if (other_device_data.second->object_map[object_type].find(object_handle) !=
other_device_data.second->object_map[object_type].end() ||
(object_type == VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT &&
other_device_data.second->swapchainImageMap.find(object_handle) !=
other_device_data.second->swapchainImageMap.end())) {
// Object found on other device, report an error if object has a device parent error code
if (wrong_device_code != VALIDATION_ERROR_UNDEFINED) {
return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object_handle,
__LINE__, wrong_device_code, LayerName,
"Object 0x%" PRIxLEAST64
" was not created, allocated or retrieved from the correct device. %s",
object_handle, validation_error_map[wrong_device_code]);
} else {
return false;
}
}
}
}
// Report an error if object was not found anywhere
return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object_handle, __LINE__,
invalid_handle_code, LayerName, "Invalid %s Object 0x%" PRIxLEAST64 ". %s", object_name[object_type],
object_handle, validation_error_map[invalid_handle_code]);
}
}
return false;
}
static void DeviceReportUndestroyedObjects(VkDevice device, VkDebugReportObjectTypeEXT object_type,
enum UNIQUE_VALIDATION_ERROR_CODE error_code) {
layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
for (auto item = device_data->object_map[object_type].begin(); item != device_data->object_map[object_type].end();) {
OBJTRACK_NODE *object_info = item->second;
log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_info->object_type, object_info->handle, __LINE__,
error_code, LayerName,
"OBJ ERROR : For device 0x%" PRIxLEAST64 ", %s object 0x%" PRIxLEAST64 " has not been destroyed. %s",
reinterpret_cast<uint64_t>(device), object_name[object_type], object_info->handle,
validation_error_map[error_code]);
item = device_data->object_map[object_type].erase(item);
}
}
VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
std::unique_lock<std::mutex> lock(global_lock);
dispatch_key key = get_dispatch_key(instance);
layer_data *instance_data = GetLayerDataPtr(key, layer_data_map);
// Enable the temporary callback(s) here to catch cleanup issues:
bool callback_setup = false;
if (instance_data->num_tmp_callbacks > 0) {
if (!layer_enable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks,
instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks)) {
callback_setup = true;
}
}
// TODO: The instance handle can not be validated here. The loader will likely have to validate it.
ValidateObject(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, true, VALIDATION_ERROR_00021,
VALIDATION_ERROR_UNDEFINED);
DestroyObject(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, pAllocator, VALIDATION_ERROR_00019,
VALIDATION_ERROR_00020);
// Report any remaining objects in LL
for (auto iit = instance_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT].begin();
iit != instance_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT].end();) {
OBJTRACK_NODE *pNode = iit->second;
VkDevice device = reinterpret_cast<VkDevice>(pNode->handle);
log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->object_type, pNode->handle, __LINE__,
OBJTRACK_OBJECT_LEAK, LayerName, "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.",
string_VkDebugReportObjectTypeEXT(pNode->object_type), pNode->handle);
// Semaphore:
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, VALIDATION_ERROR_00018);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VALIDATION_ERROR_00018);
// DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT);
}
instance_data->object_map[VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT].clear();
VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ot_instance_table_map, instance);
pInstanceTable->DestroyInstance(instance, pAllocator);
// Disable and cleanup the temporary callback(s):
if (callback_setup) {
layer_disable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, instance_data->tmp_callbacks);
}
if (instance_data->num_tmp_callbacks > 0) {
layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks);
instance_data->num_tmp_callbacks = 0;
}
// Clean up logging callback, if any
while (instance_data->logging_callback.size() > 0) {
VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator);
instance_data->logging_callback.pop_back();
}
layer_debug_report_destroy_instance(instance_data->report_data);
layer_data_map.erase(key);
instanceExtMap.erase(pInstanceTable);
lock.unlock();
ot_instance_table_map.erase(key);
}
VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
std::unique_lock<std::mutex> lock(global_lock);
ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, true, VALIDATION_ERROR_00052,
VALIDATION_ERROR_UNDEFINED);
DestroyObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, pAllocator, VALIDATION_ERROR_00050,
VALIDATION_ERROR_00051);
// Report any remaining objects associated with this VkDevice object in LL
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VALIDATION_ERROR_00049);
// DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, VALIDATION_ERROR_00049);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, VALIDATION_ERROR_00049);
// DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT);
DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VALIDATION_ERROR_00049);
// DeviceReportUndestroyedObjects(device, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT);
// Clean up Queue's MemRef Linked Lists
DestroyQueueDataStructures(device);
lock.unlock();
dispatch_key key = get_dispatch_key(device);
VkLayerDispatchTable *pDisp = get_dispatch_table(ot_device_table_map, device);
pDisp->DestroyDevice(device, pAllocator);
ot_device_table_map.erase(key);
}
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false,
VALIDATION_ERROR_01679, VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_instance_table_map, physicalDevice)->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
}
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
VkFormatProperties *pFormatProperties) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false,
VALIDATION_ERROR_01683, VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_instance_table_map, physicalDevice)
->GetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties);
}
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
VkImageType type, VkImageTiling tiling,
VkImageUsageFlags usage, VkImageCreateFlags flags,
VkImageFormatProperties *pImageFormatProperties) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false,
VALIDATION_ERROR_01686, VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result =
get_dispatch_table(ot_instance_table_map, physicalDevice)
->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
return result;
}
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false,
VALIDATION_ERROR_00026, VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_instance_table_map, physicalDevice)->GetPhysicalDeviceProperties(physicalDevice, pProperties);
}
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceMemoryProperties *pMemoryProperties) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false,
VALIDATION_ERROR_00609, VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_instance_table_map, physicalDevice)->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
}
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *pName);
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *pName);
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName);
VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pPropertyCount,
VkExtensionProperties *pProperties);
VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pPropertyCount, VkLayerProperties *pProperties);
VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
VkLayerProperties *pProperties);
VKAPI_ATTR VkResult VKAPI_CALL QueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(queue, fence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, true, VALIDATION_ERROR_00130,
VALIDATION_ERROR_00131);
if (pSubmits) {
for (uint32_t idx0 = 0; idx0 < submitCount; ++idx0) {
if (pSubmits[idx0].pCommandBuffers) {
for (uint32_t idx1 = 0; idx1 < pSubmits[idx0].commandBufferCount; ++idx1) {
skip_call |= ValidateObject(queue, pSubmits[idx0].pCommandBuffers[idx1],
VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, false, VALIDATION_ERROR_00149,
VALIDATION_ERROR_00151);
}
}
if (pSubmits[idx0].pSignalSemaphores) {
for (uint32_t idx2 = 0; idx2 < pSubmits[idx0].signalSemaphoreCount; ++idx2) {
skip_call |=
ValidateObject(queue, pSubmits[idx0].pSignalSemaphores[idx2], VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT,
false, VALIDATION_ERROR_00150, VALIDATION_ERROR_00151);
}
}
if (pSubmits[idx0].pWaitSemaphores) {
for (uint32_t idx3 = 0; idx3 < pSubmits[idx0].waitSemaphoreCount; ++idx3) {
skip_call |=
ValidateObject(queue, pSubmits[idx0].pWaitSemaphores[idx3], VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT,
false, VALIDATION_ERROR_00146, VALIDATION_ERROR_00151);
}
}
}
}
if (queue) {
skip_call |= ValidateObject(queue, queue, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, false, VALIDATION_ERROR_00128,
VALIDATION_ERROR_00131);
}
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, queue)->QueueSubmit(queue, submitCount, pSubmits, fence);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL QueueWaitIdle(VkQueue queue) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(queue, queue, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, false, VALIDATION_ERROR_00317,
VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, queue)->QueueWaitIdle(queue);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL DeviceWaitIdle(VkDevice device) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00318,
VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->DeviceWaitIdle(device);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00612,
VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->AllocateMemory(device, pAllocateInfo, pAllocator, pMemory);
{
std::lock_guard<std::mutex> lock(global_lock);
if (result == VK_SUCCESS) {
CreateObject(device, *pMemory, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, pAllocator);
}
}
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL FlushMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount,
const VkMappedMemoryRange *pMemoryRanges) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00635,
VALIDATION_ERROR_UNDEFINED);
if (pMemoryRanges) {
for (uint32_t idx0 = 0; idx0 < memoryRangeCount; ++idx0) {
if (pMemoryRanges[idx0].memory) {
skip_call |= ValidateObject(device, pMemoryRanges[idx0].memory, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT,
false, VALIDATION_ERROR_00648, VALIDATION_ERROR_UNDEFINED);
}
}
}
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result =
get_dispatch_table(ot_device_table_map, device)->FlushMappedMemoryRanges(device, memoryRangeCount, pMemoryRanges);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL InvalidateMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount,
const VkMappedMemoryRange *pMemoryRanges) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00638,
VALIDATION_ERROR_UNDEFINED);
if (pMemoryRanges) {
for (uint32_t idx0 = 0; idx0 < memoryRangeCount; ++idx0) {
if (pMemoryRanges[idx0].memory) {
skip_call |= ValidateObject(device, pMemoryRanges[idx0].memory, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT,
false, VALIDATION_ERROR_00648, VALIDATION_ERROR_UNDEFINED);
}
}
}
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result =
get_dispatch_table(ot_device_table_map, device)->InvalidateMappedMemoryRanges(device, memoryRangeCount, pMemoryRanges);
return result;
}
VKAPI_ATTR void VKAPI_CALL GetDeviceMemoryCommitment(VkDevice device, VkDeviceMemory memory,
VkDeviceSize *pCommittedMemoryInBytes) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00654,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, memory, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, false, VALIDATION_ERROR_00655,
VALIDATION_ERROR_00657);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_device_table_map, device)->GetDeviceMemoryCommitment(device, memory, pCommittedMemoryInBytes);
}
VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory,
VkDeviceSize memoryOffset) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00798,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, false, VALIDATION_ERROR_00799,
VALIDATION_ERROR_00801);
skip_call |= ValidateObject(device, memory, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, false, VALIDATION_ERROR_00800,
VALIDATION_ERROR_00802);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->BindBufferMemory(device, buffer, memory, memoryOffset);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL BindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00807,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false, VALIDATION_ERROR_00808,
VALIDATION_ERROR_00810);
skip_call |= ValidateObject(device, memory, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, false, VALIDATION_ERROR_00809,
VALIDATION_ERROR_00811);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->BindImageMemory(device, image, memory, memoryOffset);
return result;
}
VKAPI_ATTR void VKAPI_CALL GetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
VkMemoryRequirements *pMemoryRequirements) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00783,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, false, VALIDATION_ERROR_00784,
VALIDATION_ERROR_00786);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_device_table_map, device)->GetBufferMemoryRequirements(device, buffer, pMemoryRequirements);
}
VKAPI_ATTR void VKAPI_CALL GetImageMemoryRequirements(VkDevice device, VkImage image, VkMemoryRequirements *pMemoryRequirements) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00787,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false, VALIDATION_ERROR_00788,
VALIDATION_ERROR_00790);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_device_table_map, device)->GetImageMemoryRequirements(device, image, pMemoryRequirements);
}
VKAPI_ATTR void VKAPI_CALL GetImageSparseMemoryRequirements(VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_01610,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, false, VALIDATION_ERROR_01611,
VALIDATION_ERROR_01614);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_device_table_map, device)
->GetImageSparseMemoryRequirements(device, image, pSparseMemoryRequirementCount, pSparseMemoryRequirements);
}
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
VkImageType type, VkSampleCountFlagBits samples,
VkImageUsageFlags usage, VkImageTiling tiling,
uint32_t *pPropertyCount,
VkSparseImageFormatProperties *pProperties) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(physicalDevice, physicalDevice, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, false,
VALIDATION_ERROR_01601, VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return;
}
get_dispatch_table(ot_instance_table_map, physicalDevice)
->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pPropertyCount,
pProperties);
}
VKAPI_ATTR VkResult VKAPI_CALL CreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkFence *pFence) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00166,
VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->CreateFence(device, pCreateInfo, pAllocator, pFence);
{
std::lock_guard<std::mutex> lock(global_lock);
if (result == VK_SUCCESS) {
CreateObject(device, *pFence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, pAllocator);
}
}
return result;
}
VKAPI_ATTR void VKAPI_CALL DestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00176,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, fence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, true, VALIDATION_ERROR_00177,
VALIDATION_ERROR_00179);
}
if (skip_call) {
return;
}
{
std::lock_guard<std::mutex> lock(global_lock);
DestroyObject(device, fence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, pAllocator, VALIDATION_ERROR_00174,
VALIDATION_ERROR_00175);
}
get_dispatch_table(ot_device_table_map, device)->DestroyFence(device, fence, pAllocator);
}
VKAPI_ATTR VkResult VKAPI_CALL ResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00184,
VALIDATION_ERROR_UNDEFINED);
if (pFences) {
for (uint32_t idx0 = 0; idx0 < fenceCount; ++idx0) {
skip_call |= ValidateObject(device, pFences[idx0], VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, false,
VALIDATION_ERROR_00185, VALIDATION_ERROR_00187);
}
}
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->ResetFences(device, fenceCount, pFences);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL GetFenceStatus(VkDevice device, VkFence fence) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00180,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, fence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, false, VALIDATION_ERROR_00181,
VALIDATION_ERROR_00182);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->GetFenceStatus(device, fence);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL WaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, VkBool32 waitAll,
uint64_t timeout) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00188,
VALIDATION_ERROR_UNDEFINED);
if (pFences) {
for (uint32_t idx0 = 0; idx0 < fenceCount; ++idx0) {
skip_call |= ValidateObject(device, pFences[idx0], VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, false,
VALIDATION_ERROR_00189, VALIDATION_ERROR_00191);
}
}
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL CreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00192,
VALIDATION_ERROR_UNDEFINED);
}
if (skip_call) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult result = get_dispatch_table(ot_device_table_map, device)->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
{
std::lock_guard<std::mutex> lock(global_lock);
if (result == VK_SUCCESS) {
CreateObject(device, *pSemaphore, VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, pAllocator);
}
}
return result;
}
VKAPI_ATTR void VKAPI_CALL DestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks *pAllocator) {
bool skip_call = false;
{
std::lock_guard<std::mutex> lock(global_lock);
skip_call |= ValidateObject(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false, VALIDATION_ERROR_00202,
VALIDATION_ERROR_UNDEFINED);
skip_call |= ValidateObject(device, semaphore, VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, true, VALIDATION_ERROR_00203,
VALIDATION_ERROR_00205);
}