LLVM 17.0.0git
DXContainerYAML.cpp
Go to the documentation of this file.
1//===- DXContainerYAML.cpp - DXContainer YAMLIO implementation ------------===//
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 classes for handling the YAML representation of
10// DXContainerYAML.
11//
12//===----------------------------------------------------------------------===//
13
16
17namespace llvm {
18
19// This assert is duplicated here to leave a breadcrumb of the places that need
20// to be updated if flags grow past 64-bits.
21static_assert((uint64_t)dxbc::FeatureFlags::NextUnusedBit <= 1ull << 63,
22 "Shader flag bits exceed enum size.");
23
25#define SHADER_FLAG(Num, Val, Str) \
26 Val = (FlagData & (uint64_t)dxbc::FeatureFlags::Val) > 0;
27#include "llvm/BinaryFormat/DXContainerConstants.def"
28}
29
31 uint64_t Flag = 0;
32#define SHADER_FLAG(Num, Val, Str) \
33 if (Val) \
34 Flag |= (uint64_t)dxbc::FeatureFlags::Val;
35#include "llvm/BinaryFormat/DXContainerConstants.def"
36 return Flag;
37}
38
40 : IncludesSource((Data.Flags & static_cast<uint32_t>(
41 dxbc::HashFlags::IncludesSource)) != 0),
42 Digest(16, 0) {
43 memcpy(Digest.data(), &Data.Digest[0], 16);
44}
45
47 memset(&Info, 0, sizeof(Info));
48}
49
51 uint16_t Stage)
52 : Version(0) {
53 memset(&Info, 0, sizeof(Info));
54 memcpy(&Info, P, sizeof(dxbc::PSV::v0::RuntimeInfo));
55
56 assert(Stage < std::numeric_limits<uint8_t>::max() &&
57 "Stage should be a very small number");
58 // We need to bring the stage in separately since it isn't part of the v1 data
59 // structure.
60 Info.ShaderStage = static_cast<uint8_t>(Stage);
61}
62
64 : Version(1) {
65 memset(&Info, 0, sizeof(Info));
66 memcpy(&Info, P, sizeof(dxbc::PSV::v1::RuntimeInfo));
67}
68
70 : Version(2) {
71 memset(&Info, 0, sizeof(Info));
72 memcpy(&Info, P, sizeof(dxbc::PSV::v2::RuntimeInfo));
73}
74
75namespace yaml {
76
78 IO &IO, DXContainerYAML::VersionTuple &Version) {
79 IO.mapRequired("Major", Version.Major);
80 IO.mapRequired("Minor", Version.Minor);
81}
82
84 IO &IO, DXContainerYAML::FileHeader &Header) {
85 IO.mapRequired("Hash", Header.Hash);
86 IO.mapRequired("Version", Header.Version);
87 IO.mapOptional("FileSize", Header.FileSize);
88 IO.mapRequired("PartCount", Header.PartCount);
89 IO.mapOptional("PartOffsets", Header.PartOffsets);
90}
91
93 IO &IO, DXContainerYAML::DXILProgram &Program) {
94 IO.mapRequired("MajorVersion", Program.MajorVersion);
95 IO.mapRequired("MinorVersion", Program.MinorVersion);
96 IO.mapRequired("ShaderKind", Program.ShaderKind);
97 IO.mapOptional("Size", Program.Size);
98 IO.mapRequired("DXILMajorVersion", Program.DXILMajorVersion);
99 IO.mapRequired("DXILMinorVersion", Program.DXILMinorVersion);
100 IO.mapOptional("DXILSize", Program.DXILSize);
101 IO.mapOptional("DXIL", Program.DXIL);
102}
103
106#define SHADER_FLAG(Num, Val, Str) IO.mapRequired(#Val, Flags.Val);
107#include "llvm/BinaryFormat/DXContainerConstants.def"
108}
109
111 IO &IO, DXContainerYAML::ShaderHash &Hash) {
112 IO.mapRequired("IncludesSource", Hash.IncludesSource);
113 IO.mapRequired("Digest", Hash.Digest);
114}
115
117 IO &IO, DXContainerYAML::PSVInfo &PSV) {
118 IO.mapRequired("Version", PSV.Version);
119
120 // Store the PSV version in the YAML context.
121 void *OldContext = IO.getContext();
122 uint32_t Version = PSV.Version;
123 IO.setContext(&Version);
124
125 // Shader stage is only included in binaries for v1 and later, but we always
126 // include it since it simplifies parsing and file construction.
127 IO.mapRequired("ShaderStage", PSV.Info.ShaderStage);
128 PSV.mapInfoForVersion(IO);
129
130 IO.mapRequired("Resources", PSV.Resources);
131
132 // Restore the YAML context.
133 IO.setContext(OldContext);
134}
135
138 IO.mapRequired("Name", P.Name);
139 IO.mapRequired("Size", P.Size);
140 IO.mapOptional("Program", P.Program);
141 IO.mapOptional("Flags", P.Flags);
142 IO.mapOptional("Hash", P.Hash);
143 IO.mapOptional("PSVInfo", P.Info);
144}
145
147 IO &IO, DXContainerYAML::Object &Obj) {
148 IO.mapTag("!dxcontainer", true);
149 IO.mapRequired("Header", Obj.Header);
150 IO.mapRequired("Parts", Obj.Parts);
151}
152
155 IO.mapRequired("Type", Res.Type);
156 IO.mapRequired("Space", Res.Space);
157 IO.mapRequired("LowerBound", Res.LowerBound);
158 IO.mapRequired("UpperBound", Res.UpperBound);
159
160 const uint32_t *PSVVersion = static_cast<uint32_t *>(IO.getContext());
161 if (*PSVVersion < 2)
162 return;
163
164 IO.mapRequired("Kind", Res.Kind);
165 IO.mapRequired("Flags", Res.Flags);
166}
167
168} // namespace yaml
169
171 dxbc::PipelinePSVInfo &StageInfo = Info.StageInfo;
173
174 switch (Stage) {
176 IO.mapRequired("DepthOutput", StageInfo.PS.DepthOutput);
177 IO.mapRequired("SampleFrequency", StageInfo.PS.SampleFrequency);
178 break;
180 IO.mapRequired("OutputPositionPresent", StageInfo.VS.OutputPositionPresent);
181 break;
183 IO.mapRequired("InputPrimitive", StageInfo.GS.InputPrimitive);
184 IO.mapRequired("OutputTopology", StageInfo.GS.OutputTopology);
185 IO.mapRequired("OutputStreamMask", StageInfo.GS.OutputStreamMask);
186 IO.mapRequired("OutputPositionPresent", StageInfo.GS.OutputPositionPresent);
187 break;
189 IO.mapRequired("InputControlPointCount",
190 StageInfo.HS.InputControlPointCount);
191 IO.mapRequired("OutputControlPointCount",
192 StageInfo.HS.OutputControlPointCount);
193 IO.mapRequired("TessellatorDomain", StageInfo.HS.TessellatorDomain);
194 IO.mapRequired("TessellatorOutputPrimitive",
196 break;
198 IO.mapRequired("InputControlPointCount",
199 StageInfo.DS.InputControlPointCount);
200 IO.mapRequired("OutputPositionPresent", StageInfo.DS.OutputPositionPresent);
201 IO.mapRequired("TessellatorDomain", StageInfo.DS.TessellatorDomain);
202 break;
204 IO.mapRequired("GroupSharedBytesUsed", StageInfo.MS.GroupSharedBytesUsed);
205 IO.mapRequired("GroupSharedBytesDependentOnViewID",
207 IO.mapRequired("PayloadSizeInBytes", StageInfo.MS.PayloadSizeInBytes);
208 IO.mapRequired("MaxOutputVertices", StageInfo.MS.MaxOutputVertices);
209 IO.mapRequired("MaxOutputPrimitives", StageInfo.MS.MaxOutputPrimitives);
210 break;
212 IO.mapRequired("PayloadSizeInBytes", StageInfo.AS.PayloadSizeInBytes);
213 break;
214 default:
215 break;
216 }
217
218 IO.mapRequired("MinimumWaveLaneCount", Info.MinimumWaveLaneCount);
219 IO.mapRequired("MaximumWaveLaneCount", Info.MaximumWaveLaneCount);
220
221 if (Version == 0)
222 return;
223
224 IO.mapRequired("UsesViewID", Info.UsesViewID);
225
226 switch (Stage) {
228 IO.mapRequired("MaxVertexCount", Info.GeomData.MaxVertexCount);
229 break;
232 IO.mapRequired("SigPatchConstOrPrimVectors",
233 Info.GeomData.SigPatchConstOrPrimVectors);
234 break;
236 IO.mapRequired("SigPrimVectors", Info.GeomData.MeshInfo.SigPrimVectors);
237 IO.mapRequired("MeshOutputTopology",
238 Info.GeomData.MeshInfo.MeshOutputTopology);
239 break;
240 default:
241 break;
242 }
243
244 IO.mapRequired("SigInputElements", Info.SigInputElements);
245 IO.mapRequired("SigOutputElements", Info.SigOutputElements);
246 IO.mapRequired("SigPatchConstOrPrimElements",
247 Info.SigPatchConstOrPrimElements);
248 IO.mapRequired("SigInputVectors", Info.SigInputVectors);
249 MutableArrayRef<uint8_t> Vec(Info.SigOutputVectors);
250 IO.mapRequired("SigOutputVectors", Vec);
251
252 if (Version == 1)
253 return;
254
255 IO.mapRequired("NumThreadsX", Info.NumThreadsX);
256 IO.mapRequired("NumThreadsY", Info.NumThreadsY);
257 IO.mapRequired("NumThreadsZ", Info.NumThreadsZ);
258}
259
260} // namespace llvm
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file declares classes for handling the YAML representation of DXContainer.
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
@ Flags
Definition: TextStubV5.cpp:93
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:305
@ Amplification
Definition: Triple.h:276
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition: DXContainer.h:40
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::optional< uint32_t > Size
std::optional< std::vector< llvm::yaml::Hex8 > > DXIL
std::optional< uint32_t > DXILSize
std::vector< ResourceBindInfo > Resources
dxbc::PSV::v2::RuntimeInfo Info
void mapInfoForVersion(yaml::IO &IO)
std::vector< llvm::yaml::Hex8 > Digest
uint32_t TessellatorOutputPrimitive
Definition: DXContainer.h:165
uint32_t OutputControlPointCount
Definition: DXContainer.h:163
uint32_t InputControlPointCount
Definition: DXContainer.h:162
uint32_t GroupSharedBytesDependentOnViewID
Definition: DXContainer.h:213
AmplificationPSVInfo AS
Definition: DXContainer.h:240