LLVM 20.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 MinorVersion; // DXIL version.
107 uint8_t MajorVersion; // 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 Version;
123 uint8_t Unused;
125 uint32_t Size; // Size in uint32_t words including this header.
127
128 void swapBytes() {
132 }
133 uint8_t getMajorVersion() { return Version >> 4; }
134 uint8_t getMinorVersion() { return Version & 0xF; }
135 static uint8_t getVersion(uint8_t Major, uint8_t Minor) {
136 return (Major << 4) | Minor;
137 }
138};
139
140static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
141
142#define CONTAINER_PART(Part) Part,
143enum class PartType {
144 Unknown = 0,
145#include "DXContainerConstants.def"
146};
147
148#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) Val = 1ull << Num,
149enum class FeatureFlags : uint64_t {
150#include "DXContainerConstants.def"
151};
152static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
153 "Shader flag bits exceed enum size.");
154
156
159 uint8_t Unused[3];
160
161 void swapBytes() {
162 // nothing to swap
163 }
164};
165
171
172 void swapBytes() {
177 }
178};
179
183 uint8_t Unused[3];
185
186 void swapBytes() {
189 }
190};
191
197 uint8_t Unused[3];
198
199 void swapBytes() {
203 }
204};
205
207 uint8_t DepthOutput;
209 uint8_t Unused[2];
210
211 void swapBytes() {
212 // nothing to swap
213 }
214};
215
222
223 void swapBytes() {
229 }
230};
231
234
236};
237
246
248 switch (Stage) {
250 PS.swapBytes();
251 break;
253 VS.swapBytes();
254 break;
256 GS.swapBytes();
257 break;
259 HS.swapBytes();
260 break;
262 DS.swapBytes();
263 break;
265 MS.swapBytes();
266 break;
268 AS.swapBytes();
269 break;
270 default:
271 break;
272 }
273 }
274};
275
276static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
277 "Pipeline-specific PSV info must fit in 16 bytes.");
278
279namespace PSV {
280
281#define SEMANTIC_KIND(Val, Enum) Enum = Val,
282enum class SemanticKind : uint8_t {
283#include "DXContainerConstants.def"
284};
285
287
288#define COMPONENT_TYPE(Val, Enum) Enum = Val,
289enum class ComponentType : uint8_t {
290#include "DXContainerConstants.def"
291};
292
294
295#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
296enum class InterpolationMode : uint8_t {
297#include "DXContainerConstants.def"
298};
299
301
302namespace v0 {
305 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
306 uint32_t MaximumWaveLaneCount; // maximum lane count required,
307 // 0xffffffff if unused
308 void swapBytes() {
309 // Skip the union because we don't know which field it has
312 }
313
315};
316
322
323 void swapBytes() {
328 }
329};
330
334
335 uint8_t Rows;
336 uint8_t StartRow;
337 uint8_t Cols : 4;
338 uint8_t StartCol : 2;
339 uint8_t Allocated : 1;
340 uint8_t Unused : 1;
342
345 uint8_t DynamicMask : 4;
346 uint8_t Stream : 2;
347 uint8_t Unused2 : 2;
348 uint8_t Reserved;
349
350 void swapBytes() {
353 }
354};
355
356static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
357 "PSV Signature elements must fit in 16 bytes.");
358
359} // namespace v0
360
361namespace v1 {
362
364 uint8_t SigPrimVectors; // Primitive output for MS
366};
367
369 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
370 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
371 // Primitive output for MS (overlaps
372 // MeshInfo::SigPrimVectors)
374};
376 uint8_t ShaderStage; // PSVShaderKind
377 uint8_t UsesViewID;
379
380 // PSVSignatureElement counts
384
385 // Number of packed vectors per signature
388
389 void swapBytes() {
390 // nothing to swap since everything is single-byte or a union field
391 }
392
397 }
398};
399
400} // namespace v1
401
402namespace v2 {
407
408 void swapBytes() {
412 }
413
416 }
417};
418
422
423 void swapBytes() {
427 }
428};
429
430} // namespace v2
431
432namespace v3 {
435
436 void swapBytes() {
439 }
440
443 }
444};
445
446} // namespace v3
447} // namespace PSV
448
449#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
451#include "DXContainerConstants.def"
452};
453
455
456#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
458#include "DXContainerConstants.def"
459};
460
462
463#define COMPONENT_TYPE(Val, Enum) Enum = Val,
465#include "DXContainerConstants.def"
466};
467
469
473
474 void swapBytes() {
477 }
478};
479
481 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
482 // stream order)
483 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
484 // the start of the null terminated string for the name.
485 uint32_t Index; // Semantic Index
486 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
487 SigComponentType CompType; // Type of bits.
488 uint32_t Register; // Register Index (row index)
489 uint8_t Mask; // Mask (column allocation)
490
491 // The ExclusiveMask has a different meaning for input and output signatures.
492 // For an output signature, masked components of the output register are never
493 // written to.
494 // For an input signature, masked components of the input register are always
495 // read.
497
499 SigMinPrecision MinPrecision; // Minimum precision of input/output data
500
501 void swapBytes() {
511 }
512};
513
514static_assert(sizeof(ProgramSignatureElement) == 32,
515 "ProgramSignatureElement is misaligned");
516
517} // namespace dxbc
518} // namespace llvm
519
520#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:289
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:170
uint32_t OutputControlPointCount
Definition: DXContainer.h:168
uint32_t InputControlPointCount
Definition: DXContainer.h:167
uint32_t GroupSharedBytesDependentOnViewID
Definition: DXContainer.h:218
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:314
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:393
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:414
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:441
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
static uint8_t getVersion(uint8_t Major, uint8_t Minor)
Definition: DXContainer.h:135
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:247
AmplificationPSVInfo AS
Definition: DXContainer.h:245