[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Use powerPreference to request high or low power GPUs



I think it's great such a feature exists.

I'm a little sad no public discussion was had on the feature. Looking at the spec it's not as simple as

     let gl = canvas.getContext("webgl", { powerPreference: "high-performance" });

It's more like

     canvas.addEventListener('webglcontextlost`, function() {});
     canvas.addEventListener('webglcontextrestored`, function() {});
     let gl = canvas.getContext("webgl", { powerPreference: "high-performance" });

According the the spec, without the first 2 lines the setting is ignored. It's not clear why that part was important.
Sure I get you might lose the context and get restored on a different GPU but that was already the case before this new setting (on windows with 2 GPUs just disable one and assuming the browser handles it you'd lose the context and get restored on the new one). so what's the need for the requiring the listeners for the hint to have any effect?


It's also not clear from the spec what gets reported. For example the alpha, depth, stencil, and basically all of the other attributes are READable after creation to see what you actually got. For example you might request {stencil: true} then later you check if you actually got a stencil buffer

    const gl = canvas.getContext("webgl", { stencil: true });
    const haveStencil = gl.getContextAttributes().stencil;

It's not clear (at least to me) from the spec if I can do the same with `powerPerformance`

     canvas.addEventListener('webglcontextlost`, function() {});
     canvas.addEventListener('webglcontextrestored`, function() {});
     const gl = canvas.getContext("webgl", { powerPreference: "high-performance" });
     const havePerf = gl.getContextAttributes().powerPreference === "high-performance";
     if (!havePerf) {
         alert("Dear user, this site requires a gamer ready GPU. Sucks to be you");
    }

I suppose that doesn't make any sense on a typical 1 GPU machine but it is confusing that all the other attributes are readable and this one is different.





On Sat, Mar 18, 2017 at 7:04 AM, Dean Jackson <dino@apple.com> wrote:

Hello WebGL community,

We recently added powerPreference to the WebGL 1.0 specification, which allows content developers to give a hint as to what type of GPU they require.

https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.2.1

This replaces the old preferLowPowerToHighPerformance which, even though WebKit implemented it, never shipped in a form that actually changed behaviour.

Here's an example. If you're on a macOS system with two GPUs (e.g. a Macbook Pro), you'd request the more powerful and power hungry GPU using:

    let gl = canvas.getContext("webgl", { powerPreference: "high-performance" });

Note that, as the specification suggests, it doesn't guarantee you'll get the GPU, and you'll be at the front of the line if the system needs to reset some WebGL contexts in order to reclaim system resources. You MUST have a registered event handler for the webglcontextlost and webglcontextrestored events if you want the user agent to respect your request for high-performance.

WebKit and Safari Technology Preview have implemented this attribute, so you can try them out now. Some details on the current WebKit implementation:

- the default value for powerPreference is equivalent to "low-power" (i.e. we still prioritise power use).
- even if you get the discrete GPU, you WILL swap to the integrated GPU if your tab is moved to the background, or the page is hidden. This shouldn't cause any issues, but please let me know if you think it is.
- similarly, if you request "low-power" you might be swapped to the discrete GPU if another page or system app turns it on.

Other browser engines are indicating they'll be implementing this soon too. The behaviour on other operating systems and hardware might be slightly different.

Dean


-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------