[llvm] [DirectX] adding support in obj2yaml and yaml2obj to root constants (PR #127840)

Damyan Pepper via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 21 11:28:47 PST 2025


================
@@ -546,13 +560,75 @@ struct ProgramSignatureElement {
 static_assert(sizeof(ProgramSignatureElement) == 32,
               "ProgramSignatureElement is misaligned");
 
+struct RootConstants {
+  uint32_t ShaderRegister = 0;
+  uint32_t RegisterSpace = 0;
+  uint32_t Num32BitValues = 0;
+
+  RootConstants() = default;
+
+  void swapBytes() {
+    sys::swapByteOrder(ShaderRegister);
+    sys::swapByteOrder(RegisterSpace);
+    sys::swapByteOrder(Num32BitValues);
+  }
+};
+
+struct RootParameter {
+  dxbc::RootParameterType ParameterType;
+  union {
+    dxbc::RootConstants Constants;
+  };
----------------
damyanp wrote:

I think that'll become a problem when you add more entries to that enum.

Some options I see:

## 1. Deal with it later when you add more types
```suggestion
    dxbc::RootConstants Constants;
```

## 2. Use std::variant
```suggestion
    std::variant<dxbc::RootConstants> Parameter;
```

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


More information about the llvm-commits mailing list