LLVM 22.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"
24#include <array>
25#include <optional>
26#include <string>
27#include <vector>
28
29namespace llvm {
30namespace DXContainerYAML {
31
35};
36
37// The optional header fields are required in the binary and will be populated
38// when reading from binary, but can be omitted in the YAML text because the
39// emitter can calculate them.
40struct FileHeader {
41 std::vector<llvm::yaml::Hex8> Hash;
43 std::optional<uint32_t> FileSize;
45 std::optional<std::vector<uint32_t>> PartOffsets;
46};
47
52 std::optional<uint32_t> Size;
55 std::optional<uint32_t> DXILOffset;
56 std::optional<uint32_t> DXILSize;
57 std::optional<std::vector<llvm::yaml::Hex8>> DXIL;
58};
59
60#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) bool Val = false;
62 ShaderFeatureFlags() = default;
65#include "llvm/BinaryFormat/DXContainerConstants.def"
66};
67
68struct ShaderHash {
69 ShaderHash() = default;
71
73 std::vector<llvm::yaml::Hex8> Digest;
74};
75
80};
81
83 RootDescriptorYaml() = default;
84
87
89
90#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) bool Enum = false;
91#include "llvm/BinaryFormat/DXContainerConstants.def"
92};
93
100
102
103#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) bool Enum = false;
104#include "llvm/BinaryFormat/DXContainerConstants.def"
105};
106
111};
112
117
120};
121
124 std::optional<size_t> IndexInSignature;
125
128 : Header(Header) {}
129};
130
133
137
138 template <typename T>
140 SmallVectorImpl<T> &Container) {
141 if (!ParamDesc.IndexInSignature) {
142 ParamDesc.IndexInSignature = Container.size();
143 Container.emplace_back();
144 }
145 return Container[*ParamDesc.IndexInSignature];
146 }
147
150 return getOrInsertImpl(ParamDesc, Constants);
151 }
152
155 return getOrInsertImpl(ParamDesc, Descriptors);
156 }
157
159 return getOrInsertImpl(ParamDesc, Tables);
160 }
161
163 Locations.push_back(Location);
164 }
165};
166
168 uint32_t Filter = llvm::to_underlying(dxbc::SamplerFilter::Anisotropic);
169 uint32_t AddressU = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
170 uint32_t AddressV = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
171 uint32_t AddressW = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
172 float MipLODBias = 0.f;
175 llvm::to_underlying(dxbc::ComparisonFunc::LessEqual);
177 llvm::to_underlying(dxbc::StaticBorderColor::OpaqueWhite);
178 float MinLOD = 0.f;
179 float MaxLOD = std::numeric_limits<float>::max();
183};
184
187
190 std::optional<uint32_t> RootParametersOffset;
192 std::optional<uint32_t> StaticSamplersOffset;
193
196
198
200 return make_range(StaticSamplers.begin(), StaticSamplers.end());
201 }
202
205
206#define ROOT_SIGNATURE_FLAG(Num, Val) bool Val = false;
207#include "llvm/BinaryFormat/DXContainerConstants.def"
208};
209
212
214 SignatureElement() = default;
215
217 ArrayRef<uint32_t> IdxTable)
218 : Name(StringTable.substr(El.NameOffset,
219 StringTable.find('\0', El.NameOffset) -
220 El.NameOffset)),
221 Indices(IdxTable.slice(El.IndicesOffset, El.Rows)),
223 Allocated(El.Allocated != 0), Kind(El.Kind), Type(El.Type),
227
233
236 llvm::yaml::Hex8 DynamicMask;
238};
239
240struct PSVInfo {
241 // The version field isn't actually encoded in the file, but it is inferred by
242 // the size of data regions. We include it in the yaml because it simplifies
243 // the format.
245
252
254 std::array<MaskVector, 4> OutputVectorMasks;
256 std::array<MaskVector, 4> InputOutputMap;
259
261
262 LLVM_ABI void mapInfoForVersion(yaml::IO &IO);
263
269};
270
273 std::string Name;
281};
282
283struct Signature {
285};
286
287struct Part {
288 Part() = default;
289 Part(std::string N, uint32_t S) : Name(N), Size(S) {}
290 std::string Name;
292 std::optional<DXILProgram> Program;
293 std::optional<ShaderFeatureFlags> Flags;
294 std::optional<ShaderHash> Hash;
295 std::optional<PSVInfo> Info;
296 std::optional<DXContainerYAML::Signature> Signature;
297 std::optional<DXContainerYAML::RootSignatureYamlDesc> RootSignature;
298};
299
300struct Object {
302 std::vector<Part> Parts;
303};
304
305} // namespace DXContainerYAML
306} // namespace llvm
307
324
325namespace llvm {
326
327class raw_ostream;
328
329namespace yaml {
330
331template <> struct MappingTraits<DXContainerYAML::VersionTuple> {
332 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version);
333};
334
335template <> struct MappingTraits<DXContainerYAML::FileHeader> {
336 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::FileHeader &Header);
337};
338
339template <> struct MappingTraits<DXContainerYAML::DXILProgram> {
340 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program);
341};
342
343template <> struct MappingTraits<DXContainerYAML::ShaderFeatureFlags> {
344 LLVM_ABI static void mapping(IO &IO,
346};
347
348template <> struct MappingTraits<DXContainerYAML::ShaderHash> {
349 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash);
350};
351
352template <> struct MappingTraits<DXContainerYAML::PSVInfo> {
353 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV);
354};
355
356template <> struct MappingTraits<DXContainerYAML::Part> {
357 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Part &Version);
358};
359
360template <> struct MappingTraits<DXContainerYAML::Object> {
361 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Object &Obj);
362};
363
364template <> struct MappingTraits<DXContainerYAML::ResourceFlags> {
365 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceFlags &Flags);
366};
367
368template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
369 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
370};
371
372template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
373 LLVM_ABI static void mapping(IO &IO,
375};
376
377template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
378 LLVM_ABI static void mapping(IO &IO,
380};
381
382template <> struct MappingTraits<DXContainerYAML::Signature> {
383 LLVM_ABI static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
384};
385
386template <> struct MappingTraits<DXContainerYAML::RootSignatureYamlDesc> {
387 LLVM_ABI static void
388 mapping(IO &IO, DXContainerYAML::RootSignatureYamlDesc &RootSignature);
389};
390
391template <>
392struct MappingContextTraits<DXContainerYAML::RootParameterLocationYaml,
394 LLVM_ABI static void
397};
398
400 LLVM_ABI static void mapping(IO &IO,
402};
403
405 LLVM_ABI static void mapping(IO &IO,
407};
408
410 LLVM_ABI static void mapping(IO &IO,
412};
413
415 LLVM_ABI static void mapping(IO &IO,
417};
418
420 LLVM_ABI static void mapping(IO &IO,
422};
423
424} // namespace yaml
425
426} // namespace llvm
427
428#endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition: Compiler.h:213
#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
Tagged union holding either a T or a Error.
Definition: Error.h:485
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:938
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
A table of densely packed, null-terminated strings indexed by offset.
Definition: StringTable.h:33
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:30
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
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:1770
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
#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
SmallVector< DescriptorRangeYaml > Ranges
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
LLVM_ABI void mapInfoForVersion(yaml::IO &IO)
dxbc::PSV::v3::RuntimeInfo Info
std::array< MaskVector, 4 > OutputVectorMasks
std::optional< PSVInfo > Info
std::optional< DXContainerYAML::RootSignatureYamlDesc > RootSignature
std::optional< DXILProgram > Program
std::optional< DXContainerYAML::Signature > Signature
std::optional< ShaderHash > Hash
std::optional< ShaderFeatureFlags > Flags
Part(std::string N, uint32_t S)
RootParameterLocationYaml(RootParameterHeaderYaml Header)
RootDescriptorYaml & getOrInsertDescriptor(RootParameterLocationYaml &ParamDesc)
T & getOrInsertImpl(RootParameterLocationYaml &ParamDesc, SmallVectorImpl< T > &Container)
SmallVector< RootParameterLocationYaml > Locations
RootConstantsYaml & getOrInsertConstants(RootParameterLocationYaml &ParamDesc)
void insertLocation(RootParameterLocationYaml &Location)
DescriptorTableYaml & getOrInsertTable(RootParameterLocationYaml &ParamDesc)
SmallVector< RootConstantsYaml > Constants
SmallVector< RootDescriptorYaml > Descriptors
SmallVector< DescriptorTableYaml > Tables
iterator_range< StaticSamplerYamlDesc * > samplers()
SmallVector< StaticSamplerYamlDesc > StaticSamplers
std::optional< uint32_t > RootParametersOffset
static LLVM_ABI llvm::Expected< DXContainerYAML::RootSignatureYamlDesc > create(const object::DirectX::RootSignature &Data)
std::optional< uint32_t > StaticSamplersOffset
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