-
Notifications
You must be signed in to change notification settings - Fork 336
Expand file tree
/
Copy pathloader_extension_generator.py
More file actions
1344 lines (1126 loc) · 72.9 KB
/
Copy pathloader_extension_generator.py
File metadata and controls
1344 lines (1126 loc) · 72.9 KB
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/python3 -i
#
# Copyright (c) 2015-2022 The Khronos Group Inc.
# Copyright (c) 2015-2022 Valve Corporation
# Copyright (c) 2015-2022 LunarG, Inc.
# Copyright (c) 2015-2017 Google Inc.
# Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2023-2023 RasterGrid Kft.
#
# 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 Young <marky@lunarg.com>
# Author: Mark Lobodzinski <mark@lunarg.com>
# Author: Charles Giessen <charles@lunarg.com>
import re
import os
from base_generator import BaseGenerator
WSI_EXT_NAMES = ['VK_KHR_surface',
'VK_KHR_display',
'VK_KHR_xlib_surface',
'VK_KHR_xcb_surface',
'VK_KHR_wayland_surface',
'VK_EXT_directfb_surface',
'VK_KHR_win32_surface',
'VK_KHR_android_surface',
'VK_GGP_stream_descriptor_surface',
'VK_MVK_macos_surface',
'VK_MVK_ios_surface',
'VK_EXT_headless_surface',
'VK_EXT_metal_surface',
'VK_FUCHSIA_imagepipe_surface',
'VK_KHR_swapchain',
'VK_KHR_display_swapchain',
'VK_KHR_get_display_properties2',
'VK_KHR_get_surface_capabilities2',
'VK_QNX_screen_surface',
'VK_NN_vi_surface']
ADD_INST_CMDS = ['vkCreateInstance',
'vkEnumerateInstanceExtensionProperties',
'vkEnumerateInstanceLayerProperties',
'vkEnumerateInstanceVersion']
AVOID_EXT_NAMES = ['VK_EXT_debug_report']
NULL_CHECK_EXT_NAMES= ['VK_EXT_debug_utils']
AVOID_CMD_NAMES = ['vkCreateDebugUtilsMessengerEXT',
'vkDestroyDebugUtilsMessengerEXT',
'vkSubmitDebugUtilsMessageEXT']
DEVICE_CMDS_NEED_TERM = ['vkGetDeviceProcAddr',
'vkCreateSwapchainKHR',
'vkCreateSharedSwapchainsKHR',
'vkGetDeviceGroupSurfacePresentModesKHR',
'vkDebugMarkerSetObjectTagEXT',
'vkDebugMarkerSetObjectNameEXT',
'vkSetDebugUtilsObjectNameEXT',
'vkSetDebugUtilsObjectTagEXT',
'vkQueueBeginDebugUtilsLabelEXT',
'vkQueueEndDebugUtilsLabelEXT',
'vkQueueInsertDebugUtilsLabelEXT',
'vkCmdBeginDebugUtilsLabelEXT',
'vkCmdEndDebugUtilsLabelEXT',
'vkCmdInsertDebugUtilsLabelEXT',
'vkGetDeviceGroupSurfacePresentModes2EXT']
DEVICE_CMDS_MUST_USE_TRAMP = ['vkSetDebugUtilsObjectNameEXT',
'vkSetDebugUtilsObjectTagEXT',
'vkDebugMarkerSetObjectNameEXT',
'vkDebugMarkerSetObjectTagEXT']
# These are the aliased functions that use the same terminator for both extension and core versions
# Generally, this is only applies to physical device level functions in instance extensions
SHARED_ALIASES = {
# 1.1 aliases
'vkEnumeratePhysicalDeviceGroupsKHR': 'vkEnumeratePhysicalDeviceGroups',
'vkGetPhysicalDeviceFeatures2KHR': 'vkGetPhysicalDeviceFeatures2',
'vkGetPhysicalDeviceProperties2KHR': 'vkGetPhysicalDeviceProperties2',
'vkGetPhysicalDeviceFormatProperties2KHR': 'vkGetPhysicalDeviceFormatProperties2',
'vkGetPhysicalDeviceImageFormatProperties2KHR': 'vkGetPhysicalDeviceImageFormatProperties2',
'vkGetPhysicalDeviceQueueFamilyProperties2KHR': 'vkGetPhysicalDeviceQueueFamilyProperties2',
'vkGetPhysicalDeviceMemoryProperties2KHR': 'vkGetPhysicalDeviceMemoryProperties2',
'vkGetPhysicalDeviceSparseImageFormatProperties2KHR': 'vkGetPhysicalDeviceSparseImageFormatProperties2',
'vkGetPhysicalDeviceExternalBufferPropertiesKHR': 'vkGetPhysicalDeviceExternalBufferProperties',
'vkGetPhysicalDeviceExternalSemaphorePropertiesKHR': 'vkGetPhysicalDeviceExternalSemaphoreProperties',
'vkGetPhysicalDeviceExternalFencePropertiesKHR': 'vkGetPhysicalDeviceExternalFenceProperties',
}
PRE_INSTANCE_FUNCTIONS = ['vkEnumerateInstanceExtensionProperties',
'vkEnumerateInstanceLayerProperties',
'vkEnumerateInstanceVersion']
class LoaderExtensionGenerator(BaseGenerator):
def __init__(self):
BaseGenerator.__init__(self)
self.core_commands = []
self.extension_commands = []
self.instance_extensions = []
def generate(self):
self.core_commands = [x for x in self.vk.commands.values() if len(x.extensions) == 0]
self.extension_commands = [x for x in self.vk.commands.values() if len(x.extensions) > 0]
self.instance_extensions = [x for x in self.vk.extensions.values() if x.instance]
out = []
self.add_preamble(out)
if self.filename == 'vk_loader_extensions.h':
self.print_vk_loader_extensions_h(out)
elif self.filename == 'vk_loader_extensions.c':
self.print_vk_loader_extensions_c(out)
elif self.filename == 'vk_layer_dispatch_table.h':
self.print_vk_layer_dispatch_table(out)
out.append('// clang-format on')
self.write(''.join(out))
def add_preamble(self, out):
out.append(f'''// *** THIS FILE IS GENERATED - DO NOT EDIT ***
// See {os.path.basename(__file__)} for modifications
/*
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2023-2023 RasterGrid Kft.
*
* 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 <mark@lunarg.com>
* Author: Mark Young <marky@lunarg.com>
* Author: Charles Giessen <charles@lunarg.com>
*/
// clang-format off
''')
def print_vk_loader_extensions_h(self, out):
out.append('#pragma once\n')
out.append('\n')
out.append('#include <stdbool.h>\n')
out.append('#include <vulkan/vulkan.h>\n')
out.append('#include <vulkan/vk_layer.h>\n')
out.append('#include "vk_layer_dispatch_table.h"\n')
out.append('\n\n')
self.OutputPrototypesInHeader(out)
self.OutputLoaderTerminators(out)
self.OutputIcdDispatchTable(out)
self.OutputIcdExtensionEnableUnion(out)
self.OutputDeviceFunctionTerminatorDispatchTable(out)
def print_vk_loader_extensions_c(self, out):
out.append('#include <stdio.h>\n')
out.append('#include <stdlib.h>\n')
out.append('#include <string.h>\n')
out.append('#include "loader.h"\n')
out.append('#include "vk_loader_extensions.h"\n')
out.append('#include <vulkan/vk_icd.h>\n')
out.append('#include "wsi.h"\n')
out.append('#include "debug_utils.h"\n')
out.append('#include "extension_manual.h"\n')
self.OutputUtilitiesInSource(out)
self.OutputIcdDispatchTableInit(out)
self.OutputLoaderDispatchTables(out)
self.InitDeviceFunctionTerminatorDispatchTable(out)
self.OutputDeviceFunctionTrampolinePrototypes(out)
self.OutputLoaderLookupFunc(out)
self.CreateTrampTermFuncs(out)
self.InstExtensionGPA(out)
self.InstantExtensionCreate(out)
self.DeviceExtensionGetTerminator(out)
self.InitInstLoaderExtensionDispatchTable(out)
self.OutputInstantExtensionWhitelistArray(out)
def print_vk_layer_dispatch_table(self, out):
out.append('#pragma once\n')
out.append('\n')
out.append('#include <vulkan/vulkan.h>\n')
out.append('\n')
out.append('#if !defined(PFN_GetPhysicalDeviceProcAddr)\n')
out.append('typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);\n')
out.append('#endif\n\n')
self.OutputLayerInstanceDispatchTable(out)
self.OutputLayerDeviceDispatchTable(out)
# Convert an XML dependency expression to a C expression, taking a callback to replace extension names
# See https://registry.khronos.org/vulkan/specs/1.4/registry.html#depends-expressions
@staticmethod
def ConvertDependencyExpression(expr, replace_func):
# '(' and ')' can pass through unchanged
expr = re.sub(',', ' || ', expr)
expr = re.sub(r'\+', ' && ', expr)
expr = re.sub(r'\w+', lambda match: replace_func(match.group()), expr)
return expr
def DescribeBlock(self, command, current_block, out, custom_commands_string = ' commands', indent = ' '):
if command.extensions != current_block and command.version != current_block:
if command.version is None and len(command.extensions) == 0: # special case for 1.0
out.append(f'\n{indent}// ---- Core Vulkan 1.0{custom_commands_string}\n')
return None
elif command.version is not None:
if command.version != current_block:
out.append(f"\n{indent}// ---- Core Vulkan 1.{command.version.name.split('_')[-1]}{custom_commands_string}\n")
return command.version
else:
# don't repeat unless the first extension is different (while rest can vary)
if not isinstance(current_block, list) or current_block[0] != command.extensions[0]:
out.append(f"\n{indent}// ---- {command.extensions[0] if len(command.extensions) > 0 else ''} extension{custom_commands_string}\n")
return command.extensions
else:
return current_block
def OutputPrototypesInHeader(self, out: list):
out.append('''// Structures defined externally, but used here
struct loader_instance;
struct loader_device;
struct loader_icd_term;
struct loader_dev_dispatch_table;
// Device extension error function
VKAPI_ATTR VkResult VKAPI_CALL vkDevExtError(VkDevice dev);
// Extension interception for vkGetInstanceProcAddr function, so we can return
// the appropriate information for any instance extensions we know about.
bool extension_instance_gpa(struct loader_instance *ptr_instance, const char *name, void **addr);
struct loader_instance_extension_enable_list; // Forward declaration
// Extension interception for vkCreateInstance function, so we can properly
// detect and enable any instance extension information for extensions we know
// about.
void fill_out_enabled_instance_extensions(uint32_t extension_count, const char *const * extension_list, struct loader_instance_extension_enable_list* enables);
// Extension interception for vkGetDeviceProcAddr function, so we can return
// an appropriate terminator if this is one of those few device commands requiring
// a terminator.
PFN_vkVoidFunction get_extension_device_proc_terminator(struct loader_device *dev, const char *name, bool* found_name);
// Dispatch table properly filled in with appropriate terminators for the
// supported extensions.
extern const VkLayerInstanceDispatchTable instance_disp;
// Array of extension strings for instance extensions we support.
extern const char *const LOADER_INSTANCE_EXTENSIONS[];
VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_instance* inst, struct loader_icd_term *icd_term);
// Init Device function pointer dispatch table with core commands
VKAPI_ATTR void VKAPI_CALL loader_init_device_dispatch_table(struct loader_dev_dispatch_table *dev_table, PFN_vkGetDeviceProcAddr gpa,
VkDevice dev);
// Init Device function pointer dispatch table with extension commands
VKAPI_ATTR void VKAPI_CALL loader_init_device_extension_dispatch_table(struct loader_dev_dispatch_table *dev_table,
PFN_vkGetInstanceProcAddr gipa,
PFN_vkGetDeviceProcAddr gdpa,
VkInstance inst,
VkDevice dev);
// Init Instance function pointer dispatch table with core commands
VKAPI_ATTR void VKAPI_CALL loader_init_instance_core_dispatch_table(VkLayerInstanceDispatchTable *table, PFN_vkGetInstanceProcAddr gpa,
VkInstance inst);
// Init Instance function pointer dispatch table with core commands
VKAPI_ATTR void VKAPI_CALL loader_init_instance_extension_dispatch_table(VkLayerInstanceDispatchTable *table, PFN_vkGetInstanceProcAddr gpa,
VkInstance inst);
// Device command lookup function
VKAPI_ATTR void* VKAPI_CALL loader_lookup_device_dispatch_table(const VkLayerDispatchTable *table, const char *name, bool* name_found);
// Instance command lookup function
VKAPI_ATTR void* VKAPI_CALL loader_lookup_instance_dispatch_table(const VkLayerInstanceDispatchTable *table, const char *name,
bool *found_name);
''')
# Creates the prototypes for the loader's core instance command terminators
def OutputLoaderTerminators(self, out):
out.append('// Loader core instance terminators\n')
for command in [x for x in self.vk.commands.values() if len(x.extensions) == 0]:
if not (command.name in ADD_INST_CMDS) and not (command.params[0].type in ['VkInstance', 'VkPhysicalDevice']):
continue
mod_string = ''
new_terminator = command.cPrototype
mod_string = new_terminator.replace("VKAPI_CALL vk", "VKAPI_CALL terminator_")
if command.name in PRE_INSTANCE_FUNCTIONS:
pre_instance_basic_version = mod_string
mod_string = mod_string.replace("terminator_", "terminator_pre_instance_")
mod_string = mod_string.replace(command.name[2:] + '(\n', command.name[2:] + '(\n const Vk' + command.name[2:] + 'Chain* chain,\n')
if command.protect is not None:
out.append(f'#if defined({command.protect})\n')
if command.name in PRE_INSTANCE_FUNCTIONS:
out.append(pre_instance_basic_version)
out.append('\n')
out.append(mod_string)
out.append('\n')
if command.protect is not None:
out.append(f'#endif // {command.protect}\n')
out.append('\n')
# Create a dispatch table from the appropriate list
def OutputIcdDispatchTable(self, out):
skip_commands = ['vkGetInstanceProcAddr',
'vkEnumerateDeviceLayerProperties',
]
out.append('// ICD function pointer dispatch table\n')
out.append('struct loader_icd_term_dispatch {\n')
current_block = ''
for command in self.vk.commands.values():
if (command.name in skip_commands or command.device )and command.name != 'vkGetDeviceProcAddr':
continue
current_block = self.DescribeBlock(command, current_block, out)
if command.protect:
out.append(f'#if defined({command.protect})\n')
out.append(f' PFN_{command.name} {command.name[2:]};\n')
if command.protect:
out.append(f'#endif // {command.protect}\n')
out.append('};\n\n')
# Create the extension enable union
def OutputIcdExtensionEnableUnion(self, out):
out.append( 'struct loader_instance_extension_enable_list {\n')
for extension in self.instance_extensions:
if extension.protect:
out.append(f'#if defined({extension.protect})\n')
out.append( f' uint8_t {extension.name[3:].lower()};\n')
if extension.protect:
out.append(f'#endif // defined({extension.protect})\n')
out.append( '};\n\n')
# Create a dispatch table solely for device functions which have custom terminators
def OutputDeviceFunctionTerminatorDispatchTable(self, out):
out.append('// Functions that required a terminator need to have a separate dispatch table which contains their corresponding\n')
out.append('// device function. This is used in the terminators themselves.\n')
out.append('struct loader_device_terminator_dispatch {\n')
# last_protect = None
current_block = ''
for command in self.vk.commands.values():
if len(command.extensions) == 0:
continue
if command.name in DEVICE_CMDS_NEED_TERM:
if command.protect is not None:
out.append( f'#if defined({command.protect})\n')
current_block = self.DescribeBlock(command, current_block, out)
out.append( f' PFN_{command.name} {command.name[2:]};\n')
if command.protect is not None:
out.append( f'#endif // {command.protect}\n')
out.append( '};\n\n')
# Create a layer instance dispatch table from the appropriate list
def OutputLayerInstanceDispatchTable(self, out):
out.append('// Instance function pointer dispatch table\n')
out.append('typedef struct VkLayerInstanceDispatchTable_ {\n')
# First add in an entry for GetPhysicalDeviceProcAddr. This will not
# ever show up in the XML or header, so we have to manually add it.
out.append(' // Manually add in GetPhysicalDeviceProcAddr entry\n')
out.append(' PFN_GetPhysicalDeviceProcAddr GetPhysicalDeviceProcAddr;\n')
current_block = ''
for command_name, command in self.vk.commands.items():
if not command.instance:
continue
current_block = self.DescribeBlock(command, current_block, out)
if command.protect:
out.append(f'#if defined({command.protect})\n')
out.append(f' PFN_{command_name} {command_name[2:]};\n')
if command.protect:
out.append(f'#endif // {command.protect}\n')
out.append('} VkLayerInstanceDispatchTable;\n\n')
# Create a layer device dispatch table from the appropriate list
def OutputLayerDeviceDispatchTable(self, out):
out.append('// Device function pointer dispatch table\n')
out.append('#define DEVICE_DISP_TABLE_MAGIC_NUMBER 0x10ADED040410ADEDUL\n')
out.append('typedef struct VkLayerDispatchTable_ {\n')
out.append(' uint64_t magic; // Should be DEVICE_DISP_TABLE_MAGIC_NUMBER\n')
current_block = ''
for command in [x for x in self.vk.commands.values() if x.device]:
current_block = self.DescribeBlock(command, current_block, out)
if command.protect:
out.append(f'#if defined({command.protect})\n')
out.append(f' PFN_{command.name} {command.name[2:]};\n')
if command.protect:
out.append(f'#endif // {command.protect}\n')
out.append('} VkLayerDispatchTable;\n\n')
def OutputUtilitiesInSource(self, out):
out.append('''
// Device extension error function
VKAPI_ATTR VkResult VKAPI_CALL vkDevExtError(VkDevice dev) {
struct loader_device *found_dev;
// The device going in is a trampoline device
struct loader_icd_term *icd_term = loader_get_icd_and_device(dev, &found_dev);
if (icd_term)
loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
"Bad destination in loader trampoline dispatch,"
"Are layers and extensions that you are calling enabled?");
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
''')
# Init a dispatch table from the appropriate list
def OutputIcdDispatchTableInit(self, out):
out.append('VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_instance* inst, struct loader_icd_term *icd_term) {\n')
out.append(' const PFN_vkGetInstanceProcAddr fp_gipa = icd_term->scanned_icd->GetInstanceProcAddr;\n')
out.append('\n')
out.append('#define LOOKUP_GIPA(func) icd_term->dispatch.func = (PFN_vk##func)fp_gipa(icd_term->instance, "vk" #func);\n')
out.append('\n')
out.append('#define LOOKUP_REQUIRED_GIPA(func) \\\n')
out.append(' do { \\\n')
out.append(' LOOKUP_GIPA(func); \\\n')
out.append(' if (!icd_term->dispatch.func) { \\\n')
out.append(' loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, "Unable to load %s from ICD %s",\\\n')
out.append(' "vk"#func, icd_term->scanned_icd->lib_name); \\\n')
out.append(' return false; \\\n')
out.append(' } \\\n')
out.append(' } while (0)\n')
out.append('\n')
skip_gipa_commands = ['vkGetInstanceProcAddr',
'vkEnumerateDeviceLayerProperties',
'vkCreateInstance',
'vkEnumerateInstanceExtensionProperties',
'vkEnumerateInstanceLayerProperties',
'vkEnumerateInstanceVersion',
]
current_block = ''
for command in [x for x in self.vk.commands.values() if x.instance or x.name == 'vkGetDeviceProcAddr']:
if command.name in skip_gipa_commands:
continue
custom_commands_string= ' commands' if len(command.extensions) > 0 else ''
current_block = self.DescribeBlock(command, current_block, out, custom_commands_string=custom_commands_string)
if command.protect is not None:
out.append( f'#if defined({command.protect})\n')
if command.version is None and len(command.extensions) == 0:
# The Core Vulkan code will be wrapped in a feature called VK_VERSION_#_#
# For example: VK_VERSION_1_0 wraps the core 1.0 Vulkan functionality
out.append(f' LOOKUP_REQUIRED_GIPA({command.name[2:]});\n')
else:
out.append( f' LOOKUP_GIPA({command.name[2:]});\n')
if command.protect is not None:
out.append(f'#endif // {command.protect}\n')
out.append('\n')
out.append('#undef LOOKUP_REQUIRED_GIPA\n')
out.append('#undef LOOKUP_GIPA\n')
out.append('\n')
out.append(' return true;\n')
out.append('};\n\n')
# Creates code to initialize the various dispatch tables
def OutputLoaderDispatchTables(self, out):
commands = []
gpa_param = ''
cur_type = ''
for x in range(0, 4):
if x == 0:
cur_type = 'device'
gpa_param = 'dev'
commands = self.core_commands
out.append('// Init Device function pointer dispatch table with core commands\n')
out.append('VKAPI_ATTR void VKAPI_CALL loader_init_device_dispatch_table(struct loader_dev_dispatch_table *dev_table, PFN_vkGetDeviceProcAddr gpa,\n')
out.append(' VkDevice dev) {\n')
out.append(' VkLayerDispatchTable *table = &dev_table->core_dispatch;\n')
out.append(' if (table->magic != DEVICE_DISP_TABLE_MAGIC_NUMBER) { abort(); }\n')
out.append(' for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) dev_table->ext_dispatch[i] = (PFN_vkDevExt)vkDevExtError;\n')
elif x == 1:
cur_type = 'device'
gpa_param = 'dev'
commands = self.extension_commands
out.append('// Init Device function pointer dispatch table with extension commands\n')
out.append('VKAPI_ATTR void VKAPI_CALL loader_init_device_extension_dispatch_table(struct loader_dev_dispatch_table *dev_table,\n')
out.append(' PFN_vkGetInstanceProcAddr gipa,\n')
out.append(' PFN_vkGetDeviceProcAddr gdpa,\n')
out.append(' VkInstance inst,\n')
out.append(' VkDevice dev) {\n')
out.append(' VkLayerDispatchTable *table = &dev_table->core_dispatch;\n')
out.append(' table->magic = DEVICE_DISP_TABLE_MAGIC_NUMBER;\n')
elif x == 2:
cur_type = 'instance'
gpa_param = 'inst'
commands = self.core_commands
out.append('// Init Instance function pointer dispatch table with core commands\n')
out.append('VKAPI_ATTR void VKAPI_CALL loader_init_instance_core_dispatch_table(VkLayerInstanceDispatchTable *table, PFN_vkGetInstanceProcAddr gpa,\n')
out.append(' VkInstance inst) {\n')
else:
cur_type = 'instance'
gpa_param = 'inst'
commands = self.extension_commands
out.append('// Init Instance function pointer dispatch table with core commands\n')
out.append('VKAPI_ATTR void VKAPI_CALL loader_init_instance_extension_dispatch_table(VkLayerInstanceDispatchTable *table, PFN_vkGetInstanceProcAddr gpa,\n')
out.append(' VkInstance inst) {\n')
current_block = ''
for command in commands:
is_inst_handle_type = command.params[0].type in ['VkInstance', 'VkPhysicalDevice']
if ((cur_type == 'instance' and is_inst_handle_type) or (cur_type == 'device' and not is_inst_handle_type)):
current_block = self.DescribeBlock(command, current_block, out)
# Remove 'vk' from proto name
base_name = command.name[2:]
# Names to skip
if (base_name == 'CreateInstance' or base_name == 'CreateDevice' or
base_name == 'EnumerateInstanceExtensionProperties' or
base_name == 'EnumerateInstanceLayerProperties' or
base_name == 'EnumerateInstanceVersion'):
continue
if command.protect is not None:
out.append(f'#if defined({command.protect})\n')
# If we're looking for the proc we are passing in, just point the table to it. This fixes the issue where
# a layer overrides the function name for the loader.
if x == 1:
if base_name == 'GetDeviceProcAddr':
out.append(' table->GetDeviceProcAddr = gdpa;\n')
elif len(command.extensions) > 0 and self.vk.extensions[command.extensions[0]].instance:
out.append(f' table->{base_name} = (PFN_{command.name})gipa(inst, "{command.name}");\n')
else:
out.append(f' table->{base_name} = (PFN_{command.name})gdpa(dev, "{command.name}");\n')
elif (x < 1 and base_name == 'GetDeviceProcAddr'):
out.append(' table->GetDeviceProcAddr = gpa;\n')
elif (x > 1 and base_name == 'GetInstanceProcAddr'):
out.append(' table->GetInstanceProcAddr = gpa;\n')
else:
out.append(f' table->{base_name} = (PFN_{command.name})gpa({gpa_param}, "{command.name}");\n')
if command.protect is not None:
out.append(f'#endif // {command.protect}\n')
out.append('}\n\n')
#
# Create code to initialize a dispatch table from the appropriate list of extension entrypoints
def InitDeviceFunctionTerminatorDispatchTable(self, out):
out.append('// Functions that required a terminator need to have a separate dispatch table which contains their corresponding\n')
out.append('// device function. This is used in the terminators themselves.\n')
out.append('void init_extension_device_proc_terminator_dispatch(struct loader_device *dev) {\n')
out.append(' struct loader_device_terminator_dispatch* dispatch = &dev->loader_dispatch.extension_terminator_dispatch;\n')
out.append(' PFN_vkGetDeviceProcAddr gpda = (PFN_vkGetDeviceProcAddr)dev->phys_dev_term->this_icd_term->dispatch.GetDeviceProcAddr;\n')
current_block = ''
for command in [x for x in self.vk.commands.values() if x.extensions or x.version]:
if command.name in DEVICE_CMDS_NEED_TERM:
if command.protect is not None:
out.append(f'#if defined({command.protect})\n')
current_block = self.DescribeBlock(command, current_block, out)
if command.name == 'vkGetDeviceGroupSurfacePresentModes2EXT': # command.extensions[0].depends in [x for x in self.vk.commands.values() if x.device]:
# Hardcode the dependency expression as vulkan_object.py doesn't expose this information
dep_expr = self.ConvertDependencyExpression('VK_KHR_device_group,VK_VERSION_1_1', lambda ext_name: f'dev->driver_extensions.{ext_name[3:].lower()}_enabled')
out.append(f' if (dev->driver_extensions.{command.extensions[0][3:].lower()}_enabled && ({dep_expr}))\n')
out.append(f' dispatch->{command.name[2:]} = (PFN_{(command.name)})gpda(dev->icd_device, "{(command.name)}");\n')
else:
out.append(f' if (dev->driver_extensions.{command.extensions[0][3:].lower()}_enabled)\n')
out.append(f' dispatch->{command.name[2:]} = (PFN_{(command.name)})gpda(dev->icd_device, "{(command.name)}");\n')
if command.protect is not None:
out.append(f'#endif // {command.protect}\n')
out.append('}\n\n')
def OutputDeviceFunctionTrampolinePrototypes(self, out):
out.append('// These are prototypes for functions that need their trampoline called in all circumstances.\n')
out.append('// They are used in loader_lookup_device_dispatch_table but are defined afterwards.\n')
current_block = ''
for command in self.vk.commands.values():
if command.name in DEVICE_CMDS_MUST_USE_TRAMP:
if command.protect is not None:
out.append(f'#if defined({command.protect})\n')
current_block = self.DescribeBlock(command, current_block, out)
out.append(f'{command.cPrototype.replace("VKAPI_CALL vk", "VKAPI_CALL ")}\n')
if command.protect is not None:
out.append(f'#endif // {command.protect}\n')
out.append('\n')
#
# Create a lookup table function from the appropriate list of entrypoints
def OutputLoaderLookupFunc(self, out):
commands = []
cur_type = ''
for x in range(0, 2):
if x == 0:
cur_type = 'device'
out.append('// Device command lookup function\n')
out.append('VKAPI_ATTR void* VKAPI_CALL loader_lookup_device_dispatch_table(const VkLayerDispatchTable *table, const char *name, bool* found_name) {\n')
out.append(' if (!name || name[0] != \'v\' || name[1] != \'k\') {\n')
out.append(' *found_name = false;\n')
out.append(' return NULL;\n')
out.append(' }\n')
out.append('\n')
out.append(' name += 2;\n')
out.append(' *found_name = true;\n')
out.append(' struct loader_device* dev = (struct loader_device *)table;\n')
out.append(' const struct loader_instance* inst = dev->phys_dev_term->this_icd_term->this_instance;\n')
out.append(' uint32_t api_version = VK_MAKE_API_VERSION(0, inst->app_api_version.major, inst->app_api_version.minor, inst->app_api_version.patch);\n')
out.append('\n')
else:
cur_type = 'instance'
out.append('// Instance command lookup function\n')
out.append('VKAPI_ATTR void* VKAPI_CALL loader_lookup_instance_dispatch_table(const VkLayerInstanceDispatchTable *table, const char *name,\n')
out.append(' bool *found_name) {\n')
out.append(' if (!name || name[0] != \'v\' || name[1] != \'k\') {\n')
out.append(' *found_name = false;\n')
out.append(' return NULL;\n')
out.append(' }\n')
out.append('\n')
out.append(' *found_name = true;\n')
out.append(' name += 2;\n')
for command_list in [self.core_commands, self.extension_commands]:
commands = command_list
version_check = ''
current_block = ''
for command in commands:
is_inst_handle_type = command.params[0].type in ['VkInstance', 'VkPhysicalDevice']
if ((cur_type == 'instance' and is_inst_handle_type) or (cur_type == 'device' and not is_inst_handle_type)):
current_block = self.DescribeBlock(command, current_block, out)
if len(command.extensions) == 0:
if cur_type == 'device':
version_check = f" if (dev->should_ignore_device_commands_from_newer_version && api_version < {command.version.nameApi if command.version else 'VK_API_VERSION_1_0'}) return NULL;\n"
else:
version_check = ''
# Remove 'vk' from proto name
base_name = command.name[2:]
if (base_name == 'CreateInstance' or base_name == 'CreateDevice' or
base_name == 'EnumerateInstanceExtensionProperties' or
base_name == 'EnumerateInstanceLayerProperties' or
base_name == 'EnumerateInstanceVersion'):
continue
if command.protect is not None:
out.append(f'#if defined({command.protect})\n')
out.append(f' if (!strcmp(name, "{base_name}")) ')
if command.name in DEVICE_CMDS_MUST_USE_TRAMP:
if version_check != '':
out.append(f'{{\n{version_check} return dev->layer_extensions.{command.extensions[0][3:].lower()}_enabled ? (void *){base_name} : NULL;\n }}\n')
else:
out.append(f'return dev->layer_extensions.{command.extensions[0][3:].lower()}_enabled ? (void *){base_name} : NULL;\n')
else:
if version_check != '':
out.append(f'{{\n{version_check} return (void *)table->{base_name};\n }}\n')
else:
out.append(f'return (void *)table->{base_name};\n')
if command.protect is not None:
out.append(f'#endif // {command.protect}\n')
out.append('\n')
out.append(' *found_name = false;\n')
out.append(' return NULL;\n')
out.append('}\n\n')
#
# Create the appropriate trampoline (and possibly terminator) functions
def CreateTrampTermFuncs(self, out):
# Some extensions have to be manually added. Skip those in the automatic
# generation. They will be manually added later.
manual_ext_commands = ['vkEnumeratePhysicalDeviceGroupsKHR',
'vkGetPhysicalDeviceExternalImageFormatPropertiesNV',
'vkGetPhysicalDeviceFeatures2KHR',
'vkGetPhysicalDeviceProperties2KHR',
'vkGetPhysicalDeviceFormatProperties2KHR',
'vkGetPhysicalDeviceImageFormatProperties2KHR',
'vkGetPhysicalDeviceQueueFamilyProperties2KHR',
'vkGetPhysicalDeviceMemoryProperties2KHR',
'vkGetPhysicalDeviceSparseImageFormatProperties2KHR',
'vkGetPhysicalDeviceSurfaceCapabilities2KHR',
'vkGetPhysicalDeviceSurfaceFormats2KHR',
'vkGetPhysicalDeviceSurfaceCapabilities2EXT',
'vkReleaseDisplayEXT',
'vkAcquireXlibDisplayEXT',
'vkGetRandROutputDisplayEXT',
'vkGetPhysicalDeviceExternalBufferPropertiesKHR',
'vkGetPhysicalDeviceExternalSemaphorePropertiesKHR',
'vkGetPhysicalDeviceExternalFencePropertiesKHR',
'vkGetPhysicalDeviceDisplayProperties2KHR',
'vkGetPhysicalDeviceDisplayPlaneProperties2KHR',
'vkGetDisplayModeProperties2KHR',
'vkGetDisplayPlaneCapabilities2KHR',
'vkGetPhysicalDeviceSurfacePresentModes2EXT',
'vkGetDeviceGroupSurfacePresentModes2EXT',
'vkGetPhysicalDeviceToolPropertiesEXT']
current_block = ''
for command in [x for x in self.vk.commands.values() if x.extensions]:
if (command.extensions[0] in WSI_EXT_NAMES or
command.extensions[0] in AVOID_EXT_NAMES or
command.name in AVOID_CMD_NAMES or
command.name in manual_ext_commands):
continue
current_block = self.DescribeBlock(command=command, current_block=current_block, out=out, custom_commands_string=' trampoline/terminators\n', indent='')
if command.protect is not None:
out.append(f'#if defined({command.protect})\n')
func_header = command.cPrototype.replace(";", " {\n")
tramp_header = func_header.replace("VKAPI_CALL vk", "VKAPI_CALL ")
return_prefix = ' '
base_name = command.name[2:]
has_surface = 0
update_structure_surface = 0
update_structure_string = ''
requires_terminator = 0
surface_var_name = ''
phys_dev_var_name = ''
instance_var_name = ''
has_return_type = False
always_use_param_name = True
surface_type_to_replace = ''
surface_name_replacement = ''
physdev_type_to_replace = ''
physdev_name_replacement = ''
for param in command.params:
if param.type == 'VkSurfaceKHR':
has_surface = 1
surface_var_name = param.name
requires_terminator = 1
always_use_param_name = False
surface_type_to_replace = 'VkSurfaceKHR'
surface_name_replacement = 'unwrapped_surface'
if param.type == 'VkPhysicalDeviceSurfaceInfo2KHR':
has_surface = 1
surface_var_name = param.name + '->surface'
requires_terminator = 1
update_structure_surface = 1
update_structure_string = ' VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;\n'
update_structure_string += ' info_copy.surface = unwrapped_surface;\n'
always_use_param_name = False
surface_type_to_replace = 'VkPhysicalDeviceSurfaceInfo2KHR'
surface_name_replacement = '&info_copy'
if param.type == 'VkPhysicalDevice':
requires_terminator = 1
phys_dev_var_name = param.name
always_use_param_name = False
physdev_type_to_replace = 'VkPhysicalDevice'
physdev_name_replacement = 'phys_dev_term->phys_dev'
if param.type == 'VkInstance':
requires_terminator = 1
instance_var_name = param.name
if command.returnType != 'void':
return_prefix += 'return '
has_return_type = True
if ( command.params[0].type in ['VkInstance', 'VkPhysicalDevice'] or
'DebugMarkerSetObject' in command.name or 'SetDebugUtilsObject' in command.name or
command.name in DEVICE_CMDS_NEED_TERM):
requires_terminator = 1
if requires_terminator == 1:
term_header = tramp_header.replace("VKAPI_CALL ", "VKAPI_CALL terminator_")
out.append(tramp_header)
if command.params[0].type == 'VkPhysicalDevice':
out.append(' const VkLayerInstanceDispatchTable *disp;\n')
out.append(f' VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device({phys_dev_var_name});\n')
out.append(' if (VK_NULL_HANDLE == unwrapped_phys_dev) {\n')
out.append(' loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n')
out.append(f' "{command.name}: Invalid {phys_dev_var_name} "\n')
out.append(f' "[VUID-{command.name}-{phys_dev_var_name}-parameter]");\n')
out.append(' abort(); /* Intentionally fail so user can correct issue. */\n')
out.append(' }\n')
out.append(f' disp = loader_get_instance_layer_dispatch({phys_dev_var_name});\n')
elif command.params[0].type == 'VkInstance':
out.append(f' struct loader_instance *inst = loader_get_instance({instance_var_name});\n')
out.append(' if (NULL == inst) {\n')
out.append(' loader_log(\n')
out.append(' NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n')
out.append(f' "{command.name}: Invalid instance [VUID-{command.name}-{instance_var_name}-parameter]");\n')
out.append(' abort(); /* Intentionally fail so user can correct issue. */\n')
out.append(' }\n')
out.append('#error("Not implemented. Likely needs to be manually generated!");\n')
else:
out.append(' const VkLayerDispatchTable *disp = loader_get_dispatch(')
out.append(command.params[0].name)
out.append(');\n')
out.append(' if (NULL == disp) {\n')
out.append(' loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n')
out.append(f' "{command.name}: Invalid {command.params[0].name} "\n')
out.append(f' "[VUID-{command.name}-{command.params[0].name}-parameter]");\n')
out.append(' abort(); /* Intentionally fail so user can correct issue. */\n')
out.append(' }\n')
if 'DebugMarkerSetObjectName' in command.name:
out.append(' VkDebugMarkerObjectNameInfoEXT local_name_info;\n')
out.append(' memcpy(&local_name_info, pNameInfo, sizeof(VkDebugMarkerObjectNameInfoEXT));\n')
out.append(' // If this is a physical device, we have to replace it with the proper one for the next call.\n')
out.append(' if (pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {\n')
out.append(' struct loader_physical_device_tramp *phys_dev_tramp = (struct loader_physical_device_tramp *)(uintptr_t)pNameInfo->object;\n')
out.append(' local_name_info.object = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev;\n')
out.append(' }\n')
out.append(' if (pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) {\n')
out.append(' struct loader_instance* instance = (struct loader_instance *)(uintptr_t)pNameInfo->object;\n')
out.append(' local_name_info.object = (uint64_t)(uintptr_t)instance->instance;\n')
out.append(' }\n')
elif 'DebugMarkerSetObjectTag' in command.name:
out.append(' VkDebugMarkerObjectTagInfoEXT local_tag_info;\n')
out.append(' memcpy(&local_tag_info, pTagInfo, sizeof(VkDebugMarkerObjectTagInfoEXT));\n')
out.append(' // If this is a physical device, we have to replace it with the proper one for the next call.\n')
out.append(' if (pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {\n')
out.append(' struct loader_physical_device_tramp *phys_dev_tramp = (struct loader_physical_device_tramp *)(uintptr_t)pTagInfo->object;\n')
out.append(' local_tag_info.object = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev;\n')
out.append(' }\n')
out.append(' if (pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) {\n')
out.append(' struct loader_instance* instance = (struct loader_instance *)(uintptr_t)pTagInfo->object;\n')
out.append(' local_tag_info.object = (uint64_t)(uintptr_t)instance->instance;\n')
out.append(' }\n')
elif 'SetDebugUtilsObjectName' in command.name:
out.append(' VkDebugUtilsObjectNameInfoEXT local_name_info;\n')
out.append(' memcpy(&local_name_info, pNameInfo, sizeof(VkDebugUtilsObjectNameInfoEXT));\n')
out.append(' // If this is a physical device, we have to replace it with the proper one for the next call.\n')
out.append(' if (pNameInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) {\n')
out.append(' struct loader_physical_device_tramp *phys_dev_tramp = (struct loader_physical_device_tramp *)(uintptr_t)pNameInfo->objectHandle;\n')
out.append(' local_name_info.objectHandle = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev;\n')
out.append(' }\n')
out.append(' if (pNameInfo->objectType == VK_OBJECT_TYPE_INSTANCE) {\n')
out.append(' struct loader_instance* instance = (struct loader_instance *)(uintptr_t)pNameInfo->objectHandle;\n')
out.append(' local_name_info.objectHandle = (uint64_t)(uintptr_t)instance->instance;\n')
out.append(' }\n')
elif 'SetDebugUtilsObjectTag' in command.name:
out.append(' VkDebugUtilsObjectTagInfoEXT local_tag_info;\n')
out.append(' memcpy(&local_tag_info, pTagInfo, sizeof(VkDebugUtilsObjectTagInfoEXT));\n')
out.append(' // If this is a physical device, we have to replace it with the proper one for the next call.\n')
out.append(' if (pTagInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) {\n')
out.append(' struct loader_physical_device_tramp *phys_dev_tramp = (struct loader_physical_device_tramp *)(uintptr_t)pTagInfo->objectHandle;\n')
out.append(' local_tag_info.objectHandle = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev;\n')
out.append(' }\n')
out.append(' if (pTagInfo->objectType == VK_OBJECT_TYPE_INSTANCE) {\n')
out.append(' struct loader_instance* instance = (struct loader_instance *)(uintptr_t)pTagInfo->objectHandle;\n')
out.append(' local_tag_info.objectHandle = (uint64_t)(uintptr_t)instance->instance;\n')
out.append(' }\n')
if command.extensions[0] in NULL_CHECK_EXT_NAMES:
out.append(' if (disp->' + base_name + ' != NULL) {\n')
out.append(' ')
out.append(return_prefix)
if command.params[0].type == 'VkInstance':
out.append('inst->')
out.append('disp->')
out.append(base_name)
out.append('(')
count = 0
for param in command.params:
if count != 0:
out.append(', ')
if param.type == 'VkPhysicalDevice':
out.append('unwrapped_phys_dev')
elif ('DebugMarkerSetObject' in command.name or 'SetDebugUtilsObject' in command.name) and param.name == 'pNameInfo':
out.append('&local_name_info')
elif ('DebugMarkerSetObject' in command.name or 'SetDebugUtilsObject' in command.name) and param.name == 'pTagInfo':
out.append('&local_tag_info')
else:
out.append(param.name)
count += 1
out.append(');\n')
if command.extensions[0] in NULL_CHECK_EXT_NAMES:
if command.returnType != 'void':
out.append(' } else {\n')
out.append(' return VK_SUCCESS;\n')
out.append(' }\n')
out.append('}\n\n')
out.append(term_header)
if command.params[0].type == 'VkPhysicalDevice':
out.append(f' struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *){phys_dev_var_name};\n')
out.append(' struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;\n')
out.append(' if (NULL == icd_term->dispatch.')
out.append(base_name)
out.append(') {\n')
fatal_error_bit = '' if has_return_type and (len(command.extensions) == 0 or self.vk.extensions[command.extensions[0]].instance) else 'VULKAN_LOADER_FATAL_ERROR_BIT | '
out.append(f' loader_log(icd_term->this_instance, {fatal_error_bit}VULKAN_LOADER_ERROR_BIT, 0,\n')
out.append(' "ICD associated with VkPhysicalDevice does not support ')
out.append(base_name)
out.append('");\n')
# If this is an instance function taking a physical device (i.e. pre Vulkan 1.1), we need to behave and not crash so return an
# error here.
if has_return_type and (len(command.extensions) == 0 or self.vk.extensions[command.extensions[0]].instance):
out.append(' return VK_ERROR_EXTENSION_NOT_PRESENT;\n')
else:
out.append(' abort(); /* Intentionally fail so user can correct issue. */\n')
out.append(' }\n')
if has_surface == 1:
out.append(f' VkSurfaceKHR unwrapped_surface = {surface_var_name};\n')
out.append(' VkResult unwrap_res = wsi_unwrap_icd_surface(icd_term, &unwrapped_surface);\n')
out.append(' if (unwrap_res == VK_SUCCESS) {\n')
# If there's a structure with a surface, we need to update its internals with the correct surface for the ICD
if update_structure_surface == 1:
out.append(update_structure_string)
out.append(' ' + return_prefix + 'icd_term->dispatch.')
out.append(base_name)
out.append('(')
count = 0