aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2025-10-01 12:58:38 -0500
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2025-10-06 11:09:20 -0600
commitbc714eb5327f4f42192892c77b76bd02e69129f6 (patch)
treed0b588e2a3196856767b1043ec27307769f17edd /scripts
parenta36938d354a65b709f8f322d004478e1aeca1a19 (diff)
downloadusermoji-bc714eb5327f4f42192892c77b76bd02e69129f6.tar.xz
scripts: Update codegen to use Vulkan-Object
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate_source.py295
-rw-r--r--scripts/generators/mock_icd_generator.py581
-rw-r--r--scripts/generators/vulkan_tools_helper_file_generator.py1327
-rw-r--r--scripts/generators/vulkaninfo_generator.py1983
4 files changed, 1189 insertions, 2997 deletions
diff --git a/scripts/generate_source.py b/scripts/generate_source.py
index 336e5ffb..82bc213e 100755
--- a/scripts/generate_source.py
+++ b/scripts/generate_source.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
-# Copyright (c) 2019-2025 The Khronos Group Inc.
-# Copyright (c) 2019-2025 Valve Corporation
-# Copyright (c) 2019-2025 LunarG, Inc.
-# Copyright (c) 2019-2025 Google Inc.
-# Copyright (c) 2023-2025 RasterGrid Kft.
+# Copyright (c) 2019 The Khronos Group Inc.
+# Copyright (c) 2019 Valve Corporation
+# Copyright (c) 2019 LunarG, Inc.
+# Copyright (c) 2019 Google Inc.
+# Copyright (c) 2021-2022 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.
@@ -22,118 +23,218 @@
import argparse
import filecmp
import os
-import re
-import json
import shutil
-import subprocess
import sys
+import re
import tempfile
-
+import json
import common_codegen
-# files to exclude from --verify check
-verify_exclude = ['.clang-format']
+from xml.etree import ElementTree
+
+# Because we have special logic to import the Registry from input arguments and the BaseGenerator comes from the registry, we have to delay defining it until *after*
+# the Registry has been imported. Yes this is awkward, but it was the least awkward way to make --verify work.
+generators = {}
+
+def RunGenerators(api: str, registry: str, video_registry: str, directory: str, styleFile: str, targetFilter: str, flatOutput: bool):
+
+ try:
+ common_codegen.RunShellCmd(f'clang-format --version')
+ has_clang_format = True
+ except:
+ has_clang_format = False
+ if not has_clang_format:
+ print("WARNING: Unable to find clang-format!")
+
+ # These live in the Vulkan-Docs repo, but are pulled in via the
+ # Vulkan-Headers/registry folder
+ # At runtime we inject python path to find these helper scripts
+ scripts = os.path.dirname(registry)
+ scripts_directory_path = os.path.dirname(os.path.abspath(__file__))
+ registry_headers_path = os.path.join(scripts_directory_path, scripts)
+ sys.path.insert(0, registry_headers_path)
+ try:
+ from reg import Registry
+ except:
+ print("ModuleNotFoundError: No module named 'reg'") # normal python error message
+ print(f'{registry_headers_path} is not pointing to the Vulkan-Headers registry directory.')
+ print("Inside Vulkan-Headers there is a registry/reg.py file that is used.")
+ sys.exit(1) # Return without call stack so easy to spot error
+
+ from base_generator import BaseGeneratorOptions
+ from generators.mock_icd_generator import MockICDOutputGenerator
+ from generators.vulkan_tools_helper_file_generator import HelperFileOutputGenerator
+ from generators.vulkaninfo_generator import VulkanInfoGenerator
+
+ # These set fields that are needed by both OutputGenerator and BaseGenerator,
+ # but are uniform and don't need to be set at a per-generated file level
+ from base_generator import (SetTargetApiName, SetMergedApiNames)
+ SetTargetApiName(api)
+
+ # Generated directory and dispatch table helper file name may be API specific (e.g. Vulkan SC)
+ mock_icd_generated_directory = 'icd/generated'
+ vulkaninfo_generated_directory = 'vulkaninfo/generated'
+
+ generators.update({
+ 'vk_typemap_helper.h': {
+ 'generator' : HelperFileOutputGenerator,
+ 'genCombined': False,
+ 'directory' : mock_icd_generated_directory,
+ },
+ 'function_declarations.h': {
+ 'generator' : MockICDOutputGenerator,
+ 'genCombined': False,
+ 'directory' : mock_icd_generated_directory,
+ },
+ 'function_definitions.h': {
+ 'generator' : MockICDOutputGenerator,
+ 'genCombined': False,
+ 'directory' : mock_icd_generated_directory,
+ },
+ 'vulkaninfo.hpp': {
+ 'generator' : VulkanInfoGenerator,
+ 'genCombined': False,
+ 'directory' : vulkaninfo_generated_directory,
+ },
+ })
+
+ unknownTargets = [x for x in (targetFilter if targetFilter else []) if x not in generators.keys()]
+ if unknownTargets:
+ print(f'ERROR: No generator options for unknown target(s): {", ".join(unknownTargets)}', file=sys.stderr)
+ return 1
+
+ # Filter if --target is passed in
+ targets = [x for x in generators.keys() if not targetFilter or x in targetFilter]
+
+ for index, target in enumerate(targets, start=1):
+ print(f'[{index}|{len(targets)}] Generating {target}')
+
+ # First grab a class constructor object and create an instance
+ generator = generators[target]['generator']
+ gen = generator()
+
+ # This code and the 'genCombined' generator metadata is used by downstream
+ # users to generate code with all Vulkan APIs merged into the target API variant
+ # (e.g. Vulkan SC) when needed. The constructed apiList is also used to filter
+ # out non-applicable extensions later below.
+ apiList = [api]
+ if api != 'vulkan' and generators[target]['genCombined']:
+ SetMergedApiNames('vulkan')
+ apiList.append('vulkan')
+ else:
+ SetMergedApiNames(None)
+
+ # For people who want to generate all the files in a single director
+ if flatOutput:
+ outDirectory = os.path.abspath(os.path.join(directory))
+ else:
+ outDirectory = os.path.abspath(os.path.join(directory, generators[target]['directory']))
+
+ options = BaseGeneratorOptions(
+ customFileName = target,
+ customDirectory = outDirectory)
+
+ if not os.path.exists(outDirectory):
+ os.makedirs(outDirectory)
+
+ # Create the registry object with the specified generator and generator
+ # options. The options are set before XML loading as they may affect it.
+ reg = Registry(gen, options)
+
+ # Parse the specified registry XML into an ElementTree object
+ tree = ElementTree.parse(registry)
+
+ # Load the XML tree into the registry object
+ reg.loadElementTree(tree)
+
+ # Set the path to the video registry so that videoStd is available
+ reg.genOpts.videoXmlPath = video_registry
+
+ # Finally, use the output generator to create the requested target
+ reg.apiGen()
+
+ # Run clang-format on the file
+ if has_clang_format and styleFile:
+ common_codegen.RunShellCmd(f'clang-format -i --style=file:{styleFile} {os.path.join(outDirectory, target)}')
+
def main(argv):
+
+ # files to exclude from --verify check
+ verify_exclude = ['.clang-format'] # None currently
+
parser = argparse.ArgumentParser(description='Generate source code for this repository')
+ parser.add_argument('registry', metavar='REGISTRY_PATH', help='path to the Vulkan-Headers registry directory')
parser.add_argument('--api',
default='vulkan',
choices=['vulkan', 'vulkansc'],
help='Specify API name to generate')
parser.add_argument('--generated-version', help='sets the header version used to generate the repo')
- parser.add_argument('registry', metavar='REGISTRY_PATH', help='path to the Vulkan-Headers registry directory')
group = parser.add_mutually_exclusive_group()
+ group.add_argument('--target', nargs='+', help='only generate file names passed in')
group.add_argument('-i', '--incremental', action='store_true', help='only update repo files that change')
group.add_argument('-v', '--verify', action='store_true', help='verify repo files match generator output')
+ group.add_argument('-o', action='store', dest='directory', help='Create target and related files in specified directory')
args = parser.parse_args(argv)
- # output paths and the list of files in the path
- files_to_gen = {str(os.path.join('icd','generated')) : ['vk_typemap_helper.h',
- 'function_definitions.h',
- 'function_declarations.h'],
- str(os.path.join('vulkaninfo','generated')): ['vulkaninfo.hpp']}
-
- #base directory for the source repository
- repo_dir = common_codegen.repo_relative('')
-
- # Update the api_version in the respective json files
- if args.generated_version:
- json_files = []
- json_files.append(common_codegen.repo_relative('icd/VkICD_mock_icd.json.in'))
- for json_file in json_files:
- with open(json_file) as f:
- data = json.load(f)
-
- data["ICD"]["api_version"] = args.generated_version
-
- with open(json_file, mode='w', encoding='utf-8', newline='\n') as f:
- f.write(json.dumps(data, indent=4))
-
- # get directory where generators will run if needed
- if args.verify or args.incremental:
- # generate in temp directory so we can compare or copy later
- temp_obj = tempfile.TemporaryDirectory(prefix='VulkanLoader_generated_source_')
- temp_dir = temp_obj.name
- for path in files_to_gen.keys():
- os.makedirs(os.path.join(temp_dir, path))
+ repo_dir = common_codegen.repo_relative('.')
registry = os.path.abspath(os.path.join(args.registry, 'vk.xml'))
- if not os.path.isfile(registry):
+ video_registry = os.path.abspath(os.path.join(args.registry, 'video.xml'))
+ if not os.path.isfile(registry) and not os.path.isfile(registry):
registry = os.path.abspath(os.path.join(args.registry, 'Vulkan-Headers/registry/vk.xml'))
if not os.path.isfile(registry):
print(f'cannot find vk.xml in {args.registry}')
return -1
+ video_registry = os.path.abspath(os.path.join(args.registry, 'Vulkan-Headers/registry/video.xml'))
+ if not os.path.isfile(video_registry):
+ print(f'{video_registry} does not exist')
+ return -1
+
+ # Need pass style file incase running with --verify and it can't find the file automatically in the temp directory
+ style_file = os.path.join(repo_dir, '.clang-format')
- # run each code generator
- for path, filenames in files_to_gen.items():
- for filename in filenames:
- if args.verify or args.incremental:
- output_path = os.path.join(temp_dir, path)
- else:
- output_path = common_codegen.repo_relative(path)
-
- cmd = [common_codegen.repo_relative(os.path.join('scripts','kvt_genvk.py')),
- '-api', args.api,
- '-registry', registry,
- '-quiet', '-directory', output_path, filename]
- print(' '.join(cmd))
- try:
- if args.verify or args.incremental:
- subprocess.check_call([sys.executable] + cmd, cwd=temp_dir)
- else:
- subprocess.check_call([sys.executable] + cmd, cwd=repo_dir)
-
- except Exception as e:
- print('ERROR:', str(e))
- return 1
+ # get directory where generators will run
+ if args.verify or args.incremental:
+ # generate in temp directory so we can compare or copy later
+ temp_obj = tempfile.TemporaryDirectory(prefix='vulkan_tools_codegen_')
+ temp_dir = temp_obj.name
+ gen_dir = temp_dir
+ elif args.directory:
+ gen_dir = args.directory
+ else:
+ # generate directly in the repo
+ gen_dir = repo_dir
+
+ RunGenerators(api=args.api,registry=registry, video_registry=video_registry, directory=gen_dir, styleFile=style_file, targetFilter=args.target, flatOutput=False)
# optional post-generation steps
if args.verify:
# compare contents of temp dir and repo
temp_files = {}
- for path in files_to_gen.keys():
- temp_files[path] = set()
- temp_files[path].update(set(os.listdir(os.path.join(temp_dir, path))))
-
repo_files = {}
- for path in files_to_gen.keys():
- repo_files[path] = set()
- repo_files[path].update(set(os.listdir(os.path.join(repo_dir, path))) - set(verify_exclude))
+ for details in generators.values():
+ if details['directory'] not in temp_files:
+ temp_files[details['directory']] = set()
+ temp_files[details['directory']].update(set(os.listdir(os.path.join(temp_dir, details['directory']))))
+ if details['directory'] not in repo_files:
+ repo_files[details['directory']] = set()
+ repo_files[details['directory']].update(set(os.listdir(os.path.join(repo_dir, details['directory']))) - set(verify_exclude))
+ # compare contents of temp dir and repo
files_match = True
- for path in files_to_gen.keys():
- for filename in sorted((temp_files[path] | repo_files[path])):
- if filename not in repo_files[path]:
- print('ERROR: Missing repo file', filename)
- files_match = False
- elif filename not in temp_files[path]:
- print('ERROR: Missing generator for', filename)
- files_match = False
- elif not filecmp.cmp(os.path.join(temp_dir, path, filename),
- os.path.join(repo_dir, path, filename),
- shallow=False):
- print('ERROR: Repo files do not match generator output for', filename)
- files_match = False
+ for filename, details in generators.items():
+ if filename not in repo_files[details['directory']]:
+ print('ERROR: Missing repo file', filename)
+ files_match = False
+ elif filename not in temp_files[details['directory']]:
+ print('ERROR: Missing generator for', filename)
+ files_match = False
+ elif not filecmp.cmp(os.path.join(temp_dir, details['directory'], filename),
+ os.path.join(repo_dir, details['directory'], filename),
+ shallow=False):
+ print('ERROR: Repo files do not match generator output for', filename)
+ files_match = False
# return code for test scripts
if files_match:
@@ -143,17 +244,27 @@ def main(argv):
elif args.incremental:
# copy missing or differing files from temp directory to repo
- for path in files_to_gen.keys():
- for filename in os.listdir(os.path.join(temp_dir,path)):
- temp_filename = os.path.join(temp_dir, path, filename)
- repo_filename = os.path.join(repo_dir, path, filename)
- if not os.path.exists(repo_filename) or \
- not filecmp.cmp(temp_filename, repo_filename, shallow=False):
- print('update', repo_filename)
- shutil.copyfile(temp_filename, repo_filename)
+ for filename, details in generators.items():
+ temp_filename = os.path.join(temp_dir, details['directory'], filename)
+ repo_filename = os.path.join(repo_dir, details['directory'], filename)
+ if not os.path.exists(repo_filename) or \
+ not filecmp.cmp(temp_filename, repo_filename, shallow=False):
+ print('update', repo_filename)
+ shutil.copyfile(temp_filename, repo_filename)
# write out the header version used to generate the code to a checked in CMake file
if args.generated_version:
+ json_files = []
+ json_files.append(common_codegen.repo_relative('icd/VkICD_mock_icd.json.in'))
+ for json_file in json_files:
+ with open(json_file) as f:
+ data = json.load(f)
+
+ data["ICD"]["api_version"] = args.generated_version
+
+ with open(json_file, mode='w', encoding='utf-8', newline='\n') as f:
+ f.write(json.dumps(data, indent=4))
+
# Update the CMake project version
with open(common_codegen.repo_relative('CMakeLists.txt'), "r+") as f:
data = f.read()
diff --git a/scripts/generators/mock_icd_generator.py b/scripts/generators/mock_icd_generator.py
index f64f4af0..c78253ce 100644
--- a/scripts/generators/mock_icd_generator.py
+++ b/scripts/generators/mock_icd_generator.py
@@ -25,9 +25,7 @@
# in its initial state. Rather it's intended to be a starting point that
# can be copied and customized to assist in creation of a new layer.
-import os,re,sys
-from generator import *
-from common_codegen import *
+from base_generator import BaseGenerator
CUSTOM_C_INTERCEPTS = {
'vkCreateInstance': '''
@@ -1200,323 +1198,80 @@ CUSTOM_C_INTERCEPTS = {
'''
}
-# MockICDGeneratorOptions - subclass of GeneratorOptions.
-#
-# Adds options used by MockICDOutputGenerator objects during Mock
-# ICD generation.
-#
-# Additional members
-# prefixText - list of strings to prefix generated header with
-# (usually a copyright statement + calling convention macros).
-# protectFile - True if multiple inclusion protection should be
-# generated (based on the filename) around the entire header.
-# protectFeature - True if #ifndef..#endif protection should be
-# generated around a feature interface in the header file.
-# genFuncPointers - True if function pointer typedefs should be
-# generated
-# protectProto - If conditional protection should be generated
-# around prototype declarations, set to either '#ifdef'
-# to require opt-in (#ifdef protectProtoStr) or '#ifndef'
-# to require opt-out (#ifndef protectProtoStr). Otherwise
-# set to None.
-# protectProtoStr - #ifdef/#ifndef symbol to use around prototype
-# declarations, if protectProto is set
-# 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.
-# indentFuncProto - True if prototype declarations should put each
-# parameter on a separate line
-# indentFuncPointer - True if typedefed function pointers should put each
-# parameter on a separate line
-# alignFuncParam - if nonzero and parameters are being put on a
-# separate line, align parameter names at the specified column
-class MockICDGeneratorOptions(GeneratorOptions):
- def __init__(self,
- conventions = None,
- filename = None,
- directory = '.',
- genpath = None,
- apiname = None,
- profile = None,
- versions = '.*',
- emitversions = '.*',
- defaultExtensions = None,
- addExtensions = None,
- removeExtensions = None,
- emitExtensions = None,
- sortProcedure = regSortFeatures,
- prefixText = "",
- genFuncPointers = True,
- protectFile = True,
- protectFeature = True,
- protectProto = None,
- protectProtoStr = None,
- apicall = '',
- apientry = '',
- apientryp = '',
- indentFuncProto = True,
- indentFuncPointer = False,
- alignFuncParam = 0,
- expandEnumerants = True,
- helper_file_type = ''):
- GeneratorOptions.__init__(self,
- conventions = conventions,
- filename = filename,
- directory = directory,
- genpath = genpath,
- apiname = apiname,
- profile = profile,
- versions = versions,
- emitversions = emitversions,
- defaultExtensions = defaultExtensions,
- addExtensions = addExtensions,
- removeExtensions = removeExtensions,
- emitExtensions = emitExtensions,
- sortProcedure = sortProcedure)
- self.prefixText = prefixText
- self.genFuncPointers = genFuncPointers
- self.protectFile = protectFile
- self.protectFeature = protectFeature
- self.protectProto = protectProto
- self.protectProtoStr = protectProtoStr
- self.apicall = apicall
- self.apientry = apientry
- self.apientryp = apientryp
- self.indentFuncProto = indentFuncProto
- self.indentFuncPointer = indentFuncPointer
- self.alignFuncParam = alignFuncParam
-
-# MockICDOutputGenerator - subclass of OutputGenerator.
+# MockICDOutputGenerator
# Generates a mock vulkan ICD.
# This is intended to be a minimal replacement for a vulkan device in order
-# to enable Vulkan Validation testing.
+# to enable testing of Vulkan applications and layers
#
-# ---- methods ----
-# MockOutputGenerator(errFile, warnFile, diagFile) - args as for
-# OutputGenerator. Defines additional internal state.
-# ---- methods overriding base class ----
-# beginFile(genOpts)
-# endFile()
-# beginFeature(interface, emit)
-# endFeature()
-# genType(typeinfo,name)
-# genStruct(typeinfo,name)
-# genGroup(groupinfo,name)
-# genEnum(enuminfo, name)
-# genCmd(cmdinfo)
-class MockICDOutputGenerator(OutputGenerator):
- """Generate specified API interfaces in a specific style, such as a C header"""
- # This is an ordered list of sections in the header file.
- TYPE_SECTIONS = ['include', 'define', 'basetype', 'handle', 'enum',
- 'group', 'bitmask', 'funcpointer', 'struct']
- ALL_SECTIONS = TYPE_SECTIONS + ['command']
- def __init__(self,
- errFile = sys.stderr,
- warnFile = sys.stderr,
- diagFile = sys.stdout):
- OutputGenerator.__init__(self, errFile, warnFile, diagFile)
- # Internal state - accumulators for different inner block text
- self.sections = dict([(section, []) for section in self.ALL_SECTIONS])
- self.intercepts = []
- self.function_declarations = False
-
- # Check if the parameter passed in is a pointer to an array
- def paramIsArray(self, param):
- return param.attrib.get('len') is not None
-
- # Check if the parameter passed in is a pointer
- def paramIsPointer(self, param):
- ispointer = False
- for elem in param:
- if ((elem.tag != 'type') and (elem.tail is not None)) and '*' in elem.tail:
- ispointer = True
- return ispointer
+class MockICDOutputGenerator(BaseGenerator):
+ def __init__(self):
+ BaseGenerator.__init__(self)
- # Check if an object is a non-dispatchable handle
- def isHandleTypeNonDispatchable(self, handletype):
- handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']")
- if handle is not None and handle.find('type').text == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE':
- return True
- else:
- return False
-
- # Check if an object is a dispatchable handle
- def isHandleTypeDispatchable(self, handletype):
- handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']")
- if handle is not None and handle.find('type').text == 'VK_DEFINE_HANDLE':
- return True
- else:
- return False
+ # Ignore extensions that ICDs should not implement or are not safe to report
+ self.ignore_exts = ['VK_EXT_validation_cache', 'VK_KHR_portability_subset']
- # Check that the target API is in the supported list for the extension
- def checkExtensionAPISupport(self, supported):
- return self.genOpts.apiname in supported.split(',')
+ # Dispatchable handles
+ self.dispatchable_handles = ['VkInstance','VkPhysicalDevice', 'VkDevice', 'VkCommandBuffer', 'VkQueue']
- def beginFile(self, genOpts):
- OutputGenerator.beginFile(self, genOpts)
- # C-specific
- #
- # Multiple inclusion protection & C++ namespace.
- if (genOpts.protectFile and self.genOpts.filename == "function_declarations.h"):
- self.function_declarations = True
+ def generate_function_declarations(self, out):
- # User-supplied prefix text, if any (list of strings)
- if (genOpts.prefixText):
- for s in genOpts.prefixText:
- write(s, file=self.outFile)
-
- if self.function_declarations:
- self.newline()
- # Include all of the extensions in ICD except specific ignored ones
- device_exts = []
- instance_exts = []
- # Ignore extensions that ICDs should not implement or are not safe to report
- ignore_exts = ['VK_EXT_validation_cache', 'VK_KHR_portability_subset']
- for ext in self.registry.tree.findall("extensions/extension"):
- if self.checkExtensionAPISupport(ext.attrib['supported']): # Only include API-relevant extensions
- if (ext.attrib['name'] not in ignore_exts):
- # Search for extension version enum
- for enum in ext.findall('require/enum'):
- if enum.get('name', '').endswith('_SPEC_VERSION'):
- ext_version = enum.get('value')
- if (ext.attrib.get('type') == 'instance'):
- instance_exts.append(' {"%s", %s},' % (ext.attrib['name'], ext_version))
- else:
- device_exts.append(' {"%s", %s},' % (ext.attrib['name'], ext_version))
- break
- write('#pragma once\n',file=self.outFile)
- write('#include <stdint.h>',file=self.outFile)
- write('#include <cstring>',file=self.outFile)
- write('#include <string>',file=self.outFile)
- write('#include <unordered_map>',file=self.outFile)
- write('#include <vulkan/vulkan.h>',file=self.outFile)
- self.newline()
- write('namespace vkmock {\n', file=self.outFile)
- write('// Map of instance extension name to version', file=self.outFile)
- write('static const std::unordered_map<std::string, uint32_t> instance_extension_map = {', file=self.outFile)
- write('\n'.join(instance_exts), file=self.outFile)
- write('};', file=self.outFile)
- write('// Map of device extension name to version', file=self.outFile)
- write('static const std::unordered_map<std::string, uint32_t> device_extension_map = {', file=self.outFile)
- write('\n'.join(device_exts), file=self.outFile)
- write('};', file=self.outFile)
- else:
- write('#pragma once\n',file=self.outFile)
- write('#include "mock_icd.h"',file=self.outFile)
- write('#include "function_declarations.h"\n',file=self.outFile)
- write('namespace vkmock {', file=self.outFile)
+ out.append('#include <stdint.h>\n')
+ out.append('#include <cstring>\n')
+ out.append('#include <string>\n')
+ out.append('#include <unordered_map>\n')
+ out.append('#include <vulkan/vulkan.h>\n')
+ out.append('\n')
+ out.append('namespace vkmock {\n')
+ out.append('// Map of instance extension name to version\n')
+ out.append('static const std::unordered_map<std::string, uint32_t> instance_extension_map = {\n')
+ for ext in [x for x in self.vk.extensions.values() if x.instance and x.name not in self.ignore_exts]:
+ if ext.protect:
+ out.append(f'#ifdef {ext.protect}\n')
+ out.append(f' {{"{ext.name}", {ext.specVersion}}},\n')
+ if ext.protect:
+ out.append('#endif\n')
+ out.append('};\n')
+ out.append('// Map of device extension name to version\n')
+ out.append('static const std::unordered_map<std::string, uint32_t> device_extension_map = {\n')
+ for ext in [x for x in self.vk.extensions.values() if x.device and x.name not in self.ignore_exts]:
+ if ext.protect:
+ out.append(f'#ifdef {ext.protect}\n')
+ out.append(f' {{"{ext.name}", {ext.specVersion}}},\n')
+ if ext.protect:
+ out.append('#endif\n')
+ out.append('};\n')
+ current_protect = None
+ for name, cmd in self.vk.commands.items():
+ prepend_newline = '\n'
+ if cmd.protect != current_protect:
+ if current_protect is not None:
+ out.append(f'#endif /* {current_protect} */\n')
+ prepend_newline = ''
+ if current_protect is not None and cmd.protect is not None:
+ out.append('\n')
+ if cmd.protect is not None:
+ out.append(f'#ifdef {cmd.protect}\n')
+ current_protect = cmd.protect
+ out.append(f'{prepend_newline}static {cmd.cPrototype.replace(name, name[2:])}\n')
+ if current_protect is not None:
+ out.append('#endif\n')
- def endFile(self):
- # C-specific
- # Finish C++ namespace
- self.newline()
- if self.function_declarations:
# record intercepted procedures
- write('// Map of all APIs to be intercepted by this layer', file=self.outFile)
- write('static const std::unordered_map<std::string, void*> name_to_funcptr_map = {', file=self.outFile)
- write('\n'.join(self.intercepts), file=self.outFile)
- write('};\n', file=self.outFile)
- write('} // namespace vkmock', file=self.outFile)
- self.newline()
+ out.append('// Map of all APIs to be intercepted by this layer\n')
+ out.append('static const std::unordered_map<std::string, void*> name_to_funcptr_map = {\n')
+ for name, cmd in self.vk.commands.items():
+ if cmd.protect:
+ out.append(f'#ifdef {cmd.protect}\n')
+ out.append(f' {{"{name}", (void*){name[2:]}}},\n')
+ if cmd.protect:
+ out.append('#endif\n')
+ out.append('};\n')
- # Finish processing in superclass
- OutputGenerator.endFile(self)
- def beginFeature(self, interface, emit):
- #write('// starting beginFeature', file=self.outFile)
- # Start processing in superclass
- OutputGenerator.beginFeature(self, interface, emit)
- self.featureExtraProtect = GetFeatureProtect(interface)
- # C-specific
- # Accumulate includes, defines, types, enums, function pointer typedefs,
- # end function prototypes separately for this feature. They're only
- # printed in endFeature().
- self.sections = dict([(section, []) for section in self.ALL_SECTIONS])
- #write('// ending beginFeature', file=self.outFile)
- def endFeature(self):
- # C-specific
- # Actually write the interface to the output file.
- #write('// starting endFeature', file=self.outFile)
- if (self.emit):
- self.newline()
- if (self.genOpts.protectFeature):
- write('#ifndef', self.featureName, file=self.outFile)
- # If type declarations are needed by other features based on
- # this one, it may be necessary to suppress the ExtraProtect,
- # or move it below the 'for section...' loop.
- #write('// endFeature looking at self.featureExtraProtect', file=self.outFile)
- if (self.featureExtraProtect != None):
- write('#ifdef', self.featureExtraProtect, file=self.outFile)
- #write('#define', self.featureName, '1', file=self.outFile)
- for section in self.TYPE_SECTIONS:
- #write('// endFeature writing section'+section, file=self.outFile)
- contents = self.sections[section]
- if contents:
- write('\n'.join(contents), file=self.outFile)
- self.newline()
- #write('// endFeature looking at self.sections[command]', file=self.outFile)
- if (self.sections['command']):
- write('\n'.join(self.sections['command']), end=u'', file=self.outFile)
- self.newline()
- if (self.featureExtraProtect != None):
- write('#endif /*', self.featureExtraProtect, '*/', file=self.outFile)
- if (self.genOpts.protectFeature):
- write('#endif /*', self.featureName, '*/', file=self.outFile)
- # Finish processing in superclass
- OutputGenerator.endFeature(self)
- #write('// ending endFeature', file=self.outFile)
- #
- # Append a definition to the specified section
- def appendSection(self, section, text):
- # self.sections[section].append('SECTION: ' + section + '\n')
- self.sections[section].append(text)
- #
- # Type generation
- def genType(self, typeinfo, name, alias):
- pass
- #
- # 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.
- # Only simple member declarations are supported (no nested
- # structs etc.)
- def genStruct(self, typeinfo, typeName, alias):
- OutputGenerator.genStruct(self, typeinfo, typeName, alias)
- body = 'typedef ' + typeinfo.elem.get('category') + ' ' + typeName + ' {\n'
- # paramdecl = self.makeCParamDecl(typeinfo.elem, self.genOpts.alignFuncParam)
- for member in typeinfo.elem.findall('.//member'):
- body += self.makeCParamDecl(member, self.genOpts.alignFuncParam)
- body += ';\n'
- body += '} ' + typeName + ';\n'
- self.appendSection('struct', body)
- #
- # Group (e.g. C "enum" type) generation.
- # These are concatenated together with other types.
- def genGroup(self, groupinfo, groupName, alias):
- pass
- # Enumerant generation
- # <enum> tags may specify their values in several ways, but are usually
- # just integers.
- def genEnum(self, enuminfo, name, alias):
- pass
- #
- # Command generation
- def genCmd(self, cmdinfo, name, alias):
- decls = self.makeCDecls(cmdinfo.elem)
- if self.function_declarations: # In the header declare all intercepts
- self.appendSection('command', '')
- self.appendSection('command', 'static %s' % (decls[0]))
- if (self.featureExtraProtect != None):
- self.intercepts += [ '#ifdef %s' % self.featureExtraProtect ]
- self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ]
- if (self.featureExtraProtect != None):
- self.intercepts += [ '#endif' ]
- return
+ def generate_function_definitions(self, out):
+ out.append('#include "mock_icd.h"\n')
+ out.append('#include "function_declarations.h"\n')
+ out.append('namespace vkmock {\n')
manual_functions = [
# Include functions here to be intercepted w/ manually implemented function bodies
@@ -1537,99 +1292,127 @@ class MockICDOutputGenerator(OutputGenerator):
'vkEnumerateDeviceLayerProperties',
'vkEnumerateDeviceExtensionProperties',
]
- if name in manual_functions:
- self.appendSection('command', '')
- if name not in CUSTOM_C_INTERCEPTS:
- self.appendSection('command', '// declare only')
- self.appendSection('command', 'static %s' % (decls[0]))
- self.appendSection('command', '// TODO: Implement custom intercept body')
- else:
- self.appendSection('command', 'static %s' % (decls[0][:-1]))
- self.appendSection('command', '{\n%s}' % (CUSTOM_C_INTERCEPTS[name]))
- self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ]
- return
- # record that the function will be intercepted
- if (self.featureExtraProtect != None):
- self.intercepts += [ '#ifdef %s' % self.featureExtraProtect ]
- self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ]
- if (self.featureExtraProtect != None):
- self.intercepts += [ '#endif' ]
+ current_protect = None
+ for name, cmd in self.vk.commands.items():
+ if cmd.protect != current_protect:
+ if current_protect is not None:
+ out.append(f'#endif /* {current_protect} */\n')
+ if current_protect is not None and cmd.protect is not None:
+ out.append('\n')
+ if cmd.protect is not None:
+ out.append(f'#ifdef {cmd.protect}\n')
+ current_protect = cmd.protect
+
+ if name in manual_functions:
+ if name not in CUSTOM_C_INTERCEPTS:
+ out.append(f'static {cmd.cPrototype.replace(name, name[2:])}\n')
+ out.append('// TODO: Implement custom intercept body\n')
+ else:
+ out.append(f'static {cmd.cPrototype[:-1].replace(name, name[2:])}\n')
+ out.append(f'{{{CUSTOM_C_INTERCEPTS[name]}}}\n')
+ continue
+
+ out.append(f'static {cmd.cPrototype[:-1].replace(name, name[2:])}\n')
+ if name in CUSTOM_C_INTERCEPTS:
+ out.append(f'{{{CUSTOM_C_INTERCEPTS[name]}}}\n')
+ continue
- OutputGenerator.genCmd(self, cmdinfo, name, alias)
- #
- self.appendSection('command', '')
- self.appendSection('command', 'static %s' % (decls[0][:-1]))
- if name in CUSTOM_C_INTERCEPTS:
- self.appendSection('command', '{%s}' % (CUSTOM_C_INTERCEPTS[name]))
- return
+ # if the name w/ KHR postfix is in the CUSTOM_C_INTERCEPTS
+ # Call the KHR custom version instead of generating separate code
+ khr_name = name + "KHR"
+ if khr_name in CUSTOM_C_INTERCEPTS:
+ return_string = ''
+ if cmd.returnType != 'void':
+ return_string = 'return '
- # Declare result variable, if any.
- resulttype = cmdinfo.elem.find('proto/type')
- if (resulttype != None and resulttype.text == 'void'):
- resulttype = None
- # if the name w/ KHR postfix is in the CUSTOM_C_INTERCEPTS
- # Call the KHR custom version instead of generating separate code
- khr_name = name + "KHR"
- if khr_name in CUSTOM_C_INTERCEPTS:
- return_string = ''
- if resulttype != None:
- return_string = 'return '
- params = cmdinfo.elem.findall('param/name')
- param_names = []
- for param in params:
- param_names.append(param.text)
- self.appendSection('command', '{\n %s%s(%s);\n}' % (return_string, khr_name[2:], ", ".join(param_names)))
- return
- self.appendSection('command', '{')
+ param_names = []
+ for param in cmd.params:
+ param_names.append(param.name)
+ out.append(f'{{\n {return_string}{khr_name[2:]}({", ".join(param_names)});\n}}\n')
+ continue
+ out.append('{\n')
- api_function_name = cmdinfo.elem.attrib.get('name')
- # GET THE TYPE OF FUNCTION
- if any(api_function_name.startswith(ftxt) for ftxt in ('vkCreate', 'vkAllocate')):
- # Get last param
- last_param = cmdinfo.elem.findall('param')[-1]
- lp_txt = last_param.find('name').text
- lp_len = None
- if ('len' in last_param.attrib):
- lp_len = last_param.attrib['len']
- lp_len = lp_len.replace('::', '->')
- lp_type = last_param.find('type').text
- handle_type = 'dispatchable'
- allocator_txt = 'CreateDispObjHandle()';
- if (self.isHandleTypeNonDispatchable(lp_type)):
- handle_type = 'non-' + handle_type
- allocator_txt = 'global_unique_handle++';
- # Need to lock in both cases
- self.appendSection('command', ' unique_lock_t lock(global_lock);')
- if (lp_len != None):
- #print("%s last params (%s) has len %s" % (handle_type, lp_txt, lp_len))
- self.appendSection('command', ' for (uint32_t i = 0; i < %s; ++i) {' % (lp_len))
- self.appendSection('command', ' %s[i] = (%s)%s;' % (lp_txt, lp_type, allocator_txt))
- self.appendSection('command', ' }')
+ # GET THE TYPE OF FUNCTION
+ if any(name.startswith(ftxt) for ftxt in ('vkCreate', 'vkAllocate')):
+ # Get last param
+ last_param = cmd.params[-1]
+ lp_txt = last_param.name
+ lp_len = None
+ if last_param.length is not None:
+ lp_len = last_param.length
+ lp_len = lp_len.replace('::', '->')
+ lp_type = last_param.type
+ handle_type = 'dispatchable'
+ allocator_txt = 'CreateDispObjHandle()'
+ if lp_type not in self.dispatchable_handles:
+ handle_type = 'non-' + handle_type
+ allocator_txt = 'global_unique_handle++'
+ # Need to lock in both cases
+ out.append(' unique_lock_t lock(global_lock);\n')
+ if lp_len is not None:
+ #print("%s last params (%s) has len %s" % (handle_type, lp_txt, lp_len))
+ out.append(f' for (uint32_t i = 0; i < {lp_len}; ++i) {{\n')
+ out.append(f' {lp_txt}[i] = ({lp_type}){allocator_txt};\n')
+ out.append(' }\n')
+ else:
+ #print("Single %s last param is '%s' w/ type '%s'" % (handle_type, lp_txt, lp_type))
+ if 'AllocateMemory' in name:
+ # Store allocation size in case it's mapped
+ out.append(' allocated_memory_size_map[(VkDeviceMemory)global_unique_handle] = pAllocateInfo->allocationSize;\n')
+ out.append(f' *{lp_txt} = ({lp_type}){allocator_txt};\n')
+ elif True in [ftxt in name for ftxt in ['Destroy', 'Free']]:
+ out.append('//Destroy object\n')
+ if 'FreeMemory' in name:
+ # If the memory is mapped, unmap it
+ out.append(' UnmapMemory(device, memory);\n')
+ # Remove from allocation map
+ out.append(' unique_lock_t lock(global_lock);\n')
+ out.append(' allocated_memory_size_map.erase(memory);\n')
else:
- #print("Single %s last param is '%s' w/ type '%s'" % (handle_type, lp_txt, lp_type))
- if 'AllocateMemory' in api_function_name:
- # Store allocation size in case it's mapped
- self.appendSection('command', ' allocated_memory_size_map[(VkDeviceMemory)global_unique_handle] = pAllocateInfo->allocationSize;')
- self.appendSection('command', ' *%s = (%s)%s;' % (lp_txt, lp_type, allocator_txt))
- elif True in [ftxt in api_function_name for ftxt in ['Destroy', 'Free']]:
- self.appendSection('command', '//Destroy object')
- if 'FreeMemory' in api_function_name:
- # If the memory is mapped, unmap it
- self.appendSection('command', ' UnmapMemory(device, memory);')
- # Remove from allocation map
- self.appendSection('command', ' unique_lock_t lock(global_lock);')
- self.appendSection('command', ' allocated_memory_size_map.erase(memory);')
+ out.append('//Not a CREATE or DESTROY function\n')
+
+ # Return result variable, if any.
+ if cmd.returnType != 'void':
+ if name == 'vkGetEventStatus':
+ out.append(' return VK_EVENT_SET;\n')
+ else:
+ out.append(' return VK_SUCCESS;\n')
+ out.append('}\n')
+ if current_protect is not None:
+ out.append('#endif\n')
+
+ def generate(self):
+ out = []
+ out.append('''/*
+** Copyright (c) 2015-2025 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.
+*/
+
+/*
+** This header is generated from the Khronos Vulkan XML API Registry.
+**
+*/
+
+#pragma once
+''')
+
+ if self.filename == "function_declarations.h":
+ self.generate_function_declarations(out)
else:
- self.appendSection('command', '//Not a CREATE or DESTROY function')
+ self.generate_function_definitions(out)
- # Return result variable, if any.
- if (resulttype != None):
- if api_function_name == 'vkGetEventStatus':
- self.appendSection('command', ' return VK_EVENT_SET;')
- else:
- self.appendSection('command', ' return VK_SUCCESS;')
- self.appendSection('command', '}')
- #
- # override makeProtoName to drop the "vk" prefix
- def makeProtoName(self, name, tail):
- return self.genOpts.apientry + name[2:] + tail
+ out.append('\n')
+ out.append('} // namespace vkmock\n')
+ out.append('\n')
+ self.write(''.join(out))
diff --git a/scripts/generators/vulkan_tools_helper_file_generator.py b/scripts/generators/vulkan_tools_helper_file_generator.py
index b0e486ef..baf3e816 100644
--- a/scripts/generators/vulkan_tools_helper_file_generator.py
+++ b/scripts/generators/vulkan_tools_helper_file_generator.py
@@ -21,1220 +21,143 @@
# Author: Tobin Ehlis <tobine@google.com>
# Author: John Zulauf <jzulauf@lunarg.com>
-import os,re,sys
-import xml.etree.ElementTree as etree
-from generator import *
-from collections import namedtuple
-from common_codegen import *
+from base_generator import BaseGenerator
-#
-# HelperFileOutputGeneratorOptions - subclass of GeneratorOptions.
-class HelperFileOutputGeneratorOptions(GeneratorOptions):
- def __init__(self,
- conventions = None,
- filename = None,
- directory = '.',
- genpath = None,
- apiname = None,
- profile = None,
- versions = '.*',
- emitversions = '.*',
- defaultExtensions = None,
- addExtensions = None,
- removeExtensions = None,
- emitExtensions = None,
- sortProcedure = regSortFeatures,
- prefixText = "",
- genFuncPointers = True,
- protectFile = True,
- protectFeature = True,
- apicall = '',
- apientry = '',
- apientryp = '',
- alignFuncParam = 0,
- library_name = '',
- expandEnumerants = True,
- helper_file_type = ''):
- GeneratorOptions.__init__(self,
- conventions = conventions,
- filename = filename,
- directory = directory,
- genpath = genpath,
- apiname = apiname,
- profile = profile,
- versions = versions,
- emitversions = emitversions,
- defaultExtensions = defaultExtensions,
- addExtensions = addExtensions,
- removeExtensions = removeExtensions,
- emitExtensions = emitExtensions,
- sortProcedure = sortProcedure)
- self.prefixText = prefixText
- self.genFuncPointers = genFuncPointers
- self.protectFile = protectFile
- self.protectFeature = protectFeature
- self.apicall = apicall
- self.apientry = apientry
- self.apientryp = apientryp
- self.alignFuncParam = alignFuncParam
- self.library_name = library_name
- self.helper_file_type = helper_file_type
-#
# HelperFileOutputGenerator - subclass of OutputGenerator. Outputs Vulkan helper files
-class HelperFileOutputGenerator(OutputGenerator):
- """Generate helper file based on XML element attributes"""
- def __init__(self,
- errFile = sys.stderr,
- warnFile = sys.stderr,
- diagFile = sys.stdout):
- OutputGenerator.__init__(self, errFile, warnFile, diagFile)
- # Internal state - accumulators for different inner block text
- self.enum_output = '' # string built up of enum string routines
- # Internal state - accumulators for different inner block text
- self.structNames = [] # List of Vulkan struct typenames
- self.structTypes = dict() # Map of Vulkan struct typename to required VkStructureType
- self.structMembers = [] # List of StructMemberData records for all Vulkan structs
- self.object_types = [] # List of all handle types
- self.object_type_aliases = [] # Aliases to handles types (for handles that were extensions)
- self.debug_report_object_types = [] # Handy copy of debug_report_object_type enum data
- self.core_object_types = [] # Handy copy of core_object_type enum data
- self.device_extension_info = dict() # Dict of device extension name defines and ifdef values
- self.instance_extension_info = dict() # Dict of instance extension name defines and ifdef values
-
- # Named tuples to store struct and command data
- self.StructType = namedtuple('StructType', ['name', 'value'])
- self.CommandParam = namedtuple('CommandParam', ['type', 'name', 'ispointer', 'isstaticarray', 'isconst', 'iscount', 'len', 'extstructs', 'cdecl'])
- self.StructMemberData = namedtuple('StructMemberData', ['name', 'members', 'ifdef_protect'])
-
- self.custom_construct_params = {
- # safe_VkGraphicsPipelineCreateInfo needs to know if subpass has color and\or depth\stencil attachments to use its pointers
- 'VkGraphicsPipelineCreateInfo' :
- ', const bool uses_color_attachment, const bool uses_depthstencil_attachment',
- # safe_VkPipelineViewportStateCreateInfo needs to know if viewport and scissor is dynamic to use its pointers
- 'VkPipelineViewportStateCreateInfo' :
- ', const bool is_dynamic_viewports, const bool is_dynamic_scissors',
- }
- #
- # Called once at the beginning of each run
- def beginFile(self, genOpts):
- OutputGenerator.beginFile(self, genOpts)
- # User-supplied prefix text, if any (list of strings)
- self.helper_file_type = genOpts.helper_file_type
- self.library_name = genOpts.library_name
- # File Comment
- file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n'
- file_comment += '// See vulkan_tools_helper_file_generator.py for modifications\n'
- write(file_comment, file=self.outFile)
- # Copyright Notice
- copyright = ''
- copyright += '\n'
- copyright += '/***************************************************************************\n'
- copyright += ' *\n'
- copyright += ' * Copyright (c) 2015-2017 The Khronos Group Inc.\n'
- copyright += ' * Copyright (c) 2015-2017 Valve Corporation\n'
- copyright += ' * Copyright (c) 2015-2017 LunarG, Inc.\n'
- copyright += ' * Copyright (c) 2015-2017 Google Inc.\n'
- copyright += ' *\n'
- copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n'
- copyright += ' * you may not use this file except in compliance with the License.\n'
- copyright += ' * You may obtain a copy of the License at\n'
- copyright += ' *\n'
- copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n'
- copyright += ' *\n'
- copyright += ' * Unless required by applicable law or agreed to in writing, software\n'
- copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n'
- copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
- copyright += ' * See the License for the specific language governing permissions and\n'
- copyright += ' * limitations under the License.\n'
- copyright += ' *\n'
- copyright += ' * Author: Mark Lobodzinski <mark@lunarg.com>\n'
- copyright += ' * Author: Courtney Goeltzenleuchter <courtneygo@google.com>\n'
- copyright += ' * Author: Tobin Ehlis <tobine@google.com>\n'
- copyright += ' * Author: Chris Forbes <chrisforbes@google.com>\n'
- copyright += ' * Author: John Zulauf<jzulauf@lunarg.com>\n'
- copyright += ' *\n'
- copyright += ' ****************************************************************************/\n'
- write(copyright, file=self.outFile)
- #
- # Write generated file content to output file
- def endFile(self):
- dest_file = ''
- dest_file += self.OutputDestFile()
- # Remove blank lines at EOF
- if dest_file.endswith('\n'):
- dest_file = dest_file[:-1]
- write(dest_file, file=self.outFile);
- # Finish processing in superclass
- OutputGenerator.endFile(self)
- #
- # Override parent class to be notified of the beginning of an extension
- def beginFeature(self, interface, emit):
- # Start processing in superclass
- OutputGenerator.beginFeature(self, interface, emit)
- self.featureExtraProtect = GetFeatureProtect(interface)
-
- if interface.tag != 'extension':
- return
- name = self.featureName
- for enum in interface.findall('require/enum'):
- if enum.get('name', '').endswith('EXTENSION_NAME'):
- name_define = enum.get('name')
- break
- requires = interface.get('requires')
- if requires is not None:
- required_extensions = requires.split(',')
- else:
- required_extensions = list()
- info = { 'define': name_define, 'ifdef':self.featureExtraProtect, 'reqs':required_extensions }
- if interface.get('type') == 'instance':
- self.instance_extension_info[name] = info
- else:
- self.device_extension_info[name] = info
-
- #
- # Override parent class to be notified of the end of an extension
- def endFeature(self):
- # Finish processing in superclass
- OutputGenerator.endFeature(self)
- #
- # Grab group (e.g. C "enum" type) info to output for enum-string conversion helper
- def genGroup(self, groupinfo, groupName, alias):
- OutputGenerator.genGroup(self, groupinfo, groupName, alias)
- groupElem = groupinfo.elem
- # For enum_string_header
- if self.helper_file_type == 'enum_string_header':
- value_set = set()
- for elem in groupElem.findall('enum'):
- if elem.get('supported') != 'disabled' and elem.get('alias') == None:
- value_set.add(elem.get('name'))
- self.enum_output += self.GenerateEnumStringConversion(groupName, value_set)
- elif self.helper_file_type == 'object_types_header':
- if groupName == 'VkDebugReportObjectTypeEXT':
- for elem in groupElem.findall('enum'):
- if elem.get('supported') != 'disabled':
- item_name = elem.get('name')
- self.debug_report_object_types.append(item_name)
- elif groupName == 'VkObjectType':
- for elem in groupElem.findall('enum'):
- if elem.get('supported') != 'disabled':
- item_name = elem.get('name')
- self.core_object_types.append(item_name)
-
- #
- # Called for each type -- if the type is a struct/union, grab the metadata
- def genType(self, typeinfo, name, alias):
- OutputGenerator.genType(self, typeinfo, name, alias)
- typeElem = typeinfo.elem
- # If the type is a struct type, traverse the imbedded <member> tags generating a structure.
- # Otherwise, emit the tag text.
- category = typeElem.get('category')
- if category == 'handle':
- if alias:
- self.object_type_aliases.append((name,alias))
- else:
- self.object_types.append(name)
- elif (category == 'struct' or category == 'union'):
- self.structNames.append(name)
- self.genStruct(typeinfo, name, alias)
- #
- # Check if the parameter passed in is a pointer
- def paramIsPointer(self, param):
- ispointer = False
- for elem in param:
- if ((elem.tag != 'type') and (elem.tail is not None)) and '*' in elem.tail:
- ispointer = True
- return ispointer
- #
- # Check if the parameter passed in is a static array
- def paramIsStaticArray(self, param):
- isstaticarray = 0
- paramname = param.find('name')
- if (paramname.tail is not None) and ('[' in paramname.tail):
- isstaticarray = paramname.tail.count('[')
- return isstaticarray
- #
- # Retrieve the type and name for a parameter
- def getTypeNameTuple(self, param):
- type = ''
- name = ''
- for elem in param:
- if elem.tag == 'type':
- type = noneStr(elem.text)
- elif elem.tag == 'name':
- name = noneStr(elem.text)
- return (type, name)
- #
- # Retrieve the value of the len tag
- def getLen(self, param):
- result = None
- len = param.attrib.get('len')
- if len and len != 'null-terminated':
- # For string arrays, 'len' can look like 'count,null-terminated', indicating that we
- # have a null terminated array of strings. We strip the null-terminated from the
- # 'len' field and only return the parameter specifying the string count
- if 'null-terminated' in len:
- result = len.split(',')[0]
- else:
- result = len
- if 'altlen' in param.attrib:
- # Elements with latexmath 'len' also contain a C equivalent 'altlen' attribute
- # Use indexing operator instead of get() so we fail if the attribute is missing
- result = param.attrib['altlen']
- # Spec has now notation for len attributes, using :: instead of platform specific pointer symbol
- result = str(result).replace('::', '->')
- return result
- #
- # Check if a structure is or contains a dispatchable (dispatchable = True) or
- # non-dispatchable (dispatchable = False) handle
- def TypeContainsObjectHandle(self, handle_type, dispatchable):
- if dispatchable:
- type_key = 'VK_DEFINE_HANDLE'
- else:
- type_key = 'VK_DEFINE_NON_DISPATCHABLE_HANDLE'
- handle = self.registry.tree.find("types/type/[name='" + handle_type + "'][@category='handle']")
- if handle is not None and handle.find('type').text == type_key:
- return True
- # if handle_type is a struct, search its members
- if handle_type in self.structNames:
- member_index = next((i for i, v in enumerate(self.structMembers) if v[0] == handle_type), None)
- if member_index is not None:
- for item in self.structMembers[member_index].members:
- handle = self.registry.tree.find("types/type/[name='" + item.type + "'][@category='handle']")
- if handle is not None and handle.find('type').text == type_key:
- return True
- return False
- #
- # Generate local ready-access data describing Vulkan structures and unions from the XML metadata
- def genStruct(self, typeinfo, typeName, alias):
- OutputGenerator.genStruct(self, typeinfo, typeName, alias)
- members = typeinfo.elem.findall('.//member')
- # Iterate over members once to get length parameters for arrays
- lens = set()
- for member in members:
- len = self.getLen(member)
- if len:
- lens.add(len)
- # Generate member info
- membersInfo = []
- for member in members:
- # Get the member's type and name
- info = self.getTypeNameTuple(member)
- type = info[0]
- name = info[1]
- cdecl = self.makeCParamDecl(member, 1)
- # Process VkStructureType
- if type == 'VkStructureType':
- # Extract the required struct type value from the comments
- # embedded in the original text defining the 'typeinfo' element
- rawXml = etree.tostring(typeinfo.elem).decode('ascii')
- result = re.search(r'VK_STRUCTURE_TYPE_\w+', rawXml)
- if result:
- value = result.group(0)
- # Store the required type value
- self.structTypes[typeName] = self.StructType(name=name, value=value)
- # Store pointer/array/string info
- isstaticarray = self.paramIsStaticArray(member)
- membersInfo.append(self.CommandParam(type=type,
- name=name,
- ispointer=self.paramIsPointer(member),
- isstaticarray=isstaticarray,
- isconst=True if 'const' in cdecl else False,
- iscount=True if name in lens else False,
- len=self.getLen(member),
- extstructs=self.registry.validextensionstructs[typeName] if name == 'pNext' else None,
- cdecl=cdecl))
- self.structMembers.append(self.StructMemberData(name=typeName, members=membersInfo, ifdef_protect=self.featureExtraProtect))
- #
- # Enum_string_header: Create a routine to convert an enumerated value into a string
- def GenerateEnumStringConversion(self, groupName, value_list):
- outstring = '\n'
- outstring += 'static inline const char* string_%s(%s input_value)\n' % (groupName, groupName)
- outstring += '{\n'
- outstring += ' switch ((%s)input_value)\n' % groupName
- outstring += ' {\n'
- for item in value_list:
- outstring += ' case %s:\n' % item
- outstring += ' return "%s";\n' % item
- outstring += ' default:\n'
- outstring += ' return "Unhandled %s";\n' % groupName
- outstring += ' }\n'
- outstring += '}\n'
- return outstring
- #
- # Tack on a helper which, given an index into a VkPhysicalDeviceFeatures structure, will print the corresponding feature name
- def DeIndexPhysDevFeatures(self):
- pdev_members = None
- for name, members, ifdef in self.structMembers:
- if name == 'VkPhysicalDeviceFeatures':
- pdev_members = members
- break
- deindex = '\n'
- deindex += 'static inline const char * GetPhysDevFeatureString(uint32_t index) {\n'
- deindex += ' const char * IndexToPhysDevFeatureString[] = {\n'
- for feature in pdev_members:
- deindex += ' "%s",\n' % feature.name
- deindex += ' };\n\n'
- deindex += ' return IndexToPhysDevFeatureString[index];\n'
- deindex += '}\n'
- return deindex
- #
- # Combine enum string helper header file preamble with body text and return
- def GenerateEnumStringHelperHeader(self):
- enum_string_helper_header = '\n'
- enum_string_helper_header += '#pragma once\n'
- enum_string_helper_header += '#ifdef _WIN32\n'
- enum_string_helper_header += '#pragma warning( disable : 4065 )\n'
- enum_string_helper_header += '#endif\n'
- enum_string_helper_header += '\n'
- enum_string_helper_header += '#include <vulkan/vulkan.h>\n'
- enum_string_helper_header += '\n'
- enum_string_helper_header += self.enum_output
- enum_string_helper_header += self.DeIndexPhysDevFeatures()
- return enum_string_helper_header
- #
- # Helper function for declaring a counter variable only once
- def DeclareCounter(self, string_var, declare_flag):
- if declare_flag == False:
- string_var += ' uint32_t i = 0;\n'
- declare_flag = True
- return string_var, declare_flag
- #
- # Combine safe struct helper header file preamble with body text and return
- def GenerateSafeStructHelperHeader(self):
- safe_struct_helper_header = '\n'
- safe_struct_helper_header += '#pragma once\n'
- safe_struct_helper_header += '#include <vulkan/vulkan.h>\n'
- safe_struct_helper_header += '\n'
- safe_struct_helper_header += self.GenerateSafeStructHeader()
- return safe_struct_helper_header
- #
- # safe_struct header: build function prototypes for header file
- def GenerateSafeStructHeader(self):
- safe_struct_header = ''
- for item in self.structMembers:
- if self.NeedSafeStruct(item) == True:
- safe_struct_header += '\n'
- if item.ifdef_protect != None:
- safe_struct_header += '#ifdef %s\n' % item.ifdef_protect
- safe_struct_header += 'struct safe_%s {\n' % (item.name)
- for member in item.members:
- if member.type in self.structNames:
- member_index = next((i for i, v in enumerate(self.structMembers) if v[0] == member.type), None)
- if member_index is not None and self.NeedSafeStruct(self.structMembers[member_index]) == True:
- if member.ispointer:
- safe_struct_header += ' safe_%s* %s;\n' % (member.type, member.name)
- else:
- safe_struct_header += ' safe_%s %s;\n' % (member.type, member.name)
- continue
- if member.len is not None and (self.TypeContainsObjectHandle(member.type, True) or self.TypeContainsObjectHandle(member.type, False)):
- safe_struct_header += ' %s* %s;\n' % (member.type, member.name)
- else:
- safe_struct_header += '%s;\n' % member.cdecl
- safe_struct_header += ' safe_%s(const %s* in_struct%s);\n' % (item.name, item.name, self.custom_construct_params.get(item.name, ''))
- safe_struct_header += ' safe_%s(const safe_%s& src);\n' % (item.name, item.name)
- safe_struct_header += ' safe_%s& operator=(const safe_%s& src);\n' % (item.name, item.name)
- safe_struct_header += ' safe_%s();\n' % item.name
- safe_struct_header += ' ~safe_%s();\n' % item.name
- safe_struct_header += ' void initialize(const %s* in_struct%s);\n' % (item.name, self.custom_construct_params.get(item.name, ''))
- safe_struct_header += ' void initialize(const safe_%s* src);\n' % (item.name)
- safe_struct_header += ' %s *ptr() { return reinterpret_cast<%s *>(this); }\n' % (item.name, item.name)
- safe_struct_header += ' %s const *ptr() const { return reinterpret_cast<%s const *>(this); }\n' % (item.name, item.name)
- safe_struct_header += '};\n'
- if item.ifdef_protect != None:
- safe_struct_header += '#endif // %s\n' % item.ifdef_protect
- return safe_struct_header
- #
- # Generate extension helper header file
- def GenerateExtensionHelperHeader(self):
-
- V_1_0_instance_extensions_promoted_to_core = [
- 'vk_khr_device_group_creation',
- 'vk_khr_external_fence_capabilities',
- 'vk_khr_external_memory_capabilities',
- 'vk_khr_external_semaphore_capabilities',
- 'vk_khr_get_physical_device_properties_2',
- ]
-
- V_1_0_device_extensions_promoted_to_core = [
- 'vk_khr_16bit_storage',
- 'vk_khr_bind_memory_2',
- 'vk_khr_dedicated_allocation',
- 'vk_khr_descriptor_update_template',
- 'vk_khr_device_group',
- 'vk_khr_external_fence',
- 'vk_khr_external_memory',
- 'vk_khr_external_semaphore',
- 'vk_khr_get_memory_requirements_2',
- 'vk_khr_maintenance1',
- 'vk_khr_maintenance2',
- 'vk_khr_maintenance3',
- 'vk_khr_multiview',
- 'vk_khr_relaxed_block_layout',
- 'vk_khr_sampler_ycbcr_conversion',
- 'vk_khr_shader_draw_parameters',
- 'vk_khr_storage_buffer_storage_class',
- 'vk_khr_variable_pointers',
- ]
-
- output = [
- '',
- '#ifndef VK_EXTENSION_HELPER_H_',
- '#define VK_EXTENSION_HELPER_H_',
- '#include <string>',
- '#include <unordered_map>',
- '#include <utility>',
- '',
- '#include <vulkan/vulkan.h>',
- '']
-
- def guarded(ifdef, value):
- if ifdef is not None:
- return '\n'.join([ '#ifdef %s' % ifdef, value, '#endif' ])
- else:
- return value
-
- for type in ['Instance', 'Device']:
- struct_type = '%sExtensions' % type
- if type == 'Instance':
- extension_dict = self.instance_extension_info
- promoted_ext_list = V_1_0_instance_extensions_promoted_to_core
- struct_decl = 'struct %s {' % struct_type
- instance_struct_type = struct_type
- else:
- extension_dict = self.device_extension_info
- promoted_ext_list = V_1_0_device_extensions_promoted_to_core
- struct_decl = 'struct %s : public %s {' % (struct_type, instance_struct_type)
-
- extension_items = sorted(extension_dict.items())
-
- field_name = { ext_name: re.sub('_extension_name', '', info['define'].lower()) for ext_name, info in extension_items }
- if type == 'Instance':
- instance_field_name = field_name
- instance_extension_dict = extension_dict
- else:
- # Get complete field name and extension data for both Instance and Device extensions
- field_name.update(instance_field_name)
- extension_dict = extension_dict.copy() # Don't modify the self.<dict> we're pointing to
- extension_dict.update(instance_extension_dict)
-
- # Output the data member list
- struct = [struct_decl]
- struct.extend([ ' bool %s{false};' % field_name[ext_name] for ext_name, info in extension_items])
-
- # Construct the extension information map -- mapping name to data member (field), and required extensions
- # The map is contained within a static function member for portability reasons.
- info_type = '%sInfo' % type
- info_map_type = '%sMap' % info_type
- req_type = '%sReq' % type
- req_vec_type = '%sVec' % req_type
- struct.extend([
- '',
- ' struct %s {' % req_type,
- ' const bool %s::* enabled;' % struct_type,
- ' const char *name;',
- ' };',
- ' typedef std::vector<%s> %s;' % (req_type, req_vec_type),
- ' struct %s {' % info_type,
- ' %s(bool %s::* state_, const %s requires_): state(state_), requires(requires_) {}' % ( info_type, struct_type, req_vec_type),
- ' bool %s::* state;' % struct_type,
- ' %s requires;' % req_vec_type,
- ' };',
- '',
- ' typedef std::unordered_map<std::string,%s> %s;' % (info_type, info_map_type),
- ' static const %s &get_info(const char *name) {' %info_type,
- ' static const %s info_map = {' % info_map_type ])
-
- field_format = '&' + struct_type + '::%s'
- req_format = '{' + field_format+ ', %s}'
- req_indent = '\n '
- req_join = ',' + req_indent
- info_format = (' std::make_pair(%s, ' + info_type + '(' + field_format + ', {%s})),')
- def format_info(ext_name, info):
- reqs = req_join.join([req_format % (field_name[req], extension_dict[req]['define']) for req in info['reqs']])
- return info_format % (info['define'], field_name[ext_name], '{%s}' % (req_indent + reqs) if reqs else '')
-
- struct.extend([guarded(info['ifdef'], format_info(ext_name, info)) for ext_name, info in extension_items])
- struct.extend([
- ' };',
- '',
- ' static const %s empty_info {nullptr, %s()};' % (info_type, req_vec_type),
- ' %s::const_iterator info = info_map.find(name);' % info_map_type,
- ' if ( info != info_map.cend()) {',
- ' return info->second;',
- ' }',
- ' return empty_info;',
- ' }',
- ''])
-
- if type == 'Instance':
- struct.extend([
- ' uint32_t NormalizeApiVersion(uint32_t specified_version) {',
- ' uint32_t api_version = (specified_version < VK_API_VERSION_1_1) ? VK_API_VERSION_1_0 : VK_API_VERSION_1_1;',
- ' return api_version;',
- ' }',
- '',
- ' uint32_t InitFromInstanceCreateInfo(uint32_t requested_api_version, const VkInstanceCreateInfo *pCreateInfo) {'])
- else:
- struct.extend([
- ' %s() = default;' % struct_type,
- ' %s(const %s& instance_ext) : %s(instance_ext) {}' % (struct_type, instance_struct_type, instance_struct_type),
- '',
- ' uint32_t InitFromDeviceCreateInfo(const %s *instance_extensions, uint32_t requested_api_version,' % instance_struct_type,
- ' const VkDeviceCreateInfo *pCreateInfo) {',
- ' // Initialize: this to defaults, base class fields to input.',
- ' assert(instance_extensions);',
- ' *this = %s(*instance_extensions);' % struct_type])
-
- struct.extend([
- '',
- ' static const std::vector<const char *> V_1_0_promoted_%s_extensions = {' % type.lower() ])
- struct.extend([' %s_EXTENSION_NAME,' % ext_name.upper() for ext_name in promoted_ext_list])
- struct.extend([
- ' };',
- '',
- ' // Initialize struct data, robust to invalid pCreateInfo',
- ' if (pCreateInfo->ppEnabledExtensionNames) {',
- ' for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {',
- ' if (!pCreateInfo->ppEnabledExtensionNames[i]) continue;',
- ' auto info = get_info(pCreateInfo->ppEnabledExtensionNames[i]);',
- ' if(info.state) this->*(info.state) = true;',
- ' }',
- ' }',
- ' uint32_t api_version = NormalizeApiVersion(requested_api_version);',
- ' if (api_version >= VK_API_VERSION_1_1) {',
- ' for (auto promoted_ext : V_1_0_promoted_%s_extensions) {' % type.lower(),
- ' auto info = get_info(promoted_ext);',
- ' assert(info.state);',
- ' if (info.state) this->*(info.state) = true;',
- ' }',
- ' }',
- ' return api_version;',
- ' }',
- '};'])
-
- # Output reference lists of instance/device extension names
- struct.extend(['', 'static const char * const k%sExtensionNames = ' % type])
- struct.extend([guarded(info['ifdef'], ' %s' % info['define']) for ext_name, info in extension_items])
- struct.extend([';', ''])
- output.extend(struct)
-
- output.extend(['', '#endif // VK_EXTENSION_HELPER_H_'])
- return '\n'.join(output)
- #
- # Combine object types helper header file preamble with body text and return
- def GenerateObjectTypesHelperHeader(self):
- object_types_helper_header = '\n'
- object_types_helper_header += '#pragma once\n'
- object_types_helper_header += '\n'
- object_types_helper_header += '#include <vulkan/vulkan.h>\n\n'
- object_types_helper_header += self.GenerateObjectTypesHeader()
- return object_types_helper_header
- #
- # Object types header: create object enum type header file
- def GenerateObjectTypesHeader(self):
- object_types_header = ''
- object_types_header += '// Object Type enum for validation layer internal object handling\n'
- object_types_header += 'typedef enum VulkanObjectType {\n'
- object_types_header += ' kVulkanObjectTypeUnknown = 0,\n'
- enum_num = 1
- type_list = [];
- enum_entry_map = {}
+class HelperFileOutputGenerator(BaseGenerator):
+ def __init__(self):
+ BaseGenerator.__init__(self)
- # Output enum definition as each handle is processed, saving the names to use for the conversion routine
- for item in self.object_types:
- fixup_name = item[2:]
- enum_entry = 'kVulkanObjectType%s' % fixup_name
- enum_entry_map[item] = enum_entry
- object_types_header += ' ' + enum_entry
- object_types_header += ' = %d,\n' % enum_num
- enum_num += 1
- type_list.append(enum_entry)
- object_types_header += ' kVulkanObjectTypeMax = %d,\n' % enum_num
- object_types_header += ' // Aliases for backwards compatibilty of "promoted" types\n'
- for (name, alias) in self.object_type_aliases:
- fixup_name = name[2:]
- object_types_header += ' kVulkanObjectType{} = {},\n'.format(fixup_name, enum_entry_map[alias])
- object_types_header += '} VulkanObjectType;\n\n'
- # Output name string helper
- object_types_header += '// Array of object name strings for OBJECT_TYPE enum conversion\n'
- object_types_header += 'static const char * const object_string[kVulkanObjectTypeMax] = {\n'
- object_types_header += ' "Unknown",\n'
- for item in self.object_types:
- fixup_name = item[2:]
- object_types_header += ' "%s",\n' % fixup_name
- object_types_header += '};\n'
+ def generate(self):
+ out = []
- # Key creation helper for map comprehensions that convert between k<Name> and VK<Name> symbols
- def to_key(regex, raw_key): return re.search(regex, raw_key).group(1).lower().replace("_","")
-
- # Output a conversion routine from the layer object definitions to the debug report definitions
- # As the VK_DEBUG_REPORT types are not being updated, specify UNKNOWN for unmatched types
- object_types_header += '\n'
- object_types_header += '// Helper array to get Vulkan VK_EXT_debug_report object type enum from the internal layers version\n'
- object_types_header += 'const VkDebugReportObjectTypeEXT get_debug_report_enum[] = {\n'
- object_types_header += ' VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, // kVulkanObjectTypeUnknown\n'
-
- dbg_re = '^VK_DEBUG_REPORT_OBJECT_TYPE_(.*)_EXT$'
- dbg_map = {to_key(dbg_re, dbg) : dbg for dbg in self.debug_report_object_types}
- dbg_default = 'VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT'
- for object_type in type_list:
- vk_object_type = dbg_map.get(object_type.replace("kVulkanObjectType", "").lower(), dbg_default)
- object_types_header += ' %s, // %s\n' % (vk_object_type, object_type)
- object_types_header += '};\n'
-
- # Output a conversion routine from the layer object definitions to the core object type definitions
- # This will intentionally *fail* for unmatched types as the VK_OBJECT_TYPE list should match the kVulkanObjectType list
- object_types_header += '\n'
- object_types_header += '// Helper array to get Official Vulkan VkObjectType enum from the internal layers version\n'
- object_types_header += 'const VkObjectType get_object_type_enum[] = {\n'
- object_types_header += ' VK_OBJECT_TYPE_UNKNOWN, // kVulkanObjectTypeUnknown\n'
-
- vko_re = '^VK_OBJECT_TYPE_(.*)'
- vko_map = {to_key(vko_re, vko) : vko for vko in self.core_object_types}
- for object_type in type_list:
- vk_object_type = vko_map[object_type.replace("kVulkanObjectType", "").lower()]
- object_types_header += ' %s, // %s\n' % (vk_object_type, object_type)
- object_types_header += '};\n'
-
- # Create a function to convert from VkDebugReportObjectTypeEXT to VkObjectType
- object_types_header += '\n'
- object_types_header += '// Helper function to convert from VkDebugReportObjectTypeEXT to VkObjectType\n'
- object_types_header += 'static inline VkObjectType convertDebugReportObjectToCoreObject(VkDebugReportObjectTypeEXT debug_report_obj){\n'
- object_types_header += ' if (debug_report_obj == VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT) {\n'
- object_types_header += ' return VK_OBJECT_TYPE_UNKNOWN;\n'
- for core_object_type in self.core_object_types:
- core_target_type = core_object_type.replace("VK_OBJECT_TYPE_", "").lower()
- core_target_type = core_target_type.replace("_", "")
- for dr_object_type in self.debug_report_object_types:
- dr_target_type = dr_object_type.replace("VK_DEBUG_REPORT_OBJECT_TYPE_", "").lower()
- dr_target_type = dr_target_type[:-4]
- dr_target_type = dr_target_type.replace("_", "")
- if core_target_type == dr_target_type:
- object_types_header += ' } else if (debug_report_obj == %s) {\n' % dr_object_type
- object_types_header += ' return %s;\n' % core_object_type
- break
- object_types_header += ' }\n'
- object_types_header += ' return VK_OBJECT_TYPE_UNKNOWN;\n'
- object_types_header += '}\n'
-
- # Create a function to convert from VkObjectType to VkDebugReportObjectTypeEXT
- object_types_header += '\n'
- object_types_header += '// Helper function to convert from VkDebugReportObjectTypeEXT to VkObjectType\n'
- object_types_header += 'static inline VkDebugReportObjectTypeEXT convertCoreObjectToDebugReportObject(VkObjectType core_report_obj){\n'
- object_types_header += ' if (core_report_obj == VK_OBJECT_TYPE_UNKNOWN) {\n'
- object_types_header += ' return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;\n'
- for core_object_type in self.core_object_types:
- core_target_type = core_object_type.replace("VK_OBJECT_TYPE_", "").lower()
- core_target_type = core_target_type.replace("_", "")
- for dr_object_type in self.debug_report_object_types:
- dr_target_type = dr_object_type.replace("VK_DEBUG_REPORT_OBJECT_TYPE_", "").lower()
- dr_target_type = dr_target_type[:-4]
- dr_target_type = dr_target_type.replace("_", "")
- if core_target_type == dr_target_type:
- object_types_header += ' } else if (core_report_obj == %s) {\n' % core_object_type
- object_types_header += ' return %s;\n' % dr_object_type
- break
- object_types_header += ' }\n'
- object_types_header += ' return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;\n'
- object_types_header += '}\n'
- return object_types_header
- #
- # Determine if a structure needs a safe_struct helper function
- # That is, it has an sType or one of its members is a pointer
- def NeedSafeStruct(self, structure):
- if 'sType' == structure.name:
- return True
- for member in structure.members:
- if member.ispointer == True:
- return True
- return False
- #
- # Combine safe struct helper source file preamble with body text and return
- def GenerateSafeStructHelperSource(self):
- safe_struct_helper_source = '\n'
- safe_struct_helper_source += '#include "vk_safe_struct.h"\n'
- safe_struct_helper_source += '#include <string.h>\n'
- safe_struct_helper_source += '#ifdef VK_USE_PLATFORM_ANDROID_KHR\n'
- safe_struct_helper_source += '#if __ANDROID_API__ < __ANDROID_API_O__\n'
- safe_struct_helper_source += 'struct AHardwareBuffer {};\n'
- safe_struct_helper_source += '#endif\n'
- safe_struct_helper_source += '#endif\n'
-
- safe_struct_helper_source += '\n'
- safe_struct_helper_source += self.GenerateSafeStructSource()
- return safe_struct_helper_source
- #
- # safe_struct source -- create bodies of safe struct helper functions
- def GenerateSafeStructSource(self):
- safe_struct_body = []
- wsi_structs = ['VkXlibSurfaceCreateInfoKHR',
- 'VkXcbSurfaceCreateInfoKHR',
- 'VkWaylandSurfaceCreateInfoKHR',
- 'VkMirSurfaceCreateInfoKHR',
- 'VkAndroidSurfaceCreateInfoKHR',
- 'VkWin32SurfaceCreateInfoKHR'
- ]
- for item in self.structMembers:
- if self.NeedSafeStruct(item) == False:
- continue
- if item.name in wsi_structs:
- continue
- if item.ifdef_protect != None:
- safe_struct_body.append("#ifdef %s\n" % item.ifdef_protect)
- ss_name = "safe_%s" % item.name
- init_list = '' # list of members in struct constructor initializer
- default_init_list = '' # Default constructor just inits ptrs to nullptr in initializer
- init_func_txt = '' # Txt for initialize() function that takes struct ptr and inits members
- construct_txt = '' # Body of constuctor as well as body of initialize() func following init_func_txt
- destruct_txt = ''
-
- custom_construct_txt = {
- # VkWriteDescriptorSet is special case because pointers may be non-null but ignored
- 'VkWriteDescriptorSet' :
- ' switch (descriptorType) {\n'
- ' case VK_DESCRIPTOR_TYPE_SAMPLER:\n'
- ' case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:\n'
- ' case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:\n'
- ' case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:\n'
- ' case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:\n'
- ' if (descriptorCount && in_struct->pImageInfo) {\n'
- ' pImageInfo = new VkDescriptorImageInfo[descriptorCount];\n'
- ' for (uint32_t i=0; i<descriptorCount; ++i) {\n'
- ' pImageInfo[i] = in_struct->pImageInfo[i];\n'
- ' }\n'
- ' }\n'
- ' break;\n'
- ' case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:\n'
- ' case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:\n'
- ' case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:\n'
- ' case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:\n'
- ' if (descriptorCount && in_struct->pBufferInfo) {\n'
- ' pBufferInfo = new VkDescriptorBufferInfo[descriptorCount];\n'
- ' for (uint32_t i=0; i<descriptorCount; ++i) {\n'
- ' pBufferInfo[i] = in_struct->pBufferInfo[i];\n'
- ' }\n'
- ' }\n'
- ' break;\n'
- ' case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:\n'
- ' case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:\n'
- ' if (descriptorCount && in_struct->pTexelBufferView) {\n'
- ' pTexelBufferView = new VkBufferView[descriptorCount];\n'
- ' for (uint32_t i=0; i<descriptorCount; ++i) {\n'
- ' pTexelBufferView[i] = in_struct->pTexelBufferView[i];\n'
- ' }\n'
- ' }\n'
- ' break;\n'
- ' default:\n'
- ' break;\n'
- ' }\n',
- 'VkShaderModuleCreateInfo' :
- ' if (in_struct->pCode) {\n'
- ' pCode = reinterpret_cast<uint32_t *>(new uint8_t[codeSize]);\n'
- ' memcpy((void *)pCode, (void *)in_struct->pCode, codeSize);\n'
- ' }\n',
- # VkGraphicsPipelineCreateInfo is special case because its pointers may be non-null but ignored
- 'VkGraphicsPipelineCreateInfo' :
- ' if (stageCount && in_struct->pStages) {\n'
- ' pStages = new safe_VkPipelineShaderStageCreateInfo[stageCount];\n'
- ' for (uint32_t i=0; i<stageCount; ++i) {\n'
- ' pStages[i].initialize(&in_struct->pStages[i]);\n'
- ' }\n'
- ' }\n'
- ' if (in_struct->pVertexInputState)\n'
- ' pVertexInputState = new safe_VkPipelineVertexInputStateCreateInfo(in_struct->pVertexInputState);\n'
- ' else\n'
- ' pVertexInputState = NULL;\n'
- ' if (in_struct->pInputAssemblyState)\n'
- ' pInputAssemblyState = new safe_VkPipelineInputAssemblyStateCreateInfo(in_struct->pInputAssemblyState);\n'
- ' else\n'
- ' pInputAssemblyState = NULL;\n'
- ' bool has_tessellation_stage = false;\n'
- ' if (stageCount && pStages)\n'
- ' for (uint32_t i=0; i<stageCount && !has_tessellation_stage; ++i)\n'
- ' if (pStages[i].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || pStages[i].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)\n'
- ' has_tessellation_stage = true;\n'
- ' if (in_struct->pTessellationState && has_tessellation_stage)\n'
- ' pTessellationState = new safe_VkPipelineTessellationStateCreateInfo(in_struct->pTessellationState);\n'
- ' else\n'
- ' pTessellationState = NULL; // original pTessellationState pointer ignored\n'
- ' bool has_rasterization = in_struct->pRasterizationState ? !in_struct->pRasterizationState->rasterizerDiscardEnable : false;\n'
- ' if (in_struct->pViewportState && has_rasterization) {\n'
- ' bool is_dynamic_viewports = false;\n'
- ' bool is_dynamic_scissors = false;\n'
- ' if (in_struct->pDynamicState && in_struct->pDynamicState->pDynamicStates) {\n'
- ' for (uint32_t i = 0; i < in_struct->pDynamicState->dynamicStateCount && !is_dynamic_viewports; ++i)\n'
- ' if (in_struct->pDynamicState->pDynamicStates[i] == VK_DYNAMIC_STATE_VIEWPORT)\n'
- ' is_dynamic_viewports = true;\n'
- ' for (uint32_t i = 0; i < in_struct->pDynamicState->dynamicStateCount && !is_dynamic_scissors; ++i)\n'
- ' if (in_struct->pDynamicState->pDynamicStates[i] == VK_DYNAMIC_STATE_SCISSOR)\n'
- ' is_dynamic_scissors = true;\n'
- ' }\n'
- ' pViewportState = new safe_VkPipelineViewportStateCreateInfo(in_struct->pViewportState, is_dynamic_viewports, is_dynamic_scissors);\n'
- ' } else\n'
- ' pViewportState = NULL; // original pViewportState pointer ignored\n'
- ' if (in_struct->pRasterizationState)\n'
- ' pRasterizationState = new safe_VkPipelineRasterizationStateCreateInfo(in_struct->pRasterizationState);\n'
- ' else\n'
- ' pRasterizationState = NULL;\n'
- ' if (in_struct->pMultisampleState && has_rasterization)\n'
- ' pMultisampleState = new safe_VkPipelineMultisampleStateCreateInfo(in_struct->pMultisampleState);\n'
- ' else\n'
- ' pMultisampleState = NULL; // original pMultisampleState pointer ignored\n'
- ' // needs a tracked subpass state uses_depthstencil_attachment\n'
- ' if (in_struct->pDepthStencilState && has_rasterization && uses_depthstencil_attachment)\n'
- ' pDepthStencilState = new safe_VkPipelineDepthStencilStateCreateInfo(in_struct->pDepthStencilState);\n'
- ' else\n'
- ' pDepthStencilState = NULL; // original pDepthStencilState pointer ignored\n'
- ' // needs a tracked subpass state usesColorAttachment\n'
- ' if (in_struct->pColorBlendState && has_rasterization && uses_color_attachment)\n'
- ' pColorBlendState = new safe_VkPipelineColorBlendStateCreateInfo(in_struct->pColorBlendState);\n'
- ' else\n'
- ' pColorBlendState = NULL; // original pColorBlendState pointer ignored\n'
- ' if (in_struct->pDynamicState)\n'
- ' pDynamicState = new safe_VkPipelineDynamicStateCreateInfo(in_struct->pDynamicState);\n'
- ' else\n'
- ' pDynamicState = NULL;\n',
- # VkPipelineViewportStateCreateInfo is special case because its pointers may be non-null but ignored
- 'VkPipelineViewportStateCreateInfo' :
- ' if (in_struct->pViewports && !is_dynamic_viewports) {\n'
- ' pViewports = new VkViewport[in_struct->viewportCount];\n'
- ' memcpy ((void *)pViewports, (void *)in_struct->pViewports, sizeof(VkViewport)*in_struct->viewportCount);\n'
- ' }\n'
- ' else\n'
- ' pViewports = NULL;\n'
- ' if (in_struct->pScissors && !is_dynamic_scissors) {\n'
- ' pScissors = new VkRect2D[in_struct->scissorCount];\n'
- ' memcpy ((void *)pScissors, (void *)in_struct->pScissors, sizeof(VkRect2D)*in_struct->scissorCount);\n'
- ' }\n'
- ' else\n'
- ' pScissors = NULL;\n',
- # VkDescriptorSetLayoutBinding is special case because its pImmutableSamplers pointer may be non-null but ignored
- 'VkDescriptorSetLayoutBinding' :
- ' const bool sampler_type = in_struct->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || in_struct->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;\n'
- ' if (descriptorCount && in_struct->pImmutableSamplers && sampler_type) {\n'
- ' pImmutableSamplers = new VkSampler[descriptorCount];\n'
- ' for (uint32_t i=0; i<descriptorCount; ++i) {\n'
- ' pImmutableSamplers[i] = in_struct->pImmutableSamplers[i];\n'
- ' }\n'
- ' }\n',
- }
-
- custom_copy_txt = {
- # VkGraphicsPipelineCreateInfo is special case because it has custom construct parameters
- 'VkGraphicsPipelineCreateInfo' :
- ' if (stageCount && src.pStages) {\n'
- ' pStages = new safe_VkPipelineShaderStageCreateInfo[stageCount];\n'
- ' for (uint32_t i=0; i<stageCount; ++i) {\n'
- ' pStages[i].initialize(&src.pStages[i]);\n'
- ' }\n'
- ' }\n'
- ' if (src.pVertexInputState)\n'
- ' pVertexInputState = new safe_VkPipelineVertexInputStateCreateInfo(*src.pVertexInputState);\n'
- ' else\n'
- ' pVertexInputState = NULL;\n'
- ' if (src.pInputAssemblyState)\n'
- ' pInputAssemblyState = new safe_VkPipelineInputAssemblyStateCreateInfo(*src.pInputAssemblyState);\n'
- ' else\n'
- ' pInputAssemblyState = NULL;\n'
- ' bool has_tessellation_stage = false;\n'
- ' if (stageCount && pStages)\n'
- ' for (uint32_t i=0; i<stageCount && !has_tessellation_stage; ++i)\n'
- ' if (pStages[i].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || pStages[i].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)\n'
- ' has_tessellation_stage = true;\n'
- ' if (src.pTessellationState && has_tessellation_stage)\n'
- ' pTessellationState = new safe_VkPipelineTessellationStateCreateInfo(*src.pTessellationState);\n'
- ' else\n'
- ' pTessellationState = NULL; // original pTessellationState pointer ignored\n'
- ' bool has_rasterization = src.pRasterizationState ? !src.pRasterizationState->rasterizerDiscardEnable : false;\n'
- ' if (src.pViewportState && has_rasterization) {\n'
- ' pViewportState = new safe_VkPipelineViewportStateCreateInfo(*src.pViewportState);\n'
- ' } else\n'
- ' pViewportState = NULL; // original pViewportState pointer ignored\n'
- ' if (src.pRasterizationState)\n'
- ' pRasterizationState = new safe_VkPipelineRasterizationStateCreateInfo(*src.pRasterizationState);\n'
- ' else\n'
- ' pRasterizationState = NULL;\n'
- ' if (src.pMultisampleState && has_rasterization)\n'
- ' pMultisampleState = new safe_VkPipelineMultisampleStateCreateInfo(*src.pMultisampleState);\n'
- ' else\n'
- ' pMultisampleState = NULL; // original pMultisampleState pointer ignored\n'
- ' if (src.pDepthStencilState && has_rasterization)\n'
- ' pDepthStencilState = new safe_VkPipelineDepthStencilStateCreateInfo(*src.pDepthStencilState);\n'
- ' else\n'
- ' pDepthStencilState = NULL; // original pDepthStencilState pointer ignored\n'
- ' if (src.pColorBlendState && has_rasterization)\n'
- ' pColorBlendState = new safe_VkPipelineColorBlendStateCreateInfo(*src.pColorBlendState);\n'
- ' else\n'
- ' pColorBlendState = NULL; // original pColorBlendState pointer ignored\n'
- ' if (src.pDynamicState)\n'
- ' pDynamicState = new safe_VkPipelineDynamicStateCreateInfo(*src.pDynamicState);\n'
- ' else\n'
- ' pDynamicState = NULL;\n',
- # VkPipelineViewportStateCreateInfo is special case because it has custom construct parameters
- 'VkPipelineViewportStateCreateInfo' :
- ' if (src.pViewports) {\n'
- ' pViewports = new VkViewport[src.viewportCount];\n'
- ' memcpy ((void *)pViewports, (void *)src.pViewports, sizeof(VkViewport)*src.viewportCount);\n'
- ' }\n'
- ' else\n'
- ' pViewports = NULL;\n'
- ' if (src.pScissors) {\n'
- ' pScissors = new VkRect2D[src.scissorCount];\n'
- ' memcpy ((void *)pScissors, (void *)src.pScissors, sizeof(VkRect2D)*src.scissorCount);\n'
- ' }\n'
- ' else\n'
- ' pScissors = NULL;\n',
- }
-
- custom_destruct_txt = {'VkShaderModuleCreateInfo' :
- ' if (pCode)\n'
- ' delete[] reinterpret_cast<const uint8_t *>(pCode);\n' }
-
- for member in item.members:
- m_type = member.type
- if member.type in self.structNames:
- member_index = next((i for i, v in enumerate(self.structMembers) if v[0] == member.type), None)
- if member_index is not None and self.NeedSafeStruct(self.structMembers[member_index]) == True:
- m_type = 'safe_%s' % member.type
- if member.ispointer and 'safe_' not in m_type and self.TypeContainsObjectHandle(member.type, False) == False:
- # Ptr types w/o a safe_struct, for non-null case need to allocate new ptr and copy data in
- if m_type in ['void', 'char']:
- # For these exceptions just copy initial value over for now
- init_list += '\n %s(in_struct->%s),' % (member.name, member.name)
- init_func_txt += ' %s = in_struct->%s;\n' % (member.name, member.name)
- else:
- default_init_list += '\n %s(nullptr),' % (member.name)
- init_list += '\n %s(nullptr),' % (member.name)
- init_func_txt += ' %s = nullptr;\n' % (member.name)
- if 'pNext' != member.name and 'void' not in m_type:
- if not member.isstaticarray and (member.len is None or '/' in member.len):
- construct_txt += ' if (in_struct->%s) {\n' % member.name
- construct_txt += ' %s = new %s(*in_struct->%s);\n' % (member.name, m_type, member.name)
- construct_txt += ' }\n'
- destruct_txt += ' if (%s)\n' % member.name
- destruct_txt += ' delete %s;\n' % member.name
- else:
- construct_txt += ' if (in_struct->%s) {\n' % member.name
- construct_txt += ' %s = new %s[in_struct->%s];\n' % (member.name, m_type, member.len)
- construct_txt += ' memcpy ((void *)%s, (void *)in_struct->%s, sizeof(%s)*in_struct->%s);\n' % (member.name, member.name, m_type, member.len)
- construct_txt += ' }\n'
- destruct_txt += ' if (%s)\n' % member.name
- destruct_txt += ' delete[] %s;\n' % member.name
- elif member.isstaticarray or member.len is not None:
- if member.len is None:
- # Extract length of static array by grabbing val between []
- static_array_size = re.match(r"[^[]*\[([^]]*)\]", member.cdecl)
- construct_txt += ' for (uint32_t i=0; i<%s; ++i) {\n' % static_array_size.group(1)
- construct_txt += ' %s[i] = in_struct->%s[i];\n' % (member.name, member.name)
- construct_txt += ' }\n'
- else:
- # Init array ptr to NULL
- default_init_list += '\n %s(nullptr),' % member.name
- init_list += '\n %s(nullptr),' % member.name
- init_func_txt += ' %s = nullptr;\n' % member.name
- array_element = 'in_struct->%s[i]' % member.name
- if member.type in self.structNames:
- member_index = next((i for i, v in enumerate(self.structMembers) if v[0] == member.type), None)
- if member_index is not None and self.NeedSafeStruct(self.structMembers[member_index]) == True:
- array_element = '%s(&in_struct->safe_%s[i])' % (member.type, member.name)
- construct_txt += ' if (%s && in_struct->%s) {\n' % (member.len, member.name)
- construct_txt += ' %s = new %s[%s];\n' % (member.name, m_type, member.len)
- destruct_txt += ' if (%s)\n' % member.name
- destruct_txt += ' delete[] %s;\n' % member.name
- construct_txt += ' for (uint32_t i=0; i<%s; ++i) {\n' % (member.len)
- if 'safe_' in m_type:
- construct_txt += ' %s[i].initialize(&in_struct->%s[i]);\n' % (member.name, member.name)
- else:
- construct_txt += ' %s[i] = %s;\n' % (member.name, array_element)
- construct_txt += ' }\n'
- construct_txt += ' }\n'
- elif member.ispointer == True:
- construct_txt += ' if (in_struct->%s)\n' % member.name
- construct_txt += ' %s = new %s(in_struct->%s);\n' % (member.name, m_type, member.name)
- construct_txt += ' else\n'
- construct_txt += ' %s = NULL;\n' % member.name
- destruct_txt += ' if (%s)\n' % member.name
- destruct_txt += ' delete %s;\n' % member.name
- elif 'safe_' in m_type:
- init_list += '\n %s(&in_struct->%s),' % (member.name, member.name)
- init_func_txt += ' %s.initialize(&in_struct->%s);\n' % (member.name, member.name)
- else:
- init_list += '\n %s(in_struct->%s),' % (member.name, member.name)
- init_func_txt += ' %s = in_struct->%s;\n' % (member.name, member.name)
- if '' != init_list:
- init_list = init_list[:-1] # hack off final comma
- if item.name in custom_construct_txt:
- construct_txt = custom_construct_txt[item.name]
- if item.name in custom_destruct_txt:
- destruct_txt = custom_destruct_txt[item.name]
- safe_struct_body.append("\n%s::%s(const %s* in_struct%s) :%s\n{\n%s}" % (ss_name, ss_name, item.name, self.custom_construct_params.get(item.name, ''), init_list, construct_txt))
- if '' != default_init_list:
- default_init_list = " :%s" % (default_init_list[:-1])
- safe_struct_body.append("\n%s::%s()%s\n{}" % (ss_name, ss_name, default_init_list))
- # Create slight variation of init and construct txt for copy constructor that takes a src object reference vs. struct ptr
- copy_construct_init = init_func_txt.replace('in_struct->', 'src.')
- copy_construct_txt = construct_txt.replace(' (in_struct->', ' (src.') # Exclude 'if' blocks from next line
- copy_construct_txt = copy_construct_txt.replace('(in_struct->', '(*src.') # Pass object to copy constructors
- copy_construct_txt = copy_construct_txt.replace('in_struct->', 'src.') # Modify remaining struct refs for src object
- if item.name in custom_copy_txt:
- copy_construct_txt = custom_copy_txt[item.name]
- copy_assign_txt = ' if (&src == this) return *this;\n\n' + destruct_txt + '\n' + copy_construct_init + copy_construct_txt + '\n return *this;'
- safe_struct_body.append("\n%s::%s(const %s& src)\n{\n%s%s}" % (ss_name, ss_name, ss_name, copy_construct_init, copy_construct_txt)) # Copy constructor
- safe_struct_body.append("\n%s& %s::operator=(const %s& src)\n{\n%s\n}" % (ss_name, ss_name, ss_name, copy_assign_txt)) # Copy assignment operator
- safe_struct_body.append("\n%s::~%s()\n{\n%s}" % (ss_name, ss_name, destruct_txt))
- safe_struct_body.append("\nvoid %s::initialize(const %s* in_struct%s)\n{\n%s%s}" % (ss_name, item.name, self.custom_construct_params.get(item.name, ''), init_func_txt, construct_txt))
- # Copy initializer uses same txt as copy constructor but has a ptr and not a reference
- init_copy = copy_construct_init.replace('src.', 'src->')
- init_construct = copy_construct_txt.replace('src.', 'src->')
- safe_struct_body.append("\nvoid %s::initialize(const %s* src)\n{\n%s%s}" % (ss_name, ss_name, init_copy, init_construct))
- if item.ifdef_protect != None:
- safe_struct_body.append("#endif // %s\n" % item.ifdef_protect)
- return "\n".join(safe_struct_body)
- #
- # Generate the type map
- def GenerateTypeMapHelperHeader(self):
- prefix = 'Lvl'
- fprefix = 'lvl_'
- typemap = prefix + 'TypeMap'
- idmap = prefix + 'STypeMap'
- type_member = 'Type'
- id_member = 'kSType'
- id_decl = 'static const VkStructureType '
- generic_header = prefix + 'GenericHeader'
- generic_mod_header = prefix + 'GenericModHeader'
- typename_func = fprefix + 'typename'
- idname_func = fprefix + 'stype_name'
- find_func = fprefix + 'find_in_chain'
- find_mod_func = fprefix + 'find_mod_in_chain'
- init_func = fprefix + 'init_struct'
-
- explanatory_comment = '\n'.join((
- '// These empty generic templates are specialized for each type with sType',
- '// members and for each sType -- providing a two way map between structure',
- '// types and sTypes'))
-
- empty_typemap = 'template <typename T> struct ' + typemap + ' {};'
- typemap_format = 'template <> struct {template}<{typename}> {{\n'
- typemap_format += ' {id_decl}{id_member} = {id_value};\n'
- typemap_format += '}};\n'
+ # File Comment
+ out.append('// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n')
+ out.append('// See vulkan_tools_helper_file_generator.py for modifications\n')
- empty_idmap = 'template <VkStructureType id> struct ' + idmap + ' {};'
- idmap_format = ''.join((
- 'template <> struct {template}<{id_value}> {{\n',
- ' typedef {typename} {typedef};\n',
- '}};\n'))
+ # Copyright Notice
+ out.append('''
+
+/***************************************************************************
+ *
+ * Copyright (c) 2015-2017 The Khronos Group Inc.
+ * Copyright (c) 2015-2017 Valve Corporation
+ * Copyright (c) 2015-2017 LunarG, Inc.
+ * Copyright (c) 2015-2017 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: Mark Lobodzinski <mark@lunarg.com>
+ * Author: Courtney Goeltzenleuchter <courtneygo@google.com>
+ * Author: Tobin Ehlis <tobine@google.com>
+ * Author: Chris Forbes <chrisforbes@google.com>
+ * Author: John Zulauf<jzulauf@lunarg.com>
+ *
+ ****************************************************************************/
+''')
- # Define the utilities (here so any renaming stays consistent), if this grows large, refactor to a fixed .h file
- utilities_format = '\n'.join((
- '// Header "base class" for pNext chain traversal',
- 'struct {header} {{',
- ' VkStructureType sType;',
- ' const {header} *pNext;',
- '}};',
- 'struct {mod_header} {{',
- ' VkStructureType sType;',
- ' {mod_header} *pNext;',
- '}};',
- '',
- '// Find an entry of the given type in the pNext chain',
- 'template <typename T> const T *{find_func}(const void *next) {{',
- ' const {header} *current = reinterpret_cast<const {header} *>(next);',
- ' const T *found = nullptr;',
- ' while (current) {{',
- ' if ({type_map}<T>::{id_member} == current->sType) {{',
- ' found = reinterpret_cast<const T*>(current);',
- ' current = nullptr;',
- ' }} else {{',
- ' current = current->pNext;',
- ' }}',
- ' }}',
- ' return found;',
- '}}',
- '// Find an entry of the given type in the pNext chain',
- 'template <typename T> T *{find_mod_func}(void *next) {{',
- ' {mod_header} *current = reinterpret_cast<{mod_header} *>(next);',
- ' T *found = nullptr;',
- ' while (current) {{',
- ' if ({type_map}<T>::{id_member} == current->sType) {{',
- ' found = reinterpret_cast<T*>(current);',
- ' current = nullptr;',
- ' }} else {{',
- ' current = current->pNext;',
- ' }}',
- ' }}',
- ' return found;',
- '}}',
- '',
- '// Init the header of an sType struct with pNext',
- 'template <typename T> T {init_func}(void *p_next) {{',
- ' T out = {{}};',
- ' out.sType = {type_map}<T>::kSType;',
- ' out.pNext = p_next;',
- ' return out;',
- '}}',
- '',
- '// Init the header of an sType struct',
- 'template <typename T> T {init_func}() {{',
- ' T out = {{}};',
- ' out.sType = {type_map}<T>::kSType;',
- ' return out;',
- '}}',
+ # Generate header
+ out.append('''
+#pragma once
+#include <vulkan/vulkan.h>
- ''))
+// These empty generic templates are specialized for each type with sType
+// members and for each sType -- providing a two way map between structure
+// types and sTypes
- code = []
+template <VkStructureType id> struct LvlSTypeMap {};
+template <typename T> struct LvlTypeMap {};
- # Generate header
- code.append('\n'.join((
- '#pragma once',
- '#include <vulkan/vulkan.h>\n',
- explanatory_comment, '',
- empty_idmap,
- empty_typemap, '')))
+''')
# Generate the specializations for each type and stype
- for item in self.structMembers:
- typename = item.name
- info = self.structTypes.get(typename)
- if not info:
+ for struct in self.vk.structs.values():
+ if struct.sType is None:
continue
- if item.ifdef_protect != None:
- code.append('#ifdef %s' % item.ifdef_protect)
-
- code.append('// Map type {} to id {}'.format(typename, info.value))
- code.append(typemap_format.format(template=typemap, typename=typename, id_value=info.value,
- id_decl=id_decl, id_member=id_member))
- code.append(idmap_format.format(template=idmap, typename=typename, id_value=info.value, typedef=type_member))
-
- if item.ifdef_protect != None:
- code.append('#endif // %s' % item.ifdef_protect)
-
- # Generate utilities for all types
- code.append('\n'.join((
- utilities_format.format(id_member=id_member, id_map=idmap, type_map=typemap,
- type_member=type_member, header=generic_header, mod_header=generic_mod_header,
- typename_func=typename_func, idname_func=idname_func, find_func=find_func,
- find_mod_func=find_mod_func, init_func=init_func), ''
- )))
-
- return "\n".join(code)
+ if struct.protect is not None:
+ out.append(f'#ifdef {struct.protect}\n')
+
+ out.append(f'// Map type {struct.name} to id {struct.sType}\n')
+ out.append(f'template <> struct LvlTypeMap<{struct.name}> {{\n')
+ out.append(f' static const VkStructureType kSType = {struct.sType};\n')
+ out.append('};\n\n')
+
+
+ out.append(f'template <> struct LvlSTypeMap<{struct.sType}> {{\n')
+ out.append(f' typedef {struct.name} Type;\n')
+ out.append('};\n\n')
+
+ if struct.protect is not None:
+ out.append(f'#endif // {struct.protect}\n')
+
+ # Define the utilities (here so any renaming stays consistent), if this grows large, refactor to a fixed .h file
+
+ out.append('''// Header "base class" for pNext chain traversal
+struct LvlGenericHeader {
+ VkStructureType sType;
+ const LvlGenericHeader *pNext;
+};
+struct LvlGenericModHeader {
+ VkStructureType sType;
+ LvlGenericModHeader *pNext;
+};
+
+// Find an entry of the given type in the pNext chain
+template <typename T> const T *lvl_find_in_chain(const void *next) {
+ const LvlGenericHeader *current = reinterpret_cast<const LvlGenericHeader *>(next);
+ const T *found = nullptr;
+ while (current) {
+ if (LvlTypeMap<T>::kSType == current->sType) {
+ found = reinterpret_cast<const T*>(current);
+ current = nullptr;
+ } else {
+ current = current->pNext;
+ }
+ }
+ return found;
+}
+// Find an entry of the given type in the pNext chain
+template <typename T> T *lvl_find_mod_in_chain(void *next) {
+ LvlGenericModHeader *current = reinterpret_cast<LvlGenericModHeader *>(next);
+ T *found = nullptr;
+ while (current) {
+ if (LvlTypeMap<T>::kSType == current->sType) {
+ found = reinterpret_cast<T*>(current);
+ current = nullptr;
+ } else {
+ current = current->pNext;
+ }
+ }
+ return found;
+}
+
+// Init the header of an sType struct with pNext
+template <typename T> T lvl_init_struct(void *p_next) {
+ T out = {};
+ out.sType = LvlTypeMap<T>::kSType;
+ out.pNext = p_next;
+ return out;
+}
+
+// Init the header of an sType struct
+template <typename T> T lvl_init_struct() {
+ T out = {};
+ out.sType = LvlTypeMap<T>::kSType;
+ return out;
+}
+''')
+
+ self.write(''.join(out))
- #
- # Create a helper file and return it as a string
- def OutputDestFile(self):
- if self.helper_file_type == 'enum_string_header':
- return self.GenerateEnumStringHelperHeader()
- elif self.helper_file_type == 'safe_struct_header':
- return self.GenerateSafeStructHelperHeader()
- elif self.helper_file_type == 'safe_struct_source':
- return self.GenerateSafeStructHelperSource()
- elif self.helper_file_type == 'object_types_header':
- return self.GenerateObjectTypesHelperHeader()
- elif self.helper_file_type == 'extension_helper_header':
- return self.GenerateExtensionHelperHeader()
- elif self.helper_file_type == 'typemap_helper_header':
- return self.GenerateTypeMapHelperHeader()
- else:
- return 'Bad Helper File Generator Option %s' % self.helper_file_type
diff --git a/scripts/generators/vulkaninfo_generator.py b/scripts/generators/vulkaninfo_generator.py
index 20e408e4..6843e7eb 100644
--- a/scripts/generators/vulkaninfo_generator.py
+++ b/scripts/generators/vulkaninfo_generator.py
@@ -19,16 +19,9 @@
#
# Author: Charles Giessen <charles@lunarg.com>
-import re
-import os
-import sys
-import copy
-import operator
+from base_generator import BaseGenerator
+
from collections import OrderedDict
-import generator as gen
-from common_codegen import GetFeatureProtect
-from generator import GeneratorOptions, OutputGenerator
-import xml.etree.ElementTree as etree
LICENSE_HEADER = '''
/*
@@ -117,28 +110,24 @@ EXTENSION_CATEGORIES = OrderedDict((
('phys_device_props2',
{'extends': 'VkPhysicalDeviceProperties2',
'type': EXTENSION_TYPE_BOTH,
- 'holder_type': 'VkPhysicalDeviceProperties2',
'print_iterator': True,
'can_show_promoted_structs': True,
'ignore_vendor_exclusion': False}),
('phys_device_mem_props2',
{'extends': 'VkPhysicalDeviceMemoryProperties2',
'type': EXTENSION_TYPE_DEVICE,
- 'holder_type':'VkPhysicalDeviceMemoryProperties2',
'print_iterator': False,
'can_show_promoted_structs': False,
'ignore_vendor_exclusion': False}),
('phys_device_features2',
- {'extends': 'VkPhysicalDeviceFeatures2,VkDeviceCreateInfo',
+ {'extends': 'VkPhysicalDeviceFeatures2',
'type': EXTENSION_TYPE_DEVICE,
- 'holder_type': 'VkPhysicalDeviceFeatures2',
'print_iterator': True,
'can_show_promoted_structs': True,
'ignore_vendor_exclusion': False}),
('surface_capabilities2',
{'extends': 'VkSurfaceCapabilities2KHR',
'type': EXTENSION_TYPE_BOTH,
- 'holder_type': 'VkSurfaceCapabilities2KHR',
'print_iterator': True,
'can_show_promoted_structs': False,
'ignore_vendor_exclusion': False,
@@ -146,421 +135,221 @@ EXTENSION_CATEGORIES = OrderedDict((
('format_properties2',
{'extends': 'VkFormatProperties2',
'type': EXTENSION_TYPE_DEVICE,
- 'holder_type':'VkFormatProperties2',
'print_iterator': True,
'can_show_promoted_structs': False,
'ignore_vendor_exclusion': False}),
('queue_properties2',
{'extends': 'VkQueueFamilyProperties2',
'type': EXTENSION_TYPE_DEVICE,
- 'holder_type': 'VkQueueFamilyProperties2',
'print_iterator': True,
'can_show_promoted_structs': False,
'ignore_vendor_exclusion': False}),
('video_profile_info',
{'extends': 'VkVideoProfileInfoKHR',
'type': EXTENSION_TYPE_DEVICE,
- 'holder_type': 'VkVideoProfileInfoKHR',
'print_iterator': True,
'can_show_promoted_structs': False,
'ignore_vendor_exclusion': True}),
('video_capabilities',
{'extends': 'VkVideoCapabilitiesKHR',
'type': EXTENSION_TYPE_DEVICE,
- 'holder_type': 'VkVideoCapabilitiesKHR',
'print_iterator': True,
'can_show_promoted_structs': False,
'ignore_vendor_exclusion': True,}),
('video_format_properties',
{'extends': 'VkVideoFormatPropertiesKHR',
'type': EXTENSION_TYPE_DEVICE,
- 'holder_type': 'VkVideoFormatPropertiesKHR',
'print_iterator': True,
'can_show_promoted_structs': False,
'ignore_vendor_exclusion': True})
))
-class VulkanInfoGeneratorOptions(GeneratorOptions):
- def __init__(self,
- conventions=None,
- input=None,
- filename=None,
- directory='.',
- genpath = None,
- apiname=None,
- profile=None,
- versions='.*',
- emitversions='.*',
- defaultExtensions=None,
- addExtensions=None,
- removeExtensions=None,
- emitExtensions=None,
- sortProcedure=None,
- prefixText='',
- genFuncPointers=True,
- protectFile=True,
- protectFeature=True,
- protectProto=None,
- protectProtoStr=None,
- apicall='',
- apientry='',
- apientryp='',
- indentFuncProto=True,
- indentFuncPointer=False,
- alignFuncParam=0,
- expandEnumerants=True,
- registryFile='vk.xml'
- ):
- GeneratorOptions.__init__(self,
- conventions = conventions,
- filename = filename,
- directory = directory,
- genpath = genpath,
- apiname = apiname,
- profile = profile,
- versions = versions,
- emitversions = emitversions,
- defaultExtensions = defaultExtensions,
- addExtensions = addExtensions,
- removeExtensions = removeExtensions,
- emitExtensions = emitExtensions,
- sortProcedure = sortProcedure)
- self.input = input
- self.prefixText = prefixText
- self.genFuncPointers = genFuncPointers
- self.protectFile = protectFile
- self.protectFeature = protectFeature
- self.protectProto = protectProto
- self.protectProtoStr = protectProtoStr
- self.apicall = apicall
- self.apientry = apientry
- self.apientryp = apientryp
- self.indentFuncProto = indentFuncProto
- self.indentFuncPointer = indentFuncPointer
- self.alignFuncParam = alignFuncParam
- self.registryFile = registryFile
-
-# VulkanInfoGenerator - subclass of OutputGenerator.
-# Generates a vulkan info output helper function
-
-
-class VulkanInfoGenerator(OutputGenerator):
-
- def __init__(self,
- errFile=sys.stderr,
- warnFile=sys.stderr,
- diagFile=sys.stdout):
- OutputGenerator.__init__(self, errFile, warnFile, diagFile)
-
- self.constants = OrderedDict()
-
- self.types_to_gen = set()
-
- self.extension_sets = OrderedDict()
- for ext_cat in EXTENSION_CATEGORIES.keys():
- self.extension_sets[ext_cat] = set()
-
- self.enums = []
- self.flags = []
- self.bitmasks = []
+class VulkanInfoGenerator(BaseGenerator):
+ def __init__(self):
+ BaseGenerator.__init__(self)
self.format_ranges = []
- self.all_structures = []
- self.aliases = OrderedDict()
-
- self.extFuncs = OrderedDict()
- self.extTypes = OrderedDict()
-
- self.vendor_abbreviations = []
- self.vulkan_versions = []
-
- def beginFile(self, genOpts):
- gen.OutputGenerator.beginFile(self, genOpts)
-
- for node in self.registry.reg.findall('enums'):
- if node.get('name') == 'API Constants':
- for item in node.findall('enum'):
- self.constants[item.get('name')] = item.get('value')
-
- for node in self.registry.reg.find('extensions').findall('extension'):
- ext = VulkanExtension(node)
- for item in ext.vktypes:
- if item not in self.extTypes:
- self.extTypes[item] = []
- self.extTypes[item].append(ext)
- for item in ext.vkfuncs:
- self.extFuncs[item] = ext
- # need list of venders to blacklist vendor extensions
- for tag in self.registry.reg.find('tags'):
- if tag.get('name') not in ['KHR', 'EXT']:
- self.vendor_abbreviations.append('_' + tag.get('name'))
-
- for ver in self.registry.reg.findall('feature'):
- self.vulkan_versions.append(VulkanVersion(ver))
-
- def endFile(self):
+ def generate(self):
self.findFormatRanges()
# gather the types that are needed to generate
types_to_gen = set()
- for s in ENUMS_TO_GEN:
- types_to_gen.add(s)
-
- for f in FLAGS_TO_GEN:
- types_to_gen.add(f)
+ types_to_gen.update(ENUMS_TO_GEN)
+ types_to_gen.update(FLAGS_TO_GEN)
+ types_to_gen.update(STRUCTURES_TO_GEN)
+
+ extension_types = {}
+ for key, ext_info in EXTENSION_CATEGORIES.items():
+ extension_types[key] = []
+
+ for extended_struct in self.vk.structs[ext_info.get('extends')].extendedBy:
+ if ext_info.get('exclude') is not None and extended_struct in ext_info.get('exclude'):
+ continue
+ elif ext_info.get('ignore_vendor_exclusion'):
+ extension_types[key].append(extended_struct)
+ continue
+ vendor_tags = []
+ for extension in self.vk.structs[extended_struct].extensions:
+ vendor_tags.append(extension.split('_')[1])
+ if len(vendor_tags) == 0 or 'KHR' in vendor_tags or 'EXT' in vendor_tags:
+ extension_types[key].append(extended_struct)
+ extension_types[key] = sorted(extension_types[key])
+ types_to_gen.update(extension_types[key])
+
+ # find all the types that need
+ types_to_gen.update(self.findAllTypesToGen(types_to_gen))
- types_to_gen.update(
- GatherTypesToGen(self.all_structures, STRUCTURES_TO_GEN))
- for key, info in EXTENSION_CATEGORIES.items():
- types_to_gen.update(
- GatherTypesToGen(self.all_structures, self.extension_sets[key], info.get('exclude')))
types_to_gen = sorted(types_to_gen)
- names_of_structures_to_gen = set()
- for s in self.all_structures:
- if s.name in types_to_gen:
- names_of_structures_to_gen.add(s.name)
- names_of_structures_to_gen = sorted(names_of_structures_to_gen)
+ comparison_types_to_gen = set()
+ comparison_types_to_gen.update(STRUCT_COMPARISONS_TO_GEN)
+ comparison_types_to_gen.update(self.findAllTypesToGen(comparison_types_to_gen))
+ comparison_types_to_gen = sorted(comparison_types_to_gen)
- structs_to_comp = set()
- for s in STRUCT_COMPARISONS_TO_GEN:
- structs_to_comp.add(s)
- structs_to_comp.update(
- GatherTypesToGen(self.all_structures, STRUCT_COMPARISONS_TO_GEN))
-
- for key, value in self.extension_sets.items():
- self.extension_sets[key] = sorted(value)
-
- self.enums = sorted(self.enums, key=operator.attrgetter('name'))
- self.flags = sorted(self.flags, key=operator.attrgetter('name'))
- self.bitmasks = sorted(self.bitmasks, key=operator.attrgetter('name'))
- self.all_structures = sorted(self.all_structures, key=operator.attrgetter('name'))
# print the types gathered
- out = ''
- out += LICENSE_HEADER + '\n'
- out += '#include "vulkaninfo.h"\n'
- out += '#include "outputprinter.h"\n'
- out += CUSTOM_FORMATTERS
+ out = []
+ out.append(LICENSE_HEADER + '\n')
+ out.append('#include "vulkaninfo.h"\n')
+ out.append('#include "outputprinter.h"\n')
+ out.append(CUSTOM_FORMATTERS)
+
+ out.extend(self.genVideoEnums())
- out += self.genVideoEnums()
+ for enum in (e for e in types_to_gen if e in self.vk.enums):
+ out.extend(self.PrintEnumToString(self.vk.enums[enum]))
+ out.extend(self.PrintEnum(self.vk.enums[enum]))
- for enum in (e for e in self.enums if e.name in types_to_gen):
- out += PrintEnumToString(enum, self)
- out += PrintEnum(enum, self)
+ # Need to go through all flags to find if they or their associated bitmask needs printing
+ # This is because both bitmask and flag types are generated in PrintBitMask
+ for name in (x for x in sorted(self.vk.flags.keys()) if x in types_to_gen or self.vk.flags[x].bitmaskName in types_to_gen):
+ bitmask = self.vk.bitmasks[self.vk.flags[name].bitmaskName]
- for flag in self.flags:
- if flag.name in types_to_gen or flag.enum in types_to_gen:
- for bitmask in (b for b in self.bitmasks if b.name == flag.enum):
- out += PrintBitMask(bitmask, flag.name, self)
+ out.extend(self.PrintBitMask(bitmask, bitmask.flagName))
- if flag.name in FLAG_STRINGS_TO_GEN:
- for bitmask in (b for b in self.bitmasks if b.name == flag.enum):
- out += PrintBitMaskToString(bitmask, flag.name, self)
+ if bitmask.flagName in FLAG_STRINGS_TO_GEN:
+ out.extend(self.PrintBitMaskToString(bitmask, bitmask.flagName))
- for s in (x for x in self.all_structures if x.name in types_to_gen and x.name not in STRUCT_BLACKLIST):
- out += PrintStructure(s)
+ for s in (x for x in types_to_gen if x in self.vk.structs and x not in STRUCT_BLACKLIST):
+ out.extend(self.PrintStructure(self.vk.structs[s]))
for key, value in EXTENSION_CATEGORIES.items():
- out += PrintChainStruct(key, self.extension_sets[key], self.all_structures, value, self.extTypes, self.aliases, self.vulkan_versions)
+ out.extend(self.PrintChainStruct(key, extension_types[key], value))
- for s in (x for x in self.all_structures if x.name in structs_to_comp):
- out += PrintStructComparisonForwardDecl(s)
- for s in (x for x in self.all_structures if x.name in structs_to_comp):
- out += PrintStructComparison(s)
- for s in (x for x in self.all_structures if x.name in STRUCT_SHORT_VERSIONS_TO_GEN):
- out += PrintStructShort(s)
+ for s in (x for x in comparison_types_to_gen if x in self.vk.structs):
+ out.extend(self.PrintStructComparisonForwardDecl(self.vk.structs[s]))
+ for s in (x for x in comparison_types_to_gen if x in self.vk.structs):
+ out.extend(self.PrintStructComparison(self.vk.structs[s]))
+ for s in (x for x in types_to_gen if x in self.vk.structs and x in STRUCT_SHORT_VERSIONS_TO_GEN):
+ out.extend(self.PrintStructShort(self.vk.structs[s]))
- out += 'auto format_ranges = std::array{\n'
+ out.append('auto format_ranges = std::array{\n')
for f in self.format_ranges:
- out += f' FormatRange{{{f.minimum_instance_version}, {f.extension_name if f.extension_name is not None else "nullptr"}, '
- out += f'static_cast<VkFormat>({f.first_format}), static_cast<VkFormat>({f.last_format})}},\n'
- out += '};\n'
+ out.append(f' FormatRange{{{f.minimum_instance_version}, {self.vk.extensions[f.extensions[0]].nameString if len(f.extensions) > 0 else "nullptr"}, ')
+ out.append(f'static_cast<VkFormat>({f.first_format}), static_cast<VkFormat>({f.last_format})}},\n')
+ out.append('};\n')
- out += self.genVideoProfileUtils()
+ out.extend(self.genVideoProfileUtils())
- gen.write(out, file=self.outFile)
+ self.write(''.join(out))
- gen.OutputGenerator.endFile(self)
def genVideoEnums(self):
- # We need to add dumping utilities for enums declared in the video std headers and directly
- # present in the Vulkan API structures. In order to do that we really have no choice but
- # to parse the video.xml and generate the utilities based on the enum types defined there
- videoRegistryFile = self.genOpts.registryFile.replace('vk.xml', 'video.xml')
- if os.path.isfile(videoRegistryFile):
- videoxml = etree.parse(videoRegistryFile)
- else:
- assert False, "Could not find video.xml to generate utilities for video enum types"
- out = ''
- for enum in videoxml.findall("./enums[@name]"):
- enumname = enum.get('name')
- out += f'std::string {enumname}String({enumname} value) {{\n'
- out += ' switch (value) {\n'
- for option in enum.findall("./enum[@name]"):
- name = option.get('name')
+ out = []
+ for enum in self.vk.videoStd.enums.values():
+ out.append(f'std::string {enum.name}String({enum.name} value) {{\n')
+ out.append(' switch (value) {\n')
+ for field in enum.fields:
# Ignore aliases
- if option.get('value') is not None:
- out += f' case {name}: return "{name}";\n'
- out += f' default: return std::string("UNKNOWN_{enumname}_value") + std::to_string(value);\n'
- out += ' }\n}\n'
- out += f'void Dump{enumname}(Printer &p, std::string name, {enumname} value) {{\n'
- out += f' p.PrintKeyString(name, {enumname}String(value));\n}}\n'
+ if field.value is not None:
+ out.append(f' case {field.name}: return "{field.name}";\n')
+ out.append(f' default: return std::string("UNKNOWN_{enum.name}_value") + std::to_string(value);\n')
+ out.append(' }\n}\n')
+ out.append(f'void Dump{enum.name}(Printer &p, std::string name, {enum.name} value) {{\n')
+ out.append(f' p.PrintKeyString(name, {enum.name}String(value));\n}}\n')
return out
- def genVideoProfileUtils(self):
- out = ''
-
- # Parse video codec information from the XML
- videoCodecs = OrderedDict()
- xmlVideoCodecs = self.registry.reg.find("./videocodecs")
- for xmlVideoCodec in xmlVideoCodecs.findall("./videocodec"):
- name = xmlVideoCodec.get('name')
- extend = xmlVideoCodec.get('extend')
- value = xmlVideoCodec.get('value')
- if value is None:
- # Video codec category
- videoCodecs[name] = VulkanVideoCodec(name)
- else:
- # Specific video codec
- videoCodecs[name] = VulkanVideoCodec(name, videoCodecs[extend], value)
- videoCodec = videoCodecs[name]
-
- for xmlVideoProfiles in xmlVideoCodec.findall("./videoprofiles"):
- videoProfileStructName = xmlVideoProfiles.get('struct')
- videoCodec.profileStructs[videoProfileStructName] = VulkanVideoProfileStruct(videoProfileStructName)
- videoProfileStruct = videoCodec.profileStructs[videoProfileStructName]
-
- for xmlVideoProfileMember in xmlVideoProfiles.findall("./videoprofilemember"):
- memberName = xmlVideoProfileMember.get('name')
- videoProfileStruct.members[memberName] = VulkanVideoProfileStructMember(memberName)
- videoProfileStructMember = videoProfileStruct.members[memberName]
-
- for xmlVideoProfile in xmlVideoProfileMember.findall("./videoprofile"):
- videoProfileStructMember.values[xmlVideoProfile.get('value')] = xmlVideoProfile.get('name')
-
- for xmlVideoCapabilities in xmlVideoCodec.findall("./videocapabilities"):
- capabilityStructName = xmlVideoCapabilities.get('struct')
- videoCodec.capabilities[capabilityStructName] = capabilityStructName
-
- for xmlVideoFormat in xmlVideoCodec.findall("./videoformat"):
- videoFormatName = xmlVideoFormat.get('name')
- videoFormatExtend = xmlVideoFormat.get('extend')
- if videoFormatName is not None:
- # This is a new video format category
- videoFormatUsage = xmlVideoFormat.get('usage')
- videoCodec.formats[videoFormatName] = VulkanVideoFormat(videoFormatName, videoFormatUsage)
- videoFormat = videoCodec.formats[videoFormatName]
- elif videoFormatExtend is not None:
- # This is an extension to an already defined video format category
- if videoFormatExtend in videoCodec.formats:
- videoFormat = videoCodec.formats[videoFormatExtend]
- else:
- assert False, f"Video format category '{videoFormatExtend}' not found but it is attempted to be extended"
- else:
- assert False, "'name' or 'extend' is attribute is required for 'videoformat' element"
-
- for xmlVideoFormatProperties in xmlVideoFormat.findall("./videoformatproperties"):
- propertiesStructName = xmlVideoFormatProperties.get('struct')
- videoFormat.properties[propertiesStructName] = propertiesStructName
-
- for xmlVideoFormatRequiredCap in xmlVideoFormat.findall("./videorequirecapabilities"):
- requiredCapStruct = xmlVideoFormatRequiredCap.get('struct')
- requiredCapMember = xmlVideoFormatRequiredCap.get('member')
- requiredCapValue = xmlVideoFormatRequiredCap.get('value')
- videoFormat.requiredCaps.append(VulkanVideoRequiredCapabilities(requiredCapStruct, requiredCapMember, requiredCapValue))
-
- # Collect flag types in a set because we will need to look this up
- flagTypes = set()
- for flagType in self.flags:
- flagTypes.add(flagType.name)
-
- # Utility to get structure definition from structure name
- def GetStructDef(name):
- for s in self.all_structures:
- if s.name == name:
- return s
- assert False, f"Definition for structure '{name}' is missing"
-
- # Utility to get the extension / version precondition of a list of type names
- def GetTypesPrecondition(typelist, indent):
- indent = ' ' * indent
- out = ''
- extEnables = {}
- for typename in typelist:
- for k, elem in self.extTypes.items():
- if k == typename or (typename in self.aliases.keys() and k in self.aliases[typename]):
- for e in elem:
- extEnables[e.extNameStr] = e.type
-
- version = None
- for typename in typelist:
- for v in self.vulkan_versions:
- if typename in v.names:
- if version is not None and (v.major > version.major or (v.major == version.major and v.minor > version.minor)):
- version = v
-
- has_version = version is not None
- has_extNameStr = len(extEnables) > 0 or typename in self.aliases.keys()
- if has_version or has_extNameStr:
- out += f'{indent}if ('
- has_printed_condition = False
- if has_extNameStr:
- for key, value in extEnables.items():
- if has_printed_condition:
- out += f'\n{indent} || '
- else:
- has_printed_condition = True
- if has_version:
- out += '('
- if value == EXTENSION_TYPE_DEVICE:
- out += f'gpu.CheckPhysicalDeviceExtensionIncluded({key})'
- else:
- assert False, 'Should never get here'
- if has_version:
+
+ # Utility to get the extension / version precondition of a list of type names
+ def GetTypesPrecondition(self, typelist, indent):
+ indent = ' ' * indent
+ out = []
+ extEnables = []
+ for typename in typelist:
+ extEnables.extend(self.vk.structs[typename].extensions)
+
+ version = None
+ for typename in typelist:
+ for v in self.vk.versions.values():
+ if typename in v.name:
+ if version is not None and (v.major > version.major or (v.major == version.major and v.minor > version.minor)):
+ version = v
+
+
+ has_version = version is not None
+ has_extNameStr = len(extEnables) > 0
+ if has_version or has_extNameStr:
+ out.append(f'{indent}if (')
+ has_printed_condition = False
+ if has_extNameStr:
+ for ext in extEnables:
if has_printed_condition:
- out += f'\n{indent} || (gpu.api_version >= {version.constant})'
+ out.append(f'\n{indent} || ')
else:
- out += f'gpu.api_version >= {version.constant}'
- out += ') {\n'
- else:
- out = f'{indent}{{\n'
- return out
-
- # Utility to construct a capability prerequisite condition evaluation expression
- def GetRequiredCapsCondition(structName, memberName, memberRef, value):
- condition = ''
- requiredCapStructDef = GetStructDef(structName)
- for member in requiredCapStructDef.members:
- if member.name == memberName:
- if member.typeID in flagTypes:
- # Check that the flags contain all the required values
- def genExpressionFromValue(value):
- return value if value == "" else f"({memberRef} & {value}) != 0"
-
- for char in condition:
- if char in ['(', ')', '+', ',']:
- condition += genExpressionFromValue(value)
- value = ""
- if char == '+':
- # '+' means AND
- condition += ' && '
- elif char == ',':
- # ',' means OR
- condition += ' || '
- else:
- condition += char
- else:
- value += char
- condition += genExpressionFromValue(value)
+ has_printed_condition = True
+ if has_version:
+ out.append('(')
+ if self.vk.extensions[ext].device:
+ out.append(f'gpu.CheckPhysicalDeviceExtensionIncluded({self.vk.extensions[ext].nameString})')
else:
- condition = f'{memberRef} == {value}'
- if condition == '':
- return 'true'
- else:
- return f'({condition})'
+ assert False, 'Should never get here'
+ if has_version:
+ if has_printed_condition:
+ out.append(f'\n{indent} || (gpu.api_version >= {version.nameApi})')
+ else:
+ out.append(f'gpu.api_version >= {version.nameApi}')
+ out.append(') {\n')
+ else:
+ out = f'{indent}{{\n'
+ return out
+
+ # Utility to construct a capability prerequisite condition evaluation expression
+ def GetRequiredCapsCondition(self, structName, memberName, memberRef, value):
+ condition = ''
+ requiredCapStructDef = self.vk.structs[structName]
+ for member in requiredCapStructDef.members:
+ if member.name == memberName:
+ if member.type in self.vk.flags:
+ # Check that the flags contain all the required values
+ def genExpressionFromValue(value):
+ return value if value == "" else f"({memberRef} & {value}) != 0"
+
+ for char in condition:
+ if char in ['(', ')', '+', ',']:
+ condition += genExpressionFromValue(value)
+ value = ""
+ if char == '+':
+ # '+' means AND
+ condition += ' && '
+ elif char == ',':
+ # ',' means OR
+ condition += ' || '
+ else:
+ condition += char
+ else:
+ value += char
+ condition += genExpressionFromValue(value)
+ else:
+ condition = f'{memberRef} == {value}'
+ if condition == '':
+ return 'true'
+ else:
+ return f'({condition})'
+
+ def genVideoProfileUtils(self):
+ out = []
# Generate video format properties comparator
- out += '''
+ out.append('''
bool is_video_format_same(const VkVideoFormatPropertiesKHR &format_a, const VkVideoFormatPropertiesKHR &format_b) {
auto a = reinterpret_cast<const VkBaseInStructure*>(&format_a);
auto b = reinterpret_cast<const VkBaseInStructure*>(&format_b);
@@ -570,19 +359,19 @@ bool is_video_format_same(const VkVideoFormatPropertiesKHR &format_a, const VkVi
// Structure type mismatch (extension structures are expected to be chained in the same order)
same = false;
} else {
- switch (a->sType) {'''
+ switch (a->sType) {''')
if 'VkVideoFormatPropertiesKHR' in self.registry.validextensionstructs:
for extstruct in ['VkVideoFormatPropertiesKHR'] + self.registry.validextensionstructs['VkVideoFormatPropertiesKHR']:
- extstructDef = GetStructDef(extstruct)
- out += f'''
- case {extstructDef.sTypeName}:
+ extstructDef = self.vk.structs[extstruct]
+ out.append(f'''
+ case {extstructDef.sType}:
same = same && memcmp(reinterpret_cast<const char*>(a) + sizeof(VkBaseInStructure),
reinterpret_cast<const char*>(b) + sizeof(VkBaseInStructure),
sizeof({extstruct}) - sizeof(VkBaseInStructure)) == 0;
- break;'''
+ break;''')
- out += '''
+ out.append('''
default:
// Unexpected structure type
same = false;
@@ -594,10 +383,10 @@ bool is_video_format_same(const VkVideoFormatPropertiesKHR &format_a, const VkVi
}
return same;
}
-'''
+''')
# Generate video profile info capture utilities
- out += '''
+ out.append('''
std::vector<std::unique_ptr<AppVideoProfile>> enumerate_supported_video_profiles(AppGpu &gpu) {
std::vector<std::unique_ptr<AppVideoProfile>> result{};
@@ -665,19 +454,19 @@ std::vector<std::unique_ptr<AppVideoProfile>> enumerate_supported_video_profiles
result.push_back(std::move(profile));
}
};
-'''
+''')
# Generate individual video profiles from the video codec metadata
- for videoCodec in videoCodecs.values():
+ for videoCodec in self.vk.videoCodecs.values():
# Ignore video codec categories
if videoCodec.value is None:
continue
- out += '\n'
- out += GetTypesPrecondition(videoCodec.profileStructs, 4)
- out += f'{" " * 8}const std::string codec_name = "{videoCodec.name}";\n'
+ out.append('\n')
+ out.extend(self.GetTypesPrecondition(videoCodec.profiles.keys(), 4))
+ out.append(f'{" " * 8}const std::string codec_name = "{videoCodec.name}";\n')
- out += '''
+ out.append('''
for (auto chroma_subsampling : chroma_subsampling_list) {
for (auto luma_bit_depth : bit_depth_list) {
for (auto chroma_bit_depth : bit_depth_list) {
@@ -687,107 +476,107 @@ std::vector<std::unique_ptr<AppVideoProfile>> enumerate_supported_video_profiles
}
std::string profile_base_name = codec_name + base_format(chroma_subsampling, luma_bit_depth, chroma_bit_depth);
-'''
+''')
# Setup video profile info
- out += f'{" " * 20}VkVideoProfileInfoKHR profile_info{{\n'
- out += f'{" " * 20} VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR,\n'
- out += f'{" " * 20} nullptr,\n'
- out += f'{" " * 20} {videoCodec.value},\n'
- out += f'{" " * 20} chroma_subsampling.value,\n'
- out += f'{" " * 20} luma_bit_depth.value,\n'
- out += f'{" " * 20} chroma_bit_depth.value\n'
- out += f'{" " * 20}}};\n\n'
+ out.append(f'{" " * 20}VkVideoProfileInfoKHR profile_info{{\n')
+ out.append(f'{" " * 20} VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR,\n')
+ out.append(f'{" " * 20} nullptr,\n')
+ out.append(f'{" " * 20} {videoCodec.value},\n')
+ out.append(f'{" " * 20} chroma_subsampling.value,\n')
+ out.append(f'{" " * 20} luma_bit_depth.value,\n')
+ out.append(f'{" " * 20} chroma_bit_depth.value\n')
+ out.append(f'{" " * 20}}};\n\n')
# Setup video profile info chain creation callback
- out += f'{" " * 20}auto create_profile_info_chain = [&](const void **ppnext) -> std::unique_ptr<video_profile_info_chain> {{\n'
- out += f'{" " * 20} auto profile_info_chain = std::make_unique<video_profile_info_chain>();\n'
- for profileStruct in videoCodec.profileStructs:
- structDef = GetStructDef(profileStruct)
- out += AddGuardHeader(structDef)
- out += f'{" " * 24}if (profile_info_chain != nullptr) {{\n'
- out += f'{" " * 28}profile_info_chain->{profileStruct[2:]}.sType = {structDef.sTypeName};\n'
- out += f'{" " * 28}profile_info_chain->{profileStruct[2:]}.pNext = nullptr;\n'
- out += f'{" " * 28}*ppnext = &profile_info_chain->{profileStruct[2:]};\n'
- out += f'{" " * 28}ppnext = &profile_info_chain->{profileStruct[2:]}.pNext;\n'
- out += f'{" " * 24}}}\n'
- if structDef.guard:
- out += f'#else\n{" " * 20}profile_info_chain = nullptr;\n'
- out += AddGuardFooter(structDef)
- out += f'{" " * 20} return profile_info_chain;\n'
- out += f'{" " * 20}}};\n\n'
+ out.append(f'{" " * 20}auto create_profile_info_chain = [&](const void **ppnext) -> std::unique_ptr<video_profile_info_chain> {{\n')
+ out.append(f'{" " * 20} auto profile_info_chain = std::make_unique<video_profile_info_chain>();\n')
+ for profileStruct in videoCodec.profiles:
+ structDef = self.vk.structs[profileStruct]
+ out.append(self.AddGuardHeader(structDef))
+ out.append(f'{" " * 24}if (profile_info_chain != nullptr) {{\n')
+ out.append(f'{" " * 28}profile_info_chain->{profileStruct[2:]}.sType = {structDef.sType};\n')
+ out.append(f'{" " * 28}profile_info_chain->{profileStruct[2:]}.pNext = nullptr;\n')
+ out.append(f'{" " * 28}*ppnext = &profile_info_chain->{profileStruct[2:]};\n')
+ out.append(f'{" " * 28}ppnext = &profile_info_chain->{profileStruct[2:]}.pNext;\n')
+ out.append(f'{" " * 24}}}\n')
+ if structDef.protect:
+ out.append(f'#else\n{" " * 20}profile_info_chain = nullptr;\n')
+ out.append(self.AddGuardFooter(structDef))
+ out.append(f'{" " * 20} return profile_info_chain;\n')
+ out.append(f'{" " * 20}}};\n\n')
# Setup video capabilities chain creation callback
- out += f'{" " * 20}auto create_capabilities_chain = [&](void **ppnext) -> std::unique_ptr<video_capabilities_chain> {{\n'
- out += f'{" " * 20} auto capabilities_chain = std::make_unique<video_capabilities_chain>();\n'
+ out.append(f'{" " * 20}auto create_capabilities_chain = [&](void **ppnext) -> std::unique_ptr<video_capabilities_chain> {{\n')
+ out.append(f'{" " * 20} auto capabilities_chain = std::make_unique<video_capabilities_chain>();\n')
for capabilities in videoCodec.capabilities:
- structDef = GetStructDef(capabilities)
- out += AddGuardHeader(structDef)
- out += f'{" " * 24}if (capabilities_chain != nullptr) {{\n'
- out += GetTypesPrecondition([capabilities], 28)
- out += f'{" " * 32}capabilities_chain->{capabilities[2:]}.sType = {structDef.sTypeName};\n'
- out += f'{" " * 32}capabilities_chain->{capabilities[2:]}.pNext = nullptr;\n'
- out += f'{" " * 32}*ppnext = &capabilities_chain->{capabilities[2:]};\n'
- out += f'{" " * 32}ppnext = &capabilities_chain->{capabilities[2:]}.pNext;\n'
- out += f'{" " * 28}}}\n'
- out += f'{" " * 24}}}\n'
- out += AddGuardFooter(structDef)
- out += f'{" " * 20} return capabilities_chain;\n'
- out += f'{" " * 20}}};\n\n'
+ structDef = self.vk.structs[capabilities]
+ out.append(self.AddGuardHeader(structDef))
+ out.append(f'{" " * 24}if (capabilities_chain != nullptr) {{\n')
+ out.extend(self.GetTypesPrecondition([capabilities], 28))
+ out.append(f'{" " * 32}capabilities_chain->{capabilities[2:]}.sType = {structDef.sType};\n')
+ out.append(f'{" " * 32}capabilities_chain->{capabilities[2:]}.pNext = nullptr;\n')
+ out.append(f'{" " * 32}*ppnext = &capabilities_chain->{capabilities[2:]};\n')
+ out.append(f'{" " * 32}ppnext = &capabilities_chain->{capabilities[2:]}.pNext;\n')
+ out.append(f'{" " * 28}}}\n')
+ out.append(f'{" " * 24}}}\n')
+ out.append(self.AddGuardFooter(structDef))
+ out.append(f'{" " * 20} return capabilities_chain;\n')
+ out.append(f'{" " * 20}}};\n\n')
# Setup video format properties chain creation callbacks
- out += f'{" " * 20}const AppVideoProfile::CreateFormatPropertiesChainCbList create_format_properties_chain_list = {{\n'
+ out.append(f'{" " * 20}const AppVideoProfile::CreateFormatPropertiesChainCbList create_format_properties_chain_list = {{\n')
for format in videoCodec.formats.values():
- out += f'{" " * 24}AppVideoProfile::CreateFormatPropertiesChainCb {{\n'
- out += f'{" " * 28}"{format.name}",\n'
- out += f'{" " * 28}{format.usage.replace("+", " | ")},\n'
+ out.append(f'{" " * 24}AppVideoProfile::CreateFormatPropertiesChainCb {{\n')
+ out.append(f'{" " * 28}"{format.name}",\n')
+ out.append(f'{" " * 28}{format.usage.replace("+", " | ")},\n')
# Callback to check required capabilities
- out += f'{" " * 28}[&](const VkVideoCapabilitiesKHR &capabilities) -> bool {{\n'
- out += f'{" " * 28} bool supported = true;\n'
+ out.append(f'{" " * 28}[&](const VkVideoCapabilitiesKHR &capabilities) -> bool {{\n')
+ out.append(f'{" " * 28} bool supported = true;\n')
for requiredCap in format.requiredCaps:
- structDef = GetStructDef(requiredCap.struct)
- out += AddGuardHeader(structDef)
- out += GetTypesPrecondition([requiredCap.struct], 32)
- out += f'{" " * 32} auto caps = reinterpret_cast<const {requiredCap.struct}*>(find_caps_struct(capabilities, {structDef.sTypeName}));\n'
- out += f'{" " * 32} if (caps != nullptr) {{\n'
- out += f'{" " * 32} supported = supported && {GetRequiredCapsCondition(requiredCap.struct, requiredCap.member, f"caps->{requiredCap.member}", requiredCap.value)};\n'
- out += f'{" " * 32} }} else {{\n'
- out += f'{" " * 32} supported = false;\n'
- out += f'{" " * 32} }}\n'
- out += f'{" " * 32}}} else {{\n'
- out += f'{" " * 32} supported = false;\n'
- out += f'{" " * 32}}}\n'
- if structDef.guard:
- out += f'#else\n{" " * 32}supported = false;\n'
- out += AddGuardFooter(structDef)
- out += f'{" " * 28} return supported;\n'
- out += f'{" " * 28}}},\n'
+ structDef = self.vk.structs[requiredCap.struct]
+ out.append(self.AddGuardHeader(structDef))
+ out.extend(self.GetTypesPrecondition([requiredCap.struct], 32))
+ out.append(f'{" " * 32} auto caps = reinterpret_cast<const {requiredCap.struct}*>(find_caps_struct(capabilities, {structDef.sType}));\n')
+ out.append(f'{" " * 32} if (caps != nullptr) {{\n')
+ out.append(f'{" " * 32} supported = supported && {self.GetRequiredCapsCondition(requiredCap.struct, requiredCap.member, f"caps->{requiredCap.member}", requiredCap.value)};\n')
+ out.append(f'{" " * 32} }} else {{\n')
+ out.append(f'{" " * 32} supported = false;\n')
+ out.append(f'{" " * 32} }}\n')
+ out.append(f'{" " * 32}}} else {{\n')
+ out.append(f'{" " * 32} supported = false;\n')
+ out.append(f'{" " * 32}}}\n')
+ if structDef.protect:
+ out.append(f'#else\n{" " * 32}supported = false;\n')
+ out.append(self.AddGuardFooter(structDef))
+ out.append(f'{" " * 28} return supported;\n')
+ out.append(f'{" " * 28}}},\n')
# Callback to create video format properties chain
- out += f'{" " * 28}[&](void **ppnext) -> std::unique_ptr<video_format_properties_chain> {{\n'
- out += f'{" " * 28} auto format_properties_chain = std::make_unique<video_format_properties_chain>();\n'
+ out.append(f'{" " * 28}[&](void **ppnext) -> std::unique_ptr<video_format_properties_chain> {{\n')
+ out.append(f'{" " * 28} auto format_properties_chain = std::make_unique<video_format_properties_chain>();\n')
for formatProps in format.properties:
- structDef = GetStructDef(formatProps)
- out += AddGuardHeader(structDef)
- out += f'{" " * 32}if (format_properties_chain != nullptr) {{\n'
- out += GetTypesPrecondition([formatProps], 36)
- out += f'{" " * 40}format_properties_chain->{formatProps[2:]}.sType = {structDef.sTypeName};\n'
- out += f'{" " * 40}format_properties_chain->{formatProps[2:]}.pNext = nullptr;\n'
- out += f'{" " * 40}*ppnext = &format_properties_chain->{formatProps[2:]};\n'
- out += f'{" " * 40}ppnext = &format_properties_chain->{formatProps[2:]}.pNext;\n'
- out += f'{" " * 36}}}\n'
- out += f'{" " * 32}}}\n'
- out += AddGuardFooter(structDef)
- out += f'{" " * 28} return format_properties_chain;\n'
- out += f'{" " * 28}}},\n'
-
- out += f'{" " * 24}}},\n'
- out += f'{" " * 20}}};\n\n'
+ structDef = self.vk.structs[formatProps]
+ out.append(self.AddGuardHeader(structDef))
+ out.append(f'{" " * 32}if (format_properties_chain != nullptr) {{\n')
+ out.extend(self.GetTypesPrecondition([formatProps], 36))
+ out.append(f'{" " * 40}format_properties_chain->{formatProps[2:]}.sType = {structDef.sType};\n')
+ out.append(f'{" " * 40}format_properties_chain->{formatProps[2:]}.pNext = nullptr;\n')
+ out.append(f'{" " * 40}*ppnext = &format_properties_chain->{formatProps[2:]};\n')
+ out.append(f'{" " * 40}ppnext = &format_properties_chain->{formatProps[2:]}.pNext;\n')
+ out.append(f'{" " * 36}}}\n')
+ out.append(f'{" " * 32}}}\n')
+ out.append(self.AddGuardFooter(structDef))
+ out.append(f'{" " * 28} return format_properties_chain;\n')
+ out.append(f'{" " * 28}}},\n')
+
+ out.append(f'{" " * 24}}},\n')
+ out.append(f'{" " * 20}}};\n\n')
# Permute profiles for each profile struct member value
profiles = {'': []}
- for profileStruct in videoCodec.profileStructs.values():
+ for profileStruct in videoCodec.profiles.values():
for profileStructMember in profileStruct.members.values():
newProfiles = {}
for profileStructMemberValue, profileStructMemberName in profileStructMember.values.items():
@@ -795,246 +584,144 @@ std::vector<std::unique_ptr<AppVideoProfile>> enumerate_supported_video_profiles
# Only add video profile name suffix to the full descriptive name if not empty to avoid excess whitespace
newProfileName = profileName if profileStructMemberName == '' else f'{profileName} {profileStructMemberName}'
newProfiles[newProfileName] = profile + [{
- "struct": profileStruct.struct,
+ "struct": profileStruct.name,
"member": profileStructMember.name,
"value": profileStructMemberValue
}]
profiles = newProfiles
for profileName, profile in profiles.items():
- out += f'{" " * 20}add_profile(profile_base_name + "{profileName}", profile_info,\n'
- out += f'{" " * 20} create_profile_info_chain, create_capabilities_chain,\n'
- out += f'{" " * 20} create_format_properties_chain_list,\n'
- out += f'{" " * 20} [](AppVideoProfile& profile) {{\n'
- for profileStruct in videoCodec.profileStructs:
- structDef = GetStructDef(profileStruct)
- out += AddGuardHeader(structDef)
+ out.append(f'{" " * 20}add_profile(profile_base_name + "{profileName}", profile_info,\n')
+ out.append(f'{" " * 20} create_profile_info_chain, create_capabilities_chain,\n')
+ out.append(f'{" " * 20} create_format_properties_chain_list,\n')
+ out.append(f'{" " * 20} [](AppVideoProfile& profile) {{\n')
+ for profileStruct in videoCodec.profiles:
+ structDef = self.vk.structs[profileStruct]
+ out.append(self.AddGuardHeader(structDef))
for elem in profile:
if elem['struct'] == profileStruct:
- out += f'{" " * 24}profile.profile_info_chain->{elem["struct"][2:]}.{elem["member"]} = {elem["value"]};\n'
- out += AddGuardFooter(structDef)
- out += f'{" " * 20}}});\n'
+ out.append(f'{" " * 24}profile.profile_info_chain->{elem["struct"][2:]}.{elem["member"]} = {elem["value"]};\n')
+ out.append(self.AddGuardFooter(structDef))
+ out.append(f'{" " * 20}}});\n')
- out += f'{" " * 16}}}\n'
- out += f'{" " * 12}}}\n'
- out += f'{" " * 8}}}\n'
- out += f'{" " * 4}}}\n'
+ out.append(f'{" " * 16}}}\n')
+ out.append(f'{" " * 12}}}\n')
+ out.append(f'{" " * 8}}}\n')
+ out.append(f'{" " * 4}}}\n')
- out += ' return result;\n'
- out += '}\n\n'
+ out.append(' return result;\n')
+ out.append('}\n\n')
return out
- def genCmd(self, cmd, name, alias):
- gen.OutputGenerator.genCmd(self, cmd, name, alias)
- # These are actually constants
- def genEnum(self, enuminfo, name, alias):
- gen.OutputGenerator.genEnum(self, enuminfo, name, alias)
+ # finds all the ranges of formats from core (1.0), core versions (1.1+), and extensions
+ def findFormatRanges(self):
+ min_val = 2**32
+ prev_field = None
+ max_val = 0
+ for f in self.vk.enums['VkFormat'].fields:
+ if f.value is None:
+ continue
+ if prev_field is not None and f.value != prev_field.value + 1:
+ for ext in prev_field.extensions:
+ if self.vk.extensions[ext].promotedTo is not None:
+ self.format_ranges.append(VulkanFormatRange(self.vk.extensions[ext].promotedTo.replace("VK_", "VK_API_"), [], min_val, max_val))
+ break
+ # only bother with the first extension
+ self.format_ranges.append(VulkanFormatRange(0, prev_field.extensions, min_val, max_val))
+ min_val = 2**32
+ max_val = 0
+ min_val = min(min_val, f.value)
+ max_val = max(max_val, f.value)
- # These are actually enums
- def genGroup(self, groupinfo, groupName, alias):
- gen.OutputGenerator.genGroup(self, groupinfo, groupName, alias)
+ prev_field = f
- if alias is not None:
- if alias in self.aliases.keys():
- self.aliases[alias].append(groupName)
- else:
- self.aliases[alias] = [groupName, ]
- return
+ for ext in prev_field.extensions:
+ if self.vk.extensions[ext].promotedTo is not None:
+ self.format_ranges.append(VulkanFormatRange(self.vk.extensions[ext].promotedTo.replace("VK_", "VK_API_"), [], min_val, max_val))
+ break
- if groupinfo.elem.get('type') == 'bitmask':
- self.bitmasks.append(VulkanBitmask(groupinfo.elem))
- elif groupinfo.elem.get('type') == 'enum':
- self.enums.append(VulkanEnum(groupinfo.elem))
+ self.format_ranges.append(VulkanFormatRange(0, prev_field.extensions, min_val, max_val))
- def genType(self, typeinfo, name, alias):
- gen.OutputGenerator.genType(self, typeinfo, name, alias)
+ def findAllTypesToGen(self, initial_type_set):
+ out_set = set()
+ current_set = initial_type_set
+ while len(current_set) > 0:
+ out_set.update(current_set)
+ next_set = set()
- if alias is not None:
- if alias in self.aliases.keys():
- self.aliases[alias].append(name)
- else:
- self.aliases[alias] = [name, ]
- return
-
- if typeinfo.elem.get('category') == 'bitmask':
- self.flags.append(VulkanFlags(typeinfo.elem))
-
- if typeinfo.elem.get('category') == 'struct':
- self.all_structures.append(VulkanStructure(
- name, typeinfo.elem, self.constants, self.extTypes))
-
- is_vendor_type = False
- for vendor in self.vendor_abbreviations:
- for node in typeinfo.elem.findall('member'):
- if node.get('values') is not None:
- if node.get('values').find(vendor) != -1:
- is_vendor_type = True
- break
- if is_vendor_type:
- break
+ for current_item in current_set:
+ if current_item in self.vk.structs:
+ for member in self.vk.structs[current_item].members:
+ if member.type not in out_set and member.name not in NAMES_TO_IGNORE:
+ next_set.add(member.type)
- for key, value in EXTENSION_CATEGORIES.items():
- if str(typeinfo.elem.get('structextends')).find(value.get('extends')) != -1:
- if value.get('exclude') is None or name not in value.get('exclude'):
- if not is_vendor_type or value.get('ignore_vendor_exclusion'):
- self.extension_sets[key].add(name)
+ current_set = next_set
+ return out_set
- # finds all the ranges of formats from core (1.0), core versions (1.1+), and extensions
- def findFormatRanges(self):
- for enums in self.registry.reg.findall('enums'):
- if enums.get('name') == 'VkFormat':
- min_val = 2**32
- max_val = 0
- for enum in enums.findall('enum'):
- if enum.get('value') is None:
- continue
- value = int(enum.get('value'))
- min_val = min(min_val, value)
- max_val = max(max_val, value)
- if min_val < 2**32 and max_val > 0:
- self.format_ranges.append(VulkanFormatRange(0, None, min_val, max_val))
-
- for feature in self.registry.reg.findall('feature'):
- for require in feature.findall('require'):
- comment = require.get('comment')
- original_ext = None
- if comment is not None and comment.find('Promoted from') >= 0:
- # may need tweaking in the future - some ext names aren't just the upper case version
- original_ext = comment.split(' ')[2].upper() + '_EXTENSION_NAME'
- # insert an underscore before numbers in the name define
- original_ext = re.sub(r'([A-Z])(\d+)', r'\1_\2', original_ext)
- min_val = 2**32
- max_val = 0
- for enum in require.findall('enum'):
- if enum.get('extends') == 'VkFormat':
- value = CalcEnumValue(int(enum.get('extnumber')), int(enum.get('offset')))
- min_val = min(min_val, value)
- max_val = max(max_val, value)
- if min_val < 2**32 and max_val > 0:
- self.format_ranges.append(VulkanFormatRange(feature.get('name').replace('_VERSION_', '_API_VERSION_'), None, min_val, max_val))
- # If the formats came from an extension, add a format range for that extension so it'll be printed if the ext is supported but not the core version
- if original_ext is not None:
- self.format_ranges.append(VulkanFormatRange(0, original_ext, min_val, max_val))
-
- for extension in self.registry.reg.find('extensions').findall('extension'):
- if not self.genOpts.apiname in extension.get('supported').split(','):
- continue
+ def AddGuardHeader(self,obj):
+ if obj is not None and obj.protect is not None:
+ return f'#ifdef {obj.protect}\n'
+ else:
+ return ''
+
+
+ def AddGuardFooter(self,obj):
+ if obj is not None and obj.protect is not None:
+ return f'#endif // {obj.protect}\n'
+ else:
+ return ''
+
+ def PrintEnumToString(self,enum):
+ out = []
+ out.append(self.AddGuardHeader(enum))
+ out.append(f'std::string {enum.name}String({enum.name} value) {{\n')
+ out.append(' switch (value) {\n')
+ for v in enum.fields:
+ out.append(f' case ({v.name}): return "{v.name[3:]}";\n')
+ out.append(f' default: return std::string("UNKNOWN_{enum.name}_value") + std::to_string(value);\n')
+ out.append(' }\n}\n')
+ out.append(self.AddGuardFooter(enum))
+ return out
- min_val = 2**32
- max_val = 0
- enum_name_string = ''
- for require in extension.findall('require'):
- for enum in require.findall('enum'):
- if enum.get('value') is not None and enum.get('value').find(extension.get('name')):
- enum_name_string = enum.get('name')
- if enum.get('extends') == 'VkFormat':
- if enum.get('offset') is None:
- continue
- value = CalcEnumValue(int(extension.get('number')), int(enum.get('offset')))
- min_val = min(min_val, value)
- max_val = max(max_val, value)
- if min_val < 2**32 and max_val > 0:
- self.format_ranges.append(VulkanFormatRange(0, enum_name_string, min_val, max_val))
-
-
-
-def GatherTypesToGen(structure_list, structures, exclude = None):
- if exclude is None:
- exclude = []
- types = set()
- for s in structures:
- types.add(s)
- added_stuff = True # repeat until no new types are added
- while added_stuff is True:
- added_stuff = False
- for s in structure_list:
- if s.name in types:
- for m in s.members:
- if m.typeID not in PREDEFINED_TYPES and m.name not in NAMES_TO_IGNORE:
- if m.typeID not in types:
- if s.name not in exclude:
- types.add(m.typeID)
- added_stuff = True
- return types
-
-
-def GetExtension(name, generator):
- if name in generator.extFuncs:
- return generator.extFuncs[name]
- elif name in generator.extTypes:
- return generator.extTypes[name][0]
- else:
- return None
-
-
-def AddGuardHeader(obj):
- if obj is not None and obj.guard is not None:
- return f'#ifdef {obj.guard}\n'
- else:
- return ''
-
-
-def AddGuardFooter(obj):
- if obj is not None and obj.guard is not None:
- return f'#endif // {obj.guard}\n'
- else:
- return ''
-
-def CalcEnumValue(num, offset):
- base = 1000000000
- block_size = 1000
- return base + (num - 1) * block_size + offset
-
-def PrintEnumToString(enum, generator):
- out = ''
- out += AddGuardHeader(GetExtension(enum.name, generator))
- out += f'std::string {enum.name}String({enum.name} value) {{\n'
- out += ' switch (value) {\n'
- for v in enum.options:
- out += f' case ({v.name}): return "{v.name[3:]}";\n'
- out += f' default: return std::string("UNKNOWN_{enum.name}_value") + std::to_string(value);\n'
- out += ' }\n}\n'
- out += AddGuardFooter(GetExtension(enum.name, generator))
- return out
-
-
-def PrintEnum(enum, generator):
- out = ''
- out += AddGuardHeader(GetExtension(enum.name, generator))
- out += f'''void Dump{enum.name}(Printer &p, std::string name, {enum.name} value) {{
+
+ def PrintEnum(self,enum):
+ out = []
+ out.append(self.AddGuardHeader(enum))
+ out.append(f'''void Dump{enum.name}(Printer &p, std::string name, {enum.name} value) {{
if (p.Type() == OutputType::json)
p.PrintKeyString(name, std::string("VK_") + {enum.name}String(value));
else
p.PrintKeyString(name, {enum.name}String(value));
}}
-'''
- out += AddGuardFooter(GetExtension(enum.name, generator))
- return out
-
-
-def PrintGetFlagStrings(name, bitmask):
- out = ''
- out += f'std::vector<const char *> {name}GetStrings({name} value) {{\n'
- out += ' std::vector<const char *> strings;\n'
- # If a bitmask contains a field whose value is zero, we want to support printing the correct bitflag
- # Otherwise, use "None" for when there are not bits set in the bitmask
- if bitmask.options[0].value != 0:
- out += ' if (value == 0) { strings.push_back("None"); return strings; }\n'
- else:
- out += f' if (value == 0) {{ strings.push_back("{bitmask.options[0].name[3:]}"); return strings; }}\n'
- for v in bitmask.options:
- # only check single-bit flags
- if v.value != 0 and (v.value & (v.value - 1)) == 0:
- out += f' if ({v.name} & value) strings.push_back("{v.name[3:]}");\n'
- out += ' return strings;\n}\n'
- return out
-
-
-def PrintFlags(bitmask, name):
- out = f'void Dump{name}(Printer &p, std::string name, {name} value) {{\n'
- out += f''' if (static_cast<{bitmask.name}>(value) == 0) {{
+''')
+ out.append(self.AddGuardFooter(enum))
+ return out
+
+
+ def PrintGetFlagStrings(self,name, bitmask):
+ out = []
+ out.append(f'std::vector<const char *> {name}GetStrings({name} value) {{\n')
+ out.append(' std::vector<const char *> strings;\n')
+ # If a bitmask contains a field whose value is zero, we want to support printing the correct bitflag
+ # Otherwise, use "None" for when there are not bits set in the bitmask
+ if bitmask.flags[0].value != 0:
+ out.append(' if (value == 0) { strings.push_back("None"); return strings; }\n')
+ else:
+ out.append(f' if (value == 0) {{ strings.push_back("{bitmask.flags[0].name[3:]}"); return strings; }}\n')
+ for v in bitmask.flags:
+ # only check single-bit flags
+ if v.value != 0 and (v.value & (v.value - 1)) == 0:
+ out.append(f' if ({v.name} & value) strings.push_back("{v.name[3:]}");\n')
+ out.append(' return strings;\n}\n')
+ return out
+
+
+ def PrintFlags(self, bitmask, name):
+ out = []
+ out.append(f'void Dump{name}(Printer &p, std::string name, {name} value) {{\n')
+ out.append(f''' if (static_cast<{bitmask.name}>(value) == 0) {{
ArrayWrapper arr(p, name, 0);
if (p.Type() != OutputType::json && p.Type() != OutputType::vkconfig_output)
p.SetAsType().PrintString("None");
@@ -1049,12 +736,12 @@ def PrintFlags(bitmask, name):
p.SetAsType().PrintString(str);
}}
}}
-'''
- return out
+''')
+ return out
-def PrintFlagBits(bitmask):
- return f'''void Dump{bitmask.name}(Printer &p, std::string name, {bitmask.name} value) {{
+ def PrintFlagBits(self, bitmask):
+ return [f'''void Dump{bitmask.name}(Printer &p, std::string name, {bitmask.name} value) {{
auto strings = {bitmask.name}GetStrings(value);
if (strings.size() > 0) {{
if (p.Type() == OutputType::json)
@@ -1063,263 +750,249 @@ def PrintFlagBits(bitmask):
p.PrintKeyString(name, strings.at(0));
}}
}}
-'''
+''']
+
+
+ def PrintBitMask(self,bitmask, name):
+ out = []
+ out.extend(self.PrintGetFlagStrings(bitmask.name, bitmask))
+ out.append(self.AddGuardHeader(bitmask))
+ out.extend(self.PrintFlags(bitmask, name))
+ out.extend(self.PrintFlagBits(bitmask))
+ out.append(self.AddGuardFooter(bitmask))
+ out.append('\n')
+ return out
+
+ def PrintBitMaskToString(self, bitmask, name):
+ out = []
+ out.append(self.AddGuardHeader(bitmask))
+ out.append(f'std::string {name}String({name} value) {{\n')
+ out.append(' std::string out;\n')
+ out.append(' bool is_first = true;\n')
+ for v in bitmask.flags:
+ out.append(f' if ({v.name} & value) {{\n')
+ out.append(' if (is_first) { is_first = false; } else { out += " | "; }\n')
+ out.append(f' out += "{str(v.name)[3:]}";\n')
+ out.append(' }\n')
+ out.append(' return out;\n')
+ out.append('}\n')
+ out.append(self.AddGuardFooter(bitmask))
+ return out
-def PrintBitMask(bitmask, name, generator):
- out = PrintGetFlagStrings(bitmask.name, bitmask)
- out += AddGuardHeader(GetExtension(bitmask.name, generator))
- out += PrintFlags(bitmask, name)
- out += PrintFlagBits(bitmask)
- out += AddGuardFooter(GetExtension(bitmask.name, generator))
- out += '\n'
- return out
-
-
-def PrintBitMaskToString(bitmask, name, generator):
- out = AddGuardHeader(GetExtension(bitmask.name, generator))
- out += f'std::string {name}String({name} value) {{\n'
- out += ' std::string out;\n'
- out += ' bool is_first = true;\n'
- for v in bitmask.options:
- out += f' if ({v.name} & value) {{\n'
- out += ' if (is_first) { is_first = false; } else { out += " | "; }\n'
- out += f' out += "{str(v.name)[3:]}";\n'
- out += ' }\n'
- out += ' return out;\n'
- out += '}\n'
- out += AddGuardFooter(GetExtension(bitmask.name, generator))
- return out
-
-
-def PrintStructure(struct):
- if len(struct.members) == 0:
- return ''
- out = ''
- out += AddGuardHeader(struct)
- max_key_len = 0
- for v in struct.members:
- if v.arrayLength is not None:
- if len(v.name) + len(v.arrayLength) + 2 > max_key_len:
- max_key_len = len(v.name) + len(v.arrayLength) + 2
- elif v.typeID in PREDEFINED_TYPES or v.typeID in STRUCT_BLACKLIST:
- if len(v.name) > max_key_len:
- max_key_len = len(v.name)
-
- out += f'void Dump{struct.name}(Printer &p, std::string name, const {struct.name} &obj) {{\n'
- if struct.name == 'VkPhysicalDeviceLimits':
- out += ' if (p.Type() == OutputType::json)\n'
- out += ' p.ObjectStart("limits");\n'
- out += ' else\n'
- out += ' p.SetSubHeader().ObjectStart(name);\n'
- elif struct.name == 'VkPhysicalDeviceSparseProperties':
- out += ' if (p.Type() == OutputType::json)\n'
- out += ' p.ObjectStart("sparseProperties");\n'
- out += ' else\n'
- out += ' p.SetSubHeader().ObjectStart(name);\n'
- else:
- out += ' ObjectWrapper object{p, name};\n'
- if max_key_len > 0:
- out += f' p.SetMinKeyWidth({max_key_len});\n'
- for v in struct.members:
- # arrays
- if v.arrayLength is not None:
- # strings
- if v.typeID == 'char':
- out += f' p.PrintKeyString("{v.name}", obj.{v.name});\n'
- # uuid's
- elif v.typeID == 'uint8_t' and (v.arrayLength == '8' or v.arrayLength == '16'): # VK_UUID_SIZE
- if v.arrayLength == '8':
- out += ' if (obj.deviceLUIDValid) { // special case\n'
- out += f' p.PrintKeyValue("{v.name}", obj.{v.name});\n'
- if v.arrayLength == '8':
- out += ' }\n'
- elif struct.name == 'VkQueueFamilyGlobalPriorityProperties' and v.name == 'priorities':
- out += f' ArrayWrapper arr(p,"{v.name}", obj.priorityCount);\n'
- out += ' for (uint32_t i = 0; i < obj.priorityCount; i++) {\n'
- out += ' if (p.Type() == OutputType::json)\n'
- out += ' p.PrintString(std::string("VK_") + VkQueueGlobalPriorityString(obj.priorities[i]));\n'
- out += ' else\n'
- out += ' p.PrintString(VkQueueGlobalPriorityString(obj.priorities[i]));\n'
- out += ' }\n'
- elif v.arrayLength.isdigit():
- out += f' {{\n ArrayWrapper arr(p,"{v.name}", ' + v.arrayLength + ');\n'
- out += f' for (uint32_t i = 0; i < {v.arrayLength}; i++) {{ p.PrintElement(obj.{v.name}[i]); }}\n'
- out += ' }\n'
- else: # dynamic array length based on other member
- out += f' if (obj.{v.arrayLength} == 0 || obj.{v.name} == nullptr) {{\n'
- out += f' p.PrintKeyString("{v.name}", "NULL");\n'
- out += ' } else {\n'
- out += f' ArrayWrapper arr(p,"{v.name}", obj.{v.arrayLength});\n'
- out += f' for (uint32_t i = 0; i < obj.{v.arrayLength}; i++) {{\n'
- out += f' Dump{v.typeID}(p, std::to_string(i), obj.{v.name}[i]);\n'
- out += ' }\n'
- out += ' }\n'
- elif v.typeID == 'VkBool32':
- out += f' p.PrintKeyBool("{v.name}", static_cast<bool>(obj.{v.name}));\n'
- elif v.typeID == 'uint8_t':
- out += f' p.PrintKeyValue("{v.name}", static_cast<uint32_t>(obj.{v.name}));\n'
- elif v.typeID == 'VkDeviceSize' or (v.typeID == 'uint32_t' and v.name in ['vendorID', 'deviceID']):
- out += f' p.PrintKeyValue("{v.name}", to_hex_str(p, obj.{v.name}));\n'
- elif v.typeID in PREDEFINED_TYPES:
- out += f' p.PrintKeyValue("{v.name}", obj.{v.name});\n'
- elif v.name not in NAMES_TO_IGNORE:
- # if it is an enum/flag/bitmask
- if v.typeID in ['VkFormatFeatureFlags', 'VkFormatFeatureFlags2']:
- out += ' p.SetOpenDetails();\n' # special case so that feature flags are open in html output
- out += f' Dump{v.typeID}(p, "{v.name}", obj.{v.name});\n'
-
- if struct.name in ['VkPhysicalDeviceLimits', 'VkPhysicalDeviceSparseProperties']:
- out += ' p.ObjectEnd();\n'
- out += '}\n'
-
- out += AddGuardFooter(struct)
- return out
-
-
-def PrintStructShort(struct):
- out = ''
- out += AddGuardHeader(struct)
- out += f'std::ostream &operator<<(std::ostream &o, {struct.name} &obj) {{\n'
- out += ' return o << "(" << '
-
- first = True
- for v in struct.members:
- if first:
- first = False
- out += f'obj.{v.name} << '
+ def PrintStructure(self,struct):
+ if len(struct.members) == 0:
+ return []
+ out = []
+ out.append(self.AddGuardHeader(struct))
+ max_key_len = 0
+ for v in struct.members:
+ if (v.type in PREDEFINED_TYPES or v.type in STRUCT_BLACKLIST) and (v.length is None or v.type in ['char'] or v.fixedSizeArray[0] in ['VK_UUID_SIZE', 'VK_LUID_SIZE']):
+ max_key_len = max(max_key_len, len(v.name))
+
+ out.append(f'void Dump{struct.name}(Printer &p, std::string name, const {struct.name} &obj) {{\n')
+ if struct.name == 'VkPhysicalDeviceLimits':
+ out.append(' if (p.Type() == OutputType::json)\n')
+ out.append(' p.ObjectStart("limits");\n')
+ out.append(' else\n')
+ out.append(' p.SetSubHeader().ObjectStart(name);\n')
+ elif struct.name == 'VkPhysicalDeviceSparseProperties':
+ out.append(' if (p.Type() == OutputType::json)\n')
+ out.append(' p.ObjectStart("sparseProperties");\n')
+ out.append(' else\n')
+ out.append(' p.SetSubHeader().ObjectStart(name);\n')
else:
- out += f'\',\' << obj.{v.name} << '
- out += '")";\n'
- out += '}\n'
- out += AddGuardFooter(struct)
- return out
-
-def PrintChainStruct(listName, structures, all_structures, chain_details, extTypes, aliases, vulkan_versions):
- sorted_structures = sorted(
- all_structures, key=operator.attrgetter('name'))
-
- version_desc = ''
- if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
- version_desc = 'gpu.api_version'
- else:
- version_desc = 'inst.instance_version'
-
- out = ''
- structs_to_print = []
- for s in sorted_structures:
- if s.name in structures:
- structs_to_print.append(s)
- # use default constructor and delete copy & move operators
- out += f'''struct {listName}_chain {{
+ out.append(' ObjectWrapper object{p, name};\n')
+ if max_key_len > 0:
+ out.append(f' p.SetMinKeyWidth({max_key_len});\n')
+ for v in struct.members:
+ # arrays
+ if v.length is not None:
+ # strings
+ if v.type == 'char':
+ out.append(f' p.PrintKeyString("{v.name}", obj.{v.name});\n')
+ # uuid's
+ elif v.type == 'uint8_t' and (v.fixedSizeArray[0] == 'VK_LUID_SIZE' or v.fixedSizeArray[0] == 'VK_UUID_SIZE'): # VK_UUID_SIZE
+ if v.fixedSizeArray[0] == 'VK_LUID_SIZE':
+ out.append(' if (obj.deviceLUIDValid) { // special case\n')
+ out.append(f' p.PrintKeyValue("{v.name}", obj.{v.name});\n')
+ if v.fixedSizeArray[0] == 'VK_LUID_SIZE':
+ out.append(' }\n')
+ elif struct.name == 'VkQueueFamilyGlobalPriorityProperties' and v.name == 'priorities':
+ out.append(f' ArrayWrapper arr(p,"{v.name}", obj.priorityCount);\n')
+ out.append(' for (uint32_t i = 0; i < obj.priorityCount; i++) {\n')
+ out.append(' if (p.Type() == OutputType::json)\n')
+ out.append(' p.PrintString(std::string("VK_") + VkQueueGlobalPriorityString(obj.priorities[i]));\n')
+ out.append(' else\n')
+ out.append(' p.PrintString(VkQueueGlobalPriorityString(obj.priorities[i]));\n')
+ out.append(' }\n')
+ elif len(v.fixedSizeArray) == 2:
+ out.append(f' {{\n ArrayWrapper arr(p,"{v.name}", ' + v.fixedSizeArray[0] + ');\n')
+ out.append(f' for (uint32_t i = 0; i < {v.fixedSizeArray[0]}; i++) {{\n')
+ out.append(f' for (uint32_t j = 0; j < {v.fixedSizeArray[1]}; j++) {{\n')
+ out.append(f' p.PrintElement(obj.{v.name}[i][j]); }} }}\n')
+ out.append(' }\n')
+ elif len(v.fixedSizeArray) == 1:
+ out.append(f' {{\n ArrayWrapper arr(p,"{v.name}", ' + v.fixedSizeArray[0] + ');\n')
+ out.append(f' for (uint32_t i = 0; i < {v.fixedSizeArray[0]}; i++) {{ p.PrintElement(obj.{v.name}[i]); }}\n')
+ out.append(' }\n')
+ else: # dynamic array length based on other member
+ out.append(f' if (obj.{v.length} == 0 || obj.{v.name} == nullptr) {{\n')
+ out.append(f' p.PrintKeyString("{v.name}", "NULL");\n')
+ out.append(' } else {\n')
+ out.append(f' ArrayWrapper arr(p,"{v.name}", obj.{v.length});\n')
+ out.append(f' for (uint32_t i = 0; i < obj.{v.length}; i++) {{\n')
+ out.append(f' Dump{v.type}(p, std::to_string(i), obj.{v.name}[i]);\n')
+ out.append(' }\n')
+ out.append(' }\n')
+ elif v.type == 'VkBool32':
+ out.append(f' p.PrintKeyBool("{v.name}", static_cast<bool>(obj.{v.name}));\n')
+ elif v.type == 'uint8_t':
+ out.append(f' p.PrintKeyValue("{v.name}", static_cast<uint32_t>(obj.{v.name}));\n')
+ elif v.type == 'VkDeviceSize' or (v.type == 'uint32_t' and v.name in ['vendorID', 'deviceID']):
+ out.append(f' p.PrintKeyValue("{v.name}", to_hex_str(p, obj.{v.name}));\n')
+ elif v.type in PREDEFINED_TYPES:
+ out.append(f' p.PrintKeyValue("{v.name}", obj.{v.name});\n')
+ elif v.name not in NAMES_TO_IGNORE:
+ # if it is an enum/flag/bitmask
+ if v.type in ['VkFormatFeatureFlags', 'VkFormatFeatureFlags2']:
+ out.append(' p.SetOpenDetails();\n') # special case so that feature flags are open in html output
+ out.append(f' Dump{v.type}(p, "{v.name}", obj.{v.name});\n')
+
+ if struct.name in ['VkPhysicalDeviceLimits', 'VkPhysicalDeviceSparseProperties']:
+ out.append(' p.ObjectEnd();\n')
+ out.append('}\n')
+
+ out.append(self.AddGuardFooter(struct))
+ return out
+
+
+ def PrintStructShort(self,struct):
+ out = []
+ out.append(self.AddGuardHeader(struct))
+ out.append(f'std::ostream &operator<<(std::ostream &o, {struct.name} &obj) {{\n')
+ out.append(' return o << "(" << ')
+
+ first = True
+ for v in struct.members:
+ if first:
+ first = False
+ out.append(f'obj.{v.name} << ')
+ else:
+ out.append(f'\',\' << obj.{v.name} << ')
+ out.append('")";\n')
+ out.append('}\n')
+ out.append(self.AddGuardFooter(struct))
+ return out
+
+ def PrintChainStruct(self, listName, structs_to_print, chain_details):
+ version_desc = ''
+ if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
+ version_desc = 'gpu.api_version'
+ else:
+ version_desc = 'inst.instance_version'
+
+ out = []
+
+ # use default constructor and delete copy & move operators
+ out.append(f'''struct {listName}_chain {{
{listName}_chain() = default;
{listName}_chain(const {listName}_chain &) = delete;
{listName}_chain& operator=(const {listName}_chain &) = delete;
{listName}_chain({listName}_chain &&) = delete;
{listName}_chain& operator=({listName}_chain &&) = delete;
-'''
+''')
+
+ out.append(' void* start_of_chain = nullptr;\n')
+ for s in structs_to_print:
+ if s in STRUCT_BLACKLIST:
+ continue
+ struct = self.vk.structs[s]
+ out.append(self.AddGuardHeader(struct))
+ if struct.sType is not None:
+ out.append(f' {struct.name} {struct.name[2:]}{{}};\n')
+ # Specific versions of drivers have an incorrect definition of the size of these structs.
+ # We need to artificially pad the structure it just so the driver doesn't write out of bounds and
+ # into other structures that are adjacent. This bug comes from the in-development version of
+ # the extension having a larger size than the final version, so older drivers try to write to
+ # members which don't exist.
+ if struct.name in ['VkPhysicalDeviceShaderIntegerDotProductFeatures', 'VkPhysicalDeviceHostImageCopyFeaturesEXT']:
+ out.append(f' char {struct.name}_padding[64];\n')
+ for member in struct.members:
+ if member.length is not None and len(member.fixedSizeArray) == 0:
+ out.append(f' std::vector<{member.type}> {struct.name}_{member.name};\n')
+ out.append(self.AddGuardFooter(struct))
+ out.append(' void initialize_chain(')
+ if chain_details.get('type') in [EXTENSION_TYPE_INSTANCE, EXTENSION_TYPE_BOTH]:
+ out.append('AppInstance &inst, ')
+ if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
+ out.append('AppGpu &gpu ')
+ if chain_details.get('can_show_promoted_structs'):
+ out.append(', bool show_promoted_structs')
+ out.append(') noexcept {\n')
+ for s in structs_to_print:
+ if s in STRUCT_BLACKLIST:
+ continue
+ struct = self.vk.structs[s]
- out += ' void* start_of_chain = nullptr;\n'
- for s in structs_to_print:
- if s.name in STRUCT_BLACKLIST:
- continue
- out += AddGuardHeader(s)
- if s.sTypeName is not None:
- out += f' {s.name} {s.name[2:]}{{}};\n'
- # Specific versions of drivers have an incorrect definition of the size of these structs.
- # We need to artificially pad the structure it just so the driver doesn't write out of bounds and
- # into other structures that are adjacent. This bug comes from the in-development version of
- # the extension having a larger size than the final version, so older drivers try to write to
- # members which don't exist.
- if s.name in ['VkPhysicalDeviceShaderIntegerDotProductFeatures', 'VkPhysicalDeviceHostImageCopyFeaturesEXT']:
- out += f' char {s.name}_padding[64];\n'
- if s.hasLengthmember:
- for member in s.members:
- if member.lengthMember:
- out += f' std::vector<{member.typeID}> {s.name}_{member.name};\n'
- out += AddGuardFooter(s)
- out += ' void initialize_chain('
- if chain_details.get('type') in [EXTENSION_TYPE_INSTANCE, EXTENSION_TYPE_BOTH]:
- out += 'AppInstance &inst, '
- if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
- out += 'AppGpu &gpu '
- if chain_details.get('can_show_promoted_structs'):
- out += ', bool show_promoted_structs'
- out += ') noexcept {\n'
- for s in structs_to_print:
- if s.name in STRUCT_BLACKLIST:
- continue
- out += AddGuardHeader(s)
- out += f' {s.name[2:]}.sType = {s.sTypeName};\n'
- out += AddGuardFooter(s)
-
-
- out += ' std::vector<VkBaseOutStructure*> chain_members{};\n'
- for s in structs_to_print:
- if s.name in STRUCT_BLACKLIST:
- continue
- out += AddGuardHeader(s)
- extEnables = {}
- for k, elem in extTypes.items():
- if k == s.name or (s.name in aliases.keys() and k in aliases[s.name]):
- for e in elem:
- extEnables[e.extNameStr] = e.type
+ out.append(self.AddGuardHeader(struct))
+ out.append(f' {struct.name[2:]}.sType = {struct.sType};\n')
+ out.append(self.AddGuardFooter(struct))
- version = None
- oldVersionName = None
- for v in vulkan_versions:
- if s.name in v.names:
- version = v
- if s.name in aliases.keys():
- for alias in aliases[s.name]:
- oldVersionName = alias
- has_version = version is not None
- has_extNameStr = len(extEnables) > 0 or s.name in aliases.keys()
- if has_version or has_extNameStr:
- out += ' if ('
- has_printed_condition = False
- if has_extNameStr:
- for key, value in extEnables.items():
- if has_printed_condition:
- out += '\n || '
- else:
- has_printed_condition = True
- if has_version:
- out += '('
- if value == EXTENSION_TYPE_DEVICE:
- out += f'gpu.CheckPhysicalDeviceExtensionIncluded({key})'
- elif value == EXTENSION_TYPE_INSTANCE:
- out += f'inst.CheckExtensionEnabled({key})'
+ out.append(' std::vector<VkBaseOutStructure*> chain_members{};\n')
+ for s in structs_to_print:
+ if s in STRUCT_BLACKLIST:
+ continue
+ struct = self.vk.structs[s]
+ out.append(self.AddGuardHeader(struct))
+
+ has_version = struct.version is not None
+ has_extNameStr = len(struct.extensions) > 0 or len(struct.aliases) > 0
+ if has_version or has_extNameStr:
+ out.append(' if (')
+ has_printed_condition = False
+ if has_extNameStr:
+ for ext in struct.extensions:
+ if has_printed_condition:
+ out.append('\n || ')
+ else:
+ has_printed_condition = True
+ if has_version:
+ out.append('(')
+ if self.vk.extensions[ext].device:
+ out.append(f'gpu.CheckPhysicalDeviceExtensionIncluded({self.vk.extensions[ext].nameString})')
+ elif self.vk.extensions[ext].instance:
+ out.append(f'inst.CheckExtensionEnabled({self.vk.extensions[ext].nameString})')
+ else:
+ assert False, 'Should never get here'
+ if has_version:
+ str_show_promoted_structs = '|| show_promoted_structs' if chain_details.get('can_show_promoted_structs') else ''
+ if struct.name in STRUCT_1_1_LIST:
+ out.append(f'{version_desc} == {struct.version.nameApi} {str_show_promoted_structs}')
+ elif has_printed_condition:
+ out.append(f')\n && ({version_desc} < {struct.version.nameApi} {str_show_promoted_structs})')
else:
- assert False, 'Should never get here'
- if has_version:
- str_show_promoted_structs = '|| show_promoted_structs' if chain_details.get('can_show_promoted_structs') else ''
- if s.name in STRUCT_1_1_LIST:
- out += f'{version_desc} == {version.constant} {str_show_promoted_structs}'
- elif has_printed_condition:
- out += f')\n && ({version_desc} < {version.constant} {str_show_promoted_structs})'
- else:
- out += f'({version_desc} >= {version.constant})'
- out += ')\n '
- else:
- out += ' '
- out += f'chain_members.push_back(reinterpret_cast<VkBaseOutStructure*>(&{s.name[2:]}));\n'
- out += AddGuardFooter(s)
- chain_param_list = []
- chain_arg_list = []
- if chain_details.get('type') in [EXTENSION_TYPE_INSTANCE, EXTENSION_TYPE_BOTH]:
- chain_param_list.append('AppInstance &inst')
- chain_arg_list.append('inst')
- if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
- chain_param_list.append('AppGpu &gpu')
- chain_arg_list.append('gpu')
- if chain_details.get('can_show_promoted_structs'):
- chain_param_list.append('bool show_promoted_structs')
- chain_arg_list.append('show_promoted_structs')
-
- out += f'''
+ out.append(f'({version_desc} >= {struct.version.nameApi})')
+ out.append(')\n ')
+ else:
+ out.append(' ')
+ out.append(f'chain_members.push_back(reinterpret_cast<VkBaseOutStructure*>(&{struct.name[2:]}));\n')
+ out.append(self.AddGuardFooter(struct))
+ chain_param_list = []
+ chain_arg_list = []
+ if chain_details.get('type') in [EXTENSION_TYPE_INSTANCE, EXTENSION_TYPE_BOTH]:
+ chain_param_list.append('AppInstance &inst')
+ chain_arg_list.append('inst')
+ if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
+ chain_param_list.append('AppGpu &gpu')
+ chain_arg_list.append('gpu')
+ if chain_details.get('can_show_promoted_structs'):
+ chain_param_list.append('bool show_promoted_structs')
+ chain_arg_list.append('show_promoted_structs')
+
+ out.append(f'''
if (!chain_members.empty()) {{
for(size_t i = 0; i < chain_members.size() - 1; i++){{
chain_members[i]->pNext = chain_members[i + 1];
@@ -1328,402 +1001,104 @@ def PrintChainStruct(listName, structures, all_structures, chain_details, extTyp
}}
}}
}};
-void setup_{listName}_chain({chain_details['holder_type']}& start, std::unique_ptr<{listName}_chain>& chain, {','.join(chain_param_list)}){{
+void setup_{listName}_chain({chain_details['extends']}& start, std::unique_ptr<{listName}_chain>& chain, {','.join(chain_param_list)}){{
chain = std::unique_ptr<{listName}_chain>(new {listName}_chain());
chain->initialize_chain({','.join(chain_arg_list)});
start.pNext = chain->start_of_chain;
}};
-'''
- if chain_details.get('print_iterator'):
- out += '\n'
- out += f'void chain_iterator_{listName}(Printer &p, '
- if chain_details.get('type') in [EXTENSION_TYPE_INSTANCE, EXTENSION_TYPE_BOTH]:
- out += 'AppInstance &inst, '
- if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
- out += 'AppGpu &gpu, '
- if chain_details.get('can_show_promoted_structs'):
- out += 'bool show_promoted_structs, '
- out += 'const void * place) {\n'
- out += ' while (place) {\n'
- out += ' const VkBaseOutStructure *structure = (const VkBaseOutStructure *)place;\n'
- out += ' p.SetSubHeader();\n'
-
- for s in sorted_structures:
- if s.sTypeName is None or s.name in STRUCT_BLACKLIST:
- continue
-
- extEnables = {}
- for k, elem in extTypes.items():
- if k == s.name or (s.name in aliases.keys() and k in aliases[s.name]):
- for e in elem:
- extEnables[e.extNameStr] = e.type
-
- version = None
- oldVersionName = None
- for v in vulkan_versions:
- if s.name in v.names:
- version = v
- if s.name in aliases.keys():
- for alias in aliases[s.name]:
- oldVersionName = alias
-
- if s.name in structures:
- out += AddGuardHeader(s)
- out += f' if (structure->sType == {s.sTypeName}'
- if s.name in PORTABILITY_STRUCTS:
- out += ' && p.Type() != OutputType::json'
- has_version = version is not None
- has_extNameStr = len(extEnables) > 0 or s.name in aliases.keys()
- out += ') {\n'
- out += f' const {s.name}* props = (const {s.name}*)structure;\n'
- out += f' Dump{s.name}(p, '
- if s.name in aliases.keys() and version is not None:
- out += f'{version_desc} >= {version.constant} ?"{s.name}":"{oldVersionName}"'
+''')
+ if chain_details.get('print_iterator'):
+ out.append('\n')
+ out.append(f'void chain_iterator_{listName}(Printer &p, ')
+ if chain_details.get('type') in [EXTENSION_TYPE_INSTANCE, EXTENSION_TYPE_BOTH]:
+ out.append('AppInstance &inst, ')
+ if chain_details.get('type') in [EXTENSION_TYPE_DEVICE, EXTENSION_TYPE_BOTH]:
+ out.append('AppGpu &gpu, ')
+ if chain_details.get('can_show_promoted_structs'):
+ out.append('bool show_promoted_structs, ')
+ out.append('const void * place) {\n')
+ out.append(' while (place) {\n')
+ out.append(' const VkBaseOutStructure *structure = (const VkBaseOutStructure *)place;\n')
+ out.append(' p.SetSubHeader();\n')
+
+ for s in structs_to_print:
+ if s in STRUCT_BLACKLIST:
+ continue
+ struct = self.vk.structs[s]
+
+ out.append(self.AddGuardHeader(struct))
+ out.append(f' if (structure->sType == {struct.sType}')
+ if struct.name in PORTABILITY_STRUCTS:
+ out.append(' && p.Type() != OutputType::json')
+ has_version = struct.version is not None
+ has_extNameStr = len(struct.extensions) > 0 or len(struct.aliases) > 0
+ out.append(') {\n')
+ out.append(f' const {struct.name}* props = (const {struct.name}*)structure;\n')
+ out.append(f' Dump{struct.name}(p, ')
+ if len(struct.aliases) > 0 and struct.version is not None:
+ out.append(f'{version_desc} >= {struct.version.nameApi} ?"{struct.name}":"{struct.aliases[0]}"')
else:
- out += f'"{s.name}"'
- out += ', *props);\n'
- out += ' p.AddNewline();\n'
- out += ' }\n'
- out += AddGuardFooter(s)
- out += ' place = structure->pNext;\n'
- out += ' }\n'
- out += '}\n'
-
- out += '\n'
- out += f'bool prepare_{listName}_twocall_chain_vectors(std::unique_ptr<{listName}_chain>& chain) {{\n'
- out += ' (void)chain;\n'
- is_twocall = False
- for s in structs_to_print:
- if not s.hasLengthmember:
- continue
- if s.name in STRUCT_BLACKLIST:
- continue
- out += AddGuardHeader(s)
- for member in s.members:
- if member.lengthMember:
- out += f' chain->{s.name}_{member.name}.resize(chain->{s.name[2:]}.{member.arrayLength});\n'
- out += f' chain->{s.name[2:]}.{member.name} = chain->{s.name}_{member.name}.data();\n'
- out += AddGuardFooter(s)
- is_twocall = True
- out += f' return {"true" if is_twocall else "false"};\n'
- out += '}\n'
-
- return out
-
-
-def PrintStructComparisonForwardDecl(structure):
- out = ''
- out += f'bool operator==(const {structure.name} & a, const {structure.name} b);\n'
- return out
-
-
-def PrintStructComparison(structure):
- out = ''
- out += f'bool operator==(const {structure.name} & a, const {structure.name} b) {{\n'
- out += ' return '
- is_first = True
- for m in structure.members:
- if m.name not in NAMES_TO_IGNORE:
- if not is_first:
- out += '\n && '
- else:
- is_first = False
- out += f'a.{m.name} == b.{m.name}'
- out += ';\n'
- out += '}\n'
- return out
-
-
-class VulkanEnum:
- class Option:
-
- def __init__(self, name, value, bitpos, comment):
- self.name = name
- self.comment = comment
-
- if bitpos is not None:
- value = 1 << int(bitpos)
- elif isinstance(value, str):
- if value.lower().startswith('0x'):
- value = int(value, 16)
- else:
- value = int(value)
-
- self.value = value
-
- def values(self):
- return {
- 'optName': self.name,
- 'optValue': self.value,
- 'optComment': self.comment,
- }
-
- def __init__(self, rootNode):
- self.name = rootNode.get('name')
- self.type = rootNode.get('type')
- self.options = []
-
- for child in rootNode:
- childName = child.get('name')
- childValue = child.get('value')
- childBitpos = child.get('bitpos')
- childComment = child.get('comment')
- childExtends = child.get('extends')
- childOffset = child.get('offset')
- childExtNum = child.get('extnumber')
- support = child.get('supported')
- if support == 'disabled':
- continue
-
- if childName is None:
+ out.append(f'"{struct.name}"')
+ out.append(', *props);\n')
+ out.append(' p.AddNewline();\n')
+ out.append(' }\n')
+ out.append(self.AddGuardFooter(struct))
+ out.append(' place = structure->pNext;\n')
+ out.append(' }\n')
+ out.append('}\n')
+
+ out.append('\n')
+ out.append(f'bool prepare_{listName}_twocall_chain_vectors(std::unique_ptr<{listName}_chain>& chain) {{\n')
+ out.append(' (void)chain;\n')
+ is_twocall = False
+ for s in structs_to_print:
+ if s in STRUCT_BLACKLIST:
continue
- if childValue is None and childBitpos is None and childOffset is None:
+ struct = self.vk.structs[s]
+ has_length = False
+ for member in struct.members:
+ if member.length is not None and len(member.fixedSizeArray) == 0:
+ has_length = True
+ if not has_length:
continue
+ out.append(self.AddGuardHeader(struct))
+ for member in struct.members:
+ if member.length is not None and len(member.fixedSizeArray) == 0:
+ out.append(f' chain->{struct.name}_{member.name}.resize(chain->{struct.name[2:]}.{member.length});\n')
+ out.append(f' chain->{struct.name[2:]}.{member.name} = chain->{struct.name}_{member.name}.data();\n')
+ out.append(self.AddGuardFooter(struct))
+ is_twocall = True
+ out.append(f' return {"true" if is_twocall else "false"};\n')
+ out.append('}\n')
- if childExtends is not None and childExtNum is not None and childOffset is not None:
- childValue = CalcEnumValue(int(childExtNum), int(childOffset))
- if 'dir' in child.keys():
- childValue = -childValue
- duplicate = False
- for o in self.options:
- if o.values()['optName'] == childName:
- duplicate = True
- if duplicate:
- continue
-
- self.options.append(VulkanEnum.Option(
- childName, childValue, childBitpos, childComment))
-
-
-class VulkanBitmask:
-
- def __init__(self, rootNode):
- self.name = rootNode.get('name')
- self.type = rootNode.get('type')
+ return out
- # Read each value that the enum contains
- self.options = []
- for child in rootNode:
- childName = child.get('name')
- childValue = child.get('value')
- childBitpos = child.get('bitpos')
- childComment = child.get('comment')
- support = child.get('supported')
- if childName is None or (childValue is None and childBitpos is None):
- continue
- if support == 'disabled':
- continue
- duplicate = False
- for option in self.options:
- if option.name == childName:
- duplicate = True
- if duplicate:
- continue
+ def PrintStructComparisonForwardDecl(self,structure):
+ out = []
+ out.append(f'bool operator==(const {structure.name} & a, const {structure.name} b);\n')
+ return out
- self.options.append(VulkanEnum.Option(
- childName, childValue, childBitpos, childComment))
-
-
-class VulkanFlags:
-
- def __init__(self, rootNode):
- self.name = rootNode.get('name')
- self.type = rootNode.get('type')
- self.enum = rootNode.get('requires')
- # 64 bit flags use bitvalues, not requires
- if self.enum is None:
- self.enum = rootNode.get('bitvalues')
-
-
-class VulkanVariable:
- def __init__(self, rootNode, constants):
- self.name = rootNode.find('name').text
- # Typename, dereferenced and converted to a useable C++ token
- self.typeID = rootNode.find('type').text
- self.baseType = self.typeID
- self.childType = None
- self.arrayLength = None
- self.text = ''
- for node in rootNode.itertext():
- comment = rootNode.find('comment')
- if comment is not None and comment.text == node:
- continue
- self.text += node
-
- typeMatch = re.search('.+?(?=' + self.name + ')', self.text)
- self.type = typeMatch.string[typeMatch.start():typeMatch.end()]
- self.type = ' '.join(self.type.split())
- bracketMatch = re.search('(?<=\\[)[a-zA-Z0-9_]+(?=\\])', self.text)
- if bracketMatch is not None:
- matchText = bracketMatch.string[bracketMatch.start(
- ):bracketMatch.end()]
- self.childType = self.type
- self.type += '[' + matchText + ']'
- if matchText in constants:
- self.arrayLength = constants[matchText]
- else:
- self.arrayLength = matchText
-
- self.lengthMember = False
- lengthString = rootNode.get('len')
- lengths = []
- if lengthString is not None:
- lengths = re.split(',', lengthString)
- lengths = list(filter(('null-terminated').__ne__, lengths))
- if self.arrayLength is None and len(lengths) > 0:
- self.childType = '*'.join(self.type.split('*')[0:-1])
- self.arrayLength = lengths[0]
- self.lengthMember = True
- if self.arrayLength is not None and self.arrayLength.startswith('latexmath'):
- code = self.arrayLength[10:len(self.arrayLength)]
- code = re.sub('\\[', '', code)
- code = re.sub('\\]', '', code)
- code = re.sub('\\\\(lceil|rceil)', '', code)
- code = re.sub('{|}', '', code)
- code = re.sub('\\\\mathit', '', code)
- code = re.sub('\\\\over', '/', code)
- code = re.sub('\\\\textrm', '', code)
- self.arrayLength = code
-
- # Dereference if necessary and handle members of variables
- if self.arrayLength is not None:
- self.arrayLength = re.sub('::', '->', self.arrayLength)
- sections = self.arrayLength.split('->')
- if sections[-1][0] == 'p' and sections[0][1].isupper():
- self.arrayLength = '*' + self.arrayLength
-
-
-class VulkanStructure:
- def __init__(self, name, rootNode, constants, extTypes):
- self.name = name
- self.members = []
- self.guard = None
- self.sTypeName = None
- self.extendsStruct = rootNode.get('structextends')
- self.hasLengthmember = False
-
- for node in rootNode.findall('member'):
- if node.get('values') is not None:
- self.sTypeName = node.get('values')
- self.members.append(VulkanVariable(node, constants))
-
- for member in self.members:
- if member.lengthMember:
- self.hasLengthmember = True
- break
- for k, elem in extTypes.items():
- if k == self.name:
- for e in elem:
- if e.guard is not None:
- self.guard = e.guard
-
-
-class VulkanExtension:
- def __init__(self, rootNode):
- self.name = rootNode.get('name')
- self.number = int(rootNode.get('number'))
- self.type = rootNode.get('type')
- self.dependency = rootNode.get('requires')
- self.guard = GetFeatureProtect(rootNode)
- self.supported = rootNode.get('supported')
- self.extNameStr = None
- self.vktypes = []
- self.vkfuncs = []
- self.constants = OrderedDict()
- self.enumValues = OrderedDict()
- self.node = rootNode
-
- for req in rootNode.findall('require'):
- for ty in req.findall('type'):
- self.vktypes.append(ty.get('name'))
-
- for func in req.findall('command'):
- self.vkfuncs.append(func.get('name'))
-
- for enum in req.findall('enum'):
- base = enum.get('extends')
- name = enum.get('name')
- value = enum.get('value')
- bitpos = enum.get('bitpos')
- offset = enum.get('offset')
- # gets the VK_XXX_EXTENSION_NAME string
- if value == f'"{self.name}"':
- self.extNameStr = name
-
- if value is None and bitpos is not None:
- value = 1 << int(bitpos)
-
- if offset is not None:
- offset = int(offset)
- if base is not None and offset is not None:
- enumValue = 1000000000 + 1000*(self.number - 1) + offset
- if enum.get('dir') == '-':
- enumValue = -enumValue
- self.enumValues[base] = (name, enumValue)
+ def PrintStructComparison(self,structure):
+ out = []
+ out.append(f'bool operator==(const {structure.name} & a, const {structure.name} b) {{\n')
+ out.append(' return ')
+ is_first = True
+ for m in structure.members:
+ if m.name not in NAMES_TO_IGNORE:
+ if not is_first:
+ out.append('\n && ')
else:
- self.constants[name] = value
-
-
-class VulkanVersion:
- def __init__(self, rootNode):
- self.name = rootNode.get('name')
- self.constant = self.name.replace('_VERSION_', '_API_VERSION_')
- self.names = set()
-
- match = re.search(r"^[A-Z]+_VERSION_([1-9][0-9]*)_([0-9]+)$", self.name)
- self.major = int(match.group(1))
- self.minor = int(match.group(2))
-
- for req in rootNode.findall('require'):
- for ty in req.findall('type'):
- self.names.add(ty.get('name'))
- for func in req.findall('command'):
- self.names.add(func.get('name'))
- for enum in req.findall('enum'):
- self.names.add(enum.get('name'))
- self.names = sorted(self.names)
+ is_first = False
+ out.append(f'a.{m.name} == b.{m.name}')
+ out.append(';\n')
+ out.append('}\n')
+ return out
class VulkanFormatRange:
- def __init__(self, min_inst_version, ext_name, first, last):
+ def __init__(self, min_inst_version, extensions, first, last):
self.minimum_instance_version = min_inst_version
- self.extension_name = ext_name
+ self.extensions = extensions
self.first_format = first
self.last_format = last
-
-class VulkanVideoRequiredCapabilities():
- def __init__(self, struct, member, value):
- self.struct = struct
- self.member = member
- self.value = value
-
-class VulkanVideoFormat():
- def __init__(self, name, usage):
- self.name = name
- self.usage = usage
- self.properties = OrderedDict()
- self.requiredCaps = list()
- super().__init__()
-
-class VulkanVideoProfileStructMember():
- def __init__(self, name):
- self.name = name
- self.values = OrderedDict()
-
-class VulkanVideoProfileStruct():
- def __init__(self, struct):
- self.struct = struct
- self.members = OrderedDict()
-
-class VulkanVideoCodec():
- def __init__(self, name, extend = None, value = None):
- self.name = name
- self.value = value
- self.profileStructs = OrderedDict()
- self.capabilities = OrderedDict()
- self.formats = OrderedDict()
- if extend is not None:
- self.profileStructs = copy.deepcopy(extend.profileStructs)
- self.capabilities = copy.deepcopy(extend.capabilities)
- self.formats = copy.deepcopy(extend.formats)