Skip to content

Commit fe934d0

Browse files
committed
Attempt to implement barrier for fonts
1 parent 7aca66d commit fe934d0

File tree

4 files changed

+154
-418
lines changed

4 files changed

+154
-418
lines changed

src/d3d12/D3D12.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ struct D3D12
100100
std::array<ImDrawData, 3> m_imguiDrawDataBuffers;
101101
std::atomic_bool m_delayedTrapInput{false};
102102
std::atomic_bool m_delayedTrapInputState{false};
103+
bool m_imGuiInitialized{false};
103104
};

src/d3d12/D3D12_Functions.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDest
2222
drawData.Clear();
2323
}
2424

25-
ImGui_ImplDX12_Shutdown();
26-
ImGui_ImplWin32_Shutdown();
25+
ImGui::GetIO().Fonts->Clear();
2726

2827
if (acDestroyContext)
28+
{
29+
ImGui_ImplDX12_Shutdown();
30+
ImGui_ImplWin32_Shutdown();
2931
ImGui::DestroyContext();
32+
33+
m_imGuiInitialized = false;
34+
}
3035
}
3136

3237
m_frameContexts.clear();
@@ -278,14 +283,15 @@ bool D3D12::InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resour
278283
void D3D12::ReloadFonts()
279284
{
280285
std::lock_guard _(m_imguiLock);
286+
287+
auto& io = ImGui::GetIO();
288+
if (io.Fonts->IsBuilt())
289+
return;
281290

282291
// TODO - scale also by DPI
283292
const auto [resx, resy] = m_outSize;
284293
const auto scaleFromReference = std::min(static_cast<float>(resx) / 1920.0f, static_cast<float>(resy) / 1080.0f);
285294

286-
auto& io = ImGui::GetIO();
287-
io.Fonts->Clear();
288-
289295
ImFontConfig config;
290296
const auto& fontSettings = m_options.Font;
291297
config.SizePixels = std::floorf(fontSettings.BaseSize * scaleFromReference);
@@ -415,12 +421,16 @@ void D3D12::ReloadFonts()
415421
static const ImWchar icon_ranges[] = {ICON_MIN_MD, ICON_MAX_MD, 0};
416422
auto cetIconPath = GetAbsolutePath(L"materialdesignicons.ttf", m_paths.Fonts(), false);
417423
io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(cetIconPath.native()).c_str(), config.SizePixels, &config, icon_ranges);
424+
io.Fonts->Build();
418425
}
419426

420427
bool D3D12::InitializeImGui(size_t aBuffersCounts)
421428
{
422429
std::lock_guard _(m_imguiLock);
423430

431+
if (m_imGuiInitialized)
432+
return true;
433+
424434
// TODO - scale also by DPI
425435
const auto [resx, resy] = m_outSize;
426436
const auto scaleFromReference = std::min(static_cast<float>(resx) / 1920.0f, static_cast<float>(resy) / 1080.0f);
@@ -469,9 +479,13 @@ bool D3D12::InitializeImGui(size_t aBuffersCounts)
469479
Log::Error("D3D12::InitializeImGui() - ImGui_ImplDX12_CreateDeviceObjects call failed!");
470480
ImGui_ImplDX12_Shutdown();
471481
ImGui_ImplWin32_Shutdown();
482+
483+
ImGui::GetIO().Fonts->Clear();
484+
472485
return false;
473486
}
474487

488+
m_imGuiInitialized = true;
475489
return true;
476490
}
477491

@@ -482,6 +496,13 @@ void D3D12::PrepareUpdate()
482496

483497
std::lock_guard _(m_imguiLock);
484498

499+
if (!ImGui::GetIO().Fonts->IsBuilt())
500+
{
501+
ReloadFonts();
502+
503+
ImGui_ImplDX12_CreateDeviceObjects(m_pCommandQueue.Get());
504+
}
505+
485506
ImGui_ImplWin32_NewFrame(m_outSize);
486507
ImGui::NewFrame();
487508

0 commit comments

Comments
 (0)