diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h --- a/llvm/include/llvm/BinaryFormat/DXContainer.h +++ b/llvm/include/llvm/BinaryFormat/DXContainer.h @@ -91,6 +91,39 @@ // Structure is followed directly by part data: uint8_t PartData[PartSize]. }; +struct BitcodeHeader { + uint8_t Magic[4]; // ACSII "DXIL". + uint8_t MajorVersion; // DXIL version. + uint8_t MinorVersion; // DXIL version. + uint16_t Unused; + uint32_t Offset; // Offset to LLVM bitcode (from start of header). + uint32_t Size; // Size of LLVM bitcode. + // Followed by uint8_t[BitcodeHeader.BitcodeOffset] + + void swapBytes() { + sys::swapByteOrder(MinorVersion); + sys::swapByteOrder(MajorVersion); + sys::swapByteOrder(Offset); + sys::swapByteOrder(Size); + } +}; +struct ProgramHeader { + uint8_t MinorVersion : 4; + uint8_t MajorVersion : 4; + uint8_t Unused; + uint16_t ShaderKind; + uint32_t Size; // Size in uint32_t units including this header. + BitcodeHeader Bitcode; + + void swapBytes() { + sys::swapByteOrder(ShaderKind); + sys::swapByteOrder(Size); + Bitcode.swapBytes(); + } +}; + +static_assert(sizeof(ProgramHeader) == 24, "ProgramHeader Size incorrect!"); + } // namespace dxbc } // namespace llvm diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h --- a/llvm/include/llvm/Object/DXContainer.h +++ b/llvm/include/llvm/Object/DXContainer.h @@ -15,6 +15,7 @@ #ifndef LLVM_OBJECT_DXCONTAINER_H #define LLVM_OBJECT_DXCONTAINER_H +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/DXContainer.h" @@ -24,15 +25,20 @@ namespace llvm { namespace object { class DXContainer { +public: + using DXILData = std::pair; + private: DXContainer(MemoryBufferRef O); MemoryBufferRef Data; dxbc::Header Header; SmallVector PartOffsets; + Optional DXIL; Error parseHeader(); Error parsePartOffsets(); + Error parseDXILHeader(uint32_t Offset); friend class PartIterator; public: @@ -108,6 +114,8 @@ static Expected create(MemoryBufferRef Object); const dxbc::Header &getHeader() const { return Header; } + + Optional getDXIL() const { return DXIL; } }; } // namespace object diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h --- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h +++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h @@ -41,9 +41,22 @@ Optional> PartOffsets; }; +struct DXILProgram { + uint8_t MajorVersion; + uint8_t MinorVersion; + uint16_t ShaderKind; + Optional Size; + uint16_t DXILMajorVersion; + uint16_t DXILMinorVersion; + Optional DXILOffset; + Optional DXILSize; + Optional> DXIL; +}; + struct Part { std::string Name; uint32_t Size; + Optional Program; }; struct Object { @@ -69,6 +82,10 @@ static void mapping(IO &IO, DXContainerYAML::FileHeader &Header); }; +template <> struct MappingTraits { + static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program); +}; + template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::Part &Version); }; diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp --- a/llvm/lib/Object/DXContainer.cpp +++ b/llvm/lib/Object/DXContainer.cpp @@ -10,6 +10,8 @@ #include "llvm/BinaryFormat/DXContainer.h" #include "llvm/Object/Error.h" +#include + using namespace llvm; using namespace llvm::object; @@ -53,6 +55,18 @@ return readStruct(Data.getBuffer(), Data.getBuffer().data(), Header); } +Error DXContainer::parseDXILHeader(uint32_t Offset) { + if (DXIL) + return parseFailed("More than one DXIL part is present in the file"); + const char *Current = Data.getBuffer().data() + Offset; + dxbc::ProgramHeader Header; + if (Error Err = readStruct(Data.getBuffer(), Current, Header)) + return Err; + Current += offsetof(dxbc::ProgramHeader, Bitcode) + Header.Bitcode.Offset; + DXIL.emplace(std::make_pair(Header, Current)); + return Error::success(); +} + Error DXContainer::parsePartOffsets() { const char *Current = Data.getBuffer().data() + sizeof(dxbc::Header); for (uint32_t Part = 0; Part < Header.PartCount; ++Part) { @@ -63,6 +77,12 @@ if (PartOffset + sizeof(dxbc::PartHeader) > Data.getBufferSize()) return parseFailed("Part offset points beyond boundary of the file"); PartOffsets.push_back(PartOffset); + + // If this isn't a dxil part stop here... + if (Data.getBuffer().substr(PartOffset, 4) != "DXIL") + continue; + if (Error Err = parseDXILHeader(PartOffset + sizeof(dxbc::PartHeader))) + return Err; } return Error::success(); } diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp --- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp +++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp @@ -118,7 +118,45 @@ OS.write(reinterpret_cast(&P.Size), sizeof(uint32_t)); RollingOffset = std::get<1>(I) + sizeof(dxbc::PartHeader); - // TODO: Write Part data + if (P.Name == "DXIL" && P.Program) { + dxbc::ProgramHeader Header; + Header.MajorVersion = P.Program->MajorVersion; + Header.MinorVersion = P.Program->MinorVersion; + Header.ShaderKind = P.Program->ShaderKind; + memcpy(Header.Bitcode.Magic, "DXIL", 4); + Header.Bitcode.MajorVersion = P.Program->DXILMajorVersion; + Header.Bitcode.MinorVersion = P.Program->DXILMinorVersion; + + // Compute the optional fields if needed... + if (P.Program->DXILOffset) + Header.Bitcode.Offset = P.Program->DXILOffset.getValue(); + else + Header.Bitcode.Offset = sizeof(dxbc::BitcodeHeader); + + if (P.Program->DXILSize) + Header.Bitcode.Size = P.Program->DXILSize.getValue(); + else + Header.Bitcode.Size = P.Program->DXIL ? P.Program->DXIL->size() : 0; + + if (P.Program->Size) + Header.Size = P.Program->Size.getValue(); + else + Header.Size = sizeof(dxbc::ProgramHeader) + Header.Bitcode.Size; + if (sys::IsBigEndianHost) + Header.swapBytes(); + OS.write(reinterpret_cast(&Header), + sizeof(dxbc::ProgramHeader)); + if (P.Program->DXIL) { + if (Header.Bitcode.Offset > sizeof(dxbc::BitcodeHeader)) { + uint32_t PadBytes = + Header.Bitcode.Offset - sizeof(dxbc::BitcodeHeader); + std::vector FillData(PadBytes, 0); + OS.write(reinterpret_cast(FillData.data()), PadBytes); + } + OS.write(reinterpret_cast(P.Program->DXIL->data()), + P.Program->DXIL->size()); + } + } } } diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp --- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp +++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp @@ -31,10 +31,23 @@ IO.mapOptional("PartOffsets", Header.PartOffsets); } +void MappingTraits::mapping( + IO &IO, DXContainerYAML::DXILProgram &Program) { + IO.mapRequired("MajorVersion", Program.MajorVersion); + IO.mapRequired("MinorVersion", Program.MinorVersion); + IO.mapRequired("ShaderKind", Program.ShaderKind); + IO.mapOptional("Size", Program.Size); + IO.mapRequired("DXIMMajorVersion", Program.DXILMajorVersion); + IO.mapRequired("DXILMinorVersion", Program.DXILMinorVersion); + IO.mapOptional("DXILSize", Program.DXILSize); + IO.mapOptional("DXIL", Program.DXIL); +} + void MappingTraits::mapping(IO &IO, DXContainerYAML::Part &P) { IO.mapRequired("Name", P.Name); IO.mapRequired("Size", P.Size); + IO.mapOptional("Program", P.Program); } void MappingTraits::mapping( diff --git a/llvm/test/tools/obj2yaml/DXContainer/DXILPart.yaml b/llvm/test/tools/obj2yaml/DXContainer/DXILPart.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/obj2yaml/DXContainer/DXILPart.yaml @@ -0,0 +1,238 @@ +# RUN: yaml2obj %s | obj2yaml | FileCheck %s + +--- !dxcontainer +Header: + Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] + Version: + Major: 1 + Minor: 0 + FileSize: 3548 + PartCount: 7 + PartOffsets: [ 60, 76, 92, 108, 236, 1932, 1960 ] +Parts: + - Name: SFI0 + Size: 8 + - Name: ISG1 + Size: 8 + - Name: OSG1 + Size: 8 + - Name: PSV0 + Size: 120 + - Name: STAT + Size: 1688 + - Name: HASH + Size: 20 + - Name: DXIL + Size: 1580 + Program: + MajorVersion: 6 + MinorVersion: 5 + ShaderKind: 5 + Size: 395 + DXIMMajorVersion: 1 + DXILMinorVersion: 5 + DXILSize: 1556 + DXIL: [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0x82, + 0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0, + 0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0x23, + 0x91, 0x41, 0xC8, 0x4, 0x49, 0x6, 0x10, 0x32, + 0x39, 0x92, 0x1, 0x84, 0xC, 0x25, 0x5, 0x8, 0x19, + 0x1E, 0x4, 0x8B, 0x62, 0x80, 0x14, 0x45, 0x2, + 0x42, 0x92, 0xB, 0x42, 0xA4, 0x10, 0x32, 0x14, + 0x38, 0x8, 0x18, 0x4B, 0xA, 0x32, 0x52, 0x88, + 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5, + 0x0, 0x19, 0x32, 0x42, 0xE4, 0x48, 0xE, 0x90, + 0x91, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C, + 0xE1, 0x83, 0xE5, 0x8A, 0x4, 0x29, 0x46, 0x6, + 0x51, 0x18, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x1B, + 0x8C, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x7, 0x40, + 0x2, 0xA8, 0xD, 0x86, 0xF0, 0xFF, 0xFF, 0xFF, + 0xFF, 0x3, 0x20, 0x1, 0xD5, 0x6, 0x62, 0xF8, 0xFF, + 0xFF, 0xFF, 0xFF, 0x1, 0x90, 0x0, 0x49, 0x18, + 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x13, 0x82, 0x60, + 0x42, 0x20, 0x4C, 0x8, 0x6, 0x0, 0x0, 0x0, 0x0, + 0x89, 0x20, 0x0, 0x0, 0x45, 0x0, 0x0, 0x0, 0x32, + 0x22, 0x48, 0x9, 0x20, 0x64, 0x85, 0x4, 0x93, + 0x22, 0xA4, 0x84, 0x4, 0x93, 0x22, 0xE3, 0x84, + 0xA1, 0x90, 0x14, 0x12, 0x4C, 0x8A, 0x8C, 0xB, + 0x84, 0xA4, 0x4C, 0x10, 0x74, 0x23, 0x0, 0x25, + 0x0, 0x14, 0xE6, 0x8, 0xC0, 0xA0, 0x8, 0x63, 0x10, + 0x99, 0x1, 0xB8, 0x69, 0xB8, 0xFC, 0x9, 0x7B, + 0x8, 0xC9, 0x5F, 0x9, 0x69, 0x25, 0x26, 0xBF, + 0xB8, 0x6D, 0x54, 0x18, 0x63, 0xCC, 0x98, 0x23, + 0x40, 0x8, 0xDD, 0x33, 0x5C, 0xFE, 0x84, 0x3D, + 0x84, 0xE4, 0x87, 0x40, 0x33, 0x2C, 0x4, 0xA, + 0x52, 0x39, 0xCE, 0x50, 0x63, 0xA0, 0x41, 0xEB, + 0xA6, 0xE1, 0xF2, 0x27, 0xEC, 0x21, 0x24, 0x7F, + 0x25, 0xA4, 0x95, 0x98, 0x7C, 0xE4, 0xB6, 0x51, + 0x31, 0xC6, 0x18, 0xA3, 0x1C, 0x6D, 0xA8, 0x31, + 0xD0, 0x20, 0x57, 0x16, 0x30, 0xD4, 0x18, 0xC6, + 0x18, 0x83, 0x6, 0xC1, 0x39, 0x82, 0xA0, 0x18, + 0x6A, 0xA0, 0x31, 0x24, 0xCD, 0x81, 0x80, 0x61, + 0x4, 0xC2, 0xB8, 0x44, 0x9A, 0x22, 0x4A, 0x98, + 0x7C, 0xB1, 0x41, 0x82, 0x1D, 0x33, 0x71, 0xE3, + 0xC0, 0xE, 0xE1, 0x30, 0xF, 0xF3, 0xE0, 0x6, 0xB2, + 0x70, 0xB, 0xB3, 0x40, 0xF, 0xF2, 0x50, 0xF, 0xE3, + 0x40, 0xF, 0xF5, 0x20, 0xF, 0xE5, 0x40, 0xE, 0xA2, + 0x50, 0xF, 0xE6, 0x60, 0xE, 0xE5, 0x20, 0xF, 0x7C, + 0x90, 0xA, 0xEE, 0xE0, 0x7, 0x28, 0xB8, 0x84, + 0x67, 0x5A, 0x83, 0x71, 0x60, 0x87, 0x70, 0x98, + 0x87, 0x79, 0x70, 0x3, 0x59, 0xB8, 0x85, 0x59, + 0xA0, 0x7, 0x79, 0xA8, 0x87, 0x71, 0xA0, 0x87, + 0x7A, 0x90, 0x87, 0x72, 0x20, 0x7, 0x51, 0xA8, + 0x7, 0x73, 0x30, 0x87, 0x72, 0x90, 0x7, 0x3E, + 0xB0, 0x87, 0x72, 0x18, 0x7, 0x7A, 0x78, 0x7, + 0x79, 0xE0, 0x3, 0x73, 0x60, 0x87, 0x77, 0x8, + 0x7, 0x7A, 0x60, 0x3, 0x30, 0xA0, 0x3, 0x3F, 0x0, + 0x3, 0x3F, 0x40, 0x81, 0x25, 0x3D, 0x47, 0x0, + 0xA, 0x0, 0x0, 0x0, 0x0, 0x13, 0x14, 0x72, 0xC0, + 0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79, + 0x68, 0x3, 0x72, 0xC0, 0x87, 0xD, 0xAF, 0x50, + 0xE, 0x6D, 0xD0, 0xE, 0x7A, 0x50, 0xE, 0x6D, 0x0, + 0xF, 0x7A, 0x30, 0x7, 0x72, 0xA0, 0x7, 0x73, 0x20, + 0x7, 0x6D, 0x90, 0xE, 0x71, 0xA0, 0x7, 0x73, 0x20, + 0x7, 0x6D, 0x90, 0xE, 0x78, 0xA0, 0x7, 0x73, 0x20, + 0x7, 0x6D, 0x90, 0xE, 0x71, 0x60, 0x7, 0x7A, 0x30, + 0x7, 0x72, 0xD0, 0x6, 0xE9, 0x30, 0x7, 0x72, 0xA0, + 0x7, 0x73, 0x20, 0x7, 0x6D, 0x90, 0xE, 0x76, 0x40, + 0x7, 0x7A, 0x60, 0x7, 0x74, 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13, 0x44, 0x35, 0x18, 0x63, 0xB, + 0x73, 0x3B, 0x3, 0xB1, 0x2B, 0x93, 0x9B, 0x4B, + 0x7B, 0x73, 0x3, 0x99, 0x71, 0xB9, 0x1, 0x41, + 0xA1, 0xB, 0x3B, 0x9B, 0x7B, 0x91, 0x2A, 0x62, + 0x2A, 0xA, 0x9A, 0x2A, 0xFA, 0x9A, 0xB9, 0x81, + 0x79, 0x31, 0x4B, 0x73, 0xB, 0x63, 0x4B, 0xD9, + 0x10, 0x4, 0x13, 0x84, 0xC1, 0x98, 0x20, 0xC, + 0xC7, 0x6, 0x61, 0x20, 0x26, 0x8, 0x3, 0xB2, 0x41, + 0x18, 0xC, 0xA, 0x63, 0x73, 0x13, 0x84, 0x21, + 0xD9, 0x30, 0x20, 0x9, 0x31, 0x41, 0x18, 0x94, + 0x9, 0x42, 0x36, 0x11, 0x98, 0x20, 0xC, 0xCB, + 0x4, 0x41, 0x82, 0x26, 0x8, 0x3, 0xB3, 0x41, 0x18, + 0xA0, 0xD, 0xCB, 0xC2, 0x34, 0xCB, 0x32, 0x38, + 0xCF, 0xF3, 0x44, 0x13, 0x84, 0x4D, 0x9A, 0x20, + 0xC, 0xCD, 0x6, 0x61, 0xA0, 0x36, 0x2C, 0xC3, + 0xD4, 0x2C, 0xC3, 0xE0, 0x3C, 0xCF, 0x53, 0x6D, + 0x10, 0x24, 0x6B, 0x3, 0x1, 0x5C, 0x0, 0x30, 0x41, + 0x10, 0x0, 0x1A, 0x43, 0x53, 0x4D, 0x61, 0x69, + 0x6E, 0x13, 0x4, 0x2E, 0x9A, 0x20, 0xC, 0xCE, + 0x4, 0x61, 0x78, 0x36, 0xC, 0x5D, 0x37, 0x6C, + 0x20, 0x96, 0x8D, 0xF3, 0x36, 0x14, 0x99, 0x6, + 0x60, 0x5F, 0x15, 0x36, 0x36, 0xBB, 0x36, 0x97, + 0x34, 0xB2, 0x32, 0x37, 0xBA, 0x29, 0x41, 0x50, + 0x85, 0xC, 0xCF, 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30, 0xF, 0x6E, + 0x30, 0xF, 0xE3, 0xF0, 0xE, 0xF0, 0x50, 0xE, 0x33, + 0x10, 0xC4, 0x1D, 0xDE, 0x21, 0x1C, 0xD8, 0x21, + 0x1D, 0xC2, 0x61, 0x1E, 0x66, 0x30, 0x89, 0x3B, + 0xBC, 0x83, 0x3B, 0xD0, 0x43, 0x39, 0xB4, 0x3, + 0x3C, 0xBC, 0x83, 0x3C, 0x84, 0x3, 0x3B, 0xCC, + 0xF0, 0x14, 0x76, 0x60, 0x7, 0x7B, 0x68, 0x7, + 0x37, 0x68, 0x87, 0x72, 0x68, 0x7, 0x37, 0x80, + 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x7, 0x76, + 0x28, 0x7, 0x76, 0xF8, 0x5, 0x76, 0x78, 0x87, + 0x77, 0x80, 0x87, 0x5F, 0x8, 0x87, 0x71, 0x18, + 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2C, + 0xEE, 0xF0, 0xE, 0xEE, 0xE0, 0xE, 0xF5, 0xC0, + 0xE, 0xEC, 0x30, 0x3, 0x62, 0xC8, 0xA1, 0x1C, + 0xE4, 0xA1, 0x1C, 0xCC, 0xA1, 0x1C, 0xE4, 0xA1, + 0x1C, 0xDC, 0x61, 0x1C, 0xCA, 0x21, 0x1C, 0xC4, + 0x81, 0x1D, 0xCA, 0x61, 0x6, 0xD6, 0x90, 0x43, + 0x39, 0xC8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xC8, + 0x43, 0x39, 0xB8, 0xC3, 0x38, 0x94, 0x43, 0x38, + 0x88, 0x3, 0x3B, 0x94, 0xC3, 0x2F, 0xBC, 0x83, + 0x3C, 0xFC, 0x82, 0x3B, 0xD4, 0x3, 0x3B, 0xB0, + 0xC3, 0xC, 0xC4, 0x21, 0x7, 0x7C, 0x70, 0x3, 0x7A, + 0x28, 0x87, 0x76, 0x80, 0x87, 0x19, 0xD1, 0x43, + 0xE, 0xF8, 0xE0, 0x6, 0xE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51, 0xCA, + 0x88, 0x41, 0x2, 0x80, 0x20, 0x18, 0x4C, 0xD6, + 0x31, 0x44, 0xD1, 0x32, 0x62, 0x50, 0x0, 0x20, + 0x8, 0x6, 0xC4, 0x66, 0x8C, 0x18, 0x28, 0x0, 0x8, + 0x82, 0xC1, 0xB2, 0x21, 0x42, 0x30, 0x11, 0xCF, + 0x68, 0x42, 0x0, 0x8C, 0x26, 0x8, 0xC1, 0x68, + 0xC2, 0x20, 0x8C, 0x26, 0x10, 0xC3, 0x88, 0x81, + 0x2, 0x80, 0x20, 0x18, 0x38, 0x5F, 0x73, 0x18, + 0x95, 0x42, 0x8D, 0x26, 0x4, 0xC0, 0x88, 0x81, + 0x3, 0x80, 0x20, 0x18, 0x40, 0x60, 0xD0, 0x28, + 0x81, 0x66, 0x14, 0xC4, 0xB0, 0x58, 0x8, 0x0, + 0x0, 0x0, 0x0 ] +... + + + + +#CHECK: - Name: DXIL +#CHECK-NEXT: Size: 1580 +#CHECK-NEXT: Program: +#CHECK-NEXT: MajorVersion: 6 +#CHECK-NEXT: MinorVersion: 5 +#CHECK-NEXT: ShaderKind: 5 +#CHECK-NEXT: Size: 395 +#CHECK-NEXT: DXIMMajorVersion: 1 +#CHECK-NEXT: DXILMinorVersion: 5 +#CHECK-NEXT: DXILSize: 1556 +#CHECK-NEXT: DXIL: [ 0x42, 0x43, 0xC0, 0xDE, diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp --- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp +++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp @@ -38,8 +38,24 @@ Obj->Header.PartOffsets = std::vector(); for (const auto P : Container) { Obj->Header.PartOffsets->push_back(P.Offset); - Obj->Parts.push_back( - DXContainerYAML::Part{P.Part.getName().str(), P.Part.Size}); + if (P.Part.getName() == "DXIL") { + Optional DXIL = Container.getDXIL(); + assert(DXIL.hasValue() && "Since we are iterating and found a DXIL part, " + "this should never not have a value"); + Obj->Parts.push_back(DXContainerYAML::Part{ + P.Part.getName().str(), P.Part.Size, + DXContainerYAML::DXILProgram{ + DXIL->first.MajorVersion, DXIL->first.MinorVersion, + DXIL->first.ShaderKind, DXIL->first.Size, + DXIL->first.Bitcode.MajorVersion, + DXIL->first.Bitcode.MinorVersion, DXIL->first.Bitcode.Offset, + DXIL->first.Bitcode.Size, + std::vector( + DXIL->second, DXIL->second + DXIL->first.Bitcode.Size)}}); + } else { + Obj->Parts.push_back( + DXContainerYAML::Part{P.Part.getName().str(), P.Part.Size, None}); + } } return Obj.release();