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

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



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
-----------------------------------------------------------