Skip to content

Commit

Permalink
D3D12on7 changes
Browse files Browse the repository at this point in the history
- Revert 2facdc7 (resize detection); was causing CTD even if not resizing for some users
- Initialize m_outWidth and m_outHeight
  • Loading branch information
Mattiwatti committed Jan 2, 2021
1 parent 2eea72f commit 0c21440
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/overlay/Overlay_D3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ bool Overlay::InitializeD3D12Downlevel(ID3D12CommandQueue* pCommandQueue, ID3D12
}

m_pCommandQueue = pCommandQueue;
m_outWidth = static_cast<UINT>(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<void*>(m_hWnd), reinterpret_cast<void*>(hWindow));
Expand Down
26 changes: 7 additions & 19 deletions src/overlay/Overlay_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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);
}
Expand Down

0 comments on commit 0c21440

Please sign in to comment.