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
232
233#define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
235#include "DXContainerConstants.def"
236};
237
239
240#define COMPARISON_FUNC(Val, Enum) Enum = Val,
242#include "DXContainerConstants.def"
243};
244
246
247#define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
249#include "DXContainerConstants.def"
250};
251
253
255
259
260 void swapBytes() {
261 // nothing to swap
262 }
263};
264
278
290
304
309
310 void swapBytes() {
311 // nothing to swap
312 }
313};
314
330
336
345
347 switch (Stage) {
349 PS.swapBytes();
350 break;
352 VS.swapBytes();
353 break;
355 GS.swapBytes();
356 break;
358 HS.swapBytes();
359 break;
361 DS.swapBytes();
362 break;
364 MS.swapBytes();
365 break;
367 AS.swapBytes();
368 break;
369 default:
370 break;
371 }
372 }
373};
374
375static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
376 "Pipeline-specific PSV info must fit in 16 bytes.");
377
378namespace PSV {
379
380#define SEMANTIC_KIND(Val, Enum) Enum = Val,
381enum class SemanticKind : uint8_t {
382#include "DXContainerConstants.def"
383};
384
386
387#define COMPONENT_TYPE(Val, Enum) Enum = Val,
388enum class ComponentType : uint8_t {
389#include "DXContainerConstants.def"
390};
391
393
394#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
396#include "DXContainerConstants.def"
397};
398
400
401#define RESOURCE_TYPE(Val, Enum) Enum = Val,
402enum class ResourceType : uint32_t {
403#include "DXContainerConstants.def"
404};
405
407
408#define RESOURCE_KIND(Val, Enum) Enum = Val,
409enum class ResourceKind : uint32_t {
410#include "DXContainerConstants.def"
411};
412
414
415#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
418 struct FlagsBits {
419#include "llvm/BinaryFormat/DXContainerConstants.def"
420 };
421 union {
424 };
425 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
426};
427
428namespace v0 {
431 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
432 uint32_t MaximumWaveLaneCount; // maximum lane count required,
433 // 0xffffffff if unused
434 void swapBytes() {
435 // Skip the union because we don't know which field it has
438 }
439
440 void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); }
441};
442
456
481
482static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
483 "PSV Signature elements must fit in 16 bytes.");
484
485} // namespace v0
486
487namespace v1 {
488
490 uint8_t SigPrimVectors; // Primitive output for MS
492};
493
495 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
496 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
497 // Primitive output for MS (overlaps
498 // MeshInfo::SigPrimVectors)
500};
502 uint8_t ShaderStage; // PSVShaderKind
505
506 // PSVSignatureElement counts
510
511 // Number of packed vectors per signature
514
515 void swapBytes() {
516 // nothing to swap since everything is single-byte or a union field
517 }
518
524};
525
526} // namespace v1
527
557
558namespace v3 {
571
572} // namespace v3
573} // namespace PSV
574
575#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
577#include "DXContainerConstants.def"
578};
579
581
582#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
584#include "DXContainerConstants.def"
585};
586
588
589#define COMPONENT_TYPE(Val, Enum) Enum = Val,
591#include "DXContainerConstants.def"
592};
593
595
605
607 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
608 // stream order)
609 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
610 // the start of the null terminated string for the name.
611 uint32_t Index; // Semantic Index
612 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
613 SigComponentType CompType; // Type of bits.
614 uint32_t Register; // Register Index (row index)
615 uint8_t Mask; // Mask (column allocation)
616
617 // The ExclusiveMask has a different meaning for input and output signatures.
618 // For an output signature, masked components of the output register are never
619 // written to.
620 // For an input signature, masked components of the input register are always
621 // read.
623
625 SigMinPrecision MinPrecision; // Minimum precision of input/output data
626
638};
639
640static_assert(sizeof(ProgramSignatureElement) == 32,
641 "ProgramSignatureElement is misaligned");
642
643namespace RTS0 {
644namespace v1 {
675
690
699
700// following dx12 naming
701// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
713
725
743} // namespace v1
744
776} // namespace RTS0
777
778// D3D_ROOT_SIGNATURE_VERSION
780 V1_0 = 0x1,
781 V1_1 = 0x2,
782};
783
784} // namespace dxbc
785} // namespace llvm
786
787#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)
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 isValidParameterType(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< StaticBorderColor > > getStaticBorderColors()
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