LLVM 18.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
15#include "llvm/ADT/ScopeExit.h"
18
19namespace llvm {
20
21// This assert is duplicated here to leave a breadcrumb of the places that need
22// to be updated if flags grow past 64-bits.
23static_assert((uint64_t)dxbc::FeatureFlags::NextUnusedBit <= 1ull << 63,
24 "Shader flag bits exceed enum size.");
25
27#define SHADER_FLAG(Num, Val, Str) \
28 Val = (FlagData & (uint64_t)dxbc::FeatureFlags::Val) > 0;
29#include "llvm/BinaryFormat/DXContainerConstants.def"
30}
31
33 uint64_t Flag = 0;
34#define SHADER_FLAG(Num, Val, Str) \
35 if (Val) \
36 Flag |= (uint64_t)dxbc::FeatureFlags::Val;
37#include "llvm/BinaryFormat/DXContainerConstants.def"
38 return Flag;
39}
40
42 : IncludesSource((Data.Flags & static_cast<uint32_t>(
43 dxbc::HashFlags::IncludesSource)) != 0),
44 Digest(16, 0) {
45 memcpy(Digest.data(), &Data.Digest[0], 16);
46}
47
49 memset(&Info, 0, sizeof(Info));
50}
51
53 uint16_t Stage)
54 : Version(0) {
55 memset(&Info, 0, sizeof(Info));
56 memcpy(&Info, P, sizeof(dxbc::PSV::v0::RuntimeInfo));
57
58 assert(Stage < std::numeric_limits<uint8_t>::max() &&
59 "Stage should be a very small number");
60 // We need to bring the stage in separately since it isn't part of the v1 data
61 // structure.
62 Info.ShaderStage = static_cast<uint8_t>(Stage);
63}
64
66 : Version(1) {
67 memset(&Info, 0, sizeof(Info));
68 memcpy(&Info, P, sizeof(dxbc::PSV::v1::RuntimeInfo));
69}
70
72 : Version(2) {
73 memset(&Info, 0, sizeof(Info));
74 memcpy(&Info, P, sizeof(dxbc::PSV::v2::RuntimeInfo));
75}
76
77namespace yaml {
78
80 IO &IO, DXContainerYAML::VersionTuple &Version) {
81 IO.mapRequired("Major", Version.Major);
82 IO.mapRequired("Minor", Version.Minor);
83}
84
86 IO &IO, DXContainerYAML::FileHeader &Header) {
87 IO.mapRequired("Hash", Header.Hash);
88 IO.mapRequired("Version", Header.Version);
89 IO.mapOptional("FileSize", Header.FileSize);
90 IO.mapRequired("PartCount", Header.PartCount);
91 IO.mapOptional("PartOffsets", Header.PartOffsets);
92}
93
95 IO &IO, DXContainerYAML::DXILProgram &Program) {
96 IO.mapRequired("MajorVersion", Program.MajorVersion);
97 IO.mapRequired("MinorVersion", Program.MinorVersion);
98 IO.mapRequired("ShaderKind", Program.ShaderKind);
99 IO.mapOptional("Size", Program.Size);
100 IO.mapRequired("DXILMajorVersion", Program.DXILMajorVersion);
101 IO.mapRequired("DXILMinorVersion", Program.DXILMinorVersion);
102 IO.mapOptional("DXILSize", Program.DXILSize);
103 IO.mapOptional("DXIL", Program.DXIL);
104}
105
107 IO &IO, DXContainerYAML::ShaderFlags &Flags) {
108#define SHADER_FLAG(Num, Val, Str) IO.mapRequired(#Val, Flags.Val);
109#include "llvm/BinaryFormat/DXContainerConstants.def"
110}
111
113 IO &IO, DXContainerYAML::ShaderHash &Hash) {
114 IO.mapRequired("IncludesSource", Hash.IncludesSource);
115 IO.mapRequired("Digest", Hash.Digest);
116}
117
119 IO &IO, DXContainerYAML::PSVInfo &PSV) {
120 IO.mapRequired("Version", PSV.Version);
121
122 // Store the PSV version in the YAML context.
123 void *OldContext = IO.getContext();
124 uint32_t Version = PSV.Version;
125 IO.setContext(&Version);
126
127 // Restore the YAML context on function exit.
128 auto RestoreContext = make_scope_exit([&]() { IO.setContext(OldContext); });
129
130 // Shader stage is only included in binaries for v1 and later, but we always
131 // include it since it simplifies parsing and file construction.
132 IO.mapRequired("ShaderStage", PSV.Info.ShaderStage);
133 PSV.mapInfoForVersion(IO);
134
135 IO.mapRequired("ResourceStride", PSV.ResourceStride);
136 IO.mapRequired("Resources", PSV.Resources);
137 if (PSV.Version == 0)
138 return;
139 IO.mapRequired("SigInputElements", PSV.SigInputElements);
140 IO.mapRequired("SigOutputElements", PSV.SigOutputElements);
141 IO.mapRequired("SigPatchOrPrimElements", PSV.SigPatchOrPrimElements);
142
143 Triple::EnvironmentType Stage = dxbc::getShaderStage(PSV.Info.ShaderStage);
144 if (PSV.Info.UsesViewID) {
147 IO.mapRequired("OutputVectorMasks", MutableOutMasks);
148 if (Stage == Triple::EnvironmentType::Hull)
149 IO.mapRequired("PatchOrPrimMasks", PSV.PatchOrPrimMasks);
150 }
152 PSV.InputOutputMap);
153 IO.mapRequired("InputOutputMap", MutableIOMap);
154
155 if (Stage == Triple::EnvironmentType::Hull)
156 IO.mapRequired("InputPatchMap", PSV.InputPatchMap);
157
158 if (Stage == Triple::EnvironmentType::Domain)
159 IO.mapRequired("PatchOutputMap", PSV.PatchOutputMap);
160}
161
164 IO.mapRequired("Name", P.Name);
165 IO.mapRequired("Size", P.Size);
166 IO.mapOptional("Program", P.Program);
167 IO.mapOptional("Flags", P.Flags);
168 IO.mapOptional("Hash", P.Hash);
169 IO.mapOptional("PSVInfo", P.Info);
170}
171
173 IO &IO, DXContainerYAML::Object &Obj) {
174 IO.mapTag("!dxcontainer", true);
175 IO.mapRequired("Header", Obj.Header);
176 IO.mapRequired("Parts", Obj.Parts);
177}
178
181 IO.mapRequired("Type", Res.Type);
182 IO.mapRequired("Space", Res.Space);
183 IO.mapRequired("LowerBound", Res.LowerBound);
184 IO.mapRequired("UpperBound", Res.UpperBound);
185
186 const uint32_t *PSVVersion = static_cast<uint32_t *>(IO.getContext());
187 if (*PSVVersion < 2)
188 return;
189
190 IO.mapRequired("Kind", Res.Kind);
191 IO.mapRequired("Flags", Res.Flags);
192}
193
196 IO.mapRequired("Name", El.Name);
197 IO.mapRequired("Indices", El.Indices);
198 IO.mapRequired("StartRow", El.StartRow);
199 IO.mapRequired("Cols", El.Cols);
200 IO.mapRequired("StartCol", El.StartCol);
201 IO.mapRequired("Allocated", El.Allocated);
202 IO.mapRequired("Kind", El.Kind);
203 IO.mapRequired("ComponentType", El.Type);
204 IO.mapRequired("Interpolation", El.Mode);
205 IO.mapRequired("DynamicMask", El.DynamicMask);
206 IO.mapRequired("Stream", El.Stream);
207}
208
209void ScalarEnumerationTraits<dxbc::PSV::SemanticKind>::enumeration(
211 for (const auto &E : dxbc::PSV::getSemanticKinds())
212 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
213}
214
215void ScalarEnumerationTraits<dxbc::PSV::ComponentType>::enumeration(
217 for (const auto &E : dxbc::PSV::getComponentTypes())
218 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
219}
220
221void ScalarEnumerationTraits<dxbc::PSV::InterpolationMode>::enumeration(
222 IO &IO, dxbc::PSV::InterpolationMode &Value) {
223 for (const auto &E : dxbc::PSV::getInterpolationModes())
224 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
225}
226
227} // namespace yaml
228
230 dxbc::PipelinePSVInfo &StageInfo = Info.StageInfo;
232
233 switch (Stage) {
235 IO.mapRequired("DepthOutput", StageInfo.PS.DepthOutput);
236 IO.mapRequired("SampleFrequency", StageInfo.PS.SampleFrequency);
237 break;
239 IO.mapRequired("OutputPositionPresent", StageInfo.VS.OutputPositionPresent);
240 break;
242 IO.mapRequired("InputPrimitive", StageInfo.GS.InputPrimitive);
243 IO.mapRequired("OutputTopology", StageInfo.GS.OutputTopology);
244 IO.mapRequired("OutputStreamMask", StageInfo.GS.OutputStreamMask);
245 IO.mapRequired("OutputPositionPresent", StageInfo.GS.OutputPositionPresent);
246 break;
248 IO.mapRequired("InputControlPointCount",
249 StageInfo.HS.InputControlPointCount);
250 IO.mapRequired("OutputControlPointCount",
251 StageInfo.HS.OutputControlPointCount);
252 IO.mapRequired("TessellatorDomain", StageInfo.HS.TessellatorDomain);
253 IO.mapRequired("TessellatorOutputPrimitive",
255 break;
257 IO.mapRequired("InputControlPointCount",
258 StageInfo.DS.InputControlPointCount);
259 IO.mapRequired("OutputPositionPresent", StageInfo.DS.OutputPositionPresent);
260 IO.mapRequired("TessellatorDomain", StageInfo.DS.TessellatorDomain);
261 break;
263 IO.mapRequired("GroupSharedBytesUsed", StageInfo.MS.GroupSharedBytesUsed);
264 IO.mapRequired("GroupSharedBytesDependentOnViewID",
266 IO.mapRequired("PayloadSizeInBytes", StageInfo.MS.PayloadSizeInBytes);
267 IO.mapRequired("MaxOutputVertices", StageInfo.MS.MaxOutputVertices);
268 IO.mapRequired("MaxOutputPrimitives", StageInfo.MS.MaxOutputPrimitives);
269 break;
271 IO.mapRequired("PayloadSizeInBytes", StageInfo.AS.PayloadSizeInBytes);
272 break;
273 default:
274 break;
275 }
276
277 IO.mapRequired("MinimumWaveLaneCount", Info.MinimumWaveLaneCount);
278 IO.mapRequired("MaximumWaveLaneCount", Info.MaximumWaveLaneCount);
279
280 if (Version == 0)
281 return;
282
283 IO.mapRequired("UsesViewID", Info.UsesViewID);
284
285 switch (Stage) {
287 IO.mapRequired("MaxVertexCount", Info.GeomData.MaxVertexCount);
288 break;
291 IO.mapRequired("SigPatchConstOrPrimVectors",
292 Info.GeomData.SigPatchConstOrPrimVectors);
293 break;
295 IO.mapRequired("SigPrimVectors", Info.GeomData.MeshInfo.SigPrimVectors);
296 IO.mapRequired("MeshOutputTopology",
297 Info.GeomData.MeshInfo.MeshOutputTopology);
298 break;
299 default:
300 break;
301 }
302
303 IO.mapRequired("SigInputVectors", Info.SigInputVectors);
304 MutableArrayRef<uint8_t> Vec(Info.SigOutputVectors);
305 IO.mapRequired("SigOutputVectors", Vec);
306
307 if (Version == 1)
308 return;
309
310 IO.mapRequired("NumThreadsX", Info.NumThreadsX);
311 IO.mapRequired("NumThreadsY", Info.NumThreadsY);
312 IO.mapRequired("NumThreadsZ", Info.NumThreadsZ);
313}
314
315} // namespace llvm
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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())
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
@ Amplification
Definition: Triple.h:273
LLVM Value Representation.
Definition: Value.h:74
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition: DXContainer.h:41
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
Definition: ScopeExit.h:59
std::optional< uint32_t > Size
std::optional< std::vector< llvm::yaml::Hex8 > > DXIL
std::optional< uint32_t > DXILSize
std::array< MaskVector, 4 > InputOutputMap
SmallVector< SignatureElement > SigOutputElements
dxbc::PSV::v2::RuntimeInfo Info
SmallVector< SignatureElement > SigPatchOrPrimElements
SmallVector< ResourceBindInfo > Resources
SmallVector< SignatureElement > SigInputElements
void mapInfoForVersion(yaml::IO &IO)
std::array< MaskVector, 4 > OutputVectorMasks
std::vector< llvm::yaml::Hex8 > Digest
dxbc::PSV::InterpolationMode Mode
uint32_t TessellatorOutputPrimitive
Definition: DXContainer.h:166
uint32_t OutputControlPointCount
Definition: DXContainer.h:164
uint32_t InputControlPointCount
Definition: DXContainer.h:163
uint32_t GroupSharedBytesDependentOnViewID
Definition: DXContainer.h:214
AmplificationPSVInfo AS
Definition: DXContainer.h:241