[llvm-branch-commits] [llvm] [HLSLSemanticSignatures] Implement the optimal packing of elements (PR #218064)

Deric C. via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 25 16:50:09 PDT 2026


================
@@ -105,6 +105,42 @@ static uint8_t getStartColumn(uint8_t ColumnMask) {
   return countr_zero(ColumnMask);
 }
 
+// Returns a lower value for groups that must be packed earlier.
+static unsigned
+getOptimizedPackingPriority(const SemanticSignatureElement &Element,
+                            Triple::EnvironmentType ShaderStage, IOType IOTy) {
+  const SemanticInterpretation Interpretation =
+      getInterpretationKind(Element.SemanticKind, ShaderStage, IOTy);
+  assert((Interpretation != SemanticInterpretation::Invalid &&
+          Interpretation != SemanticInterpretation::Target) &&
+         "unexpected semantic interpretation for optimized packing");
+
+  if (Element.Cols == MaxSignatureCols &&
+      (Interpretation == SemanticInterpretation::Arbitrary ||
+       Interpretation == SemanticInterpretation::SV))
+    return 0;
+
+  if (Interpretation == SemanticInterpretation::TessFactor && Element.Rows > 1)
+    return 1;
+
+  switch (Interpretation) {
+  case SemanticInterpretation::Arbitrary:
+    return 2;
+  case SemanticInterpretation::SV:
+  case SemanticInterpretation::TessFactor:
+    return 3;
+  case SemanticInterpretation::ClipCull:
+    return 4;
+  case SemanticInterpretation::SGV:
+    return 5;
+  case SemanticInterpretation::NotAllocated:
+    return 6;
+  default:
+    break;
----------------
Icohedron wrote:

[SUGGESTION] Cover the enum instead of using a default so that `-Wswitch` will ensure there is a compile error in the case of a new `SemanticInterpretation`.

```suggestion
case SemanticInterpretation::Invalid:
case SemanticInterpretation::Target:
  break;
```

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


More information about the llvm-branch-commits mailing list