summaryrefslogtreecommitdiff
path: root/src/core/hw/gpu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hw/gpu.cpp')
-rw-r--r--src/core/hw/gpu.cpp41
1 files changed, 1 insertions, 40 deletions
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index fa8c13d36..42809c731 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -8,17 +8,13 @@
8#include "common/color.h" 8#include "common/color.h"
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/logging/log.h" 10#include "common/logging/log.h"
11#include "common/math_util.h"
12#include "common/microprofile.h" 11#include "common/microprofile.h"
13#include "common/thread.h"
14#include "common/timer.h"
15#include "common/vector_math.h" 12#include "common/vector_math.h"
16#include "core/core_timing.h" 13#include "core/core_timing.h"
17#include "core/hle/service/gsp_gpu.h" 14#include "core/hle/service/gsp_gpu.h"
18#include "core/hw/gpu.h" 15#include "core/hw/gpu.h"
19#include "core/hw/hw.h" 16#include "core/hw/hw.h"
20#include "core/memory.h" 17#include "core/memory.h"
21#include "core/settings.h"
22#include "core/tracer/recorder.h" 18#include "core/tracer/recorder.h"
23#include "video_core/command_processor.h" 19#include "video_core/command_processor.h"
24#include "video_core/debug_utils/debug_utils.h" 20#include "video_core/debug_utils/debug_utils.h"
@@ -32,19 +28,9 @@ namespace GPU {
32Regs g_regs; 28Regs g_regs;
33 29
34/// 268MHz CPU clocks / 60Hz frames per second 30/// 268MHz CPU clocks / 60Hz frames per second
35const u64 frame_ticks = BASE_CLOCK_RATE_ARM11 / 60; 31const u64 frame_ticks = BASE_CLOCK_RATE_ARM11 / SCREEN_REFRESH_RATE;
36/// Event id for CoreTiming 32/// Event id for CoreTiming
37static int vblank_event; 33static int vblank_event;
38/// Total number of frames drawn
39static u64 frame_count;
40/// Start clock for frame limiter
41static u32 time_point;
42/// Total delay caused by slow frames
43static float time_delay;
44constexpr float FIXED_FRAME_TIME = 1000.0f / 60;
45// Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher
46// values increases time needed to limit frame rate after spikes
47constexpr float MAX_LAG_TIME = 18;
48 34
49template <typename T> 35template <typename T>
50inline void Read(T& var, const u32 raw_addr) { 36inline void Read(T& var, const u32 raw_addr) {
@@ -522,24 +508,8 @@ template void Write<u32>(u32 addr, const u32 data);
522template void Write<u16>(u32 addr, const u16 data); 508template void Write<u16>(u32 addr, const u16 data);
523template void Write<u8>(u32 addr, const u8 data); 509template void Write<u8>(u32 addr, const u8 data);
524 510
525static void FrameLimiter() {
526 time_delay += FIXED_FRAME_TIME;
527 time_delay = MathUtil::Clamp(time_delay, -MAX_LAG_TIME, MAX_LAG_TIME);
528 s32 desired_time = static_cast<s32>(time_delay);
529 s32 elapsed_time = static_cast<s32>(Common::Timer::GetTimeMs() - time_point);
530
531 if (elapsed_time < desired_time) {
532 Common::SleepCurrentThread(desired_time - elapsed_time);
533 }
534
535 u32 frame_time = Common::Timer::GetTimeMs() - time_point;
536
537 time_delay -= frame_time;
538}
539
540/// Update hardware 511/// Update hardware
541static void VBlankCallback(u64 userdata, int cycles_late) { 512static void VBlankCallback(u64 userdata, int cycles_late) {
542 frame_count++;
543 VideoCore::g_renderer->SwapBuffers(); 513 VideoCore::g_renderer->SwapBuffers();
544 514
545 // Signal to GSP that GPU interrupt has occurred 515 // Signal to GSP that GPU interrupt has occurred
@@ -550,12 +520,6 @@ static void VBlankCallback(u64 userdata, int cycles_late) {
550 Service::GSP::SignalInterrupt(Service::GSP::InterruptId::PDC0); 520 Service::GSP::SignalInterrupt(Service::GSP::InterruptId::PDC0);
551 Service::GSP::SignalInterrupt(Service::GSP::InterruptId::PDC1); 521 Service::GSP::SignalInterrupt(Service::GSP::InterruptId::PDC1);
552 522
553 if (!Settings::values.use_vsync && Settings::values.toggle_framelimit) {
554 FrameLimiter();
555 }
556
557 time_point = Common::Timer::GetTimeMs();
558
559 // Reschedule recurrent event 523 // Reschedule recurrent event
560 CoreTiming::ScheduleEvent(frame_ticks - cycles_late, vblank_event); 524 CoreTiming::ScheduleEvent(frame_ticks - cycles_late, vblank_event);
561} 525}
@@ -590,9 +554,6 @@ void Init() {
590 framebuffer_sub.color_format.Assign(Regs::PixelFormat::RGB8); 554 framebuffer_sub.color_format.Assign(Regs::PixelFormat::RGB8);
591 framebuffer_sub.active_fb = 0; 555 framebuffer_sub.active_fb = 0;
592 556
593 frame_count = 0;
594 time_point = Common::Timer::GetTimeMs();
595
596 vblank_event = CoreTiming::RegisterEvent("GPU::VBlankCallback", VBlankCallback); 557 vblank_event = CoreTiming::RegisterEvent("GPU::VBlankCallback", VBlankCallback);
597 CoreTiming::ScheduleEvent(frame_ticks, vblank_event); 558 CoreTiming::ScheduleEvent(frame_ticks, vblank_event);
598 559