From 9c1d957e8479bc599ab88a17b43b3e98ef17d798 Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 13 Mar 2024 09:54:45 -0700 Subject: [PATCH] D3D12: Possible fix for menu rendering issues --- src/REFramework.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/REFramework.cpp b/src/REFramework.cpp index 181dc2a1a..5fb85ddf2 100644 --- a/src/REFramework.cpp +++ b/src/REFramework.cpp @@ -662,6 +662,19 @@ void REFramework::on_frame_d3d12() { return; } + auto swapchain = m_d3d12_hook->get_swap_chain(); + const auto bb_index = swapchain->GetCurrentBackBufferIndex(); + + // Test if our RT for this index is valid. + if (m_d3d12.get_rt((D3D12::RTV)bb_index) == nullptr) { + spdlog::error("RTV for index {} is null, reinitializing...", bb_index); + deinit_d3d12(); + m_has_frame = false; + m_first_initialize = false; + m_initialized = false; + return; + } + cmd_ctx->wait(INFINITE); { std::scoped_lock _{ cmd_ctx->mtx }; @@ -692,8 +705,6 @@ void REFramework::on_frame_d3d12() { cmd_ctx->cmd_list->ResourceBarrier(1, &barrier); // Draw to the back buffer. - auto swapchain = m_d3d12_hook->get_swap_chain(); - auto bb_index = swapchain->GetCurrentBackBufferIndex(); barrier.Transition.pResource = m_d3d12.rts[bb_index].Get(); barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; @@ -1845,12 +1856,20 @@ bool REFramework::init_d3d12() { if (SUCCEEDED(swapchain->GetBuffer(i, IID_PPV_ARGS(&m_d3d12.rts[i])))) { device->CreateRenderTargetView(m_d3d12.rts[i].Get(), nullptr, m_d3d12.get_cpu_rtv(device, (D3D12::RTV)i)); } else { - spdlog::error("[D3D12] Failed to get back buffer for rtv."); + spdlog::error("[D3D12] Failed to get back buffer for rtv {}", i); + m_d3d12.rts[i].Reset(); // just in case } } // Create our imgui and blank rts. auto& backbuffer = m_d3d12.get_rt(D3D12::RTV::BACKBUFFER_0); + + if (backbuffer == nullptr) { + spdlog::error("[D3D12] Failed to get first back buffer RTV."); + deinit_d3d12(); + return false; + } + auto desc = backbuffer->GetDesc(); spdlog::info("[D3D12] Back buffer format is {}", desc.Format);