This commit is contained in:
Бранимир Караџић 2019-01-06 17:15:56 -08:00
parent 2cd8c6c2b0
commit 9d211e2ee4
1 changed files with 56 additions and 39 deletions

View File

@ -9,53 +9,63 @@
#include <bx/string.h> #include <bx/string.h>
#include <bx/timer.h> #include <bx/timer.h>
#include <bx/math.h> #include <bx/math.h>
#include <string>
#define SAMPLE_COUNT 100
struct SampleData struct SampleData
{ {
static constexpr uint32_t kNumSamples = 100;
SampleData()
{
reset();
}
void reset()
{
m_offset = 0;
bx::memSet(m_values, 0, sizeof(m_values) );
}
void pushSample(float value) void pushSample(float value)
{ {
values[offset] = value; m_values[m_offset] = value;
offset = (offset+1) % SAMPLE_COUNT; m_offset = (m_offset+1) % kNumSamples;
float min = bx::kFloatMax;
float max = -bx::kFloatMax;
float avg = 0.0f;
for (uint32_t ii = 0; ii < kNumSamples; ++ii)
{
const float val = m_values[ii];
min = bx::min(min, val);
max = bx::max(max, val);
avg += val;
}
m_avg = avg / kNumSamples;
} }
float getMin() const float getMin() const
{ {
float minValue = FLT_MAX; return m_min;
for(size_t i = 0; i < SAMPLE_COUNT; ++i)
{
minValue = bx::min(minValue, values[i]);
}
return minValue;
} }
float getMax() const float getMax() const
{ {
float maxValue = -FLT_MAX; return m_max;
for(size_t i = 0; i < SAMPLE_COUNT; ++i)
{
maxValue = bx::max(maxValue, values[i]);
}
return maxValue;
} }
float getAvg() const float getAvg() const
{ {
float avgValue = 0; return m_avg;
for(size_t i = 0; i < SAMPLE_COUNT; ++i)
{
avgValue += values[i];
}
return avgValue / SAMPLE_COUNT;
} }
int32_t m_offset;
float m_values[kNumSamples];
int offset = 0; float m_min = bx::kFloatMax;
float values[SAMPLE_COUNT] = {0}; float m_max = bx::kFloatMax;
float m_avg = bx::kFloatMax;
}; };
static SampleData s_frameTime; static SampleData s_frameTime;
@ -130,7 +140,7 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText)
, ImGuiCond_FirstUseEver , ImGuiCond_FirstUseEver
); );
ImGui::SetNextWindowSize( ImGui::SetNextWindowSize(
ImVec2(300.0f, 220.0f) ImVec2(300.0f, 210.0f)
, ImGuiCond_FirstUseEver , ImGuiCond_FirstUseEver
); );
@ -280,23 +290,30 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText)
const double toMsGpu = 1000.0/stats->gpuTimerFreq; const double toMsGpu = 1000.0/stats->gpuTimerFreq;
const double frameMs = double(stats->cpuTimeFrame)*toMsCpu; const double frameMs = double(stats->cpuTimeFrame)*toMsCpu;
s_frameTime.pushSample(float(frameMs)); s_frameTime.pushSample(float(frameMs) );
const float frameMsAvg = s_frameTime.getAvg(); const float frameMsAvg = s_frameTime.getAvg();
std::string frameTextOverlay; char frameTextOverlay[256];
bx::stringPrintf(frameTextOverlay, "%s%.3fms, %s%.3fms\nAvg: %.3fms, %.1f FPS" bx::snprintf(frameTextOverlay, BX_COUNTOF(frameTextOverlay), "%s%.3fms, %s%.3fms\nAvg: %.3fms, %.1f FPS"
, ICON_FA_ARROW_UP, s_frameTime.getMax() , ICON_FA_ARROW_UP
, ICON_FA_ARROW_DOWN, s_frameTime.getMin() , s_frameTime.getMax()
, frameMsAvg, 1000.0/frameMsAvg , ICON_FA_ARROW_DOWN
); , s_frameTime.getMin()
, frameMsAvg
, 1000.0/frameMsAvg
);
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImColor(0.0f,0.5f,0.15f,1.0f).Value); ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImColor(0.0f,0.5f,0.15f,1.0f).Value);
ImGui::PlotHistogram("Frame", s_frameTime.values ImGui::PlotHistogram("Frame"
, SAMPLE_COUNT, s_frameTime.offset , s_frameTime.m_values
, frameTextOverlay.c_str() , SampleData::kNumSamples
, 0.0f, 60.0f, ImVec2(0, 45) , s_frameTime.m_offset
); , frameTextOverlay
, 0.0f
, 60.0f
, ImVec2(0, 45)
);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::Text("Submit CPU %0.3f, GPU %0.3f (L: %d)" ImGui::Text("Submit CPU %0.3f, GPU %0.3f (L: %d)"