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/BitmaskEnum.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Support/Error.h"
20 #include "llvm/Support/SwapByteOrder.h"
21 #include "llvm/TargetParser/Triple.h"
22
23 #include <stdint.h>
24
25 namespace llvm {
26 template <typename T> struct EnumEntry;
27
28 // The DXContainer file format is arranged as a header and "parts". Semantically
29 // parts are similar to sections in other object file formats. The File format
30 // structure is roughly:
31
32 // ┌────────────────────────────────┐
33 // │ Header │
34 // ├────────────────────────────────┤
35 // │ Part │
36 // ├────────────────────────────────┤
37 // │ Part │
38 // ├────────────────────────────────┤
39 // │ ... │
40 // └────────────────────────────────┘
41
42 namespace dxbc {
43
44 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
45
getShaderStage(uint32_t Kind)46 inline Triple::EnvironmentType getShaderStage(uint32_t Kind) {
47 assert(Kind <= Triple::Amplification - Triple::Pixel &&
48 "Shader kind out of expected range.");
49 return static_cast<Triple::EnvironmentType>(Triple::Pixel + Kind);
50 }
51
52 struct Hash {
53 uint8_t Digest[16];
54 };
55
56 enum class HashFlags : uint32_t {
57 None = 0, // No flags defined.
58 IncludesSource = 1, // This flag indicates that the shader hash was computed
59 // taking into account source information (-Zss)
60 };
61
62 struct ShaderHash {
63 uint32_t Flags; // dxbc::HashFlags
64 uint8_t Digest[16];
65
66 LLVM_ABI bool isPopulated();
67
swapBytesShaderHash68 void swapBytes() { sys::swapByteOrder(Flags); }
69 };
70
71 struct ContainerVersion {
72 uint16_t Major;
73 uint16_t Minor;
74
swapBytesContainerVersion75 void swapBytes() {
76 sys::swapByteOrder(Major);
77 sys::swapByteOrder(Minor);
78 }
79 };
80
81 struct Header {
82 uint8_t Magic[4]; // "DXBC"
83 Hash FileHash;
84 ContainerVersion Version;
85 uint32_t FileSize;
86 uint32_t PartCount;
87
swapBytesHeader88 void swapBytes() {
89 Version.swapBytes();
90 sys::swapByteOrder(FileSize);
91 sys::swapByteOrder(PartCount);
92 }
93 // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
94 // The offset is to a PartHeader, which is followed by the Part Data.
95 };
96
97 /// Use this type to describe the size and type of a DXIL container part.
98 struct PartHeader {
99 uint8_t Name[4];
100 uint32_t Size;
101
swapBytesPartHeader102 void swapBytes() { sys::swapByteOrder(Size); }
getNamePartHeader103 StringRef getName() const {
104 return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
105 }
106 // Structure is followed directly by part data: uint8_t PartData[PartSize].
107 };
108
109 struct BitcodeHeader {
110 uint8_t Magic[4]; // ACSII "DXIL".
111 uint8_t MinorVersion; // DXIL version.
112 uint8_t MajorVersion; // DXIL version.
113 uint16_t Unused;
114 uint32_t Offset; // Offset to LLVM bitcode (from start of header).
115 uint32_t Size; // Size of LLVM bitcode (in bytes).
116 // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
117
swapBytesBitcodeHeader118 void swapBytes() {
119 sys::swapByteOrder(MinorVersion);
120 sys::swapByteOrder(MajorVersion);
121 sys::swapByteOrder(Offset);
122 sys::swapByteOrder(Size);
123 }
124 };
125
126 struct ProgramHeader {
127 uint8_t Version;
128 uint8_t Unused;
129 uint16_t ShaderKind;
130 uint32_t Size; // Size in uint32_t words including this header.
131 BitcodeHeader Bitcode;
132
swapBytesProgramHeader133 void swapBytes() {
134 sys::swapByteOrder(ShaderKind);
135 sys::swapByteOrder(Size);
136 Bitcode.swapBytes();
137 }
getMajorVersionProgramHeader138 uint8_t getMajorVersion() { return Version >> 4; }
getMinorVersionProgramHeader139 uint8_t getMinorVersion() { return Version & 0xF; }
getVersionProgramHeader140 static uint8_t getVersion(uint8_t Major, uint8_t Minor) {
141 return (Major << 4) | Minor;
142 }
143 };
144
145 static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
146
147 #define CONTAINER_PART(Part) Part,
148 enum class PartType {
149 Unknown = 0,
150 #include "DXContainerConstants.def"
151 };
152
153 #define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) Val = 1ull << Num,
154 enum class FeatureFlags : uint64_t {
155 #include "DXContainerConstants.def"
156 };
157 static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
158 "Shader flag bits exceed enum size.");
159
160 #define ROOT_SIGNATURE_FLAG(Num, Val) Val = Num,
161 enum class RootFlags : uint32_t {
162 #include "DXContainerConstants.def"
163
164 LLVM_MARK_AS_BITMASK_ENUM(SamplerHeapDirectlyIndexed)
165 };
166
167 LLVM_ABI ArrayRef<EnumEntry<RootFlags>> getRootFlags();
168
169 #define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) Enum = Num,
170 enum class RootDescriptorFlags : uint32_t {
171 #include "DXContainerConstants.def"
172
173 LLVM_MARK_AS_BITMASK_ENUM(DataStatic)
174 };
175
176 LLVM_ABI ArrayRef<EnumEntry<RootDescriptorFlags>> getRootDescriptorFlags();
177
178 #define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) Enum = Num,
179 enum class DescriptorRangeFlags : uint32_t {
180 #include "DXContainerConstants.def"
181
182 LLVM_MARK_AS_BITMASK_ENUM(DescriptorsStaticKeepingBufferBoundsChecks)
183 };
184
185 LLVM_ABI ArrayRef<EnumEntry<DescriptorRangeFlags>> getDescriptorRangeFlags();
186
187 #define ROOT_PARAMETER(Val, Enum) Enum = Val,
188 enum class RootParameterType : uint32_t {
189 #include "DXContainerConstants.def"
190 };
191
192 LLVM_ABI ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();
193
194 #define DESCRIPTOR_RANGE(Val, Enum) Enum = Val,
195 enum class DescriptorRangeType : uint32_t {
196 #include "DXContainerConstants.def"
197 };
198
199 LLVM_ABI ArrayRef<EnumEntry<DescriptorRangeType>> getDescriptorRangeTypes();
200
201 #define ROOT_PARAMETER(Val, Enum) \
202 case Val: \
203 return true;
isValidParameterType(uint32_t V)204 inline bool isValidParameterType(uint32_t V) {
205 switch (V) {
206 #include "DXContainerConstants.def"
207 }
208 return false;
209 }
210
211 #define SHADER_VISIBILITY(Val, Enum) Enum = Val,
212 enum class ShaderVisibility : uint32_t {
213 #include "DXContainerConstants.def"
214 };
215
216 LLVM_ABI ArrayRef<EnumEntry<ShaderVisibility>> getShaderVisibility();
217
218 #define SHADER_VISIBILITY(Val, Enum) \
219 case Val: \
220 return true;
isValidShaderVisibility(uint32_t V)221 inline bool isValidShaderVisibility(uint32_t V) {
222 switch (V) {
223 #include "DXContainerConstants.def"
224 }
225 return false;
226 }
227
228 #define FILTER(Val, Enum) Enum = Val,
229 enum class SamplerFilter : uint32_t {
230 #include "DXContainerConstants.def"
231 };
232
233 LLVM_ABI ArrayRef<EnumEntry<SamplerFilter>> getSamplerFilters();
234
235 #define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
236 enum class TextureAddressMode : uint32_t {
237 #include "DXContainerConstants.def"
238 };
239
240 LLVM_ABI ArrayRef<EnumEntry<TextureAddressMode>> getTextureAddressModes();
241
242 #define COMPARISON_FUNC(Val, Enum) Enum = Val,
243 enum class ComparisonFunc : uint32_t {
244 #include "DXContainerConstants.def"
245 };
246
247 LLVM_ABI ArrayRef<EnumEntry<ComparisonFunc>> getComparisonFuncs();
248
249 #define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
250 enum class StaticBorderColor : uint32_t {
251 #include "DXContainerConstants.def"
252 };
253
254 LLVM_ABI ArrayRef<EnumEntry<StaticBorderColor>> getStaticBorderColors();
255
256 LLVM_ABI PartType parsePartType(StringRef S);
257
258 struct VertexPSVInfo {
259 uint8_t OutputPositionPresent;
260 uint8_t Unused[3];
261
swapBytesVertexPSVInfo262 void swapBytes() {
263 // nothing to swap
264 }
265 };
266
267 struct HullPSVInfo {
268 uint32_t InputControlPointCount;
269 uint32_t OutputControlPointCount;
270 uint32_t TessellatorDomain;
271 uint32_t TessellatorOutputPrimitive;
272
swapBytesHullPSVInfo273 void swapBytes() {
274 sys::swapByteOrder(InputControlPointCount);
275 sys::swapByteOrder(OutputControlPointCount);
276 sys::swapByteOrder(TessellatorDomain);
277 sys::swapByteOrder(TessellatorOutputPrimitive);
278 }
279 };
280
281 struct DomainPSVInfo {
282 uint32_t InputControlPointCount;
283 uint8_t OutputPositionPresent;
284 uint8_t Unused[3];
285 uint32_t TessellatorDomain;
286
swapBytesDomainPSVInfo287 void swapBytes() {
288 sys::swapByteOrder(InputControlPointCount);
289 sys::swapByteOrder(TessellatorDomain);
290 }
291 };
292
293 struct GeometryPSVInfo {
294 uint32_t InputPrimitive;
295 uint32_t OutputTopology;
296 uint32_t OutputStreamMask;
297 uint8_t OutputPositionPresent;
298 uint8_t Unused[3];
299
swapBytesGeometryPSVInfo300 void swapBytes() {
301 sys::swapByteOrder(InputPrimitive);
302 sys::swapByteOrder(OutputTopology);
303 sys::swapByteOrder(OutputStreamMask);
304 }
305 };
306
307 struct PixelPSVInfo {
308 uint8_t DepthOutput;
309 uint8_t SampleFrequency;
310 uint8_t Unused[2];
311
swapBytesPixelPSVInfo312 void swapBytes() {
313 // nothing to swap
314 }
315 };
316
317 struct MeshPSVInfo {
318 uint32_t GroupSharedBytesUsed;
319 uint32_t GroupSharedBytesDependentOnViewID;
320 uint32_t PayloadSizeInBytes;
321 uint16_t MaxOutputVertices;
322 uint16_t MaxOutputPrimitives;
323
swapBytesMeshPSVInfo324 void swapBytes() {
325 sys::swapByteOrder(GroupSharedBytesUsed);
326 sys::swapByteOrder(GroupSharedBytesDependentOnViewID);
327 sys::swapByteOrder(PayloadSizeInBytes);
328 sys::swapByteOrder(MaxOutputVertices);
329 sys::swapByteOrder(MaxOutputPrimitives);
330 }
331 };
332
333 struct AmplificationPSVInfo {
334 uint32_t PayloadSizeInBytes;
335
swapBytesAmplificationPSVInfo336 void swapBytes() { sys::swapByteOrder(PayloadSizeInBytes); }
337 };
338
339 union PipelinePSVInfo {
340 VertexPSVInfo VS;
341 HullPSVInfo HS;
342 DomainPSVInfo DS;
343 GeometryPSVInfo GS;
344 PixelPSVInfo PS;
345 MeshPSVInfo MS;
346 AmplificationPSVInfo AS;
347
swapBytes(Triple::EnvironmentType Stage)348 void swapBytes(Triple::EnvironmentType Stage) {
349 switch (Stage) {
350 case Triple::EnvironmentType::Pixel:
351 PS.swapBytes();
352 break;
353 case Triple::EnvironmentType::Vertex:
354 VS.swapBytes();
355 break;
356 case Triple::EnvironmentType::Geometry:
357 GS.swapBytes();
358 break;
359 case Triple::EnvironmentType::Hull:
360 HS.swapBytes();
361 break;
362 case Triple::EnvironmentType::Domain:
363 DS.swapBytes();
364 break;
365 case Triple::EnvironmentType::Mesh:
366 MS.swapBytes();
367 break;
368 case Triple::EnvironmentType::Amplification:
369 AS.swapBytes();
370 break;
371 default:
372 break;
373 }
374 }
375 };
376
377 static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),
378 "Pipeline-specific PSV info must fit in 16 bytes.");
379
380 namespace PSV {
381
382 #define SEMANTIC_KIND(Val, Enum) Enum = Val,
383 enum class SemanticKind : uint8_t {
384 #include "DXContainerConstants.def"
385 };
386
387 LLVM_ABI ArrayRef<EnumEntry<SemanticKind>> getSemanticKinds();
388
389 #define COMPONENT_TYPE(Val, Enum) Enum = Val,
390 enum class ComponentType : uint8_t {
391 #include "DXContainerConstants.def"
392 };
393
394 LLVM_ABI ArrayRef<EnumEntry<ComponentType>> getComponentTypes();
395
396 #define INTERPOLATION_MODE(Val, Enum) Enum = Val,
397 enum class InterpolationMode : uint8_t {
398 #include "DXContainerConstants.def"
399 };
400
401 LLVM_ABI ArrayRef<EnumEntry<InterpolationMode>> getInterpolationModes();
402
403 #define RESOURCE_TYPE(Val, Enum) Enum = Val,
404 enum class ResourceType : uint32_t {
405 #include "DXContainerConstants.def"
406 };
407
408 LLVM_ABI ArrayRef<EnumEntry<ResourceType>> getResourceTypes();
409
410 #define RESOURCE_KIND(Val, Enum) Enum = Val,
411 enum class ResourceKind : uint32_t {
412 #include "DXContainerConstants.def"
413 };
414
415 LLVM_ABI ArrayRef<EnumEntry<ResourceKind>> getResourceKinds();
416
417 #define RESOURCE_FLAG(Index, Enum) bool Enum = false;
418 struct ResourceFlags {
ResourceFlagsResourceFlags419 ResourceFlags() : Flags(0U) {};
420 struct FlagsBits {
421 #include "llvm/BinaryFormat/DXContainerConstants.def"
422 };
423 union {
424 uint32_t Flags;
425 FlagsBits Bits;
426 };
427 bool operator==(const uint32_t RFlags) const { return Flags == RFlags; }
428 };
429
430 namespace v0 {
431 struct RuntimeInfo {
432 PipelinePSVInfo StageInfo;
433 uint32_t MinimumWaveLaneCount; // minimum lane count required, 0 if unused
434 uint32_t MaximumWaveLaneCount; // maximum lane count required,
435 // 0xffffffff if unused
swapBytesRuntimeInfo436 void swapBytes() {
437 // Skip the union because we don't know which field it has
438 sys::swapByteOrder(MinimumWaveLaneCount);
439 sys::swapByteOrder(MaximumWaveLaneCount);
440 }
441
swapBytesRuntimeInfo442 void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); }
443 };
444
445 struct ResourceBindInfo {
446 ResourceType Type;
447 uint32_t Space;
448 uint32_t LowerBound;
449 uint32_t UpperBound;
450
swapBytesResourceBindInfo451 void swapBytes() {
452 sys::swapByteOrder(Type);
453 sys::swapByteOrder(Space);
454 sys::swapByteOrder(LowerBound);
455 sys::swapByteOrder(UpperBound);
456 }
457 };
458
459 struct SignatureElement {
460 uint32_t NameOffset;
461 uint32_t IndicesOffset;
462
463 uint8_t Rows;
464 uint8_t StartRow;
465 uint8_t Cols : 4;
466 uint8_t StartCol : 2;
467 uint8_t Allocated : 1;
468 uint8_t Unused : 1;
469 SemanticKind Kind;
470
471 ComponentType Type;
472 InterpolationMode Mode;
473 uint8_t DynamicMask : 4;
474 uint8_t Stream : 2;
475 uint8_t Unused2 : 2;
476 uint8_t Reserved;
477
swapBytesSignatureElement478 void swapBytes() {
479 sys::swapByteOrder(NameOffset);
480 sys::swapByteOrder(IndicesOffset);
481 }
482 };
483
484 static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
485 "PSV Signature elements must fit in 16 bytes.");
486
487 } // namespace v0
488
489 namespace v1 {
490
491 struct MeshRuntimeInfo {
492 uint8_t SigPrimVectors; // Primitive output for MS
493 uint8_t MeshOutputTopology;
494 };
495
496 union GeometryExtraInfo {
497 uint16_t MaxVertexCount; // MaxVertexCount for GS only (max 1024)
498 uint8_t SigPatchConstOrPrimVectors; // Output for HS; Input for DS;
499 // Primitive output for MS (overlaps
500 // MeshInfo::SigPrimVectors)
501 MeshRuntimeInfo MeshInfo;
502 };
503 struct RuntimeInfo : public v0::RuntimeInfo {
504 uint8_t ShaderStage; // PSVShaderKind
505 uint8_t UsesViewID;
506 GeometryExtraInfo GeomData;
507
508 // PSVSignatureElement counts
509 uint8_t SigInputElements;
510 uint8_t SigOutputElements;
511 uint8_t SigPatchOrPrimElements;
512
513 // Number of packed vectors per signature
514 uint8_t SigInputVectors;
515 uint8_t SigOutputVectors[4];
516
swapBytesRuntimeInfo517 void swapBytes() {
518 // nothing to swap since everything is single-byte or a union field
519 }
520
swapBytesRuntimeInfo521 void swapBytes(Triple::EnvironmentType Stage) {
522 v0::RuntimeInfo::swapBytes(Stage);
523 if (Stage == Triple::EnvironmentType::Geometry)
524 sys::swapByteOrder(GeomData.MaxVertexCount);
525 }
526 };
527
528 } // namespace v1
529
530 namespace v2 {
531 struct RuntimeInfo : public v1::RuntimeInfo {
532 uint32_t NumThreadsX;
533 uint32_t NumThreadsY;
534 uint32_t NumThreadsZ;
535
swapBytesRuntimeInfo536 void swapBytes() {
537 sys::swapByteOrder(NumThreadsX);
538 sys::swapByteOrder(NumThreadsY);
539 sys::swapByteOrder(NumThreadsZ);
540 }
541
swapBytesRuntimeInfo542 void swapBytes(Triple::EnvironmentType Stage) {
543 v1::RuntimeInfo::swapBytes(Stage);
544 }
545 };
546
547 struct ResourceBindInfo : public v0::ResourceBindInfo {
548 ResourceKind Kind;
549 ResourceFlags Flags;
550
swapBytesResourceBindInfo551 void swapBytes() {
552 v0::ResourceBindInfo::swapBytes();
553 sys::swapByteOrder(Kind);
554 sys::swapByteOrder(Flags.Flags);
555 }
556 };
557
558 } // namespace v2
559
560 namespace v3 {
561 struct RuntimeInfo : public v2::RuntimeInfo {
562 uint32_t EntryNameOffset;
563
swapBytesRuntimeInfo564 void swapBytes() {
565 v2::RuntimeInfo::swapBytes();
566 sys::swapByteOrder(EntryNameOffset);
567 }
568
swapBytesRuntimeInfo569 void swapBytes(Triple::EnvironmentType Stage) {
570 v2::RuntimeInfo::swapBytes(Stage);
571 }
572 };
573
574 } // namespace v3
575 } // namespace PSV
576
577 #define COMPONENT_PRECISION(Val, Enum) Enum = Val,
578 enum class SigMinPrecision : uint32_t {
579 #include "DXContainerConstants.def"
580 };
581
582 LLVM_ABI ArrayRef<EnumEntry<SigMinPrecision>> getSigMinPrecisions();
583
584 #define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
585 enum class D3DSystemValue : uint32_t {
586 #include "DXContainerConstants.def"
587 };
588
589 LLVM_ABI ArrayRef<EnumEntry<D3DSystemValue>> getD3DSystemValues();
590
591 #define COMPONENT_TYPE(Val, Enum) Enum = Val,
592 enum class SigComponentType : uint32_t {
593 #include "DXContainerConstants.def"
594 };
595
596 LLVM_ABI ArrayRef<EnumEntry<SigComponentType>> getSigComponentTypes();
597
598 struct ProgramSignatureHeader {
599 uint32_t ParamCount;
600 uint32_t FirstParamOffset;
601
swapBytesProgramSignatureHeader602 void swapBytes() {
603 sys::swapByteOrder(ParamCount);
604 sys::swapByteOrder(FirstParamOffset);
605 }
606 };
607
608 struct ProgramSignatureElement {
609 uint32_t Stream; // Stream index (parameters must appear in non-decreasing
610 // stream order)
611 uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
612 // the start of the null terminated string for the name.
613 uint32_t Index; // Semantic Index
614 D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
615 SigComponentType CompType; // Type of bits.
616 uint32_t Register; // Register Index (row index)
617 uint8_t Mask; // Mask (column allocation)
618
619 // The ExclusiveMask has a different meaning for input and output signatures.
620 // For an output signature, masked components of the output register are never
621 // written to.
622 // For an input signature, masked components of the input register are always
623 // read.
624 uint8_t ExclusiveMask;
625
626 uint16_t Unused;
627 SigMinPrecision MinPrecision; // Minimum precision of input/output data
628
swapBytesProgramSignatureElement629 void swapBytes() {
630 sys::swapByteOrder(Stream);
631 sys::swapByteOrder(NameOffset);
632 sys::swapByteOrder(Index);
633 sys::swapByteOrder(SystemValue);
634 sys::swapByteOrder(CompType);
635 sys::swapByteOrder(Register);
636 sys::swapByteOrder(Mask);
637 sys::swapByteOrder(ExclusiveMask);
638 sys::swapByteOrder(MinPrecision);
639 }
640 };
641
642 static_assert(sizeof(ProgramSignatureElement) == 32,
643 "ProgramSignatureElement is misaligned");
644
645 namespace RTS0 {
646 namespace v1 {
647 struct StaticSampler {
648 uint32_t Filter;
649 uint32_t AddressU;
650 uint32_t AddressV;
651 uint32_t AddressW;
652 float MipLODBias;
653 uint32_t MaxAnisotropy;
654 uint32_t ComparisonFunc;
655 uint32_t BorderColor;
656 float MinLOD;
657 float MaxLOD;
658 uint32_t ShaderRegister;
659 uint32_t RegisterSpace;
660 uint32_t ShaderVisibility;
swapBytesStaticSampler661 void swapBytes() {
662 sys::swapByteOrder(Filter);
663 sys::swapByteOrder(AddressU);
664 sys::swapByteOrder(AddressV);
665 sys::swapByteOrder(AddressW);
666 sys::swapByteOrder(MipLODBias);
667 sys::swapByteOrder(MaxAnisotropy);
668 sys::swapByteOrder(ComparisonFunc);
669 sys::swapByteOrder(BorderColor);
670 sys::swapByteOrder(MinLOD);
671 sys::swapByteOrder(MaxLOD);
672 sys::swapByteOrder(ShaderRegister);
673 sys::swapByteOrder(RegisterSpace);
674 sys::swapByteOrder(ShaderVisibility);
675 };
676 };
677
678 struct DescriptorRange {
679 uint32_t RangeType;
680 uint32_t NumDescriptors;
681 uint32_t BaseShaderRegister;
682 uint32_t RegisterSpace;
683 uint32_t OffsetInDescriptorsFromTableStart;
swapBytesDescriptorRange684 void swapBytes() {
685 sys::swapByteOrder(RangeType);
686 sys::swapByteOrder(NumDescriptors);
687 sys::swapByteOrder(BaseShaderRegister);
688 sys::swapByteOrder(RegisterSpace);
689 sys::swapByteOrder(OffsetInDescriptorsFromTableStart);
690 }
691 };
692
693 struct RootDescriptor {
694 uint32_t ShaderRegister;
695 uint32_t RegisterSpace;
swapBytesRootDescriptor696 void swapBytes() {
697 sys::swapByteOrder(ShaderRegister);
698 sys::swapByteOrder(RegisterSpace);
699 }
700 };
701
702 // following dx12 naming
703 // https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
704 struct RootConstants {
705 uint32_t ShaderRegister;
706 uint32_t RegisterSpace;
707 uint32_t Num32BitValues;
708
swapBytesRootConstants709 void swapBytes() {
710 sys::swapByteOrder(ShaderRegister);
711 sys::swapByteOrder(RegisterSpace);
712 sys::swapByteOrder(Num32BitValues);
713 }
714 };
715
716 struct RootParameterHeader {
717 uint32_t ParameterType;
718 uint32_t ShaderVisibility;
719 uint32_t ParameterOffset;
720
swapBytesRootParameterHeader721 void swapBytes() {
722 sys::swapByteOrder(ParameterType);
723 sys::swapByteOrder(ShaderVisibility);
724 sys::swapByteOrder(ParameterOffset);
725 }
726 };
727
728 struct RootSignatureHeader {
729 uint32_t Version;
730 uint32_t NumParameters;
731 uint32_t ParametersOffset;
732 uint32_t NumStaticSamplers;
733 uint32_t StaticSamplerOffset;
734 uint32_t Flags;
735
swapBytesRootSignatureHeader736 void swapBytes() {
737 sys::swapByteOrder(Version);
738 sys::swapByteOrder(NumParameters);
739 sys::swapByteOrder(ParametersOffset);
740 sys::swapByteOrder(NumStaticSamplers);
741 sys::swapByteOrder(StaticSamplerOffset);
742 sys::swapByteOrder(Flags);
743 }
744 };
745 } // namespace v1
746
747 namespace v2 {
748 struct RootDescriptor : public v1::RootDescriptor {
749 uint32_t Flags;
750
751 RootDescriptor() = default;
RootDescriptorRootDescriptor752 explicit RootDescriptor(v1::RootDescriptor &Base)
753 : v1::RootDescriptor(Base), Flags(0u) {}
754
swapBytesRootDescriptor755 void swapBytes() {
756 v1::RootDescriptor::swapBytes();
757 sys::swapByteOrder(Flags);
758 }
759 };
760
761 struct DescriptorRange {
762 uint32_t RangeType;
763 uint32_t NumDescriptors;
764 uint32_t BaseShaderRegister;
765 uint32_t RegisterSpace;
766 uint32_t Flags;
767 uint32_t OffsetInDescriptorsFromTableStart;
swapBytesDescriptorRange768 void swapBytes() {
769 sys::swapByteOrder(RangeType);
770 sys::swapByteOrder(NumDescriptors);
771 sys::swapByteOrder(BaseShaderRegister);
772 sys::swapByteOrder(RegisterSpace);
773 sys::swapByteOrder(OffsetInDescriptorsFromTableStart);
774 sys::swapByteOrder(Flags);
775 }
776 };
777 } // namespace v2
778 } // namespace RTS0
779
780 // D3D_ROOT_SIGNATURE_VERSION
781 enum class RootSignatureVersion {
782 V1_0 = 0x1,
783 V1_1 = 0x2,
784 };
785
786 } // namespace dxbc
787 } // namespace llvm
788
789 #endif // LLVM_BINARYFORMAT_DXCONTAINER_H
790