21
21
#include " llvm/Support/Error.h"
22
22
#include " llvm/Support/MemoryBufferRef.h"
23
23
#include " llvm/TargetParser/Triple.h"
24
+ #include < array>
24
25
#include < variant>
25
26
26
27
namespace llvm {
27
28
namespace object {
28
29
29
30
namespace DirectX {
31
+
32
+ namespace detail {
33
+ template <typename T>
34
+ std::enable_if_t <std::is_arithmetic<T>::value, void > swapBytes (T &value) {
35
+ sys::swapByteOrder (value);
36
+ }
37
+
38
+ template <typename T>
39
+ std::enable_if_t <std::is_class<T>::value, void > swapBytes (T &value) {
40
+ value.swapBytes ();
41
+ }
42
+ } // namespace detail
30
43
class PSVRuntimeInfo {
31
44
32
45
// This class provides a view into the underlying resource array. The Resource
@@ -35,7 +48,7 @@ class PSVRuntimeInfo {
35
48
// swaps it as appropriate.
36
49
template <typename T> struct ViewArray {
37
50
StringRef Data;
38
- uint32_t Stride; // size of each element in the list.
51
+ uint32_t Stride = sizeof (T) ; // size of each element in the list.
39
52
40
53
ViewArray () = default ;
41
54
ViewArray (StringRef D, size_t S) : Data(D), Stride(S) {}
@@ -65,7 +78,7 @@ class PSVRuntimeInfo {
65
78
memcpy (static_cast <void *>(&Val), Current,
66
79
std::min (Stride, MaxStride ()));
67
80
if (sys::IsBigEndianHost)
68
- Val. swapBytes ();
81
+ detail:: swapBytes (Val );
69
82
return Val;
70
83
}
71
84
@@ -120,6 +133,12 @@ class PSVRuntimeInfo {
120
133
SigElementArray SigOutputElements;
121
134
SigElementArray SigPatchOrPrimElements;
122
135
136
+ std::array<ViewArray<uint32_t >, 4 > OutputVectorMasks;
137
+ ViewArray<uint32_t > PatchOrPrimMasks;
138
+ std::array<ViewArray<uint32_t >, 4 > InputOutputMap;
139
+ ViewArray<uint32_t > InputPatchMap;
140
+ ViewArray<uint32_t > PatchOutputMap;
141
+
123
142
public:
124
143
PSVRuntimeInfo (StringRef D) : Data(D), Size (0 ) {}
125
144
@@ -140,6 +159,22 @@ class PSVRuntimeInfo {
140
159
141
160
const InfoStruct &getInfo () const { return BasicInfo; }
142
161
162
+ template <typename T> const T *getInfoAs () const {
163
+ if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
164
+ return static_cast <const T *>(P);
165
+ if (std::is_same<T, dxbc::PSV::v2::RuntimeInfo>::value)
166
+ return nullptr ;
167
+
168
+ if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
169
+ return static_cast <const T *>(P);
170
+ if (std::is_same<T, dxbc::PSV::v1::RuntimeInfo>::value)
171
+ return nullptr ;
172
+
173
+ if (const auto *P = std::get_if<dxbc::PSV::v0::RuntimeInfo>(&BasicInfo))
174
+ return static_cast <const T *>(P);
175
+ return nullptr ;
176
+ }
177
+
143
178
StringRef getStringTable () const { return StringTable; }
144
179
ArrayRef<uint32_t > getSemanticIndexTable () const {
145
180
return SemanticIndexTable;
@@ -155,7 +190,46 @@ class PSVRuntimeInfo {
155
190
return SigPatchOrPrimElements;
156
191
}
157
192
193
+ ViewArray<uint32_t > getOutputVectorMasks (size_t Idx) const {
194
+ assert (Idx < 4 );
195
+ return OutputVectorMasks[Idx];
196
+ }
197
+
198
+ ViewArray<uint32_t > getPatchOrPrimMasks () const { return PatchOrPrimMasks; }
199
+
200
+ ViewArray<uint32_t > getInputOutputMap (size_t Idx) const {
201
+ assert (Idx < 4 );
202
+ return InputOutputMap[Idx];
203
+ }
204
+
205
+ ViewArray<uint32_t > getInputPatchMap () const { return InputPatchMap; }
206
+ ViewArray<uint32_t > getPatchOutputMap () const { return PatchOutputMap; }
207
+
158
208
uint32_t getSigElementStride () const { return SigInputElements.Stride ; }
209
+
210
+ bool usesViewID () const {
211
+ if (const auto *P = getInfoAs<dxbc::PSV::v1::RuntimeInfo>())
212
+ return P->UsesViewID != 0 ;
213
+ return false ;
214
+ }
215
+
216
+ uint8_t getInputVectorCount () const {
217
+ if (const auto *P = getInfoAs<dxbc::PSV::v1::RuntimeInfo>())
218
+ return P->SigInputVectors ;
219
+ return 0 ;
220
+ }
221
+
222
+ ArrayRef<uint8_t > getOutputVectorCounts () const {
223
+ if (const auto *P = getInfoAs<dxbc::PSV::v1::RuntimeInfo>())
224
+ return ArrayRef<uint8_t >(P->SigOutputVectors );
225
+ return ArrayRef<uint8_t >();
226
+ }
227
+
228
+ uint8_t getPatchConstOrPrimVectorCount () const {
229
+ if (const auto *P = getInfoAs<dxbc::PSV::v1::RuntimeInfo>())
230
+ return P->GeomData .SigPatchConstOrPrimVectors ;
231
+ return 0 ;
232
+ }
159
233
};
160
234
161
235
} // namespace DirectX
0 commit comments