Fix periodic events drifting when eating cycles.

Need to set the next timer before rescheduling threads or etc.
This commit is contained in:
Unknown W. Brackets 2014-07-01 00:25:20 -07:00
parent e9fd43b947
commit 5cd4a17e88
4 changed files with 11 additions and 6 deletions

View File

@ -83,16 +83,18 @@ static inline s16 adjustvolume(s16 sample, int vol) {
}
void hleAudioUpdate(u64 userdata, int cyclesLate) {
__AudioUpdate();
// Schedule the next cycle first. __AudioUpdate() may consume cycles.
CoreTiming::ScheduleEvent(usToCycles(audioIntervalUs) - cyclesLate, eventAudioUpdate, 0);
__AudioUpdate();
}
void hleHostAudioUpdate(u64 userdata, int cyclesLate) {
CoreTiming::ScheduleEvent(usToCycles(audioHostIntervalUs) - cyclesLate, eventHostAudioUpdate, 0);
// Not all hosts need this call to poke their audio system once in a while, but those that don't
// can just ignore it.
host->UpdateSound();
CoreTiming::ScheduleEvent(usToCycles(audioHostIntervalUs) - cyclesLate, eventHostAudioUpdate, 0);
}
void __AudioInit() {

View File

@ -289,8 +289,9 @@ void __CtrlTimerUpdate(u64 userdata, int cyclesLate)
// This only runs in timer mode (ctrlCycle > 0.)
_dbg_assert_msg_(SCECTRL, ctrlCycle > 0, "Ctrl: sampling cycle should be > 0");
__CtrlDoSample();
CoreTiming::ScheduleEvent(usToCycles(ctrlCycle), ctrlTimer, 0);
__CtrlDoSample();
}
void __CtrlInit()

View File

@ -602,6 +602,8 @@ void hleEnterVblank(u64 userdata, int cyclesLate) {
}
frameStartTicks = CoreTiming::GetTicks();
CoreTiming::ScheduleEvent(msToCycles(vblankMs) - cyclesLate, leaveVblankEvent, vbCount + 1);
// Wake up threads waiting for VBlank
u32 error;
bool wokeThreads = false;
@ -623,8 +625,6 @@ void hleEnterVblank(u64 userdata, int cyclesLate) {
// Trigger VBlank interrupt handlers.
__TriggerInterrupt(PSP_INTR_IMMEDIATE | PSP_INTR_ONLY_IF_ENABLED | PSP_INTR_ALWAYS_RESCHED, PSP_VBLANK_INTR, PSP_INTR_SUB_ALL);
CoreTiming::ScheduleEvent(msToCycles(vblankMs) - cyclesLate, leaveVblankEvent, vbCount + 1);
gpuStats.numVBlanks++;
numVBlanksSinceFlip++;

View File

@ -264,6 +264,8 @@ void __GeCheckCycles(u64 userdata, int cyclesLate)
CoreTiming::Advance();
}
}
// This may get out of step if we synced, but that's okay.
CoreTiming::ScheduleEvent(usToCycles(geIntervalUs), geCycleEvent, 0);
}