[llvm] [DirectX][ObectYAML] Make `RootParameterOffset` and `StaticSamplersOffset` behaviour consistent (PR #155521)

Finn Plummer via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 10:45:57 PDT 2025


https://github.com/inbelic updated https://github.com/llvm/llvm-project/pull/155521

>From 7bfa043d42f3baabadb11dbaabaf4884554a2246 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 14:30:49 -0700
Subject: [PATCH 01/12] always compute the staticsampleroffset in code
 generation

---
 llvm/lib/MC/DXContainerRootSignature.cpp | 38 ++++++++++--------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index c04dc6bd1800a..a13b6e34df35a 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -76,11 +76,7 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
   support::endian::write(BOS, NumParameters, llvm::endianness::little);
   support::endian::write(BOS, RootParameterOffset, llvm::endianness::little);
   support::endian::write(BOS, NumSamplers, llvm::endianness::little);
-  uint32_t SSO = StaticSamplersOffset;
-  if (NumSamplers > 0)
-    SSO = writePlaceholder(BOS);
-  else
-    support::endian::write(BOS, SSO, llvm::endianness::little);
+  uint32_t SSO = writePlaceholder(BOS);
   support::endian::write(BOS, Flags, llvm::endianness::little);
 
   SmallVector<uint32_t> ParamsOffsets;
@@ -144,23 +140,21 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
     }
     }
   }
-  if (NumSamplers > 0) {
-    rewriteOffsetToCurrentByte(BOS, SSO);
-    for (const auto &S : StaticSamplers) {
-      support::endian::write(BOS, S.Filter, llvm::endianness::little);
-      support::endian::write(BOS, S.AddressU, llvm::endianness::little);
-      support::endian::write(BOS, S.AddressV, llvm::endianness::little);
-      support::endian::write(BOS, S.AddressW, llvm::endianness::little);
-      support::endian::write(BOS, S.MipLODBias, llvm::endianness::little);
-      support::endian::write(BOS, S.MaxAnisotropy, llvm::endianness::little);
-      support::endian::write(BOS, S.ComparisonFunc, llvm::endianness::little);
-      support::endian::write(BOS, S.BorderColor, llvm::endianness::little);
-      support::endian::write(BOS, S.MinLOD, llvm::endianness::little);
-      support::endian::write(BOS, S.MaxLOD, llvm::endianness::little);
-      support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
-      support::endian::write(BOS, S.RegisterSpace, llvm::endianness::little);
-      support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
-    }
+  rewriteOffsetToCurrentByte(BOS, SSO);
+  for (const auto &S : StaticSamplers) {
+    support::endian::write(BOS, S.Filter, llvm::endianness::little);
+    support::endian::write(BOS, S.AddressU, llvm::endianness::little);
+    support::endian::write(BOS, S.AddressV, llvm::endianness::little);
+    support::endian::write(BOS, S.AddressW, llvm::endianness::little);
+    support::endian::write(BOS, S.MipLODBias, llvm::endianness::little);
+    support::endian::write(BOS, S.MaxAnisotropy, llvm::endianness::little);
+    support::endian::write(BOS, S.ComparisonFunc, llvm::endianness::little);
+    support::endian::write(BOS, S.BorderColor, llvm::endianness::little);
+    support::endian::write(BOS, S.MinLOD, llvm::endianness::little);
+    support::endian::write(BOS, S.MaxLOD, llvm::endianness::little);
+    support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
+    support::endian::write(BOS, S.RegisterSpace, llvm::endianness::little);
+    support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
   }
   assert(Storage.size() == getSize());
   OS.write(Storage.data(), Storage.size());

>From 77fb33836fc52bd969725b6f3fe2443534ce98d1 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 14:58:56 -0700
Subject: [PATCH 02/12] make offset parameters optional and enforce their
 values

---
 .../include/llvm/ObjectYAML/DXContainerYAML.h |  4 +-
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp    | 59 ++++++++++++++++---
 llvm/lib/ObjectYAML/DXContainerYAML.cpp       |  4 +-
 3 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 7e0a4c6b07039..359b27761cea3 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -187,9 +187,9 @@ struct RootSignatureYamlDesc {
 
   uint32_t Version;
   uint32_t NumRootParameters;
-  uint32_t RootParametersOffset;
+  std::optional<uint32_t> RootParametersOffset;
   uint32_t NumStaticSamplers;
-  uint32_t StaticSamplersOffset;
+  std::optional<uint32_t> StaticSamplersOffset;
 
   RootParameterYamlDesc Parameters;
   SmallVector<StaticSamplerYamlDesc> StaticSamplers;
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index b112c6f21ee5a..726a879075435 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -38,7 +38,7 @@ class DXContainerWriter {
   Error validateSize(uint32_t Computed);
 
   void writeHeader(raw_ostream &OS);
-  void writeParts(raw_ostream &OS);
+  Error writeParts(raw_ostream &OS);
 };
 } // namespace
 
@@ -107,7 +107,7 @@ void DXContainerWriter::writeHeader(raw_ostream &OS) {
            Offsets.size() * sizeof(uint32_t));
 }
 
