fps display
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
#include "Instance.h"
|
||||
#include "Mesh.h"
|
||||
#include "Tools.h"
|
||||
#include "bx/timer.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr int32_t FrameTimeBufSize = 512;
|
||||
int64_t FrameTimes[FrameTimeBufSize]{0};
|
||||
int32_t FrameTimeIdx = 0;
|
||||
} // namespace
|
||||
|
||||
namespace Tools
|
||||
{
|
||||
const char* GetAssetPath(Generated::AssetHandle assetHandle)
|
||||
@@ -337,10 +345,35 @@ namespace Tools
|
||||
{
|
||||
auto& drawList = *ImGui::GetWindowDrawList();
|
||||
ImVec2 pos = ImGui::GetWindowPos();
|
||||
drawList.AddRectFilled(pos, {pos.x + FpsPlotSize.x, pos.y + FpsPlotSize.y}, 0xFFFFFF33);
|
||||
drawList.AddRectFilled(pos, {pos.x + FpsPlotSize.x, pos.y + FpsPlotSize.y}, 0x22222233);
|
||||
|
||||
float scale = 1000.0f;
|
||||
|
||||
for (int32_t i = 0; i < FrameTimeBufSize; ++i)
|
||||
{
|
||||
int32_t idx = FrameTimeIdx - i - 1;
|
||||
int32_t prevIdx = idx - 1;
|
||||
if (idx < 0) idx += FrameTimeBufSize;
|
||||
if (prevIdx < 0) prevIdx += FrameTimeBufSize;
|
||||
|
||||
if (FrameTimes[idx] == 0 || FrameTimes[prevIdx] == 0) continue;
|
||||
|
||||
int64_t frameTime = FrameTimes[idx] - FrameTimes[prevIdx];
|
||||
double frameTimeSec = (double)frameTime / bx::getHPFrequency();
|
||||
drawList.AddLine(
|
||||
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y},
|
||||
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y - (float)frameTimeSec * scale},
|
||||
0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
void MeasureFrameEnd()
|
||||
{
|
||||
FrameTimes[FrameTimeIdx] = bx::getHPCounter();
|
||||
++FrameTimeIdx;
|
||||
if (FrameTimeIdx >= FrameTimeBufSize) FrameTimeIdx = 0;
|
||||
}
|
||||
} // namespace Tools
|
||||
|
||||
Reference in New Issue
Block a user