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 ROOT_PARAMETER(Val, Enum) Enum = Val,
190#include "DXContainerConstants.def"
191};
192
194
195#define ROOT_PARAMETER(Val, Enum) \
196 case Val: \
197 return true;
199 switch (V) {
200#include "DXContainerConstants.def"
201 }
202 return false;
203}
204
208
209#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
211#include "DXContainerConstants.def"
212};
213
215
216#define SHADER_VISIBILITY(Val, Enum) \
217 case Val: \
218 return true;
220 switch (V) {
221#include "DXContainerConstants.def"
222 }
223 return false;
224}
225
226#define FILTER(Val, Enum) Enum = Val,
228#include "DXContainerConstants.def"
229};
230
231#define FILTER(Val, Enum) \
232 case Val: \
233 return true;
235 switch (V) {
236#include "DXContainerConstants.def"
237 }
238 return false;
239}
240
242
243#define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
245#include "DXContainerConstants.def"
246};
247
249
250#define TEXTURE_ADDRESS_MODE(Val, Enum) \
251 case Val: \
252 return true;
253inline bool isValidAddress(uint32_t V) {
254 switch (V) {
255#include "DXContainerConstants.def"
256 }
257 return false;
258}
259
260#define COMPARISON_FUNC(Val, Enum) Enum = Val,
262#include "DXContainerConstants.def"
263};
264
266
267#define COMPARISON_FUNC(Val, Enum) \
268 case Val: \
269 return true;
271 switch (V) {
272#include "DXContainerConstants.def"
273 }
274 return false;
275}
276
277#define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
279#include "DXContainerConstants.def"
280};
281
282#define STATIC_BORDER_COLOR(Val, Enum) \
283 case Val: \
284 return true;
286 switch (V) {
287#include "DXContainerConstants.def"
288 }
289 return false;
290}
291
293
295
299
300 void swapBytes() {
301 // nothing to swap
302 }
303};
304
318
330
344
349
350 void swapBytes() {
351 // nothing to swap
352 }
353};
354
370
376
385
387 switch (Stage) {
389 PS.swapBytes();
390 break;
392 VS.swapBytes();
393 break;
395 GS.swapBytes();
396 break;
398 HS.swapBytes();
399 break;
401 DS.swapBytes();
402 break;
404 MS.swapBytes();
405 break;
407 AS.swapBytes();
408 break;
409 default:
410 break;
411 }
412 }
413};
414
415static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
416 "Pipeline-specific PSV info must fit in 16 bytes.");
417
418namespace PSV {
419
420#define SEMANTIC_KIND(Val, Enum) Enum = Val,
421enum class SemanticKind : uint8_t {
422#include "DXContainerConstants.def"
423};
424
426
427#define COMPONENT_TYPE(Val, Enum) Enum = Val,
428enum class ComponentType : uint8_t {
429#include "DXContainerConstants.def"
430};
431
433
434#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
436#include "DXContainerConstants.def"
437};
438
440
441#define RESOURCE_TYPE(Val, Enum) Enum = Val,
442enum class ResourceType : uint32_t {
443#include "DXContainerConstants.def"
444};
445
447
448#define RESOURCE_KIND(Val, Enum) Enum = Val,
449enum class ResourceKind : uint32_t {
450#include "DXContainerConstants.def"
451};
452
454
455#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
458 struct FlagsBits {
459#include "llvm/BinaryFormat/DXContainerConstants.def"
460 };
461 union {
464 };
465 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
466};
467
468namespace v0 {
471 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
472 uint32_t MaximumWaveLaneCount; // maximum lane count required,
473 // 0xffffffff if unused
474 void swapBytes() {
475 // Skip the union because we don't know which field it has
478 }
479
480 void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); }
481};
482
496
521
522static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
523 "PSV Signature elements must fit in 16 bytes.");
524
525} // namespace v0
526
527namespace v1 {
528
530 uint8_t SigPrimVectors; // Primitive output for MS
532};
533
535 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
536 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
537 // Primitive output for MS (overlaps
538 // MeshInfo::SigPrimVectors)
540};
542 uint8_t ShaderStage; // PSVShaderKind
545
546 // PSVSignatureElement counts
550
551 // Number of packed vectors per signature
554
555 void swapBytes() {
556 // nothing to swap since everything is single-byte or a union field
557 }
558
564};
565
566} // namespace v1
567
597
598namespace v3 {
611
612} // namespace v3
613} // namespace PSV
614
615#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
617#include "DXContainerConstants.def"
618};
619
621
622#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
624#include "DXContainerConstants.def"
625};
626
628
629#define COMPONENT_TYPE(Val, Enum) Enum = Val,
631#include "DXContainerConstants.def"
632};
633
635
645
647 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
648 // stream order)
649 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
650 // the start of the null terminated string for the name.
651 uint32_t Index; // Semantic Index
652 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
653 SigComponentType CompType; // Type of bits.
654 uint32_t Register; // Register Index (row index)
655 uint8_t Mask; // Mask (column allocation)
656
657 // The ExclusiveMask has a different meaning for input and output signatures.
658 // For an output signature, masked components of the output register are never
659 // written to.
660 // For an input signature, masked components of the input register are always
661 // read.
663
665 SigMinPrecision MinPrecision; // Minimum precision of input/output data
666
678};
679
680static_assert(sizeof(ProgramSignatureElement) == 32,
681 "ProgramSignatureElement is misaligned");
682
683namespace RTS0 {
684namespace v1 {
715
730
739
740// following dx12 naming
741// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
753
765
783} // namespace v1
784
816} // namespace RTS0
817
818// D3D_ROOT_SIGNATURE_VERSION
820 V1_0 = 0x1,
821 V1_1 = 0x2,
822};
823
824} // namespace dxbc
825} // namespace llvm
826
827#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< 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)
LLVM_ABI bool isPopulated()
void swapBytes(Triple::EnvironmentType Stage)
AmplificationPSVInfo AS