LLVM 19.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
16#include "llvm/ADT/StringRef.h"
19
20#include <stdint.h>
21
22namespace llvm {
23template <typename T> struct EnumEntry;
24
25// The DXContainer file format is arranged as a header and "parts". Semantically
26// parts are similar to sections in other object file formats. The File format
27// structure is roughly:
28
29// ┌────────────────────────────────┐
30// │ Header │
31// ├────────────────────────────────┤
32// │ Part │
33// ├────────────────────────────────┤
34// │ Part │
35// ├────────────────────────────────┤
36// │ ... │
37// └────────────────────────────────┘
38
39namespace dxbc {
40
43 "Shader kind out of expected range.");
44 return static_cast<Triple::EnvironmentType>(Triple::Pixel + Kind);
45}
46
47struct Hash {
48 uint8_t Digest[16];
49};
50
51enum class HashFlags : uint32_t {
52 None = 0, // No flags defined.
53 IncludesSource = 1, // This flag indicates that the shader hash was computed
54 // taking into account source information (-Zss)
55};
56
57struct ShaderHash {
58 uint32_t Flags; // dxbc::HashFlags
59 uint8_t Digest[16];
60
61 bool isPopulated();
62
64};
65
69
70 void swapBytes() {
73 }
74};
75
76struct Header {
77 uint8_t Magic[4]; // "DXBC"
82
83 void swapBytes() {
87 }
88 // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
89 // The offset is to a PartHeader, which is followed by the Part Data.
90};
91
92/// Use this type to describe the size and type of a DXIL container part.
93struct PartHeader {
94 uint8_t Name[4];
96
99 return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
100 }
101 // Structure is followed directly by part data: uint8_t PartData[PartSize].
102};
103
105 uint8_t Magic[4]; // ACSII "DXIL".
106 uint8_t MajorVersion; // DXIL version.
107 uint8_t MinorVersion; // DXIL version.
109 uint32_t Offset; // Offset to LLVM bitcode (from start of header).
110 uint32_t Size; // Size of LLVM bitcode (in bytes).
111 // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
112
113 void swapBytes() {
118 }
119};
120
122 uint8_t MinorVersion : 4;
123 uint8_t MajorVersion : 4;
124 uint8_t Unused;
126 uint32_t Size; // Size in uint32_t words including this header.
128
129 void swapBytes() {
133 }
134};
135
136static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
137
138#define CONTAINER_PART(Part) Part,
139enum class PartType {
140 Unknown = 0,
141#include "DXContainerConstants.def"
142};
143
144#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) Val = 1ull << Num,
145enum class FeatureFlags : uint64_t {
146#include "DXContainerConstants.def"
147};
148static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
149 "Shader flag bits exceed enum size.");
150
152
155 uint8_t Unused[3];
156
157 void swapBytes() {
158 // nothing to swap
159 }
160};
161
167
168 void swapBytes() {
173 }
174};
175
179 uint8_t Unused[3];
181
182 void swapBytes() {
185 }
186};
187
193 uint8_t Unused[3];
194
195 void swapBytes() {
199 }
200};
201
203 uint8_t DepthOutput;
205 uint8_t Unused[2];
206
207 void swapBytes() {
208 // nothing to swap
209 }
210};
211
218
219 void swapBytes() {
225 }
226};
227
230
232};
233
242
244 switch (Stage) {
246 PS.swapBytes();
247 break;
249 VS.swapBytes();
250 break;
252 GS.swapBytes();
253 break;
255 HS.swapBytes();
256 break;
258 DS.swapBytes();
259 break;
261 MS.swapBytes();
262 break;
264 AS.swapBytes();
265 break;
266 default:
267 break;
268 }
269 }
270};
271
272static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
273 "Pipeline-specific PSV info must fit in 16 bytes.");
274
275namespace PSV {
276
277#define SEMANTIC_KIND(Val, Enum) Enum = Val,
278enum class SemanticKind : uint8_t {
279#include "DXContainerConstants.def"
280};
281
283
284#define COMPONENT_TYPE(Val, Enum) Enum = Val,
285enum class ComponentType : uint8_t {
286#include "DXContainerConstants.def"
287};
288
290
291#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
292enum class InterpolationMode : uint8_t {
293#include "DXContainerConstants.def"
294};
295
297
298namespace v0 {
301 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
302 uint32_t MaximumWaveLaneCount; // maximum lane count required,
303 // 0xffffffff if unused
304 void swapBytes() {
305 // Skip the union because we don't know which field it has
308 }
309
311};
312
318
319 void swapBytes() {
324 }
325};
326
330
331 uint8_t Rows;
332 uint8_t StartRow;
333 uint8_t Cols : 4;
334 uint8_t StartCol : 2;
335 uint8_t Allocated : 1;
336 uint8_t Unused : 1;
338
341 uint8_t DynamicMask : 4;
342 uint8_t Stream : 2;
343 uint8_t Unused2 : 2;
344 uint8_t Reserved;
345
346 void swapBytes() {
349 }
350};
351
352static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
353 "PSV Signature elements must fit in 16 bytes.");
354
355} // namespace v0
356
357namespace v1 {
358
360 uint8_t SigPrimVectors; // Primitive output for MS
362};
363
365 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
366 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
367 // Primitive output for MS (overlaps
368 // MeshInfo::SigPrimVectors)
370};
372 uint8_t ShaderStage; // PSVShaderKind
373 uint8_t UsesViewID;
375
376 // PSVSignatureElement counts
380
381 // Number of packed vectors per signature
384
385 void swapBytes() {
386 // nothing to swap since everything is single-byte or a union field
387 }
388
393 }
394};
395
396} // namespace v1
397
398namespace v2 {
403
404 void swapBytes() {
408 }
409
412 }
413};
414
418
419 void swapBytes() {
423 }
424};
425
426} // namespace v2
427
428namespace v3 {
431
432 void swapBytes() {
435 }
436
439 }
440};
441
442} // namespace v3
443} // namespace PSV
444
445#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
447#include "DXContainerConstants.def"
448};
449
451
452#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
454#include "DXContainerConstants.def"
455};
456
458
459#define COMPONENT_TYPE(Val, Enum) Enum = Val,
461#include "DXContainerConstants.def"
462};
463
465
469
470 void swapBytes() {
473 }
474};
475
477 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
478 // stream order)
479 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
480 // the start of the null terminated string for the name.
481 uint32_t Index; // Semantic Index
482 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
483 SigComponentType CompType; // Type of bits.
484 uint32_t Register; // Register Index (row index)
485 uint8_t Mask; // Mask (column allocation)
486
487 // The ExclusiveMask has a different meaning for input and output signatures.
488 // For an output signature, masked components of the output register are never
489 // written to.
490 // For an input signature, masked components of the input register are always
491 // read.
493
495 SigMinPrecision MinPrecision; // Minimum precision of input/output data
496
497 void swapBytes() {
507 }
508};
509
510static_assert(sizeof(ProgramSignatureElement) == 32,
511 "ProgramSignatureElement is misaligned");
512
513} // namespace dxbc
514} // namespace llvm
515
516#endif // LLVM_BINARYFORMAT_DXCONTAINER_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:50
@ Amplification
Definition: Triple.h:290
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
ArrayRef< EnumEntry< ComponentType > > getComponentTypes()
Definition: DXContainer.cpp:79
ArrayRef< EnumEntry< SemanticKind > > getSemanticKinds()
Definition: DXContainer.cpp:69
ArrayRef< EnumEntry< InterpolationMode > > getInterpolationModes()
Definition: DXContainer.cpp:89
PartType parsePartType(StringRef S)
Definition: DXContainer.cpp:21
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition: DXContainer.h:41
ArrayRef< EnumEntry< SigComponentType > > getSigComponentTypes()
Definition: DXContainer.cpp:59
ArrayRef< EnumEntry< SigMinPrecision > > getSigMinPrecisions()
Definition: DXContainer.cpp:39
ArrayRef< EnumEntry< D3DSystemValue > > getD3DSystemValues()
Definition: DXContainer.cpp:49
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:48
ContainerVersion Version
Definition: DXContainer.h:79
uint8_t Magic[4]
Definition: DXContainer.h:77
uint32_t PartCount
Definition: DXContainer.h:81
uint32_t TessellatorOutputPrimitive
Definition: DXContainer.h:166
uint32_t OutputControlPointCount
Definition: DXContainer.h:164
uint32_t InputControlPointCount
Definition: DXContainer.h:163
uint32_t GroupSharedBytesDependentOnViewID
Definition: DXContainer.h:214
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:310
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:389
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:410
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:437
Use this type to describe the size and type of a DXIL container part.
Definition: DXContainer.h:93
StringRef getName() const
Definition: DXContainer.h:98
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:243
AmplificationPSVInfo AS
Definition: DXContainer.h:241