1111#include " llvm/Support/ErrorHandling.h"
1212#include < cstddef>
1313#include < cstdint>
14+ #include < optional>
1415#include < variant>
1516
1617namespace llvm {
1718
1819class raw_ostream ;
1920namespace mcdxbc {
2021
21- struct RootParameterHeader : public dxbc ::RootParameterHeader {
22-
22+ struct RootParameterInfo {
23+ dxbc::RootParameterHeader Header;
2324 size_t Location;
2425
25- RootParameterHeader () = default ;
26+ RootParameterInfo () = default ;
2627
27- RootParameterHeader (dxbc::RootParameterHeader H, size_t L)
28- : dxbc::RootParameterHeader (H), Location(L) {}
28+ RootParameterInfo (dxbc::RootParameterHeader H, size_t L)
29+ : Header (H), Location(L) {}
2930};
3031
3132using RootDescriptor = std::variant<dxbc::RST0::v0::RootDescriptor,
3233 dxbc::RST0::v1::RootDescriptor>;
3334using ParametersView =
3435 std::variant<dxbc::RootConstants, dxbc::RST0::v0::RootDescriptor,
3536 dxbc::RST0::v1::RootDescriptor>;
36- struct RootParameter {
37- SmallVector<RootParameterHeader> Headers ;
37+ struct RootParametersContainer {
38+ SmallVector<RootParameterInfo> ParametersInfo ;
3839
3940 SmallVector<dxbc::RootConstants> Constants;
4041 SmallVector<RootDescriptor> Descriptors;
4142
42- void addHeader (dxbc::RootParameterHeader H, size_t L) {
43- Headers .push_back (RootParameterHeader (H, L));
43+ void addInfo (dxbc::RootParameterHeader H, size_t L) {
44+ ParametersInfo .push_back (RootParameterInfo (H, L));
4445 }
4546
4647 void addParameter (dxbc::RootParameterHeader H, dxbc::RootConstants C) {
47- addHeader (H, Constants.size ());
48+ addInfo (H, Constants.size ());
4849 Constants.push_back (C);
4950 }
5051
5152 void addParameter (dxbc::RootParameterHeader H,
5253 dxbc::RST0::v0::RootDescriptor D) {
53- addHeader (H, Descriptors.size ());
54+ addInfo (H, Descriptors.size ());
5455 Descriptors.push_back (D);
5556 }
5657
5758 void addParameter (dxbc::RootParameterHeader H,
5859 dxbc::RST0::v1::RootDescriptor D) {
59- addHeader (H, Descriptors.size ());
60+ addInfo (H, Descriptors.size ());
6061 Descriptors.push_back (D);
6162 }
6263
63- ParametersView get (const RootParameterHeader & H) const {
64- switch (H.ParameterType ) {
64+ std::optional< ParametersView> getParameter (const RootParameterInfo * H) const {
65+ switch (H-> Header .ParameterType ) {
6566 case llvm::to_underlying (dxbc::RootParameterType::Constants32Bit):
66- return Constants[H. Location ];
67+ return Constants[H-> Location ];
6768 case llvm::to_underlying (dxbc::RootParameterType::CBV):
6869 case llvm::to_underlying (dxbc::RootParameterType::SRV):
6970 case llvm::to_underlying (dxbc::RootParameterType::UAV):
70- RootDescriptor VersionedParam = Descriptors[H. Location ];
71+ RootDescriptor VersionedParam = Descriptors[H-> Location ];
7172 if (std::holds_alternative<dxbc::RST0::v0::RootDescriptor>(
7273 VersionedParam))
7374 return std::get<dxbc::RST0::v0::RootDescriptor>(VersionedParam);
7475 return std::get<dxbc::RST0::v1::RootDescriptor>(VersionedParam);
7576 }
7677
77- llvm_unreachable ( " Unimplemented parameter type " ) ;
78+ return std:: nullopt ;
7879 }
7980
80- struct iterator {
81- const RootParameter &Parameters;
82- SmallVector<RootParameterHeader>::const_iterator Current;
83-
84- // Changed parameter type to match member variable (removed const)
85- iterator (const RootParameter &P,
86- SmallVector<RootParameterHeader>::const_iterator C)
87- : Parameters(P), Current(C) {}
88- iterator (const iterator &) = default ;
89-
90- ParametersView operator *() {
91- ParametersView Val;
92- switch (Current->ParameterType ) {
93- case llvm::to_underlying (dxbc::RootParameterType::Constants32Bit):
94- Val = Parameters.Constants [Current->Location ];
95- break ;
96-
97- case llvm::to_underlying (dxbc::RootParameterType::CBV):
98- case llvm::to_underlying (dxbc::RootParameterType::SRV):
99- case llvm::to_underlying (dxbc::RootParameterType::UAV):
100- RootDescriptor VersionedParam =
101- Parameters.Descriptors [Current->Location ];
102- if (std::holds_alternative<dxbc::RST0::v0::RootDescriptor>(
103- VersionedParam))
104- Val = std::get<dxbc::RST0::v0::RootDescriptor>(VersionedParam);
105- else
106- Val = std::get<dxbc::RST0::v1::RootDescriptor>(VersionedParam);
107- break ;
108- }
109- return Val;
110- }
111-
112- iterator operator ++() {
113- Current++;
114- return *this ;
115- }
116-
117- iterator operator ++(int ) {
118- iterator Tmp = *this ;
119- ++*this ;
120- return Tmp;
121- }
122-
123- iterator operator --() {
124- Current--;
125- return *this ;
126- }
127-
128- iterator operator --(int ) {
129- iterator Tmp = *this ;
130- --*this ;
131- return Tmp;
132- }
133-
134- bool operator ==(const iterator I) { return I.Current == Current; }
135- bool operator !=(const iterator I) { return !(*this == I); }
136- };
137-
138- iterator begin () const { return iterator (*this , Headers.begin ()); }
81+ size_t size () const { return ParametersInfo.size (); }
13982
140- iterator end () const { return iterator (*this , Headers.end ()); }
141-
142- size_t size () const { return Headers.size (); }
143-
144- bool isEmpty () const { return Headers.empty (); }
83+ SmallVector<RootParameterInfo>::const_iterator begin () const {
84+ return ParametersInfo.begin ();
85+ }
86+ SmallVector<RootParameterInfo>::const_iterator end () const {
87+ return ParametersInfo.end ();
88+ }
14589
146- llvm::iterator_range<RootParameter::iterator> getAll () const {
90+ llvm::iterator_range<SmallVector<RootParameterInfo>::const_iterator>
91+ getInfo () const {
14792 return llvm::make_range (begin (), end ());
14893 }
14994};
@@ -154,7 +99,7 @@ struct RootSignatureDesc {
15499 uint32_t RootParameterOffset = 0U ;
155100 uint32_t StaticSamplersOffset = 0u ;
156101 uint32_t NumStaticSamplers = 0u ;
157- mcdxbc::RootParameter Parameters ;
102+ mcdxbc::RootParametersContainer ParametersContainer ;
158103
159104 void write (raw_ostream &OS) const ;
160105
0 commit comments