LLVM 23.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
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
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
112
121
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
157
161
163 Locations.push_back(Location);
164 }
165};
166
168 dxbc::SamplerFilter Filter = dxbc::SamplerFilter::Anisotropic;
169 dxbc::TextureAddressMode AddressU = dxbc::TextureAddressMode::Wrap;
170 dxbc::TextureAddressMode AddressV = dxbc::TextureAddressMode::Wrap;
171 dxbc::TextureAddressMode AddressW = dxbc::TextureAddressMode::Wrap;
172 float MipLODBias = 0.f;
174 dxbc::ComparisonFunc ComparisonFunc = dxbc::ComparisonFunc::LessEqual;
175 dxbc::StaticBorderColor BorderColor = dxbc::StaticBorderColor::OpaqueWhite;
176 float MinLOD = 0.f;
177 float MaxLOD = std::numeric_limits<float>::max();
181
183
184#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) bool Enum = false;
185#include "llvm/BinaryFormat/DXContainerConstants.def"
186};
187
212
215
242
247
282
294
298
299struct DebugName {
300 std::optional<uint16_t> Flags;
301 std::optional<uint16_t> NameLength;
302 std::string Filename;
303};
304
306 std::optional<uint16_t> Major;
307 std::optional<uint16_t> Minor;
308 std::optional<bool> IsDebugBuild;
309 std::optional<bool> IsValidated;
310 std::optional<uint32_t> CommitCount;
311 std::optional<uint32_t> ContentSizeInBytes;
312 std::optional<std::string> CommitSha;
313 std::optional<std::string> CustomVersionString;
314};
315
317 struct Header {
318 std::optional<uint32_t> AlignedSizeInBytes;
319 std::optional<uint16_t> Flags;
320 std::optional<uint16_t> SectionCount;
321 };
322
324 std::optional<uint32_t> AlignedSizeInBytes;
325 std::optional<uint16_t> Flags;
326 std::optional<dxbc::SourceInfo::SectionType> Type;
327 };
328
332
333 struct SourceContents : public Section {
334 struct Header {
335 std::optional<uint32_t> AlignedSizeInBytes;
336 std::optional<uint16_t> Flags;
338 std::optional<uint32_t> EntriesSizeInBytes;
339 std::optional<uint32_t> UncompressedEntriesSizeInBytes;
340 std::optional<uint32_t> Count;
341 };
342
343 struct Entry {
344 std::optional<uint32_t> AlignedSizeInBytes;
345 std::optional<uint32_t> Flags;
346 std::optional<uint32_t> ContentSizeInBytes;
347 std::string FileContent;
348 };
349
352 };
353
354 struct SourceNames : public Section {
355 struct Header {
356 std::optional<uint32_t> Flags;
357 std::optional<uint32_t> Count;
358 std::optional<uint16_t> EntriesSizeInBytes;
359 };
360
361 struct Entry {
362 std::optional<uint32_t> AlignedSizeInBytes;
363 std::optional<uint32_t> Flags;
364 std::optional<uint32_t> NameSizeInBytes;
365 std::optional<uint32_t> ContentSizeInBytes;
367 };
368
371 };
372
373 struct ProgramArgs : public Section {
374 struct Header {
375 std::optional<uint32_t> Flags;
376 std::optional<uint32_t> SizeInBytes;
377 std::optional<uint32_t> Count;
378 };
379
382 };
383
388};
389
390struct Part {
391 Part() = default;
392 Part(std::string N, uint32_t S) : Name(N), Size(S) {}
393 std::string Name;
395 std::optional<DXILProgram> Program;
396 std::optional<ShaderFeatureFlags> Flags;
397 std::optional<ShaderHash> Hash;
398 std::optional<PSVInfo> Info;
399 std::optional<DXContainerYAML::Signature> Signature;
400 std::optional<DXContainerYAML::RootSignatureYamlDesc> RootSignature;
401 std::optional<DXContainerYAML::DebugName> DebugName;
402 std::optional<DXContainerYAML::CompilerVersion> CompilerVersion;
403 std::optional<DXContainerYAML::SourceInfo> SourceInfo;
404};
405
406struct Object {
408 std::vector<Part> Parts;
409};
410
413
414} // namespace DXContainerYAML
415} // namespace llvm
416
430LLVM_YAML_IS_SEQUENCE_VECTOR(mcdxbc::SourceInfo::ProgramArgs::Entry)
440LLVM_YAML_DECLARE_ENUM_TRAITS(dxil::ResourceClass)
448
449namespace llvm {
450
451class raw_ostream;
452
453namespace yaml {
454
455template <> struct MappingTraits<DXContainerYAML::VersionTuple> {
456 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version);
457};
458
459template <> struct MappingTraits<DXContainerYAML::FileHeader> {
460 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::FileHeader &Header);
461};
462
463template <> struct MappingTraits<DXContainerYAML::DXILProgram> {
464 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program);
465};
466
467template <> struct MappingTraits<DXContainerYAML::ShaderFeatureFlags> {
468 LLVM_ABI static void mapping(IO &IO,
469 DXContainerYAML::ShaderFeatureFlags &Flags);
470};
471
472template <> struct MappingTraits<DXContainerYAML::ShaderHash> {
473 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash);
474};
475
476template <> struct MappingTraits<DXContainerYAML::PSVInfo> {
477 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV);
478};
479
480template <> struct MappingTraits<DXContainerYAML::DebugName> {
481 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::DebugName &DebugName);
482};
483
484template <> struct MappingTraits<DXContainerYAML::CompilerVersion> {
485 LLVM_ABI static void
486 mapping(IO &IO, DXContainerYAML::CompilerVersion &CompilerVersion);
487};
488
489template <> struct MappingTraits<DXContainerYAML::Part> {
490 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Part &Version);
491};
492
493template <> struct MappingTraits<DXContainerYAML::Object> {
494 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Object &Obj);
495};
496
497template <> struct MappingTraits<DXContainerYAML::ResourceFlags> {
498 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceFlags &Flags);
499};
500
501template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
502 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
503};
504
505template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
506 LLVM_ABI static void mapping(IO &IO,
507 llvm::DXContainerYAML::SignatureElement &El);
508};
509
510template <> struct MappingTraits<DXContainerYAML::StringTableEntry> {
511 static void mapping(IO &IO, DXContainerYAML::StringTableEntry &E);
512};
513
514template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
515 LLVM_ABI static void mapping(IO &IO,
516 llvm::DXContainerYAML::SignatureParameter &El);
517};
518
519template <> struct MappingTraits<DXContainerYAML::Signature> {
520 LLVM_ABI static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
521};
522
523template <> struct MappingTraits<DXContainerYAML::RootSignatureYamlDesc> {
524 LLVM_ABI static void
525 mapping(IO &IO, DXContainerYAML::RootSignatureYamlDesc &RootSignature);
526};
527
528template <>
529struct MappingContextTraits<DXContainerYAML::RootParameterLocationYaml,
530 DXContainerYAML::RootSignatureYamlDesc> {
531 LLVM_ABI static void
532 mapping(IO &IO, llvm::DXContainerYAML::RootParameterLocationYaml &L,
533 DXContainerYAML::RootSignatureYamlDesc &S);
534};
535
536template <> struct MappingTraits<llvm::DXContainerYAML::RootConstantsYaml> {
537 LLVM_ABI static void mapping(IO &IO,
538 llvm::DXContainerYAML::RootConstantsYaml &C);
539};
540
541template <> struct MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml> {
542 LLVM_ABI static void mapping(IO &IO,
543 llvm::DXContainerYAML::RootDescriptorYaml &D);
544};
545
546template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorTableYaml> {
547 LLVM_ABI static void mapping(IO &IO,
548 llvm::DXContainerYAML::DescriptorTableYaml &D);
549};
550
551template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorRangeYaml> {
552 LLVM_ABI static void mapping(IO &IO,
553 llvm::DXContainerYAML::DescriptorRangeYaml &D);
554};
555
556template <> struct MappingTraits<llvm::DXContainerYAML::StaticSamplerYamlDesc> {
557 LLVM_ABI static void mapping(IO &IO,
558 llvm::DXContainerYAML::StaticSamplerYamlDesc &S);
559};
560
561template <> struct MappingTraits<llvm::DXContainerYAML::SourceInfo::Header> {
562 LLVM_ABI static void mapping(IO &IO,
563 llvm::DXContainerYAML::SourceInfo::Header &H);
564};
565
566template <>
567struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SectionHeader> {
568 LLVM_ABI static void
569 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SectionHeader &H);
570};
571
572template <>
573struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames::Header> {
574 LLVM_ABI static void
575 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames::Header &H);
576};
577
578template <>
579struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames::Entry> {
580 LLVM_ABI static void
581 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames::Entry &E);
582};
583
584template <>
585struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames> {
586 LLVM_ABI static void
587 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames &S);
588};
589
590template <>
591struct MappingTraits<
592 llvm::DXContainerYAML::SourceInfo::SourceContents::Header> {
593 LLVM_ABI static void
594 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents::Header &H);
595};
596
597template <>
598struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceContents::Entry> {
599 LLVM_ABI static void
600 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents::Entry &E);
601};
602
603template <>
604struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceContents> {
605 LLVM_ABI static void
606 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents &S);
607};
608
609template <>
610struct MappingTraits<llvm::DXContainerYAML::SourceInfo::ProgramArgs::Header> {
611 LLVM_ABI static void
612 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::ProgramArgs::Header &H);
613};
614
615template <> struct MappingTraits<mcdxbc::SourceInfo::ProgramArgs::Entry> {
616 LLVM_ABI static void mapping(IO &IO,
618};
619
620template <>
621struct MappingTraits<llvm::DXContainerYAML::SourceInfo::ProgramArgs> {
622 LLVM_ABI static void
623 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::ProgramArgs &S);
624};
625
626template <> struct MappingTraits<llvm::DXContainerYAML::SourceInfo> {
627 LLVM_ABI static void mapping(IO &IO, llvm::DXContainerYAML::SourceInfo &S);
628};
629
630} // namespace yaml
631
632} // namespace llvm
633
634#endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
#define H(x, y, z)
Definition MD5.cpp:56
#define T
#define P(N)
static StringRef substr(StringRef Str, uint64_t Len)
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Tagged union holding either a T or a Error.
Definition Error.h:485
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A table of densely packed, null-terminated strings indexed by offset.
Definition StringTable.h:34
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
LLVM_ABI Expected< std::unique_ptr< DXContainerYAML::Object > > fromDXContainer(object::DXContainer &DXC)
dxbc::PSV::ResourceFlags ResourceFlags
dxbc::PSV::v2::ResourceBindInfo ResourceBindInfo
This is an optimization pass for GlobalISel generic memory operations.
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:1764
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
#define N
std::optional< std::string > CommitSha
std::optional< uint32_t > ContentSizeInBytes
std::optional< uint32_t > CommitCount
std::optional< std::string > CustomVersionString
std::optional< uint32_t > DXILOffset
std::optional< uint32_t > Size
std::optional< std::vector< llvm::yaml::Hex8 > > DXIL
std::optional< uint32_t > DXILSize
std::optional< uint16_t > NameLength
std::optional< uint16_t > Flags
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< StringTableEntry > StringTable
SmallVector< SignatureElement > SigOutputElements
SmallVector< SignatureElement > SigPatchOrPrimElements
SmallVector< ResourceBindInfo > Resources
SmallVector< SignatureElement > SigInputElements
SmallVector< llvm::yaml::Hex32 > MaskVector
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< DXContainerYAML::CompilerVersion > CompilerVersion
std::optional< DXContainerYAML::DebugName > DebugName
std::optional< ShaderFeatureFlags > Flags
Part(std::string N, uint32_t S)
std::optional< DXContainerYAML::SourceInfo > SourceInfo
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
static LLVM_ABI llvm::Expected< DXContainerYAML::RootSignatureYamlDesc > create(const object::DirectX::RootSignature &Data)
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
std::optional< uint32_t > AlignedSizeInBytes
SmallVector< mcdxbc::SourceInfo::ProgramArgs::Entry > Args
std::optional< dxbc::SourceInfo::SectionType > Type
dxbc::SourceInfo::Contents::CompressionType Type
std::pair< StringRef, StringRef > Entry
This class is similar to MappingTraits<T> but allows you to pass in additional context for each map o...
Definition YAMLTraits.h:86
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63