[llvm] Add support for PSV EntryFunctionName (PR #84409)

Cooper Partin via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 19 12:18:27 PDT 2024


https://github.com/coopp updated https://github.com/llvm/llvm-project/pull/84409

>From d52ff6e2bec60c121811229e75e27a6f6e5cc315 Mon Sep 17 00:00:00 2001
From: Cooper Partin <coopp at ntdev.microsoft.com>
Date: Thu, 7 Mar 2024 16:34:44 -0800
Subject: [PATCH 1/6] Add support for PSV EntryFunctionName

---
 llvm/include/llvm/BinaryFormat/DXContainer.h  |  13 +++
 llvm/include/llvm/MC/DXContainerPSVInfo.h     |   2 +-
 llvm/include/llvm/Object/DXContainer.h        |  16 ++-
 .../include/llvm/ObjectYAML/DXContainerYAML.h |   3 +-
 llvm/lib/MC/DXContainerPSVInfo.cpp            |   6 +-
 llvm/lib/Object/DXContainer.cpp               |  15 ++-
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp    |   2 +-
 llvm/lib/ObjectYAML/DXContainerYAML.cpp       |  11 ++
 .../DXContainer/PSVv3-amplification.yaml      |  97 ++++++++++++++++
 .../ObjectYAML/DXContainer/PSVv3-compute.yaml |  95 +++++++++++++++
 .../ObjectYAML/DXContainer/PSVv3-domain.yaml  | 105 +++++++++++++++++
 .../DXContainer/PSVv3-geometry.yaml           | 105 +++++++++++++++++
 .../ObjectYAML/DXContainer/PSVv3-hull.yaml    | 107 +++++++++++++++++
 .../ObjectYAML/DXContainer/PSVv3-mesh.yaml    | 109 ++++++++++++++++++
 .../ObjectYAML/DXContainer/PSVv3-pixel.yaml   |  99 ++++++++++++++++
 .../ObjectYAML/DXContainer/PSVv3-vertex.yaml  |  97 ++++++++++++++++
 llvm/tools/obj2yaml/dxcontainer2yaml.cpp      |   3 +
 17 files changed, 876 insertions(+), 9 deletions(-)
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml

diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index c3dcd568216b71..9da262a8084add 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -424,6 +424,19 @@ struct ResourceBindInfo : public v0::ResourceBindInfo {
 };
 
 } // namespace v2
+
+namespace v3 {
+struct RuntimeInfo : public v2::RuntimeInfo {
+  uint32_t EntryFunctionName;
+
+  void swapBytes() { sys::swapByteOrder(EntryFunctionName); }
+
+  void swapBytes(Triple::EnvironmentType Stage) {
+    v2::RuntimeInfo::swapBytes(Stage);
+  }
+};
+
+} // namespace v3
 } // namespace PSV
 
 #define COMPONENT_PRECISION(Val, Enum) Enum = Val,
diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h
index 7d21c18d252f1c..5cd0c5262b552e 100644
--- a/llvm/include/llvm/MC/DXContainerPSVInfo.h
+++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h
@@ -46,7 +46,7 @@ struct PSVSignatureElement {
 // RuntimeInfo.
 struct PSVRuntimeInfo {
   bool IsFinalized = false;
-  dxbc::PSV::v2::RuntimeInfo BaseData;
+  dxbc::PSV::v3::RuntimeInfo BaseData;
   SmallVector<dxbc::PSV::v2::ResourceBindInfo> Resources;
   SmallVector<PSVSignatureElement> InputElements;
   SmallVector<PSVSignatureElement> OutputElements;
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index a7f18c79969803..cdf709fd848128 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -125,7 +125,8 @@ class PSVRuntimeInfo {
   uint32_t Size;
   using InfoStruct =
       std::variant<std::monostate, dxbc::PSV::v0::RuntimeInfo,
-                   dxbc::PSV::v1::RuntimeInfo, dxbc::PSV::v2::RuntimeInfo>;
+                   dxbc::PSV::v1::RuntimeInfo, dxbc::PSV::v2::RuntimeInfo,
+                   dxbc::PSV::v3::RuntimeInfo>;
   InfoStruct BasicInfo;
   ResourceArray Resources;
   StringRef StringTable;
@@ -151,9 +152,11 @@ class PSVRuntimeInfo {
   ResourceArray getResources() const { return Resources; }
 
   uint32_t getVersion() const {
-    return Size >= sizeof(dxbc::PSV::v2::RuntimeInfo)
-               ? 2
-               : (Size >= sizeof(dxbc::PSV::v1::RuntimeInfo) ? 1 : 0);
+    return Size >= sizeof(dxbc::PSV::v3::RuntimeInfo)
+               ? 3
+               : (Size >= sizeof(dxbc::PSV::v2::RuntimeInfo)     ? 2
+                  : (Size >= sizeof(dxbc::PSV::v1::RuntimeInfo)) ? 1
+                                                                 : 0);
   }
 
   uint32_t getResourceStride() const { return Resources.Stride; }
@@ -161,6 +164,11 @@ class PSVRuntimeInfo {
   const InfoStruct &getInfo() const { return BasicInfo; }
 
   template <typename T> const T *getInfoAs() const {
+    if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
+      return static_cast<const T *>(P);
+    if (std::is_same<T, dxbc::PSV::v3::RuntimeInfo>::value)
+      return nullptr;
+
     if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
       return static_cast<const T *>(P);
     if (std::is_same<T, dxbc::PSV::v2::RuntimeInfo>::value)
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 66a6ac70bbea10..cad2e606d7db45 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -107,7 +107,7 @@ struct PSVInfo {
   // the format.
   uint32_t Version;
 
-  dxbc::PSV::v2::RuntimeInfo Info;
+  dxbc::PSV::v3::RuntimeInfo Info;
   uint32_t ResourceStride;
   SmallVector<ResourceBindInfo> Resources;
   SmallVector<SignatureElement> SigInputElements;
@@ -127,6 +127,7 @@ struct PSVInfo {
   PSVInfo(const dxbc::PSV::v0::RuntimeInfo *P, uint16_t Stage);
   PSVInfo(const dxbc::PSV::v1::RuntimeInfo *P);
   PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P);
+  PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P);
 };
 
 struct SignatureParameter {
diff --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp
index 48182fcd31df06..82edf9f4bd6fb9 100644
--- a/llvm/lib/MC/DXContainerPSVInfo.cpp
+++ b/llvm/lib/MC/DXContainerPSVInfo.cpp
@@ -81,9 +81,13 @@ void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const {
     BindingSize = sizeof(dxbc::PSV::v0::ResourceBindInfo);
     break;
   case 2:
-  default:
     InfoSize = sizeof(dxbc::PSV::v2::RuntimeInfo);
     BindingSize = sizeof(dxbc::PSV::v2::ResourceBindInfo);
+    break;
+  case 3:
+  default:
+    InfoSize = sizeof(dxbc::PSV::v3::RuntimeInfo);
+    BindingSize = sizeof(dxbc::PSV::v2::ResourceBindInfo);
   }
   // Write the size of the info.
 
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 0401c20b98ec8e..7c6daba163f61e 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -247,7 +247,14 @@ Error DirectX::PSVRuntimeInfo::parse(uint16_t ShaderKind) {
   const uint32_t PSVVersion = getVersion();
 
   // Detect the PSVVersion by looking at the size field.
-  if (PSVVersion == 2) {
+  if (PSVVersion == 3) {
+    v3::RuntimeInfo Info;
+    if (Error Err = readStruct(PSVInfoData, Current, Info))
+      return Err;
+    if (sys::IsBigEndianHost)
+      Info.swapBytes(ShaderStage);
+    BasicInfo = Info;
+  } else if (PSVVersion == 2) {
     v2::RuntimeInfo Info;
     if (Error Err = readStruct(PSVInfoData, Current, Info))
       return Err;
@@ -425,6 +432,8 @@ Error DirectX::PSVRuntimeInfo::parse(uint16_t ShaderKind) {
 }
 
 uint8_t DirectX::PSVRuntimeInfo::getSigInputCount() const {
+  if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
+    return P->SigInputElements;
   if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
     return P->SigInputElements;
   if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
@@ -433,6 +442,8 @@ uint8_t DirectX::PSVRuntimeInfo::getSigInputCount() const {
 }
 
 uint8_t DirectX::PSVRuntimeInfo::getSigOutputCount() const {
+  if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
+    return P->SigOutputElements;
   if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
     return P->SigOutputElements;
   if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
@@ -441,6 +452,8 @@ uint8_t DirectX::PSVRuntimeInfo::getSigOutputCount() const {
 }
 
 uint8_t DirectX::PSVRuntimeInfo::getSigPatchOrPrimCount() const {
+  if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
+    return P->SigPatchOrPrimElements;
   if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
     return P->SigPatchOrPrimElements;
   if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 09a5e41c71234f..da2cdd7cac8800 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -198,7 +198,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
       if (!P.Info.has_value())
         continue;
       mcdxbc::PSVRuntimeInfo PSV;
-      memcpy(&PSV.BaseData, &P.Info->Info, sizeof(dxbc::PSV::v2::RuntimeInfo));
+      memcpy(&PSV.BaseData, &P.Info->Info, sizeof(dxbc::PSV::v3::RuntimeInfo));
       PSV.Resources = P.Info->Resources;
 
       for (auto El : P.Info->SigInputElements)
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 1f03f2c7d39966..9b623c00af2668 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -74,6 +74,12 @@ DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P)
   memcpy(&Info, P, sizeof(dxbc::PSV::v2::RuntimeInfo));
 }
 
+DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P)
+    : Version(3) {
+  memset(&Info, 0, sizeof(Info));
+  memcpy(&Info, P, sizeof(dxbc::PSV::v3::RuntimeInfo));
+}
+
 namespace yaml {
 
 void MappingTraits<DXContainerYAML::VersionTuple>::mapping(
@@ -347,6 +353,11 @@ void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO &IO) {
   IO.mapRequired("NumThreadsX", Info.NumThreadsX);
   IO.mapRequired("NumThreadsY", Info.NumThreadsY);
   IO.mapRequired("NumThreadsZ", Info.NumThreadsZ);
+
+  if (Version == 2)
+    return;
+
+  IO.mapRequired("EntryFunctionName", Info.EntryFunctionName);
 }
 
 } // namespace llvm
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
new file mode 100644
index 00000000000000..92ceac5b52ffae
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
@@ -0,0 +1,97 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     14
+      PayloadSizeInBytes: 4092
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      SigInputVectors: 0
+      SigOutputVectors: [ 8, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      14
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     14
+# CHECK-NEXT: PayloadSizeInBytes: 4092
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
new file mode 100644
index 00000000000000..c9c6cf85879449
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
@@ -0,0 +1,95 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     5
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      SigInputVectors: 0
+      SigOutputVectors: [ 8, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      5
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     5
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
new file mode 100644
index 00000000000000..6584e90f82210b
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
@@ -0,0 +1,105 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     4
+      InputControlPointCount: 1024
+      OutputPositionPresent: 1
+      TessellatorDomain: 2056
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      SigPatchConstOrPrimVectors:  0
+      SigInputVectors: 0
+      SigOutputVectors: [ 0, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+      PatchOutputMap: []
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      4
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     4
+# CHECK-NEXT: InputControlPointCount: 1024
+# CHECK-NEXT: OutputPositionPresent: 1
+# CHECK-NEXT: TessellatorDomain: 2056
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: SigPatchConstOrPrimVectors:  0
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 0, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: PatchOutputMap: [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
new file mode 100644
index 00000000000000..43d9f70dba5eec
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
@@ -0,0 +1,105 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     2
+      InputPrimitive: 1024
+      OutputTopology: 4096
+      OutputStreamMask: 2056
+      OutputPositionPresent: 1
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      MaxVertexCount:  4096
+      SigInputVectors: 0
+      SigOutputVectors: [ 8, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      2
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     2
+# CHECK-NEXT: InputPrimitive: 1024
+# CHECK-NEXT: OutputTopology: 4096
+# CHECK-NEXT: OutputStreamMask: 2056
+# CHECK-NEXT: OutputPositionPresent: 1
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: MaxVertexCount:  4096
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
new file mode 100644
index 00000000000000..7b1b902fe9a3ae
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
@@ -0,0 +1,107 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     3
+      InputControlPointCount: 1024
+      OutputControlPointCount: 4096
+      TessellatorDomain: 2056
+      TessellatorOutputPrimitive: 8192
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      SigPatchConstOrPrimVectors:  0
+      SigInputVectors: 0
+      SigOutputVectors: [ 0, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+      InputPatchMap: []
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      3
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     3
+# CHECK-NEXT: InputControlPointCount: 1024
+# CHECK-NEXT: OutputControlPointCount: 4096
+# CHECK-NEXT: TessellatorDomain: 2056
+# CHECK-NEXT: TessellatorOutputPrimitive: 8192
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: SigPatchConstOrPrimVectors:  0
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 0, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: InputPatchMap: [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
new file mode 100644
index 00000000000000..0df2312738b92f
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
@@ -0,0 +1,109 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     13
+      GroupSharedBytesUsed: 1024
+      GroupSharedBytesDependentOnViewID: 2056
+      PayloadSizeInBytes: 4092
+      MaxOutputVertices: 8196
+      MaxOutputPrimitives: 4092
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      SigPrimVectors:  128
+      MeshOutputTopology: 16
+      SigInputVectors: 0
+      SigOutputVectors: [ 8, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      13
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     13
+# CHECK-NEXT: GroupSharedBytesUsed: 1024
+# CHECK-NEXT: GroupSharedBytesDependentOnViewID: 2056
+# CHECK-NEXT: PayloadSizeInBytes: 4092
+# CHECK-NEXT: MaxOutputVertices: 8196
+# CHECK-NEXT: MaxOutputPrimitives: 4092
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: SigPrimVectors:  128
+# CHECK-NEXT: MeshOutputTopology: 16
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
new file mode 100644
index 00000000000000..7aae2c0e8bbfa6
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
@@ -0,0 +1,99 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     0
+      DepthOutput:     7
+      SampleFrequency: 96
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      SigInputVectors: 0
+      SigOutputVectors: [ 8, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      0
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     0
+# CHECK-NEXT: DepthOutput:     7
+# CHECK-NEXT: SampleFrequency: 96
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
new file mode 100644
index 00000000000000..c6f8d3bcf9a9de
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
@@ -0,0 +1,97 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+  PartCount:       2
+Parts:
+  - Name:            PSV0
+    Size:            144
+    PSVInfo:
+      Version:         3
+      ShaderStage:     1
+      OutputPositionPresent: 1
+      MinimumWaveLaneCount: 0
+      MaximumWaveLaneCount: 4294967295
+      UsesViewID:      0
+      SigInputVectors: 0
+      SigOutputVectors: [ 8, 16, 32, 64 ]
+      NumThreadsX:     512
+      NumThreadsY:     1024
+      NumThreadsZ:     2048
+      EntryFunctionName: 1
+      ResourceStride:       24
+      Resources:
+        - Type:            1
+          Space:           2
+          LowerBound:      3
+          UpperBound:      4
+          Kind:            5
+          Flags:           6
+        - Type:            128
+          Space:           32768
+          LowerBound:      8388608
+          UpperBound:      2147483648
+          Kind:            65535
+          Flags:           16776960
+      SigInputElements: []
+      SigOutputElements: []
+      SigPatchOrPrimElements: []
+      InputOutputMap:
+        - [  ]
+        - [  ]
+        - [  ]
+        - [  ]
+  - Name:            DXIL
+    Size:            24
+    Program:
+      MajorVersion:    6
+      MinorVersion:    0
+      ShaderKind:      1
+      Size:            6
+      DXILMajorVersion: 0
+      DXILMinorVersion: 1
+      DXILSize:        0
+...
+
+# CHECK: Name:            PSV0
+# CHECK: PSVInfo:
+# CHECK-NEXT: Version:         3
+# CHECK-NEXT: ShaderStage:     1
+# CHECK-NEXT: OutputPositionPresent: 1
+# CHECK-NEXT: MinimumWaveLaneCount: 0
+# CHECK-NEXT: MaximumWaveLaneCount: 4294967295
+# CHECK-NEXT: UsesViewID:      0
+# CHECK-NEXT: SigInputVectors: 0
+# CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ]
+# CHECK-NEXT: NumThreadsX:     512
+# CHECK-NEXT: NumThreadsY:     1024
+# CHECK-NEXT: NumThreadsZ:     2048
+# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: ResourceStride: 24
+# CHECK-NEXT: Resources:
+# CHECK-NEXT: - Type:            1
+# CHECK-NEXT: Space:           2
+# CHECK-NEXT: LowerBound:      3
+# CHECK-NEXT: UpperBound:      4
+# CHECK-NEXT: Kind:            5
+# CHECK-NEXT: Flags:           6
+# CHECK-NEXT: - Type:            128
+# CHECK-NEXT: Space:           32768
+# CHECK-NEXT: LowerBound:      8388608
+# CHECK-NEXT: UpperBound:      2147483648
+# CHECK-NEXT: Kind:            65535
+# CHECK-NEXT: Flags:           16776960
+# CHECK-NEXT: SigInputElements: []
+# CHECK-NEXT: SigOutputElements: []
+# CHECK-NEXT: SigPatchOrPrimElements: []
+# CHECK-NEXT: InputOutputMap:
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT:   - [  ]
+# CHECK-NEXT: Name
diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
index b58d7cd952aff0..8447c2490303bd 100644
--- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
+++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
@@ -99,6 +99,9 @@ dumpDXContainer(MemoryBufferRef Source) {
       else if (const auto *P =
                    std::get_if<dxbc::PSV::v2::RuntimeInfo>(&PSVInfo->getInfo()))
         NewPart.Info = DXContainerYAML::PSVInfo(P);
+      else if (const auto *P =
+                   std::get_if<dxbc::PSV::v3::RuntimeInfo>(&PSVInfo->getInfo()))
+        NewPart.Info = DXContainerYAML::PSVInfo(P);
       NewPart.Info->ResourceStride = PSVInfo->getResourceStride();
       for (auto Res : PSVInfo->getResources())
         NewPart.Info->Resources.push_back(Res);

>From e84d33cd2e99532f652ab48b74a687f094aa66d1 Mon Sep 17 00:00:00 2001
From: Cooper Partin <coopp at ntdev.microsoft.com>
Date: Wed, 13 Mar 2024 16:07:38 -0700
Subject: [PATCH 2/6] Updated change to use a string in the YML instead of an
 offset and added writing of the entry point into a proper string table

---
 llvm/include/llvm/MC/DXContainerPSVInfo.h     | 82 +++++++++++++++++++
 .../include/llvm/ObjectYAML/DXContainerYAML.h |  4 +-
 llvm/lib/MC/DXContainerPSVInfo.cpp            | 79 ++----------------
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp    |  1 +
 llvm/lib/ObjectYAML/DXContainerYAML.cpp       | 10 ++-
 .../DXContainer/PSVv3-amplification.yaml      |  4 +-
 .../ObjectYAML/DXContainer/PSVv3-compute.yaml |  4 +-
 .../ObjectYAML/DXContainer/PSVv3-domain.yaml  |  4 +-
 .../DXContainer/PSVv3-geometry.yaml           |  4 +-
 .../ObjectYAML/DXContainer/PSVv3-hull.yaml    |  4 +-
 .../ObjectYAML/DXContainer/PSVv3-mesh.yaml    |  4 +-
 .../ObjectYAML/DXContainer/PSVv3-pixel.yaml   |  4 +-
 .../ObjectYAML/DXContainer/PSVv3-vertex.yaml  |  4 +-
 llvm/tools/obj2yaml/dxcontainer2yaml.cpp      |  2 +-
 14 files changed, 115 insertions(+), 95 deletions(-)

diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h
index 5cd0c5262b552e..b33c058067fe08 100644
--- a/llvm/include/llvm/MC/DXContainerPSVInfo.h
+++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h
@@ -9,9 +9,11 @@
 #ifndef LLVM_MC_DXCONTAINERPSVINFO_H
 #define LLVM_MC_DXCONTAINERPSVINFO_H
 
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/MC/StringTableBuilder.h"
 #include "llvm/TargetParser/Triple.h"
 
 #include <array>
@@ -45,6 +47,7 @@ struct PSVSignatureElement {
 // modifiable format, and can be used to serialize the data back into valid PSV
 // RuntimeInfo.
 struct PSVRuntimeInfo {
+  PSVRuntimeInfo() : DXConStrTabBuilder(StringTableBuilder::DXContainer) {}
   bool IsFinalized = false;
   dxbc::PSV::v3::RuntimeInfo BaseData;
   SmallVector<dxbc::PSV::v2::ResourceBindInfo> Resources;
@@ -65,18 +68,97 @@ struct PSVRuntimeInfo {
   SmallVector<uint32_t> InputPatchMap;
   SmallVector<uint32_t> PatchOutputMap;
 
+  StringTableBuilder DXConStrTabBuilder;
+  SmallVector<uint32_t, 64> IndexBuffer;
+  SmallVector<llvm::dxbc::PSV::v0::SignatureElement, 32> SignatureElements;
+  SmallVector<StringRef, 32> SemanticNames;
+
+  llvm::StringRef EntryFunctionName;
+
   // Serialize PSVInfo into the provided raw_ostream. The version field
   // specifies the data version to encode, the default value specifies encoding
   // the highest supported version.
   void write(raw_ostream &OS,
              uint32_t Version = std::numeric_limits<uint32_t>::max()) const;
 
+  static constexpr size_t npos = StringRef::npos;
+  static size_t FindSequence(ArrayRef<uint32_t> Buffer,
+                             ArrayRef<uint32_t> Sequence) {
+    if (Buffer.size() < Sequence.size())
+      return npos;
+    for (size_t Idx = 0; Idx <= Buffer.size() - Sequence.size(); ++Idx) {
+      if (0 == memcmp(static_cast<const void *>(&Buffer[Idx]),
+                      static_cast<const void *>(Sequence.begin()),
+                      Sequence.size() * sizeof(uint32_t)))
+        return Idx;
+    }
+    return npos;
+  }
+
+  static void ProcessElementList(
+      StringTableBuilder &StrTabBuilder, SmallVectorImpl<uint32_t> &IndexBuffer,
+      SmallVectorImpl<llvm::dxbc::PSV::v0::SignatureElement> &FinalElements,
+      SmallVectorImpl<StringRef> &SemanticNames,
+      ArrayRef<PSVSignatureElement> Elements) {
+    for (const auto &El : Elements) {
+      // Put the name in the string table and the name list.
+      StrTabBuilder.add(El.Name);
+      SemanticNames.push_back(El.Name);
+
+      llvm::dxbc::PSV::v0::SignatureElement FinalElement;
+      memset(&FinalElement, 0, sizeof(llvm::dxbc::PSV::v0::SignatureElement));
+      FinalElement.Rows = static_cast<uint8_t>(El.Indices.size());
+      FinalElement.StartRow = El.StartRow;
+      FinalElement.Cols = El.Cols;
+      FinalElement.StartCol = El.StartCol;
+      FinalElement.Allocated = El.Allocated;
+      FinalElement.Kind = El.Kind;
+      FinalElement.Type = El.Type;
+      FinalElement.Mode = El.Mode;
+      FinalElement.DynamicMask = El.DynamicMask;
+      FinalElement.Stream = El.Stream;
+
+      size_t Idx = FindSequence(IndexBuffer, El.Indices);
+      if (Idx == npos) {
+        FinalElement.IndicesOffset = static_cast<uint32_t>(IndexBuffer.size());
+        IndexBuffer.insert(IndexBuffer.end(), El.Indices.begin(),
+                           El.Indices.end());
+      } else
+        FinalElement.IndicesOffset = static_cast<uint32_t>(Idx);
+      FinalElements.push_back(FinalElement);
+    }
+  }
+
   void finalize(Triple::EnvironmentType Stage) {
     IsFinalized = true;
     BaseData.SigInputElements = static_cast<uint32_t>(InputElements.size());
     BaseData.SigOutputElements = static_cast<uint32_t>(OutputElements.size());
     BaseData.SigPatchOrPrimElements =
         static_cast<uint32_t>(PatchOrPrimElements.size());
+
+    // Build a string table and set associated offsets to be written when
+    // write() is called
+    ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
+                       SemanticNames, InputElements);
+    ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
+                       SemanticNames, OutputElements);
+    ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
+                       SemanticNames, PatchOrPrimElements);
+
+    DXConStrTabBuilder.add(EntryFunctionName);
+
+    DXConStrTabBuilder.finalize();
+    for (auto ElAndName : zip(SignatureElements, SemanticNames)) {
+      llvm::dxbc::PSV::v0::SignatureElement &El = std::get<0>(ElAndName);
+      StringRef Name = std::get<1>(ElAndName);
+      El.NameOffset = static_cast<uint32_t>(DXConStrTabBuilder.getOffset(Name));
+      if (sys::IsBigEndianHost)
+        El.swapBytes();
+    }
+
+    BaseData.EntryFunctionName =
+        static_cast<uint32_t>(DXConStrTabBuilder.getOffset(EntryFunctionName));
+
     if (!sys::IsBigEndianHost)
       return;
     BaseData.swapBytes();
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index cad2e606d7db45..53c97a5a317822 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -121,13 +121,15 @@ struct PSVInfo {
   MaskVector InputPatchMap;
   MaskVector PatchOutputMap;
 
+  StringRef EntryFunctionName;
+
   void mapInfoForVersion(yaml::IO &IO);
 
   PSVInfo();
   PSVInfo(const dxbc::PSV::v0::RuntimeInfo *P, uint16_t Stage);
   PSVInfo(const dxbc::PSV::v1::RuntimeInfo *P);
   PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P);
-  PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P);
+  PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P, StringRef StringTable);
 };
 
 struct SignatureParameter {
diff --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp
index 82edf9f4bd6fb9..1511612a4cd038 100644
--- a/llvm/lib/MC/DXContainerPSVInfo.cpp
+++ b/llvm/lib/MC/DXContainerPSVInfo.cpp
@@ -16,56 +16,6 @@ using namespace llvm;
 using namespace llvm::mcdxbc;
 using namespace llvm::dxbc::PSV;
 
-static constexpr size_t npos = StringRef::npos;
-
-static size_t FindSequence(ArrayRef<uint32_t> Buffer,
-                           ArrayRef<uint32_t> Sequence) {
-  if (Buffer.size() < Sequence.size())
-    return npos;
-  for (size_t Idx = 0; Idx <= Buffer.size() - Sequence.size(); ++Idx) {
-    if (0 == memcmp(static_cast<const void *>(&Buffer[Idx]),
-                    static_cast<const void *>(Sequence.begin()),
-                    Sequence.size() * sizeof(uint32_t)))
-      return Idx;
-  }
-  return npos;
-}
-
-static void
-ProcessElementList(StringTableBuilder &StrTabBuilder,
-                   SmallVectorImpl<uint32_t> &IndexBuffer,
-                   SmallVectorImpl<v0::SignatureElement> &FinalElements,
-                   SmallVectorImpl<StringRef> &SemanticNames,
-                   ArrayRef<PSVSignatureElement> Elements) {
-  for (const auto &El : Elements) {
-    // Put the name in the string table and the name list.
-    StrTabBuilder.add(El.Name);
-    SemanticNames.push_back(El.Name);
-
-    v0::SignatureElement FinalElement;
-    memset(&FinalElement, 0, sizeof(v0::SignatureElement));
-    FinalElement.Rows = static_cast<uint8_t>(El.Indices.size());
-    FinalElement.StartRow = El.StartRow;
-    FinalElement.Cols = El.Cols;
-    FinalElement.StartCol = El.StartCol;
-    FinalElement.Allocated = El.Allocated;
-    FinalElement.Kind = El.Kind;
-    FinalElement.Type = El.Type;
-    FinalElement.Mode = El.Mode;
-    FinalElement.DynamicMask = El.DynamicMask;
-    FinalElement.Stream = El.Stream;
-
-    size_t Idx = FindSequence(IndexBuffer, El.Indices);
-    if (Idx == npos) {
-      FinalElement.IndicesOffset = static_cast<uint32_t>(IndexBuffer.size());
-      IndexBuffer.insert(IndexBuffer.end(), El.Indices.begin(),
-                         El.Indices.end());
-    } else
-      FinalElement.IndicesOffset = static_cast<uint32_t>(Idx);
-    FinalElements.push_back(FinalElement);
-  }
-}
-
 void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const {
   assert(IsFinalized && "finalize must be called before write");
 
@@ -89,9 +39,10 @@ void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const {
     InfoSize = sizeof(dxbc::PSV::v3::RuntimeInfo);
     BindingSize = sizeof(dxbc::PSV::v2::ResourceBindInfo);
   }
-  // Write the size of the info.
 
+  // Write the size of the info.
   support::endian::write(OS, InfoSize, llvm::endianness::little);
+
   // Write the info itself.
   OS.write(reinterpret_cast<const char *>(&BaseData), InfoSize);
 
@@ -108,32 +59,12 @@ void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const {
   if (Version == 0)
     return;
 
-  StringTableBuilder StrTabBuilder((StringTableBuilder::DXContainer));
-  SmallVector<uint32_t, 64> IndexBuffer;
-  SmallVector<v0::SignatureElement, 32> SignatureElements;
-  SmallVector<StringRef, 32> SemanticNames;
-
-  ProcessElementList(StrTabBuilder, IndexBuffer, SignatureElements,
-                     SemanticNames, InputElements);
-  ProcessElementList(StrTabBuilder, IndexBuffer, SignatureElements,
-                     SemanticNames, OutputElements);
-  ProcessElementList(StrTabBuilder, IndexBuffer, SignatureElements,
-                     SemanticNames, PatchOrPrimElements);
-
-  StrTabBuilder.finalize();
-  for (auto ElAndName : zip(SignatureElements, SemanticNames)) {
-    v0::SignatureElement &El = std::get<0>(ElAndName);
-    StringRef Name = std::get<1>(ElAndName);
-    El.NameOffset = static_cast<uint32_t>(StrTabBuilder.getOffset(Name));
-    if (sys::IsBigEndianHost)
-      El.swapBytes();
-  }
-
-  support::endian::write(OS, static_cast<uint32_t>(StrTabBuilder.getSize()),
+  support::endian::write(OS,
+                         static_cast<uint32_t>(DXConStrTabBuilder.getSize()),
                          llvm::endianness::little);
 
   // Write the string table.
-  StrTabBuilder.write(OS);
+  DXConStrTabBuilder.write(OS);
 
   // Write the index table size, then table.
   support::endian::write(OS, static_cast<uint32_t>(IndexBuffer.size()),
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index da2cdd7cac8800..f2aaf7c06ad2a2 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -200,6 +200,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
       mcdxbc::PSVRuntimeInfo PSV;
       memcpy(&PSV.BaseData, &P.Info->Info, sizeof(dxbc::PSV::v3::RuntimeInfo));
       PSV.Resources = P.Info->Resources;
+      PSV.EntryFunctionName = P.Info->EntryFunctionName;
 
       for (auto El : P.Info->SigInputElements)
         PSV.InputElements.push_back(mcdxbc::PSVSignatureElement{
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 9b623c00af2668..2b685cfb68f27b 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -74,8 +74,12 @@ DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P)
   memcpy(&Info, P, sizeof(dxbc::PSV::v2::RuntimeInfo));
 }
 
-DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P)
-    : Version(3) {
+DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P,
+                                  StringRef StringTable)
+    : Version(3),
+      EntryFunctionName(StringTable.substr(
+          P->EntryFunctionName, StringTable.find('\0', P->EntryFunctionName) -
+                                    P->EntryFunctionName)) {
   memset(&Info, 0, sizeof(Info));
   memcpy(&Info, P, sizeof(dxbc::PSV::v3::RuntimeInfo));
 }
@@ -357,7 +361,7 @@ void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO &IO) {
   if (Version == 2)
     return;
 
-  IO.mapRequired("EntryFunctionName", Info.EntryFunctionName);
+  IO.mapRequired("EntryFunctionName", EntryFunctionName);
 }
 
 } // namespace llvm
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
index 92ceac5b52ffae..9b1c8877b5cd40 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
@@ -23,7 +23,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: ASEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -71,7 +71,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: ASEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
index c9c6cf85879449..f7d640853e58b9 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
@@ -22,7 +22,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: CSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -69,7 +69,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: CSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
index 6584e90f82210b..d381c467002888 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
@@ -26,7 +26,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: DSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -78,7 +78,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: DSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
index 43d9f70dba5eec..b632210b8c6bbf 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
@@ -27,7 +27,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: GSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -79,7 +79,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: GSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
index 7b1b902fe9a3ae..ed926a8f0b9566 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
@@ -27,7 +27,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: HSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -80,7 +80,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: HSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
index 0df2312738b92f..d0b47693c27116 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
@@ -29,7 +29,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: MSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -83,7 +83,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: MSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
index 7aae2c0e8bbfa6..b153c32f46d2cd 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
@@ -24,7 +24,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: PSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -73,7 +73,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: PSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
index c6f8d3bcf9a9de..a10a81a424439b 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
@@ -23,7 +23,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: 1
+      EntryFunctionName: VSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -71,7 +71,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: 1
+# CHECK-NEXT: EntryFunctionName: VSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
index 8447c2490303bd..8496611910af14 100644
--- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
+++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
@@ -101,7 +101,7 @@ dumpDXContainer(MemoryBufferRef Source) {
         NewPart.Info = DXContainerYAML::PSVInfo(P);
       else if (const auto *P =
                    std::get_if<dxbc::PSV::v3::RuntimeInfo>(&PSVInfo->getInfo()))
-        NewPart.Info = DXContainerYAML::PSVInfo(P);
+        NewPart.Info = DXContainerYAML::PSVInfo(P, PSVInfo->getStringTable());
       NewPart.Info->ResourceStride = PSVInfo->getResourceStride();
       for (auto Res : PSVInfo->getResources())
         NewPart.Info->Resources.push_back(Res);

>From 2f79e4674cf795838c19da175e5685cc98a712e1 Mon Sep 17 00:00:00 2001
From: Cooper Partin <coopp at ntdev.microsoft.com>
Date: Tue, 19 Mar 2024 09:34:59 -0700
Subject: [PATCH 3/6] Rename EntryFunctionName to EntryNameOffset

This change makes the variable be more descriptive to what it is actually representing.
---
 llvm/include/llvm/BinaryFormat/DXContainer.h              | 4 ++--
 llvm/include/llvm/MC/DXContainerPSVInfo.h                 | 8 ++++----
 llvm/include/llvm/ObjectYAML/DXContainerYAML.h            | 2 +-
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp                | 2 +-
 llvm/lib/ObjectYAML/DXContainerYAML.cpp                   | 8 ++++----
 llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml | 4 ++--
 llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml       | 4 ++--
 llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml        | 4 ++--
 llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml      | 4 ++--
 llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml          | 4 ++--
 llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml          | 4 ++--
 llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml         | 4 ++--
 llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml        | 4 ++--
 13 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 9da262a8084add..60d7c281e81713 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -427,9 +427,9 @@ struct ResourceBindInfo : public v0::ResourceBindInfo {
 
 namespace v3 {
 struct RuntimeInfo : public v2::RuntimeInfo {
-  uint32_t EntryFunctionName;
+  uint32_t EntryNameOffset;
 
-  void swapBytes() { sys::swapByteOrder(EntryFunctionName); }
+  void swapBytes() { sys::swapByteOrder(EntryNameOffset); }
 
   void swapBytes(Triple::EnvironmentType Stage) {
     v2::RuntimeInfo::swapBytes(Stage);
diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h
index b33c058067fe08..1d9f9d67c48af4 100644
--- a/llvm/include/llvm/MC/DXContainerPSVInfo.h
+++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h
@@ -73,7 +73,7 @@ struct PSVRuntimeInfo {
   SmallVector<llvm::dxbc::PSV::v0::SignatureElement, 32> SignatureElements;
   SmallVector<StringRef, 32> SemanticNames;
 
-  llvm::StringRef EntryFunctionName;
+  llvm::StringRef EntryName;
 
   // Serialize PSVInfo into the provided raw_ostream. The version field
   // specifies the data version to encode, the default value specifies encoding
@@ -145,7 +145,7 @@ struct PSVRuntimeInfo {
     ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
                        SemanticNames, PatchOrPrimElements);
 
-    DXConStrTabBuilder.add(EntryFunctionName);
+    DXConStrTabBuilder.add(EntryName);
 
     DXConStrTabBuilder.finalize();
     for (auto ElAndName : zip(SignatureElements, SemanticNames)) {
@@ -156,8 +156,8 @@ struct PSVRuntimeInfo {
         El.swapBytes();
     }
 
-    BaseData.EntryFunctionName =
-        static_cast<uint32_t>(DXConStrTabBuilder.getOffset(EntryFunctionName));
+    BaseData.EntryNameOffset =
+        static_cast<uint32_t>(DXConStrTabBuilder.getOffset(EntryName));
 
     if (!sys::IsBigEndianHost)
       return;
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 53c97a5a317822..a47f53e7de5b68 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -121,7 +121,7 @@ struct PSVInfo {
   MaskVector InputPatchMap;
   MaskVector PatchOutputMap;
 
-  StringRef EntryFunctionName;
+  StringRef EntryName;
 
   void mapInfoForVersion(yaml::IO &IO);
 
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index f2aaf7c06ad2a2..f3a518df317504 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -200,7 +200,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
       mcdxbc::PSVRuntimeInfo PSV;
       memcpy(&PSV.BaseData, &P.Info->Info, sizeof(dxbc::PSV::v3::RuntimeInfo));
       PSV.Resources = P.Info->Resources;
-      PSV.EntryFunctionName = P.Info->EntryFunctionName;
+      PSV.EntryName = P.Info->EntryName;
 
       for (auto El : P.Info->SigInputElements)
         PSV.InputElements.push_back(mcdxbc::PSVSignatureElement{
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 2b685cfb68f27b..4200f167f9170b 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -77,9 +77,9 @@ DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P)
 DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P,
                                   StringRef StringTable)
     : Version(3),
-      EntryFunctionName(StringTable.substr(
-          P->EntryFunctionName, StringTable.find('\0', P->EntryFunctionName) -
-                                    P->EntryFunctionName)) {
+      EntryName(StringTable.substr(
+          P->EntryNameOffset, StringTable.find('\0', P->EntryNameOffset) -
+                                    P->EntryNameOffset)) {
   memset(&Info, 0, sizeof(Info));
   memcpy(&Info, P, sizeof(dxbc::PSV::v3::RuntimeInfo));
 }
@@ -361,7 +361,7 @@ void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO &IO) {
   if (Version == 2)
     return;
 
-  IO.mapRequired("EntryFunctionName", EntryFunctionName);
+  IO.mapRequired("EntryName", EntryName);
 }
 
 } // namespace llvm
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
index 9b1c8877b5cd40..09885bd529f05f 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-amplification.yaml
@@ -23,7 +23,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: ASEntry
+      EntryName: ASEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -71,7 +71,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: ASEntry
+# CHECK-NEXT: EntryName: ASEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
index f7d640853e58b9..ee6fb112c77222 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-compute.yaml
@@ -22,7 +22,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: CSEntry
+      EntryName: CSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -69,7 +69,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: CSEntry
+# CHECK-NEXT: EntryName: CSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
index d381c467002888..dd367deae88e47 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-domain.yaml
@@ -26,7 +26,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: DSEntry
+      EntryName: DSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -78,7 +78,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: DSEntry
+# CHECK-NEXT: EntryName: DSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
index b632210b8c6bbf..4c7680b63b02b6 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-geometry.yaml
@@ -27,7 +27,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: GSEntry
+      EntryName: GSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -79,7 +79,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: GSEntry
+# CHECK-NEXT: EntryName: GSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
index ed926a8f0b9566..3bbad8a9b0ee62 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-hull.yaml
@@ -27,7 +27,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: HSEntry
+      EntryName: HSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -80,7 +80,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: HSEntry
+# CHECK-NEXT: EntryName: HSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
index d0b47693c27116..c5ea1fcf078087 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-mesh.yaml
@@ -29,7 +29,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: MSEntry
+      EntryName: MSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -83,7 +83,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: MSEntry
+# CHECK-NEXT: EntryName: MSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
index b153c32f46d2cd..b28d5ec8074d85 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-pixel.yaml
@@ -24,7 +24,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: PSEntry
+      EntryName: PSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -73,7 +73,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: PSEntry
+# CHECK-NEXT: EntryName: PSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1
diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
index a10a81a424439b..d1fb55839931ca 100644
--- a/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/PSVv3-vertex.yaml
@@ -23,7 +23,7 @@ Parts:
       NumThreadsX:     512
       NumThreadsY:     1024
       NumThreadsZ:     2048
-      EntryFunctionName: VSEntry
+      EntryName: VSEntry
       ResourceStride:       24
       Resources:
         - Type:            1
@@ -71,7 +71,7 @@ Parts:
 # CHECK-NEXT: NumThreadsX:     512
 # CHECK-NEXT: NumThreadsY:     1024
 # CHECK-NEXT: NumThreadsZ:     2048
-# CHECK-NEXT: EntryFunctionName: VSEntry
+# CHECK-NEXT: EntryName: VSEntry
 # CHECK-NEXT: ResourceStride: 24
 # CHECK-NEXT: Resources:
 # CHECK-NEXT: - Type:            1

>From 0c1878e52317e5452c35a9726414a56aa248a183 Mon Sep 17 00:00:00 2001
From: Cooper Partin <coopp at ntdev.microsoft.com>
Date: Tue, 19 Mar 2024 10:26:39 -0700
Subject: [PATCH 4/6] Move finalize() implementation to .cpp file reducing
 clutter in the header file.

---
 llvm/include/llvm/MC/DXContainerPSVInfo.h | 88 +----------------------
 llvm/lib/MC/DXContainerPSVInfo.cpp        | 86 ++++++++++++++++++++++
 2 files changed, 88 insertions(+), 86 deletions(-)

diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h
index 1d9f9d67c48af4..42e05c8a4dbec1 100644
--- a/llvm/include/llvm/MC/DXContainerPSVInfo.h
+++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h
@@ -80,92 +80,8 @@ struct PSVRuntimeInfo {
   // the highest supported version.
   void write(raw_ostream &OS,
              uint32_t Version = std::numeric_limits<uint32_t>::max()) const;
-
-  static constexpr size_t npos = StringRef::npos;
-  static size_t FindSequence(ArrayRef<uint32_t> Buffer,
-                             ArrayRef<uint32_t> Sequence) {
-    if (Buffer.size() < Sequence.size())
-      return npos;
-    for (size_t Idx = 0; Idx <= Buffer.size() - Sequence.size(); ++Idx) {
-      if (0 == memcmp(static_cast<const void *>(&Buffer[Idx]),
-                      static_cast<const void *>(Sequence.begin()),
-                      Sequence.size() * sizeof(uint32_t)))
-        return Idx;
-    }
-    return npos;
-  }
-
-  static void ProcessElementList(
-      StringTableBuilder &StrTabBuilder, SmallVectorImpl<uint32_t> &IndexBuffer,
-      SmallVectorImpl<llvm::dxbc::PSV::v0::SignatureElement> &FinalElements,
-      SmallVectorImpl<StringRef> &SemanticNames,
-      ArrayRef<PSVSignatureElement> Elements) {
-    for (const auto &El : Elements) {
-      // Put the name in the string table and the name list.
-      StrTabBuilder.add(El.Name);
-      SemanticNames.push_back(El.Name);
-
-      llvm::dxbc::PSV::v0::SignatureElement FinalElement;
-      memset(&FinalElement, 0, sizeof(llvm::dxbc::PSV::v0::SignatureElement));
-      FinalElement.Rows = static_cast<uint8_t>(El.Indices.size());
-      FinalElement.StartRow = El.StartRow;
-      FinalElement.Cols = El.Cols;
-      FinalElement.StartCol = El.StartCol;
-      FinalElement.Allocated = El.Allocated;
-      FinalElement.Kind = El.Kind;
-      FinalElement.Type = El.Type;
-      FinalElement.Mode = El.Mode;
-      FinalElement.DynamicMask = El.DynamicMask;
-      FinalElement.Stream = El.Stream;
-
-      size_t Idx = FindSequence(IndexBuffer, El.Indices);
-      if (Idx == npos) {
-        FinalElement.IndicesOffset = static_cast<uint32_t>(IndexBuffer.size());
-        IndexBuffer.insert(IndexBuffer.end(), El.Indices.begin(),
-                           El.Indices.end());
-      } else
-        FinalElement.IndicesOffset = static_cast<uint32_t>(Idx);
-      FinalElements.push_back(FinalElement);
-    }
-  }
-
-  void finalize(Triple::EnvironmentType Stage) {
-    IsFinalized = true;
-    BaseData.SigInputElements = static_cast<uint32_t>(InputElements.size());
-    BaseData.SigOutputElements = static_cast<uint32_t>(OutputElements.size());
-    BaseData.SigPatchOrPrimElements =
-        static_cast<uint32_t>(PatchOrPrimElements.size());
-
-    // Build a string table and set associated offsets to be written when
-    // write() is called
-    ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
-                       SemanticNames, InputElements);
-    ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
-                       SemanticNames, OutputElements);
-    ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
-                       SemanticNames, PatchOrPrimElements);
-
-    DXConStrTabBuilder.add(EntryName);
-
-    DXConStrTabBuilder.finalize();
-    for (auto ElAndName : zip(SignatureElements, SemanticNames)) {
-      llvm::dxbc::PSV::v0::SignatureElement &El = std::get<0>(ElAndName);
-      StringRef Name = std::get<1>(ElAndName);
-      El.NameOffset = static_cast<uint32_t>(DXConStrTabBuilder.getOffset(Name));
-      if (sys::IsBigEndianHost)
-        El.swapBytes();
-    }
-
-    BaseData.EntryNameOffset =
-        static_cast<uint32_t>(DXConStrTabBuilder.getOffset(EntryName));
-
-    if (!sys::IsBigEndianHost)
-      return;
-    BaseData.swapBytes();
-    BaseData.swapBytes(Stage);
-    for (auto &Res : Resources)
-      Res.swapBytes();
-  }
+ 
+  void finalize(Triple::EnvironmentType Stage);
 };
 
 class Signature {
diff --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp
index 1511612a4cd038..24bdb4ffff565c 100644
--- a/llvm/lib/MC/DXContainerPSVInfo.cpp
+++ b/llvm/lib/MC/DXContainerPSVInfo.cpp
@@ -97,6 +97,92 @@ void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const {
                                llvm::endianness::little);
 }
 
+static constexpr size_t npos = StringRef::npos;
+static size_t FindSequence(ArrayRef<uint32_t> Buffer,
+                           ArrayRef<uint32_t> Sequence) {
+  if (Buffer.size() < Sequence.size())
+    return npos;
+  for (size_t Idx = 0; Idx <= Buffer.size() - Sequence.size(); ++Idx) {
+    if (0 == memcmp(static_cast<const void *>(&Buffer[Idx]),
+                    static_cast<const void *>(Sequence.begin()),
+                    Sequence.size() * sizeof(uint32_t)))
+      return Idx;
+  }
+  return npos;
+}
+
+static void ProcessElementList(
+    StringTableBuilder &StrTabBuilder, SmallVectorImpl<uint32_t> &IndexBuffer,
+    SmallVectorImpl<llvm::dxbc::PSV::v0::SignatureElement> &FinalElements,
+    SmallVectorImpl<StringRef> &SemanticNames,
+    ArrayRef<PSVSignatureElement> Elements) {
+  for (const auto &El : Elements) {
+    // Put the name in the string table and the name list.
+    StrTabBuilder.add(El.Name);
+    SemanticNames.push_back(El.Name);
+
+    llvm::dxbc::PSV::v0::SignatureElement FinalElement;
+    memset(&FinalElement, 0, sizeof(llvm::dxbc::PSV::v0::SignatureElement));
+    FinalElement.Rows = static_cast<uint8_t>(El.Indices.size());
+    FinalElement.StartRow = El.StartRow;
+    FinalElement.Cols = El.Cols;
+    FinalElement.StartCol = El.StartCol;
+    FinalElement.Allocated = El.Allocated;
+    FinalElement.Kind = El.Kind;
+    FinalElement.Type = El.Type;
+    FinalElement.Mode = El.Mode;
+    FinalElement.DynamicMask = El.DynamicMask;
+    FinalElement.Stream = El.Stream;
+
+    size_t Idx = FindSequence(IndexBuffer, El.Indices);
+    if (Idx == npos) {
+      FinalElement.IndicesOffset = static_cast<uint32_t>(IndexBuffer.size());
+      IndexBuffer.insert(IndexBuffer.end(), El.Indices.begin(),
+                         El.Indices.end());
+    } else
+      FinalElement.IndicesOffset = static_cast<uint32_t>(Idx);
+    FinalElements.push_back(FinalElement);
+  }
+}
+
+void PSVRuntimeInfo::finalize(Triple::EnvironmentType Stage) {
+  IsFinalized = true;
+  BaseData.SigInputElements = static_cast<uint32_t>(InputElements.size());
+  BaseData.SigOutputElements = static_cast<uint32_t>(OutputElements.size());
+  BaseData.SigPatchOrPrimElements =
+      static_cast<uint32_t>(PatchOrPrimElements.size());
+
+  // Build a string table and set associated offsets to be written when
+  // write() is called
+  ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
+                     SemanticNames, InputElements);
+  ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
+                     SemanticNames, OutputElements);
+  ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
+                     SemanticNames, PatchOrPrimElements);
+
+  DXConStrTabBuilder.add(EntryName);
+
+  DXConStrTabBuilder.finalize();
+  for (auto ElAndName : zip(SignatureElements, SemanticNames)) {
+    llvm::dxbc::PSV::v0::SignatureElement &El = std::get<0>(ElAndName);
+    StringRef Name = std::get<1>(ElAndName);
+    El.NameOffset = static_cast<uint32_t>(DXConStrTabBuilder.getOffset(Name));
+    if (sys::IsBigEndianHost)
+      El.swapBytes();
+  }
+
+  BaseData.EntryNameOffset =
+      static_cast<uint32_t>(DXConStrTabBuilder.getOffset(EntryName));
+
+  if (!sys::IsBigEndianHost)
+    return;
+  BaseData.swapBytes();
+  BaseData.swapBytes(Stage);
+  for (auto &Res : Resources)
+    Res.swapBytes();
+}
+
 void Signature::write(raw_ostream &OS) {
   SmallVector<dxbc::ProgramSignatureElement> SigParams;
   SigParams.reserve(Params.size());

>From 1e93738ae10de5f793b97bc464a930b667109b99 Mon Sep 17 00:00:00 2001
From: Cooper Partin <coopp at ntdev.microsoft.com>
Date: Tue, 19 Mar 2024 10:29:28 -0700
Subject: [PATCH 5/6] clang-format! Fix'n up the unpretty bits.

---
 llvm/include/llvm/MC/DXContainerPSVInfo.h | 2 +-
 llvm/include/llvm/MC/StringTableBuilder.h | 8 ++------
 llvm/lib/ObjectYAML/DXContainerYAML.cpp   | 6 +++---
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h
index 42e05c8a4dbec1..8cec0d489240ca 100644
--- a/llvm/include/llvm/MC/DXContainerPSVInfo.h
+++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h
@@ -80,7 +80,7 @@ struct PSVRuntimeInfo {
   // the highest supported version.
   void write(raw_ostream &OS,
              uint32_t Version = std::numeric_limits<uint32_t>::max()) const;
- 
+
   void finalize(Triple::EnvironmentType Stage);
 };
 
diff --git a/llvm/include/llvm/MC/StringTableBuilder.h b/llvm/include/llvm/MC/StringTableBuilder.h
index 4ee421e22c171f..a738683548cfa5 100644
--- a/llvm/include/llvm/MC/StringTableBuilder.h
+++ b/llvm/include/llvm/MC/StringTableBuilder.h
@@ -74,12 +74,8 @@ class StringTableBuilder {
   /// Check if a string is contained in the string table. Since this class
   /// doesn't store the string values, this function can be used to check if
   /// storage needs to be done prior to adding the string.
-  bool contains(StringRef S) const {
-    return contains(CachedHashStringRef(S));
-  }
-  bool contains(CachedHashStringRef S) const {
-    return StringIndexMap.count(S);
-  }
+  bool contains(StringRef S) const { return contains(CachedHashStringRef(S)); }
+  bool contains(CachedHashStringRef S) const { return StringIndexMap.count(S); }
 
   size_t getSize() const { return Size; }
   void clear();
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 4200f167f9170b..bd63448ce6ec66 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -77,9 +77,9 @@ DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P)
 DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P,
                                   StringRef StringTable)
     : Version(3),
-      EntryName(StringTable.substr(
-          P->EntryNameOffset, StringTable.find('\0', P->EntryNameOffset) -
-                                    P->EntryNameOffset)) {
+      EntryName(StringTable.substr(P->EntryNameOffset,
+                                   StringTable.find('\0', P->EntryNameOffset) -
+                                       P->EntryNameOffset)) {
   memset(&Info, 0, sizeof(Info));
   memcpy(&Info, P, sizeof(dxbc::PSV::v3::RuntimeInfo));
 }

>From fb4c4faef4a013b7966fafd3601523641dc4f4bc Mon Sep 17 00:00:00 2001
From: Cooper Partin <coopp at ntdev.microsoft.com>
Date: Tue, 19 Mar 2024 12:18:07 -0700
Subject: [PATCH 6/6] Move members to private that are not accessed by external
 setters.

---
 llvm/include/llvm/MC/DXContainerPSVInfo.h | 11 +++++------
 llvm/lib/MC/DXContainerPSVInfo.cpp        |  2 ++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h
index 8cec0d489240ca..bad2fe78eb8fbb 100644
--- a/llvm/include/llvm/MC/DXContainerPSVInfo.h
+++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h
@@ -67,12 +67,6 @@ struct PSVRuntimeInfo {
   std::array<SmallVector<uint32_t>, 4> InputOutputMap;
   SmallVector<uint32_t> InputPatchMap;
   SmallVector<uint32_t> PatchOutputMap;
-
-  StringTableBuilder DXConStrTabBuilder;
-  SmallVector<uint32_t, 64> IndexBuffer;
-  SmallVector<llvm::dxbc::PSV::v0::SignatureElement, 32> SignatureElements;
-  SmallVector<StringRef, 32> SemanticNames;
-
   llvm::StringRef EntryName;
 
   // Serialize PSVInfo into the provided raw_ostream. The version field
@@ -82,6 +76,11 @@ struct PSVRuntimeInfo {
              uint32_t Version = std::numeric_limits<uint32_t>::max()) const;
 
   void finalize(Triple::EnvironmentType Stage);
+
+private:
+  SmallVector<uint32_t, 64> IndexBuffer;
+  SmallVector<llvm::dxbc::PSV::v0::SignatureElement, 32> SignatureElements;
+  StringTableBuilder DXConStrTabBuilder;
 };
 
 class Signature {
diff --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp
index 24bdb4ffff565c..cb1e78b3a1677c 100644
--- a/llvm/lib/MC/DXContainerPSVInfo.cpp
+++ b/llvm/lib/MC/DXContainerPSVInfo.cpp
@@ -152,6 +152,8 @@ void PSVRuntimeInfo::finalize(Triple::EnvironmentType Stage) {
   BaseData.SigPatchOrPrimElements =
       static_cast<uint32_t>(PatchOrPrimElements.size());
 
+  SmallVector<StringRef, 32> SemanticNames;
+
   // Build a string table and set associated offsets to be written when
   // write() is called
   ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,



More information about the llvm-commits mailing list