1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===- DXContainerYAML.h - DXContainer YAMLIO implementation ----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file declares classes for handling the YAML representation
/// of DXContainer.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
#define LLVM_OBJECTYAML_DXCONTAINERYAML_H
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/YAMLTraits.h"
#include <array>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
namespace llvm {
namespace DXContainerYAML {
struct VersionTuple {
uint16_t Major;
uint16_t Minor;
};
// The optional header fields are required in the binary and will be populated
// when reading from binary, but can be omitted in the YAML text because the
// emitter can calculate them.
struct FileHeader {
std::vector<llvm::yaml::Hex8> Hash;
VersionTuple Version;
std::optional<uint32_t> FileSize;
uint32_t PartCount;
std::optional<std::vector<uint32_t>> PartOffsets;
};
struct DXILProgram {
uint8_t MajorVersion;
uint8_t MinorVersion;
uint16_t ShaderKind;
std::optional<uint32_t> Size;
uint16_t DXILMajorVersion;
uint16_t DXILMinorVersion;
std::optional<uint32_t> DXILOffset;
std::optional<uint32_t> DXILSize;
std::optional<std::vector<llvm::yaml::Hex8>> DXIL;
};
#define SHADER_FLAG(Num, Val, Str) bool Val = false;
struct ShaderFlags {
ShaderFlags() = default;
ShaderFlags(uint64_t FlagData);
uint64_t getEncodedFlags();
#include "llvm/BinaryFormat/DXContainerConstants.def"
};
struct ShaderHash {
ShaderHash() = default;
ShaderHash(const dxbc::ShaderHash &Data);
bool IncludesSource;
std::vector<llvm::yaml::Hex8> Digest;
};
using ResourceBindInfo = dxbc::PSV::v2::ResourceBindInfo;
struct SignatureElement {
SignatureElement() = default;
SignatureElement(dxbc::PSV::v0::SignatureElement El, StringRef StringTable,
ArrayRef<uint32_t> IdxTable)
: Name(StringTable.substr(El.NameOffset,
StringTable.find('\0', El.NameOffset) -
El.NameOffset)),
Indices(IdxTable.slice(El.IndicesOffset, El.Rows)),
StartRow(El.StartRow), Cols(El.Cols), StartCol(El.StartCol),
Allocated(El.Allocated != 0), Kind(El.Kind), Type(El.Type),
Mode(El.Mode), DynamicMask(El.DynamicMask), Stream(El.Stream) {}
StringRef Name;
SmallVector<uint32_t> Indices;
uint8_t StartRow;
uint8_t Cols;
uint8_t StartCol;
bool Allocated;
dxbc::PSV::SemanticKind Kind;
dxbc::PSV::ComponentType Type;
dxbc::PSV::InterpolationMode Mode;
llvm::yaml::Hex8 DynamicMask;
uint8_t Stream;
};
struct PSVInfo {
// The version field isn't actually encoded in the file, but it is inferred by
// the size of data regions. We include it in the yaml because it simplifies
// the format.
uint32_t Version;
dxbc::PSV::v2::RuntimeInfo Info;
uint32_t ResourceStride;
SmallVector<ResourceBindInfo> Resources;
SmallVector<SignatureElement> SigInputElements;
SmallVector<SignatureElement> SigOutputElements;
SmallVector<SignatureElement> SigPatchOrPrimElements;
using MaskVector = SmallVector<llvm::yaml::Hex32>;
std::array<MaskVector, 4> OutputVectorMasks;
MaskVector PatchOrPrimMasks;
std::array<MaskVector, 4> InputOutputMap;
MaskVector InputPatchMap;
MaskVector PatchOutputMap;
void mapInfoForVersion(yaml::IO &IO);
PSVInfo();
PSVInfo(const dxbc::PSV::v0::RuntimeInfo *P, uint16_t Stage);
PSVInfo(const dxbc::PSV::v1::RuntimeInfo *P);
PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P);
};
struct SignatureParameter {
uint32_t Stream;
std::string Name;
uint32_t Index;
dxbc::D3DSystemValue SystemValue;
dxbc::SigComponentType CompType;
uint32_t Register;
uint8_t Mask;
uint8_t ExclusiveMask;
dxbc::SigMinPrecision MinPrecision;
};
struct Signature {
llvm::SmallVector<SignatureParameter> Parameters;
};
struct Part {
Part() = default;
Part(std::string N, uint32_t S) : Name(N), Size(S) {}
std::string Name;
uint32_t Size;
std::optional<DXILProgram> Program;
std::optional<ShaderFlags> Flags;
std::optional<ShaderHash> Hash;
std::optional<PSVInfo> Info;
std::optional<DXContainerYAML::Signature> Signature;
};
struct Object {
FileHeader Header;
std::vector<Part> Parts;
};
} // namespace DXContainerYAML
} // namespace llvm
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::Part)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::ResourceBindInfo)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureElement)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::PSVInfo::MaskVector)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureParameter)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::SemanticKind)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ComponentType)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::InterpolationMode)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::D3DSystemValue)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigComponentType)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigMinPrecision)
namespace llvm {
class raw_ostream;
namespace yaml {
template <> struct MappingTraits<DXContainerYAML::VersionTuple> {
static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version);
};
template <> struct MappingTraits<DXContainerYAML::FileHeader> {
static void mapping(IO &IO, DXContainerYAML::FileHeader &Header);
};
template <> struct MappingTraits<DXContainerYAML::DXILProgram> {
static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program);
};
template <> struct MappingTraits<DXContainerYAML::ShaderFlags> {
static void mapping(IO &IO, DXContainerYAML::ShaderFlags &Flags);
};
template <> struct MappingTraits<DXContainerYAML::ShaderHash> {
static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash);
};
template <> struct MappingTraits<DXContainerYAML::PSVInfo> {
static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV);
};
template <> struct MappingTraits<DXContainerYAML::Part> {
static void mapping(IO &IO, DXContainerYAML::Part &Version);
};
template <> struct MappingTraits<DXContainerYAML::Object> {
static void mapping(IO &IO, DXContainerYAML::Object &Obj);
};
template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
};
template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
static void mapping(IO &IO, llvm::DXContainerYAML::SignatureElement &El);
};
template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
static void mapping(IO &IO, llvm::DXContainerYAML::SignatureParameter &El);
};
template <> struct MappingTraits<DXContainerYAML::Signature> {
static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
};
} // namespace yaml
} // namespace llvm
#endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|