From 0c21440170c09d06c33015845140ea2514c96a53 Mon Sep 17 00:00:00 2001 From: Matthijs Lavrijsen Date: Sat, 2 Jan 2021 22:02:21 +0100 Subject: [PATCH] D3D12on7 changes - Revert 2facdc7 (resize detection); was causing CTD even if not resizing for some users - Initialize m_outWidth and m_outHeight --- src/overlay/Overlay_D3D12.cpp | 2 ++ src/overlay/Overlay_Hooks.cpp | 26 +++++++------------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/overlay/Overlay_D3D12.cpp b/src/overlay/Overlay_D3D12.cpp index a31f8d9c..5840d5fc 100644 --- a/src/overlay/Overlay_D3D12.cpp +++ b/src/overlay/Overlay_D3D12.cpp @@ -227,6 +227,8 @@ bool Overlay::InitializeD3D12Downlevel(ID3D12CommandQueue* pCommandQueue, ID3D12 } m_pCommandQueue = pCommandQueue; + m_outWidth = static_cast(pSourceTex2D->GetDesc().Width); + m_outHeight = pSourceTex2D->GetDesc().Height; if (hWindow != m_hWnd) spdlog::warn("Overlay::InitializeD3D12Downlevel() - current output window does not match hooked window! Currently hooked to {0} while current output window is {1}.", reinterpret_cast(m_hWnd), reinterpret_cast(hWindow)); diff --git a/src/overlay/Overlay_Hooks.cpp b/src/overlay/Overlay_Hooks.cpp index 3706df73..72fae7e6 100644 --- a/src/overlay/Overlay_Hooks.cpp +++ b/src/overlay/Overlay_Hooks.cpp @@ -173,27 +173,15 @@ HRESULT Overlay::PresentD3D12Downlevel(ID3D12CommandQueueDownlevel* pCommandQueu { auto& overlay = Get(); - // On Windows 7 there is no swap chain to query the current backbuffer index. Instead do a reverse lookup in the known backbuffer list - const auto it = std::find(overlay.m_downlevelBackbuffers.cbegin(), overlay.m_downlevelBackbuffers.cend(), pSourceTex2D); - bool resizing = false; - if (it == overlay.m_downlevelBackbuffers.cend()) - { - if (overlay.m_initialized) - { - spdlog::warn("Overlay::PresentD3D12Downlevel() - buffer at {0} not found in backbuffer list! Assuming window was resized - note that support for resizing is experimental.", (void*)pSourceTex2D); - overlay.ResetD3D12State(); - } + // On Windows 7 there is no swap chain to query the current backbuffer index, so instead we simply count to 3 and wrap around. + // Increment the buffer index here even if the overlay is not enabled, so we stay in sync with the game's present calls. + // TODO: investigate if there isn't a better way of doing this (finding the current index in the game exe?) + overlay.m_downlevelBufferIndex = (!overlay.m_initialized || overlay.m_downlevelBufferIndex == 2) ? 0 : overlay.m_downlevelBufferIndex + 1; - overlay.m_downlevelBackbuffers.emplace_back(pSourceTex2D); - - // If we don't have a full backbuffer list, do not attempt to reinitialize yet - resizing = overlay.m_downlevelBackbuffers.size() < 3; - } - else - overlay.m_downlevelBufferIndex = static_cast(std::distance(overlay.m_downlevelBackbuffers.cbegin(), it)); - - if (!resizing && overlay.InitializeD3D12Downlevel(overlay.m_pCommandQueue, pSourceTex2D, hWindow)) + if (overlay.InitializeD3D12Downlevel(overlay.m_pCommandQueue, pSourceTex2D, hWindow)) + { overlay.Render(); + } return overlay.m_realPresentD3D12Downlevel(pCommandQueueDownlevel, pOpenCommandList, pSourceTex2D, hWindow, Flags); }