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 {
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
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 {
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
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
160
161 void swapBytes() {
162 // nothing to swap
163 }
164};
165
171
172 void swapBytes() {
177 }
178};
179
185
186 void swapBytes() {
189 }
190};
191
198
199 void swapBytes() {
203 }
204};
205
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,
297#include "DXContainerConstants.def"
298};
299
301
302#define RESOURCE_TYPE(Val, Enum) Enum = Val,
303enum class ResourceType : uint32_t {
304#include "DXContainerConstants.def"
305};
306
308
309#define RESOURCE_KIND(Val, Enum) Enum = Val,
310enum class ResourceKind : uint32_t {
311#include "DXContainerConstants.def"
312};
313
315
316#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
319 struct FlagsBits {
320#include "llvm/BinaryFormat/DXContainerConstants.def"
321 };
322 union {
325 };
326 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
327};
328
329namespace v0 {
332 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
333 uint32_t MaximumWaveLaneCount; // maximum lane count required,
334 // 0xffffffff if unused
335 void swapBytes() {
336 // Skip the union because we don't know which field it has
339 }
340
342};
343
349
350 void swapBytes() {
355 }
356};
357
361
369
376
377 void swapBytes() {
380 }
381};
382
383static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
384 "PSV Signature elements must fit in 16 bytes.");
385
386} // namespace v0
387
388namespace v1 {
389
391 uint8_t SigPrimVectors; // Primitive output for MS
393};
394
396 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
397 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
398 // Primitive output for MS (overlaps
399 // MeshInfo::SigPrimVectors)
401};
403 uint8_t ShaderStage; // PSVShaderKind
406
407 // PSVSignatureElement counts
411
412 // Number of packed vectors per signature
415
416 void swapBytes() {
417 // nothing to swap since everything is single-byte or a union field
418 }
419
424 }
425};
426
427} // namespace v1
428
429namespace v2 {
434
435 void swapBytes() {
439 }
440
443 }
444};
445
449
450 void swapBytes() {
454 }
455};
456
457} // namespace v2
458
459namespace v3 {
462
463 void swapBytes() {
466 }
467
470 }
471};
472
473} // namespace v3
474} // namespace PSV
475
476#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
478#include "DXContainerConstants.def"
479};
480
482
483#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
485#include "DXContainerConstants.def"
486};
487
489
490#define COMPONENT_TYPE(Val, Enum) Enum = Val,
492#include "DXContainerConstants.def"
493};
494
496
500
501 void swapBytes() {
504 }
505};
506
508 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
509 // stream order)
510 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
511 // the start of the null terminated string for the name.
512 uint32_t Index; // Semantic Index
513 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
514 SigComponentType CompType; // Type of bits.
515 uint32_t Register; // Register Index (row index)
516 uint8_t Mask; // Mask (column allocation)
517
518 // The ExclusiveMask has a different meaning for input and output signatures.
519 // For an output signature, masked components of the output register are never
520 // written to.
521 // For an input signature, masked components of the input register are always
522 // read.
524
526 SigMinPrecision MinPrecision; // Minimum precision of input/output data
527
528 void swapBytes() {
538 }
539};
540
541static_assert(sizeof(ProgramSignatureElement) == 32,
542 "ProgramSignatureElement is misaligned");
543
544} // namespace dxbc
545} // namespace llvm
546
547#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:51
@ Amplification
Definition: Triple.h:299
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
ArrayRef< EnumEntry< ResourceKind > > getResourceKinds()
ArrayRef< EnumEntry< ComponentType > > getComponentTypes()
Definition: DXContainer.cpp:79
ArrayRef< EnumEntry< ResourceType > > getResourceTypes()
Definition: DXContainer.cpp:99
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
bool operator==(const uint32_t RFlags) const
Definition: DXContainer.h:326
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:341
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:420
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:441
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:468
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