25class DXContainerWriter {
35 Error computePartOffsets();
36 Error validatePartOffsets();
47 else if (*
ObjectFile.Header.FileSize < Computed)
49 "File size specified is too small.");
53Error DXContainerWriter::validatePartOffsets() {
56 errc::invalid_argument,
57 "Mismatch between number of parts and part offsets.");
61 if (RollingOffset > std::get<1>(
I))
63 "Offset mismatch, not enough space for data.");
67 if (
Error Err = validateSize(RollingOffset))
73Error DXContainerWriter::computePartOffsets() {
75 return validatePartOffsets();
78 ObjectFile.Header.PartOffsets = std::vector<uint32_t>();
80 ObjectFile.Header.PartOffsets->push_back(RollingOffset);
83 if (
Error Err = validateSize(RollingOffset))
91 memcpy(Header.Magic,
"DXBC", 4);
92 memcpy(Header.FileHash.Digest,
ObjectFile.Header.Hash.data(), 16);
93 Header.Version.Major =
ObjectFile.Header.Version.Major;
94 Header.Version.Minor =
ObjectFile.Header.Version.Minor;
99 OS.
write(
reinterpret_cast<char *
>(&Header),
sizeof(Header));
103 for (
auto &O : Offsets)
113 if (RollingOffset < std::get<1>(
I)) {
114 uint32_t PadBytes = std::get<1>(
I) - RollingOffset;
130 case dxbc::PartType::DXIL: {
135 P.Program->MinorVersion);
137 Header.ShaderKind =
P.Program->ShaderKind;
138 memcpy(Header.Bitcode.Magic,
"DXIL", 4);
139 Header.Bitcode.MajorVersion =
P.Program->DXILMajorVersion;
140 Header.Bitcode.MinorVersion =
P.Program->DXILMinorVersion;
141 Header.Bitcode.Unused = 0;
144 if (
P.Program->DXILOffset)
145 Header.Bitcode.Offset = *
P.Program->DXILOffset;
149 if (
P.Program->DXILSize)
150 Header.Bitcode.Size = *
P.Program->DXILSize;
152 Header.Bitcode.Size =
P.Program->DXIL ?
P.Program->DXIL->size() : 0;
155 Header.Size = *
P.Program->Size;
159 uint32_t BitcodeOffset = Header.Bitcode.Offset;
162 OS.
write(
reinterpret_cast<const char *
>(&Header),
164 if (
P.Program->DXIL) {
169 OS.
write(
reinterpret_cast<char *
>(
P.Program->DXIL->data()),
170 P.Program->DXIL->size());
174 case dxbc::PartType::SFI0: {
177 if (!
P.Flags.has_value())
185 case dxbc::PartType::HASH: {
186 if (!
P.Hash.has_value())
189 if (
P.Hash->IncludesSource)
190 Hash.
Flags |=
static_cast<uint32_t>(dxbc::HashFlags::IncludesSource);
191 memcpy(&Hash.
Digest[0], &
P.Hash->Digest[0], 16);
197 case dxbc::PartType::PSV0: {
198 if (!
P.Info.has_value())
205 for (
auto El :
P.Info->SigInputElements)
207 El.
Name, El.Indices, El.StartRow, El.Cols, El.StartCol,
208 El.Allocated, El.Kind, El.Type, El.Mode, El.DynamicMask,
211 for (
auto El :
P.Info->SigOutputElements)
213 El.
Name, El.Indices, El.StartRow, El.Cols, El.StartCol,
214 El.Allocated, El.Kind, El.Type, El.Mode, El.DynamicMask,
217 for (
auto El :
P.Info->SigPatchOrPrimElements)
219 El.
Name, El.Indices, El.StartRow, El.Cols, El.StartCol,
220 El.Allocated, El.Kind, El.Type, El.Mode, El.DynamicMask,
226 P.Info->OutputVectorMasks[
I].begin(),
227 P.Info->OutputVectorMasks[
I].end());
229 P.Info->InputOutputMap[
I].begin(),
230 P.Info->InputOutputMap[
I].end());
234 P.Info->PatchOrPrimMasks.begin(),
235 P.Info->PatchOrPrimMasks.end());
237 P.Info->InputPatchMap.begin(),
238 P.Info->InputPatchMap.end());
240 P.Info->PatchOutputMap.begin(),
241 P.Info->PatchOutputMap.end());
248 case dxbc::PartType::ISG1:
249 case dxbc::PartType::OSG1:
250 case dxbc::PartType::PSG1: {
252 if (
P.Signature.has_value()) {
253 for (
const auto &Param :
P.Signature->Parameters) {
262 case dxbc::PartType::Unknown:
266 RollingOffset += BytesWritten;
267 if (BytesWritten < PartSize)
269 RollingOffset += PartSize;
274 if (
Error Err = computePartOffsets())
286 DXContainerWriter Writer(Doc);
287 if (
Error Err = Writer.write(Out)) {
Base class for error info classes.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
iterator insert(iterator I, T &&Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An efficient, type-erasing, non-owning reference to a callable.
void addParam(uint32_t Stream, StringRef Name, uint32_t Index, dxbc::D3DSystemValue SystemValue, dxbc::SigComponentType CompType, uint32_t Register, uint8_t Mask, uint8_t ExclusiveMask, dxbc::SigMinPrecision MinPrecision)
void write(raw_ostream &OS)
This class is the base class for all object file types.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
PartType parsePartType(StringRef S)
constexpr bool IsBigEndianHost
void swapByteOrder(T &Value)
bool yaml2dxcontainer(DXContainerYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH)
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
dxbc::PSV::v3::RuntimeInfo BaseData
llvm::StringRef EntryName
SmallVector< uint32_t > PatchOrPrimMasks
SmallVector< uint32_t > PatchOutputMap
SmallVector< dxbc::PSV::v2::ResourceBindInfo > Resources
void finalize(Triple::EnvironmentType Stage)
SmallVector< PSVSignatureElement > InputElements
SmallVector< uint32_t > InputPatchMap
SmallVector< PSVSignatureElement > OutputElements
SmallVector< PSVSignatureElement > PatchOrPrimElements
void write(raw_ostream &OS, uint32_t Version=std::numeric_limits< uint32_t >::max()) const
std::array< SmallVector< uint32_t >, 4 > OutputVectorMasks
std::array< SmallVector< uint32_t >, 4 > InputOutputMap
Common declarations for yaml2obj.