LLVM 23.0.0git
DXContainer.h
Go to the documentation of this file.
1//===-- llvm/BinaryFormat/DXContainer.h - The DXBC file format --*- 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// This file defines manifest constants for the DXContainer object file format.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_BINARYFORMAT_DXCONTAINER_H
14#define LLVM_BINARYFORMAT_DXCONTAINER_H
15
17#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/Error.h"
23
24#include <stdint.h>
25
26namespace llvm {
27template <typename T> struct EnumEntry;
28
29// The DXContainer file format is arranged as a header and "parts". Semantically
30// parts are similar to sections in other object file formats. The File format
31// structure is roughly:
32
33// ┌────────────────────────────────┐
34// │ Header │
35// ├────────────────────────────────┤
36// │ Part │
37// ├────────────────────────────────┤
38// │ Part │
39// ├────────────────────────────────┤
40// │ ... │
41// └────────────────────────────────┘
42
43namespace dxbc {
44
46
48
51 "Shader kind out of expected range.");
52 return static_cast<Triple::EnvironmentType>(Triple::Pixel + Kind);
53}
54
55struct Hash {
57};
58
59enum class HashFlags : uint32_t {
60 None = 0, // No flags defined.
61 IncludesSource = 1, // This flag indicates that the shader hash was computed
62 // taking into account source information (-Zss)
63};
64
65struct ShaderHash {
66 uint32_t Flags; // dxbc::HashFlags
68
69 LLVM_ABI bool isPopulated();
70
72};
73
83
84struct Header {
85 uint8_t Magic[4]; // "DXBC"
90
96 // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
97 // The offset is to a PartHeader, which is followed by the Part Data.
98};
99
100/// Use this type to describe the size and type of a DXIL container part.
104
107 return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
108 }
109 // Structure is followed directly by part data: uint8_t PartData[PartSize].
110};
111
113 uint8_t Magic[4]; // ACSII "DXIL".
114 uint8_t MinorVersion; // DXIL version.
115 uint8_t MajorVersion; // DXIL version.
117 uint32_t Offset; // Offset to LLVM bitcode (from start of header).
118 uint32_t Size; // Size of LLVM bitcode (in bytes).
119 // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
120
127};
128
133 uint32_t Size; // Size in uint32_t words including this header.
135
136 void swapBytes() {
139 Bitcode.swapBytes();
140 }
141 uint8_t getMajorVersion() { return Version >> 4; }
142 uint8_t getMinorVersion() { return Version & 0xF; }
143 static uint8_t getVersion(uint8_t Major, uint8_t Minor) {
144 return (Major << 4) | Minor;
145 }
146};
147
148static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
149
150#define CONTAINER_PART(Part) Part,
151enum class PartType {
153#include "DXContainerConstants.def"
154};
155
156#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) Val = 1ull << Num,
157enum class FeatureFlags : uint64_t {
158#include "DXContainerConstants.def"
159};
160static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
161 "Shader flag bits exceed enum size.");
162
163#define ROOT_SIGNATURE_FLAG(Num, Val) Val = Num,
164enum class RootFlags : uint32_t {
165#include "DXContainerConstants.def"
166
167 LLVM_MARK_AS_BITMASK_ENUM(SamplerHeapDirectlyIndexed)
168};
169
171
172#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) Enum = Num,
174#include "DXContainerConstants.def"
175
176 LLVM_MARK_AS_BITMASK_ENUM(DataStatic)
177};
178
180
181#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) Enum = Num,
183#include "DXContainerConstants.def"
184
185 LLVM_MARK_AS_BITMASK_ENUM(DescriptorsStaticKeepingBufferBoundsChecks)
186};
187
189
190#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) Enum = Num,
192#include "DXContainerConstants.def"
193
194 LLVM_MARK_AS_BITMASK_ENUM(NonNormalizedCoordinates)
195};
196
198
199#define ROOT_PARAMETER(Val, Enum) Enum = Val,
201#include "DXContainerConstants.def"
202};
203
205
207
209
210#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
212#include "DXContainerConstants.def"
213};
214
216
218
219#define FILTER(Val, Enum) Enum = Val,
221#include "DXContainerConstants.def"
222};
223
225
227
228#define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
230#include "DXContainerConstants.def"
231};
232
234
236
237#define COMPARISON_FUNC(Val, Enum) Enum = Val,
239#include "DXContainerConstants.def"
240};
241
243
245
246#define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
248#include "DXContainerConstants.def"
249};
250
252
254
256
258
260
262
264
265LLVM_ABI const char *getProgramPartName(bool IsDebug);
266LLVM_ABI bool isProgramPart(StringRef PartName);
267
271
272 void swapBytes() {
273 // nothing to swap
274 }
275};
276
290
302
316
321
322 void swapBytes() {
323 // nothing to swap
324 }
325};
326
342
348
357
359 switch (Stage) {
361 PS.swapBytes();
362 break;
364 VS.swapBytes();
365 break;
367 GS.swapBytes();
368 break;
370 HS.swapBytes();
371 break;
373 DS.swapBytes();
374 break;
376 MS.swapBytes();
377 break;
379 AS.swapBytes();
380 break;
381 default:
382 break;
383 }
384 }
385};
386
387static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
388 "Pipeline-specific PSV info must fit in 16 bytes.");
389
390namespace PSV {
391
392#define SEMANTIC_KIND(Val, Enum) Enum = Val,
393enum class SemanticKind : uint8_t {
394#include "DXContainerConstants.def"
395};
396
398
399#define COMPONENT_TYPE(Val, Enum) Enum = Val,
400enum class ComponentType : uint8_t {
401#include "DXContainerConstants.def"
402};
403
405
406#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
408#include "DXContainerConstants.def"
409};
410
412
413#define RESOURCE_TYPE(Val, Enum) Enum = Val,
414enum class ResourceType : uint32_t {
415#include "DXContainerConstants.def"
416};
417
419
420#define RESOURCE_KIND(Val, Enum) Enum = Val,
421enum class ResourceKind : uint32_t {
422#include "DXContainerConstants.def"
423};
424
426
427#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
430 struct FlagsBits {
431#include "llvm/BinaryFormat/DXContainerConstants.def"
432 };
433 union {
436 };
437 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
438};
439
440namespace v0 {
443 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
444 uint32_t MaximumWaveLaneCount; // maximum lane count required,
445 // 0xffffffff if unused
446 void swapBytes() {
447 // Skip the union because we don't know which field it has
450 }
451
452 void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); }
453};
454
468
493
494static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
495 "PSV Signature elements must fit in 16 bytes.");
496
497} // namespace v0
498
499namespace v1 {
500
502 uint8_t SigPrimVectors; // Primitive output for MS
504};
505
507 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
508 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
509 // Primitive output for MS (overlaps
510 // MeshInfo::SigPrimVectors)
512};
514 uint8_t ShaderStage; // PSVShaderKind
517
518 // PSVSignatureElement counts
522
523 // Number of packed vectors per signature
526
527 void swapBytes() {
528 // nothing to swap since everything is single-byte or a union field
529 }
530
536};
537
538} // namespace v1
539
569
570namespace v3 {
572 // Offset into the string table, which is stored separately in the PSV0 part.
573 // The entry name string itself is not stored in the RuntimeInfo record.
575
580
584};
585
586} // namespace v3
587} // namespace PSV
588
589#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
591#include "DXContainerConstants.def"
592};
593
595
596#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
598#include "DXContainerConstants.def"
599};
600
602
603#define COMPONENT_TYPE(Val, Enum) Enum = Val,
605#include "DXContainerConstants.def"
606};
607
609
619
621 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
622 // stream order)
623 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
624 // the start of the null terminated string for the name.
625 uint32_t Index; // Semantic Index
626 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
627 SigComponentType CompType; // Type of bits.
628 uint32_t Register; // Register Index (row index)
629 uint8_t Mask; // Mask (column allocation)
630
631 // The ExclusiveMask has a different meaning for input and output signatures.
632 // For an output signature, masked components of the output register are never
633 // written to.
634 // For an input signature, masked components of the input register are always
635 // read.
637
639 SigMinPrecision MinPrecision; // Minimum precision of input/output data
640
652};
653
654static_assert(sizeof(ProgramSignatureElement) == 32,
655 "ProgramSignatureElement is misaligned");
656
657namespace RTS0 {
658namespace v1 {
689
704
713
714// following dx12 naming
715// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
727
739
757} // namespace v1
758
790
791namespace v3 {
804
805} // namespace v3
806} // namespace RTS0
807
808// D3D_ROOT_SIGNATURE_VERSION
810 V1_0 = 0x1,
811 V1_1 = 0x2,
812 V1_2 = 0x3,
813};
814
817 /// Debug file name length, without null terminator.
819
824};
825
826static_assert(sizeof(DebugNameHeader) == 4, "DebugNameHeader size incorrect.");
827
828#define VERSION_INFO_FLAG(Num, Val, Str) Val = Num,
830#include "llvm/BinaryFormat/DXContainerConstants.def"
831
833};
834
836
841 /// The number outputted by `git rev-list --count HEAD` in the compiler repo.
843 /// Byte size of CommitSha and CustomVersionString, padding not included.
845
853};
854
855static_assert(sizeof(CompilerVersionHeader) == 16,
856 "CompilerVersionHeader size incorrect.");
857
858namespace SourceInfo {
859
860struct Header {
861 /// Part size including this header. Aligned to a 4-byte boundary.
863 /// Reserved, must be zero.
865 /// Source info part must contain 3 sections. Each section is 4-byte aligned.
867
873};
874
875static_assert(sizeof(Header) == 8, "SourceInfo::Header size incorrect.");
876
877#define SOURCE_INFO_TYPE(Num, Val) Val = Num,
878enum class SectionType : uint16_t {
879#include "llvm/BinaryFormat/DXContainerConstants.def"
880
882};
883
887
889 /// Section size including this header. Aligned to a 4-byte boundary.
891 /// Reserved, must be zero.
894
900
901 void updateSize(uint32_t ContentSize) {
903 alignTo(sizeof(*this) + ContentSize, DXCONTAINER_STRUCT_ALIGNMENT);
904 }
905};
906
907static_assert(sizeof(SectionHeader) == 8,
908 "SourceInfo::SectionHeader size incorrect.");
909
910namespace Names {
911
912LLVM_PACKED(struct HeaderOnDisk {
913 /// Reserved, must be zero.
914 uint32_t Flags;
915 /// The number of data entries.
917 /// The total size of the data entries following this header. Each entry is
918 /// 4-byte padded.
919 uint16_t EntriesSizeInBytes;
920});
921
922static_assert(sizeof(HeaderOnDisk) == 10,
923 "SourceInfo::Names::HeaderOnDisk size incorrect.");
924
925struct Entry {
926 /// Size of entry, including this header. Aligned to a 4-byte boundary.
928 /// Reserved, must be set to zero.
930 /// Size of the file name following this header, including the null
931 /// terminator, excluding entry padding.
933 /// Size of the file content, including the null terminator.
935 /// Followed by a string of size NameSizeInBytes with HLSL source file name.
936
943};
944
945static_assert(sizeof(Entry) == 16, "SourceInfo::Names::Entry size incorrect.");
946
947} // namespace Names
948
949namespace Contents {
950
951#define COMPRESSION_TYPE(Num, Val) Val = Num,
953#include "llvm/BinaryFormat/DXContainerConstants.def"
954
956};
957
960
961struct Header {
962 /// Size of the section including this header. Aligned to a 4-byte boundary.
963 /// In some implementations, it is unused and set to zero.
965 /// Reserved, must be zero.
967 /// Type of compression used to compress the whole section content.
969 /// The size of the data entries following this header.
970 /// Aligned to a 4-byte boundary if Type is None.
971 /// Doesn’t have to be aligned otherwise.
973 /// Total size of the data entries when uncompressed. Aligned to a 4-byte
974 /// boundary.
976 /// The number of data entries.
978
987};
988
989static_assert(sizeof(Header) == 20,
990 "SourceInfo::Contents::Header size incorrect.");
991
992struct Entry {
993 /// Size of entry, including this header. Aligned to a 4-byte boundary.
995 /// Reserved, must be zero.
997 /// Size of the file contents following this header, including the null
998 /// terminator, excluding entry padding.
1000 /// Followed by a string of length ContentSizeInBytes-1 with HLSL source file
1001 /// content.
1002 /// Entry is aligned to 4-bytes (in uncompressed form).
1003 /// Entries of this section must be stored in the same order as the entries of
1004 /// the Names section.
1005
1011};
1012
1013static_assert(sizeof(Entry) == 12,
1014 "SourceInfo::Contents::Entry size incorrect.");
1015
1016} // namespace Contents
1017
1018namespace Args {
1019
1020struct Header {
1021 /// Reserved, must be zero.
1023 /// Length of all argument pairs, including their null terminators, not
1024 /// including this header.
1026 /// Number of arguments.
1028 /// Followed by Count argument pairs, representing command line arguments of
1029 /// the HLSL compiler invocation. Each pair consists of argument name and
1030 /// argument value null-terminated strings. Padding is not applied to the
1031 /// pairs.
1032
1038};
1039
1040static_assert(sizeof(Header) == 12, "SourceInfo::Args::Header size incorrect.");
1041
1042} // namespace Args
1043
1044} // namespace SourceInfo
1045
1046} // namespace dxbc
1047} // namespace llvm
1048
1049#endif // LLVM_BINARYFORMAT_DXCONTAINER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
#define LLVM_PACKED(d)
\macro LLVM_PACKED Used to specify a packed structure.
Definition Compiler.h:553
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
@ RootSignature
Definition Triple.h:323
@ Amplification
Definition Triple.h:322
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI ArrayRef< EnumEntry< ResourceKind > > getResourceKinds()
LLVM_ABI ArrayRef< EnumEntry< ComponentType > > getComponentTypes()
LLVM_ABI ArrayRef< EnumEntry< ResourceType > > getResourceTypes()
LLVM_ABI ArrayRef< EnumEntry< SemanticKind > > getSemanticKinds()
LLVM_ABI ArrayRef< EnumEntry< InterpolationMode > > getInterpolationModes()
LLVM_ABI ArrayRef< EnumEntry< CompressionType > > getCompressionTypes()
LLVM_ABI bool isValidCompressionType(uint16_t V)
LLVM_ABI bool isValidSectionType(uint16_t V)
LLVM_ABI ArrayRef< EnumEntry< SectionType > > getSectionTypes()
LLVM_ABI StringRef getSectionName(SectionType Type)
LLVM_ABI ArrayRef< EnumEntry< ComparisonFunc > > getComparisonFuncs()
LLVM_ABI ArrayRef< EnumEntry< ShaderVisibility > > getShaderVisibility()
LLVM_ABI bool isValidShaderVisibility(uint32_t V)
LLVM_ABI PartType parsePartType(StringRef S)
LLVM_ABI bool isValidSamplerFilter(uint32_t V)
LLVM_ABI bool isValidStaticSamplerFlags(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< RootFlags > > getRootFlags()
LLVM_ABI ArrayRef< EnumEntry< RootParameterType > > getRootParameterTypes()
LLVM_ABI bool isValidRootDesciptorFlags(uint32_t V)
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition DXContainer.h:49
LLVM_ABI ArrayRef< EnumEntry< SigComponentType > > getSigComponentTypes()
LLVM_ABI bool isDebugProgramPart(PartType PT)
static constexpr uint64_t DXCONTAINER_STRUCT_ALIGNMENT
Definition DXContainer.h:47
LLVM_ABI ArrayRef< EnumEntry< SigMinPrecision > > getSigMinPrecisions()
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
LLVM_ABI bool isProgramPart(StringRef PartName)
LLVM_ABI ArrayRef< EnumEntry< DescriptorRangeFlags > > getDescriptorRangeFlags()
LLVM_ABI bool isValidCompilerVersionFlags(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< SamplerFilter > > getSamplerFilters()
LLVM_ABI ArrayRef< EnumEntry< D3DSystemValue > > getD3DSystemValues()
LLVM_ABI bool isValidDescriptorRangeFlags(uint32_t V)
LLVM_ABI bool isValidBorderColor(uint32_t V)
LLVM_ABI bool isValidComparisonFunc(uint32_t V)
LLVM_ABI_FOR_TEST bool isValidParameterType(uint32_t V)
LLVM_ABI const char * getProgramPartName(bool IsDebug)
LLVM_ABI ArrayRef< EnumEntry< StaticBorderColor > > getStaticBorderColors()
LLVM_ABI bool isValidAddress(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< TextureAddressMode > > getTextureAddressModes()
LLVM_ABI bool isValidRangeType(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< StaticSamplerFlags > > getStaticSamplerFlags()
LLVM_ABI ArrayRef< EnumEntry< RootDescriptorFlags > > getRootDescriptorFlags()
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
uint32_t CommitCount
The number outputted by git rev-list --count HEAD in the compiler repo.
uint32_t ContentSizeInBytes
Byte size of CommitSha and CustomVersionString, padding not included.
uint16_t NameLength
Debug file name length, without null terminator.
uint8_t Digest[16]
Definition DXContainer.h:56
ContainerVersion Version
Definition DXContainer.h:87
uint32_t TessellatorOutputPrimitive
uint32_t GroupSharedBytesDependentOnViewID
bool operator==(const uint32_t RFlags) const
void swapBytes(Triple::EnvironmentType Stage)
void swapBytes(Triple::EnvironmentType Stage)
void swapBytes(Triple::EnvironmentType Stage)
void swapBytes(Triple::EnvironmentType Stage)
Use this type to describe the size and type of a DXIL container part.
StringRef getName() const
static uint8_t getVersion(uint8_t Major, uint8_t Minor)
RootDescriptor(v1::RootDescriptor &Base)
StaticSampler(v1::StaticSampler &Base)
LLVM_ABI bool isPopulated()
uint32_t SizeInBytes
Length of all argument pairs, including their null terminators, not including this header.
void swapBytes()
Followed by Count argument pairs, representing command line arguments of the HLSL compiler invocation...
uint32_t Count
Number of arguments.
uint32_t Flags
Reserved, must be zero.
uint32_t AlignedSizeInBytes
Size of entry, including this header. Aligned to a 4-byte boundary.
uint32_t ContentSizeInBytes
Size of the file contents following this header, including the null terminator, excluding entry paddi...
void swapBytes()
Followed by a string of length ContentSizeInBytes-1 with HLSL source file content.
uint32_t Flags
Reserved, must be zero.
CompressionType Type
Type of compression used to compress the whole section content.
uint32_t UncompressedEntriesSizeInBytes
Total size of the data entries when uncompressed.
uint32_t EntriesSizeInBytes
The size of the data entries following this header.
uint32_t AlignedSizeInBytes
Size of the section including this header.
uint32_t Count
The number of data entries.
uint16_t Flags
Reserved, must be zero.
uint16_t Flags
Reserved, must be zero.
uint32_t AlignedSizeInBytes
Part size including this header. Aligned to a 4-byte boundary.
uint16_t SectionCount
Source info part must contain 3 sections. Each section is 4-byte aligned.
void swapBytes()
Followed by a string of size NameSizeInBytes with HLSL source file name.
uint32_t AlignedSizeInBytes
Size of entry, including this header. Aligned to a 4-byte boundary.
uint32_t ContentSizeInBytes
Size of the file content, including the null terminator.
uint32_t Flags
Reserved, must be set to zero.
uint32_t NameSizeInBytes
Size of the file name following this header, including the null terminator, excluding entry padding.
uint16_t Flags
Reserved, must be zero.
void updateSize(uint32_t ContentSize)
uint32_t AlignedSizeInBytes
Section size including this header. Aligned to a 4-byte boundary.
void swapBytes(Triple::EnvironmentType Stage)
AmplificationPSVInfo AS