This commit is contained in:
Vaxry 2024-03-18 22:34:41 +00:00
parent db5adea962
commit ea7768203b
2 changed files with 12 additions and 11 deletions

View file

@ -36,7 +36,6 @@ void CFrameSchedulingManager::onFrameNeeded(CMonitor* pMonitor) {
return; return;
} }
DATA->noVblankTimer = true;
onPresent(pMonitor, nullptr); onPresent(pMonitor, nullptr);
} }
@ -52,7 +51,6 @@ void CFrameSchedulingManager::gpuDone(wlr_buffer* pBuffer) {
// delayed frame, let's render immediately, our shit will be presented soon // delayed frame, let's render immediately, our shit will be presented soon
// if we finish rendering before the next vblank somehow, kernel will be mad, but oh well // if we finish rendering before the next vblank somehow, kernel will be mad, but oh well
DATA->noVblankTimer = true;
g_pHyprRenderer->renderMonitor(DATA->pMonitor); g_pHyprRenderer->renderMonitor(DATA->pMonitor);
DATA->delayedFrameSubmitted = true; DATA->delayedFrameSubmitted = true;
} }
@ -97,7 +95,6 @@ void CFrameSchedulingManager::onPresent(CMonitor* pMonitor, wlr_output_event_pre
if (DATA->delayedFrameSubmitted) { if (DATA->delayedFrameSubmitted) {
DATA->delayedFrameSubmitted = false; DATA->delayedFrameSubmitted = false;
DATA->activelyPushing = false;
return; return;
} }
@ -127,18 +124,22 @@ void CFrameSchedulingManager::onPresent(CMonitor* pMonitor, wlr_output_event_pre
} }
// we can't do this on wayland // we can't do this on wayland
if (!wlr_backend_is_wl(pMonitor->output->backend) && !DATA->noVblankTimer && presentationData) { float msUntilVblank = 0;
if (presentationData) {
const std::chrono::system_clock::time_point LASTVBLANK{std::chrono::duration_cast<std::chrono::system_clock::duration>( const std::chrono::system_clock::time_point LASTVBLANK{std::chrono::duration_cast<std::chrono::system_clock::duration>(
std::chrono::seconds{presentationData->when->tv_sec} + std::chrono::nanoseconds{presentationData->when->tv_nsec})}; std::chrono::seconds{presentationData->when->tv_sec} + std::chrono::nanoseconds{presentationData->when->tv_nsec})};
const float MSUNTILVBLANK = (presentationData->refresh ? presentationData->refresh / 1000000.0 : pMonitor->refreshRate / 1000.0) - msUntilVblank = (presentationData->refresh ? presentationData->refresh / 1000000.0 : pMonitor->refreshRate / 1000.0) -
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - LASTVBLANK).count(); std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - LASTVBLANK).count();
} else
msUntilVblank = std::chrono::duration_cast<std::chrono::milliseconds>(DATA->nextVblank - std::chrono::system_clock::now()).count();
if (msUntilVblank > 0) {
wl_event_source_timer_update(DATA->event, 0); wl_event_source_timer_update(DATA->event, 0);
wl_event_source_timer_update(DATA->event, std::floor(MSUNTILVBLANK)); wl_event_source_timer_update(DATA->event, std::floor(msUntilVblank));
} }
renderMonitor(DATA); renderMonitor(DATA);
DATA->noVblankTimer = false;
} }
CFrameSchedulingManager::SSchedulingData* CFrameSchedulingManager::dataFor(CMonitor* pMonitor) { CFrameSchedulingManager::SSchedulingData* CFrameSchedulingManager::dataFor(CMonitor* pMonitor) {

View file

@ -43,9 +43,6 @@ class CFrameSchedulingManager {
// whether the frame was submitted from gpuDone // whether the frame was submitted from gpuDone
bool delayedFrameSubmitted = false; bool delayedFrameSubmitted = false;
// don't plant a vblank timer
bool noVblankTimer = false;
// we need to render a few full frames at the beginning to catch all buffers // we need to render a few full frames at the beginning to catch all buffers
int forceFrames = 5; int forceFrames = 5;
@ -64,6 +61,9 @@ class CFrameSchedulingManager {
// legacy scheduler: for backends that do not send us reliable present events // legacy scheduler: for backends that do not send us reliable present events
// these rely on onFrame // these rely on onFrame
bool legacyScheduler = false; bool legacyScheduler = false;
// next predicted vblank
std::chrono::system_clock::time_point nextVblank;
}; };
std::vector<SSchedulingData> m_vSchedulingData; std::vector<SSchedulingData> m_vSchedulingData;