-void DXContainerWriter::writeParts(raw_ostream &OS) {
+Error DXContainerWriter::writeParts(raw_ostream &OS) {
   uint32_t RollingOffset =
       sizeof(dxbc::Header) + (ObjectFile.Header.PartCount * sizeof(uint32_t));
   for (auto I : llvm::zip(ObjectFile.Parts, *ObjectFile.Header.PartOffsets)) {
@@ -269,13 +269,27 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
       mcdxbc::RootSignatureDesc RS;
       RS.Flags = P.RootSignature->getEncodedFlags();
       RS.Version = P.RootSignature->Version;
-      RS.RootParameterOffset = P.RootSignature->RootParametersOffset;
-      RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
-      RS.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset;
+
+      // Handling of RootParameters
+      const uint32_t RootHeaderSize =
+          sizeof(dxbc::RTS0::v1::RootSignatureHeader);
+      if (P.RootSignature->RootParametersOffset &&
+          P.RootSignature->RootParametersOffset.value() != RootHeaderSize) {
+        return createStringError(
+            errc::invalid_argument,
+            "Specified RootParametersOffset does not match required value: %d.",
+            RootHeaderSize);
+      }
+
+      uint32_t Offset = RootHeaderSize;
+      RS.RootParameterOffset = Offset;
 
       for (DXContainerYAML::RootParameterLocationYaml &L :
            P.RootSignature->Parameters.Locations) {
 
+        // Offset RootParameterHeader
+        Offset += sizeof(dxbc::RTS0::v1::RootParameterHeader);
+
         assert(dxbc::isValidParameterType(L.Header.Type) &&
                "invalid DXContainer YAML");
         assert(dxbc::isValidShaderVisibility(L.Header.Visibility) &&
@@ -294,6 +308,8 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
           Constants.RegisterSpace = ConstantYaml.RegisterSpace;
           Constants.ShaderRegister = ConstantYaml.ShaderRegister;
           RS.ParametersContainer.addParameter(Type, Visibility, Constants);
+
+          Offset += sizeof(dxbc::RTS0::v1::RootConstants);
           break;
         }
         case dxbc::RootParameterType::CBV:
@@ -305,8 +321,12 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
           dxbc::RTS0::v2::RootDescriptor Descriptor;
           Descriptor.RegisterSpace = DescriptorYaml.RegisterSpace;
           Descriptor.ShaderRegister = DescriptorYaml.ShaderRegister;
-          if (RS.Version > 1)
+          if (RS.Version > 1) {
             Descriptor.Flags = DescriptorYaml.getEncodedFlags();
+            Offset += sizeof(dxbc::RTS0::v2::RootDescriptor);
+          } else
+            Offset += sizeof(dxbc::RTS0::v1::RootDescriptor);
+
           RS.ParametersContainer.addParameter(Type, Visibility, Descriptor);
           break;
         }
@@ -314,6 +334,8 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
           const DXContainerYAML::DescriptorTableYaml &TableYaml =
               P.RootSignature->Parameters.getOrInsertTable(L);
           mcdxbc::DescriptorTable Table;
+          Offset +=
+              2 * sizeof(uint32_t); // DescriptorTable NumRanges and Offset
           for (const auto &R : TableYaml.Ranges) {
 
             dxbc::RTS0::v2::DescriptorRange Range;
@@ -323,8 +345,13 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
             Range.RegisterSpace = R.RegisterSpace;
             Range.OffsetInDescriptorsFromTableStart =
                 R.OffsetInDescriptorsFromTableStart;
-            if (RS.Version > 1)
+
+            if (RS.Version > 1) {
+              Offset += sizeof(dxbc::RTS0::v2::DescriptorRange);
               Range.Flags = R.getEncodedFlags();
+            } else
+              Offset += sizeof(dxbc::RTS0::v1::DescriptorRange);
+
             Table.Ranges.push_back(Range);
           }
           RS.ParametersContainer.addParameter(Type, Visibility, Table);
@@ -333,6 +360,19 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
         }
       }
 
+      // Handling of StaticSamplers
+      RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
+
+      if (P.RootSignature->StaticSamplersOffset &&
+          P.RootSignature->StaticSamplersOffset.value() != Offset) {
+        return createStringError(
+            errc::invalid_argument,
+            "Specified StaticSamplersOffset does not match computed value: %d.",
+            Offset);
+      }
+
+      RS.StaticSamplersOffset = Offset;
+
       for (const auto &Param : P.RootSignature->samplers()) {
         dxbc::RTS0::v1::StaticSampler NewSampler;
         NewSampler.Filter = Param.Filter;
@@ -361,14 +401,15 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
       OS.write_zeros(PartSize - BytesWritten);
     RollingOffset += PartSize;
   }
+
+  return Error::success();
 }
 
 Error DXContainerWriter::write(raw_ostream &OS) {
   if (Error Err = computePartOffsets())
     return Err;
   writeHeader(OS);
-  writeParts(OS);
-  return Error::success();
+  return writeParts(OS);
 }
 
 namespace llvm {
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 263f7bdf37bca..32b502ed4e21f 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -376,9 +376,9 @@ void MappingTraits<DXContainerYAML::RootSignatureYamlDesc>::mapping(
     IO &IO, DXContainerYAML::RootSignatureYamlDesc &S) {
   IO.mapRequired("Version", S.Version);
   IO.mapRequired("NumRootParameters", S.NumRootParameters);
-  IO.mapRequired("RootParametersOffset", S.RootParametersOffset);
+  IO.mapOptional("RootParametersOffset", S.RootParametersOffset, std::nullopt);
   IO.mapRequired("NumStaticSamplers", S.NumStaticSamplers);
-  IO.mapRequired("StaticSamplersOffset", S.StaticSamplersOffset);
+  IO.mapOptional("StaticSamplersOffset", S.StaticSamplersOffset, std::nullopt);
   IO.mapRequired("Parameters", S.Parameters.Locations, S);
   IO.mapOptional("Samplers", S.StaticSamplers);
 #define ROOT_SIGNATURE_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false);

>From 82647c317f5bbc1c10591342659016d18c0b32af Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 15:19:18 -0700
Subject: [PATCH 03/12] correct offsets in codegen tests

---
 .../RootSignature-DescriptorTable-AllValidFlagCombinations.ll   | 2 +-
 .../RootSignature-DescriptorTable-AllValidFlagCombinationsV1.ll | 2 +-
 .../DirectX/ContainerData/RootSignature-DescriptorTable.ll      | 2 +-
 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll  | 2 +-
 .../DirectX/ContainerData/RootSignature-RootConstants.ll        | 2 +-
 .../DirectX/ContainerData/RootSignature-RootDescriptor.ll       | 2 +-
 .../DirectX/ContainerData/RootSignature-RootDescriptor_V1.ll    | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinations.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinations.ll
index 8eb7f90c6b757..1bc9b85935819 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinations.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinations.ll
@@ -59,7 +59,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
 ;DXC-NEXT:      NumRootParameters: 1
 ;DXC-NEXT:      RootParametersOffset: 24
 ;DXC-NEXT:      NumStaticSamplers: 0
-;DXC-NEXT:      StaticSamplersOffset: 0
+;DXC-NEXT:      StaticSamplersOffset: 380
 ;DXC-NEXT:      Parameters:
 ;DXC-NEXT:        - ParameterType:   0
 ;DXC-NEXT:          ShaderVisibility: 0
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinationsV1.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinationsV1.ll
index 053721de1eb1f..fec6c4c959642 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinationsV1.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinationsV1.ll
@@ -24,7 +24,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
 ; DXC-NEXT:       NumRootParameters: 1
 ; DXC-NEXT:       RootParametersOffset: 24
 ; DXC-NEXT:       NumStaticSamplers: 0
-; DXC-NEXT:       StaticSamplersOffset: 0
+; DXC-NEXT:       StaticSamplersOffset: 84
 ; DXC-NEXT:       Parameters:
 ; DXC-NEXT:         - ParameterType:   0
 ; DXC-NEXT:           ShaderVisibility: 0
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable.ll
index 8e9b4b43b11a6..4f6f0d0bd6a14 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable.ll
@@ -26,7 +26,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
 ; DXC-NEXT:      NumRootParameters: 1 
 ; DXC-NEXT:      RootParametersOffset: 24 
 ; DXC-NEXT:      NumStaticSamplers: 0
-; DXC-NEXT:      StaticSamplersOffset: 0
+; DXC-NEXT:      StaticSamplersOffset: 92
 ; DXC-NEXT:      Parameters:
 ; DXC-NEXT:        - ParameterType:   0
 ; DXC-NEXT:          ShaderVisibility: 0
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
index 10235b7d17960..165e4803f8702 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
@@ -25,6 +25,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
 ; DXC-NEXT:      NumRootParameters: 0
 ; DXC-NEXT:      RootParametersOffset: 24
 ; DXC-NEXT:      NumStaticSamplers: 0
-; DXC-NEXT:      StaticSamplersOffset: 0
+; DXC-NEXT:      StaticSamplersOffset: 24
 ; DXC-NEXT:      Parameters: []
 ; DXC-NEXT:      AllowInputAssemblerInputLayout: true
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootConstants.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootConstants.ll
index 964554fe143ef..d217f396722bc 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootConstants.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootConstants.ll
@@ -24,7 +24,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
 ; DXC-NEXT:      NumRootParameters: 1 
 ; DXC-NEXT:      RootParametersOffset: 24 
 ; DXC-NEXT:      NumStaticSamplers: 0
-; DXC-NEXT:      StaticSamplersOffset: 0
+; DXC-NEXT:      StaticSamplersOffset: 48
 ; DXC-NEXT:      Parameters:
 ; DXC-NEXT:        - ParameterType:   1
 ; DXC-NEXT:          ShaderVisibility: 0
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor.ll
index f77bb96840bea..54292bb651532 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor.ll
@@ -24,7 +24,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
 ; DXC-NEXT:      NumRootParameters: 1 
 ; DXC-NEXT:      RootParametersOffset: 24 
 ; DXC-NEXT:      NumStaticSamplers: 0
-; DXC-NEXT:      StaticSamplersOffset: 0
+; DXC-NEXT:      StaticSamplersOffset: 48
 ; DXC-NEXT:      Parameters:
 ; DXC-NEXT:        - ParameterType:   2
 ; DXC-NEXT:          ShaderVisibility: 0
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor_V1.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor_V1.ll
index ddf556e7fe20a..891a03b688a82 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor_V1.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor_V1.ll
@@ -24,7 +24,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
 ; DXC-NEXT:      NumRootParameters: 1 
 ; DXC-NEXT:      RootParametersOffset: 24 
 ; DXC-NEXT:      NumStaticSamplers: 0
-; DXC-NEXT:      StaticSamplersOffset: 0
+; DXC-NEXT:      StaticSamplersOffset: 44
 ; DXC-NEXT:      Parameters:
 ; DXC-NEXT:        - ParameterType:   2
 ; DXC-NEXT:          ShaderVisibility: 0

>From 7f9237838eff935231d75684613276ed206bb2a6 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 15:30:29 -0700
Subject: [PATCH 04/12] correct offsets in obj2yaml round trip tests

---
 .../ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml   | 4 ++--
 .../ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml   | 4 ++--
 .../DXContainer/RootSignature-DescriptorTable1.0.yaml         | 4 ++--
 .../DXContainer/RootSignature-DescriptorTable1.1.yaml         | 4 ++--
 llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml     | 4 ++--
 .../DXContainer/RootSignature-MultipleParameters.yaml         | 4 ++--
 .../DXContainer/RootSignature-StaticSamplers-Defaults.yaml    | 4 ++--
 .../ObjectYAML/DXContainer/RootSignature-StaticSamplers.yaml  | 4 ++--
 8 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
index 889eccf74001f..70dc35287ba91 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
@@ -17,7 +17,7 @@ Parts:
       NumRootParameters: 1
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 44
       Parameters:         
       - ParameterType: 2 # SRV
         ShaderVisibility: 3 # Domain
@@ -34,7 +34,7 @@ Parts:
 # CHECK-NEXT:      NumRootParameters: 1
 # CHECK-NEXT:      RootParametersOffset: 24
 # CHECK-NEXT:      NumStaticSamplers: 0
-# CHECK-NEXT:      StaticSamplersOffset: 60
+# CHECK-NEXT:      StaticSamplersOffset: 44
 # CHECK-NEXT:      Parameters:         
 # CHECK-NEXT:      - ParameterType: 2
 # CHECK-NEXT:        ShaderVisibility: 3
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml
index 64e01c6836e32..33a74dbf6a3f4 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml
@@ -17,7 +17,7 @@ Parts:
       NumRootParameters: 1
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 48
       Parameters:         
       - ParameterType: 2 # SRV
         ShaderVisibility: 3 # Domain
@@ -35,7 +35,7 @@ Parts:
 # CHECK-NEXT:      NumRootParameters: 1
 # CHECK-NEXT:      RootParametersOffset: 24
 # CHECK-NEXT:      NumStaticSamplers: 0
-# CHECK-NEXT:      StaticSamplersOffset: 60
+# CHECK-NEXT:      StaticSamplersOffset: 48
 # CHECK-NEXT:      Parameters:         
 # CHECK-NEXT:      - ParameterType: 2
 # CHECK-NEXT:        ShaderVisibility: 3
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.0.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.0.yaml
index 0441bb7a256b1..b04549fde88f7 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.0.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.0.yaml
@@ -18,7 +18,7 @@ Parts:
     NumRootParameters: 1
     RootParametersOffset: 24
     NumStaticSamplers: 0
-    StaticSamplersOffset: 60
+    StaticSamplersOffset: 64
     Parameters:         
     - ParameterType: 0 # SRV
       ShaderVisibility: 3 # Domain
@@ -40,7 +40,7 @@ Parts:
 # CHECK-NEXT:     NumRootParameters: 1
 # CHECK-NEXT:     RootParametersOffset: 24
 # CHECK-NEXT:     NumStaticSamplers: 0
-# CHECK-NEXT:     StaticSamplersOffset: 60
+# CHECK-NEXT:     StaticSamplersOffset: 64
 # CHECK-NEXT:     Parameters:         
 # CHECK-NEXT:     - ParameterType: 0
 # CHECK-NEXT:       ShaderVisibility: 3
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.1.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.1.yaml
index d06be5e181418..d8f399010053e 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.1.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-DescriptorTable1.1.yaml
@@ -18,7 +18,7 @@ Parts:
     NumRootParameters: 1
     RootParametersOffset: 24
     NumStaticSamplers: 0
-    StaticSamplersOffset: 60
+    StaticSamplersOffset: 68
     Parameters:         
     - ParameterType: 0 # SRV
       ShaderVisibility: 3 # Domain
@@ -41,7 +41,7 @@ Parts:
 # CHECK-NEXT:       NumRootParameters: 1
 # CHECK-NEXT:       RootParametersOffset: 24
 # CHECK-NEXT:       NumStaticSamplers: 0
-# CHECK-NEXT:       StaticSamplersOffset: 60
+# CHECK-NEXT:       StaticSamplersOffset: 68
 # CHECK-NEXT:       Parameters:
 # CHECK-NEXT:         - ParameterType:   0
 # CHECK-NEXT:           ShaderVisibility: 3
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
index 74816d403183a..c5855a249c31d 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
@@ -17,7 +17,7 @@ Parts:
       NumRootParameters: 0
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 24
       Parameters: []
       AllowInputAssemblerInputLayout: true
       DenyGeometryShaderRootAccess: true
@@ -29,7 +29,7 @@ Parts:
 # CHECK-NEXT:      NumRootParameters: 0
 # CHECK-NEXT:      RootParametersOffset: 24
 # CHECK-NEXT:      NumStaticSamplers: 0
-# CHECK-NEXT:      StaticSamplersOffset: 60
+# CHECK-NEXT:      StaticSamplersOffset: 24
 # CHECK-NEXT:      Parameters: []
 # CHECK-NEXT:      AllowInputAssemblerInputLayout: true
 # CHECK-NEXT:      DenyGeometryShaderRootAccess: true
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
index 947fc096a9207..26d56536b9e44 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
@@ -17,7 +17,7 @@ Parts:
       NumRootParameters: 3
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 140
       Parameters:         
       - ParameterType: 1 # Constants32Bit
         ShaderVisibility: 2 # Hull
@@ -58,7 +58,7 @@ Parts:
 # CHECK-NEXT:      NumRootParameters: 4
 # CHECK-NEXT:      RootParametersOffset: 24
 # CHECK-NEXT:      NumStaticSamplers: 0
-# CHECK-NEXT:      StaticSamplersOffset: 60
+# CHECK-NEXT:      StaticSamplersOffset: 140
 # CHECK-NEXT:      Parameters:
 # CHECK-NEXT:        - ParameterType:   1
 # CHECK-NEXT:          ShaderVisibility: 2
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers-Defaults.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers-Defaults.yaml
index 2189753be0b74..5df7da87aafd2 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers-Defaults.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers-Defaults.yaml
@@ -15,7 +15,7 @@ Parts:
     RootSignature:
       Version: 2
       NumRootParameters: 0
-      RootParametersOffset: 0
+      RootParametersOffset: 24
       NumStaticSamplers: 1
       StaticSamplersOffset: 24
       Parameters: []
@@ -31,7 +31,7 @@ Parts:
 #CHECK-NEXT:    RootSignature:
 #CHECK-NEXT:      Version:         2
 #CHECK-NEXT:      NumRootParameters: 0
-#CHECK-NEXT:      RootParametersOffset: 0
+#CHECK-NEXT:      RootParametersOffset: 24
 #CHECK-NEXT:      NumStaticSamplers: 1
 #CHECK-NEXT:      StaticSamplersOffset: 24
 #CHECK-NEXT:      Parameters:      []
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers.yaml
index 8f8083e091253..82d9a4ffdb4f8 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplers.yaml
@@ -15,7 +15,7 @@ Parts:
     RootSignature:
       Version: 2
       NumRootParameters: 0
-      RootParametersOffset: 0
+      RootParametersOffset: 24
       NumStaticSamplers: 1
       StaticSamplersOffset: 24
       Parameters: []
@@ -41,7 +41,7 @@ Parts:
 #CHECK-NEXT:    RootSignature:
 #CHECK-NEXT:      Version:         2
 #CHECK-NEXT:      NumRootParameters: 0
-#CHECK-NEXT:      RootParametersOffset: 0
+#CHECK-NEXT:      RootParametersOffset: 24
 #CHECK-NEXT:      NumStaticSamplers: 1
 #CHECK-NEXT:      StaticSamplersOffset: 24
 #CHECK-NEXT:      Parameters:      []

>From c1e71aa45d3cab6fa8154c9071c82e2b46a24034 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 15:32:00 -0700
Subject: [PATCH 05/12] correct offsets in tools tests

---
 llvm/test/tools/llvm-objcopy/DXContainer/copy-basic.test        | 2 +-
 .../tools/llvm-objcopy/DXContainer/remove-root-signature.test   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/copy-basic.test b/llvm/test/tools/llvm-objcopy/DXContainer/copy-basic.test
index 16ac30f059487..b63bc09c370df 100644
--- a/llvm/test/tools/llvm-objcopy/DXContainer/copy-basic.test
+++ b/llvm/test/tools/llvm-objcopy/DXContainer/copy-basic.test
@@ -265,7 +265,7 @@ Parts:
       NumRootParameters: 0
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 0
+      StaticSamplersOffset: 24
       Parameters:      []
   - Name:            PSV0
     Size:            76
diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/remove-root-signature.test b/llvm/test/tools/llvm-objcopy/DXContainer/remove-root-signature.test
index 3bb11787b646a..585c4d6ba4d90 100644
--- a/llvm/test/tools/llvm-objcopy/DXContainer/remove-root-signature.test
+++ b/llvm/test/tools/llvm-objcopy/DXContainer/remove-root-signature.test
@@ -273,7 +273,7 @@ Parts:
       NumRootParameters: 0
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 0
+      StaticSamplersOffset: 24
       Parameters:      []
   - Name:            PSV0
     Size:            76

>From 6802d7b1bd07ef5bebd9993639cc0eef1f3c6726 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 15:46:01 -0700
Subject: [PATCH 06/12] correct offset values in unit tests

---
 .../ObjectYAML/DXContainerYAMLTest.cpp        | 40 +++++++++----------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
index 9e6f7cc4f7dbd..4cf8f61e83c8d 100644
--- a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
+++ b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
@@ -130,7 +130,7 @@ TEST(RootSignature, ParseRootFlags) {
         NumRootParameters: 0
         RootParametersOffset: 24
         NumStaticSamplers: 0
-        StaticSamplersOffset: 0
+        StaticSamplersOffset: 24
         Parameters: []
         AllowInputAssemblerInputLayout: true
     )"));
@@ -141,7 +141,7 @@ TEST(RootSignature, ParseRootFlags) {
       0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+      0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
   };
 
   EXPECT_EQ(Storage.size(), 68u);
@@ -168,9 +168,9 @@ TEST(RootSignature, HeaderData) {
       RootSignature:
         Version: 2
         NumRootParameters: 1
-        RootParametersOffset: 255
+        RootParametersOffset: 24
         NumStaticSamplers: 0
-        StaticSamplersOffset: 0
+        StaticSamplersOffset: 48
         Parameters:
           - ParameterType: 1
             ShaderVisibility: 2
@@ -187,8 +187,8 @@ TEST(RootSignature, HeaderData) {
       0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
       0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
-      0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+      0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x30, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
       0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -220,9 +220,9 @@ TEST(RootSignature, ParseRootConstants) {
       RootSignature:
         Version: 2
         NumRootParameters: 1
-        RootParametersOffset: 36
+        RootParametersOffset: 24
         NumStaticSamplers: 0
-        StaticSamplersOffset: 0
+        StaticSamplersOffset: 48
         Parameters:
           - ParameterType: 1
             ShaderVisibility: 2
@@ -239,8 +239,8 @@ TEST(RootSignature, ParseRootConstants) {
       0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
       0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
-      0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+      0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x30, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
       0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -274,7 +274,7 @@ TEST(RootSignature, ParseRootDescriptorsV10) {
       NumRootParameters: 1
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 44
       Parameters:         
       - ParameterType: 2 # SRV
         ShaderVisibility: 3 # Domain
@@ -291,7 +291,7 @@ TEST(RootSignature, ParseRootDescriptorsV10) {
       0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+      0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
       0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
       0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -325,7 +325,7 @@ TEST(RootSignature, ParseRootDescriptorsV11) {
       NumRootParameters: 1
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 48
       Parameters:         
       - ParameterType: 2 # SRV
         ShaderVisibility: 3 # Domain
@@ -343,7 +343,7 @@ TEST(RootSignature, ParseRootDescriptorsV11) {
       0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
       0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+      0x30, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
       0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
       0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -377,7 +377,7 @@ TEST(RootSignature, ParseDescriptorTableV10) {
       NumRootParameters: 1
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 64
       Parameters:         
       - ParameterType: 0 # SRV
         ShaderVisibility: 3 # Domain
@@ -399,7 +399,7 @@ TEST(RootSignature, ParseDescriptorTableV10) {
       0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x40, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00,
       0x2a, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00,
@@ -433,7 +433,7 @@ TEST(RootSignature, ParseDescriptorTableV11) {
       NumRootParameters: 1
       RootParametersOffset: 24
       NumStaticSamplers: 0
-      StaticSamplersOffset: 60
+      StaticSamplersOffset: 68
       Parameters:         
       - ParameterType: 0 # Descriptor Table
         ShaderVisibility: 3 # Domain
@@ -456,7 +456,7 @@ TEST(RootSignature, ParseDescriptorTableV11) {
       0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
       0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x44, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
       0x2a, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
@@ -487,7 +487,7 @@ TEST(RootSignature, ParseStaticSamplers) {
     RootSignature:
       Version: 2
       NumRootParameters: 0
-      RootParametersOffset: 0
+      RootParametersOffset: 24
       NumStaticSamplers: 1
       StaticSamplersOffset: 24
       Parameters: []
@@ -516,7 +516,7 @@ TEST(RootSignature, ParseStaticSamplers) {
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x52, 0x54, 0x53, 0x30, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x18, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
       0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
       0xa4, 0x70, 0x9d, 0x3f, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,

>From b2d4b85ef581e639b44752e370b7c3583411d596 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 15:54:57 -0700
Subject: [PATCH 07/12] add testing of error messages

---
 ...Signature-Invalid-RootParameterOffset.yaml | 23 +++++++++++++++
 ...ignature-Invalid-StaticSamplersOffset.yaml | 29 +++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-RootParameterOffset.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-StaticSamplersOffset.yaml

diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-RootParameterOffset.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-RootParameterOffset.yaml
new file mode 100644
index 0000000000000..22606761fe5ba
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-RootParameterOffset.yaml
@@ -0,0 +1,23 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+
+# CHECK: error: Specified RootParametersOffset does not match required value: 24.
+
+--- !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:       1
+  PartOffsets:     [ 60 ]
+Parts:
+  - Name:            RTS0
+    Size:            24
+    RootSignature:
+      Version: 2
+      NumRootParameters: 0
+      RootParametersOffset: 36
+      NumStaticSamplers: 0
+      StaticSamplersOffset: 24
+      Parameters: []
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-StaticSamplersOffset.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-StaticSamplersOffset.yaml
new file mode 100644
index 0000000000000..e805526ea7c51
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Invalid-StaticSamplersOffset.yaml
@@ -0,0 +1,29 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+
+# CHECK: error: Specified StaticSamplersOffset does not match computed value: 48.
+
+--- !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:       1
+  PartOffsets:     [ 60 ]
+Parts:
+  - Name:            RTS0
+    Size:            24
+    RootSignature:
+      Version: 2
+      NumRootParameters: 0
+      RootParametersOffset: 24
+      NumStaticSamplers: 0
+      StaticSamplersOffset: 0
+      Parameters:
+      - ParameterType: 2
+        ShaderVisibility: 3
+        Descriptor:
+          ShaderRegister: 31
+          RegisterSpace: 32
+          DATA_STATIC_WHILE_SET_AT_EXECUTE: true

>From 915abb101a9ba834a1fa9fc88e366c91725c42fb Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 16:05:51 -0700
Subject: [PATCH 08/12] add testing of computed offsets

---
 .../RootSignature-StaticSamplerOffset1.0.yaml | 60 +++++++++++++++++++
 .../RootSignature-StaticSamplerOffset1.1.yaml | 60 +++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.0.yaml
 create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.1.yaml

diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.0.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.0.yaml
new file mode 100644
index 0000000000000..347d8f3be1710
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.0.yaml
@@ -0,0 +1,60 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+## This test checks that we correctly compute the StaticSamplersOffset for each
+## of the root parameter types (version 1.0 variants)
+
+## StaticSamplerOffset
+##  = 24 (root signature header)
+##  + 12 (header) + 12 (root constants)
+##  + 12 (header) + 8 (v1.1 root descriptor)
+##  + 12 (header) + 8 (root descriptor table)
+##  + 20 (v1.1 descriptor range)
+##  + 0 (root flags)
+##  = 108
+
+# CHECK: StaticSamplersOffset: 108
+
+--- !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:       1
+  PartOffsets:     [ 60 ]
+Parts:
+  - Name:            RTS0
+    Size:            108
+    RootSignature:
+      Version: 1
+      NumRootParameters: 3
+      RootParametersOffset: 24
+      NumStaticSamplers: 0
+      StaticSamplersOffset: 108
+      Parameters:
+      - ParameterType: 1 # RootConstants
+        ShaderVisibility: 0
+        Constants:
+          Num32BitValues: 16
+          ShaderRegister: 15
+          RegisterSpace: 14
+      - ParameterType: 2 # SRV
+        ShaderVisibility: 0
+        Descriptor:
+          ShaderRegister: 31
+          RegisterSpace: 32
+          DATA_STATIC_WHILE_SET_AT_EXECUTE: true
+      - ParameterType: 0 # Descriptor Table
+        ShaderVisibility: 0
+        Table:
+          NumRanges: 1
+          Ranges:
+            - RangeType: 0 # CBV
+              NumDescriptors: -1
+              BaseShaderRegister: 42
+              RegisterSpace: 43
+              OffsetInDescriptorsFromTableStart: 41
+              DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS: true
+      AllowInputAssemblerInputLayout: true
+      DenyGeometryShaderRootAccess: true
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.1.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.1.yaml
new file mode 100644
index 0000000000000..8e03e1a8b29be
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-StaticSamplerOffset1.1.yaml
@@ -0,0 +1,60 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+## This test checks that we correctly compute the StaticSamplersOffset for each
+## of the root parameter types (version 1.1 variants)
+
+## StaticSamplerOffset
+##  = 24 (root signature header)
+##  + 12 (header) + 12 (root constants)
+##  + 12 (header) + 12 (v1.1 root descriptor)
+##  + 12 (header) + 8 (root descriptor table)
+##  + 24 (v1.1 descriptor range)
+##  + 0 (root flags)
+##  = 116
+
+# CHECK: StaticSamplersOffset: 116
+
+--- !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:       1
+  PartOffsets:     [ 60 ]
+Parts:
+  - Name:            RTS0
+    Size:            116
+    RootSignature:
+      Version: 2
+      NumRootParameters: 3
+      RootParametersOffset: 24
+      NumStaticSamplers: 0
+      StaticSamplersOffset: 116
+      Parameters:
+      - ParameterType: 1 # RootConstants
+        ShaderVisibility: 0
+        Constants:
+          Num32BitValues: 16
+          ShaderRegister: 15
+          RegisterSpace: 14
+      - ParameterType: 2 # SRV
+        ShaderVisibility: 0
+        Descriptor:
+          ShaderRegister: 31
+          RegisterSpace: 32
+          DATA_STATIC_WHILE_SET_AT_EXECUTE: true
+      - ParameterType: 0 # Descriptor Table
+        ShaderVisibility: 0
+        Table:
+          NumRanges: 1
+          Ranges:
+            - RangeType: 0 # CBV
+              NumDescriptors: -1
+              BaseShaderRegister: 42
+              RegisterSpace: 43
+              OffsetInDescriptorsFromTableStart: 41
+              DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS: true
+      AllowInputAssemblerInputLayout: true
+      DenyGeometryShaderRootAccess: true

>From b913992389b62e45ee896470e63ac8ddc88e9dc3 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Tue, 26 Aug 2025 16:16:23 -0700
Subject: [PATCH 09/12] add testing of optionally specified parameters

---
 .../RootSignature-OptionalOffsets.yaml        | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-OptionalOffsets.yaml

diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-OptionalOffsets.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-OptionalOffsets.yaml
new file mode 100644
index 0000000000000..88d7c632968be
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-OptionalOffsets.yaml
@@ -0,0 +1,56 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+## This test checks that we correctly compute the RootParametersOffset and
+## StaticSamplersOffset when they are not explicitly provided
+
+## StaticSamplerOffset
+##  = 24 (root signature header)
+##  + 12 (header) + 12 (root constants)
+##  + 12 (header) + 12 (v1.1 root descriptor)
+##  + 12 (header) + 8 (root descriptor table)
+##  + 24 (v1.1 descriptor range)
+##  = 116
+
+# CHECK: RootParametersOffset: 24
+# CHECK: StaticSamplersOffset: 116
+
+--- !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:       1
+  PartOffsets:     [ 60 ]
+Parts:
+  - Name:            RTS0
+    Size:            116
+    RootSignature:
+      Version: 2
+      NumRootParameters: 3
+      NumStaticSamplers: 0
+      Parameters:
+      - ParameterType: 1 # RootConstants
+        ShaderVisibility: 0
+        Constants:
+          Num32BitValues: 16
+          ShaderRegister: 15
+          RegisterSpace: 14
+      - ParameterType: 2 # SRV
+        ShaderVisibility: 0
+        Descriptor:
+          ShaderRegister: 31
+          RegisterSpace: 32
+          DATA_STATIC_WHILE_SET_AT_EXECUTE: true
+      - ParameterType: 0 # Descriptor Table
+        ShaderVisibility: 0
+        Table:
+          NumRanges: 1
+          Ranges:
+            - RangeType: 0 # CBV
+              NumDescriptors: -1
+              BaseShaderRegister: 42
+              RegisterSpace: 43
+              OffsetInDescriptorsFromTableStart: 41
+              DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS: true

>From b66c864263f679765c113ce194f16c356b9754c2 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Wed, 27 Aug 2025 09:22:42 -0700
Subject: [PATCH 10/12] review: move offset computation to RootSignatureDesc in
 common place

---
 .../llvm/MC/DXContainerRootSignature.h        |  2 +
 llvm/lib/MC/DXContainerRootSignature.cpp      | 31 ++++++---
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp    | 66 +++++++------------
 3 files changed, 47 insertions(+), 52 deletions(-)

diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 4db3f3458c808..3cb631b0a8871 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -110,6 +110,8 @@ struct RootSignatureDesc {
   LLVM_ABI void write(raw_ostream &OS) const;
 
   LLVM_ABI size_t getSize() const;
+  LLVM_ABI uint32_t computeRootParametersOffset() const;
+  LLVM_ABI uint32_t computeStaticSamplersOffset() const;
 };
 } // namespace mcdxbc
 } // namespace llvm
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index a13b6e34df35a..96b46446a8f1a 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -29,23 +29,33 @@ static void rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
 }
 
 size_t RootSignatureDesc::getSize() const {
-  size_t Size =
-      sizeof(dxbc::RTS0::v1::RootSignatureHeader) +
-      ParametersContainer.size() * sizeof(dxbc::RTS0::v1::RootParameterHeader) +
+  uint32_t StaticSamplersOffset = computeStaticSamplersOffset();
+  size_t StaticSamplersSize =
       StaticSamplers.size() * sizeof(dxbc::RTS0::v1::StaticSampler);
 
+  return size_t(StaticSamplersOffset) + StaticSamplersSize;
+}
+
+uint32_t RootSignatureDesc::computeRootParametersOffset() const {
+  return sizeof(dxbc::RTS0::v1::RootSignatureHeader);
+}
+
+uint32_t RootSignatureDesc::computeStaticSamplersOffset() const {
+  uint32_t Offset = computeRootParametersOffset();
+
   for (const RootParameterInfo &I : ParametersContainer) {
+    Offset += sizeof(dxbc::RTS0::v1::RootParameterHeader);
     switch (I.Type) {
     case dxbc::RootParameterType::Constants32Bit:
-      Size += sizeof(dxbc::RTS0::v1::RootConstants);
+      Offset += sizeof(dxbc::RTS0::v1::RootConstants);
       break;
     case dxbc::RootParameterType::CBV:
     case dxbc::RootParameterType::SRV:
     case dxbc::RootParameterType::UAV:
       if (Version == 1)
-        Size += sizeof(dxbc::RTS0::v1::RootDescriptor);
+        Offset += sizeof(dxbc::RTS0::v1::RootDescriptor);
       else
-        Size += sizeof(dxbc::RTS0::v2::RootDescriptor);
+        Offset += sizeof(dxbc::RTS0::v2::RootDescriptor);
 
       break;
     case dxbc::RootParameterType::DescriptorTable:
@@ -54,15 +64,16 @@ size_t RootSignatureDesc::getSize() const {
 
       // 4 bytes for the number of ranges in table and
       // 4 bytes for the ranges offset
-      Size += 2 * sizeof(uint32_t);
+      Offset += 2 * sizeof(uint32_t);
       if (Version == 1)
-        Size += sizeof(dxbc::RTS0::v1::DescriptorRange) * Table.Ranges.size();
+        Offset += sizeof(dxbc::RTS0::v1::DescriptorRange) * Table.Ranges.size();
       else
-        Size += sizeof(dxbc::RTS0::v2::DescriptorRange) * Table.Ranges.size();
+        Offset += sizeof(dxbc::RTS0::v2::DescriptorRange) * Table.Ranges.size();
       break;
     }
   }
-  return Size;
+
+  return Offset;
 }
 
 void RootSignatureDesc::write(raw_ostream &OS) const {
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 726a879075435..9aee4ffd13925 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -269,27 +269,11 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
       mcdxbc::RootSignatureDesc RS;
       RS.Flags = P.RootSignature->getEncodedFlags();
       RS.Version = P.RootSignature->Version;
-
-      // Handling of RootParameters
-      const uint32_t RootHeaderSize =
-          sizeof(dxbc::RTS0::v1::RootSignatureHeader);
-      if (P.RootSignature->RootParametersOffset &&
-          P.RootSignature->RootParametersOffset.value() != RootHeaderSize) {
-        return createStringError(
-            errc::invalid_argument,
-            "Specified RootParametersOffset does not match required value: %d.",
-            RootHeaderSize);
-      }
-
-      uint32_t Offset = RootHeaderSize;
-      RS.RootParameterOffset = Offset;
+      RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
 
       for (DXContainerYAML::RootParameterLocationYaml &L :
            P.RootSignature->Parameters.Locations) {
 
-        // Offset RootParameterHeader
-        Offset += sizeof(dxbc::RTS0::v1::RootParameterHeader);
-
         assert(dxbc::isValidParameterType(L.Header.Type) &&
                "invalid DXContainer YAML");
         assert(dxbc::isValidShaderVisibility(L.Header.Visibility) &&
@@ -308,8 +292,6 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
           Constants.RegisterSpace = ConstantYaml.RegisterSpace;
           Constants.ShaderRegister = ConstantYaml.ShaderRegister;
           RS.ParametersContainer.addParameter(Type, Visibility, Constants);
-
-          Offset += sizeof(dxbc::RTS0::v1::RootConstants);
           break;
         }
         case dxbc::RootParameterType::CBV:
@@ -321,11 +303,8 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
           dxbc::RTS0::v2::RootDescriptor Descriptor;
           Descriptor.RegisterSpace = DescriptorYaml.RegisterSpace;
           Descriptor.ShaderRegister = DescriptorYaml.ShaderRegister;
-          if (RS.Version > 1) {
+          if (RS.Version > 1)
             Descriptor.Flags = DescriptorYaml.getEncodedFlags();
-            Offset += sizeof(dxbc::RTS0::v2::RootDescriptor);
-          } else
-            Offset += sizeof(dxbc::RTS0::v1::RootDescriptor);
 
           RS.ParametersContainer.addParameter(Type, Visibility, Descriptor);
           break;
@@ -334,8 +313,6 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
           const DXContainerYAML::DescriptorTableYaml &TableYaml =
               P.RootSignature->Parameters.getOrInsertTable(L);
           mcdxbc::DescriptorTable Table;
-          Offset +=
-              2 * sizeof(uint32_t); // DescriptorTable NumRanges and Offset
           for (const auto &R : TableYaml.Ranges) {
 
             dxbc::RTS0::v2::DescriptorRange Range;
@@ -346,11 +323,8 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
             Range.OffsetInDescriptorsFromTableStart =
                 R.OffsetInDescriptorsFromTableStart;
 
-            if (RS.Version > 1) {
-              Offset += sizeof(dxbc::RTS0::v2::DescriptorRange);
+            if (RS.Version > 1)
               Range.Flags = R.getEncodedFlags();
-            } else
-              Offset += sizeof(dxbc::RTS0::v1::DescriptorRange);
 
             Table.Ranges.push_back(Range);
           }
@@ -360,19 +334,6 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
         }
       }
 
-      // Handling of StaticSamplers
-      RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
-
-      if (P.RootSignature->StaticSamplersOffset &&
-          P.RootSignature->StaticSamplersOffset.value() != Offset) {
-        return createStringError(
-            errc::invalid_argument,
-            "Specified StaticSamplersOffset does not match computed value: %d.",
-            Offset);
-      }
-
-      RS.StaticSamplersOffset = Offset;
-
       for (const auto &Param : P.RootSignature->samplers()) {
         dxbc::RTS0::v1::StaticSampler NewSampler;
         NewSampler.Filter = Param.Filter;
@@ -392,6 +353,27 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
         RS.StaticSamplers.push_back(NewSampler);
       }
 
+      // Handling of offsets
+      RS.RootParameterOffset = RS.computeRootParametersOffset();
+      if (P.RootSignature->RootParametersOffset &&
+          P.RootSignature->RootParametersOffset.value() !=
+              RS.RootParameterOffset) {
+        return createStringError(
+            errc::invalid_argument,
+            "Specified RootParametersOffset does not match required value: %d.",
+            RS.RootParameterOffset);
+      }
+
+      RS.StaticSamplersOffset = RS.computeStaticSamplersOffset();
+      if (P.RootSignature->StaticSamplersOffset &&
+          P.RootSignature->StaticSamplersOffset.value() !=
+              RS.StaticSamplersOffset) {
+        return createStringError(
+            errc::invalid_argument,
+            "Specified StaticSamplersOffset does not match computed value: %d.",
+            RS.StaticSamplersOffset);
+      }
+
       RS.write(OS);
       break;
     }

>From 8ff2d0a3aec48ce0b739d5d24e26980d11e2dd20 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Wed, 27 Aug 2025 10:37:54 -0700
Subject: [PATCH 11/12] review: nit

---
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 9aee4ffd13925..283749ec12971 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -305,7 +305,6 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
           Descriptor.ShaderRegister = DescriptorYaml.ShaderRegister;
           if (RS.Version > 1)
             Descriptor.Flags = DescriptorYaml.getEncodedFlags();
-
           RS.ParametersContainer.addParameter(Type, Visibility, Descriptor);
           break;
         }

>From 3736a63076ef229490e7abbd348c4e20f13b2eb4 Mon Sep 17 00:00:00 2001
From: Finn Plummer <mail at inbelic.dev>
Date: Wed, 27 Aug 2025 10:43:04 -0700
Subject: [PATCH 12/12] review: assert computed offset matches written offset

---
 llvm/lib/MC/DXContainerRootSignature.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 96b46446a8f1a..3513892ffcdcc 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -20,12 +20,13 @@ static uint32_t writePlaceholder(raw_svector_ostream &Stream) {
   return Offset;
 }
 
-static void rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
-                                       uint32_t Offset) {
+static uint32_t rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
+                                           uint32_t Offset) {
   uint32_t Value =
       support::endian::byte_swap<uint32_t, llvm::endianness::little>(
           Stream.tell());
   Stream.pwrite(reinterpret_cast<const char *>(&Value), sizeof(Value), Offset);
+  return Value;
 }
 
 size_t RootSignatureDesc::getSize() const {
@@ -151,7 +152,9 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
     }
     }
   }
-  rewriteOffsetToCurrentByte(BOS, SSO);
+  [[maybe_unused]] uint32_t Offset = rewriteOffsetToCurrentByte(BOS, SSO);
+  assert(Offset == computeStaticSamplersOffset() &&
+         "Computed offset does not match written offset");
   for (const auto &S : StaticSamplers) {
     support::endian::write(BOS, S.Filter, llvm::endianness::little);
     support::endian::write(BOS, S.AddressU, llvm::endianness::little);



More information about the llvm-commits mailing list