From c5a453e56985022deb820cbbb2ff5cd6a8347e34 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 1 Jun 2024 19:26:14 -0700 Subject: Support different SPIRV versions. (#4254) --- source/slang/slang.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 8b0012f1d..66e75a282 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1666,6 +1666,12 @@ HLSLToVulkanLayoutOptions* TargetRequest::getHLSLToVulkanLayoutOptions() return hlslToVulkanOptions.get(); } +void TargetRequest::setTargetCaps(CapabilitySet capSet) +{ + cookedCapabilities = capSet; + +} + CapabilitySet TargetRequest::getTargetCaps() { if(!cookedCapabilities.isEmpty()) @@ -1691,6 +1697,11 @@ CapabilitySet TargetRequest::getTargetCaps() // are available where can be directly encoded on the declarations. List atoms; + + // If the user specified a explicit profile, we should pull + // a corresponding atom representing the target version from the profile. + CapabilitySet profileCaps = CapabilitySet(optionSet.getProfile().getCapabilityName()); + bool isGLSLTarget = false; switch(getTarget()) { @@ -1704,7 +1715,40 @@ CapabilitySet TargetRequest::getTargetCaps() case CodeGenTarget::SPIRVAssembly: if (getOptionSet().shouldEmitSPIRVDirectly()) { - atoms.add(CapabilityName::spirv_1_5); + // Default to SPIRV 1.5 if the user has not specified a target version. + bool hasTargetVersionAtom = false; + if (!profileCaps.isEmpty()) + { + profileCaps.join(CapabilitySet(CapabilityName::spirv_1_0)); + for (auto profileCapAtomSet : profileCaps.getAtomSets()) + { + for (auto atom : profileCapAtomSet) + { + if (isTargetVersionAtom((CapabilityName)atom)) + { + atoms.add((CapabilityName)atom); + hasTargetVersionAtom = true; + } + } + } + } + if (!hasTargetVersionAtom) + { + atoms.add(CapabilityName::spirv_1_5); + } + // If the user specified any SPIR-V extensions in the profile, + // pull them in. + for (auto profileCapAtomSet : profileCaps.getAtomSets()) + { + for (auto atom : profileCapAtomSet) + { + if (isSpirvExtensionAtom((CapabilityName)atom)) + { + atoms.add((CapabilityName)atom); + hasTargetVersionAtom = true; + } + } + } } else { @@ -1752,9 +1796,7 @@ CapabilitySet TargetRequest::getTargetCaps() CapabilitySet targetCap = CapabilitySet(atoms); - CapabilitySet latestSpirvCapSet = CapabilitySet(CapabilityName::spirv_latest); - auto latestSpirvCapSetElements = latestSpirvCapSet.getAtomSets()->getElements(); - CapabilityName latestSpirvAtom = (CapabilityName)latestSpirvCapSetElements[latestSpirvCapSetElements.getCount()-2]; //-1 gets shader stage + CapabilityName latestSpirvAtom = getLatestSpirvAtom(); for (auto atomVal : optionSet.getArray(CompilerOptionName::Capability)) { -- cgit v1.2.3