diff --git a/renderdoc/serialise/codecs/xml_codec.cpp b/renderdoc/serialise/codecs/xml_codec.cpp index 45eab764f..99290538e 100644 --- a/renderdoc/serialise/codecs/xml_codec.cpp +++ b/renderdoc/serialise/codecs/xml_codec.cpp @@ -43,6 +43,35 @@ static const char *typeNames[] = { "uint", "int", "float", "bool", "char", "ResourceId", }; +struct LiteralFileSection +{ + SectionType type; + rdcstr filename; + rdcstr chunkName; +}; + +static const LiteralFileSection literalFileSections[] = { + {SectionType::EmbeddedLogfile, "diagnostic.log", "diagnostic_log"}, + {SectionType::D3D12Core, "D3D12Core.dll", "d3d12core"}, + {SectionType::D3D12SDKLayers, "D3D12SDKLayers.dll", "d3d12sdklayers"}, +}; + +static bool isLiteralFileChunkName(const rdcstr &chunkName) +{ + for(const LiteralFileSection §ion : literalFileSections) + if(chunkName == section.chunkName) + return true; + return false; +} + +static bool isLiteralFileFileName(const rdcstr &filename) +{ + for(const LiteralFileSection §ion : literalFileSections) + if(filename == section.filename) + return true; + return false; +} + template rdcstr GetBufferName(inttype i) { @@ -368,13 +397,24 @@ static RDResult Structured2XML(const rdcstr &filename, const RDCFile &file, uint delete reader; continue; } - else if(props.type == SectionType::EmbeddedLogfile) + else { - pugi::xml_node xLogfile = xRoot.append_child("diagnostic_log"); - xLogfile.text() = "diagnostic.log"; + bool literalSection = false; - delete reader; - continue; + for(const LiteralFileSection §ion : literalFileSections) + { + if(section.type == props.type) + { + pugi::xml_node xFile = xRoot.append_child(section.chunkName.c_str()); + xFile.text() = section.filename.c_str(); + + delete reader; + literalSection = true; + } + } + + if(literalSection) + continue; } pugi::xml_node xSection = xRoot.append_child("section"); @@ -578,7 +618,8 @@ static SDObject *XML2Obj(pugi::xml_node &obj) } static RDResult XML2Structured(const rdcstr &xml, const ThumbTypeAndData &thumb, - const ThumbTypeAndData &extThumb, const bytebuf &logfile, + const ThumbTypeAndData &extThumb, + const std::map &literalFiles, const StructuredBufferList &buffers, RDCFile *rdc, uint64_t &version, StructuredChunkList &chunks, RENDERDOC_ProgressCallback progress) { @@ -659,7 +700,7 @@ static RDResult XML2Structured(const rdcstr &xml, const ThumbTypeAndData &thumb, pugi::xml_node xSection = xHeader.next_sibling(); while(!strcmp(xSection.name(), "section") || !strcmp(xSection.name(), "extended_thumbnail") || - !strcmp(xSection.name(), "diagnostic_log")) + isLiteralFileChunkName(xSection.name())) { if(!strcmp(xSection.name(), "extended_thumbnail")) { @@ -683,21 +724,36 @@ static RDResult XML2Structured(const rdcstr &xml, const ThumbTypeAndData &thumb, xSection = xSection.next_sibling(); continue; } - else if(!strcmp(xSection.name(), "diagnostic_log")) + else { - SectionProperties props = {}; - props.type = SectionType::EmbeddedLogfile; - props.version = 1; - props.flags = SectionFlags::LZ4Compressed; + bool literalSection = false; - StreamWriter *w = rdc->WriteSection(props); - w->Write(logfile.data(), logfile.size()); - w->Finish(); + for(const LiteralFileSection §ion : literalFileSections) + { + if(section.chunkName == xSection.name()) + { + auto litIt = literalFiles.find(section.type); + if(litIt != literalFiles.end()) + { + SectionProperties props = {}; + props.type = section.type; + props.version = 1; + props.flags = SectionFlags::LZ4Compressed; - delete w; + StreamWriter *w = rdc->WriteSection(props); + w->Write(litIt->second.data(), litIt->second.size()); + w->Finish(); - xSection = xSection.next_sibling(); - continue; + delete w; + + xSection = xSection.next_sibling(); + literalSection = true; + } + } + } + + if(literalSection) + continue; } SectionProperties props; @@ -918,18 +974,25 @@ static RDResult Buffers2ZIP(const rdcstr &filename, const RDCFile &file, delete reader; continue; } - else if(props.type == SectionType::EmbeddedLogfile) + else { - StreamReader *reader = file.ReadSection(i); + for(const LiteralFileSection §ion : literalFileSections) + { + if(section.type == props.type) + { + StreamReader *reader = file.ReadSection(i); - bytebuf log; - log.resize((size_t)reader->GetSize()); - reader->Read(log.data(), log.size()); + bytebuf literalFile; + literalFile.resize((size_t)reader->GetSize()); + reader->Read(literalFile.data(), literalFile.size()); - mz_zip_writer_add_mem(&zip, "diagnostic.log", log.data(), log.size(), MZ_BEST_SPEED); + mz_zip_writer_add_mem(&zip, section.filename.c_str(), literalFile.data(), + literalFile.size(), MZ_BEST_SPEED); - delete reader; - continue; + delete reader; + break; + } + } } } @@ -940,7 +1003,7 @@ static RDResult Buffers2ZIP(const rdcstr &filename, const RDCFile &file, } static RDResult ZIP2Buffers(const rdcstr &filename, ThumbTypeAndData &thumb, - ThumbTypeAndData &extThumb, bytebuf &logfile, + ThumbTypeAndData &extThumb, std::map &literalFiles, StructuredBufferList &buffers, RENDERDOC_ProgressCallback progress) { rdcstr zipFile = strip_extension(filename); @@ -991,10 +1054,14 @@ static RDResult ZIP2Buffers(const rdcstr &filename, ThumbTypeAndData &thumb, thumb.data.assign(buf, sz); } } - else if(strstr(zstat.m_filename, "diagnostic.log")) + else if(isLiteralFileFileName(zstat.m_filename)) { - // same for logfile - logfile.assign(buf, sz); + // same for literal files (log file, D3D12 dlls, etc) + for(const LiteralFileSection §ion : literalFileSections) + { + if(section.filename == zstat.m_filename) + literalFiles[section.type].assign(buf, sz); + } } else { @@ -1023,10 +1090,10 @@ RDResult importXMLZ(const rdcstr &filename, StreamReader &reader, RDCFile *rdc, RENDERDOC_ProgressCallback progress) { ThumbTypeAndData thumb, extThumb; - bytebuf logfile; + std::map literalFiles; if(!filename.empty()) { - RDResult res = ZIP2Buffers(filename, thumb, extThumb, logfile, structData.buffers, progress); + RDResult res = ZIP2Buffers(filename, thumb, extThumb, literalFiles, structData.buffers, progress); if(res != ResultCode::Succeeded) return res; } @@ -1035,7 +1102,7 @@ RDResult importXMLZ(const rdcstr &filename, StreamReader &reader, RDCFile *rdc, buf.resize((size_t)reader.GetSize()); reader.Read(buf.data(), buf.size()); - return XML2Structured(buf.c_str(), thumb, extThumb, logfile, structData.buffers, rdc, + return XML2Structured(buf.c_str(), thumb, extThumb, literalFiles, structData.buffers, rdc, structData.version, structData.chunks, progress); }