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
205
207
208#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
210#include "DXContainerConstants.def"
211};
212
214
216
217#define FILTER(Val, Enum) Enum = Val,
219#include "DXContainerConstants.def"
220};
221
223
225
226#define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
228#include "DXContainerConstants.def"
229};
230
232
234
235#define COMPARISON_FUNC(Val, Enum) Enum = Val,
237#include "DXContainerConstants.def"
238};
239
241
243
244#define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
246#include "DXContainerConstants.def"
247};
248
250
252
254
256
258
260
264
265 void swapBytes() {
266 // nothing to swap
267 }
268};
269
283
295
309
314
315 void swapBytes() {
316 // nothing to swap
317 }
318};
319
335
341
350
352 switch (Stage) {
354 PS.swapBytes();
355 break;
357 VS.swapBytes();
358 break;
360 GS.swapBytes();
361 break;
363 HS.swapBytes();
364 break;
366 DS.swapBytes();
367 break;
369 MS.swapBytes();
370 break;
372 AS.swapBytes();
373 break;
374 default:
375 break;
376 }
377 }
378};
379
380static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
381 "Pipeline-specific PSV info must fit in 16 bytes.");
382
383namespace PSV {
384
385#define SEMANTIC_KIND(Val, Enum) Enum = Val,
386enum class SemanticKind : uint8_t {
387#include "DXContainerConstants.def"
388};
389
391
392#define COMPONENT_TYPE(Val, Enum) Enum = Val,
393enum class ComponentType : uint8_t {
394#include "DXContainerConstants.def"
395};
396
398
399#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
401#include "DXContainerConstants.def"
402};
403
405
406#define RESOURCE_TYPE(Val, Enum) Enum = Val,
407enum class ResourceType : uint32_t {
408#include "DXContainerConstants.def"
409};
410
412
413#define RESOURCE_KIND(Val, Enum) Enum = Val,
414enum class ResourceKind : uint32_t {
415#include "DXContainerConstants.def"
416};
417
419
420#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
423 struct FlagsBits {
424#include "llvm/BinaryFormat/DXContainerConstants.def"
425 };
426 union {
429 };
430 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
431};
432
433namespace v0 {
436 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
437 uint32_t MaximumWaveLaneCount; // maximum lane count required,
438 // 0xffffffff if unused
439 void swapBytes() {
440 // Skip the union because we don't know which field it has
443 }
444
445 void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); }
446};
447
461
486
487static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
488 "PSV Signature elements must fit in 16 bytes.");
489
490} // namespace v0
491
492namespace v1 {
493
495 uint8_t SigPrimVectors; // Primitive output for MS
497};
498
500 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
501 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
502 // Primitive output for MS (overlaps
503 // MeshInfo::SigPrimVectors)
505};
507 uint8_t ShaderStage; // PSVShaderKind
510
511 // PSVSignatureElement counts
515
516 // Number of packed vectors per signature
519
520 void swapBytes() {
521 // nothing to swap since everything is single-byte or a union field
522 }
523
529};
530
531} // namespace v1
532
562
563namespace v3 {
576
577} // namespace v3
578} // namespace PSV
579
580#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
582#include "DXContainerConstants.def"
583};
584
586
587#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
589#include "DXContainerConstants.def"
590};
591
593
594#define COMPONENT_TYPE(Val, Enum) Enum = Val,
596#include "DXContainerConstants.def"
597};
598
600
610
612 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
613 // stream order)
614 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
615 // the start of the null terminated string for the name.
616 uint32_t Index; // Semantic Index
617 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
618 SigComponentType CompType; // Type of bits.
619 uint32_t Register; // Register Index (row index)
620 uint8_t Mask; // Mask (column allocation)
621
622 // The ExclusiveMask has a different meaning for input and output signatures.
623 // For an output signature, masked components of the output register are never
624 // written to.
625 // For an input signature, masked components of the input register are always
626 // read.
628
630 SigMinPrecision MinPrecision; // Minimum precision of input/output data
631
643};
644
645static_assert(sizeof(ProgramSignatureElement) == 32,
646 "ProgramSignatureElement is misaligned");
647
648namespace RTS0 {
649namespace v1 {
680
695
704
705// following dx12 naming
706// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
718
730
748} // namespace v1
749
781
782namespace v3 {
795
796} // namespace v3
797} // namespace RTS0
798
799// D3D_ROOT_SIGNATURE_VERSION
801 V1_0 = 0x1,
802 V1_1 = 0x2,
803 V1_2 = 0x3,
804};
805
806} // namespace dxbc
807} // namespace llvm
808
809#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)
bool isValidStaticSamplerFlags(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< RootFlags > > getRootFlags()
LLVM_ABI ArrayRef< EnumEntry< RootParameterType > > getRootParameterTypes()
bool isValidRootDesciptorFlags(uint32_t V)
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 isValidDescriptorRangeFlags(uint32_t V)
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.
@ 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