i have problems with atom being unable to run webgl processes if the discrete gpu is not already in use by another process in the background.
i’m using two packages (glsl-preview and glsl-livecoder) to render shaders inside the atom editor. Both of them are built on three.js, which create a html canvas inside atom and depends on webgl to render images inside. If the discrete gpu is already switched on by another program, atom will be able to use it, but if it is off and the integrated gpu is on, none of the package will be able to execute the THREE.WebGLRenderer() function which create a canvas inside the editor.
By default, the computer switches automatically between the two gpu when a process needs it, like chrome whenever it is running, or firefox when it is running a webgl process. But atom seems unable to switch between the two gpu by itself. So when a package like glsl-preview or glsl-livecoder needs use the discrete gpu, it can’t, unless the discrete gpu is already switched on by another process.
I’m using atom 1.19.4 (current latest stable release) on a macbook pro 15” mid 2011 running macos 10.12.6. the integrated gpu is an intel hd graphics 3000 and the discrete one is a amd radeon hd 6750m.
Looking at Apple’s
Activity Monitor, i encounter two cases.
case 1: the discrete gpu is active
=> atom is able to run webgl
By default, atom has 4
Atom Helper processes. When i open the
Developer Tools, a 5th one appears. When i switch on one of the atom webgl packages, the packages work great. Three.js starts up and run the command
document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ); which returns a
<canvas width=“300” height=“150”>.
case 2: the integrated gpu is active, or the computer is in
Dynamic Switching mode (= default)
=> nothing works
Atom has 4
Atom Helper processes, when i open the
Developer Tools, a 5th one appears and then disappears in the
Activity Monitor. When i switch on one of the atom webgl packages, the 5th
Atom Helper process doesn’t reappear and the packages don’t work. By don’t work i mean both of them return the error
THREE.WebGLRenderer: Error creating WebGL context.
and when three.js initializes and runs the command
document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ), the command returns a
<canvas>. Trying to extract the
.getContext( 'webgl', contextAttributes ) of this canvas returns
If i have the discrete gpu on, and launch atom from the terminal with the
—disable-gpu argument, atom launches with 3
Atom Helper processes, opening the
Developer Tools creates a 4th
Atom Helper process (but not a 5th one). The packages don’t work and throw the same error as case 2.
For the sake of completeness, here is the content of the 5th
Atom Helper process: https://pastebin.com/cbBzjHWu.
I can’t find the link anymore but there is an old pull request on the atom github to create a “use hardware acceleration” toggle in atom’s settings. Has it been implemented in any way? I’d tend to think no, as everything works fine if the discrete gpu is on and i don’t launch atom with the
--disable-gpu argument. I have tried as well to launch atom when the integrated gpu is on with an
--enable-gpu-rasterization argument, but the results were the same as case 2. Using sudo or giving 777 permissions doesn’t change anything.
Big question: is there any way to force atom to switch to the discrete gpu when needed other than manually switching between gpu before launching it?