From 2b74938ccda6fe2f9b7389d22ce9292455e681e1 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 22 Apr 2021 12:05:15 +0100 Subject: [PATCH] When present, embed D3D12Core.dll into the capture * This way we know we have the right matching version for use on replay. --- renderdoc/api/replay/renderdoc_tostr.inl | 1 + renderdoc/api/replay/replay_enums.h | 7 +++++ renderdoc/driver/d3d12/d3d12_device.cpp | 40 +++++++++++++++++++----- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/renderdoc/api/replay/renderdoc_tostr.inl b/renderdoc/api/replay/renderdoc_tostr.inl index 19d524f34..574b4a32b 100644 --- a/renderdoc/api/replay/renderdoc_tostr.inl +++ b/renderdoc/api/replay/renderdoc_tostr.inl @@ -1029,6 +1029,7 @@ rdcstr DoStringise(const SectionType &el) STRINGISE_ENUM_CLASS_NAMED(ExtendedThumbnail, "renderdoc/internal/exthumb"); STRINGISE_ENUM_CLASS_NAMED(EmbeddedLogfile, "renderdoc/internal/logfile"); STRINGISE_ENUM_CLASS_NAMED(EditedShaders, "renderdoc/ui/edits"); + STRINGISE_ENUM_CLASS_NAMED(D3D12Core, "renderdoc/internal/d3d12core"); } END_ENUM_STRINGISE(); } diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index c71508423..7db54358e 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -98,6 +98,12 @@ version of RenderDoc that addes a new section type. They should be considered eq This section contains any edited shaders. The name for this section will be "renderdoc/ui/edits". + +.. data:: D3D12Core + + This section contains an internal copy of D3D12Core for replaying. + + The name for this section will be "renderdoc/internal/d3d12core". )"); enum class SectionType : uint32_t { @@ -112,6 +118,7 @@ enum class SectionType : uint32_t ExtendedThumbnail, EmbeddedLogfile, EditedShaders, + D3D12Core, Count, }; diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index d6b35af47..3d80b11ad 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -2481,6 +2481,12 @@ bool WrappedID3D12Device::EndFrameCapture(void *dev, void *wnd) StreamWriter *captureWriter = NULL; + HMODULE D3D12Core = GetModuleHandleA("D3D12Core.dll"); + if(D3D12Core) + { + m_InitParams.SDKVersion = *(DWORD *)GetProcAddress(D3D12Core, "D3D12SDKVersion"); + } + if(rdc) { SectionProperties props; @@ -2508,13 +2514,6 @@ bool WrappedID3D12Device::EndFrameCapture(void *dev, void *wnd) m_InitParams.usedDXIL = m_UsedDXIL; - HMODULE D3D12Core = GetModuleHandleA("D3D12Core.dll"); - if(D3D12Core) - { - m_InitParams.SDKVersion = *(DWORD *)GetProcAddress(D3D12Core, "D3D12SDKVersion"); - FreeLibrary(D3D12Core); - } - if(m_UsedDXIL) { RDCLOG("Capture used DXIL"); @@ -2598,6 +2597,33 @@ bool WrappedID3D12Device::EndFrameCapture(void *dev, void *wnd) RDCLOG("Captured D3D12 frame with %f MB capture section in %f seconds", double(captureSectionSize) / (1024.0 * 1024.0), m_CaptureTimer.GetMilliseconds() / 1000.0); + if(D3D12Core) + { + if(rdc) + { + wchar_t core_filename[MAX_PATH + 1] = {}; + GetModuleFileNameW(D3D12Core, core_filename, MAX_PATH); + + bytebuf core_file; + FileIO::ReadAll(StringFormat::Wide2UTF8(core_filename), core_file); + + SectionProperties props; + + props.flags = SectionFlags::ZstdCompressed; + props.version = 1; + props.type = SectionType::D3D12Core; + + captureWriter = rdc->WriteSection(props); + + captureWriter->Write(core_file.data(), core_file.size()); + + captureWriter->Finish(); + SAFE_DELETE(captureWriter); + } + + FreeLibrary(D3D12Core); + } + RenderDoc::Inst().FinishCaptureWriting(rdc, m_CapturedFrames.back().frameNumber); m_HeaderChunk->Delete();