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?

user1338054
  • 842
  • 1
  • 8
  • 21

2 Answers2

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.

Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
  • it runs whatever id do on internal GPU so no idea what it must, but it is a problem at least for WebGL, any idea how to fix that? – user1338054 Feb 03 '19 at 21:30
1

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);
}
Chris
  • 115
  • 9