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

Author Topic: Switch GPU with code?  (Read 10586 times)

0 Members and 1 Guest are viewing this topic.

hechelion

  • Newbie
  • *
  • Posts: 24
    • View Profile
Switch GPU with code?
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Switch GPU with code?
« Reply #1 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

hechelion

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Switch GPU with code?
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Switch GPU with code?
« Reply #3 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;
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

hechelion

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Switch GPU with code?
« Reply #4 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.