SFML community forums

Bindings - other languages => DotNet => Topic started by: hechelion on September 05, 2021, 04:18:19 am

Title: Switch GPU with code?
Post by: hechelion on September 05, 2021, 04:18:19 am
Hi.
it is possible through code, determine which GPU a game should use?

Many laptops use 2 GPUs (integrated intel and dedicated nvidia for example).

If I run a game as "factorio", the laptop automatically knows to run that game with the Nvidia GPU.
On the contrary, if I have a game programmed with SFML, when it runs, it does so with the integrated GPU.

I know it is possible to change this manually in the Nvidia settings, but I would like to know if there is any way to select the GPU automatically. when creating videomode maybe?
Title: Re: Switch GPU with code?
Post by: eXpl0it3r on September 06, 2021, 05:19:34 pm
You can't explicitly pick it, but you can place a hint, that your application should prefer the discrete GPU by setting the macro SFML_DEFINE_DISCRETE_GPU_PREFERENCE .

See here: https://www.sfml-dev.org/documentation/2.5.1/GpuPreference_8hpp.php
Title: Re: Switch GPU with code?
Post by: hechelion on September 08, 2021, 03:22:06 am
Thank you very much for your answer.
I've been trying to activate the macro in VB NET for a while but without success.
Will you have an example to guide me?
Title: Re: Switch GPU with code?
Post by: eXpl0it3r on September 08, 2021, 09:46:54 am
Not sure you can really do that out of VB.Net, in that case it's probably easier to export the two fields yourself, but I don't know how this is really done in VB.Net

extern "C" __declspec(dllexport) unsigned long NvOptimusEnablement = 1;
extern "C" __declspec(dllexport) unsigned long AmdPowerXpressRequestHighPerformance = 1;
Title: Re: Switch GPU with code?
Post by: hechelion on September 08, 2021, 10:53:49 pm
I'm going to see if I can implement it in VB, but I will save that code for my next project. I will do with code and C #.

Thanks very much.