[clang] [llvm] [HLSL] Explicitly set the SPIR-V version with spv-target-env (PR #121961)

Steven Perron via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 07:05:11 PST 2025


================
@@ -1468,9 +1468,14 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
 
         // Set specific Vulkan version if applicable.
         if (const Arg *A = Args.getLastArg(options::OPT_fspv_target_env_EQ)) {
-          const llvm::StringSet<> ValidValues = {"vulkan1.2", "vulkan1.3"};
-          if (ValidValues.contains(A->getValue())) {
-            T.setOSName(A->getValue());
+          const llvm::StringMap<llvm::Triple::SubArchType> ValidTargets = {
+              {"vulkan1.2", llvm::Triple::SPIRVSubArch_v15},
+              {"vulkan1.3", llvm::Triple::SPIRVSubArch_v16}};
+
+          auto TargetInfo = ValidTargets.find(A->getValue());
+          if (TargetInfo != ValidTargets.end()) {
----------------
s-perron wrote:

I'm not sure I understand the question. If you are asking if we could possibly map a value for the `-fspv-target-env` option to that target triple, then the answer is no. We cannot do that before or after this change. We also could not do that in DXC.

If you are asking if we could get that target triple by using clang's `-triple` option, then yes you can. This does not affect the parsing of that other option. It only change how `-fspv-target-env` is used when using the DXC compatibility mode, and is intended to match the DXC behaviour.

https://github.com/llvm/llvm-project/pull/121961


More information about the llvm-commits mailing list