1 //===- DXContainerYAML.cpp - DXContainer YAMLIO implementation ------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines classes for handling the YAML representation of
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ObjectYAML/DXContainerYAML.h"
15 #include "llvm/BinaryFormat/DXContainer.h"
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.
21 static_assert((uint64_t)dxbc::FeatureFlags::NextUnusedBit
<= 1ull << 63,
22 "Shader flag bits exceed enum size.");
24 DXContainerYAML::ShaderFlags::ShaderFlags(uint64_t FlagData
) {
25 #define SHADER_FLAG(Num, Val, Str) \
26 Val = (FlagData & (uint64_t)dxbc::FeatureFlags::Val) > 0;
27 #include "llvm/BinaryFormat/DXContainerConstants.def"
30 uint64_t DXContainerYAML::ShaderFlags::getEncodedFlags() {
32 #define SHADER_FLAG(Num, Val, Str) \
34 Flag |= (uint64_t)dxbc::FeatureFlags::Val;
35 #include "llvm/BinaryFormat/DXContainerConstants.def"
39 DXContainerYAML::ShaderHash::ShaderHash(const dxbc::ShaderHash
&Data
)
40 : IncludesSource((Data
.Flags
& static_cast<uint32_t>(
41 dxbc::HashFlags::IncludesSource
)) != 0),
43 memcpy(Digest
.data(), &Data
.Digest
[0], 16);
46 DXContainerYAML::PSVInfo::PSVInfo() : Version(0) {
47 memset(&Info
, 0, sizeof(Info
));
50 DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v0::RuntimeInfo
*P
,
53 memset(&Info
, 0, sizeof(Info
));
54 memcpy(&Info
, P
, sizeof(dxbc::PSV::v0::RuntimeInfo
));
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
60 Info
.ShaderStage
= static_cast<uint8_t>(Stage
);
63 DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v1::RuntimeInfo
*P
)
65 memset(&Info
, 0, sizeof(Info
));
66 memcpy(&Info
, P
, sizeof(dxbc::PSV::v1::RuntimeInfo
));
69 DXContainerYAML::PSVInfo::PSVInfo(const dxbc::PSV::v2::RuntimeInfo
*P
)
71 memset(&Info
, 0, sizeof(Info
));
72 memcpy(&Info
, P
, sizeof(dxbc::PSV::v2::RuntimeInfo
));
77 void MappingTraits
<DXContainerYAML::VersionTuple
>::mapping(
78 IO
&IO
, DXContainerYAML::VersionTuple
&Version
) {
79 IO
.mapRequired("Major", Version
.Major
);
80 IO
.mapRequired("Minor", Version
.Minor
);
83 void MappingTraits
<DXContainerYAML::FileHeader
>::mapping(
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
);
92 void MappingTraits
<DXContainerYAML::DXILProgram
>::mapping(
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
);
104 void MappingTraits
<DXContainerYAML::ShaderFlags
>::mapping(
105 IO
&IO
, DXContainerYAML::ShaderFlags
&Flags
) {
106 #define SHADER_FLAG(Num, Val, Str) IO.mapRequired(#Val, Flags.Val);
107 #include "llvm/BinaryFormat/DXContainerConstants.def"
110 void MappingTraits
<DXContainerYAML::ShaderHash
>::mapping(
111 IO
&IO
, DXContainerYAML::ShaderHash
&Hash
) {
112 IO
.mapRequired("IncludesSource", Hash
.IncludesSource
);
113 IO
.mapRequired("Digest", Hash
.Digest
);
116 void MappingTraits
<DXContainerYAML::PSVInfo
>::mapping(
117 IO
&IO
, DXContainerYAML::PSVInfo
&PSV
) {
118 IO
.mapRequired("Version", PSV
.Version
);
120 // Store the PSV version in the YAML context.
121 void *OldContext
= IO
.getContext();
122 uint32_t Version
= PSV
.Version
;
123 IO
.setContext(&Version
);
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
);
130 IO
.mapRequired("Resources", PSV
.Resources
);
132 // Restore the YAML context.
133 IO
.setContext(OldContext
);
136 void MappingTraits
<DXContainerYAML::Part
>::mapping(IO
&IO
,
137 DXContainerYAML::Part
&P
) {
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
);
146 void MappingTraits
<DXContainerYAML::Object
>::mapping(
147 IO
&IO
, DXContainerYAML::Object
&Obj
) {
148 IO
.mapTag("!dxcontainer", true);
149 IO
.mapRequired("Header", Obj
.Header
);
150 IO
.mapRequired("Parts", Obj
.Parts
);
153 void MappingTraits
<DXContainerYAML::ResourceBindInfo
>::mapping(
154 IO
&IO
, DXContainerYAML::ResourceBindInfo
&Res
) {
155 IO
.mapRequired("Type", Res
.Type
);
156 IO
.mapRequired("Space", Res
.Space
);
157 IO
.mapRequired("LowerBound", Res
.LowerBound
);
158 IO
.mapRequired("UpperBound", Res
.UpperBound
);
160 const uint32_t *PSVVersion
= static_cast<uint32_t *>(IO
.getContext());
164 IO
.mapRequired("Kind", Res
.Kind
);
165 IO
.mapRequired("Flags", Res
.Flags
);
170 void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO
&IO
) {
171 dxbc::PipelinePSVInfo
&StageInfo
= Info
.StageInfo
;
172 Triple::EnvironmentType Stage
= dxbc::getShaderStage(Info
.ShaderStage
);
175 case Triple::EnvironmentType::Pixel
:
176 IO
.mapRequired("DepthOutput", StageInfo
.PS
.DepthOutput
);
177 IO
.mapRequired("SampleFrequency", StageInfo
.PS
.SampleFrequency
);
179 case Triple::EnvironmentType::Vertex
:
180 IO
.mapRequired("OutputPositionPresent", StageInfo
.VS
.OutputPositionPresent
);
182 case Triple::EnvironmentType::Geometry
:
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
);
188 case Triple::EnvironmentType::Hull
:
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",
195 StageInfo
.HS
.TessellatorOutputPrimitive
);
197 case Triple::EnvironmentType::Domain
:
198 IO
.mapRequired("InputControlPointCount",
199 StageInfo
.DS
.InputControlPointCount
);
200 IO
.mapRequired("OutputPositionPresent", StageInfo
.DS
.OutputPositionPresent
);
201 IO
.mapRequired("TessellatorDomain", StageInfo
.DS
.TessellatorDomain
);
203 case Triple::EnvironmentType::Mesh
:
204 IO
.mapRequired("GroupSharedBytesUsed", StageInfo
.MS
.GroupSharedBytesUsed
);
205 IO
.mapRequired("GroupSharedBytesDependentOnViewID",
206 StageInfo
.MS
.GroupSharedBytesDependentOnViewID
);
207 IO
.mapRequired("PayloadSizeInBytes", StageInfo
.MS
.PayloadSizeInBytes
);
208 IO
.mapRequired("MaxOutputVertices", StageInfo
.MS
.MaxOutputVertices
);
209 IO
.mapRequired("MaxOutputPrimitives", StageInfo
.MS
.MaxOutputPrimitives
);
211 case Triple::EnvironmentType::Amplification
:
212 IO
.mapRequired("PayloadSizeInBytes", StageInfo
.AS
.PayloadSizeInBytes
);
218 IO
.mapRequired("MinimumWaveLaneCount", Info
.MinimumWaveLaneCount
);
219 IO
.mapRequired("MaximumWaveLaneCount", Info
.MaximumWaveLaneCount
);
224 IO
.mapRequired("UsesViewID", Info
.UsesViewID
);
227 case Triple::EnvironmentType::Geometry
:
228 IO
.mapRequired("MaxVertexCount", Info
.GeomData
.MaxVertexCount
);
230 case Triple::EnvironmentType::Hull
:
231 case Triple::EnvironmentType::Domain
:
232 IO
.mapRequired("SigPatchConstOrPrimVectors",
233 Info
.GeomData
.SigPatchConstOrPrimVectors
);
235 case Triple::EnvironmentType::Mesh
:
236 IO
.mapRequired("SigPrimVectors", Info
.GeomData
.MeshInfo
.SigPrimVectors
);
237 IO
.mapRequired("MeshOutputTopology",
238 Info
.GeomData
.MeshInfo
.MeshOutputTopology
);
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
);
255 IO
.mapRequired("NumThreadsX", Info
.NumThreadsX
);
256 IO
.mapRequired("NumThreadsY", Info
.NumThreadsY
);
257 IO
.mapRequired("NumThreadsZ", Info
.NumThreadsZ
);