LLVM 17.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 {
23
24// The DXContainer file format is arranged as a header and "parts". Semantically
25// parts are similar to sections in other object file formats. The File format
26// structure is roughly:
27
28// ┌────────────────────────────────┐
29// │ Header │
30// ├────────────────────────────────┤
31// │ Part │
32// ├────────────────────────────────┤
33// │ Part │
34// ├────────────────────────────────┤
35// │ ... │
36// └────────────────────────────────┘
37
38namespace dxbc {
39
42 "Shader kind out of expected range.");
43 return static_cast<Triple::EnvironmentType>(Triple::Pixel + Kind);
44}
45
46struct Hash {
47 uint8_t Digest[16];
48};
49
50enum class HashFlags : uint32_t {
51 None = 0, // No flags defined.
52 IncludesSource = 1, // This flag indicates that the shader hash was computed
53 // taking into account source information (-Zss)
54};
55
56struct ShaderHash {
57 uint32_t Flags; // dxbc::HashFlags
58 uint8_t Digest[16];
59
60 bool isPopulated();
61
63};
64
68
69 void swapBytes() {
72 }
73};
74
75struct Header {
76 uint8_t Magic[4]; // "DXBC"
81
82 void swapBytes() {
86 }
87 // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
88 // The offset is to a PartHeader, which is followed by the Part Data.
89};
90
91/// Use this type to describe the size and type of a DXIL container part.
92struct PartHeader {
93 uint8_t Name[4];
95
98 return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
99 }
100 // Structure is followed directly by part data: uint8_t PartData[PartSize].
101};
102
104 uint8_t Magic[4]; // ACSII "DXIL".
105 uint8_t MajorVersion; // DXIL version.
106 uint8_t MinorVersion; // DXIL version.
108 uint32_t Offset; // Offset to LLVM bitcode (from start of header).
109 uint32_t Size; // Size of LLVM bitcode (in bytes).
110 // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
111
112 void swapBytes() {
117 }
118};
119
121 uint8_t MinorVersion : 4;
122 uint8_t MajorVersion : 4;
123 uint8_t Unused;
125 uint32_t Size; // Size in uint32_t words including this header.
127
128 void swapBytes() {
132 }
133};
134
135static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
136
137#define CONTAINER_PART(Part) Part,
138enum class PartType {
139 Unknown = 0,
140#include "DXContainerConstants.def"
141};
142
143#define SHADER_FLAG(Num, Val, Str) Val = 1ull << Num,
144enum class FeatureFlags : uint64_t {
145#include "DXContainerConstants.def"
146};
147static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
148 "Shader flag bits exceed enum size.");
149
151
154 uint8_t Unused[3];
155
156 void swapBytes() {
157 // nothing to swap
158 }
159};
160
166
167 void swapBytes() {
172 }
173};
174
178 uint8_t Unused[3];
180
181 void swapBytes() {
184 }
185};
186
192 uint8_t Unused[3];
193
194 void swapBytes() {
198 }
199};
200
202 uint8_t DepthOutput;
204 uint8_t Unused[2];
205
206 void swapBytes() {
207 // nothing to swap
208 }
209};
210
217
218 void swapBytes() {
224 }
225};
226
229
231};
232
241
243 switch (Stage) {
245 PS.swapBytes();
246 break;
248 VS.swapBytes();
249 break;
251 GS.swapBytes();
252 break;
254 HS.swapBytes();
255 break;
257 DS.swapBytes();
258 break;
260 MS.swapBytes();
261 break;
263 AS.swapBytes();
264 break;
265 default:
266 break;
267 }
268 }
269};
270
271static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
272 "Pipeline-specific PSV info must fit in 16 bytes.");
273
274namespace PSV {
275
276namespace v0 {
279 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
280 uint32_t MaximumWaveLaneCount; // maximum lane count required,
281 // 0xffffffff if unused
282 void swapBytes() {
283 // Skip the union because we don't know which field it has
286 }
287
289};
290
296
297 void swapBytes() {
302 }
303};
304
305} // namespace v0
306
307namespace v1 {
308
310 uint8_t SigPrimVectors; // Primitive output for MS
312};
313
315 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
316 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
317 // Primitive output for MS (overlaps
318 // MeshInfo::SigPrimVectors)
320};
322 uint8_t ShaderStage; // PSVShaderKind
323 uint8_t UsesViewID;
325
326 // PSVSignatureElement counts
330
331 // Number of packed vectors per signature
334
335 void swapBytes() {
336 // nothing to swap since everything is single-byte or a union field
337 }
338
343 }
344};
345
346} // namespace v1
347
348namespace v2 {
353
354 void swapBytes() {
358 }
359
362 }
363};
364
368
369 void swapBytes() {
373 }
374};
375
376} // namespace v2
377} // namespace PSV
378
379} // namespace dxbc
380} // namespace llvm
381
382#endif // LLVM_BINARYFORMAT_DXCONTAINER_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
@ Amplification
Definition: Triple.h:276
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
PartType parsePartType(StringRef S)
Definition: DXContainer.cpp:20
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition: DXContainer.h:40
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint8_t Digest[16]
Definition: DXContainer.h:47
ContainerVersion Version
Definition: DXContainer.h:78
uint8_t Magic[4]
Definition: DXContainer.h:76
uint32_t PartCount
Definition: DXContainer.h:80
uint32_t TessellatorOutputPrimitive
Definition: DXContainer.h:165
uint32_t OutputControlPointCount
Definition: DXContainer.h:163
uint32_t InputControlPointCount
Definition: DXContainer.h:162
uint32_t GroupSharedBytesDependentOnViewID
Definition: DXContainer.h:213
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:288
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:339
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:360
Use this type to describe the size and type of a DXIL container part.
Definition: DXContainer.h:92
StringRef getName() const
Definition: DXContainer.h:97
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:242
AmplificationPSVInfo AS
Definition: DXContainer.h:240