通用 Windows 平台 Direct3D C++ 应用程序上的 60 FPS 游戏循环

60 FPS Game Loop on Universal Windows Platform Direct3D C++ App

windows 的 C++ 方面相当新 - 特殊的非 Win32,例如 UWP -

我试图通过每 1000/60 毫秒简单地勾选 (Update/Render) 将 FPS 限制在稳定的 60 FPS。我面临着一个奇怪的情况。如果我使用 Present(0,0),交换链将自动锁定和垂直同步,一切都很好。如果我使用 Present1(0,DXGI_PRESENT_DO_NOT_WAIT, ¶ms) ...我达到了 600 FPS...

现在,在释放 FPS (600) 的同时,我想实现自己的自动收报机。到目前为止我有:

bool Ticker::Tick() {

    long currentTick = GetTickCount64();
    long deltaTicks = (currentTick - gLastTick);
    bool tick = false;

    // determine whether it is tick time
    if (deltaTicks >= gUpdateTime) {
        gLastTick = currentTick;
        gTicksCount++;
        char buf[256];
        sprintf_s(buf, "Current delta: %30d\n", deltaTicks);
        OutputDebugStringA(buf);
        tick = true;
    }

    // this metric must happen regardless of actual true Ticks
    if (currentTick - gSecondTime >= 1000) {
        gCurrentFrameRate = gTicksCount;
        gSecondTime = currentTick;
        OutputDebugStringW(L"Second is up\n");
        gTicksCount = 0;
    }

    return tick;
}

不用说这不起作用...当我的目标刷新率非常高时达到 20/21 FPS。

我相信我犯了一个相当愚蠢的错误,但我看不出在哪里。

谢谢。

来自文档:

The resolution of the GetTickCount64 function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds.

所以1000/60 ~ 15ms,计数器分辨率不够