From 56ef52e1b01936fd5c4b1d94ee385d76cfa8a495 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Fri, 13 Sep 2024 09:36:56 -0700 Subject: [PATCH] gfxstream: delete unneccessary code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit genvk.py itself includes different types of generators: spirvgenerator.py, rubygenerator.py, etc.  cerealgenerator.py is an additional one.  A strategy to pare down the size of the code would be modify genvk.py to remove unneeded generators, and just import the cerealgenerator: i.e, importing the subset of scripts useful to gfxstream. The removes the notion of upstreaming to vulkan-docs, but does imply more dedicated codegen strategy long-term.   About 300kLoC can be removed, since previously we just a blanket copy. Reviewed-by: Aaron Ruby Acked-by: Yonggang Luo Acked-by: Adam Jackson Part-of: --- src/gfxstream/codegen/scripts/genvk.py | 671 ------------------------- 1 file changed, 671 deletions(-) diff --git a/src/gfxstream/codegen/scripts/genvk.py b/src/gfxstream/codegen/scripts/genvk.py index d4c1ab64d53..eb231f6ff02 100755 --- a/src/gfxstream/codegen/scripts/genvk.py +++ b/src/gfxstream/codegen/scripts/genvk.py @@ -16,28 +16,9 @@ import xml.etree.ElementTree as etree sys.path.append(os.path.abspath(os.path.dirname(__file__))) from cgenerator import CGeneratorOptions, COutputGenerator -# Vulkan SC modules -from json_parser import JSONParserGenerator, JSONParserOptions -from schema_generator import SchemaGeneratorOptions, SchemaOutputGenerator -from json_generator import JSONGeneratorOptions, JSONOutputGenerator -from json_h_generator import JSONHeaderOutputGenerator, JSONHeaderGeneratorOptions -from json_c_generator import JSONCOutputGenerator, JSONCGeneratorOptions -from docgenerator import DocGeneratorOptions, DocOutputGenerator -from extensionmetadocgenerator import (ExtensionMetaDocGeneratorOptions, - ExtensionMetaDocOutputGenerator) -from interfacedocgenerator import InterfaceDocGenerator from generator import write -from spirvcapgenerator import SpirvCapabilityOutputGenerator -from hostsyncgenerator import HostSynchronizationOutputGenerator -from formatsgenerator import FormatsOutputGenerator -from syncgenerator import SyncOutputGenerator -from jsgenerator import JSOutputGenerator -from pygenerator import PyOutputGenerator -from rubygenerator import RubyOutputGenerator -from reflib import logDiag, logWarn, logErr, setLogFile from reg import Registry -from validitygenerator import ValidityOutputGenerator from apiconventions import APIConventions # gfxstream + cereal modules @@ -57,7 +38,6 @@ def endTimer(timeit, msg): global startTime if timeit and startTime is not None: endTime = time.process_time() - logDiag(msg, endTime - startTime) startTime = None @@ -165,235 +145,6 @@ def makeGenOpts(args): isCTS = args.isCTS - # API include files for spec and ref pages - # Overwrites include subdirectories in spec source tree - # The generated include files do not include the calling convention - # macros (apientry etc.), unlike the header files. - # Because the 1.0 core branch includes ref pages for extensions, - # all the extension interfaces need to be generated, even though - # none are used by the core spec itself. - genOpts['apiinc'] = [ - DocOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = genpath, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - apicall = '', - apientry = '', - apientryp = '*', - alignFuncParam = 48, - expandEnumerants = False) - ] - - # JavaScript, Python, and Ruby representations of API information, used - # by scripts that do not need to load the full XML. - genOpts['apimap.cjs'] = [ - JSOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'apimap.cjs', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - reparentEnums = False) - ] - - genOpts['apimap.py'] = [ - PyOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'apimap.py', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - reparentEnums = False) - ] - - genOpts['apimap.rb'] = [ - RubyOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'apimap.rb', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - reparentEnums = False) - ] - - - # API validity files for spec - # - # requireCommandAliases is set to True because we need validity files - # for the command something is promoted to even when the promoted-to - # feature is not included. This avoids wordy includes of validity files. - genOpts['validinc'] = [ - ValidityOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - requireCommandAliases = True, - ) - ] - - # API host sync table files for spec - genOpts['hostsyncinc'] = [ - HostSynchronizationOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - reparentEnums = False) - ] - - # Extension metainformation for spec extension appendices - # Includes all extensions by default, but only so that the generated - # 'promoted_extensions_*' files refer to all extensions that were - # promoted to a core version. - genOpts['extinc'] = [ - ExtensionMetaDocOutputGenerator, - ExtensionMetaDocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = None, - defaultExtensions = defaultExtensions, - addExtensions = addExtensionsPat, - removeExtensions = None, - emitExtensions = emitExtensionsPat) - ] - - # Version and extension interface docs for version/extension appendices - # Includes all extensions by default. - genOpts['interfaceinc'] = [ - InterfaceDocGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - reparentEnums = False) - ] - - genOpts['spirvcapinc'] = [ - SpirvCapabilityOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - emitSpirv = emitSpirvPat, - reparentEnums = False) - ] - - # Used to generate various format chapter tables - genOpts['formatsinc'] = [ - FormatsOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - emitFormats = emitFormatsPat, - reparentEnums = False) - ] - - # Used to generate various synchronization chapter tables - genOpts['syncinc'] = [ - SyncOutputGenerator, - DocGeneratorOptions( - conventions = conventions, - filename = 'timeMarker', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - reparentEnums = False) - ] - # Platform extensions, in their own header files # Each element of the platforms[] array defines information for # generating a single platform: @@ -549,409 +300,6 @@ def makeGenOpts(args): misracppstyle = misracppstyle) ] - # Vulkan versions to include for SC header - SC *removes* features from 1.0/1.1/1.2 - scVersions = makeREstring(['VK_VERSION_1_0', 'VK_VERSION_1_1', 'VK_VERSION_1_2', 'VKSC_VERSION_1_0']) - - genOpts['vulkan_sc_core.h'] = [ - COutputGenerator, - CGeneratorOptions( - conventions = conventions, - filename = 'vulkan_sc_core.h', - directory = directory, - apiname = 'vulkansc', - profile = None, - versions = scVersions, - emitversions = scVersions, - defaultExtensions = 'vulkansc', - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48, - misracstyle = misracstyle, - misracppstyle = misracppstyle) - ] - - genOpts['vulkan_sc_core.hpp'] = [ - COutputGenerator, - CGeneratorOptions( - conventions = conventions, - filename = 'vulkan_sc_core.hpp', - directory = directory, - apiname = 'vulkansc', - profile = None, - versions = scVersions, - emitversions = scVersions, - defaultExtensions = 'vulkansc', - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48, - misracstyle = misracstyle, - misracppstyle = misracppstyle) - ] - - genOpts['vk.json'] = [ - SchemaOutputGenerator, - SchemaGeneratorOptions( - conventions = conventions, - filename = 'vk.json', - directory = directory, - apiname = 'vulkansc', - profile = None, - versions = scVersions, - emitversions = scVersions, - defaultExtensions = 'vulkansc', - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48) - ] - - if vulkanLayer: - genOpts['vulkan_json_data.hpp'] = [ - JSONOutputGenerator, - JSONGeneratorOptions( - conventions = conventions, - filename = 'vulkan_json_data.hpp', - directory = directory, - apiname = 'vulkan', - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = None, - addExtensions = addExtensionsPat, - removeExtensions = None, - emitExtensions = None, - vulkanLayer = vulkanLayer, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48) - ] - else: - genOpts['vulkan_json_data.hpp'] = [ - JSONOutputGenerator, - JSONGeneratorOptions( - conventions = conventions, - filename = 'vulkan_json_data.hpp', - directory = directory, - apiname = 'vulkansc', - profile = None, - versions = scVersions, - emitversions = scVersions, - defaultExtensions = 'vulkansc', - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - vulkanLayer = vulkanLayer, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - isCTS = isCTS, - alignFuncParam = 48) - ] - - # keep any relevant platform extensions for the following generators - # (needed for e.g. the vulkan_sci extensions) - explicitRemoveExtensionsPat = makeREstring( - removeExtensions, None, strings_are_regex=True) - - # Raw C header file generator. - genOpts['vulkan_json_gen.h'] = [ - JSONHeaderOutputGenerator, - JSONHeaderGeneratorOptions( - conventions = conventions, - filename = 'vulkan_json_gen.h', - directory = directory, - apiname = 'vulkansc', - profile = None, - versions = scVersions, - emitversions = scVersions, - defaultExtensions = 'vulkansc', - addExtensions = addExtensionsPat, - removeExtensions = explicitRemoveExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48) - ] - - # Raw C source file generator. - genOpts['vulkan_json_gen.c'] = [ - JSONCOutputGenerator, - JSONCGeneratorOptions( - conventions = conventions, - filename = 'vulkan_json_gen.c', - directory = directory, - apiname = 'vulkansc', - profile = None, - versions = scVersions, - emitversions = scVersions, - defaultExtensions = 'vulkansc', - addExtensions = addExtensionsPat, - removeExtensions = explicitRemoveExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48) - ] - - genOpts['vulkan_json_parser.hpp'] = [ - JSONParserGenerator, - JSONParserOptions( - conventions = conventions, - filename = 'vulkan_json_parser.hpp', - directory = directory, - apiname = 'vulkansc', - profile = None, - versions = scVersions, - emitversions = scVersions, - defaultExtensions = 'vulkansc', - addExtensions = addExtensionsPat, - removeExtensions = explicitRemoveExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - isCTS = isCTS, - alignFuncParam = 48) - ] - - # Unused - vulkan10.h target. - # It is possible to generate a header with just the Vulkan 1.0 + - # extension interfaces defined, but since the promoted KHR extensions - # are now defined in terms of the 1.1 interfaces, such a header is very - # similar to vulkan_core.h. - genOpts['vulkan10.h'] = [ - COutputGenerator, - CGeneratorOptions( - conventions = conventions, - filename = 'vulkan10.h', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = 'VK_VERSION_1_0', - emitversions = 'VK_VERSION_1_0', - defaultExtensions = None, - addExtensions = None, - removeExtensions = None, - emitExtensions = None, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48, - misracstyle = misracstyle, - misracppstyle = misracppstyle) - ] - - # Video header target - combines all video extension dependencies into a - # single header, at present. - genOpts['vk_video.h'] = [ - COutputGenerator, - CGeneratorOptions( - conventions = conventions, - filename = 'vk_video.h', - directory = directory, - genpath = None, - apiname = 'vulkan', - profile = None, - versions = None, - emitversions = None, - defaultExtensions = defaultExtensions, - addExtensions = addExtensionsPat, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = '', - apientry = '', - apientryp = '', - alignFuncParam = 48, - misracstyle = misracstyle, - misracppstyle = misracppstyle) - ] - - # Video extension 'Std' interfaces, each in its own header files - # These are not Vulkan extensions, or a part of the Vulkan API at all. - # They are treated in a similar fashion for generation purposes, but - # all required APIs for each interface must be explicitly required. - # - # Each element of the videoStd[] array is an extension name defining an - # interface, and is also the basis for the generated header file name. - - videoStd = [ - 'vulkan_video_codecs_common', - 'vulkan_video_codec_h264std', - 'vulkan_video_codec_h264std_decode', - 'vulkan_video_codec_h264std_encode', - 'vulkan_video_codec_h265std', - 'vulkan_video_codec_h265std_decode', - 'vulkan_video_codec_h265std_encode', - ] - - # Unused at present - # addExtensionRE = makeREstring(videoStd) - for codec in videoStd: - headername = f'{codec}.h' - - # Consider all of the codecs 'extensions', but only emit this one - emitExtensionRE = makeREstring([codec]) - - opts = CGeneratorOptions( - conventions = conventions, - filename = headername, - directory = directory, - genpath = None, - apiname = defaultAPIName, - mergeApiNames = mergeApiNames, - profile = None, - versions = None, - emitversions = None, - defaultExtensions = None, - addExtensions = emitExtensionRE, - removeExtensions = None, - emitExtensions = emitExtensionRE, - requireDepends = False, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = False, - protectFile = protectFile, - protectFeature = False, - alignFuncParam = 48, - ) - - genOpts[headername] = [ COutputGenerator, opts ] - - # Unused - vulkan11.h target. - # It is possible to generate a header with just the Vulkan 1.0 + - # extension interfaces defined, but since the promoted KHR extensions - # are now defined in terms of the 1.1 interfaces, such a header is very - # similar to vulkan_core.h. - genOpts['vulkan11.h'] = [ - COutputGenerator, - CGeneratorOptions( - conventions = conventions, - filename = 'vulkan11.h', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = '^VK_VERSION_1_[01]$', - emitversions = '^VK_VERSION_1_[01]$', - defaultExtensions = None, - addExtensions = None, - removeExtensions = None, - emitExtensions = None, - prefixText = prefixStrings + vkPrefixStrings, - genFuncPointers = True, - protectFile = protectFile, - protectFeature = False, - protectProto = '#ifndef', - protectProtoStr = 'VK_NO_PROTOTYPES', - apicall = 'VKAPI_ATTR ', - apientry = 'VKAPI_CALL ', - apientryp = 'VKAPI_PTR *', - alignFuncParam = 48, - misracstyle = misracstyle, - misracppstyle = misracppstyle) - ] - - genOpts['alias.h'] = [ - COutputGenerator, - CGeneratorOptions( - conventions = conventions, - filename = 'alias.h', - directory = directory, - genpath = None, - apiname = defaultAPIName, - profile = None, - versions = featuresPat, - emitversions = featuresPat, - defaultExtensions = defaultExtensions, - addExtensions = None, - removeExtensions = removeExtensionsPat, - emitExtensions = emitExtensionsPat, - prefixText = None, - genFuncPointers = False, - protectFile = False, - protectFeature = False, - protectProto = '', - protectProtoStr = '', - apicall = '', - apientry = '', - apientryp = '', - alignFuncParam = 36) - ] - # Serializer for spec genOpts['cereal'] = [ CerealGenerator, @@ -1038,22 +386,11 @@ def genTarget(args): createGenerator = genOpts[args.target][0] options = genOpts[args.target][1] - logDiag('* Building', args.target) - logDiag('* options.versions =', options.versions) - logDiag('* options.emitversions =', options.emitversions) - logDiag('* options.defaultExtensions =', options.defaultExtensions) - logDiag('* options.addExtensions =', options.addExtensions) - logDiag('* options.removeExtensions =', options.removeExtensions) - logDiag('* options.emitExtensions =', options.emitExtensions) - logDiag('* options.emitSpirv =', options.emitSpirv) - logDiag('* options.emitFormats =', options.emitFormats) - gen = createGenerator(errFile=errWarn, warnFile=errWarn, diagFile=diag) return (gen, options) else: - logErr('No generator options for unknown target:', args.target) return None @@ -1150,10 +487,6 @@ if __name__ == '__main__': else: diag = None - if args.time: - # Log diagnostics and warnings - setLogFile(setDiag = True, setWarn = True, filename = '-') - # Create the API generator & generator options (gen, options) = genTarget(args) @@ -1225,7 +558,6 @@ if __name__ == '__main__': endTimer(args.time, '* Time to parse ElementTree =') if args.dump: - logDiag('* Dumping registry to regdump.txt') reg.dumpReg(filehandle=open('regdump.txt', 'w', encoding='utf-8')) # Finally, use the output generator to create the requested target @@ -1235,6 +567,3 @@ if __name__ == '__main__': startTimer(args.time) reg.apiGen() endTimer(args.time, '* Time to generate ' + args.target + ' =') - - if not args.quiet: - logDiag('* Generated', args.target)