LLVM  16.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 
19 #include <stdint.h>
20 
21 namespace llvm {
22 
23 // The DXContainer file format is arranged as a header and "parts". Semantically
24 // parts are similar to sections in other object file formats. The File format
25 // structure is roughly:
26 
27 // ┌────────────────────────────────┐
28 // │ Header │
29 // ├────────────────────────────────┤
30 // │ Part │
31 // ├────────────────────────────────┤
32 // │ Part │
33 // ├────────────────────────────────┤
34 // │ ... │
35 // └────────────────────────────────┘
36 
37 namespace dxbc {
38 
39 struct Hash {
40  uint8_t Digest[16];
41 };
42 
43 enum class HashFlags : uint32_t {
44  None = 0, // No flags defined.
45  IncludesSource = 1, // This flag indicates that the shader hash was computed
46  // taking into account source information (-Zss)
47 };
48 
49 struct ShaderHash {
50  uint32_t Flags; // dxbc::HashFlags
51  uint8_t Digest[16];
52 
53  bool isPopulated();
54 
56 };
57 
61 
62  void swapBytes() {
65  }
66 };
67 
68 struct Header {
69  uint8_t Magic[4]; // "DXBC"
74 
75  void swapBytes() {
79  }
80  // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
81  // The offset is to a PartHeader, which is followed by the Part Data.
82 };
83 
84 /// Use this type to describe the size and type of a DXIL container part.
85 struct PartHeader {
86  uint8_t Name[4];
88 
90  StringRef getName() const {
91  return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
92  }
93  // Structure is followed directly by part data: uint8_t PartData[PartSize].
94 };
95 
96 struct BitcodeHeader {
97  uint8_t Magic[4]; // ACSII "DXIL".
98  uint8_t MajorVersion; // DXIL version.
99  uint8_t MinorVersion; // DXIL version.
101  uint32_t Offset; // Offset to LLVM bitcode (from start of header).
102  uint32_t Size; // Size of LLVM bitcode (in bytes).
103  // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
104 
105  void swapBytes() {
110  }
111 };
112 
114  uint8_t MinorVersion : 4;
115  uint8_t MajorVersion : 4;
116  uint8_t Unused;
118  uint32_t Size; // Size in uint32_t words including this header.
120 
121  void swapBytes() {
124  Bitcode.swapBytes();
125  }
126 };
127 
128 static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
129 
130 #define CONTAINER_PART(Part) Part,
131 enum class PartType {
132  Unknown = 0,
133 #include "DXContainerConstants.def"
134 };
135 
136 #define SHADER_FLAG(Num, Val, Str) Val = 1ull << Num,
137 enum class FeatureFlags : uint64_t {
138 #include "DXContainerConstants.def"
139 };
140 static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
141  "Shader flag bits exceed enum size.");
142 
144 
145 } // namespace dxbc
146 } // namespace llvm
147 
148 #endif // LLVM_BINARYFORMAT_DXCONTAINER_H
llvm::dxbc::ProgramHeader::Unused
uint8_t Unused
Definition: DXContainer.h:116
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::dxbc::ContainerVersion
Definition: DXContainer.h:58
llvm::dxbc::PartHeader::Name
uint8_t Name[4]
Definition: DXContainer.h:86
llvm::dxbc::Hash::Digest
uint8_t Digest[16]
Definition: DXContainer.h:40
llvm::sys::swapByteOrder
void swapByteOrder(T &Value)
Definition: SwapByteOrder.h:158
StringRef.h
llvm::dxbc::HashFlags
HashFlags
Definition: DXContainer.h:43
llvm::dxbc::ProgramHeader::Size
uint32_t Size
Definition: DXContainer.h:118
llvm::dxbc::Header::Version
ContainerVersion Version
Definition: DXContainer.h:71
llvm::dxbc::PartHeader::swapBytes
void swapBytes()
Definition: DXContainer.h:89
llvm::dxbc::PartType::Unknown
@ Unknown
SwapByteOrder.h
llvm::dxbc::Header::Magic
uint8_t Magic[4]
Definition: DXContainer.h:69
llvm::dxbc::Header::FileSize
uint32_t FileSize
Definition: DXContainer.h:72
llvm::dxbc::PartType
PartType
Definition: DXContainer.h:131
llvm::dxbc::BitcodeHeader::Magic
uint8_t Magic[4]
Definition: DXContainer.h:97
llvm::dxbc::PartHeader::Size
uint32_t Size
Definition: DXContainer.h:87
llvm::dxbc::ContainerVersion::Minor
uint16_t Minor
Definition: DXContainer.h:60
llvm::dxbc::PartHeader
Use this type to describe the size and type of a DXIL container part.
Definition: DXContainer.h:85
llvm::dxbc::ShaderHash::swapBytes
void swapBytes()
Definition: DXContainer.h:55
llvm::dxbc::ShaderHash::isPopulated
bool isPopulated()
Definition: DXContainer.cpp:27
llvm::dxbc::ShaderHash::Flags
uint32_t Flags
Definition: DXContainer.h:50
llvm::dxbc::Header::PartCount
uint32_t PartCount
Definition: DXContainer.h:73
llvm::dxbc::Header::swapBytes
void swapBytes()
Definition: DXContainer.h:75
llvm::dxbc::parsePartType
PartType parsePartType(StringRef S)
Definition: DXContainer.cpp:20
uint64_t
llvm::dxbc::FeatureFlags
FeatureFlags
Definition: DXContainer.h:137
llvm::dxbc::ContainerVersion::swapBytes
void swapBytes()
Definition: DXContainer.h:62
llvm::dxbc::Hash
Definition: DXContainer.h:39
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::dxbc::ContainerVersion::Major
uint16_t Major
Definition: DXContainer.h:59
llvm::dxbc::HashFlags::IncludesSource
@ IncludesSource
uint32_t
llvm::dxbc::ProgramHeader::swapBytes
void swapBytes()
Definition: DXContainer.h:121
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::dxbc::ProgramHeader::MinorVersion
uint8_t MinorVersion
Definition: DXContainer.h:114
llvm::dxbc::ProgramHeader::MajorVersion
uint8_t MajorVersion
Definition: DXContainer.h:115
llvm::dxbc::BitcodeHeader::Size
uint32_t Size
Definition: DXContainer.h:102
llvm::dxbc::BitcodeHeader
Definition: DXContainer.h:96
uint16_t
llvm::dxbc::HashFlags::None
@ None
llvm::dxbc::ProgramHeader::ShaderKind
uint16_t ShaderKind
Definition: DXContainer.h:117
llvm::dxbc::BitcodeHeader::Offset
uint32_t Offset
Definition: DXContainer.h:101
llvm::dxbc::BitcodeHeader::swapBytes
void swapBytes()
Definition: DXContainer.h:105
llvm::dxbc::BitcodeHeader::Unused
uint16_t Unused
Definition: DXContainer.h:100
llvm::dxbc::BitcodeHeader::MinorVersion
uint8_t MinorVersion
Definition: DXContainer.h:99
llvm::dxbc::ProgramHeader::Bitcode
BitcodeHeader Bitcode
Definition: DXContainer.h:119
llvm::dxbc::ShaderHash::Digest
uint8_t Digest[16]
Definition: DXContainer.h:51
llvm::dxbc::Header
Definition: DXContainer.h:68
llvm::dxbc::ShaderHash
Definition: DXContainer.h:49
llvm::dxbc::PartHeader::getName
StringRef getName() const
Definition: DXContainer.h:90
llvm::dxbc::ProgramHeader
Definition: DXContainer.h:113
llvm::dxbc::Header::FileHash
Hash FileHash
Definition: DXContainer.h:70
llvm::dxbc::BitcodeHeader::MajorVersion
uint8_t MajorVersion
Definition: DXContainer.h:98