File tree Expand file tree Collapse file tree 9 files changed +109
-16
lines changed Expand file tree Collapse file tree 9 files changed +109
-16
lines changed Original file line number Diff line number Diff line change
1
+ // ===- llvm/MC/DXContainerRootSignature.h - DXContainer RootSignature -*- C++
2
+ // -------*-===//
3
+ //
4
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ //
8
+ // ===----------------------------------------------------------------------===//
9
+
10
+ #include < cstdint>
11
+ #include < limits>
12
+
13
+ namespace llvm {
14
+
15
+ class raw_ostream ;
16
+
17
+ namespace mcdxbc {
18
+ struct RootSignatureHeader {
19
+ uint32_t Version;
20
+ uint32_t Flags;
21
+
22
+ void swapBytes ();
23
+ void write (raw_ostream &OS,
24
+ uint32_t Version = std::numeric_limits<uint32_t >::max());
25
+ };
26
+ } // namespace mcdxbc
27
+ } // namespace llvm
Original file line number Diff line number Diff line change 22
22
#include " llvm/Support/MemoryBufferRef.h"
23
23
#include " llvm/TargetParser/Triple.h"
24
24
#include < array>
25
+ #include < cstdint>
26
+ #include < sys/types.h>
25
27
#include < variant>
26
28
27
29
namespace llvm {
@@ -116,6 +118,23 @@ template <typename T> struct ViewArray {
116
118
};
117
119
118
120
namespace DirectX {
121
+
122
+ class RootSignature {
123
+ private:
124
+ StringRef Data;
125
+ uint32_t Version;
126
+ uint32_t Flags;
127
+
128
+ public:
129
+ RootSignature (StringRef Data) : Data(Data) {}
130
+
131
+ Error parse ();
132
+
133
+ uint32_t getVersion () const { return Version; }
134
+
135
+ uint32_t getFlags () const { return Flags; }
136
+ };
137
+
119
138
class PSVRuntimeInfo {
120
139
121
140
using ResourceArray = ViewArray<dxbc::PSV::v2::ResourceBindInfo>;
@@ -287,7 +306,7 @@ class DXContainer {
287
306
std::optional<uint64_t > ShaderFeatureFlags;
288
307
std::optional<dxbc::ShaderHash> Hash;
289
308
std::optional<DirectX::PSVRuntimeInfo> PSVInfo;
290
- std::optional<dxbc::RootSignatureDesc > RootSignature;
309
+ std::optional<DirectX::RootSignature > RootSignature;
291
310
DirectX::Signature InputSignature;
292
311
DirectX::Signature OutputSignature;
293
312
DirectX::Signature PatchConstantSignature;
@@ -384,7 +403,7 @@ class DXContainer {
384
403
385
404
std::optional<dxbc::ShaderHash> getShaderHash () const { return Hash; }
386
405
387
- std::optional<dxbc::RootSignatureDesc > getRootSignature () const {
406
+ std::optional<DirectX::RootSignature > getRootSignature () const {
388
407
return RootSignature;
389
408
}
390
409
Original file line number Diff line number Diff line change 17
17
18
18
#include " llvm/ADT/StringRef.h"
19
19
#include " llvm/BinaryFormat/DXContainer.h"
20
+ #include " llvm/Object/DXContainer.h"
20
21
#include " llvm/ObjectYAML/YAML.h"
21
22
#include " llvm/Support/YAMLTraits.h"
22
23
#include < array>
@@ -75,7 +76,7 @@ struct ShaderHash {
75
76
#define ROOT_ELEMENT_FLAG (Num, Val, Str ) bool Val = false ;
76
77
struct RootSignatureDesc {
77
78
RootSignatureDesc () = default ;
78
- RootSignatureDesc (const dxbc::RootSignatureDesc &Data);
79
+ RootSignatureDesc (const object::DirectX::RootSignature &Data);
79
80
80
81
uint32_t getEncodedFlags ();
81
82
uint32_t Version;
Original file line number Diff line number Diff line change 1
1
add_llvm_component_library (LLVMMC
2
2
ConstantPools.cpp
3
3
DXContainerPSVInfo.cpp
4
+ DXContainerRootSignature.cpp
4
5
ELFObjectWriter.cpp
5
6
GOFFObjectWriter.cpp
6
7
MCAsmBackend.cpp
Original file line number Diff line number Diff line change
1
+ // ===- llvm/MC/DXContainerRootSignature.cpp - DXContainer RootSignature -*- C++
2
+ // -------*-===//
3
+ //
4
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ //
8
+ // ===----------------------------------------------------------------------===//
9
+
10
+ #include " llvm/MC/DXContainerRootSignature.h"
11
+ #include " llvm/Support/EndianStream.h"
12
+ #include " llvm/Support/SwapByteOrder.h"
13
+ #include < iterator>
14
+
15
+ using namespace llvm ;
16
+ using namespace llvm ::mcdxbc;
17
+
18
+ void RootSignatureHeader::write (raw_ostream &OS, uint32_t Version) {
19
+
20
+ uint32_t SizeInfo = sizeof (this );
21
+ // support::endian::write(OS, SizeInfo, llvm::endianness::little);
22
+
23
+ if (sys::IsBigEndianHost) {
24
+ sys::swapByteOrder (Version);
25
+ sys::swapByteOrder (Flags);
26
+ }
27
+
28
+ OS.write (reinterpret_cast <const char *>(this ), SizeInfo);
29
+ }
Original file line number Diff line number Diff line change @@ -95,8 +95,8 @@ Error DXContainer::parseHash(StringRef Part) {
95
95
Error DXContainer::parseRootSignature (StringRef Part) {
96
96
if (RootSignature)
97
97
return parseFailed (" More than one RTS0 part is present in the file" );
98
- dxbc::RootSignatureDesc Desc;
99
- if (Error Err = readStruct (Part, Part. begin (), Desc ))
98
+ DirectX::RootSignature Desc (Part) ;
99
+ if (Error Err = Desc. parse ( ))
100
100
return Err;
101
101
RootSignature = Desc;
102
102
return Error::success ();
@@ -242,6 +242,20 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
242
242
IteratorState.Offset = Offset;
243
243
}
244
244
245
+ Error DirectX::RootSignature::parse () {
246
+ const char *Current = Data.begin ();
247
+ dxbc::RootSignatureDesc Desc;
248
+ if (Error Err = readStruct (Data, Current, Desc))
249
+ return Err;
250
+
251
+ if (sys::IsBigEndianHost)
252
+ Desc.swapBytes ();
253
+
254
+ Version = Desc.Version ;
255
+ Flags = Desc.Flags ;
256
+ return Error::success ();
257
+ }
258
+
245
259
Error DirectX::PSVRuntimeInfo::parse (uint16_t ShaderKind) {
246
260
Triple::EnvironmentType ShaderStage = dxbc::getShaderStage (ShaderKind);
247
261
Original file line number Diff line number Diff line change 13
13
14
14
#include " llvm/BinaryFormat/DXContainer.h"
15
15
#include " llvm/MC/DXContainerPSVInfo.h"
16
+ #include " llvm/MC/DXContainerRootSignature.h"
16
17
#include " llvm/ObjectYAML/ObjectYAML.h"
17
18
#include " llvm/ObjectYAML/yaml2obj.h"
18
19
#include " llvm/Support/Errc.h"
@@ -264,13 +265,12 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
264
265
case dxbc::PartType::RTS0:
265
266
if (!P.RootSignature .has_value ())
266
267
continue ;
267
- uint32_t Flags = P.RootSignature ->getEncodedFlags ();
268
- if (sys::IsBigEndianHost)
269
- sys::swapByteOrder (Flags);
270
- dxbc::RootSignatureDesc RS = {P.RootSignature ->Version , Flags};
271
- if (sys::IsBigEndianHost)
272
- RS.swapBytes ();
273
- OS.write (reinterpret_cast <char *>(&RS), sizeof (dxbc::RootSignatureDesc));
268
+
269
+ mcdxbc::RootSignatureHeader Header;
270
+ Header.Version = P.RootSignature ->Version ;
271
+ Header.Flags = P.RootSignature ->getEncodedFlags ();
272
+
273
+ Header.write (OS);
274
274
break ;
275
275
}
276
276
uint64_t BytesWritten = OS.tell () - DataStart;
Original file line number Diff line number Diff line change 14
14
#include " llvm/ObjectYAML/DXContainerYAML.h"
15
15
#include " llvm/ADT/ScopeExit.h"
16
16
#include " llvm/BinaryFormat/DXContainer.h"
17
+ #include " llvm/Object/DXContainer.h"
17
18
#include " llvm/Support/ScopedPrinter.h"
18
19
#include < cstdint>
19
20
@@ -31,10 +32,11 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
31
32
}
32
33
33
34
DXContainerYAML::RootSignatureDesc::RootSignatureDesc (
34
- const dxbc::RootSignatureDesc &Data)
35
- : Version(Data.Version) {
35
+ const object::DirectX::RootSignature &Data)
36
+ : Version(Data.getVersion()) {
37
+ uint32_t Flags = Data.getFlags ();
36
38
#define ROOT_ELEMENT_FLAG (Num, Val, Str ) \
37
- Val = (Data. Flags & (uint32_t )dxbc::RootElementFlag::Val) > 0 ;
39
+ Val = (Flags & (uint32_t )dxbc::RootElementFlag::Val) > 0 ;
38
40
#include " llvm/BinaryFormat/DXContainerConstants.def"
39
41
}
40
42
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ dumpDXContainer(MemoryBufferRef Source) {
154
154
case dxbc::PartType::Unknown:
155
155
break ;
156
156
case dxbc::PartType::RTS0:
157
- std::optional<dxbc::RootSignatureDesc > RS = Container.getRootSignature ();
157
+ std::optional<DirectX::RootSignature > RS = Container.getRootSignature ();
158
158
if (RS.has_value ())
159
159
NewPart.RootSignature = DXContainerYAML::RootSignatureDesc (*RS);
160
160
break ;
You can’t perform that action at this time.
0 commit comments