summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorMai <mathew1800@gmail.com>2022-08-03 14:30:29 -0400
committerGitHub <noreply@github.com>2022-08-03 14:30:29 -0400
commita8b2174ce670de151bd991e6bfa89438d8ff0185 (patch)
treebc5110b1796e293276ce21511bd84578d91e665b /Source/Core/VideoCommon
parent173337104f9001c2d186db9303ea34652a94c191 (diff)
parentfec61f89a3bce9bf857a15ed4789629624e66584 (diff)
Merge pull request #10872 from shuffle2/timer
Timer improvements
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/FPSCounter.cpp8
-rw-r--r--Source/Core/VideoCommon/HiresTextures.cpp6
-rw-r--r--Source/Core/VideoCommon/OnScreenDisplay.cpp16
-rw-r--r--Source/Core/VideoCommon/PostProcessing.cpp2
-rw-r--r--Source/Core/VideoCommon/RenderBase.cpp4
5 files changed, 18 insertions, 18 deletions
diff --git a/Source/Core/VideoCommon/FPSCounter.cpp b/Source/Core/VideoCommon/FPSCounter.cpp
index 459856d1ef..e38305eb7f 100644
--- a/Source/Core/VideoCommon/FPSCounter.cpp
+++ b/Source/Core/VideoCommon/FPSCounter.cpp
@@ -16,7 +16,7 @@ static constexpr u64 FPS_REFRESH_INTERVAL_US = 250000;
FPSCounter::FPSCounter()
{
- m_last_time = Common::Timer::GetTimeUs();
+ m_last_time = Common::Timer::NowUs();
m_on_state_changed_handle = Core::AddOnStateChangedCallback([this](Core::State state) {
if (state == Core::State::Paused)
@@ -44,7 +44,7 @@ void FPSCounter::LogRenderTimeToFile(u64 val)
void FPSCounter::Update()
{
- const u64 time = Common::Timer::GetTimeUs();
+ const u64 time = Common::Timer::NowUs();
const u64 diff = time - m_last_time;
m_time_diff_secs = static_cast<double>(diff / 1000000.0);
if (g_ActiveConfig.bLogRenderTimeToFile)
@@ -66,11 +66,11 @@ void FPSCounter::SetPaused(bool paused)
{
if (paused)
{
- m_last_time_pause = Common::Timer::GetTimeUs();
+ m_last_time_pause = Common::Timer::NowUs();
}
else
{
- const u64 time = Common::Timer::GetTimeUs();
+ const u64 time = Common::Timer::NowUs();
const u64 diff = time - m_last_time_pause;
m_last_time += diff;
}
diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp
index 9636bfe651..f3d6d77373 100644
--- a/Source/Core/VideoCommon/HiresTextures.cpp
+++ b/Source/Core/VideoCommon/HiresTextures.cpp
@@ -159,7 +159,8 @@ void HiresTexture::Prefetch()
const size_t max_mem =
(sys_mem / 2 < recommended_min_mem) ? (sys_mem / 2) : (sys_mem - recommended_min_mem);
- const u32 start_time = Common::Timer::GetTimeMs();
+ Common::Timer timer;
+ timer.Start();
for (const auto& entry : s_textureMap)
{
const std::string& base_filename = entry.first;
@@ -207,9 +208,8 @@ void HiresTexture::Prefetch()
}
}
- const u32 stop_time = Common::Timer::GetTimeMs();
OSD::AddMessage(fmt::format("Custom Textures loaded, {:.1f} MB in {:.1f}s",
- size_sum / (1024.0 * 1024.0), (stop_time - start_time) / 1000.0),
+ size_sum / (1024.0 * 1024.0), timer.ElapsedMs() / 1000.0),
10000);
}
diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp
index 4bc7cd9494..e860c53ec0 100644
--- a/Source/Core/VideoCommon/OnScreenDisplay.cpp
+++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp
@@ -32,12 +32,14 @@ static std::atomic<int> s_obscured_pixels_top = 0;
struct Message
{
Message() = default;
- Message(std::string text_, u32 timestamp_, u32 duration_, u32 color_)
- : text(std::move(text_)), timestamp(timestamp_), duration(duration_), color(color_)
+ Message(std::string text_, u32 duration_, u32 color_)
+ : text(std::move(text_)), duration(duration_), color(color_)
{
+ timer.Start();
}
+ s64 TimeRemaining() const { return duration - timer.ElapsedMs(); }
std::string text;
- u32 timestamp = 0;
+ Common::Timer timer;
u32 duration = 0;
bool ever_drawn = false;
u32 color = 0;
@@ -93,20 +95,18 @@ void AddTypedMessage(MessageType type, std::string message, u32 ms, u32 argb)
{
std::lock_guard lock{s_messages_mutex};
s_messages.erase(type);
- s_messages.emplace(type, Message(std::move(message), Common::Timer::GetTimeMs() + ms, ms, argb));
+ s_messages.emplace(type, Message(std::move(message), ms, argb));
}
void AddMessage(std::string message, u32 ms, u32 argb)
{
std::lock_guard lock{s_messages_mutex};
- s_messages.emplace(MessageType::Typeless,
- Message(std::move(message), Common::Timer::GetTimeMs() + ms, ms, argb));
+ s_messages.emplace(MessageType::Typeless, Message(std::move(message), ms, argb));
}
void DrawMessages()
{
const bool draw_messages = Config::Get(Config::MAIN_OSD_MESSAGES);
- const u32 now = Common::Timer::GetTimeMs();
const float current_x =
LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x + s_obscured_pixels_left;
float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y + s_obscured_pixels_top;
@@ -117,7 +117,7 @@ void DrawMessages()
for (auto it = s_messages.begin(); it != s_messages.end();)
{
Message& msg = it->second;
- const int time_left = static_cast<int>(msg.timestamp - now);
+ const s64 time_left = msg.TimeRemaining();
// Make sure we draw them at least once if they were printed with 0ms,
// unless enough time has expired, in that case, we drop them
diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp
index 72ee15a776..69e4327bdd 100644
--- a/Source/Core/VideoCommon/PostProcessing.cpp
+++ b/Source/Core/VideoCommon/PostProcessing.cpp
@@ -640,7 +640,7 @@ void PostProcessing::FillUniformBuffer(const MathUtil::Rectangle<int>& src,
static_cast<float>(src.GetWidth()) * rcp_src_width,
static_cast<float>(src.GetHeight()) * rcp_src_height},
static_cast<s32>(src_layer),
- static_cast<u32>(m_timer.GetTimeElapsed()),
+ static_cast<u32>(m_timer.ElapsedMs()),
};
u8* buf = m_uniform_staging_buffer.data();
diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp
index 412461d409..e51307fa15 100644
--- a/Source/Core/VideoCommon/RenderBase.cpp
+++ b/Source/Core/VideoCommon/RenderBase.cpp
@@ -1066,7 +1066,7 @@ bool Renderer::InitializeImGui()
if (!RecompileImGuiPipeline())
return false;
- m_imgui_last_frame_time = Common::Timer::GetTimeUs();
+ m_imgui_last_frame_time = Common::Timer::NowUs();
BeginImGuiFrame();
return true;
}
@@ -1139,7 +1139,7 @@ void Renderer::BeginImGuiFrame()
{
std::unique_lock<std::mutex> imgui_lock(m_imgui_mutex);
- const u64 current_time_us = Common::Timer::GetTimeUs();
+ const u64 current_time_us = Common::Timer::NowUs();
const u64 time_diff_us = current_time_us - m_imgui_last_frame_time;
const float time_diff_secs = static_cast<float>(time_diff_us / 1000000.0);
m_imgui_last_frame_time = current_time_us;