LLVM  15.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; // DxilShaderHashFlags
51  uint8_t Digest[16];
52 
54 };
55 
59 
60  void swapBytes() {
63  }
64 };
65 
66 struct Header {
67  uint8_t Magic[4]; // "DXBC"
72 
73  void swapBytes() {
77  }
78  // Structure is followed by part offsets: uint32_t PartOffset[PartCount];
79  // The offset is to a PartHeader, which is followed by the Part Data.
80 };
81 
82 /// Use this type to describe the size and type of a DXIL container part.
83 struct PartHeader {
84  uint8_t Name[4];
86 
88  StringRef getName() const {
89  return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
90  }
91  // Structure is followed directly by part data: uint8_t PartData[PartSize].
92 };
93 
94 struct BitcodeHeader {
95  uint8_t Magic[4]; // ACSII "DXIL".
96  uint8_t MajorVersion; // DXIL version.
97  uint8_t MinorVersion; // DXIL version.
99  uint32_t Offset; // Offset to LLVM bitcode (from start of header).
100  uint32_t Size; // Size of LLVM bitcode (in bytes).
101  // Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
102 
103  void swapBytes() {
108  }
109 };
110 
112  uint8_t MinorVersion : 4;
113  uint8_t MajorVersion : 4;
114  uint8_t Unused;
116  uint32_t Size; // Size in uint32_t words including this header.
118 
119  void swapBytes() {
122  Bitcode.swapBytes();
123  }
124 };
125 
126 static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
127 
128 } // namespace dxbc
129 } // namespace llvm
130 
131 #endif // LLVM_BINARYFORMAT_DXCONTAINER_H
llvm::dxbc::ProgramHeader::Unused
uint8_t Unused
Definition: DXContainer.h:114
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::dxbc::ContainerVersion
Definition: DXContainer.h:56
llvm::dxbc::PartHeader::Name
uint8_t Name[4]
Definition: DXContainer.h:84
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:116
llvm::dxbc::Header::Version
ContainerVersion Version
Definition: DXContainer.h:69
llvm::dxbc::PartHeader::swapBytes
void swapBytes()
Definition: DXContainer.h:87
SwapByteOrder.h
llvm::dxbc::Header::Magic
uint8_t Magic[4]
Definition: DXContainer.h:67
llvm::dxbc::Header::FileSize
uint32_t FileSize
Definition: DXContainer.h:70
llvm::dxbc::BitcodeHeader::Magic
uint8_t Magic[4]
Definition: DXContainer.h:95
llvm::dxbc::PartHeader::Size
uint32_t Size
Definition: DXContainer.h:85
llvm::dxbc::ContainerVersion::Minor
uint16_t Minor
Definition: DXContainer.h:58
llvm::dxbc::PartHeader
Use this type to describe the size and type of a DXIL container part.
Definition: DXContainer.h:83
llvm::dxbc::ShaderHash::swapBytes
void swapBytes()
Definition: DXContainer.h:53
llvm::dxbc::ShaderHash::Flags
uint32_t Flags
Definition: DXContainer.h:50
llvm::dxbc::Header::PartCount
uint32_t PartCount
Definition: DXContainer.h:71
llvm::dxbc::Header::swapBytes
void swapBytes()
Definition: DXContainer.h:73
llvm::dxbc::ContainerVersion::swapBytes
void swapBytes()
Definition: DXContainer.h:60
llvm::dxbc::Hash
Definition: DXContainer.h:39
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::dxbc::ContainerVersion::Major
uint16_t Major
Definition: DXContainer.h:57
llvm::dxbc::HashFlags::IncludesSource
@ IncludesSource
uint32_t
llvm::dxbc::ProgramHeader::swapBytes
void swapBytes()
Definition: DXContainer.h:119
llvm::dxbc::ProgramHeader::MinorVersion
uint8_t MinorVersion
Definition: DXContainer.h:112
llvm::dxbc::ProgramHeader::MajorVersion
uint8_t MajorVersion
Definition: DXContainer.h:113
llvm::dxbc::BitcodeHeader::Size
uint32_t Size
Definition: DXContainer.h:100
llvm::dxbc::BitcodeHeader
Definition: DXContainer.h:94
uint16_t
llvm::dxbc::HashFlags::None
@ None
llvm::dxbc::ProgramHeader::ShaderKind
uint16_t ShaderKind
Definition: DXContainer.h:115
llvm::dxbc::BitcodeHeader::Offset
uint32_t Offset
Definition: DXContainer.h:99
llvm::dxbc::BitcodeHeader::swapBytes
void swapBytes()
Definition: DXContainer.h:103
llvm::dxbc::BitcodeHeader::Unused
uint16_t Unused
Definition: DXContainer.h:98
llvm::dxbc::BitcodeHeader::MinorVersion
uint8_t MinorVersion
Definition: DXContainer.h:97
llvm::dxbc::ProgramHeader::Bitcode
BitcodeHeader Bitcode
Definition: DXContainer.h:117
llvm::dxbc::ShaderHash::Digest
uint8_t Digest[16]
Definition: DXContainer.h:51
llvm::dxbc::Header
Definition: DXContainer.h:66
llvm::dxbc::ShaderHash
Definition: DXContainer.h:49
llvm::dxbc::PartHeader::getName
StringRef getName() const
Definition: DXContainer.h:88
llvm::dxbc::ProgramHeader
Definition: DXContainer.h:111
llvm::dxbc::Header::FileHash
Hash FileHash
Definition: DXContainer.h:68
llvm::dxbc::BitcodeHeader::MajorVersion
uint8_t MajorVersion
Definition: DXContainer.h:96