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
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 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
209
212
239
270
282
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
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> {
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> {
366};
367
368template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
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> {
384};
385
386template <> struct MappingTraits<DXContainerYAML::RootSignatureYamlDesc> {
387 LLVM_ABI static void
389};
390
391template <>
398
403
408
413
418
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 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)
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
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.
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
Represents a version number in the form major[.minor[.subminor[.build]]].
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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:1753
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:302
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
#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
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< 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
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
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::RootParameterLocationYaml &L, DXContainerYAML::RootSignatureYamlDesc &S)
This class is similar to MappingTraits<T> but allows you to pass in additional context for each map o...
Definition YAMLTraits.h:85
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::DXILProgram &Program)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::FileHeader &Header)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::Object &Obj)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::Part &Version)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::ResourceFlags &Flags)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::RootSignatureYamlDesc &RootSignature)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::ShaderFeatureFlags &Flags)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::SignatureElement &El)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::SignatureParameter &El)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::Signature &El)
static LLVM_ABI void mapping(IO &IO, DXContainerYAML::VersionTuple &Version)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::DescriptorRangeYaml &D)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::DescriptorTableYaml &D)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::RootConstantsYaml &C)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::RootDescriptorYaml &D)
static LLVM_ABI void mapping(IO &IO, llvm::DXContainerYAML::StaticSamplerYamlDesc &S)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:62