Skip to content

Commit

Permalink
D3D12: Possible fix for menu rendering issues
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Mar 13, 2024
1 parent 1a551cc commit 9c1d957
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/REFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9c1d957

Please sign in to comment.