forked from LunarG/VulkanSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vk-layer-generate.py
executable file
·1740 lines (1666 loc) · 98.6 KB
/
vk-layer-generate.py
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
#!/usr/bin/env python3
#
# VK
#
# Copyright (c) 2015-2016 The Khronos Group Inc.
# Copyright (c) 2015-2016 Valve Corporation
# Copyright (c) 2015-2016 LunarG, Inc.
# Copyright (c) 2015-2016 Google Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and/or associated documentation files (the "Materials"), to
# deal in the Materials without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Materials, and to permit persons to whom the Materials
# are furnished to do so, subject to the following conditions:
#
# The above copyright notice(s) and this permission notice shall be included
# in all copies or substantial portions of the Materials.
#
# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
#
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
# USE OR OTHER DEALINGS IN THE MATERIALS
#
# Author: Tobin Ehlis <tobine@google.com>
# Author: Courtney Goeltzenleuchter <courtneygo@google.com>
# Author: Jon Ashburn <jon@lunarg.com>
# Author: Mark Lobodzinski <mark@lunarg.com>
# Author: Mike Stroyan <stroyan@google.com>
# Author: Tony Barbour <tony@LunarG.com>
# Author: Chia-I Wu <olv@google.com>
# Author: Gwan-gyeong Mun <kk.moon@samsung.com>
import sys
import os
import re
import vulkan
import vk_helper
from source_line_info import sourcelineinfo
from collections import defaultdict
def proto_is_global(proto):
global_function_names = [
"CreateInstance",
"EnumerateInstanceLayerProperties",
"EnumerateInstanceExtensionProperties",
"EnumerateDeviceLayerProperties",
"EnumerateDeviceExtensionProperties",
"CreateXcbSurfaceKHR",
"GetPhysicalDeviceXcbPresentationSupportKHR",
"CreateXlibSurfaceKHR",
"GetPhysicalDeviceXlibPresentationSupportKHR",
"CreateWaylandSurfaceKHR",
"GetPhysicalDeviceWaylandPresentationSupportKHR",
"CreateMirSurfaceKHR",
"GetPhysicalDeviceMirPresentationSupportKHR",
"CreateAndroidSurfaceKHR",
"CreateWin32SurfaceKHR",
"GetPhysicalDeviceWin32PresentationSupportKHR"
]
if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name in global_function_names:
return True
else:
return False
def wsi_name(ext_name):
wsi_prefix = ""
if 'Xcb' in ext_name:
wsi_prefix = 'XCB'
elif 'Xlib' in ext_name:
wsi_prefix = 'XLIB'
elif 'Win32' in ext_name:
wsi_prefix = 'WIN32'
elif 'Mir' in ext_name:
wsi_prefix = 'MIR'
elif 'Wayland' in ext_name:
wsi_prefix = 'WAYLAND'
elif 'Android' in ext_name:
wsi_prefix = 'ANDROID'
else:
wsi_prefix = ''
return wsi_prefix
def wsi_ifdef(ext_name):
wsi_prefix = wsi_name(ext_name)
if not wsi_prefix:
return ''
else:
return "#ifdef VK_USE_PLATFORM_%s_KHR" % wsi_prefix
def wsi_endif(ext_name):
wsi_prefix = wsi_name(ext_name)
if not wsi_prefix:
return ''
else:
return "#endif // VK_USE_PLATFORM_%s_KHR" % wsi_prefix
def generate_get_proc_addr_check(name):
return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \
" return NULL;" % ((name,) * 3)
def ucc_to_U_C_C(CamelCase):
temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', CamelCase)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).upper()
# Parse complete struct chain and add any new ndo_uses to the dict
def gather_object_uses_in_struct(obj_list, struct_type):
struct_uses = {}
if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict:
struct_type = vk_helper.typedef_rev_dict[struct_type]
# Parse elements of this struct param to identify objects and/or arrays of objects
for m in sorted(vk_helper.struct_dict[struct_type]):
array_len = "%s" % (str(vk_helper.struct_dict[struct_type][m]['array_size']))
base_type = vk_helper.struct_dict[struct_type][m]['type']
mem_name = vk_helper.struct_dict[struct_type][m]['name']
if array_len != '0':
mem_name = "%s[%s]" % (mem_name, array_len)
if base_type in obj_list:
#if array_len not in ndo_uses:
# struct_uses[array_len] = []
#struct_uses[array_len].append("%s%s,%s" % (name_prefix, struct_name, base_type))
struct_uses[mem_name] = base_type
elif vk_helper.is_type(base_type, 'struct'):
sub_uses = gather_object_uses_in_struct(obj_list, base_type)
if len(sub_uses) > 0:
struct_uses[mem_name] = sub_uses
return struct_uses
# For the given list of object types, Parse the given list of params
# and return dict of params that use one of the obj_list types
# Format of the dict is that terminal elements have <name>,<type>
# non-terminal elements will have <name>[<array_size>]
# TODO : This analysis could be done up-front at vk_helper time
def get_object_uses(obj_list, params):
obj_uses = {}
local_decls = {}
param_count = 'NONE' # track params that give array sizes
for p in params:
base_type = p.ty.replace('const ', '').strip('*')
array_len = ''
is_ptr = False
if 'count' in p.name.lower():
param_count = p.name
ptr_txt = ''
if '*' in p.ty:
is_ptr = True
ptr_txt = '*'
if base_type in obj_list:
if is_ptr and 'const' in p.ty and param_count != 'NONE':
array_len = "[%s]" % param_count
# Non-arrays we can overwrite in place, but need local decl for arrays
local_decls[p.name] = '%s%s' % (base_type, ptr_txt)
#if array_len not in obj_uses:
# obj_uses[array_len] = {}
# obj_uses[array_len][p.name] = base_type
obj_uses["%s%s" % (p.name, array_len)] = base_type
elif vk_helper.is_type(base_type, 'struct'):
struct_name = p.name
if 'NONE' != param_count:
struct_name = "%s[%s]" % (struct_name, param_count)
struct_uses = gather_object_uses_in_struct(obj_list, base_type)
if len(struct_uses) > 0:
obj_uses[struct_name] = struct_uses
# This is a top-level struct w/ uses below it, so need local decl
local_decls['%s' % (p.name)] = '%s%s' % (base_type, ptr_txt)
return (obj_uses, local_decls)
class Subcommand(object):
def __init__(self, argv):
self.argv = argv
self.headers = vulkan.headers
self.protos = vulkan.protos
self.no_addr = False
self.layer_name = ""
self.lineinfo = sourcelineinfo()
self.wsi = sys.argv[1]
def run(self):
print(self.generate())
def generate(self):
copyright = self.generate_copyright()
header = self.generate_header()
body = self.generate_body()
footer = self.generate_footer()
contents = []
if copyright:
contents.append(copyright)
if header:
contents.append(header)
if body:
contents.append(body)
if footer:
contents.append(footer)
return "\n\n".join(contents)
def generate_copyright(self):
return """/* THIS FILE IS GENERATED. DO NOT EDIT. */
/*
* Copyright (c) 2015-2016 The Khronos Group Inc.
* Copyright (c) 2015-2016 Valve Corporation
* Copyright (c) 2015-2016 LunarG, Inc.
* Copyright (c) 2015 Google, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and/or associated documentation files (the "Materials"), to
* deal in the Materials without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Materials, and to permit persons to whom the Materials
* are furnished to do so, subject to the following conditions:
*
* The above copyright notice(s) and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
* USE OR OTHER DEALINGS IN THE MATERIALS
*
* Author: Tobin Ehlis <tobine@google.com>
* Author: Courtney Goeltzenleuchter <courtneygo@google.com>
* Author: Jon Ashburn <jon@lunarg.com>
* Author: Mark Lobodzinski <mark@lunarg.com>
* Author: Mike Stroyan <stroyan@google.com>
* Author: Tony Barbour <tony@LunarG.com>
*/"""
def generate_header(self):
return "\n".join(["#include <" + h + ">" for h in self.headers])
def generate_body(self):
pass
def generate_footer(self):
pass
# Return set of printf '%' qualifier and input to that qualifier
def _get_printf_params(self, vk_type, name, output_param, cpp=False):
# TODO : Need ENUM and STRUCT checks here
if vk_helper.is_type(vk_type, 'enum'):#"_TYPE" in vk_type: # TODO : This should be generic ENUM check
return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name))
if "char*" == vk_type:
return ("%s", name)
if "uint64" in vk_type:
if '*' in vk_type:
return ("%lu", "*%s" % name)
return ("%lu", name)
if vk_type.strip('*') in vulkan.object_non_dispatch_list:
if '*' in vk_type:
return ("%lu", "%s" % name)
return ("%lu", "%s" % name)
if "size" in vk_type:
if '*' in vk_type:
return ("%lu", "(unsigned long)*%s" % name)
return ("%lu", "(unsigned long)%s" % name)
if "float" in vk_type:
if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
if cpp:
return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name))
return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
return ("%f", name)
if "bool" in vk_type.lower() or 'xcb_randr_crtc_t' in vk_type:
return ("%u", name)
if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]:
if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
if cpp:
return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name))
return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
if '*' in vk_type:
if 'pUserData' == name:
return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
if 'const' in vk_type.lower():
return ("%p", "(void*)(%s)" % name)
return ("%i", "*(%s)" % name)
return ("%i", name)
# TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it
if "VkFormat" == vk_type:
if cpp:
return ("%p", "&%s" % name)
return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_COLOR_COMPONENT_FORMAT(%s.channelFormat), string_VK_FORMAT_RANGE_SIZE(%s.numericFormat)" % (name, name))
if output_param:
return ("%p", "(void*)*%s" % name)
if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type:
return ("%p", "(void*)(&%s)" % name)
return ("%p", "(void*)(%s)" % name)
def _gen_create_msg_callback(self):
r_body = []
r_body.append('%s' % self.lineinfo.get())
r_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(')
r_body.append(' VkInstance instance,')
r_body.append(' const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,')
r_body.append(' const VkAllocationCallbacks* pAllocator,')
r_body.append(' VkDebugReportCallbackEXT* pCallback)')
r_body.append('{')
# Switch to this code section for the new per-instance storage and debug callbacks
if self.layer_name in ['object_tracker', 'unique_objects']:
r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
r_body.append(' VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);')
r_body.append(' if (VK_SUCCESS == result) {')
r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);')
r_body.append(' result = layer_create_msg_callback(my_data->report_data,')
r_body.append(' pCreateInfo,')
r_body.append(' pAllocator,')
r_body.append(' pCallback);')
r_body.append(' }')
r_body.append(' return result;')
else:
r_body.append(' VkResult result = instance_dispatch_table(instance)->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);')
r_body.append(' if (VK_SUCCESS == result) {')
r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);')
r_body.append(' result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pCallback);')
r_body.append(' }')
r_body.append(' return result;')
r_body.append('}')
return "\n".join(r_body)
def _gen_destroy_msg_callback(self):
r_body = []
r_body.append('%s' % self.lineinfo.get())
r_body.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)')
r_body.append('{')
# Switch to this code section for the new per-instance storage and debug callbacks
if self.layer_name in ['object_tracker', 'unique_objects']:
r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
else:
r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);')
r_body.append(' pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);')
r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);')
r_body.append(' layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);')
r_body.append('}')
return "\n".join(r_body)
def _gen_debug_report_msg(self):
r_body = []
r_body.append('%s' % self.lineinfo.get())
r_body.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg)')
r_body.append('{')
# Switch to this code section for the new per-instance storage and debug callbacks
if self.layer_name == 'object_tracker':
r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
else:
r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);')
r_body.append(' pInstanceTable->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);')
r_body.append('}')
return "\n".join(r_body)
def _gen_layer_get_global_extension_props(self, layer="object_tracker"):
ggep_body = []
# generated layers do not provide any global extensions
ggep_body.append('%s' % self.lineinfo.get())
ggep_body.append('')
if self.layer_name == 'object_tracker':
ggep_body.append('static const VkExtensionProperties instance_extensions[] = {')
ggep_body.append(' {')
ggep_body.append(' VK_EXT_DEBUG_REPORT_EXTENSION_NAME,')
ggep_body.append(' VK_EXT_DEBUG_REPORT_SPEC_VERSION')
ggep_body.append(' }')
ggep_body.append('};')
ggep_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)')
ggep_body.append('{')
if self.layer_name == 'object_tracker':
ggep_body.append(' return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);')
else:
ggep_body.append(' return util_GetExtensionProperties(0, NULL, pCount, pProperties);')
ggep_body.append('}')
return "\n".join(ggep_body)
def _gen_layer_get_global_layer_props(self, layer="object_tracker"):
ggep_body = []
layer_name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', layer)
layer_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', layer_name).lower()
ggep_body.append('%s' % self.lineinfo.get())
ggep_body.append('static const VkLayerProperties globalLayerProps[] = {')
ggep_body.append(' {')
if self.layer_name in ['unique_objects']:
ggep_body.append(' "VK_LAYER_GOOGLE_%s",' % layer)
ggep_body.append(' VK_LAYER_API_VERSION, // specVersion')
ggep_body.append(' 1, // implementationVersion')
ggep_body.append(' "Google Validation Layer"')
else:
ggep_body.append(' "VK_LAYER_LUNARG_%s",' % layer)
ggep_body.append(' VK_LAYER_API_VERSION, // specVersion')
ggep_body.append(' 1, // implementationVersion')
ggep_body.append(' "LunarG Validation Layer"')
ggep_body.append(' }')
ggep_body.append('};')
ggep_body.append('')
ggep_body.append('%s' % self.lineinfo.get())
ggep_body.append('')
ggep_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)')
ggep_body.append('{')
ggep_body.append(' return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);')
ggep_body.append('}')
return "\n".join(ggep_body)
def _gen_layer_get_physical_device_layer_props(self, layer="object_tracker"):
gpdlp_body = []
gpdlp_body.append('%s' % self.lineinfo.get())
gpdlp_body.append('static const VkLayerProperties deviceLayerProps[] = {')
gpdlp_body.append(' {')
if self.layer_name in ['unique_objects']:
gpdlp_body.append(' "VK_LAYER_GOOGLE_%s",' % layer)
gpdlp_body.append(' VK_LAYER_API_VERSION, // specVersion')
gpdlp_body.append(' 1, // implementationVersion')
gpdlp_body.append(' "Google Validation Layer"')
else:
gpdlp_body.append(' "VK_LAYER_LUNARG_%s",' % layer)
gpdlp_body.append(' VK_LAYER_API_VERSION, // specVersion')
gpdlp_body.append(' 1, // implementationVersion')
gpdlp_body.append(' "LunarG Validation Layer"')
gpdlp_body.append(' }')
gpdlp_body.append('};')
gpdlp_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties* pProperties)')
gpdlp_body.append('{')
gpdlp_body.append(' return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties);')
gpdlp_body.append('}')
gpdlp_body.append('')
return "\n".join(gpdlp_body)
def _generate_dispatch_entrypoints(self, qual=""):
if qual:
qual += " "
funcs = []
intercepted = []
for proto in self.protos:
if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr":
continue
else:
intercept = self.generate_intercept(proto, qual)
if intercept is None:
# fill in default intercept for certain entrypoints
if 'CreateDebugReportCallbackEXT' == proto.name:
intercept = self._gen_layer_dbg_create_msg_callback()
elif 'DestroyDebugReportCallbackEXT' == proto.name:
intercept = self._gen_layer_dbg_destroy_msg_callback()
elif 'DebugReportMessageEXT' == proto.name:
intercept = self._gen_debug_report_msg()
elif 'CreateDevice' == proto.name:
funcs.append('/* CreateDevice HERE */')
elif 'EnumerateInstanceExtensionProperties' == proto.name:
intercept = self._gen_layer_get_global_extension_props(self.layer_name)
elif 'EnumerateInstanceLayerProperties' == proto.name:
intercept = self._gen_layer_get_global_layer_props(self.layer_name)
elif 'EnumerateDeviceLayerProperties' == proto.name:
intercept = self._gen_layer_get_physical_device_layer_props(self.layer_name)
if intercept is not None:
funcs.append(intercept)
if not "KHR" in proto.name:
intercepted.append(proto)
prefix="vk"
lookups = []
for proto in intercepted:
lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
lookups.append(" return (PFN_vkVoidFunction) %s%s;" %
(prefix, proto.name))
# add customized layer_intercept_proc
body = []
body.append('%s' % self.lineinfo.get())
body.append("static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)")
body.append("{")
body.append(generate_get_proc_addr_check("name"))
body.append("")
body.append(" name += 2;")
body.append(" %s" % "\n ".join(lookups))
body.append("")
body.append(" return NULL;")
body.append("}")
# add layer_intercept_instance_proc
lookups = []
for proto in self.protos:
if not proto_is_global(proto):
continue
if not proto in intercepted:
continue
if proto.name == "CreateInstance":
continue
if proto.name == "CreateDevice":
continue
lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
lookups.append(" return (PFN_vkVoidFunction) %s%s;" % (prefix, proto.name))
body.append("static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)")
body.append("{")
body.append(generate_get_proc_addr_check("name"))
body.append("")
body.append(" name += 2;")
body.append(" %s" % "\n ".join(lookups))
body.append("")
body.append(" return NULL;")
body.append("}")
funcs.append("\n".join(body))
return "\n\n".join(funcs)
def _generate_extensions(self):
exts = []
exts.append('%s' % self.lineinfo.get())
exts.append(self._gen_create_msg_callback())
exts.append(self._gen_destroy_msg_callback())
exts.append(self._gen_debug_report_msg())
return "\n".join(exts)
def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]):
func_body = []
#
# New style of GPA Functions for the new layer_data/layer_logging changes
#
if self.layer_name in ['object_tracker', 'unique_objects']:
func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n"
"{\n"
" PFN_vkVoidFunction addr;\n"
" if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n"
" return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n"
" }\n\n"
" addr = layer_intercept_proc(funcName);\n"
" if (addr)\n"
" return addr;\n"
" if (device == VK_NULL_HANDLE) {\n"
" return NULL;\n"
" }\n")
if 0 != len(extensions):
func_body.append('%s' % self.lineinfo.get())
func_body.append(' layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);')
for (ext_enable, ext_list) in extensions:
extra_space = ""
if 0 != len(ext_enable):
func_body.append(' if (my_device_data->%s) {' % ext_enable)
extra_space = " "
for ext_name in ext_list:
func_body.append(' %sif (!strcmp("%s", funcName))\n'
' %sreturn reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, extra_space, ext_name))
if 0 != len(ext_enable):
func_body.append(' }\n')
func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n"
" return NULL;\n"
" return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n"
"}\n" % (self.layer_name, self.layer_name))
func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n"
"{\n"
" PFN_vkVoidFunction addr;\n"
" if (!strcmp(funcName, \"vkGetInstanceProcAddr\"))\n"
" return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n"
" if (!strcmp(funcName, \"vkCreateInstance\"))\n"
" return (PFN_vkVoidFunction) vkCreateInstance;\n"
" if (!strcmp(funcName, \"vkCreateDevice\"))\n"
" return (PFN_vkVoidFunction) vkCreateDevice;\n"
" addr = layer_intercept_instance_proc(funcName);\n"
" if (addr) {\n"
" return addr;"
" }\n"
" if (instance == VK_NULL_HANDLE) {\n"
" return NULL;\n"
" }\n"
)
table_declared = False
if 0 != len(instance_extensions):
for (ext_enable, ext_list) in instance_extensions:
extra_space = ""
if 0 != len(ext_enable):
if ext_enable == 'msg_callback_get_proc_addr':
func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n"
" addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n"
" if (addr) {\n"
" return addr;\n"
" }\n")
else:
if table_declared == False:
func_body.append(" VkLayerInstanceDispatchTable* pTable = get_dispatch_table(%s_instance_table_map, instance);" % self.layer_name)
table_declared = True
func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable)
func_body.append(' {')
extra_space = " "
for ext_name in ext_list:
if wsi_name(ext_name):
func_body.append('%s' % wsi_ifdef(ext_name))
func_body.append(' %sif (!strcmp("%s", funcName))\n'
' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
if wsi_name(ext_name):
func_body.append('%s' % wsi_endif(ext_name))
if 0 != len(ext_enable):
func_body.append(' }\n')
func_body.append(" if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n"
" return NULL;\n"
" }\n"
" return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n"
"}\n" % (self.layer_name, self.layer_name))
return "\n".join(func_body)
else:
func_body.append('%s' % self.lineinfo.get())
func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n"
"{\n"
" PFN_vkVoidFunction addr;\n")
func_body.append("\n"
" loader_platform_thread_once(&initOnce, init%s);\n\n"
" if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n"
" return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n"
" }\n\n"
" addr = layer_intercept_proc(funcName);\n"
" if (addr)\n"
" return addr;" % self.layer_name)
func_body.append(" if (device == VK_NULL_HANDLE) {\n"
" return NULL;\n"
" }\n")
func_body.append('')
func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);')
if 0 != len(extensions):
extra_space = ""
for (ext_enable, ext_list) in extensions:
if 0 != len(ext_enable):
func_body.append(' if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].%s)' % ext_enable)
func_body.append(' {')
extra_space = " "
for ext_name in ext_list:
func_body.append(' %sif (!strcmp("%s", funcName))\n'
' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
if 0 != len(ext_enable):
func_body.append(' }')
func_body.append('%s' % self.lineinfo.get())
func_body.append(" {\n"
" if (pDisp->GetDeviceProcAddr == NULL)\n"
" return NULL;\n"
" return pDisp->GetDeviceProcAddr(device, funcName);\n"
" }\n"
"}\n")
func_body.append('%s' % self.lineinfo.get())
func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n"
"{\n"
" PFN_vkVoidFunction addr;\n"
" if (!strcmp(funcName, \"vkGetInstanceProcAddr\"))\n"
" return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n"
" if (!strcmp(funcName, \"vkCreateInstance\"))\n"
" return (PFN_vkVoidFunction) vkCreateInstance;\n"
" if (!strcmp(funcName, \"vkCreateDevice\"))\n"
" return (PFN_vkVoidFunction) vkCreateDevice;\n"
)
func_body.append(
" loader_platform_thread_once(&initOnce, init%s);\n\n"
" addr = layer_intercept_instance_proc(funcName);\n"
" if (addr)\n"
" return addr;" % self.layer_name)
func_body.append(" if (instance == VK_NULL_HANDLE) {\n"
" return NULL;\n"
" }\n")
func_body.append("")
func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n")
if 0 != len(instance_extensions):
extra_space = ""
for (ext_enable, ext_list) in instance_extensions:
if 0 != len(ext_enable):
if ext_enable == 'msg_callback_get_proc_addr':
func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n"
" addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n"
" if (addr) {\n"
" return addr;\n"
" }\n")
else:
func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable)
func_body.append(' {')
extra_space = " "
for ext_name in ext_list:
if wsi_name(ext_name):
func_body.append('%s' % wsi_ifdef(ext_name))
func_body.append(' %sif (!strcmp("%s", funcName))\n'
' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
if wsi_name(ext_name):
func_body.append('%s' % wsi_endif(ext_name))
if 0 != len(ext_enable):
func_body.append(' }\n')
func_body.append(" if (pTable->GetInstanceProcAddr == NULL)\n"
" return NULL;\n"
" return pTable->GetInstanceProcAddr(instance, funcName);\n"
"}\n")
return "\n".join(func_body)
def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None):
func_body = ["#include \"vk_dispatch_table_helper.h\""]
func_body.append('%s' % self.lineinfo.get())
func_body.append('static void init_%s(layer_data *my_data, const VkAllocationCallbacks *pAllocator)\n'
'{\n' % self.layer_name)
if init_opts:
func_body.append('%s' % self.lineinfo.get())
func_body.append('')
func_body.append(' layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_%s");' % self.layer_name)
func_body.append('')
if lockname is not None:
func_body.append('%s' % self.lineinfo.get())
func_body.append(" if (!%sLockInitialized)" % lockname)
func_body.append(" {")
func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname)
if condname is not None:
func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname)
func_body.append(" %sLockInitialized = 1;" % lockname)
func_body.append(" }")
func_body.append("}\n")
func_body.append('')
return "\n".join(func_body)
class ObjectTrackerSubcommand(Subcommand):
def generate_header(self):
header_txt = []
header_txt.append('%s' % self.lineinfo.get())
header_txt.append('#include "vk_loader_platform.h"')
header_txt.append('#include "vulkan/vulkan.h"')
header_txt.append('')
header_txt.append('#include <stdio.h>')
header_txt.append('#include <stdlib.h>')
header_txt.append('#include <string.h>')
header_txt.append('#include <inttypes.h>')
header_txt.append('')
header_txt.append('#include <unordered_map>')
header_txt.append('using namespace std;')
header_txt.append('#include "vulkan/vk_layer.h"')
header_txt.append('#include "vk_layer_config.h"')
header_txt.append('#include "vk_layer_table.h"')
header_txt.append('#include "vk_layer_data.h"')
header_txt.append('#include "vk_layer_logging.h"')
header_txt.append('')
# NOTE: The non-autoGenerated code is in the object_tracker.h header file
header_txt.append('#include "object_tracker.h"')
header_txt.append('')
return "\n".join(header_txt)
def generate_maps(self):
maps_txt = []
for o in vulkan.object_type_list:
maps_txt.append('unordered_map<uint64_t, OBJTRACK_NODE*> %sMap;' % (o))
return "\n".join(maps_txt)
def _gather_object_uses(self, obj_list, struct_type, obj_set):
# for each member of struct_type
# add objs in obj_list to obj_set
# call self for structs
for m in vk_helper.struct_dict[struct_type]:
if vk_helper.struct_dict[struct_type][m]['type'] in obj_list:
obj_set.add(vk_helper.struct_dict[struct_type][m]['type'])
elif vk_helper.is_type(vk_helper.struct_dict[struct_type][m]['type'], 'struct'):
obj_set = obj_set.union(self._gather_object_uses(obj_list, vk_helper.struct_dict[struct_type][m]['type'], obj_set))
return obj_set
def generate_procs(self):
procs_txt = []
# First parse through funcs and gather dict of all objects seen by each call
obj_use_dict = {}
proto_list = vulkan.core.protos + vulkan.ext_khr_surface.protos + vulkan.ext_khr_surface.protos + vulkan.ext_khr_win32_surface.protos + vulkan.ext_khr_device_swapchain.protos
for proto in proto_list:
disp_obj = proto.params[0].ty.strip('*').replace('const ', '')
if disp_obj in vulkan.object_dispatch_list:
if disp_obj not in obj_use_dict:
obj_use_dict[disp_obj] = set()
for p in proto.params[1:]:
base_type = p.ty.strip('*').replace('const ', '')
if base_type in vulkan.object_type_list:
obj_use_dict[disp_obj].add(base_type)
if vk_helper.is_type(base_type, 'struct'):
obj_use_dict[disp_obj] = self._gather_object_uses(vulkan.object_type_list, base_type, obj_use_dict[disp_obj])
#for do in obj_use_dict:
# print "Disp obj %s has uses for objs: %s" % (do, ', '.join(obj_use_dict[do]))
for o in vulkan.object_type_list:# vulkan.core.objects:
procs_txt.append('%s' % self.lineinfo.get())
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o)
name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
if o in vulkan.object_dispatch_list:
procs_txt.append('static void create_%s(%s dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o, o))
else:
procs_txt.append('static void create_%s(VkDevice dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o))
procs_txt.append('{')
procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType,(uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, "OBJTRACK",')
procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDebugReportObjectTypeEXT(objType),')
procs_txt.append(' (uint64_t)(vkObj));')
procs_txt.append('')
procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;')
procs_txt.append(' pNewObjNode->belongsTo = (uint64_t)dispatchable_object;')
procs_txt.append(' pNewObjNode->objType = objType;')
procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;')
procs_txt.append(' pNewObjNode->vkObj = (uint64_t)(vkObj);')
procs_txt.append(' %sMap[(uint64_t)vkObj] = pNewObjNode;' % (o))
procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);')
procs_txt.append(' numObjs[objIndex]++;')
procs_txt.append(' numTotalObjs++;')
procs_txt.append('}')
procs_txt.append('')
procs_txt.append('%s' % self.lineinfo.get())
if o in vulkan.object_dispatch_list:
procs_txt.append('static void destroy_%s(%s dispatchable_object, %s object)' % (name, o, o))
else:
procs_txt.append('static void destroy_%s(VkDevice dispatchable_object, %s object)' % (name, o))
procs_txt.append('{')
procs_txt.append(' uint64_t object_handle = (uint64_t)(object);')
procs_txt.append(' auto it = %sMap.find(object_handle);' % o)
procs_txt.append(' if (it != %sMap.end()) {' % o)
procs_txt.append(' OBJTRACK_NODE* pNode = it->second;')
procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);')
procs_txt.append(' assert(numTotalObjs > 0);')
procs_txt.append(' numTotalObjs--;')
procs_txt.append(' assert(numObjs[objIndex] > 0);')
procs_txt.append(' numObjs[objIndex]--;')
procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, object_handle, __LINE__, OBJTRACK_NONE, "OBJTRACK",')
procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",')
procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType), (uint64_t)(object), numTotalObjs, numObjs[objIndex],')
procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType));')
procs_txt.append(' delete pNode;')
procs_txt.append(' %sMap.erase(it);' % (o))
procs_txt.append(' } else {')
procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT ) 0, object_handle, __LINE__, OBJTRACK_NONE, "OBJTRACK",')
procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",')
procs_txt.append(' object_handle);')
procs_txt.append(' }')
procs_txt.append('}')
procs_txt.append('')
procs_txt.append('%s' % self.lineinfo.get())
if o in vulkan.object_dispatch_list:
procs_txt.append('static VkBool32 set_%s_status(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, ObjectStatusFlags status_flag)' % (name, o, o))
else:
procs_txt.append('static VkBool32 set_%s_status(VkDevice dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, ObjectStatusFlags status_flag)' % (name, o))
procs_txt.append('{')
procs_txt.append(' if (object != VK_NULL_HANDLE) {')
procs_txt.append(' uint64_t object_handle = (uint64_t)(object);')
procs_txt.append(' auto it = %sMap.find(object_handle);' % o)
procs_txt.append(' if (it != %sMap.end()) {' % o)
procs_txt.append(' it->second->status |= status_flag;')
procs_txt.append(' }')
procs_txt.append(' else {')
procs_txt.append(' // If we do not find it print an error')
procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT ) 0, object_handle, __LINE__, OBJTRACK_NONE, "OBJTRACK",')
procs_txt.append(' "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type",')
procs_txt.append(' object_handle, string_VkDebugReportObjectTypeEXT(objType));')
procs_txt.append(' }')
procs_txt.append(' }')
procs_txt.append(' return VK_FALSE;')
procs_txt.append('}')
procs_txt.append('')
procs_txt.append('%s' % self.lineinfo.get())
procs_txt.append('static VkBool32 validate_%s_status(' % (name))
if o in vulkan.object_dispatch_list:
procs_txt.append('%s dispatchable_object, %s object,' % (o, o))
else:
procs_txt.append('VkDevice dispatchable_object, %s object,' % (o))
procs_txt.append(' VkDebugReportObjectTypeEXT objType,')
procs_txt.append(' ObjectStatusFlags status_mask,')
procs_txt.append(' ObjectStatusFlags status_flag,')
procs_txt.append(' VkFlags msg_flags,')
procs_txt.append(' OBJECT_TRACK_ERROR error_code,')
procs_txt.append(' const char *fail_msg)')
procs_txt.append('{')
procs_txt.append(' uint64_t object_handle = (uint64_t)(object);')
procs_txt.append(' auto it = %sMap.find(object_handle);' % o)
procs_txt.append(' if (it != %sMap.end()) {' % o)
procs_txt.append(' OBJTRACK_NODE* pNode = it->second;')
procs_txt.append(' if ((pNode->status & status_mask) != status_flag) {')
procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, object_handle, __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",')
procs_txt.append(' "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkDebugReportObjectTypeEXT(objType),')
procs_txt.append(' object_handle, fail_msg);')
procs_txt.append(' return VK_FALSE;')
procs_txt.append(' }')
procs_txt.append(' return VK_TRUE;')
procs_txt.append(' }')
procs_txt.append(' else {')
procs_txt.append(' // If we do not find it print an error')
procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, (VkDebugReportObjectTypeEXT) 0, object_handle, __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",')
procs_txt.append(' "Unable to obtain status for non-existent object 0x%" PRIxLEAST64 " of %s type",')
procs_txt.append(' object_handle, string_VkDebugReportObjectTypeEXT(objType));')
procs_txt.append(' return VK_FALSE;')
procs_txt.append(' }')
procs_txt.append('}')
procs_txt.append('')
procs_txt.append('%s' % self.lineinfo.get())
if o in vulkan.object_dispatch_list:
procs_txt.append('static VkBool32 reset_%s_status(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, ObjectStatusFlags status_flag)' % (name, o, o))
else:
procs_txt.append('static VkBool32 reset_%s_status(VkDevice dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, ObjectStatusFlags status_flag)' % (name, o))
procs_txt.append('{')
procs_txt.append(' uint64_t object_handle = (uint64_t)(object);')
procs_txt.append(' auto it = %sMap.find(object_handle);' % o)
procs_txt.append(' if (it != %sMap.end()) {' % o)
procs_txt.append(' it->second->status &= ~status_flag;')
procs_txt.append(' }')
procs_txt.append(' else {')
procs_txt.append(' // If we do not find it print an error')
procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, object_handle, __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",')
procs_txt.append(' "Unable to reset status for non-existent object 0x%" PRIxLEAST64 " of %s type",')
procs_txt.append(' object_handle, string_VkDebugReportObjectTypeEXT(objType));')
procs_txt.append(' }')
procs_txt.append(' return VK_FALSE;')
procs_txt.append('}')
procs_txt.append('')
procs_txt.append('%s' % self.lineinfo.get())
# Generate the permutations of validate_* functions where for each
# dispatchable object type, we have a corresponding validate_* function
# for that object and all non-dispatchable objects that are used in API
# calls with that dispatchable object.
procs_txt.append('//%s' % str(obj_use_dict))
for do in obj_use_dict:
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', do)
name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
# First create validate_* func for disp obj
procs_txt.append('%s' % self.lineinfo.get())
procs_txt.append('static VkBool32 validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, do))
procs_txt.append('{')
procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))')
procs_txt.append(' return VK_FALSE;')
procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (do, do))
procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",')
procs_txt.append(' "Invalid %s Object 0x%%" PRIx64 ,(uint64_t)(object));' % do)
procs_txt.append(' }')
procs_txt.append(' return VK_FALSE;')
procs_txt.append('}')
procs_txt.append('')
for o in obj_use_dict[do]:
if o == do: # We already generated this case above so skip here
continue
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o)
name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
procs_txt.append('%s' % self.lineinfo.get())
procs_txt.append('static VkBool32 validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, o))
procs_txt.append('{')
procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))')
procs_txt.append(' return VK_FALSE;')
if o == "VkImage":
procs_txt.append(' // We need to validate normal image objects and those from the swapchain')
procs_txt.append(' if ((%sMap.find((uint64_t)object) == %sMap.end()) &&' % (o, o))
procs_txt.append(' (swapchainImageMap.find((uint64_t)object) == swapchainImageMap.end())) {')
else:
procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (o, o))
procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",')
procs_txt.append(' "Invalid %s Object 0x%%" PRIx64, (uint64_t)(object));' % o)
procs_txt.append(' }')
procs_txt.append(' return VK_FALSE;')
procs_txt.append('}')
procs_txt.append('')
procs_txt.append('')
return "\n".join(procs_txt)
def generate_destroy_instance(self):
gedi_txt = []
gedi_txt.append('%s' % self.lineinfo.get())
gedi_txt.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(')
gedi_txt.append('VkInstance instance,')
gedi_txt.append('const VkAllocationCallbacks* pAllocator)')
gedi_txt.append('{')
gedi_txt.append(' loader_platform_thread_lock_mutex(&objLock);')
gedi_txt.append(' validate_instance(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, false);')
gedi_txt.append('')
gedi_txt.append(' destroy_instance(instance, instance);')
gedi_txt.append(' // Report any remaining objects in LL')
gedi_txt.append('')
gedi_txt.append(' for (auto iit = VkDeviceMap.begin(); iit != VkDeviceMap.end();) {')
gedi_txt.append(' OBJTRACK_NODE* pNode = iit->second;')
gedi_txt.append(' if (pNode->belongsTo == (uint64_t)instance) {')
gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
gedi_txt.append(' pNode->vkObj);')
for o in vulkan.core.objects:
if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice']:
continue
gedi_txt.append(' for (auto idt = %sMap.begin(); idt != %sMap.end();) {' % (o, o))
gedi_txt.append(' OBJTRACK_NODE* pNode = idt->second;')
gedi_txt.append(' if (pNode->belongsTo == iit->first) {')
gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
gedi_txt.append(' pNode->vkObj);')
gedi_txt.append(' %sMap.erase(idt++);' % o )
gedi_txt.append(' } else {')
gedi_txt.append(' ++idt;')
gedi_txt.append(' }')
gedi_txt.append(' }')
gedi_txt.append(' VkDeviceMap.erase(iit++);')
gedi_txt.append(' } else {')
gedi_txt.append(' ++iit;')
gedi_txt.append(' }')
gedi_txt.append(' }')
gedi_txt.append('')
gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);')
gedi_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, instance);')
gedi_txt.append(' pInstanceTable->DestroyInstance(instance, pAllocator);')
gedi_txt.append('')