[clang] [llvm] [DirectX][DXIL] Set DXIL Version in DXIL target triple based on shader model version (PR #90809)

S. Bharadwaj Yadavalli via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 08:23:40 PDT 2024


================
@@ -1200,6 +1224,27 @@ std::string Triple::normalize(StringRef Str) {
     }
   }
 
+  // Normalize DXIL triple if it does not include DXIL version number.
+  // Determine DXIL version number using the minor version number of Shader
+  // Model version specified in target triple, if any. Prior to decoupling DXIL
+  // version numbering from that of Shader Model DXIL version 1.Y corresponds to
+  // SM 6.Y. E.g., dxilv1.Y-unknown-shadermodelX.Y-hull
+  if (Components[0] == "dxil") {
+    std::string DXILVerStr{"dxilv1."};
+    if (Components.size() > 2) {
+      // OS component specified
+      if (Components[2].starts_with("shadermodel6.")) {
+        Components[0] = DXILVerStr.append(
+            Components[2].drop_front(strlen("shadermodel6.")));
+      } else if (Components[2].starts_with("shadermodel")) {
+        // If shader model specified is other than 6.x, set DXIL Version to 1.0
+        Components[0] = DXILVerStr.append("0");
+      }
+    }
----------------
bharadwajy wrote:

The function `normalize` does not parse for `SubArch`. So, `SubArch` is not available  for checking.

An input DXIL triple string `Str` with or without version (e.g., `dxil-pc-shadermodel6.3` or `dxilv1.3-pc-shadermodel6.3` will set `Arch` to `Triple::dxil`. Implicit deduction and insertion of DXIL version should be done only is `Component[0] == "dxil"` and not otherwise. Hence the string equivalence check for "dxil" and not for `Arch == Triple::dxil`.

However, made code changes to leverage Arch and OS values already parsed as suggested. A couple of additional sanity checks are also added.


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


More information about the cfe-commits mailing list