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 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
452class raw_ostream;
453
454namespace yaml {
455
456template <> struct MappingTraits<DXContainerYAML::VersionTuple> {
457 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version);
458};
459
460template <> struct MappingTraits<DXContainerYAML::FileHeader> {
461 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::FileHeader &Header);
462};
463
464template <> struct MappingTraits<DXContainerYAML::DXILProgram> {
465 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program);
466};
467
468template <> struct MappingTraits<DXContainerYAML::ShaderFeatureFlags> {
469 LLVM_ABI static void mapping(IO &IO,
470 DXContainerYAML::ShaderFeatureFlags &Flags);
471};
472
473template <> struct MappingTraits<DXContainerYAML::ShaderHash> {
474 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash);
475};
476
477template <> struct MappingTraits<DXContainerYAML::PSVInfo> {
478 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV);
479};
480
481template <> struct MappingTraits<DXContainerYAML::DebugName> {
482 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::DebugName &DebugName);
483};
484
485template <> struct MappingTraits<DXContainerYAML::CompilerVersion> {
486 LLVM_ABI static void
487 mapping(IO &IO, DXContainerYAML::CompilerVersion &CompilerVersion);
488};
489
490template <> struct MappingTraits<DXContainerYAML::Part> {
491 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Part &Version);
492};
493
494template <> struct MappingTraits<DXContainerYAML::Object> {
495 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::Object &Obj);
496};
497
498template <> struct MappingTraits<DXContainerYAML::ResourceFlags> {
499 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceFlags &Flags);
500};
501
502template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
503 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
504};
505
506template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
507 LLVM_ABI static void mapping(IO &IO,
508 llvm::DXContainerYAML::SignatureElement &El);
509};
510
511template <> struct MappingTraits<DXContainerYAML::StringTableEntry> {
512 LLVM_ABI static void mapping(IO &IO, DXContainerYAML::StringTableEntry &E);
513};
514
515template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
516 LLVM_ABI static void mapping(IO &IO,
517 llvm::DXContainerYAML::SignatureParameter &El);
518};
519
520template <> struct MappingTraits<DXContainerYAML::Signature> {
521 LLVM_ABI static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
522};
523
524template <> struct MappingTraits<DXContainerYAML::RootSignatureYamlDesc> {
525 LLVM_ABI static void
526 mapping(IO &IO, DXContainerYAML::RootSignatureYamlDesc &RootSignature);
527};
528
529template <>
530struct MappingContextTraits<DXContainerYAML::RootParameterLocationYaml,
531 DXContainerYAML::RootSignatureYamlDesc> {
532 LLVM_ABI static void
533 mapping(IO &IO, llvm::DXContainerYAML::RootParameterLocationYaml &L,
534 DXContainerYAML::RootSignatureYamlDesc &S);
535};
536
537template <> struct MappingTraits<llvm::DXContainerYAML::RootConstantsYaml> {
538 LLVM_ABI static void mapping(IO &IO,
539 llvm::DXContainerYAML::RootConstantsYaml &C);
540};
541
542template <> struct MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml> {
543 LLVM_ABI static void mapping(IO &IO,
544 llvm::DXContainerYAML::RootDescriptorYaml &D);
545};
546
547template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorTableYaml> {
548 LLVM_ABI static void mapping(IO &IO,
549 llvm::DXContainerYAML::DescriptorTableYaml &D);
550};
551
552template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorRangeYaml> {
553 LLVM_ABI static void mapping(IO &IO,
554 llvm::DXContainerYAML::DescriptorRangeYaml &D);
555};
556
557template <> struct MappingTraits<llvm::DXContainerYAML::StaticSamplerYamlDesc> {
558 LLVM_ABI static void mapping(IO &IO,
559 llvm::DXContainerYAML::StaticSamplerYamlDesc &S);
560};
561
562template <> struct MappingTraits<llvm::DXContainerYAML::SourceInfo::Header> {
563 LLVM_ABI static void mapping(IO &IO,
564 llvm::DXContainerYAML::SourceInfo::Header &H);
565};
566
567template <>
568struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SectionHeader> {
569 LLVM_ABI static void
570 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SectionHeader &H);
571};
572
573template <>
574struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames::Header> {
575 LLVM_ABI static void
576 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames::Header &H);
577};
578
579template <>
580struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames::Entry> {
581 LLVM_ABI static void
582 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames::Entry &E);
583};
584
585template <>
586struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceNames> {
587 LLVM_ABI static void
588 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceNames &S);
589};
590
591template <>
592struct MappingTraits<
593 llvm::DXContainerYAML::SourceInfo::SourceContents::Header> {
594 LLVM_ABI static void
595 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents::Header &H);
596};
597
598template <>
599struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceContents::Entry> {
600 LLVM_ABI static void
601 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents::Entry &E);
602};
603
604template <>
605struct MappingTraits<llvm::DXContainerYAML::SourceInfo::SourceContents> {
606 LLVM_ABI static void
607 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::SourceContents &S);
608};
609
610template <>
611struct MappingTraits<llvm::DXContainerYAML::SourceInfo::ProgramArgs::Header> {
612 LLVM_ABI static void
613 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::ProgramArgs::Header &H);
614};
615
616template <> struct MappingTraits<mcdxbc::SourceInfo::ProgramArgs::Entry> {
617 LLVM_ABI static void mapping(IO &IO,
619};
620
621template <>
622struct MappingTraits<llvm::DXContainerYAML::SourceInfo::ProgramArgs> {
623 LLVM_ABI static void
624 mapping(IO &IO, llvm::DXContainerYAML::SourceInfo::ProgramArgs &S);
625};
626
627template <> struct MappingTraits<llvm::DXContainerYAML::SourceInfo> {
628 LLVM_ABI static void mapping(IO &IO, llvm::DXContainerYAML::SourceInfo &S);
629};
630
631} // namespace yaml
632
633} // namespace llvm
634
635#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:215
#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:1765
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