LLVM 24.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 std::optional<std::vector<llvm::yaml::Hex8>> PrivateData;
405};
406
407struct Object {
409 std::vector<Part> Parts;
410};
411
414
415} // namespace DXContainerYAML
416} // namespace llvm
417
431LLVM_YAML_IS_SEQUENCE_VECTOR(mcdxbc::SourceInfo::ProgramArgs::Entry)
441LLVM_YAML_DECLARE_ENUM_TRAITS(dxil::ResourceClass)
449
450namespace llvm {
451
452namespace yaml {
453
454template <> struct MappingTraits<DXContainerYAML::VersionTuple> {
455 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version);
456};
457
458template <> struct MappingTraits<DXContainerYAML::FileHeader> {
459 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::FileHeader &Header);
460};
461
462template <> struct MappingTraits<DXContainerYAML::DXILProgram> {
463 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program);
464};
465
466template <> struct MappingTraits<DXContainerYAML::ShaderFeatureFlags> {
467 LLVM_ABI static void mapping(IO &IO,
468 DXContainerYAML::ShaderFeatureFlags &Flags);
469};
470
471template <> struct MappingTraits<DXContainerYAML::ShaderHash> {
472 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash);
473};
474
475template <> struct MappingTraits<DXContainerYAML::PSVInfo> {
476 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV);
477};
478
479template <> struct MappingTraits<DXContainerYAML::DebugName> {
480 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::DebugName &DebugName);
481};
482
483template <> struct MappingTraits<DXContainerYAML::CompilerVersion> {
484 LLVM_ABI static void
485 mapping(IO &IO, DXContainerYAML::CompilerVersion &CompilerVersion);
486};
487
488template <> struct MappingTraits<DXContainerYAML::Part> {
489 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Part &Version);
490};
491
492template <> struct MappingTraits<DXContainerYAML::Object> {
493 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Object &Obj);
494};
495
496template <> struct MappingTraits<DXContainerYAML::ResourceFlags> {
497 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceFlags &Flags);
498};
499
500template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
501 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
502};
503
504template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
505 LLVM_ABI static void mapping(IO &IO,
506 llvm::DXContainerYAML::SignatureElement &El);
507};
508
509template <> struct MappingTraits<DXContainerYAML::StringTableEntry> {
510 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::StringTableEntry &E);
511};
512
513template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
514 LLVM_ABI static void mapping(IO &IO,
515 llvm::DXContainerYAML::SignatureParameter &El);
516};
517
518template <> struct MappingTraits<DXContainerYAML::Signature> {
519 LLVM_ABI static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
520};
521
522template <> struct MappingTraits<DXContainerYAML::RootSignatureYamlDesc> {
523 LLVM_ABI static void
524 mapping(IO &IO, DXContainerYAML::RootSignatureYamlDesc &RootSignature);
525};
526
527template <>
528struct MappingContextTraits<DXContainerYAML::RootParameterLocationYaml,
529 DXContainerYAML::RootSignatureYamlDesc> {
530 LLVM_ABI static void
531 mapping(IO &IO, llvm::DXContainerYAML::RootParameterLocationYaml &L,
532 DXContainerYAML::RootSignatureYamlDesc &S);
533};
534
535template <> struct MappingTraits<llvm::DXContainerYAML::RootConstantsYaml> {
536 LLVM_ABI static void mapping(IO &IO,
537 llvm::DXContainerYAML::RootConstantsYaml &C);
538};
539
540template <> struct MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml> {
541 LLVM_ABI static void mapping(IO &IO,
542 llvm::DXContainerYAML::RootDescriptorYaml &D);
543};
544
545template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorTableYaml> {
546 LLVM_ABI static void mapping(IO &IO,
547 llvm::DXContainerYAML::DescriptorTableYaml &D);
548};
549
550template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorRangeYaml> {
551 LLVM_ABI static void mapping(IO &IO,
552 llvm::DXContainerYAML::DescriptorRangeYaml &D);
553};
554
555template <> struct MappingTraits<llvm::DXContainerYAML::StaticSamplerYamlDesc> {
556 LLVM_ABI static void mapping(IO &IO,
557 llvm::DXContainerYAML::StaticSamplerYamlDesc &S);
558};
559
560template <> struct MappingTraits<llvm::DXContainerYAML::SourceInfo::Header> {
561 LLVM_ABI static void mapping(IO &IO,
562 llvm::DXContainerYAML::SourceInfo::Header &H);
563};
564
565template <>
566struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SectionHeader> {
567 LLVM_ABI static void
568 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SectionHeader &H);
569};
570
571template <>
572struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames::Header> {
573 LLVM_ABI static void
574 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames::Header &H);
575};
576
577template <>
578struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames::Entry> {
579 LLVM_ABI static void
580 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames::Entry &E);
581};
582
583template <>
584struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames> {
585 LLVM_ABI static void
586 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames &S);
587};
588
589template <>
590struct MappingTraits<
591 llvm::DXContainerYAML::SourceInfo::SourceContents::Header> {
592 LLVM_ABI static void
593 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents::Header &H);
594};
595
596template <>
597struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceContents::Entry> {
598 LLVM_ABI static void
599 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents::Entry &E);
600};
601
602template <>
603struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceContents> {
604 LLVM_ABI static void
605 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents &S);
606};
607
608template <>
609struct MappingTraits<llvm::DXContainerYAML::SourceInfo::ProgramArgs::Header> {
610 LLVM_ABI static void
611 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::ProgramArgs::Header &H);
612};
613
614template <> struct MappingTraits<mcdxbc::SourceInfo::ProgramArgs::Entry> {
615 LLVM_ABI static void mapping(IO &IO,
617};
618
619template <>
620struct MappingTraits<llvm::DXContainerYAML::SourceInfo::ProgramArgs> {
621 LLVM_ABI static void
622 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::ProgramArgs &S);
623};
624
625template <> struct MappingTraits<llvm::DXContainerYAML::SourceInfo> {
626 LLVM_ABI static void mapping(IO &IO, llvm::DXContainerYAML::SourceInfo &S);
627};
628
629} // namespace yaml
630
631} // namespace llvm
632
633#endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H
uint64_t uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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:211
#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.
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:1781
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
#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< std::vector< llvm::yaml::Hex8 > > PrivateData
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