Skip to content

Commit

Permalink
scripts: Remove manual header update step
Browse files Browse the repository at this point in the history
Make the spirv_validation_generator.py more robust to header updates by
replacing the hard-coded capability lists with ones generated from the
SPIR-V grammar.
  • Loading branch information
mikes-lunarg committed Mar 5, 2024
1 parent 4e00681 commit 5807ddc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions scripts/generate_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def RunGenerators(api: str, registry: str, grammar: str, directory: str, styleFi
'spirv_validation_helper.cpp' : {
'generator' : SpirvValidationHelperOutputGenerator,
'genCombined': False,
'options' : [grammar],
},
'spirv_grammar_helper.h' : {
'generator' : SpirvGrammarHelperOutputGenerator,
Expand Down
41 changes: 21 additions & 20 deletions scripts/generators/spirv_validation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,33 @@

import sys
import os
import json
from generators.vulkan_object import SpirvEnables
from generators.base_generator import BaseGenerator

#
# Generate SPIR-V validation for SPIR-V extensions and capabilities
class SpirvValidationHelperOutputGenerator(BaseGenerator):
def __init__(self):
def __init__(self, grammar):
BaseGenerator.__init__(self)

# Sometimes the Vulkan-Headers XML will mention new SPIR-V capability or extensions
# That require an update of the SPIRV-Headers which might not be ready to pull in.
# These 2 arrays SHOULD be empty when possible and when the SPIR-V Headers are updated these
# should be attempted to be cleared
self.capabilityExcludeList = [
'ClusterCullingShadingHUAWEI',
'TextureBlockMatch2QCOM',
'MaximallyReconvergesKHR'
]

# There are some enums that share the same value in the SPIR-V header.
# This array remove the duplicate to not print out, usually due to being the older value given
self.capabilityAliasList = [
'ShaderViewportIndexLayerNV',
'ShadingRateNV',
'FragmentBarycentricNV',
]
# that require an update of the SPIRV-Headers which might not be ready to pull in.
# Get the list of safe enum values to use from the SPIR-V grammar
self.capabilityList = []
self.capabilityAliasList = []
with open(grammar) as grammar_file:
grammar_dict = json.load(grammar_file)
for kind in grammar_dict['operand_kinds']:
if kind['kind'] == 'Capability':
enum_values = set()
for enum in kind['enumerants']:
# Detect aliases
if enum['value'] in enum_values:
self.capabilityAliasList.append(enum['enumerant'])
self.capabilityList.append(enum['enumerant'])
enum_values.add(enum['value'])
break;

# Promoted features structure in state_tracker.cpp are put in the VkPhysicalDeviceVulkan*Features structs
# but the XML can still list them. This list all promoted structs to ignore since they are aliased.
Expand Down Expand Up @@ -186,7 +187,7 @@ def generate(self):
out.append('static const std::unordered_multimap<uint32_t, RequiredSpirvInfo> spirvCapabilities = {\n')
for spirv in [x for x in self.vk.spirv if x.capability]:
for enable in [x for x in spirv.enable if x.struct is None or x.struct not in self.promotedFeatures]:
if spirv.name in self.capabilityExcludeList:
if spirv.name not in self.capabilityList:
out.append(' // Not found in current SPIR-V Headers\n //')
out.append(f' {{spv::Capability{spirv.name}, {self.createMapValue(spirv.name, enable, False)}}},\n')
out.append('};\n')
Expand All @@ -209,7 +210,7 @@ def generate(self):
out.append('static inline const char* string_SpvCapability(uint32_t input_value) {\n')
out.append(' switch ((spv::Capability)input_value) {\n')
for spirv in [x for x in self.vk.spirv if x.capability]:
if (spirv.name not in self.capabilityAliasList) and (spirv.name not in self.capabilityExcludeList):
if (spirv.name not in self.capabilityAliasList) and (spirv.name in self.capabilityList):
out.append(f' case spv::Capability{spirv.name}:\n')
out.append(f' return "{spirv.name}";\n')
out.append(' default:\n')
Expand Down Expand Up @@ -240,7 +241,7 @@ def generate(self):
static inline const char* SpvCapabilityRequirements(uint32_t capability) {
static const vvl::unordered_map<uint32_t, std::string_view> table {
''')
for spirv in [x for x in self.vk.spirv if x.capability and x.name not in self.capabilityExcludeList]:
for spirv in [x for x in self.vk.spirv if x.capability and x.name in self.capabilityList]:
requirment = ''
for index, enable in enumerate([x for x in spirv.enable if x.struct is None or x.struct not in self.promotedFeatures]):
requirment += ' OR ' if (index != 0) else ''
Expand Down

0 comments on commit 5807ddc

Please sign in to comment.