LLVM 19.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_FEATURE_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_FEATURE_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
108#define SHADER_FEATURE_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("Stream", S.Stream);
165 IO.mapRequired("Name", S.Name);
166 IO.mapRequired("Index", S.Index);
167 IO.mapRequired("SystemValue", S.SystemValue);
168 IO.mapRequired("CompType", S.CompType);
169 IO.mapRequired("Register", S.Register);
170 IO.mapRequired("Mask", S.Mask);
171 IO.mapRequired("ExclusiveMask", S.ExclusiveMask);
172 IO.mapRequired("MinPrecision", S.MinPrecision);
173}
174
176 IO &IO, DXContainerYAML::Signature &S) {
177 IO.mapRequired("Parameters", S.Parameters);
178}
179
182 IO.mapRequired("Name", P.Name);
183 IO.mapRequired("Size", P.Size);
184 IO.mapOptional("Program", P.Program);
185 IO.mapOptional("Flags", P.Flags);
186 IO.mapOptional("Hash", P.Hash);
187 IO.mapOptional("PSVInfo", P.Info);
188 IO.mapOptional("Signature", P.Signature);
189}
190
192 IO &IO, DXContainerYAML::Object &Obj) {
193 IO.mapTag("!dxcontainer", true);
194 IO.mapRequired("Header", Obj.Header);
195 IO.mapRequired("Parts", Obj.Parts);
196}
197
200 IO.mapRequired("Type", Res.Type);
201 IO.mapRequired("Space", Res.Space);
202 IO.mapRequired("LowerBound", Res.LowerBound);
203 IO.mapRequired("UpperBound", Res.UpperBound);
204
205 const uint32_t *PSVVersion = static_cast<uint32_t *>(IO.getContext());
206 if (*PSVVersion < 2)
207 return;
208
209 IO.mapRequired("Kind", Res.Kind);
210 IO.mapRequired("Flags", Res.Flags);
211}
212
215 IO.mapRequired("Name", El.Name);
216 IO.mapRequired("Indices", El.Indices);
217 IO.mapRequired("StartRow", El.StartRow);
218 IO.mapRequired("Cols", El.Cols);
219 IO.mapRequired("StartCol", El.StartCol);
220 IO.mapRequired("Allocated", El.Allocated);
221 IO.mapRequired("Kind", El.Kind);
222 IO.mapRequired("ComponentType", El.Type);
223 IO.mapRequired("Interpolation", El.Mode);
224 IO.mapRequired("DynamicMask", El.DynamicMask);
225 IO.mapRequired("Stream", El.Stream);
226}
227
228void ScalarEnumerationTraits<dxbc::PSV::SemanticKind>::enumeration(
230 for (const auto &E : dxbc::PSV::getSemanticKinds())
231 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
232}
233
234void ScalarEnumerationTraits<dxbc::PSV::ComponentType>::enumeration(
236 for (const auto &E : dxbc::PSV::getComponentTypes())
237 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
238}
239
240void ScalarEnumerationTraits<dxbc::PSV::InterpolationMode>::enumeration(
241 IO &IO, dxbc::PSV::InterpolationMode &Value) {
242 for (const auto &E : dxbc::PSV::getInterpolationModes())
243 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
244}
245
246void ScalarEnumerationTraits<dxbc::D3DSystemValue>::enumeration(
247 IO &IO, dxbc::D3DSystemValue &Value) {
248 for (const auto &E : dxbc::getD3DSystemValues())
249 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
250}
251
252void ScalarEnumerationTraits<dxbc::SigMinPrecision>::enumeration(
253 IO &IO, dxbc::SigMinPrecision &Value) {
254 for (const auto &E : dxbc::getSigMinPrecisions())
255 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
256}
257
258void ScalarEnumerationTraits<dxbc::SigComponentType>::enumeration(
259 IO &IO, dxbc::SigComponentType &Value) {
260 for (const auto &E : dxbc::getSigComponentTypes())
261 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
262}
263
264} // namespace yaml
265
267 dxbc::PipelinePSVInfo &StageInfo = Info.StageInfo;
269
270 switch (Stage) {
272 IO.mapRequired("DepthOutput", StageInfo.PS.DepthOutput);
273 IO.mapRequired("SampleFrequency", StageInfo.PS.SampleFrequency);
274 break;
276 IO.mapRequired("OutputPositionPresent", StageInfo.VS.OutputPositionPresent);
277 break;
279 IO.mapRequired("InputPrimitive", StageInfo.GS.InputPrimitive);
280 IO.mapRequired("OutputTopology", StageInfo.GS.OutputTopology);
281 IO.mapRequired("OutputStreamMask", StageInfo.GS.OutputStreamMask);
282 IO.mapRequired("OutputPositionPresent", StageInfo.GS.OutputPositionPresent);
283 break;
285 IO.mapRequired("InputControlPointCount",
286 StageInfo.HS.InputControlPointCount);
287 IO.mapRequired("OutputControlPointCount",
288 StageInfo.HS.OutputControlPointCount);
289 IO.mapRequired("TessellatorDomain", StageInfo.HS.TessellatorDomain);
290 IO.mapRequired("TessellatorOutputPrimitive",
292 break;
294 IO.mapRequired("InputControlPointCount",
295 StageInfo.DS.InputControlPointCount);
296 IO.mapRequired("OutputPositionPresent", StageInfo.DS.OutputPositionPresent);
297 IO.mapRequired("TessellatorDomain", StageInfo.DS.TessellatorDomain);
298 break;
300 IO.mapRequired("GroupSharedBytesUsed", StageInfo.MS.GroupSharedBytesUsed);
301 IO.mapRequired("GroupSharedBytesDependentOnViewID",
303 IO.mapRequired("PayloadSizeInBytes", StageInfo.MS.PayloadSizeInBytes);
304 IO.mapRequired("MaxOutputVertices", StageInfo.MS.MaxOutputVertices);
305 IO.mapRequired("MaxOutputPrimitives", StageInfo.MS.MaxOutputPrimitives);
306 break;
308 IO.mapRequired("PayloadSizeInBytes", StageInfo.AS.PayloadSizeInBytes);
309 break;
310 default:
311 break;
312 }
313
314 IO.mapRequired("MinimumWaveLaneCount", Info.MinimumWaveLaneCount);
315 IO.mapRequired("MaximumWaveLaneCount", Info.MaximumWaveLaneCount);
316
317 if (Version == 0)
318 return;
319
320 IO.mapRequired("UsesViewID", Info.UsesViewID);
321
322 switch (Stage) {
324 IO.mapRequired("MaxVertexCount", Info.GeomData.MaxVertexCount);
325 break;
328 IO.mapRequired("SigPatchConstOrPrimVectors",
329 Info.GeomData.SigPatchConstOrPrimVectors);
330 break;
332 IO.mapRequired("SigPrimVectors", Info.GeomData.MeshInfo.SigPrimVectors);
333 IO.mapRequired("MeshOutputTopology",
334 Info.GeomData.MeshInfo.MeshOutputTopology);
335 break;
336 default:
337 break;
338 }
339
340 IO.mapRequired("SigInputVectors", Info.SigInputVectors);
341 MutableArrayRef<uint8_t> Vec(Info.SigOutputVectors);
342 IO.mapRequired("SigOutputVectors", Vec);
343
344 if (Version == 1)
345 return;
346
347 IO.mapRequired("NumThreadsX", Info.NumThreadsX);
348 IO.mapRequired("NumThreadsY", Info.NumThreadsY);
349 IO.mapRequired("NumThreadsZ", Info.NumThreadsZ);
350}
351
352} // 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:279
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
llvm::SmallVector< SignatureParameter > Parameters
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