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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418
|
#!/usr/bin/python3 -i
#
# Copyright (c) 2018-2021 Valve Corporation
# Copyright (c) 2018-2021 LunarG, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# The content of this file was derived from the Khronos Registry cgenerator.py
# and related Python files found in the KhronosGroup/Vulkan-Headers GitHub repository.
#
# Copyright (c) 2013-2016 The Khronos Group Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import sys
import json
from generator import GeneratorOptions, OutputGenerator, noneStr, regSortFeatures, write
from vkconventions import VulkanConventions
def _make_re_string(list, default=None):
"""Turn a list of strings into a regexp string matching exactly those strings.
From Khronos genvk.py
"""
if (len(list) > 0) or (default is None):
return '^(' + '|'.join(list) + ')$'
else:
return default
# Descriptive names for various regexp patterns used to select versions and extensions.
# From Khronos genvk.py
_default_extensions = 'vulkan'
_extensions = _features = []
_emit_extensions = []
# Exclude extensions from code generation.
# Note, this doesn't hide them from the application, but lets them bypass our
# layer during capture, meaning we will not call any of their functions at
# replay.
# To screen an extension out from the list reported to the application it should
# be added to the list kUnsupportedDeviceExtensions in trace_layer.cpp.
_remove_extensions = [
"VK_KHR_video_queue", "VK_KHR_video_decode_queue",
"VK_KHR_video_encode_queue", "VK_EXT_video_encode_h264",
"VK_KHR_video_decode_h264", "VK_KHR_video_decode_h265",
"VK_EXT_video_encode_h265", "VK_FUCHSIA_buffer_collection",
"VK_NVX_binary_import", "VK_HUAWEI_subpass_shading",
"VK_EXT_pipeline_properties", "VK_EXT_metal_objects",
# @todo <https://github.com/LunarG/gfxreconstruct/issues/917>
"VK_EXT_descriptor_buffer",
"VK_NV_copy_memory_indirect",
"VK_NV_memory_decompression"
]
# Turn lists of names/patterns into matching regular expressions.
# From Khronos genvk.py
_add_extensions_pat = _make_re_string(_extensions)
_remove_extensions_pat = _make_re_string(_remove_extensions)
_emit_extensions_pat = _make_re_string(_emit_extensions, '.*')
_features_pat = _make_re_string(_features, '.*')
def removesuffix(self: str, suffix: str, /) -> str:
# suffix='' should not call self[:-0].
if suffix and self.endswith(suffix):
return self[:-len(suffix)]
else:
return self[:]
# Strip the "Bit" ending or near-ending from an enum representing a group of
# flag bits to give the name of the type (typedef of Flags or Flags64) used to
# hold a disjoint set of them.
# It works for true enums and the 64 bit collections of static const variables
# which are tied together only with a naming convention in the C header.
def BitsEnumToFlagsTypedef(enum):
# if enum.endswith
flags = removesuffix(enum, 'Bits')
if flags != enum:
flags = flags + 's'
return flags
flags = removesuffix(enum, 'Bits2')
if flags != enum:
flags = flags + 's2'
# Gods preserve us from Bits 3, 4, 5, etc.
return flags
class ValueInfo():
"""ValueInfo - Class to store parameter/struct member information.
Contains information descripting Vulkan API call parameters and struct members.
Members:
name - Parameter/struct member name of the value.
base_type - Undecorated typename of the value.
full_type - Fully qualified typename of the value.
pointer_count - Number of '*' characters in the type declaration.
array_length - The parameter that specifies the number of elements in an array, or None if the value is not an array.
array_capacity - The max size of a statically allocated array, or None for a dynamically allocated array.
array_dimension - Number of the array dimension
platform_base_type - For platform specific type definitions, stores the original base_type declaration before platform to trace type substitution.
platform_full_type - For platform specific type definitions, stores the original full_type declaration before platform to trace type substitution.
is_pointer - True if the value is a pointer.
is_array - True if the member is an array.
is_dynamic - True if the memory for the member is an array and it is dynamically allocated.
is_const - True if the member is a const.
"""
def __init__(
self,
name,
base_type,
full_type,
pointer_count=0,
array_length=None,
array_length_value=None,
array_capacity=None,
array_dimension=None,
platform_base_type=None,
platform_full_type=None,
bitfield_width=None,
is_const=False,
is_com_outptr=False
):
self.name = name
self.base_type = base_type
self.full_type = full_type
self.pointer_count = pointer_count
self.array_length = array_length
self.array_length_value = array_length_value
self.array_capacity = array_capacity
self.array_dimension = array_dimension
self.platform_base_type = platform_base_type
self.platform_full_type = platform_full_type
self.bitfield_width = bitfield_width
self.is_pointer = True if pointer_count > 0 else False
self.is_array = True if array_length else False
self.is_dynamic = True if not array_capacity else False
self.is_const = is_const
self.is_com_outptr = is_com_outptr
class BaseGeneratorOptions(GeneratorOptions):
"""BaseGeneratorOptions - subclass of GeneratorOptions.
Options for Vulkan API parameter encoding and decoding C++ code generation.
Adds options used by FrameworkGenerator objects during C++ language
code generation.
Additional members
blacklists - Path to JSON file listing apicalls and structs to ignore.
platform_types - Path to JSON file listing platform (WIN32, X11, etc.)
specific types that are defined outside of the Vulkan header.
Additional members (from Khronos Registry COptionsGenerator)
prefix_text - list of strings to prefix generated header with
(usually a copyright statement + calling convention macros).
protect_file - True if multiple inclusion protection should be
generated (based on the filename) around the entire header.
apicall - string to use for the function declaration prefix,
such as APICALL on Windows.
apientry - string to use for the calling convention macro,
in typedefs, such as APIENTRY.
apientryp - string to use for the calling convention macro
in function pointer typedefs, such as APIENTRYP.
indent_func_proto - True if prototype declarations should put each
parameter on a separate line
indent_func_pointer - True if typedefed function pointers should put each
parameter on a separate line
align_func_param - if nonzero and parameters are being put on a
separate line, align parameter names at the specified column
"""
def __init__(
self,
blacklists=None, # Path to JSON file listing apicalls and structs to ignore.
platform_types=None, # Path to JSON file listing platform (WIN32, X11, etc.) defined types.
# Khronos CGeneratorOptions
filename=None,
directory='.',
prefix_text='',
protect_file=False,
protect_feature=True,
conventions=VulkanConventions(),
apicall='VKAPI_ATTR ',
apientry='VKAPI_CALL ',
apientryp='VKAPI_PTR *',
indent_func_proto=True,
align_func_param=48,
sort_procedure=regSortFeatures,
apiname='vulkan',
profile=None,
versions=_features_pat,
emitversions=_features_pat,
default_extensions=_default_extensions,
add_extensions=_add_extensions_pat,
remove_extensions=_remove_extensions_pat,
emit_extensions=_emit_extensions_pat,
extraVulkanHeaders=[]
):
GeneratorOptions.__init__(
self,
conventions=conventions,
filename=filename,
directory=directory,
apiname=apiname,
profile=profile,
versions=versions,
emitversions=emitversions,
defaultExtensions=default_extensions,
addExtensions=add_extensions,
removeExtensions=remove_extensions,
emitExtensions=emit_extensions,
sortProcedure=sort_procedure
)
self.blacklists = blacklists
self.platform_types = platform_types
# Khronos CGeneratorOptions
self.prefix_text = prefix_text
self.protect_file = protect_file
self.protect_feature = protect_feature
self.apicall = apicall
self.apientry = apientry # NOTE: While not used in this file, apientry is expected to be defined here by the OutputGenerator base class.
self.apientryp = apientryp # NOTE: While not used in this file, apientry is expected to be defined here by the OutputGenerator base class.
self.indent_func_proto = indent_func_proto
self.align_func_param = align_func_param
self.code_generator = True
self.extraVulkanHeaders = extraVulkanHeaders
class BaseGenerator(OutputGenerator):
"""BaseGenerator - subclass of OutputGenerator.
Base class providing common operations used to generate C++-language code for framework
components that encode and decode Vulkan API parameters.
Base class for Vulkan API parameter encoding and decoding generators.
"""
# These API calls should not be processed by the code generator. They require special implementations.
APICALL_BLACKLIST = []
APICALL_DECODER_BLACKLIST = []
# These method calls should not be processed by the code generator. They require special implementations.
METHODCALL_BLACKLIST = []
# These structures should not be processed by the code generator. They require special implementations.
STRUCT_BLACKLIST = []
# Platform specific basic types that have been defined extarnally to the Vulkan header.
PLATFORM_TYPES = {}
# Platform specific structure types that have been defined extarnally to the Vulkan header.
PLATFORM_STRUCTS = []
GENERIC_HANDLE_APICALLS = {
'vkDebugReportMessageEXT': {
'object': 'objectType'
},
'vkSetPrivateDataEXT': {
'objectHandle': 'objectType'
},
'vkGetPrivateDataEXT': {
'objectHandle': 'objectType'
},
'vkSetPrivateData': {
'objectHandle': 'objectType'
},
'vkGetPrivateData': {
'objectHandle': 'objectType'
}
}
GENERIC_HANDLE_STRUCTS = {
'VkDebugMarkerObjectNameInfoEXT': {
'object': 'objectType'
},
'VkDebugMarkerObjectTagInfoEXT': {
'object': 'objectType'
},
'VkDebugUtilsObjectNameInfoEXT': {
'objectHandle': 'objectType'
},
'VkDebugUtilsObjectTagInfoEXT': {
'objectHandle': 'objectType'
}
}
VULKAN_REPLACE_TYPE = {
"VkRemoteAddressNV": {
"baseType": "void",
"replaceWith": "void*"
}
}
# These types represent pointers to non-Vulkan or non-Dx12 objects that were written as 64-bit address IDs.
EXTERNAL_OBJECT_TYPES = ['void', 'Void']
MAP_STRUCT_TYPE = {
'D3D12_GPU_DESCRIPTOR_HANDLE': [
'MapGpuDescriptorHandle', 'MapGpuDescriptorHandles',
'descriptor_map'
],
'D3D12_GPU_VIRTUAL_ADDRESS':
['MapGpuVirtualAddress', 'MapGpuVirtualAddresses', 'gpu_va_map']
}
# Dispatchable handle types.
DISPATCHABLE_HANDLE_TYPES = [
'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue',
'VkCommandBuffer'
]
DUPLICATE_HANDLE_TYPES = [
'VkDescriptorUpdateTemplateKHR', 'VkSamplerYcbcrConversionKHR', 'VkPrivateDataSlotEXT'
]
# Default C++ code indentation size.
INDENT_SIZE = 4
def __init__(
self,
process_cmds,
process_structs,
feature_break=True,
err_file=sys.stderr,
warn_file=sys.stderr,
diag_file=sys.stdout
):
OutputGenerator.__init__(self, err_file, warn_file, diag_file)
# Typenames
self.struct_names = set() # Set of Vulkan struct typenames
self.handle_names = set() # Set of Vulkan handle typenames
self.flags_types = dict(
) # Map of flags types to base flag type (VkFlags or VkFlags64)
self.enum_names = set() # Set of Vulkan enumeration typenames
self.enumAliases = dict() # Map of enum names to aliases
self.enumEnumerants = dict() # Map of enum names to enumerants
# Type processing options
self.process_cmds = process_cmds # Populate the feature_cmd_params map
self.process_structs = process_structs # Populate the feature_struct_members map
self.feature_break = feature_break # Insert a line break between features
# Command parameter and struct member data for the current feature
if self.process_structs:
self.feature_struct_members = dict(
) # Map of struct names to lists of per-member ValueInfo
self.feature_struct_aliases = dict(
) # Map of struct names to aliases
self.extension_structs_with_handles = dict(
) # Map of extension struct names to a Boolean value indicating that a struct member has a handle type
self.extension_structs_with_handle_ptrs = dict(
) # Map of extension struct names to a Boolean value indicating that a struct member with a handle type is a pointer
if self.process_cmds:
self.feature_cmd_params = dict(
) # Map of cmd names to lists of per-parameter ValueInfo
def need_feature_generation(self):
"""Indicates that the current feature has C++ code to generate.
The subclass should override this method."""
return False
def generate_feature(self):
"""Performs C++ code generation for the feature.
The subclass should override this method."""
def beginFile(self, gen_opts):
"""Method override."""
OutputGenerator.beginFile(self, gen_opts)
if gen_opts.blacklists:
self.__load_blacklists(gen_opts.blacklists)
if gen_opts.platform_types:
self.__load_platform_types(gen_opts.platform_types)
# Platform defined struct processing must be implemented manually,
# so these structs will be added to the blacklist.
self.STRUCT_BLACKLIST += self.PLATFORM_STRUCTS
# User-supplied prefix text, if any (list of strings)
if (gen_opts.prefix_text):
for s in gen_opts.prefix_text:
write(s, file=self.outFile)
# Multiple inclusion protection & C++ wrappers.
if (gen_opts.protect_file and self.genOpts.filename):
header_sym = 'GFXRECON_' + re.sub(
'\.h', '_H', os.path.basename(self.genOpts.filename)
).upper()
write('#ifndef ', header_sym, file=self.outFile)
write('#define ', header_sym, file=self.outFile)
self.newline()
def includeVulkanHeaders(self, gen_opts):
"""Write Vulkan header include statements
"""
write('#include "vulkan/vulkan.h"', file=self.outFile)
for extra_vulkan_header in gen_opts.extraVulkanHeaders:
header_include_path = re.sub(r'\\', '/', extra_vulkan_header)
write(f'#include "{header_include_path}"', file=self.outFile)
def endFile(self):
"""Method override."""
# Finish C++ wrapper and multiple inclusion protection
if (self.genOpts.protect_file and self.genOpts.filename):
self.newline()
write('#endif', file=self.outFile)
# Finish processing in superclass
OutputGenerator.endFile(self)
def beginFeature(self, interface, emit):
"""Method override. Start processing in superclass."""
OutputGenerator.beginFeature(self, interface, emit)
# Reset feature specific data sets
if self.process_structs:
self.feature_struct_members = dict()
self.feature_struct_aliases = dict()
if self.process_cmds:
self.feature_cmd_params = dict()
# Some generation cases require that extra feature protection be suppressed
if self.genOpts.protect_feature:
self.featureExtraProtect = self.__get_feature_protect(interface)
def endFeature(self):
"""Method override. Generate code for the feature."""
if self.emit and self.need_feature_generation():
if self.feature_break:
self.newline()
if (self.featureExtraProtect is not None):
write('#ifdef', self.featureExtraProtect, file=self.outFile)
self.generate_feature()
if (self.featureExtraProtect is not None):
write(
'#endif /*',
self.featureExtraProtect,
'*/',
file=self.outFile
)
# Finish processing in superclass
OutputGenerator.endFeature(self)
def genType(self, typeinfo, name, alias):
"""Method override. Type generation."""
OutputGenerator.genType(self, typeinfo, name, alias)
type_elem = typeinfo.elem
# If the type is a struct type, traverse the imbedded <member> tags
# generating a structure. Otherwise, emit the tag text.
category = type_elem.get('category')
if (category == 'struct' or category == 'union'):
self.struct_names.add(name)
# Skip code generation for union encode/decode functions.
if category == 'struct':
self.genStruct(typeinfo, name, alias)
elif (category == 'handle'):
self.handle_names.add(name)
elif (category == 'bitmask'):
# Flags can have either VkFlags or VkFlags64 base type
alias = type_elem.get('alias')
if alias:
# Use same base type as the alias if one exists
self.flags_types[name] = self.flags_types[alias]
else:
# Otherwise, look for base type inside type declaration
self.flags_types[name] = type_elem.find('type').text
def genStruct(self, typeinfo, typename, alias):
"""Method override.
Struct (e.g. C "struct" type) generation.
This is a special case of the <type> tag where the contents are
interpreted as a set of <member> tags instead of freeform C
C type declarations. The <member> tags are just like <param>
tags - they are a declaration of a struct or union member.
"""
OutputGenerator.genStruct(self, typeinfo, typename, alias)
# For structs, we ignore the alias because it is a typedef. Not ignoring the alias
# would produce multiple definition errors for functions with struct parameters.
if self.process_structs:
if not alias:
self.feature_struct_members[typename] = self.make_value_info(
typeinfo.elem.findall('.//member')
)
else:
self.feature_struct_aliases[typename] = alias
def genGroup(self, groupinfo, group_name, alias):
"""Method override.
Group (e.g. C "enum" type) generation.
These are concatenated together with other types.
"""
OutputGenerator.genGroup(self, groupinfo, group_name, alias)
self.enum_names.add(group_name)
if not alias:
enumerants = dict()
for elem in groupinfo.elem:
supported = elem.get('supported')
if not supported or not 'disabled' in supported:
name = elem.get('name')
if name and not elem.get('alias'):
enumerants[name] = elem.get('value')
self.enumEnumerants[group_name] = enumerants
else:
self.enumAliases[group_name] = alias
def genEnum(self, enuminfo, name, alias):
"""Method override.
Enumerant generation
<enum> tags may specify their values in several ways, but are usually
just integers.
"""
OutputGenerator.genEnum(self, enuminfo, name, alias)
def genCmd(self, cmdinfo, name, alias):
"""Method override. Command generation."""
OutputGenerator.genCmd(self, cmdinfo, name, alias)
if self.process_cmds:
# Create the declaration for the function prototype
proto = cmdinfo.elem.find('proto')
proto_decl = self.genOpts.apicall + noneStr(proto.text)
for elem in proto:
text = noneStr(elem.text)
tail = noneStr(elem.tail)
if (elem.tag == 'name'):
if text.startswith('vk'):
text = text[2:]
proto_decl += self.makeProtoName(text, tail)
else:
proto_decl += text + tail
return_type = noneStr(proto.text
) + noneStr(proto.find('type').text)
# TODO: Define a class or namedtuple for the dictionary entry
self.feature_cmd_params[name] = (
return_type, proto_decl,
self.make_value_info(cmdinfo.elem.findall('param'))
)
def make_value_info(self, params):
"""Generate a list of ValueInfo objects from a list of <param> or <member> tags
params - list of <param> or <member> tags to process
"""
values = []
for param in params:
# Get name
elem = param.find('name')
name = noneStr(elem.text)
name_tail = noneStr(elem.tail)
# Get type info
elem = param.find('type')
base_type = noneStr(elem.text)
full_type = (noneStr(param.text) + base_type
+ noneStr(elem.tail)).strip()
# Check for platform specific type definitions that need to be converted to a recognized trace format type.
platform_base_type = None
platform_full_type = None
if base_type in self.PLATFORM_TYPES:
type_info = self.PLATFORM_TYPES[base_type]
platform_base_type = base_type
platform_full_type = full_type
full_type = full_type.replace(
base_type, type_info['replaceWith']
)
base_type = type_info['baseType']
# Get array length, always use altlen when available to avoid parsing latexmath
if 'altlen' in param.attrib:
array_length = param.attrib.get('altlen')
else:
array_length = self.get_array_len(param)
array_capacity = None
if self.is_static_array(param):
array_capacity = array_length
array_length = self.get_static_array_len(
name, params, array_capacity
)
# Get bitfield width
bitfield_width = None
if ':' in name_tail:
bitfield_width = name_tail
values.append(
ValueInfo(
name=name,
base_type=base_type,
full_type=full_type,
pointer_count=self.get_pointer_count(full_type),
array_length=array_length,
array_capacity=array_capacity,
platform_base_type=platform_base_type,
platform_full_type=platform_full_type,
bitfield_width=bitfield_width
)
)
# Link array values to their corresponding length values
for array_value in [v for v in values if v.array_length]:
for v in values:
if re.search(
r'\b{}\b'.format(v.name), array_value.array_length
):
array_value.array_length_value = v
break
return values
def is_struct(self, base_type):
"""Check for struct type."""
if (
(base_type in self.struct_names)
or (base_type in self.PLATFORM_STRUCTS)
):
return True
return False
def is_class(self, value):
return False
def is_handle(self, base_type):
"""Check for handle type."""
if base_type in self.handle_names:
return True
return False
def is_dispatchable_handle(self, base_type):
"""Check for dispatchable handle type."""
if base_type in self.DISPATCHABLE_HANDLE_TYPES:
return True
return False
def is_enum(self, base_type):
"""Check for enum type."""
if base_type in self.enum_names:
return True
return False
def is_union(self, value):
return False
def is_flags(self, base_type):
"""Check for flags (bitmask) type."""
if base_type in self.flags_types:
return True
return False
def is_function_ptr(self, base_type):
"""Check for function pointer type."""
if (base_type[:4] == 'PFN_') or (base_type[-4:] == 'Func'):
return True
return False
def is_array_len(self, name, values):
"""Determine if the value name specifies an array length."""
for value in values:
if name == value.array_length:
return True
return False
def get_pointer_count(self, full_type):
"""Return the number of '*' in a type declaration."""
return full_type.count('*')
def is_input_pointer(self, value):
"""Determine if a pointer parameter is an input parameter."""
if 'const' in value.full_type:
# Vulkan seems to follow a pattern where input pointers will be const and output pointers will not be const.
return True
elif value.platform_base_type and value.base_type == 'void' and value.pointer_count == 1:
# For some extensions, platform specific handles are mapped to the 'void*' type without a const qualifier,
# but need to be treated as an input (eg. if HANDLE is mapped to void*, it should not be treated as an output).
return True
return False
def is_output_parameter(self, value):
"""Determine if a parameter is an output parameter."""
# Check for an output pointer/array or an in-out pointer.
if (
(value.is_pointer or value.is_array)
and not self.is_input_pointer(value)
):
return True
return False
def get_array_len(self, param):
"""Retrieve the length of an array defined by a <param> or <member> element."""
result = None
len = param.attrib.get('len')
if len:
# Check for a string or array of strings
if 'null-terminated' in len:
# Strings are ignored, but string arrays are checked for a length value.
# For string arrays, 'len' can look like 'count,null-terminated', indicating that we have an array of null terminated
# strings. We strip the null-terminated substring from the 'len' field and only return the parameter specifying the string count.
if len != 'null-terminated':
result = len.split(',')[0]
else:
result = len
if result:
result = str(result).replace('::', '->')
else:
# Check for a static array
paramname = param.find('name')
if (paramname.tail is not None) and ('[' in paramname.tail):
paramenumsize = param.find('enum')
if paramenumsize is not None:
result = paramenumsize.text
else:
paramsizes = paramname.tail[1:-1].split('][')
sizetokens = []
for paramsize in paramsizes:
sizetokens.append(paramsize)
result = ', '.join(sizetokens)
return result
def is_static_array(self, param):
"""Check for a static array."""
name = param.find('name')
if (name.tail is not None) and ('[' in name.tail):
return True
return False
def get_static_array_len(self, name, params, capacity):
"""Determine the length value of a static array (get_array_len() returns the total capacity, not the actual length)."""
# The XML registry does not provide a direct method for determining if a parameter provides the length
# of a static array, but the parameter naming follows a pattern of array name = 'values' and length
# name = 'value_count'. We will search the parameter list for a length parameter using this pattern.
length_name = name[:-1] + 'Count'
for param in params:
if length_name == noneStr(param.find('name').text):
return length_name
# Not all static arrays have an associated length parameter. These will use capacity as length.
return capacity
def is_struct_black_listed(self, typename):
"""Determines if a struct with the specified typename is blacklisted."""
if typename in self.STRUCT_BLACKLIST:
return True
return False
def is_cmd_black_listed(self, name):
"""Determines if a function with the specified typename is blacklisted."""
if name in self.APICALL_BLACKLIST:
return True
if 'Decoder' in self.__class__.__name__ and name in self.APICALL_DECODER_BLACKLIST:
return True
return False
def is_method_black_listed(self, class_name, method_name=None):
"""Determines if a method call with the specified typename is blacklisted."""
combined_name = class_name
if method_name:
combined_name += '_' + method_name
if combined_name in self.METHODCALL_BLACKLIST:
return True
return False
def get_filtered_struct_names(self):
"""Retrieves a filtered list of keys from self.feature_struct_memebers with blacklisted items removed."""
return [
key for key in self.feature_struct_members
if not self.is_struct_black_listed(key)
]
def get_filtered_cmd_names(self):
"""Retrieves a filtered list of keys from self.feature_cmd_params with blacklisted items removed."""
return [
key for key in self.feature_cmd_params
if not self.is_cmd_black_listed(key)
]
def check_struct_pnext_handles(self, typename):
"""Determines if the specified struct type can reference pNext extension structs that contain handles."""
found_handles = False
found_handle_ptrs = False
valid_extension_structs = self.registry.validextensionstructs.get(
typename
)
if valid_extension_structs:
# Need to search the XML tree for pNext structures that have not been processed yet.
for struct_name in valid_extension_structs:
# Check for cached results from a previous check for this struct
if struct_name in self.extension_structs_with_handles:
if self.extension_structs_with_handles[struct_name]:
found_handles = True
if self.extension_structs_with_handle_ptrs[struct_name]:
found_handle_ptrs = True
else:
# If a pre-existing result was not found, check the XML registry for the struct
has_handles = False
hasHandlePtrs = False
type_info = self.registry.lookupElementInfo(
struct_name, self.registry.typedict
)
if type_info:
member_infos = [
member for member in
type_info.elem.findall('.//member/type')
]
if member_infos:
for member_info in member_infos:
found = self.registry.tree.find(
"types/type/[name='" + member_info.text
+ "'][@category='handle']"
)
if found:
has_handles = True
self.extension_structs_with_handles[
struct_name] = True
if member_info.tail and (
'*' in member_info.tail
):
self.extension_structs_with_handle_ptrs[
struct_name] = True
hasHandlePtrs = True
else:
self.extension_structs_with_handle_ptrs[
struct_name] = False
if has_handles:
found_handles = True
if hasHandlePtrs:
found_handle_ptrs = True
else:
self.extension_structs_with_handles[struct_name
] = False
self.extension_structs_with_handle_ptrs[struct_name
] = False
return found_handles, found_handle_ptrs
def check_struct_member_handles(
self,
typename,
structs_with_handles,
structs_with_handle_ptrs=None,
ignore_output=False,
structs_with_map_data=None,
extra_types=None
):
"""Determines if the specified struct type contains members that have a handle type or are structs that contain handles.
Structs with member handles are added to a dictionary, where the key is the structure type and the value is a list of the handle members.
An optional list of structure types that contain handle members with pointer types may also be generated.
"""
handles = []
has_handle_pointer = False
map_data = []
for value in self.feature_struct_members[typename]:
if self.is_handle(value.base_type) or self.is_class(value) or (
extra_types and value.base_type in extra_types
):
# The member is a handle.
handles.append(value)
if (
(structs_with_handle_ptrs is not None)
and (value.is_pointer or value.is_array)
):
has_handle_pointer = True
elif self.is_struct(value.base_type) and (
(value.base_type in structs_with_handles) and
((not ignore_output) or (not '_Out_' in value.full_type))
):
# The member is a struct that contains a handle.
handles.append(value)
if (
(structs_with_handle_ptrs is not None)
and (value.name in structs_with_handle_ptrs)
):
has_handle_pointer = True
elif self.is_union(value.base_type):
# Check the anonymous union for objects.
union_members = self.get_union_members(value.base_type)
for union_info in union_members:
if self.is_struct(
union_info.base_type
) and (union_info.base_type in structs_with_handles):
handles.append(value)
has_handle_pointer = True
elif union_info.base_type in self.source_dict['class_dict'
]:
handles.append(value)
has_handle_pointer = True
elif union_info.base_type in self.MAP_STRUCT_TYPE:
if (structs_with_map_data is not None):
map_data.append(value)
elif ('pNext' in value.name) and (not self.is_dx12_class()):
# The pNext chain may include a struct with handles.
has_pnext_handles, has_pnext_handle_ptrs = self.check_struct_pnext_handles(
typename
)
if has_pnext_handles:
handles.append(value)
if (
structs_with_handle_ptrs is not None
) and has_pnext_handle_ptrs:
has_handle_pointer = True
if (structs_with_map_data is not None) and (
(value.base_type in self.MAP_STRUCT_TYPE) or
(value.base_type in structs_with_map_data)
):
map_data.append(value)
if map_data:
structs_with_map_data[typename] = map_data
if handles:
# Process the list of struct members a second time to check for
# members with the same type as the struct. The current struct
# type has not been added to the table of structs with handles
# yet, so we must check the struct members a second time, looking
# for members with the struct type, now that we know the current
# struct type contains members that are handles/objects. Any
# struct members that have the same type as the struct must be
# added to the handle member list.
for value in self.feature_struct_members[typename]:
if (value.base_type == typename) and (
(not ignore_output) or (not '_Out_' in value.full_type)
):
handles.append(value)
structs_with_handles[typename] = handles
if (structs_with_handle_ptrs is not None) and has_handle_pointer:
structs_with_handle_ptrs.append(typename)
return True
return False
def get_generic_struct_handle_type_value(self, struct_name, member_name):
"""For a struct member that contains a generic handle value, retrieve the struct member
containing an enum value defining the specific handle type. Generic handles have an
integer type such as uint64_t, with an associated enum value defining the specific
type such as VkObjectType.
"""
if struct_name in self.GENERIC_HANDLE_STRUCTS:
struct_entry = self.GENERIC_HANDLE_STRUCTS[struct_name]
if member_name in struct_entry:
return struct_entry[member_name]
return None
def get_generic_cmd_handle_type_value(self, cmd_name, param_name):
"""For an API call parameter that contains a generic handle value, retrieve the parameter
containing an enum value defining the specific handle type. Generic handles have an
integer type such as uint64_t, with an associated enum value defining the specific
type such as VkObjectType.
"""
if cmd_name in self.GENERIC_HANDLE_APICALLS:
cmd_entry = self.GENERIC_HANDLE_APICALLS[cmd_name]
if param_name in cmd_entry:
return cmd_entry[param_name]
return None
def is_generic_struct_handle_value(self, struct_name, member_name):
"""Determine if a struct member contains a generic handle value. Generic handles have an
integer type such as uint64_t, with an associated enum value defining the specific
type such as VkObjectType.
"""
if self.get_generic_struct_handle_type_value(struct_name, member_name):
return True
return False
def is_generic_cmd_handle_value(self, cmd_name, param_name):
"""Determine if an API call parameter contains a generic handle value. Generic handles have an
integer type such as uint64_t, with an associated enum value defining the specific
type such as VkObjectType.
"""
if self.get_generic_cmd_handle_type_value(cmd_name, param_name):
return True
return False
def indent(self, value, spaces):
"""Indent all lines in a string.
value - String to indent.
spaces - Number of spaces to indent.
"""
prefix = ' ' * spaces
return '\n'.join([prefix + v if v else v for v in value.split('\n')])
def make_unique_list(self, in_list):
"""Return a copy of in_list with duplicates removed, preserving order."""
out_list = []
for value in in_list:
if value not in out_list:
out_list.append(value)
return out_list
def make_arg_list(self, values):
"""Create a string containing a comma separated argument list from a list of ValueInfo values.
values - List of ValueInfo objects providing the parameter names for the argument list.
"""
return ', '.join([value.name for value in values])
def make_aligned_param_decl(
self, param_type, param_name, indent_column, align_column
):
"""make_aligned_param_decl - return an indented parameter declaration string with the parameter
name aligned to the specified column.
"""
param_decl = ' ' * indent_column
param_decl += param_type
if align_column:
param_decl = param_decl.ljust(align_column - 1)
param_decl += ' '
param_decl += param_name
return param_decl
def make_invocation_type_name(self, base_type):
"""Convert a type name to a string to be used as part of an encoder/decoder function/method name."""
if self.is_struct(base_type):
return base_type
elif self.is_handle(base_type):
return 'Handle'
elif self.is_flags(base_type):
# Strip 'Vk' from base flag type
return self.flags_types[base_type][2:]
elif self.is_enum(base_type):
return 'Enum'
elif base_type == 'wchar_t':
return 'WString'
elif base_type == 'char':
return 'String'
elif self.is_function_ptr(base_type):
return 'FunctionPtr'
elif base_type == 'size_t':
return 'SizeT'
elif base_type == 'int':
# Extensions use the int type when dealing with file descriptors
return 'Int32'
elif base_type.endswith('_t'):
if base_type[0] == 'u':
# For unsigned types, capitalize the first two characters.
return base_type[0].upper() + base_type[1].upper(
) + base_type[2:-2]
else:
return base_type[:-2].title()
elif base_type[0].islower():
return base_type.title()
return base_type
def make_decoded_param_type(self, value):
"""Create a type to use for a decoded parameter, using the decoder wrapper types for pointers."""
type_name = value.base_type
# is_pointer will be False for static arrays.
if value.is_pointer or value.is_array:
count = value.pointer_count
if self.is_struct(type_name):
if (
self.is_dx12_class() and
(value.array_dimension and value.array_dimension == 1)
) or (not self.is_dx12_class() and count > 1):
type_name = 'StructPointerDecoder<Decoded_{}*>'.format(
type_name
)
else:
type_name = 'StructPointerDecoder<Decoded_{}>'.format(
type_name
)
elif self.is_class(value):
if count == 1:
type_name = 'format::HandleId'
else:
type_name = 'HandlePointerDecoder<{}*>'.format(type_name)
elif type_name == 'wchar_t':
if count > 1:
type_name = 'WStringArrayDecoder'
else:
type_name = 'WStringDecoder'
elif type_name == 'char':
if count > 1:
type_name = 'StringArrayDecoder'
else:
type_name = 'StringDecoder'
elif type_name == 'void':
if value.is_array:
# If this was an array (void*) it was encoded as an array of bytes.
type_name = 'PointerDecoder<uint8_t>'
elif count > 1:
# If this was a pointer to a pointer to an unknown object (void**), it was encoded as a pointer to a 64-bit address value.
# So, we specify uint64_t as the decode type and void* as the type to be used for Vulkan API call output parameters.
type_name = 'PointerDecoder<uint64_t, void*>'
else:
# If this was a pointer to an unknown object (void*), it was encoded as a 64-bit address value.
type_name = 'uint64_t'
elif self.is_handle(type_name):
type_name = 'HandlePointerDecoder<{}>'.format(type_name)
else:
if count > 1:
type_name = 'PointerDecoder<{}*>'.format(type_name)
else:
type_name = 'PointerDecoder<{}>'.format(type_name)
elif self.is_function_ptr(type_name):
# Function pointers are encoded as a 64-bit address value.
type_name = 'uint64_t'
elif self.is_struct(type_name):
type_name = 'Decoded_{}'.format(type_name)
elif self.is_handle(type_name):
type_name = 'format::HandleId'
else:
type_name = '{}'.format(type_name)
return type_name
def make_consumer_func_decl(
self, return_type, name, values, dx12_method=False
):
"""make_consumer_decl - return VulkanConsumer class member function declaration.
Generate VulkanConsumer class member function declaration.
"""
param_decls = []
param_decl = self.make_aligned_param_decl(
'const ApiCallInfo&', 'call_info', self.INDENT_SIZE,
self.genOpts.align_func_param
)
param_decls.append(param_decl)
if dx12_method:
param_decl = self.make_aligned_param_decl(
'format::HandleId', 'object_id', self.INDENT_SIZE,
self.genOpts.align_func_param
)
param_decls.append(param_decl)
if return_type != 'void':
if self.is_dx12_class():
method_name = name[name.find('::Process_') + 10:]
return_value = self.get_return_value_info(
return_type, method_name
)
rtn_type1 = self.make_decoded_param_type(return_value)
if rtn_type1.find('Decoder') != -1:
rtn_type1 += '*'
param_decl = self.make_aligned_param_decl(
rtn_type1, 'return_value', self.INDENT_SIZE,
self.genOpts.align_func_param
)
else:
param_decl = self.make_aligned_param_decl(
return_type, 'returnValue', self.INDENT_SIZE,
self.genOpts.align_func_param
)
param_decls.append(param_decl)
for value in values:
param_type = self.make_decoded_param_type(value)
if 'Decoder' in param_type:
param_type = '{}*'.format(param_type)
param_decl = self.make_aligned_param_decl(
param_type, value.name, self.INDENT_SIZE,
self.genOpts.align_func_param
)
param_decls.append(param_decl)
if param_decls:
return 'void {}(\n{})'.format(name, ',\n'.join(param_decls))
return 'void {}()'.format(name)
def make_structure_type_enum(self, typeinfo, typename):
"""Generate the VkStructreType enumeration value for the specified structure type."""
members = typeinfo.elem.findall('.//member')
for member in members:
membername = noneStr(member.find('name').text)
# We only care about structures with an sType, which can be included in a pNext chain.
if membername == 'sType':
# Check for value in the XML element.
values = member.attrib.get('values')
if values:
return values
else:
# If the value was not specified by the XML element, process the struct type to create it.
stype = re.sub('([a-z0-9])([A-Z])', r'\1_\2', typename)
stype = stype.replace('D3_D12', 'D3D12')
stype = stype.replace('Device_IDProp', 'Device_ID_Prop')
stype = stype.upper()
return re.sub('VK_', 'VK_STRUCTURE_TYPE_', stype)
return None
def make_array_length_expression(self, value, prefix=''):
"""Generate an expression for the length of a given array value."""
length_expr = value.array_length
length_value = value.array_length_value
if length_value:
if length_value.is_pointer:
# Add implicit dereference when length expr == pointer name
if length_value.name == length_expr:
length_expr = '*' + length_expr
# Add null check to length value behind pointer
length_expr = '({length_value.name} != nullptr) ? ({length_expr}) : 0'.format(
length_value=length_value, length_expr=length_expr
)
elif length_value.base_type == 'VkDeviceSize':
# Static cast 64-bit length expression to eliminate warning in 32-bit builds
length_expr = 'static_cast<size_t>({})'.format(length_expr)
# Add prefix to parameter in the length expression
length_expr = length_expr.replace(
length_value.name, prefix + length_value.name
)
return length_expr
def make_array2d_length_expression(self, value, values, prefix=''):
length_exprs = value.array_length.split(',')
if len(length_exprs) == value.pointer_count:
# All dimensions are provided in the xml
lengths = []
for length_expr in length_exprs:
# Prefix members
for v in values:
length_expr = re.sub(
r'\b({})\b'.format(v.name), r'{}\1'.format(prefix),
length_expr
)
lengths.append(length_expr)
return lengths
else:
# XML does not provide lengths for all dimensions, instantiate a specialization of ArraySize2D to fetch the sizes
type_list = ', '.join([v.full_type for v in values])
arg_list = ', '.join([v.name for v in values])
return ['ArraySize2D<{}>({})'.format(type_list, arg_list)]
def make_encoder_method_call(
self, name, value, values, prefix, omit_output_param=None
):
"""Generate a parameter encoder method call invocation."""
arg_name = prefix + value.name
if self.is_generic_struct_handle_value(
name, value.name
) or self.is_generic_cmd_handle_value(name, value.name):
handle_type_name = prefix
if self.is_generic_struct_handle_value(name, value.name):
handle_type_name += self.get_generic_struct_handle_type_value(
name, value.name
)
else:
handle_type_name += self.get_generic_cmd_handle_type_value(
name, value.name
)
if self.is_dx12_class():
arg_name = 'GetDx12WrappedId({}, {})'.format(
arg_name, handle_type_name
)
else:
arg_name = 'GetWrappedId({}, {})'.format(
arg_name, handle_type_name
)
args = [arg_name]
is_struct = False
is_string = False
is_funcp = False
type_name = self.make_invocation_type_name(value.base_type)
if self.is_struct(type_name):
args = ['encoder'] + args
is_struct = True
method_call = 'EncodeStruct'
else:
if type_name in ['String', 'WString']:
is_string = True
elif type_name == 'FunctionPtr':
is_funcp = True
method_call = 'encoder->Encode' + type_name
if is_string:
if value.is_array and value.is_dynamic:
method_call += 'Array'
args.append(self.make_array_length_expression(value, prefix))
elif value.is_array:
if value.pointer_count > 1:
method_call += 'Array{}D'.format(value.pointer_count)
args.extend(
self.make_array2d_length_expression(value, values, prefix)
)
elif ',' in value.array_length:
method_call += '{}DMatrix'.format(
value.array_length.count(',') + 1
)
args.append(self.make_array_length_expression(value, prefix))
else:
method_call += 'Array'
args.append(self.make_array_length_expression(value, prefix))
elif is_struct:
if value.is_pointer:
method_call += 'Ptr'
elif not (is_string or is_funcp):
# Ignore string and function names, which do not use the Ptr/Value suffix
if value.is_pointer:
method_call += 'Ptr' * value.pointer_count
else:
method_call += 'Value'
if self.is_output_parameter(value) and omit_output_param:
args.append(omit_output_param)
return '{}({})'.format(method_call, ', '.join(args))
def is_dx12_class(self):
return True if ('Dx12' in self.__class__.__name__) else False
def __get_feature_protect(self, interface):
"""Return appropriate feature protect string from 'platform' tag on feature.
From Vulkan-ValidationLayers common_codegen.py.
"""
# TODO: This should probably be in a JSON file.
platform_dict = {
'android': 'VK_USE_PLATFORM_ANDROID_KHR',
'fuchsia': 'VK_USE_PLATFORM_FUCHSIA',
'ios': 'VK_USE_PLATFORM_IOS_MVK',
'macos': 'VK_USE_PLATFORM_MACOS_MVK',
'mir': 'VK_USE_PLATFORM_MIR_KHR',
'vi': 'VK_USE_PLATFORM_VI_NN',
'wayland': 'VK_USE_PLATFORM_WAYLAND_KHR',
'win32': 'VK_USE_PLATFORM_WIN32_KHR',
'xcb': 'VK_USE_PLATFORM_XCB_KHR',
'xlib': 'VK_USE_PLATFORM_XLIB_KHR',
'xlib_xrandr': 'VK_USE_PLATFORM_XLIB_XRANDR_EXT',
'ggp': 'VK_USE_PLATFORM_GGP',
'directfb': 'VK_USE_PLATFORM_DIRECTFB_EXT',
'headless': 'VK_USE_PLATFORM_HEADLESS'
}
platform = interface.get('platform')
if platform and platform in platform_dict:
return platform_dict[platform]
return None
def __load_blacklists(self, filename):
lists = json.loads(open(filename, 'r').read())
self.APICALL_BLACKLIST += lists['functions']
self.APICALL_DECODER_BLACKLIST += lists['functions-decoder']
self.STRUCT_BLACKLIST += lists['structures']
if 'classmethods' in lists:
for class_name, method_list in lists['classmethods'].items():
for method_name in method_list:
self.METHODCALL_BLACKLIST.append(
class_name + '_' + method_name
)
def __load_platform_types(self, filename):
platforms = json.loads(open(filename, 'r').read())
for platform_name in platforms:
platform = platforms[platform_name]
platform_types = platform['types']
platform_types.update(self.VULKAN_REPLACE_TYPE)
for type in platform_types:
self.PLATFORM_TYPES[type] = platform_types[type]
platform_structs = platform['structs']
if platform_structs:
self.PLATFORM_STRUCTS += platform_structs
# Return true if the type passed in is used to hold a set of bitwise flags
# that is 64 bits wide.
def is_64bit_flags(self, flag_type):
if flag_type in self.flags_types:
if self.flags_types[flag_type] == 'VkFlags64':
return True
return False
# Return true if the enum or 64 bit pseudo enum passed-in represents a set
# of bitwise flags.
# Note, all 64 bit pseudo-enums represent flags since the only reason to go to
# 64 bits is to allow more than 32 flags to be represented.
def is_flags_enum_64bit(self, enum):
flag_type = BitsEnumToFlagsTypedef(enum)
return self.is_64bit_flags(flag_type)
|