[llvm] [NFC] Refactoring MCDXBC to support out of order storage of root parameters (PR #137284)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed May 14 21:04:55 PDT 2025


================
@@ -78,27 +78,31 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
   assert(NumParameters == ParamsOffsets.size());
   for (size_t I = 0; I < NumParameters; ++I) {
     rewriteOffsetToCurrentByte(BOS, ParamsOffsets[I]);
-    const mcdxbc::RootParameter &P = Parameters[I];
-
-    switch (P.Header.ParameterType) {
-    case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
-      support::endian::write(BOS, P.Constants.ShaderRegister,
+    const auto &[Type, Loc] = ParametersContainer.getTypeAndLocForParameter(I);
+    switch (Type) {
+    case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
+      const dxbc::RootConstants &Constants =
+          ParametersContainer.getConstant(Loc);
+      support::endian::write(BOS, Constants.ShaderRegister,
                              llvm::endianness::little);
-      support::endian::write(BOS, P.Constants.RegisterSpace,
+      support::endian::write(BOS, Constants.RegisterSpace,
                              llvm::endianness::little);
-      support::endian::write(BOS, P.Constants.Num32BitValues,
+      support::endian::write(BOS, Constants.Num32BitValues,
                              llvm::endianness::little);
-      break;
+    } break;
     case llvm::to_underlying(dxbc::RootParameterType::CBV):
     case llvm::to_underlying(dxbc::RootParameterType::SRV):
-    case llvm::to_underlying(dxbc::RootParameterType::UAV):
-      support::endian::write(BOS, P.Descriptor.ShaderRegister,
+    case llvm::to_underlying(dxbc::RootParameterType::UAV): {
+      const dxbc::RTS0::v2::RootDescriptor &Descriptor =
+          ParametersContainer.getRootDescriptor(Loc);
+
+      support::endian::write(BOS, Descriptor.ShaderRegister,
                              llvm::endianness::little);
-      support::endian::write(BOS, P.Descriptor.RegisterSpace,
+      support::endian::write(BOS, Descriptor.RegisterSpace,
                              llvm::endianness::little);
       if (Version > 1)
-        support::endian::write(BOS, P.Descriptor.Flags,
-                               llvm::endianness::little);
+        support::endian::write(BOS, Descriptor.Flags, llvm::endianness::little);
+    } break;
----------------
bogner wrote:

```suggestion
      break;
    }
```

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


More information about the llvm-commits mailing list