2

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?

Danny
  • 9,199
  • 16
  • 53
  • 75

3 Answers3

2

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

default
  • 2,637
  • 21
  • 44
0

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.

jameswilddev
  • 582
  • 7
  • 16
  • Thanks for the reply. I don't know how you turn off desktop composition, but I changed it to Windows 7 Basic, and the problem still occurs - still getting around 60FPS – Danny May 31 '13 at 11:31
  • Some drivers offer the ability to force VSync. Is there anything in your nVidia Control Panel/AMD/ATi/Intel equivalent? – jameswilddev May 31 '13 at 11:48
  • I am using a nVidia Graphics card and I did use the Control Panel to turn off VSync – Danny May 31 '13 at 12:16
  • In this case I consider it likely that the vsync is not being disabled properly. How are you doing this? – jameswilddev May 31 '13 at 12:21
  • NVIDIA Control Panel > Manage 3D Settings > Global Settings > Vertical Sync (off) – Danny May 31 '13 at 12:33
  • I meant in your application; the code that says to DirectX "I want VSync off". I believe the nVidia Control Panel only affects OpenGL looking at it. – jameswilddev May 31 '13 at 12:35
  • ahhh ok. I didn't know about that - So I didnt do it lol. So how do I do this? How do I tell DirectX to turn VSync off? – Danny May 31 '13 at 12:38
  • http://msdn.microsoft.com/en-gb/library/windows/desktop/bb174349%28v=vs.85%29.aspx Try this. – jameswilddev May 31 '13 at 12:42
-2

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

Hido
  • 49
  • 13