Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unusual CPU readings relating to vertical sync/frame rate limit [solved]  (Read 3430 times)

0 Members and 1 Guest are viewing this topic.

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Wow!  Two posts in one day, that must be a record!

Today I've been learning a little about Vertex Arrays and in my testing I came across something I've noticed before, but narrowed it down to a minimal example so I can ask what it's all about (it has nothing to do with Vertex Arrays though).

Here's some code:

#include <SFML\Graphics.hpp>
#include "Random.h"

int main()
{
    sf::RenderWindow App(sf::VideoMode(1024, 768, 32), "SFML");

        App.EnableVerticalSync(true);
        //App.SetFramerateLimit(60);

        const unsigned int NOOF_DOTS = 128;

        sf::VertexArray dots(sf::Quads, NOOF_DOTS * 4);

        for (int i=0; i<NOOF_DOTS*4; i+=4)
        {
                Random gen;

                float x = gen.randomF(0,1024);
                float y = gen.randomF(0,768);

                dots[i]  .Position = sf::Vector2f( x,   y   );
                dots[i+1].Position = sf::Vector2f( x,   y+2 );
                dots[i+2].Position = sf::Vector2f( x+2, y+2 );
                dots[i+3].Position = sf::Vector2f( x+2, y   );
        }

        while (App.IsOpen())
        {
                sf::Event Event;
                while (App.PollEvent(Event))
                {
                        if (Event.Type == sf::Event::Closed)
                                App.Close();
                }

                App.Clear();
                App.Draw (dots);
                App.Display();
        }

        return EXIT_SUCCESS;
}

NOTE 1: The 'Random' thing is just a little class I made to replace the old 1.6 Randomizer, it isn't really necessary.
NOTE 2: Running SFML2 from the Release .exe
NOTE 3: The snapshot I'm using is one just prior to the naming convention change.

The purpose of this test is simply to throw lots of tiny squares on the screen as a prelude to using this new aspect of SFML2 in a particle system I'm planning to re-create.

I noticed however (something I've seen before), some odd readings from the CPU.



With Vsync enabled and running 128 dots, CPU is low.
Change up by one to 129 dots and it leaps up to 25%. ???

Removing Vsync and using just frame limiting at 60, I can nearly white-out the screen with thousands of dots and the CPU appears to be yawning at 0%!  Naturally, I'd prefer the VSync for smoothness, but I find this behaviour a little strange and it has confused me for some time now.

What exactly is it here that I'm not understanding correctly?

*Edit - changed title for future searches
« Last Edit: April 30, 2012, 09:30:29 pm by Jove »
{much better code}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Unusual CPU readings relating to Vsync/rateLimit
« Reply #1 on: April 28, 2012, 10:38:33 pm »
I'm afraid there's no clear explanation to this behaviour. Sometimes it's hard to figure out what happens inside the graphics driver.
Laurent Gomila - SFML developer

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: Unusual CPU readings relating to Vsync/rateLimit
« Reply #2 on: April 28, 2012, 11:54:53 pm »
Interesting.  ISTR John Carmack saying nasty things about PC video drivers.

It would be nice if someone with an ATI/AMD card was to try this and see if the same thing happens.

I guess I should just ignore it, although it makes code testing a little ambiguous.
{much better code}

dobbi10k

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Unusual CPU readings relating to Vsync/rateLimit
« Reply #3 on: April 29, 2012, 11:09:36 am »
I'm using an AMD Radeon HD 6970 and I don't have those issues, neither with V-Sync nor a frame rate limit. My CPU (i5 25010K) stays at 0% until I have let's say 100k dots drawn...

I also updated your code to comply with the new SFML2 camelCase:
#include <SFML\Graphics.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(1024, 768, 32), "SFML");

        App.setVerticalSyncEnabled(true);
        //App.setFramerateLimit(60);

        const unsigned int NOOF_DOTS = 100000;

        sf::VertexArray dots(sf::Quads, NOOF_DOTS * 4);

        for (int i=0; i<NOOF_DOTS*4; i+=4)
        {
                float x = rand() % 1024;
                float y = rand() % 768;

                dots[i]  .position = sf::Vector2f( x,   y   );
                dots[i+1].position = sf::Vector2f( x,   y+2 );
                dots[i+2].position = sf::Vector2f( x+2, y+2 );
                dots[i+3].position = sf::Vector2f( x+2, y   );
        }

        while (App.isOpen())
        {
                sf::Event Event;
                while (App.pollEvent(Event))
                {
                        if (Event.type == sf::Event::Closed)
                                App.close();
                }

                App.clear();
                App.draw (dots);
                App.display();
        }

        return EXIT_SUCCESS;
}
« Last Edit: April 29, 2012, 11:15:48 am by Laurent »

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: Unusual CPU readings relating to Vsync/rateLimit
« Reply #4 on: April 29, 2012, 03:20:45 pm »
Thanks for testing it, Dobbi.  :)

This is the second Nvidia card I have owned that does this strange thing, so I suppose it really does boil down to drivers.
{much better code}

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
[SOLVED]...(sort of)

I found an option in the Nvidia control panel - Threaded Optimisation.  Auto by default, switching it off seems to have helped a lot.
{much better code}

 

anything