1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===-- llvm/BinaryFormat/DXContainer.h - The DXBC file format --*- C++/-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines manifest constants for the DXContainer object file format.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_BINARYFORMAT_DXCONTAINER_H
#define LLVM_BINARYFORMAT_DXCONTAINER_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/SwapByteOrder.h"
#include <stdint.h>
namespace llvm {
// The DXContainer file format is arranged as a header and "parts". Semantically
// parts are similar to sections in other object file formats. The File format
// structure is roughly:
// ┌────────────────────────────────┐
// │ Header │
// ├────────────────────────────────┤
// │ Part │
// ├────────────────────────────────┤
// │ Part │
// ├────────────────────────────────┤
// │ ... │
// └────────────────────────────────┘
namespace dxbc {
struct Hash {
uint8_t Digest[16];
};
enum class HashFlags : uint32_t {
None = 0, // No flags defined.
IncludesSource = 1, // This flag indicates that the shader hash was computed
// taking into account source information (-Zss)
};
struct ShaderHash {
uint32_t Flags; // dxbc::HashFlags
uint8_t Digest[16];
bool isPopulated();
void swapBytes() { sys::swapByteOrder(Flags); }
};
struct ContainerVersion {
uint16_t Major;
uint16_t Minor;
void swapBytes() {
sys::swapByteOrder(Major);
sys::swapByteOrder(Minor);
}
};
struct Header {
uint8_t Magic[4]; // "DXBC"
Hash FileHash;
ContainerVersion Version;
uint32_t FileSize;
uint32_t PartCount;
void swapBytes() {
Version.swapBytes();
sys::swapByteOrder(FileSize);
sys::swapByteOrder(PartCount);
}
// Structure is followed by part offsets: uint32_t PartOffset[PartCount];
// The offset is to a PartHeader, which is followed by the Part Data.
};
/// Use this type to describe the size and type of a DXIL container part.
struct PartHeader {
uint8_t Name[4];
uint32_t Size;
void swapBytes() { sys::swapByteOrder(Size); }
StringRef getName() const {
return StringRef(reinterpret_cast<const char *>(&Name[0]), 4);
}
// Structure is followed directly by part data: uint8_t PartData[PartSize].
};
struct BitcodeHeader {
uint8_t Magic[4]; // ACSII "DXIL".
uint8_t MajorVersion; // DXIL version.
uint8_t MinorVersion; // DXIL version.
uint16_t Unused;
uint32_t Offset; // Offset to LLVM bitcode (from start of header).
uint32_t Size; // Size of LLVM bitcode (in bytes).
// Followed by uint8_t[BitcodeHeader.Size] at &BitcodeHeader + Header.Offset
void swapBytes() {
sys::swapByteOrder(MinorVersion);
sys::swapByteOrder(MajorVersion);
sys::swapByteOrder(Offset);
sys::swapByteOrder(Size);
}
};
struct ProgramHeader {
uint8_t MinorVersion : 4;
uint8_t MajorVersion : 4;
uint8_t Unused;
uint16_t ShaderKind;
uint32_t Size; // Size in uint32_t words including this header.
BitcodeHeader Bitcode;
void swapBytes() {
sys::swapByteOrder(ShaderKind);
sys::swapByteOrder(Size);
Bitcode.swapBytes();
}
};
static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!");
#define CONTAINER_PART(Part) Part,
enum class PartType {
Unknown = 0,
#include "DXContainerConstants.def"
};
#define SHADER_FLAG(Num, Val, Str) Val = 1ull << Num,
enum class FeatureFlags : uint64_t {
#include "DXContainerConstants.def"
};
static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
"Shader flag bits exceed enum size.");
PartType parsePartType(StringRef S);
} // namespace dxbc
} // namespace llvm
#endif // LLVM_BINARYFORMAT_DXCONTAINER_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|