-
Notifications
You must be signed in to change notification settings - Fork 953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make RequestAdapterOptions.power_preference optional #3903
Conversation
Could you drop the Cargo.lock change from the patch, that looks unrelated and unnecessary. |
3f208f5
to
c4d68ef
Compare
The WebGPU docs state that the `powerPreference` field is optional - it can be set to `undefined`, which provides no hint. Currently, wgpu only allows using an explicit LowPower or HighPerformance hint. This can cause a secondary backend to be chosen over a primary backend when the secondary backend is the only one matching the power preference - with no way to ensure that a primary backend takes priority. This commit changes `RequestAdapterOptions.power_preference` to store an `Option<PowerPreference>`, and removes the `Default` impl from `PowerPreference`. Under WebGPU, we leave `GPURequestAdapterOptions.powerPreference` when our value is `None`. Under native, we skip the backend preference logic.
c4d68ef
to
2243859
Compare
@cwfitzgerald @nical I've pushed a new commit addressing your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more nit, then good!
FTR: 👀Firefox is actually interested in tracking this PR at bug 1841840. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Checklist
cargo clippy
.cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
None
Description
The WebGPU docs state that the
powerPreference
field is optional - it can be set toundefined
, which provides no hint.Currently, wgpu only allows using an explicit LowPower or HighPerformance hint. This can cause a secondary backend to be chosen over a primary backend when the secondary backend is the only one matching the power preference - with no way to ensure that a primary backend takes priority.
This PR changes adds a
PowerPreference::None
variant. Under WebGPU, we leaveGPURequestAdapterOptions.powerPreference
unset when we havePowerPreference::None
. Under native, we pick the lowest-indexed adapter out of [discrete, integrated, other].Testing
On a system with an OpenGL adapter and a Vulkan adapter, run
example/hello
. The Vulkan adapter should be chosen, even if the Vulkan adapter is high-performance and the OpenGL adapter is low-power.