Developer knowledge network · moderated exchange

Супольнасць UnreliableCode

Супольнасць распрацоўшчыкаў даследаванняў, зваротнага праектавання і кадавання

Knowledge indexжыць
4Categories
919Threads
2.8KПаведамленні
Guide

High-Precision 144Hz Frame Rate Limiter using QueryPerformanceCounter & Yield [v2.4 Technical Discussion]

imgui_artisan
UI Designer
MEMBER
прадстаўнік: 202
Дата далучэння: Apr 2019
Паведамленні: 54
Дзякуй: 28
3 тыдняў таму · Jul 27, 2026 2:20 PM
#1

Why standard Sleep(1) causes overlay stuttering:

Standard Windows Sleep() has a default timer resolution of 15.6ms, causing erratic 45-80 FPS spikes on 144Hz monitors.

Hybrid Precision Frame Limiter:

CPP
void SyncFrameRate(int targetFps) {
    static LARGE_INTEGER freq, lastTime;
    if (freq.QuadPart == 0) { QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&lastTime); }
    
    double targetInterval = 1.0 / targetFps;
    LARGE_INTEGER curTime;
    QueryPerformanceCounter(&curTime);
    double elapsed = (double)(curTime.QuadPart - lastTime.QuadPart) / freq.QuadPart;
    
    // Coarse sleep if plenty of time remains, then spin-wait last 0.5ms
    while (elapsed < targetInterval) {
        if (targetInterval - elapsed > 0.002) Sleep(1);
        else _mm_pause(); // Low-latency CPU pause
        QueryPerformanceCounter(&curTime);
        elapsed = (double)(curTime.QuadPart - lastTime.QuadPart) / freq.QuadPart;
    }
    lastTime = curTime;
}
ptr_arithmetic
C++ Wizard
MEMBER
прадстаўнік: 162
Дата далучэння: May 2018
Паведамленні: 73
Дзякуй: 42
3 тыдняў таму · Jul 27, 2026 5:38 PM
#2

Combining Sleep(1) for coarse wait with _mm_pause() for fine microsecond alignment locks frame time to exactly 6.94ms (144 FPS) with 0% CPU spike!

matrix_math_guy
Math Specialist
MEMBER
прадстаўнік: 105
Дата далучэння: Aug 2018
Паведамленні: 52
Дзякуй: 41
3 тыдняў таму · Jul 28, 2026 12:44 AM
#3

Silky smooth overlay rendering.