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

Author Topic: Performance within VirtualBox  (Read 9760 times)

0 Members and 1 Guest are viewing this topic.

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« on: December 08, 2009, 10:33:36 pm »
I tried to run a simple SFML-app I've written inside a Linux virtual machine, hosted by VirtualBox on a Win 7 x64 host.

VirtualBox supports OpenGL for guest operating systems since quite a while now, and the performance is surprisingly good when using some Compiz desktop effects inside the VM (like wobbly windows or transparency). My SFML-app however (which does not much more than drawing a few sprites) runs really, really slow and stuttering, and I'm not quite sure whether this is a problem of VirtualBox, my app, or SFML.

Has anyone else here ever tried to use SFML inside a virual machine?

EDIT: Just found out that the problem seems to be created by drawing a pseudo-3D-starfield in the background which consisted of 500 stars. Perhaps there's something wrong with the way I update the position of these stars. I'll see if I can figure it out.

EDIT2: Ok, it seems to be related to some graphic/OpenGL-stuff. If I calculate the position for each star but don't draw it (by commenting out the call to the draw-method of the render-window), it runs at quite normal speed.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Performance within VirtualBox
« Reply #1 on: December 08, 2009, 11:26:05 pm »
Can you show your code?
Laurent Gomila - SFML developer

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« Reply #2 on: December 09, 2009, 10:33:40 pm »
The code for drawing the stars looks like this:
Code: [Select]

void Starfield::draw()
{
    for ( int i = 0; i < this->nStars; ++i )
    {        
        int screenX = this->starList[i].x / this->starList[i].z + this->centerX;
        int screenY = this->starList[i].y / this->starList[i].z + this->centerY;
        sf::Shape rect = sf::Shape::Rectangle( screenX, screenY, screenX + 3, screenY + 3,
                                               sf::Color(255 - starList[i].z * 2,
                                                         255 - starList[i].z * 2,
                                                         255 - starList[i].z * 2,
                                                         255) );
        this->window->Draw( rect );

        this->starList[i].z -= this->speedList[i] * this->window->GetFrameTime();

        if ( this->starList[i].z < 1 )
            this->starList[i].z = rand() % 50 + 1;
    }
}


This method is called in every iteration of the main loop. If I comment out the this->window->Draw( rect ); line, the app is running at relatively normal speed.

Perhaps its just too many OpenGL calls which lead to world switches between the guest and the host?!

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« Reply #3 on: December 09, 2009, 10:58:39 pm »
I just had a look at the activity inside the VM when my app is running: It's not the app itself that causes high CPU loads, but Xorg.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Performance within VirtualBox
« Reply #4 on: December 09, 2009, 10:59:55 pm »
Quote
Perhaps its just too many OpenGL calls

Probably. This kind of stuff is much faster in SFML 2.
Laurent Gomila - SFML developer

Dominator

  • Newbie
  • *
  • Posts: 37
    • View Profile
Performance within VirtualBox
« Reply #5 on: December 10, 2009, 02:37:14 pm »
Can you confirm that OpenGL is working correctly in the VM, kullerhamPster?

Because with Win7 x64 as host, I don't get hardware accelerated OpenGL in the Ubuntu guest.

SFML apps run really slow in software rendering mode.
I for example get only about 10 fps when simply drawing a square each frame.

For me it works fine with WinXP as host though.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Performance within VirtualBox
« Reply #6 on: December 10, 2009, 06:45:37 pm »
Quote from: "Dominator"
Can you confirm that OpenGL is working correctly in the VM, kullerhamPster?

Because with Win7 x64 as host, I don't get hardware accelerated OpenGL in the Ubuntu guest.

SFML apps run really slow in software rendering mode.
I for example get only about 10 fps when simply drawing a square each frame.

For me it works fine with WinXP as host though.


Same here, I use W7x64 and I can't get hardware accelerated OpenGL in Ubuntu.

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« Reply #7 on: December 10, 2009, 10:56:26 pm »
I didn't really check it, I just saw that the desktop-effects I enabled (wobbly windows and a transparent terminal) ran pretty smooth, so I assumed that it must be HW-accelerated.

I'm not sure how to find out if HW-acceleration is actually active. What should glxinfo print out if it is?

glxgears claims to render around 12800 frames in 5 seconds.

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« Reply #8 on: December 10, 2009, 10:58:33 pm »
I'm running Linux Mint 8 in the 32 bit version inside the VM, but Linux Mint is afaik more or less the same as Ubuntu, so that shouldn't make a difference.

Edit: Ooops, didn't want to create a new post for that, I accidentally pressed "quote" instead of "edit".

Dominator

  • Newbie
  • *
  • Posts: 37
    • View Profile
Performance within VirtualBox
« Reply #9 on: December 10, 2009, 11:58:45 pm »
Quote from: "kullerhamPster"
glxgears claims to render around 12800 frames in 5 seconds.

Looks like OpenGL is hardware accelerated for you.
You should try SFML2, it may fix your issue.

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« Reply #10 on: December 20, 2009, 09:28:04 pm »
How/when/where can I get SFML2? I just downloaded and built the trunk tarball, but that seems to be 1.6.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Performance within VirtualBox
« Reply #11 on: December 20, 2009, 09:36:39 pm »
You must use a SVN client, then checkout branches/sfml2. I think there's a tutorial on the wiki.
Laurent Gomila - SFML developer

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« Reply #12 on: December 20, 2009, 09:55:34 pm »
Quote from: "Laurent"
You must use a SVN client, then checkout branches/sfml2. I think there's a tutorial on the wiki.


Thanks for the quick reply. I just checked it out, now I'll see if it builds.

Didn't find a tutorial related to SFML 2, though.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Performance within VirtualBox
« Reply #13 on: December 20, 2009, 10:11:56 pm »
Quote from: "kullerhamPster"
Didn't find a tutorial related to SFML 2, though.
There is none.

Many things in the interface have remained the same, but there have been some key name alterations, for example at sf::String. Check out the general discussions forum, where Laurent announces important changes. For smaller things, you can orientate yourself by the documentation in the SFML headers.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kullerhamPster

  • Newbie
  • *
  • Posts: 40
    • View Profile
Performance within VirtualBox
« Reply #14 on: December 20, 2009, 10:15:59 pm »
I was able to build SFML 2, but now my project doesn't build anymore, I get tons of undefine reference errors.

I guess part of my problem is that I didn't want to install SFML 2 globally, but instead placed it in my home directory, and still have SFML 1.4 installed system-wide. As I've no idea how to specify header search dirs with scons, I guess I'm currently using the 1.4 includes, but trying to link against 2.0.

I'll see if I can fix this...

 

anything