LLVM 20.0.0git
DXContainerYAML.h
Go to the documentation of this file.
1//===- DXContainerYAML.h - DXContainer YAMLIO implementation ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares classes for handling the YAML representation
11/// of DXContainer.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
16#define LLVM_OBJECTYAML_DXCONTAINERYAML_H
17
18#include "llvm/ADT/StringRef.h"
22#include <array>
23#include <cstdint>
24#include <optional>
25#include <string>
26#include <vector>
27
28namespace llvm {
29namespace DXContainerYAML {
30
34};
35
36// The optional header fields are required in the binary and will be populated
37// when reading from binary, but can be omitted in the YAML text because the
38// emitter can calculate them.
39struct FileHeader {
40 std::vector<llvm::yaml::Hex8> Hash;
42 std::optional<uint32_t> FileSize;
44 std::optional<std::vector<uint32_t>> PartOffsets;
45};
46
48 uint8_t MajorVersion;
49 uint8_t MinorVersion;
51 std::optional<uint32_t> Size;
54 std::optional<uint32_t> DXILOffset;
55 std::optional<uint32_t> DXILSize;
56 std::optional<std::vector<llvm::yaml::Hex8>> DXIL;
57};
58
59#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) bool Val = false;
61 ShaderFeatureFlags() = default;
64#include "llvm/BinaryFormat/DXContainerConstants.def"
65};
66
67struct ShaderHash {
68 ShaderHash() = default;
70
72 std::vector<llvm::yaml::Hex8> Digest;
73};
74
76
78 SignatureElement() = default;
79
81 ArrayRef<uint32_t> IdxTable)
82 : Name(StringTable.substr(El.NameOffset,
83 StringTable.find('\0', El.NameOffset) -
84 El.NameOffset)),
85 Indices(IdxTable.slice(El.IndicesOffset, El.Rows)),
87 Allocated(El.Allocated != 0), Kind(El.Kind), Type(El.Type),
91
92 uint8_t StartRow;
93 uint8_t Cols;
94 uint8_t StartCol;
97
100 llvm::yaml::Hex8 DynamicMask;
101 uint8_t Stream;
102};
103
104struct PSVInfo {
105 // The version field isn't actually encoded in the file, but it is inferred by
106 // the size of data regions. We include it in the yaml because it simplifies
107 // the format.
109
116
118 std::array<MaskVector, 4> OutputVectorMasks;
120 std::array<MaskVector, 4> InputOutputMap;
123
125
126 void mapInfoForVersion(yaml::IO &IO);
127
128 PSVInfo();
132 PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P, StringRef StringTable);
133};
134
137 std::string Name;
142 uint8_t Mask;
145};
146
147struct Signature {
149};
150
151struct Part {
152 Part() = default;
153 Part(std::string N, uint32_t S) : Name(N), Size(S) {}
154 std::string Name;
156 std::optional<DXILProgram> Program;
157 std::optional<ShaderFeatureFlags> Flags;
158 std::optional<ShaderHash> Hash;
159 std::optional<PSVInfo> Info;
160 std::optional<DXContainerYAML::Signature> Signature;
161};
162
163struct Object {
165 std::vector<Part> Parts;
166};
167
168} // namespace DXContainerYAML
169} // namespace llvm
170
182
183namespace llvm {
184
185class raw_ostream;
186
187namespace yaml {
188
189template <> struct MappingTraits<DXContainerYAML::VersionTuple> {
190 static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version);
191};
192
193template <> struct MappingTraits<DXContainerYAML::FileHeader> {
194 static void mapping(IO &IO, DXContainerYAML::FileHeader &Header);
195};
196
197template <> struct MappingTraits<DXContainerYAML::DXILProgram> {
198 static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program);
199};
200
201template <> struct MappingTraits<DXContainerYAML::ShaderFeatureFlags> {
202 static void mapping(IO &IO, DXContainerYAML::ShaderFeatureFlags &Flags);
203};
204
205template <> struct MappingTraits<DXContainerYAML::ShaderHash> {
206 static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash);
207};
208
209template <> struct MappingTraits<DXContainerYAML::PSVInfo> {
210 static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV);
211};
212
213template <> struct MappingTraits<DXContainerYAML::Part> {
214 static void mapping(IO &IO, DXContainerYAML::Part &Version);
215};
216
217template <> struct MappingTraits<DXContainerYAML::Object> {
218 static void mapping(IO &IO, DXContainerYAML::Object &Obj);
219};
220
221template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
222 static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
223};
224
225template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
226 static void mapping(IO &IO, llvm::DXContainerYAML::SignatureElement &El);
227};
228
229template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
230 static void mapping(IO &IO, llvm::DXContainerYAML::SignatureParameter &El);
231};
232
233template <> struct MappingTraits<DXContainerYAML::Signature> {
234 static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
235};
236
237} // namespace yaml
238
239} // namespace llvm
240
241#endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H
#define P(N)
static StringRef substr(StringRef Str, uint64_t Len)
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1742
#define N
std::optional< uint32_t > DXILOffset
std::optional< uint32_t > Size
std::optional< std::vector< llvm::yaml::Hex8 > > DXIL
std::optional< uint32_t > DXILSize
std::vector< llvm::yaml::Hex8 > Hash
std::optional< uint32_t > FileSize
std::optional< std::vector< uint32_t > > PartOffsets
std::array< MaskVector, 4 > InputOutputMap
SmallVector< SignatureElement > SigOutputElements
SmallVector< SignatureElement > SigPatchOrPrimElements
SmallVector< ResourceBindInfo > Resources
SmallVector< SignatureElement > SigInputElements
void mapInfoForVersion(yaml::IO &IO)
dxbc::PSV::v3::RuntimeInfo Info
std::array< MaskVector, 4 > OutputVectorMasks
std::optional< PSVInfo > Info
std::optional< DXILProgram > Program
std::optional< DXContainerYAML::Signature > Signature
std::optional< ShaderHash > Hash
std::optional< ShaderFeatureFlags > Flags
Part(std::string N, uint32_t S)
std::vector< llvm::yaml::Hex8 > Digest
SignatureElement(dxbc::PSV::v0::SignatureElement El, StringRef StringTable, ArrayRef< uint32_t > IdxTable)
dxbc::PSV::InterpolationMode Mode
llvm::SmallVector< SignatureParameter > Parameters