LLVM 22.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
49 "Shader kind out of expected range.");
50 return static_cast<Triple::EnvironmentType>(Triple::Pixel + Kind);
51}
52
53struct Hash {
55};
56
57enum class HashFlags : uint32_t {
58 None = 0, // No flags defined.
59 IncludesSource = 1, // This flag indicates that the shader hash was computed
60 // taking into account source information (-Zss)
61};
62
63struct ShaderHash {
64 uint32_t Flags; // dxbc::HashFlags
66
67 LLVM_ABI bool isPopulated();
68
70};
71
81
82struct Header {
83 uint8_t Magic[4]; // "DXBC"
88
94 // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
95 // The offset is to a PartHeader, which is followed by the Part Data.
96};
97
98/// Use this type to describe the size and type of a DXIL container part.
99struct PartHeader {
102
105 return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
106 }
107 // Structure is followed directly by part data: uint8_t PartData[PartSize].
108};
109
111 uint8_t Magic[4]; // ACSII "DXIL".
112 uint8_t MinorVersion; // DXIL version.
113 uint8_t MajorVersion; // DXIL version.
115 uint32_t Offset; // Offset to LLVM bitcode (from start of header).
116 uint32_t Size; // Size of LLVM bitcode (in bytes).
117 // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
118
125};
126
131 uint32_t Size; // Size in uint32_t words including this header.
133
134 void swapBytes() {
137 Bitcode.swapBytes();
138 }
139 uint8_t getMajorVersion() { return Version >> 4; }
140 uint8_t getMinorVersion() { return Version & 0xF; }
141 static uint8_t getVersion(uint8_t Major, uint8_t Minor) {
142 return (Major << 4) | Minor;
143 }
144};
145
146static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
147
148#define CONTAINER_PART(Part) Part,
149enum class PartType {
151#include "DXContainerConstants.def"
152};
153
154#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) Val = 1ull << Num,
155enum class FeatureFlags : uint64_t {
156#include "DXContainerConstants.def"
157};
158static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
159 "Shader flag bits exceed enum size.");
160
161#define ROOT_SIGNATURE_FLAG(Num, Val) Val = Num,
162enum class RootFlags : uint32_t {
163#include "DXContainerConstants.def"
164
165 LLVM_MARK_AS_BITMASK_ENUM(SamplerHeapDirectlyIndexed)
166};
167
169
170#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) Enum = Num,
172#include "DXContainerConstants.def"
173
174 LLVM_MARK_AS_BITMASK_ENUM(DataStatic)
175};
176
178
179#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) Enum = Num,
181#include "DXContainerConstants.def"
182
183 LLVM_MARK_AS_BITMASK_ENUM(DescriptorsStaticKeepingBufferBoundsChecks)
184};
185
187
188#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) Enum = Num,
190#include "DXContainerConstants.def"
191
192 LLVM_MARK_AS_BITMASK_ENUM(NonNormalizedCoordinates)
193};
194
196
197#define ROOT_PARAMETER(Val, Enum) Enum = Val,
199#include "DXContainerConstants.def"
200};
201
203
204#define ROOT_PARAMETER(Val, Enum) \
205 case Val: \
206 return true;
208 switch (V) {
209#include "DXContainerConstants.def"
210 }
211 return false;
212}
213
217
218#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
220#include "DXContainerConstants.def"
221};
222
224
225#define SHADER_VISIBILITY(Val, Enum) \
226 case Val: \
227 return true;
229 switch (V) {
230#include "DXContainerConstants.def"
231 }
232 return false;
233}
234
235#define FILTER(Val, Enum) Enum = Val,
237#include "DXContainerConstants.def"
238};
239
240#define FILTER(Val, Enum) \
241 case Val: \
242 return true;
244 switch (V) {
245#include "DXContainerConstants.def"
246 }
247 return false;
248}
249
251
252#define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
254#include "DXContainerConstants.def"
255};
256
258
259#define TEXTURE_ADDRESS_MODE(Val, Enum) \
260 case Val: \
261 return true;
262inline bool isValidAddress(uint32_t V) {
263 switch (V) {
264#include "DXContainerConstants.def"
265 }
266 return false;
267}
268
269#define COMPARISON_FUNC(Val, Enum) Enum = Val,
271#include "DXContainerConstants.def"
272};
273
275
276#define COMPARISON_FUNC(Val, Enum) \
277 case Val: \
278 return true;
280 switch (V) {
281#include "DXContainerConstants.def"
282 }
283 return false;
284}
285
286#define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
288#include "DXContainerConstants.def"
289};
290
291#define STATIC_BORDER_COLOR(Val, Enum) \
292 case Val: \
293 return true;
295 switch (V) {
296#include "DXContainerConstants.def"
297 }
298 return false;
299}
300
302
304
308
309 void swapBytes() {
310 // nothing to swap
311 }
312};
313
327
339
353
358
359 void swapBytes() {
360 // nothing to swap
361 }
362};
363
379
385
394
396 switch (Stage) {
398 PS.swapBytes();
399 break;
401 VS.swapBytes();
402 break;
404 GS.swapBytes();
405 break;
407 HS.swapBytes();
408 break;
410 DS.swapBytes();
411 break;
413 MS.swapBytes();
414 break;
416 AS.swapBytes();
417 break;
418 default:
419 break;
420 }
421 }
422};
423
424static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
425 "Pipeline-specific PSV info must fit in 16 bytes.");
426
427namespace PSV {
428
429#define SEMANTIC_KIND(Val, Enum) Enum = Val,
430enum class SemanticKind : uint8_t {
431#include "DXContainerConstants.def"
432};
433
435
436#define COMPONENT_TYPE(Val, Enum) Enum = Val,
437enum class ComponentType : uint8_t {
438#include "DXContainerConstants.def"
439};
440
442
443#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
445#include "DXContainerConstants.def"
446};
447
449
450#define RESOURCE_TYPE(Val, Enum) Enum = Val,
451enum class ResourceType : uint32_t {
452#include "DXContainerConstants.def"
453};
454
456
457#define RESOURCE_KIND(Val, Enum) Enum = Val,
458enum class ResourceKind : uint32_t {
459#include "DXContainerConstants.def"
460};
461
463
464#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
467 struct FlagsBits {
468#include "llvm/BinaryFormat/DXContainerConstants.def"
469 };
470 union {
473 };
474 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
475};
476
477namespace v0 {
480 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
481 uint32_t MaximumWaveLaneCount; // maximum lane count required,
482 // 0xffffffff if unused
483 void swapBytes() {
484 // Skip the union because we don't know which field it has
487 }
488
489 void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); }
490};
491
505
530
531static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
532 "PSV Signature elements must fit in 16 bytes.");
533
534} // namespace v0
535
536namespace v1 {
537
539 uint8_t SigPrimVectors; // Primitive output for MS
541};
542
544 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
545 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
546 // Primitive output for MS (overlaps
547 // MeshInfo::SigPrimVectors)
549};
551 uint8_t ShaderStage; // PSVShaderKind
554
555 // PSVSignatureElement counts
559
560 // Number of packed vectors per signature
563
564 void swapBytes() {
565 // nothing to swap since everything is single-byte or a union field
566 }
567
573};
574
575} // namespace v1
576
606
607namespace v3 {
620
621} // namespace v3
622} // namespace PSV
623
624#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
626#include "DXContainerConstants.def"
627};
628
630
631#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
633#include "DXContainerConstants.def"
634};
635
637
638#define COMPONENT_TYPE(Val, Enum) Enum = Val,
640#include "DXContainerConstants.def"
641};
642
644
654
656 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
657 // stream order)
658 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
659 // the start of the null terminated string for the name.
660 uint32_t Index; // Semantic Index
661 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
662 SigComponentType CompType; // Type of bits.
663 uint32_t Register; // Register Index (row index)
664 uint8_t Mask; // Mask (column allocation)
665
666 // The ExclusiveMask has a different meaning for input and output signatures.
667 // For an output signature, masked components of the output register are never
668 // written to.
669 // For an input signature, masked components of the input register are always
670 // read.
672
674 SigMinPrecision MinPrecision; // Minimum precision of input/output data
675
687};
688
689static_assert(sizeof(ProgramSignatureElement) == 32,
690 "ProgramSignatureElement is misaligned");
691
692namespace RTS0 {
693namespace v1 {
724
739
748
749// following dx12 naming
750// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
762
774
792} // namespace v1
793
825
826namespace v3 {
839
840} // namespace v3
841} // namespace RTS0
842
843// D3D_ROOT_SIGNATURE_VERSION
845 V1_0 = 0x1,
846 V1_1 = 0x2,
847};
848
849} // namespace dxbc
850} // namespace llvm
851
852#endif // LLVM_BINARYFORMAT_DXCONTAINER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
@ RootSignature
Definition Triple.h:308
@ Amplification
Definition Triple.h:307
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< ComparisonFunc > > getComparisonFuncs()
LLVM_ABI ArrayRef< EnumEntry< ShaderVisibility > > getShaderVisibility()
bool isValidShaderVisibility(uint32_t V)
LLVM_ABI PartType parsePartType(StringRef S)
bool isValidSamplerFilter(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< RootFlags > > getRootFlags()
LLVM_ABI ArrayRef< EnumEntry< RootParameterType > > getRootParameterTypes()
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition DXContainer.h:47
LLVM_ABI ArrayRef< EnumEntry< SigComponentType > > getSigComponentTypes()
LLVM_ABI ArrayRef< EnumEntry< SigMinPrecision > > getSigMinPrecisions()
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
LLVM_ABI ArrayRef< EnumEntry< DescriptorRangeFlags > > getDescriptorRangeFlags()
LLVM_ABI ArrayRef< EnumEntry< SamplerFilter > > getSamplerFilters()
LLVM_ABI ArrayRef< EnumEntry< D3DSystemValue > > getD3DSystemValues()
bool isValidBorderColor(uint32_t V)
bool isValidComparisonFunc(uint32_t V)
bool isValidParameterType(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< StaticBorderColor > > getStaticBorderColors()
bool isValidAddress(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< TextureAddressMode > > getTextureAddressModes()
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 std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
@ LLVM_MARK_AS_BITMASK_ENUM
Definition ModRef.h:37
uint8_t Digest[16]
Definition DXContainer.h:54
ContainerVersion Version
Definition DXContainer.h:85
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.
Definition DXContainer.h:99
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()
void swapBytes(Triple::EnvironmentType Stage)
AmplificationPSVInfo AS