Turned off VSync but still getting 60FPS in my DirectX 9 application

心已入冬 提交于 2019-12-08 05:43:53

问题


I have an DirectX9 application which only renders a triangle on the screen, but I am getting a frame rate of 60 FPS no matter if I've got VSync on or not. Why is this?

Here is the code I've done to calculate the FPS, but I dont know if this is the problem to it.

GameTimer.h

#pragma once

#include "Windows.h"

class GameTimer {
public:
    GameTimer();
    ~GameTimer(){}

    void Update();

    float GetFrameTime();

    inline float GetFramePerSec(){return framesPerSec;}
    inline float GetMillSecPerFrame(){return millSecPerFrame;}

private:
    float secsPerCount;
    _int64 prevTimeStamp;

    float framesPerSec;
    float millSecPerFrame;
};

GameTimer.cpp

#include "GameTimer.h"

GameTimer::GameTimer()  {

    _int64 countsPerSec = 0;
    QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
    secsPerCount = 1.0f / (float)countsPerSec;

    prevTimeStamp = 0;
    QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);

    framesPerSec = 0.0f;
    millSecPerFrame = 0.0f;
}

void GameTimer::Update()
{
    static float numFrames = 0.0f;
    static float timeElapsed = 0.0f;

    numFrames += 1.0f;
    timeElapsed += GetFrameTime();

    if(timeElapsed >= 1.0f)
    {
        framesPerSec = numFrames;
        millSecPerFrame = 1000.0f / numFrames;

        numFrames = 0;
        timeElapsed = 0;
    }
}

float GameTimer::GetFrameTime() {
    _int64 currentTimeStamp = 0;
    QueryPerformanceCounter((LARGE_INTEGER*)&currentTimeStamp);
    float timeDiff = (currentTimeStamp - prevTimeStamp) * secsPerCount;
    prevTimeStamp = currentTimeStamp;

    return timeDiff;
}

Knowing that it's only a triangle on the screen (no complicated stuff being drawn), it should render over 1000 frames per second if I have VSync off shouldn't it?


回答1:


In the CreateDevice call, set the PresentationInterval of the D3DPRESENT_PARAMETERS parameter to D3DPRESENT_INTERVAL_IMMEDIATE.




回答2:


If you're under Windows, is the framerate still limited if you change your theme to Windows 7 Basic? (turn off desktop composition) I think the DWM enforces VSync in a lot of scenarios, some older software that forces a buffer flip often takes ages to redraw its window content.




回答3:


You got the limit of the monitor it self, which means that the GPU maybe can executes in 1000FPS but the monitor show it on 60FPS



来源:https://stackoverflow.com/questions/16856115/turned-off-vsync-but-still-getting-60fps-in-my-directx-9-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!