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
75
76 void swapBytes() {
79 }
80};
81
82struct Header {
83 uint8_t Magic[4]; // "DXBC"
88
89 void swapBytes() {
93 }
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
119 void swapBytes() {
124 }
125};
126
131 uint32_t Size; // Size in uint32_t words including this header.
133
134 void 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 {
150 Unknown = 0,
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 ROOT_PARAMETER(Val, Enum) Enum = Val,
190#include "DXContainerConstants.def"
191};
192
194
195#define DESCRIPTOR_RANGE(Val, Enum) Enum = Val,
197#include "DXContainerConstants.def"
198};
199
201
202#define ROOT_PARAMETER(Val, Enum) \
203 case Val: \
204 return true;
206 switch (V) {
207#include "DXContainerConstants.def"
208 }
209 return false;
210}
211
212#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
214#include "DXContainerConstants.def"
215};
216
218
219#define SHADER_VISIBILITY(Val, Enum) \
220 case Val: \
221 return true;
223 switch (V) {
224#include "DXContainerConstants.def"
225 }
226 return false;
227}
228
229#define FILTER(Val, Enum) Enum = Val,
231#include "DXContainerConstants.def"
232};
233
235
236#define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
238#include "DXContainerConstants.def"
239};
240
242
243#define COMPARISON_FUNC(Val, Enum) Enum = Val,
245#include "DXContainerConstants.def"
246};
247
249
250#define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
252#include "DXContainerConstants.def"
253};
254
256
258
262
263 void swapBytes() {
264 // nothing to swap
265 }
266};
267
273
274 void swapBytes() {
279 }
280};
281
287
288 void swapBytes() {
291 }
292};
293
300
301 void swapBytes() {
305 }
306};
307
312
313 void swapBytes() {
314 // nothing to swap
315 }
316};
317
324
325 void swapBytes() {
331 }
332};
333
336
338};
339
348
350 switch (Stage) {
352 PS.swapBytes();
353 break;
355 VS.swapBytes();
356 break;
358 GS.swapBytes();
359 break;
361 HS.swapBytes();
362 break;
364 DS.swapBytes();
365 break;
367 MS.swapBytes();
368 break;
370 AS.swapBytes();
371 break;
372 default:
373 break;
374 }
375 }
376};
377
378static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
379 "Pipeline-specific PSV info must fit in 16 bytes.");
380
381namespace PSV {
382
383#define SEMANTIC_KIND(Val, Enum) Enum = Val,
384enum class SemanticKind : uint8_t {
385#include "DXContainerConstants.def"
386};
387
389
390#define COMPONENT_TYPE(Val, Enum) Enum = Val,
391enum class ComponentType : uint8_t {
392#include "DXContainerConstants.def"
393};
394
396
397#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
399#include "DXContainerConstants.def"
400};
401
403
404#define RESOURCE_TYPE(Val, Enum) Enum = Val,
405enum class ResourceType : uint32_t {
406#include "DXContainerConstants.def"
407};
408
410
411#define RESOURCE_KIND(Val, Enum) Enum = Val,
412enum class ResourceKind : uint32_t {
413#include "DXContainerConstants.def"
414};
415
417
418#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
421 struct FlagsBits {
422#include "llvm/BinaryFormat/DXContainerConstants.def"
423 };
424 union {
427 };
428 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
429};
430
431namespace v0 {
434 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
435 uint32_t MaximumWaveLaneCount; // maximum lane count required,
436 // 0xffffffff if unused
437 void swapBytes() {
438 // Skip the union because we don't know which field it has
441 }
442
444};
445
451
452 void swapBytes() {
457 }
458};
459
463
471
478
479 void swapBytes() {
482 }
483};
484
485static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
486 "PSV Signature elements must fit in 16 bytes.");
487
488} // namespace v0
489
490namespace v1 {
491
493 uint8_t SigPrimVectors; // Primitive output for MS
495};
496
498 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
499 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
500 // Primitive output for MS (overlaps
501 // MeshInfo::SigPrimVectors)
503};
505 uint8_t ShaderStage; // PSVShaderKind
508
509 // PSVSignatureElement counts
513
514 // Number of packed vectors per signature
517
518 void swapBytes() {
519 // nothing to swap since everything is single-byte or a union field
520 }
521
526 }
527};
528
529} // namespace v1
530
531namespace v2 {
536
537 void swapBytes() {
541 }
542
545 }
546};
547
551
552 void swapBytes() {
556 }
557};
558
559} // namespace v2
560
561namespace v3 {
564
565 void swapBytes() {
568 }
569
572 }
573};
574
575} // namespace v3
576} // namespace PSV
577
578#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
580#include "DXContainerConstants.def"
581};
582
584
585#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
587#include "DXContainerConstants.def"
588};
589
591
592#define COMPONENT_TYPE(Val, Enum) Enum = Val,
594#include "DXContainerConstants.def"
595};
596
598
602
603 void swapBytes() {
606 }
607};
608
610 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
611 // stream order)
612 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
613 // the start of the null terminated string for the name.
614 uint32_t Index; // Semantic Index
615 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
616 SigComponentType CompType; // Type of bits.
617 uint32_t Register; // Register Index (row index)
618 uint8_t Mask; // Mask (column allocation)
619
620 // The ExclusiveMask has a different meaning for input and output signatures.
621 // For an output signature, masked components of the output register are never
622 // written to.
623 // For an input signature, masked components of the input register are always
624 // read.
626
628 SigMinPrecision MinPrecision; // Minimum precision of input/output data
629
630 void swapBytes() {
640 }
641};
642
643static_assert(sizeof(ProgramSignatureElement) == 32,
644 "ProgramSignatureElement is misaligned");
645
646namespace RTS0 {
647namespace v1 {
657 float MinLOD;
658 float MaxLOD;
662 void swapBytes() {
676 };
677};
678
685 void swapBytes() {
691 }
692};
693
697 void swapBytes() {
700 }
701};
702
703// following dx12 naming
704// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
709
710 void swapBytes() {
714 }
715};
716
721
722 void swapBytes() {
726 }
727};
728
736
737 void swapBytes() {
744 }
745};
746} // namespace v1
747
748namespace v2 {
751
752 RootDescriptor() = default;
754 : v1::RootDescriptor(Base), Flags(0u) {}
755
756 void swapBytes() {
759 }
760};
761
769 void swapBytes() {
776 }
777};
778} // namespace v2
779} // namespace RTS0
780
781// D3D_ROOT_SIGNATURE_VERSION
783 V1_0 = 0x1,
784 V1_1 = 0x2,
785};
786
787} // namespace dxbc
788} // namespace llvm
789
790#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
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
@ Amplification
Definition: Triple.h:305
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
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()
Definition: DXContainer.cpp:98
bool isValidShaderVisibility(uint32_t V)
Definition: DXContainer.h:222
LLVM_ABI PartType parsePartType(StringRef S)
Definition: DXContainer.cpp:21
LLVM_ABI ArrayRef< EnumEntry< RootFlags > > getRootFlags()
Definition: DXContainer.cpp:68
LLVM_ABI ArrayRef< EnumEntry< RootParameterType > > getRootParameterTypes()
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition: DXContainer.h:47
LLVM_ABI ArrayRef< EnumEntry< SigComponentType > > getSigComponentTypes()
Definition: DXContainer.cpp:59
LLVM_ABI ArrayRef< EnumEntry< SigMinPrecision > > getSigMinPrecisions()
Definition: DXContainer.cpp:39
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
LLVM_ABI ArrayRef< EnumEntry< DescriptorRangeFlags > > getDescriptorRangeFlags()
Definition: DXContainer.cpp:88
LLVM_ABI ArrayRef< EnumEntry< SamplerFilter > > getSamplerFilters()
LLVM_ABI ArrayRef< EnumEntry< D3DSystemValue > > getD3DSystemValues()
Definition: DXContainer.cpp:49
bool isValidParameterType(uint32_t V)
Definition: DXContainer.h:205
LLVM_ABI ArrayRef< EnumEntry< DescriptorRangeType > > getDescriptorRangeTypes()
LLVM_ABI ArrayRef< EnumEntry< StaticBorderColor > > getStaticBorderColors()
LLVM_ABI ArrayRef< EnumEntry< TextureAddressMode > > getTextureAddressModes()
LLVM_ABI ArrayRef< EnumEntry< RootDescriptorFlags > > getRootDescriptorFlags()
Definition: DXContainer.cpp:78
void swapByteOrder(T &Value)
Definition: SwapByteOrder.h:61
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint8_t Digest[16]
Definition: DXContainer.h:54
ContainerVersion Version
Definition: DXContainer.h:85
uint8_t Magic[4]
Definition: DXContainer.h:83
uint32_t PartCount
Definition: DXContainer.h:87
uint32_t TessellatorOutputPrimitive
Definition: DXContainer.h:272
uint32_t OutputControlPointCount
Definition: DXContainer.h:270
uint32_t InputControlPointCount
Definition: DXContainer.h:269
uint32_t GroupSharedBytesDependentOnViewID
Definition: DXContainer.h:320
bool operator==(const uint32_t RFlags) const
Definition: DXContainer.h:428
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:443
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:522
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:543
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:570
Use this type to describe the size and type of a DXIL container part.
Definition: DXContainer.h:99
StringRef getName() const
Definition: DXContainer.h:104
static uint8_t getVersion(uint8_t Major, uint8_t Minor)
Definition: DXContainer.h:141
RootDescriptor(v1::RootDescriptor &Base)
Definition: DXContainer.h:753
LLVM_ABI bool isPopulated()
Definition: DXContainer.cpp:28
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:349
AmplificationPSVInfo AS
Definition: DXContainer.h:347