11
11
#include " llvm/Support/ErrorHandling.h"
12
12
#include < cstddef>
13
13
#include < cstdint>
14
+ #include < optional>
14
15
#include < variant>
15
16
16
17
namespace llvm {
17
18
18
19
class raw_ostream ;
19
20
namespace mcdxbc {
20
21
21
- struct RootParameterHeader : public dxbc ::RootParameterHeader {
22
-
22
+ struct RootParameterInfo {
23
+ dxbc::RootParameterHeader Header;
23
24
size_t Location;
24
25
25
- RootParameterHeader () = default ;
26
+ RootParameterInfo () = default ;
26
27
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) {}
29
30
};
30
31
31
32
using RootDescriptor = std::variant<dxbc::RST0::v0::RootDescriptor,
32
33
dxbc::RST0::v1::RootDescriptor>;
33
34
using ParametersView =
34
35
std::variant<dxbc::RootConstants, dxbc::RST0::v0::RootDescriptor,
35
36
dxbc::RST0::v1::RootDescriptor>;
36
- struct RootParameter {
37
- SmallVector<RootParameterHeader> Headers ;
37
+ struct RootParametersContainer {
38
+ SmallVector<RootParameterInfo> ParametersInfo ;
38
39
39
40
SmallVector<dxbc::RootConstants> Constants;
40
41
SmallVector<RootDescriptor> Descriptors;
41
42
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));
44
45
}
45
46
46
47
void addParameter (dxbc::RootParameterHeader H, dxbc::RootConstants C) {
47
- addHeader (H, Constants.size ());
48
+ addInfo (H, Constants.size ());
48
49
Constants.push_back (C);
49
50
}
50
51
51
52
void addParameter (dxbc::RootParameterHeader H,
52
53
dxbc::RST0::v0::RootDescriptor D) {
53
- addHeader (H, Descriptors.size ());
54
+ addInfo (H, Descriptors.size ());
54
55
Descriptors.push_back (D);
55
56
}
56
57
57
58
void addParameter (dxbc::RootParameterHeader H,
58
59
dxbc::RST0::v1::RootDescriptor D) {
59
- addHeader (H, Descriptors.size ());
60
+ addInfo (H, Descriptors.size ());
60
61
Descriptors.push_back (D);
61
62
}
62
63
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 ) {
65
66
case llvm::to_underlying (dxbc::RootParameterType::Constants32Bit):
66
- return Constants[H. Location ];
67
+ return Constants[H-> Location ];
67
68
case llvm::to_underlying (dxbc::RootParameterType::CBV):
68
69
case llvm::to_underlying (dxbc::RootParameterType::SRV):
69
70
case llvm::to_underlying (dxbc::RootParameterType::UAV):
70
- RootDescriptor VersionedParam = Descriptors[H. Location ];
71
+ RootDescriptor VersionedParam = Descriptors[H-> Location ];
71
72
if (std::holds_alternative<dxbc::RST0::v0::RootDescriptor>(
72
73
VersionedParam))
73
74
return std::get<dxbc::RST0::v0::RootDescriptor>(VersionedParam);
74
75
return std::get<dxbc::RST0::v1::RootDescriptor>(VersionedParam);
75
76
}
76
77
77
- llvm_unreachable ( " Unimplemented parameter type " ) ;
78
+ return std::nullopt ;
78
79
}
79
80
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 (); }
139
82
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
+ }
145
89
146
- llvm::iterator_range<RootParameter::iterator> getAll () const {
90
+ llvm::iterator_range<SmallVector<RootParameterInfo>::const_iterator>
91
+ getInfo () const {
147
92
return llvm::make_range (begin (), end ());
148
93
}
149
94
};
@@ -154,7 +99,7 @@ struct RootSignatureDesc {
154
99
uint32_t RootParameterOffset = 0U ;
155
100
uint32_t StaticSamplersOffset = 0u ;
156
101
uint32_t NumStaticSamplers = 0u ;
157
- mcdxbc::RootParameter Parameters ;
102
+ mcdxbc::RootParametersContainer ParametersContainer ;
158
103
159
104
void write (raw_ostream &OS) const ;
160
105
0 commit comments