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
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
262
263const char *getProgramPartName(bool IsDebug);
264
268
269 void swapBytes() {
270 // nothing to swap
271 }
272};
273
287
299
313
318
319 void swapBytes() {
320 // nothing to swap
321 }
322};
323
339
345
354
356 switch (Stage) {
358 PS.swapBytes();
359 break;
361 VS.swapBytes();
362 break;
364 GS.swapBytes();
365 break;
367 HS.swapBytes();
368 break;
370 DS.swapBytes();
371 break;
373 MS.swapBytes();
374 break;
376 AS.swapBytes();
377 break;
378 default:
379 break;
380 }
381 }
382};
383
384static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
385 "Pipeline-specific PSV info must fit in 16 bytes.");
386
387namespace PSV {
388
389#define SEMANTIC_KIND(Val, Enum) Enum = Val,
390enum class SemanticKind : uint8_t {
391#include "DXContainerConstants.def"
392};
393
395
396#define COMPONENT_TYPE(Val, Enum) Enum = Val,
397enum class ComponentType : uint8_t {
398#include "DXContainerConstants.def"
399};
400
402
403#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
405#include "DXContainerConstants.def"
406};
407
409
410#define RESOURCE_TYPE(Val, Enum) Enum = Val,
411enum class ResourceType : uint32_t {
412#include "DXContainerConstants.def"
413};
414
416
417#define RESOURCE_KIND(Val, Enum) Enum = Val,
418enum class ResourceKind : uint32_t {
419#include "DXContainerConstants.def"
420};
421
423
424#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
427 struct FlagsBits {
428#include "llvm/BinaryFormat/DXContainerConstants.def"
429 };
430 union {
433 };
434 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
435};
436
437namespace v0 {
440 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
441 uint32_t MaximumWaveLaneCount; // maximum lane count required,
442 // 0xffffffff if unused
443 void swapBytes() {
444 // Skip the union because we don't know which field it has
447 }
448
449 void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); }
450};
451
465
490
491static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
492 "PSV Signature elements must fit in 16 bytes.");
493
494} // namespace v0
495
496namespace v1 {
497
499 uint8_t SigPrimVectors; // Primitive output for MS
501};
502
504 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
505 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
506 // Primitive output for MS (overlaps
507 // MeshInfo::SigPrimVectors)
509};
511 uint8_t ShaderStage; // PSVShaderKind
514
515 // PSVSignatureElement counts
519
520 // Number of packed vectors per signature
523
524 void swapBytes() {
525 // nothing to swap since everything is single-byte or a union field
526 }
527
533};
534
535} // namespace v1
536
566
567namespace v3 {
569 // Offset into the string table, which is stored separately in the PSV0 part.
570 // The entry name string itself is not stored in the RuntimeInfo record.
572
577
581};
582
583} // namespace v3
584} // namespace PSV
585
586#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
588#include "DXContainerConstants.def"
589};
590
592
593#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
595#include "DXContainerConstants.def"
596};
597
599
600#define COMPONENT_TYPE(Val, Enum) Enum = Val,
602#include "DXContainerConstants.def"
603};
604
606
616
618 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
619 // stream order)
620 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
621 // the start of the null terminated string for the name.
622 uint32_t Index; // Semantic Index
623 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
624 SigComponentType CompType; // Type of bits.
625 uint32_t Register; // Register Index (row index)
626 uint8_t Mask; // Mask (column allocation)
627
628 // The ExclusiveMask has a different meaning for input and output signatures.
629 // For an output signature, masked components of the output register are never
630 // written to.
631 // For an input signature, masked components of the input register are always
632 // read.
634
636 SigMinPrecision MinPrecision; // Minimum precision of input/output data
637
649};
650
651static_assert(sizeof(ProgramSignatureElement) == 32,
652 "ProgramSignatureElement is misaligned");
653
654namespace RTS0 {
655namespace v1 {
686
701
710
711// following dx12 naming
712// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
724
736
754} // namespace v1
755
787
788namespace v3 {
801
802} // namespace v3
803} // namespace RTS0
804
805// D3D_ROOT_SIGNATURE_VERSION
807 V1_0 = 0x1,
808 V1_1 = 0x2,
809 V1_2 = 0x3,
810};
811
814 /// Debug file name length, without null terminator.
816
821};
822
823static_assert(sizeof(DebugNameHeader) == 4, "DebugNameHeader size incorrect.");
824
825} // namespace dxbc
826} // namespace llvm
827
828#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
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
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()
bool isDebugProgramPart(PartType PT)
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)
LLVM_ABI_FOR_TEST bool isValidParameterType(uint32_t V)
const char * getProgramPartName(bool IsDebug)
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.
uint16_t NameLength
Debug file name length, without null terminator.
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