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
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.
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);
}