Skip to content

Commit 2bd899b

Browse files
committed
WIP: CPU and GPU Time include everything
1 parent 987e796 commit 2bd899b

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

Core/Source/Lux/ImGui/ImGuiRenderer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Lux {
3636

3737
auto device = Application::GetGraphicsDevice();
3838

39-
m_RenderCommandBuffer = RenderCommandBuffer::Create(0, "ImGuiRenderer");
39+
m_RenderCommandBuffer = RenderCommandBuffer::Create(0, "ImGuiRenderer", true);
4040

4141
Ref<Shader> imguiShader = Renderer::GetShaderLibrary()->Get("ImGui");
4242
m_VertexShader = imguiShader->GetHandle(nvrhi::ShaderType::Vertex);
@@ -523,6 +523,11 @@ namespace Lux {
523523
swapchain->GetAcquiredImageSemaphore());
524524
}
525525

526+
float ImGuiRenderer::GetGPUTime(uint32_t frameIndex) const
527+
{
528+
return m_RenderCommandBuffer ? m_RenderCommandBuffer->GetExecutionGPUTime(frameIndex) : 0.0f;
529+
}
530+
526531
void ImGuiRenderer::BackbufferResizing()
527532
{
528533
m_PipelineCache.clear();

Core/Source/Lux/ImGui/ImGuiRenderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ namespace Lux
161161
bool Render(ImGuiViewport* viewport, nvrhi::GraphicsPipelineHandle pipeline, nvrhi::FramebufferHandle framebuffer, VkSemaphore waitSemaphore = nullptr);
162162
bool RenderToSwapchain(ImGuiViewport* viewport, VulkanSwapChain* swapchain);
163163
void BackbufferResizing();
164+
float GetGPUTime(uint32_t frameIndex) const;
164165

165166
// Register a persistent texture (indices 0-63) - survives across frames.
166167
ImTextureID RegisterPersistentTexture(nvrhi::ITexture* texture,

Editor/Source/EditorLayer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,14 @@ namespace Lux {
959959
const float fps = io.Framerate;
960960
const float frameTimeMs = fps > 0.0f ? 1000.0f / fps : 0.0f;
961961
const float renderScale = m_SceneRenderer->GetRenderResolutionScale() * 100.0f;
962+
const auto& appTimers = Application::Get().GetPerformanceTimers();
963+
const float wholeCPUTime = appTimers.MainThreadWorkTime + appTimers.RenderThreadWorkTime;
964+
float wholeGPUTime = stats.TotalGPUTime;
965+
if (ImGuiLayer* imguiLayer = Application::Get().GetImGuiLayer())
966+
{
967+
if (ImGuiRenderer* imguiRenderer = imguiLayer->GetImGuiRenderer())
968+
wholeGPUTime += imguiRenderer->GetGPUTime(Renderer::GetCurrentFrameIndex());
969+
}
962970

963971
const ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking |
964972
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize |
@@ -969,7 +977,7 @@ namespace Lux {
969977
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.0f, 6.0f));
970978
ImGui::Begin("##viewport_performance_hud", nullptr, flags);
971979
ImGui::Text("FPS %.0f %.2f ms", fps, frameTimeMs);
972-
ImGui::Text("CPU %.2f ms GPU %.2f ms", stats.TotalCPUTime, stats.TotalGPUTime);
980+
ImGui::Text("CPU %.2f ms GPU %.2f ms", wholeCPUTime, wholeGPUTime);
973981
ImGui::Text("Draws %u Visible %u", stats.DrawCalls, stats.VisibleInstances);
974982
ImGui::Text("GPU Visible %u", stats.GPUVisibleInstances);
975983
if (memory.BudgetBytes > 0)

0 commit comments

Comments
 (0)