Skip to content

Commit 5cd3a77

Browse files
authored
Clean-up profiler window (#188)
* Clean-up profiler window * Open Memory and GPU sections by default
1 parent 6198f0e commit 5cd3a77

1 file changed

Lines changed: 158 additions & 90 deletions

File tree

MarathonRecomp/gpu/video.cpp

Lines changed: 158 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,6 @@ struct Profiler
325325
static double g_applicationValues[PROFILER_VALUE_COUNT];
326326
static Profiler g_gpuFrameProfiler;
327327
static Profiler g_presentProfiler;
328-
static Profiler g_updateDirectorProfiler;
329-
static Profiler g_renderDirectorProfiler;
330328
static Profiler g_frameFenceProfiler;
331329
static Profiler g_presentWaitProfiler;
332330
static Profiler g_swapChainAcquireProfiler;
@@ -2622,134 +2620,204 @@ static void DrawProfiler()
26222620
font->Scale = ImGui::GetDefaultFont()->FontSize / font->FontSize;
26232621
ImGui::PushFont(font);
26242622

2623+
#define IMGUI_GENERIC_ROW(name, value, ...) \
2624+
ImGui::TableNextColumn(); \
2625+
ImGui::Text(name); \
2626+
ImGui::TableNextColumn(); \
2627+
ImGui::Text(value, __VA_ARGS__);
2628+
26252629
if (ImGui::Begin("Profiler", &g_profilerVisible))
26262630
{
26272631
g_applicationValues[g_profilerValueIndex] = App::s_deltaTime * 1000.0;
26282632

26292633
const double applicationAvg = std::accumulate(g_applicationValues, g_applicationValues + PROFILER_VALUE_COUNT, 0.0) / PROFILER_VALUE_COUNT;
26302634
double gpuFrameAvg = g_gpuFrameProfiler.UpdateAndReturnAverage();
26312635
double presentAvg = g_presentProfiler.UpdateAndReturnAverage();
2632-
double updateDirectorAvg = g_updateDirectorProfiler.UpdateAndReturnAverage();
2633-
double renderDirectorAvg = g_renderDirectorProfiler.UpdateAndReturnAverage();
26342636
double frameFenceAvg = g_frameFenceProfiler.UpdateAndReturnAverage();
26352637
double presentWaitAvg = g_presentWaitProfiler.UpdateAndReturnAverage();
26362638
double swapChainAcquireAvg = g_swapChainAcquireProfiler.UpdateAndReturnAverage();
26372639

2638-
if (ImPlot::BeginPlot("Frame Time"))
2640+
if (ImGui::CollapsingHeader("Performance", ImGuiTreeNodeFlags_DefaultOpen))
26392641
{
2640-
ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, 20.0);
2641-
ImPlot::SetupAxis(ImAxis_Y1, "ms", ImPlotAxisFlags_None);
2642-
ImPlot::PlotLine<double>("Application", g_applicationValues, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2643-
ImPlot::PlotLine<double>("GPU Frame", g_gpuFrameProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2644-
ImPlot::PlotLine<double>("Present", g_presentProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2645-
ImPlot::PlotLine<double>("Update Director", g_updateDirectorProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2646-
ImPlot::PlotLine<double>("Render Director", g_renderDirectorProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2647-
ImPlot::PlotLine<double>("Frame Fence", g_frameFenceProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2648-
ImPlot::PlotLine<double>("Present Wait", g_presentWaitProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2649-
ImPlot::PlotLine<double>("Swap Chain Acquire", g_swapChainAcquireProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2650-
ImPlot::EndPlot();
2651-
}
2652-
2653-
g_profilerValueIndex = (g_profilerValueIndex + 1) % PROFILER_VALUE_COUNT;
2642+
if (ImPlot::BeginPlot("Frame Time"))
2643+
{
2644+
ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, 20.0);
2645+
ImPlot::SetupAxis(ImAxis_Y1, "ms", ImPlotAxisFlags_None);
2646+
ImPlot::PlotLine<double>("Application", g_applicationValues, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2647+
ImPlot::PlotLine<double>("GPU Frame", g_gpuFrameProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2648+
ImPlot::PlotLine<double>("Present", g_presentProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2649+
ImPlot::PlotLine<double>("Present Wait", g_presentWaitProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2650+
ImPlot::PlotLine<double>("Frame Fence", g_frameFenceProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2651+
ImPlot::PlotLine<double>("Swap Chain Acquire", g_swapChainAcquireProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
2652+
ImPlot::EndPlot();
2653+
}
26542654

2655-
ImGui::Text("Current Application: %g ms (%g FPS)", App::s_deltaTime * 1000.0, 1.0 / App::s_deltaTime);
2656-
ImGui::Text("Current GPU Frame: %g ms (%g FPS)", g_gpuFrameProfiler.value.load(), 1000.0 / g_gpuFrameProfiler.value.load());
2657-
ImGui::Text("Current Present: %g ms (%g FPS)", g_presentProfiler.value.load(), 1000.0 / g_presentProfiler.value.load());
2658-
ImGui::Text("Current Update Director: %g ms (%g FPS)", g_updateDirectorProfiler.value.load(), 1000.0 / g_updateDirectorProfiler.value.load());
2659-
ImGui::Text("Current Render Director: %g ms (%g FPS)", g_renderDirectorProfiler.value.load(), 1000.0 / g_renderDirectorProfiler.value.load());
2660-
ImGui::Text("Current Frame Fence: %g ms", g_frameFenceProfiler.value.load());
2661-
ImGui::Text("Current Present Wait: %g ms", g_presentWaitProfiler.value.load());
2662-
ImGui::Text("Current Swap Chain Acquire: %g ms", g_swapChainAcquireProfiler.value.load());
2655+
g_profilerValueIndex = (g_profilerValueIndex + 1) % PROFILER_VALUE_COUNT;
26632656

2664-
ImGui::NewLine();
2657+
if (ImGui::BeginTable("Performance", 5))
2658+
{
2659+
ImGui::TableSetupColumn("Name");
2660+
ImGui::TableSetupColumn("Current Time");
2661+
ImGui::TableSetupColumn("Average Time");
2662+
ImGui::TableSetupColumn("Current FPS");
2663+
ImGui::TableSetupColumn("Average FPS");
2664+
ImGui::TableHeadersRow();
2665+
2666+
auto drawPerfRow = [](const char* name, double ms, double msAvg, bool showFPS = false, double fps = 0, double fpsAvg = 0)
2667+
{
2668+
ImGui::TableNextColumn();
2669+
ImGui::Text("%s", name);
2670+
ImGui::TableNextColumn();
2671+
ImGui::Text("%g ms", ms);
2672+
ImGui::TableNextColumn();
2673+
ImGui::Text("%g ms", msAvg);
2674+
ImGui::TableNextColumn();
2675+
2676+
if (showFPS)
2677+
ImGui::Text("%g FPS", fps);
2678+
2679+
ImGui::TableNextColumn();
2680+
2681+
if (showFPS)
2682+
ImGui::Text("%g FPS", fpsAvg);
2683+
};
2684+
2685+
// -------- Name ---------------- Current Time --------------------------- Average Time -------- Current FPS ----------------------------- Average FPS ---------- //
2686+
drawPerfRow("Application", App::s_deltaTime * 1000.0, applicationAvg, true, 1.0 / App::s_deltaTime, 1000.0 / applicationAvg);
2687+
drawPerfRow("GPU Frame", g_gpuFrameProfiler.value.load(), gpuFrameAvg, true, 1000.0 / g_gpuFrameProfiler.value.load(), 1000.0 / gpuFrameAvg );
2688+
drawPerfRow("Present", g_presentProfiler.value.load(), presentAvg, true, 1000.0 / g_presentProfiler.value.load(), 1000.0 / presentAvg );
2689+
drawPerfRow("Present Wait", g_presentWaitProfiler.value.load(), presentWaitAvg );
2690+
drawPerfRow("Frame Fence", g_frameFenceProfiler.value.load(), frameFenceAvg );
2691+
drawPerfRow("Swap Chain Acquire", g_swapChainAcquireProfiler.value.load(), swapChainAcquireAvg );
2692+
2693+
ImGui::EndTable();
2694+
}
26652695

2666-
ImGui::Text("Average Application: %g ms (%g FPS)", applicationAvg, 1000.0 / applicationAvg);
2667-
ImGui::Text("Average GPU Frame: %g ms (%g FPS)", gpuFrameAvg, 1000.0 / gpuFrameAvg);
2668-
ImGui::Text("Average Present: %g ms (%g FPS)", presentAvg, 1000.0 / presentAvg);
2669-
ImGui::Text("Average Update Director: %g ms (%g FPS)", updateDirectorAvg, 1000.0 / updateDirectorAvg);
2670-
ImGui::Text("Average Render Director: %g ms (%g FPS)", renderDirectorAvg, 1000.0 / renderDirectorAvg);
2671-
ImGui::Text("Average Frame Fence: %g ms", frameFenceAvg);
2672-
ImGui::Text("Average Present Wait: %g ms", presentWaitAvg);
2673-
ImGui::Text("Average Swap Chain Acquire: %g ms", swapChainAcquireAvg);
2696+
ImGui::Separator();
26742697

2675-
ImGui::NewLine();
2698+
ImGui::Checkbox("Show FPS", &Config::ShowFPS.Value);
2699+
}
26762700

26772701
if (g_userHeap.heap != nullptr && g_userHeap.physicalHeap != nullptr)
26782702
{
2679-
O1HeapDiagnostics diagnostics, physicalDiagnostics;
2703+
if (ImGui::CollapsingHeader("Memory", ImGuiTreeNodeFlags_DefaultOpen))
26802704
{
2681-
std::lock_guard lock(g_userHeap.mutex);
2682-
diagnostics = o1heapGetDiagnostics(g_userHeap.heap);
2705+
O1HeapDiagnostics diagnostics, physicalDiagnostics;
2706+
{
2707+
std::lock_guard lock(g_userHeap.mutex);
2708+
diagnostics = o1heapGetDiagnostics(g_userHeap.heap);
2709+
}
2710+
{
2711+
std::lock_guard lock(g_userHeap.physicalMutex);
2712+
physicalDiagnostics = o1heapGetDiagnostics(g_userHeap.physicalHeap);
2713+
}
2714+
2715+
if (ImGui::BeginTable("Memory", 2))
2716+
{
2717+
IMGUI_GENERIC_ROW("Heap Allocated", "%d MB", int32_t(diagnostics.allocated / (1024 * 1024)));
2718+
IMGUI_GENERIC_ROW("Physical Heap Allocated", "%d MB", int32_t(diagnostics.allocated / (1024 * 1024)));
2719+
2720+
ImGui::EndTable();
2721+
}
26832722
}
2723+
}
2724+
2725+
if (ImGui::CollapsingHeader("GPU", ImGuiTreeNodeFlags_DefaultOpen))
2726+
{
2727+
std::string backend;
2728+
2729+
switch (g_backend)
26842730
{
2685-
std::lock_guard lock(g_userHeap.physicalMutex);
2686-
physicalDiagnostics = o1heapGetDiagnostics(g_userHeap.physicalHeap);
2731+
case Backend::VULKAN:
2732+
backend = "Vulkan";
2733+
break;
2734+
2735+
case Backend::D3D12:
2736+
backend = "D3D12";
2737+
break;
2738+
2739+
case Backend::METAL:
2740+
backend = "Metal";
2741+
break;
26872742
}
26882743

2689-
ImGui::Text("Heap Allocated: %d MB", int32_t(diagnostics.allocated / (1024 * 1024)));
2690-
ImGui::Text("Physical Heap Allocated: %d MB", int32_t(physicalDiagnostics.allocated / (1024 * 1024)));
2691-
}
2744+
if (ImGui::BeginTable("GPU", 2))
2745+
{
2746+
IMGUI_GENERIC_ROW("API", "%s", backend.c_str());
26922747

2693-
ImGui::Text("GPU Waits: %d", int32_t(g_waitForGPUCount));
2694-
ImGui::Text("Buffer Uploads: %d", int32_t(g_bufferUploadCount));
2695-
ImGui::NewLine();
2748+
if (auto pSDLVideoDriver = SDL_GetCurrentVideoDriver())
2749+
{
2750+
IMGUI_GENERIC_ROW("SDL Video Driver", "%s", pSDLVideoDriver);
2751+
}
26962752

2697-
ImGui::Text("Present Wait: %s", g_capabilities.presentWait ? "Supported" : "Unsupported");
2698-
ImGui::Text("Triangle Fan: %s", g_capabilities.triangleFan ? "Supported" : "Unsupported");
2699-
ImGui::Text("Dynamic Depth Bias: %s", g_capabilities.dynamicDepthBias ? "Supported" : "Unsupported");
2700-
ImGui::Text("Hardware Resolve Modes: %s", g_capabilities.resolveModes ? "Supported" : "Unsupported");
2701-
ImGui::Text("Triangle Strip Workaround: %s", g_triangleStripWorkaround ? "Enabled" : "Disabled");
2702-
ImGui::NewLine();
2753+
IMGUI_GENERIC_ROW("Device", "%s", g_device->getDescription().name.c_str());
2754+
IMGUI_GENERIC_ROW("Device Type", "%s", DeviceTypeName(g_device->getDescription().type));
2755+
IMGUI_GENERIC_ROW("VRAM", "%.2f MiB", (double)(g_device->getDescription().dedicatedVideoMemory) / (1024.0 * 1024.0));
2756+
IMGUI_GENERIC_ROW("GPU Waits", "%d", int32_t(g_waitForGPUCount));
2757+
IMGUI_GENERIC_ROW("Buffer Uploads", "%d", int32_t(g_bufferUploadCount));
27032758

2704-
std::string backend;
2759+
IMGUI_GENERIC_ROW("Resolution", "%dx%d (%dx%d)",
2760+
Video::s_viewportWidth, Video::s_viewportHeight,
2761+
uint32_t(round(Video::s_viewportWidth * Config::ResolutionScale)),
2762+
uint32_t(round(Video::s_viewportHeight * Config::ResolutionScale)));
27052763

2706-
switch (g_backend) {
2707-
case Backend::VULKAN:
2708-
backend = "Vulkan";
2709-
break;
2710-
case Backend::D3D12:
2711-
backend = "D3D12";
2712-
break;
2713-
case Backend::METAL:
2714-
backend = "Metal";
2715-
break;
2716-
}
2764+
ImGui::EndTable();
2765+
}
27172766

2718-
ImGui::Text("API: %s", backend.c_str());
2719-
ImGui::Text("Device: %s", g_device->getDescription().name.c_str());
2720-
ImGui::Text("Device Type: %s", DeviceTypeName(g_device->getDescription().type));
2721-
ImGui::Text("VRAM: %.2f MiB", (double)(g_device->getDescription().dedicatedVideoMemory) / (1024.0 * 1024.0));
2722-
ImGui::Text("UMA: %s", g_capabilities.uma ? "Supported" : "Unsupported");
2723-
ImGui::Text("GPU Upload Heap: %s", g_capabilities.gpuUploadHeap ? "Supported" : "Unsupported");
2767+
ImGui::Separator();
27242768

2725-
const char* sdlVideoDriver = SDL_GetCurrentVideoDriver();
2726-
if (sdlVideoDriver != nullptr)
2727-
ImGui::Text("SDL Video Driver: %s", sdlVideoDriver);
2769+
if (ImGui::TreeNode("Devices"))
2770+
{
2771+
ImGui::Indent();
2772+
2773+
if (ImGui::BeginTable("Devices", 2))
2774+
{
2775+
auto deviceIndex = 0;
27282776

2729-
ImGui::NewLine();
2730-
ImGui::Text("Output Resolution: %d x %d", Video::s_viewportWidth, Video::s_viewportHeight);
2777+
for (const auto& deviceName : g_interface->getDeviceNames())
2778+
{
2779+
ImGui::TableNextColumn();
2780+
ImGui::Text("Device #%d", deviceIndex++);
2781+
ImGui::TableNextColumn();
2782+
ImGui::Text("%s", deviceName.c_str());
2783+
ImGui::SameLine();
2784+
}
27312785

2732-
ImGui::NewLine();
2733-
ImGui::Checkbox("Show FPS", &Config::ShowFPS.Value);
2734-
ImGui::NewLine();
2786+
ImGui::EndTable();
2787+
}
27352788

2736-
if (ImGui::TreeNode("Device Names"))
2737-
{
2738-
ImGui::Indent();
2789+
ImGui::Unindent();
2790+
ImGui::TreePop();
2791+
}
27392792

2740-
uint32_t deviceIndex = 0;
2741-
for (const std::string &deviceName : g_interface->getDeviceNames())
2793+
if (ImGui::TreeNode("Features"))
27422794
{
2743-
ImGui::Text("Option #%d: %s", deviceIndex++, deviceName.c_str());
2744-
}
2795+
ImGui::Indent();
2796+
2797+
if (ImGui::BeginTable("Features", 2))
2798+
{
2799+
IMGUI_GENERIC_ROW("Dynamic Depth Bias", "%s", g_capabilities.dynamicDepthBias ? "Supported" : "Unsupported");
2800+
IMGUI_GENERIC_ROW("GPU Upload Heap", "%s", g_capabilities.gpuUploadHeap ? "Supported" : "Unsupported");
2801+
IMGUI_GENERIC_ROW("Hardware Resolve Modes", "%s", g_capabilities.resolveModes ? "Supported" : "Unsupported");
2802+
IMGUI_GENERIC_ROW("Present Wait", "%s", g_capabilities.presentWait ? "Supported" : "Unsupported");
2803+
IMGUI_GENERIC_ROW("Triangle Fan", "%s", g_capabilities.triangleFan ? "Supported" : "Unsupported");
2804+
IMGUI_GENERIC_ROW("Triangle Strip Workaround", "%s", g_triangleStripWorkaround ? "Enabled" : "Disabled");
2805+
IMGUI_GENERIC_ROW("UMA", "%s", g_capabilities.uma ? "Supported" : "Unsupported");
2806+
2807+
ImGui::EndTable();
2808+
}
27452809

2746-
ImGui::Unindent();
2747-
ImGui::TreePop();
2810+
ImGui::Unindent();
2811+
ImGui::TreePop();
2812+
}
27482813
}
27492814
}
2750-
ImGui::End();
27512815

2816+
#undef IMGUI_GENERIC_ROW
2817+
2818+
ImGui::End();
27522819
ImGui::PopFont();
2820+
27532821
font->Scale = defaultScale;
27542822
}
27552823

0 commit comments

Comments
 (0)