SFML community forums

Help => General => Topic started by: Kuinox on January 15, 2018, 01:25:31 pm

Title: SFML With multi GPU
Post by: Kuinox on January 15, 2018, 01:25:31 pm
Hi,
I got a laptop with intel GPU and nvidia GPU. 
I parametred my .exe to start with the nvidia. 
When i start the RenderWindow in windowed mode, it use my Nvidia card, when the RenderWindow is fullscreen, it use the intel GPU. 
Anyone know how i can fix this ?
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 15, 2018, 02:26:17 pm
Tell your GPU config to use the Nvidia GPU.

(https://i.imgur.com/p5zHkKm.png)

Alternatively, if you link sfml-main it will also enforce that the dedicated GPU is used.
Title: Re: SFML With multi GPU
Post by: Kuinox on January 15, 2018, 02:33:19 pm
This is already the case: 
(https://i.gyazo.com/797f75f15ae60fb0e26fb02b52623dd7.png)
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 15, 2018, 03:13:29 pm
I'm on the second tab in the image above, where you specify which GPU to use for which program.
Title: Re: SFML With multi GPU
Post by: Kuinox on January 15, 2018, 11:27:27 pm
I dont know why, but the screenshot doesnt work now. 
I did both, global settings and program settings. 
The weird thing is it start with nvidia gpu in windowed mode.
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 15, 2018, 11:28:12 pm
And how do you know that?
Title: Re: SFML With multi GPU
Post by: Kuinox on January 16, 2018, 12:00:04 am
Windows 10 added GPU info in the task manager, also in windowed mode i got like 900 fps but only 300 in fullscreen. 
Pics: 
(https://i.gyazo.com/8c50cbf904ad69a311bff6e1667309cd.png)

Windowed mode:
(https://i.gyazo.com/9bef5bd2958833f85908735680b88050.png)
FullScreen mode:
(https://i.gyazo.com/8b99069d7fe1bc0717c01496f8984b8a.png)

And what gpu 0 and gpu 1 correspond to: 
(https://i.gyazo.com/3ca4b331b96ca9dd796d0018a3e02ecb.png)
Used same executable for both. 
Using SFML.NET 2.2 in C#
Code that launch the RenderWindow:
Quote
var answere = Console.ReadLine()?.ToLower();
bool windowed = !(answere == "yes" || answere == "y");
var window = windowed ? new RenderWindow(VideoMode.FullscreenModes[2], "Vestige", Styles.Titlebar | Styles.Close) : new RenderWindow(VideoMode.FullscreenModes[0], "Vestige", Styles.Fullscreen);
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 16, 2018, 12:50:12 am
Do you have multiple monitors?
Title: Re: SFML With multi GPU
Post by: Kuinox on January 16, 2018, 09:52:53 am
Yes/No 
When i noticed the issue i was only using the monitor of my laptop, and no other monitor was connected. 
When i did the screenshot, i was using a monitor, while my laptop screen was off. 

Also, my colleague have a problem on his new laptop, the Fullscreen mode doesn't cover the screen. 
Pic: 
(https://i.gyazo.com/d90f7a7afaff069dc94c7b7ca5b34180.png)
Title: Re: SFML With multi GPU
Post by: Kuinox on January 20, 2018, 07:47:22 pm
Little up ! More seriously, i dont know if you didn't noticed my reply. 
Side note, a friend have some rendering problem on his mac(on a windows VM), caused by a Texture changement, but we don't have this problem on our Windows. I can have more information on this problem monday.
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 20, 2018, 10:23:15 pm
VMs are not really supported. I mean  they often do weird GPU things or just software renderers.

My notebook runs two GPUs as well and I'm not running into any issues, so I don't know what's happening.

Have you updated your Nvidia and Intel drivers?
Title: Re: SFML With multi GPU
Post by: Kuinox on January 21, 2018, 02:06:35 am
I'm using constructor latest driver for intel chipset, and the latest nvidia drivers. 
Tomorrow i will try with another laptop to reproduce this. 
Also, as i mentioned in a previous reply, the fullscreen bug on my friend laptop is now "resolved" we didn't changed anything and it fixed itself   :o
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 21, 2018, 12:22:30 pm
What's "constructor"?

What are the driver version numbers?
Title: Re: SFML With multi GPU
Post by: Kuinox on January 21, 2018, 04:21:22 pm
I mean the driver provided by HP. 
I'm using the 21.20.16.4542
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 21, 2018, 05:58:37 pm
That Intel driver is pretty much 1 year old and as such not the latest driver, but it may be the latest driver for your HP device. Unfortunately HP (and other vendors) often restrict their users in some weird ways to get the latest updates and then they don't update their special driver versions.

From my point of view this is not really an SFML issue and you might find better help on some general Windows/HP support forum.
I've quickly (http://www.tomsguide.com/answers/id-1988136/laptop-dedicated-gpu.html) googled (https://superuser.com/questions/578148/intel-hd-graphics-4000-is-used-instead-of-nvidia-geforce-630m-for-old-game) a bit and you're certainly not the only one experiencing issues with the switching. I've seen posts where people mentioned that reinstalling the Nvidia driver helped. Or that some said using the "official" HP drivers instead of the latest Nvidia driver fixed the switching issue.

I ran the following test example on my notebook with 2 GPUs and it either ran on the Intel GPU or the Nvidia GPU depending which one I told it to run on.

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Multi GPU", sf::Style::Fullscreen);
    window.setFramerateLimit(60);

    // load font
    sf::Font font;
    if (!font.loadFromFile("arial.ttf"))
    {
        std::cerr << "Failed to load font!" << std::endl;
        return 1;
    }

    sf::Text text("0", font);
    sf::Clock clock;
   
    while (window.isOpen())
    {
        auto dt = clock.restart();
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
            else if (event.type == sf::Event::KeyReleased)
            {
                if (event.key.code == sf::Keyboard::Escape)
                {
                    window.close();
                }
                else if (event.key.code == sf::Keyboard::Return)
                {
                    window.create(sf::VideoMode::getDesktopMode(), "Multi GPU", sf::Style::Fullscreen);
                }
                else if (event.key.code == sf::Keyboard::Space)
                {
                    window.create(sf::VideoMode::getDesktopMode(), "Multi GPU", sf::Style::Default);
                }
            }
        }

        text.setString(std::to_string(1.f / dt.asSeconds()));

        window.clear();
        window.draw(text);
        window.display();
    }
}
Title: Re: SFML With multi GPU
Post by: Kuinox on January 21, 2018, 07:16:21 pm
Can you try with the script i did for my game ?   
Quote
var answere = Console.ReadLine()?.ToLower();
bool windowed = !(answere == "yes" || answere == "y");
var window = windowed ? new RenderWindow(VideoMode.FullscreenModes[2], "Vestige", Styles.Titlebar | Styles.Close) : new RenderWindow(VideoMode.FullscreenModes[0], "Vestige", Styles.Fullscreen);
I will test with update driver, i will give the result soon.
Title: Re: SFML With multi GPU
Post by: Kuinox on January 21, 2018, 10:36:42 pm
I updated it. 
It's even worst. Now it won't run on my nvidia graphics card in both case ^^. 
Now using 23.20.16.4901   
Update: 
So, using a nvidia tool, i saw that the windowed mode is using the Nvidia graphics card. 
(https://i.gyazo.com/ac7d51de8b86e0dfff57febe21ba35f7.png)
There is some problems. Because the intel graphics is running really high, when the Nvidia is the default one. 
I will try to use an opengl command to see what is the GPU i'm using.
Title: Re: SFML With multi GPU
Post by: Kuinox on January 26, 2018, 04:47:20 pm
So, now we know that SFML is using the nvidia card thanks to the opengl command. 
Now, i have another problem: 
(https://i.gyazo.com/301bef67c413c51cad1657cc659d14e2.png) 
Why the intel spike, and is now always at 100% ? 
I think it sort of bottleneck the nvidia...
Title: Re: SFML With multi GPU
Post by: eXpl0it3r on January 26, 2018, 06:00:47 pm
I wonder can contexts run in different GPUs?

Personally, I'd suggest to run some example with the latest C++ SFML version. Maybe it's something that has been fixed a long time ago already.
Title: Re: SFML With multi GPU
Post by: Kuinox on January 26, 2018, 07:12:31 pm
First, i will try with another game, that is running SFML, to know if it's my fault :D 
So, i tested with OpenHexagon, it use SFML 2 while i use SFML.NET 2 
It got the same problem: 
(https://i.gyazo.com/abd8f5b26725ef3ba97da1cac516d0c4.png)
(https://i.gyazo.com/3882ae5a55cf796b94916028a151a873.png)
Windows recognize it as using the intel GPU, and it eat up the intel gpu, and it's probably being bottleneck by the intel GPU. 
Now, i will try with a game that isn't using SFML(to test if it's not my laptop fault) 
OKay, so it's look like that, more i draw frames, more it use the intel card. 
When i run CSGO, it also use the intel card, but a lot less than when i run a small 2D game that run at 300-400 fps. 
So it looks like it my laptop fault. 
For the bad GPU indicator in the task manager, it work on games not using SFML. 
Maybe there is something to do ?