LLVM 21.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"
18#include "llvm/Support/Error.h"
21
22#include <stdint.h>
23
24namespace llvm {
25template <typename T> struct EnumEntry;
26
27// The DXContainer file format is arranged as a header and "parts". Semantically
28// parts are similar to sections in other object file formats. The File format
29// structure is roughly:
30
31// ┌────────────────────────────────┐
32// │ Header │
33// ├────────────────────────────────┤
34// │ Part │
35// ├────────────────────────────────┤
36// │ Part │
37// ├────────────────────────────────┤
38// │ ... │
39// └────────────────────────────────┘
40
41namespace dxbc {
42
45 "Shader kind out of expected range.");
46 return static_cast<Triple::EnvironmentType>(Triple::Pixel + Kind);
47}
48
49struct Hash {
51};
52
53enum class HashFlags : uint32_t {
54 None = 0, // No flags defined.
55 IncludesSource = 1, // This flag indicates that the shader hash was computed
56 // taking into account source information (-Zss)
57};
58
59struct ShaderHash {
60 uint32_t Flags; // dxbc::HashFlags
62
63 bool isPopulated();
64
66};
67
71
72 void swapBytes() {
75 }
76};
77
78struct Header {
79 uint8_t Magic[4]; // "DXBC"
84
85 void swapBytes() {
89 }
90 // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
91 // The offset is to a PartHeader, which is followed by the Part Data.
92};
93
94/// Use this type to describe the size and type of a DXIL container part.
95struct PartHeader {
98
101 return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
102 }
103 // Structure is followed directly by part data: uint8_t PartData[PartSize].
104};
105
107 uint8_t Magic[4]; // ACSII "DXIL".
108 uint8_t MinorVersion; // DXIL version.
109 uint8_t MajorVersion; // DXIL version.
111 uint32_t Offset; // Offset to LLVM bitcode (from start of header).
112 uint32_t Size; // Size of LLVM bitcode (in bytes).
113 // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
114
115 void swapBytes() {
120 }
121};
122
127 uint32_t Size; // Size in uint32_t words including this header.
129
130 void swapBytes() {
134 }
135 uint8_t getMajorVersion() { return Version >> 4; }
136 uint8_t getMinorVersion() { return Version & 0xF; }
137 static uint8_t getVersion(uint8_t Major, uint8_t Minor) {
138 return (Major << 4) | Minor;
139 }
140};
141
142static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
143
144#define CONTAINER_PART(Part) Part,
145enum class PartType {
146 Unknown = 0,
147#include "DXContainerConstants.def"
148};
149
150#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) Val = 1ull << Num,
151enum class FeatureFlags : uint64_t {
152#include "DXContainerConstants.def"
153};
154static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
155 "Shader flag bits exceed enum size.");
156
157#define ROOT_ELEMENT_FLAG(Num, Val) Val = 1ull << Num,
159#include "DXContainerConstants.def"
160};
161
163
167
168 void swapBytes() {
169 // nothing to swap
170 }
171};
172
178
179 void swapBytes() {
184 }
185};
186
192
193 void swapBytes() {
196 }
197};
198
205
206 void swapBytes() {
210 }
211};
212
217
218 void swapBytes() {
219 // nothing to swap
220 }
221};
222
229
230 void swapBytes() {
236 }
237};
238
241
243};
244
253
255 switch (Stage) {
257 PS.swapBytes();
258 break;
260 VS.swapBytes();
261 break;
263 GS.swapBytes();
264 break;
266 HS.swapBytes();
267 break;
269 DS.swapBytes();
270 break;
272 MS.swapBytes();
273 break;
275 AS.swapBytes();
276 break;
277 default:
278 break;
279 }
280 }
281};
282
283static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
284 "Pipeline-specific PSV info must fit in 16 bytes.");
285
286namespace PSV {
287
288#define SEMANTIC_KIND(Val, Enum) Enum = Val,
289enum class SemanticKind : uint8_t {
290#include "DXContainerConstants.def"
291};
292
294
295#define COMPONENT_TYPE(Val, Enum) Enum = Val,
296enum class ComponentType : uint8_t {
297#include "DXContainerConstants.def"
298};
299
301
302#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
304#include "DXContainerConstants.def"
305};
306
308
309#define RESOURCE_TYPE(Val, Enum) Enum = Val,
310enum class ResourceType : uint32_t {
311#include "DXContainerConstants.def"
312};
313
315
316#define RESOURCE_KIND(Val, Enum) Enum = Val,
317enum class ResourceKind : uint32_t {
318#include "DXContainerConstants.def"
319};
320
322
323#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
326 struct FlagsBits {
327#include "llvm/BinaryFormat/DXContainerConstants.def"
328 };
329 union {
332 };
333 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
334};
335
336namespace v0 {
339 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
340 uint32_t MaximumWaveLaneCount; // maximum lane count required,
341 // 0xffffffff if unused
342 void swapBytes() {
343 // Skip the union because we don't know which field it has
346 }
347
349};
350
356
357 void swapBytes() {
362 }
363};
364
368
376
383
384 void swapBytes() {
387 }
388};
389
390static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
391 "PSV Signature elements must fit in 16 bytes.");
392
393} // namespace v0
394
395namespace v1 {
396
398 uint8_t SigPrimVectors; // Primitive output for MS
400};
401
403 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
404 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
405 // Primitive output for MS (overlaps
406 // MeshInfo::SigPrimVectors)
408};
410 uint8_t ShaderStage; // PSVShaderKind
413
414 // PSVSignatureElement counts
418
419 // Number of packed vectors per signature
422
423 void swapBytes() {
424 // nothing to swap since everything is single-byte or a union field
425 }
426
431 }
432};
433
434} // namespace v1
435
436namespace v2 {
441
442 void swapBytes() {
446 }
447
450 }
451};
452
456
457 void swapBytes() {
461 }
462};
463
464} // namespace v2
465
466namespace v3 {
469
470 void swapBytes() {
473 }
474
477 }
478};
479
480} // namespace v3
481} // namespace PSV
482
483#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
485#include "DXContainerConstants.def"
486};
487
489
490#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
492#include "DXContainerConstants.def"
493};
494
496
497#define COMPONENT_TYPE(Val, Enum) Enum = Val,
499#include "DXContainerConstants.def"
500};
501
503
507
508 void swapBytes() {
511 }
512};
513
515 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
516 // stream order)
517 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
518 // the start of the null terminated string for the name.
519 uint32_t Index; // Semantic Index
520 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
521 SigComponentType CompType; // Type of bits.
522 uint32_t Register; // Register Index (row index)
523 uint8_t Mask; // Mask (column allocation)
524
525 // The ExclusiveMask has a different meaning for input and output signatures.
526 // For an output signature, masked components of the output register are never
527 // written to.
528 // For an input signature, masked components of the input register are always
529 // read.
531
533 SigMinPrecision MinPrecision; // Minimum precision of input/output data
534
535 void swapBytes() {
545 }
546};
547
548static_assert(sizeof(ProgramSignatureElement) == 32,
549 "ProgramSignatureElement is misaligned");
550
552
554 if ((Flags & ~0x80000fff) != 0)
555 return llvm::make_error<BinaryStreamError>("Invalid Root Signature flag");
556 return Flags;
557 }
558
560 if (Version == 1 || Version == 2)
561 return Version;
562
563 return llvm::make_error<BinaryStreamError>(
564 "Invalid Root Signature Version");
565 }
566};
567
568} // namespace dxbc
569} // namespace llvm
570
571#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
Tagged union holding either a T or a Error.
Definition: Error.h:481
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:43
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:50
ContainerVersion Version
Definition: DXContainer.h:81
uint8_t Magic[4]
Definition: DXContainer.h:79
uint32_t PartCount
Definition: DXContainer.h:83
uint32_t TessellatorOutputPrimitive
Definition: DXContainer.h:177
uint32_t OutputControlPointCount
Definition: DXContainer.h:175
uint32_t InputControlPointCount
Definition: DXContainer.h:174
uint32_t GroupSharedBytesDependentOnViewID
Definition: DXContainer.h:225
bool operator==(const uint32_t RFlags) const
Definition: DXContainer.h:333
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:348
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:427
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:448
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:475
Use this type to describe the size and type of a DXIL container part.
Definition: DXContainer.h:95
StringRef getName() const
Definition: DXContainer.h:100
static uint8_t getVersion(uint8_t Major, uint8_t Minor)
Definition: DXContainer.h:137
static Expected< uint32_t > validateVersion(uint32_t Version)
Definition: DXContainer.h:559
static Expected< uint32_t > validateRootFlag(uint32_t Flags)
Definition: DXContainer.h:553
void swapBytes(Triple::EnvironmentType Stage)
Definition: DXContainer.h:254
AmplificationPSVInfo AS
Definition: DXContainer.h:252