[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 12:01:38 PDT 2025
================
@@ -9,18 +9,81 @@
#include "llvm/BinaryFormat/DXContainer.h"
#include <cstdint>
#include <limits>
+#include <variant>
namespace llvm {
class raw_ostream;
namespace mcdxbc {
-struct RootParameter {
+struct RootParameterInfo {
dxbc::RootParameterHeader Header;
- union {
- dxbc::RootConstants Constants;
- dxbc::RTS0::v2::RootDescriptor Descriptor;
- };
+ size_t Location;
+
+ RootParameterInfo() = default;
+
+ RootParameterInfo(dxbc::RootParameterHeader H, size_t L)
+ : Header(H), Location(L) {}
+};
+
+using RootDescriptor = std::variant<dxbc::RTS0::v1::RootDescriptor,
+ dxbc::RTS0::v2::RootDescriptor>;
+using ParametersView = std::variant<const dxbc::RootConstants *,
+ const dxbc::RTS0::v1::RootDescriptor *,
+ const dxbc::RTS0::v2::RootDescriptor *>;
+struct RootParametersContainer {
+ SmallVector<RootParameterInfo> ParametersInfo;
+
+ SmallVector<dxbc::RootConstants> Constants;
+ SmallVector<RootDescriptor> Descriptors;
----------------
bogner wrote:
We're not tied to the binary format itself here, so I think it would be quite a bit simpler to just have this vector contain the `v2` descriptors:
```c++
SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors;
```
This should end up simplifying `RootSignatureDesc::write`, as we have the version there, so we can just check the version for the later fields when we write it out:
```c++
support::endian::write(BOS, Descriptor.ShaderRegister,
llvm::endianness::little);
support::endian::write(BOS, Descriptor.RegisterSpace,
llvm::endianness::little);
if (Version > 1)
support::endian::write(BOS, Descriptor.Flags, llvm::endianness::little);
```
https://github.com/llvm/llvm-project/pull/137284
More information about the llvm-commits
mailing list