How to force Discrete GPU in electron.js?

1

Update: I also saw documentation and discussions that it must always use discrete GPU but it is not, it always use internal one at the moment.

I need to use discrete GPU in electron.js app in case there are integrated and discrete, how to force it in Electron?

In c++ it can be done like that:

extern "C" 
{
  __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
  __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

How to do that in electron.js?

electron
webgl
gpu
asked on Stack Overflow Jan 31, 2019 by user1338054 • edited Feb 4, 2019 by user1338054

2 Answers

1

With current Electron.js/WebGL, there is no mechanism to enforce this. However, you shouldn't need to, because running on the discrete GPU is the default.

answered on Stack Overflow Feb 3, 2019 by Paul-Jan
0

I figured out, you can silently restart the app with setting the the special windows env variable, which forces the process to use the dedicated GPU.

const { spawn } = require('child_process');

// Restart with force using the dedicated GPU
if (process.env.GPUSET !== 'true') {
  spawn(process.execPath, process.argv, {
    env: {
      ...process.env,
      SHIM_MCCOMPAT: '0x800000001', // this forces windows to use the dedicated GPU for the process
      GPUSET: 'true'
    },
    detached: true,
  });
  process.exit(0);
}
answered on Stack Overflow Aug 31, 2020 by Chris

User contributions licensed under CC BY-SA 3.0