1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!/usr/bin/python3 -i
#
# Copyright (c) 2023-2024 Valve Corporation
# Copyright (c) 2023-2024 LunarG, Inc.
#
# SPDX-License-Identifier: Apache-2.0
import os
import sys
import json
# Build a set of all vuid text strings found in validusage.json
def buildListVUID(valid_usage_file: str) -> set:
# Walk the JSON-derived dict and find all "vuid" key values
def ExtractVUIDs(vuid_dict):
if hasattr(vuid_dict, 'items'):
for key, value in vuid_dict.items():
if key == "vuid":
yield value
elif isinstance(value, dict):
for vuid in ExtractVUIDs(value):
yield vuid
elif isinstance (value, list):
for listValue in value:
for vuid in ExtractVUIDs(listValue):
yield vuid
valid_vuids = set()
if not os.path.isfile(valid_usage_file):
print(f'Error: Could not find, or error loading {valid_usage_file}')
sys.exit(1)
json_file = open(valid_usage_file, 'r', encoding='utf-8')
vuid_dict = json.load(json_file)
json_file.close()
if len(vuid_dict) == 0:
print(f'Error: Failed to load {valid_usage_file}')
sys.exit(1)
for json_vuid_string in ExtractVUIDs(vuid_dict):
valid_vuids.add(json_vuid_string)
# List of VUs that should exists, but have a spec bug
for vuid in [
# https://gitlab.khronos.org/vulkan/vulkan/-/issues/3582
"VUID-VkCopyImageToImageInfoEXT-commonparent",
"VUID-vkUpdateDescriptorSetWithTemplate-descriptorSet-parent",
"VUID-vkUpdateVideoSessionParametersKHR-videoSessionParameters-parent",
"VUID-vkDestroyVideoSessionParametersKHR-videoSessionParameters-parent",
"VUID-vkGetDescriptorSetHostMappingVALVE-descriptorSet-parent",
]:
valid_vuids.add(vuid)
return valid_vuids
# Will do a sanity check the VUID exists
def getVUID(valid_vuids: set, vuid: str, quotes: bool = True) -> str:
if vuid not in valid_vuids:
print(f'Warning: Could not find {vuid} in validusage.json')
vuid = vuid.replace('VUID-', 'UNASSIGNED-')
return vuid if not quotes else f'"{vuid}"'
class PlatformGuardHelper():
"""Used to elide platform guards together, so redundant #endif then #ifdefs are removed
Note - be sure to call add_guard(None) when done to add a trailing #endif if needed
"""
def __init__(self):
self.current_guard = None
def add_guard(self, guard, extra_newline = False):
out = []
if self.current_guard != guard and self.current_guard is not None:
out.append(f'#endif // {self.current_guard}\n')
if extra_newline:
out.append('\n')
if self.current_guard != guard and guard is not None:
out.append(f'#ifdef {guard}\n')
self.current_guard = guard
return out
# The SPIR-V grammar json doesn't have an easy way to detect these, so have listed by hand
# If we are missing one, its not critical, the goal of this list is to reduce the generated output size
def IsNonVulkanSprivCapability(capability):
return capability in [
'Kernel',
'Vector16',
'Float16Buffer',
'ImageBasic',
'ImageReadWrite',
'ImageMipmap',
'DeviceEnqueue',
'SubgroupDispatch',
'Pipes',
'LiteralSampler',
'NamedBarrier',
'PipeStorage',
'SubgroupShuffleINTEL',
'SubgroupShuffleINTEL',
'SubgroupBufferBlockIOINTEL',
'SubgroupImageBlockIOINTEL',
'SubgroupImageMediaBlockIOINTEL',
'RoundToInfinityINTEL',
'FloatingPointModeINTEL',
'IndirectReferencesINTEL',
'AsmINTEL',
'VectorComputeINTEL',
'VectorAnyINTEL',
'SubgroupAvcMotionEstimationINTEL',
'SubgroupAvcMotionEstimationIntraINTEL',
'SubgroupAvcMotionEstimationChromaINTEL',
'VariableLengthArrayINTEL',
'FunctionFloatControlINTEL',
'FPGAMemoryAttributesINTEL',
'FPFastMathModeINTEL',
'ArbitraryPrecisionIntegersINTEL',
'ArbitraryPrecisionFloatingPointINTEL',
'UnstructuredLoopControlsINTEL',
'FPGALoopControlsINTEL',
'KernelAttributesINTEL',
'FPGAKernelAttributesINTEL',
'FPGAMemoryAccessesINTEL',
'FPGAClusterAttributesINTEL',
'LoopFuseINTEL',
'FPGADSPControlINTEL',
'MemoryAccessAliasingINTEL',
'FPGAInvocationPipeliningAttributesINTEL',
'FPGABufferLocationINTEL',
'ArbitraryPrecisionFixedPointINTEL',
'USMStorageClassesINTEL',
'RuntimeAlignedAttributeINTEL',
'IOPipesINTEL',
'BlockingPipesINTEL',
'FPGARegINTEL',
'LongCompositesINTEL',
'OptNoneINTEL',
'DebugInfoModuleINTEL',
'BFloat16ConversionINTEL',
'SplitBarrierINTEL',
'FPGAClusterAttributesV2INTEL',
'FPGAKernelAttributesv2INTEL',
'FPMaxErrorINTEL',
'FPGALatencyControlINTEL',
'FPGAArgumentInterfacesINTEL',
'GlobalVariableHostAccessINTEL',
'GlobalVariableFPGADecorationsINTEL',
'MaskedGatherScatterINTEL',
'CacheControlsINTEL',
'RegisterLimitsINTEL'
]
|