mirror of
https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
synced 2025-06-02 18:07:59 +00:00
Move vk_safe_struct to VUL
This code was being generated in both Vulkan-ValidationLayers and Vulkan-ExtensionLayer. Further uses are on the horizon so lets stop the copypasta. Also, add functions to manipulate extension lists and pNext chains, since many client layers have been doing that themselves.
This commit is contained in:
parent
d90f5c7eb1
commit
cdd0e00cff
26 changed files with 91119 additions and 68 deletions
|
@ -1,12 +1,14 @@
|
|||
#!/usr/bin/python3 -i
|
||||
#
|
||||
# Copyright 2023-2024 The Khronos Group Inc.
|
||||
# Copyright 2023-2024 Valve Corporation
|
||||
# Copyright 2023-2024 LunarG, Inc.
|
||||
# Copyright 2023-2024 RasterGrid Kft.
|
||||
# Copyright (c) 2023-2024 Valve Corporation
|
||||
# Copyright (c) 2023-2024 LunarG, Inc.
|
||||
# Copyright (c) 2023-2024 RasterGrid Kft.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import pickle
|
||||
import os
|
||||
import tempfile
|
||||
from generators.vulkan_object import (VulkanObject,
|
||||
Extension, Version, Handle, Param, Queues, CommandScope, Command,
|
||||
EnumField, Enum, Flag, Bitmask, Member, Struct,
|
||||
|
@ -70,6 +72,11 @@ def SetMergedApiNames(names: str) -> None:
|
|||
global mergedApiNames
|
||||
mergedApiNames = names
|
||||
|
||||
cachingEnabled = False
|
||||
def EnableCaching() -> None:
|
||||
global cachingEnabled
|
||||
cachingEnabled = True
|
||||
|
||||
# This class is a container for any source code, data, or other behavior that is necessary to
|
||||
# customize the generator script for a specific target API variant (e.g. Vulkan SC). As such,
|
||||
# all of these API-specific interfaces and their use in the generator script are part of the
|
||||
|
@ -111,7 +118,7 @@ class BaseGeneratorOptions(GeneratorOptions):
|
|||
self.apicall = 'VKAPI_ATTR '
|
||||
self.apientry = 'VKAPI_CALL '
|
||||
self.apientryp = 'VKAPI_PTR *'
|
||||
self.alignFuncParam = 48
|
||||
self.alignFuncParam = 48
|
||||
|
||||
#
|
||||
# This object handles all the parsing from reg.py generator scripts in the Vulkan-Headers
|
||||
|
@ -219,7 +226,6 @@ class BaseGenerator(OutputGenerator):
|
|||
enum.fieldExtensions.extend([extension] if extension not in enum.fieldExtensions else [])
|
||||
enumField.extensions.extend([extension] if extension not in enumField.extensions else [])
|
||||
extension.enumFields[group].extend([enumField] if enumField not in extension.enumFields[group] else [])
|
||||
|
||||
if group in self.vk.bitmasks:
|
||||
if group not in extension.flags:
|
||||
extension.flags[group] = [] # Dict needs init
|
||||
|
@ -229,11 +235,10 @@ class BaseGenerator(OutputGenerator):
|
|||
|
||||
for flags in [x for x in bitmask.flags if x.name in flagList]:
|
||||
# Make sure list is unique
|
||||
bitmask.extensions.extend([extension] if extension not in bitmask.extensions else [])
|
||||
bitmask.flagExtensions.extend([extension] if extension not in bitmask.flagExtensions else [])
|
||||
flags.extensions.extend([extension] if extension not in flags.extensions else [])
|
||||
extension.flags[group].extend([flags] if flags not in extension.flags[group] else [])
|
||||
|
||||
|
||||
# Need to do 'enum'/'bitmask' after 'enumconstant' has applied everything so we can add implicit extensions
|
||||
#
|
||||
# Sometimes two extensions enable an Enum, but the newer extension version has extra flags allowed
|
||||
|
@ -267,17 +272,18 @@ class BaseGenerator(OutputGenerator):
|
|||
for required in dict:
|
||||
for group in dict[required]:
|
||||
for bitmaskName in dict[required][group]:
|
||||
isAlias = bitmaskName in self.enumAliasMap
|
||||
bitmaskName = bitmaskName.replace('Flags', 'FlagBits') # Works since Flags isn't repeated in name
|
||||
isAlias = bitmaskName in self.bitmaskAliasMap
|
||||
bitmaskName = self.bitmaskAliasMap[bitmaskName] if isAlias else bitmaskName
|
||||
if bitmaskName in self.vk.bitmasks:
|
||||
bitmask = self.vk.bitmasks[bitmaskName]
|
||||
bitmask.extensions.extend([extension] if extension not in bitmask.extensions else [])
|
||||
extension.bitmask.extend([bitmask] if bitmask not in extension.bitmasks else [])
|
||||
extension.bitmasks.extend([bitmask] if bitmask not in extension.bitmasks else [])
|
||||
# Update flags with implicit base extension
|
||||
if isAlias:
|
||||
continue
|
||||
bitmask.flagExtensions.extend([extension] if extension not in enum.flagExtensions else [])
|
||||
for flag in [x for x in enum.flags if (not x.extensions or (x.extensions and all(e in enum.extensions for e in x.extensions)))]:
|
||||
bitmask.flagExtensions.extend([extension] if extension not in bitmask.flagExtensions else [])
|
||||
for flag in [x for x in bitmask.flags if (not x.extensions or (x.extensions and all(e in bitmask.extensions for e in x.extensions)))]:
|
||||
flag.extensions.extend([extension] if extension not in flag.extensions else [])
|
||||
if bitmaskName not in extension.flags:
|
||||
extension.flags[bitmaskName] = [] # Dict needs init
|
||||
|
@ -304,9 +310,17 @@ class BaseGenerator(OutputGenerator):
|
|||
for struct in [x for x in self.vk.structs.values() if not x.returnedOnly]:
|
||||
for enum in [self.vk.enums[x.type] for x in struct.members if x.type in self.vk.enums]:
|
||||
enum.returnedOnly = False
|
||||
for bitmask in [self.vk.bitmasks[x.type] for x in struct.members if x.type in self.vk.bitmasks]:
|
||||
bitmask.returnedOnly = False
|
||||
for bitmask in [self.vk.bitmasks[x.type.replace('Flags', 'FlagBits')] for x in struct.members if x.type.replace('Flags', 'FlagBits') in self.vk.bitmasks]:
|
||||
bitmask.returnedOnly = False
|
||||
for command in self.vk.commands.values():
|
||||
for enum in [self.vk.enums[x.type] for x in command.params if x.type in self.vk.enums]:
|
||||
enum.returnedOnly = False
|
||||
for bitmask in [self.vk.bitmasks[x.type] for x in command.params if x.type in self.vk.bitmasks]:
|
||||
bitmask.returnedOnly = False
|
||||
for bitmask in [self.vk.bitmasks[x.type.replace('Flags', 'FlagBits')] for x in command.params if x.type.replace('Flags', 'FlagBits') in self.vk.bitmasks]:
|
||||
bitmask.returnedOnly = False
|
||||
|
||||
# Turn handle parents into pointers to classess
|
||||
for handle in [x for x in self.vk.handles.values() if x.parent is not None]:
|
||||
|
@ -327,9 +341,26 @@ class BaseGenerator(OutputGenerator):
|
|||
# All inherited generators should run from here
|
||||
self.generate()
|
||||
|
||||
if cachingEnabled:
|
||||
cachePath = os.path.join(tempfile.gettempdir(), f'vkobject_{os.getpid()}')
|
||||
if not os.path.isfile(cachePath):
|
||||
cacheFile = open(cachePath, 'wb')
|
||||
pickle.dump(self.vk, cacheFile)
|
||||
cacheFile.close()
|
||||
|
||||
# This should not have to do anything but call into OutputGenerator
|
||||
OutputGenerator.endFile(self)
|
||||
|
||||
#
|
||||
# Bypass the entire processing and load in the VkObject data
|
||||
# Still need to handle the beingFile/endFile for reg.py
|
||||
def generateFromCache(self, cacheVkObjectData, genOpts):
|
||||
OutputGenerator.beginFile(self, genOpts)
|
||||
self.filename = genOpts.filename
|
||||
self.vk = cacheVkObjectData
|
||||
self.generate()
|
||||
OutputGenerator.endFile(self)
|
||||
|
||||
#
|
||||
# Processing point at beginning of each extension definition
|
||||
def beginFeature(self, interface, emit):
|
||||
|
@ -337,7 +368,6 @@ class BaseGenerator(OutputGenerator):
|
|||
platform = interface.get('platform')
|
||||
self.featureExtraProtec = self.vk.platforms[platform] if platform in self.vk.platforms else None
|
||||
protect = self.vk.platforms[platform] if platform in self.vk.platforms else None
|
||||
|
||||
name = interface.get('name')
|
||||
|
||||
if interface.tag == 'extension':
|
||||
|
@ -463,7 +493,7 @@ class BaseGenerator(OutputGenerator):
|
|||
# fields also have their own protect
|
||||
groupProtect = self.currentExtension.protect if hasattr(self.currentExtension, 'protect') and self.currentExtension.protect is not None else None
|
||||
enumElem = groupinfo.elem
|
||||
bitwidth = 32 if enumElem.get('bitwidth') is None else enumElem.get('bitwidth')
|
||||
bitwidth = 32 if enumElem.get('bitwidth') is None else int(enumElem.get('bitwidth'))
|
||||
fields = []
|
||||
if enumElem.get('type') == "enum":
|
||||
if alias is not None:
|
||||
|
@ -514,7 +544,7 @@ class BaseGenerator(OutputGenerator):
|
|||
fields.append(Flag(flagName, protect, flagValue, flagMultiBit, flagZero, []))
|
||||
|
||||
flagName = groupName.replace('FlagBits', 'Flags')
|
||||
self.vk.bitmasks[groupName] = Bitmask(groupName, flagName, groupProtect, bitwidth, fields, [], [])
|
||||
self.vk.bitmasks[groupName] = Bitmask(groupName, flagName, groupProtect, bitwidth, True, fields, [], [])
|
||||
|
||||
def genType(self, typeInfo, typeName, alias):
|
||||
OutputGenerator.genType(self, typeInfo, typeName, alias)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue