Skip to content
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

Merged
merged 4 commits into from
Jul 19, 2023

Conversation

Aaron1011
Copy link
Contributor

@Aaron1011 Aaron1011 commented Jul 3, 2023

Checklist

  • Run cargo clippy.
  • Run cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections
None

Description
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 PR changes adds a PowerPreference::None variant. Under WebGPU, we leave GPURequestAdapterOptions.powerPreference unset when we have PowerPreference::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.

@Aaron1011 Aaron1011 requested a review from crowlKats as a code owner July 3, 2023 01:14
@nical
Copy link
Contributor

nical commented Jul 5, 2023

Could you drop the Cargo.lock change from the patch, that looks unrelated and unnecessary.

wgpu-types/src/lib.rs Show resolved Hide resolved
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.
@Aaron1011
Copy link
Contributor Author

@cwfitzgerald @nical I've pushed a new commit addressing your comments.

Copy link
Member

@cwfitzgerald cwfitzgerald left a 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!

wgpu-core/src/instance.rs Outdated Show resolved Hide resolved
@ErichDonGubler
Copy link
Member

ErichDonGubler commented Jul 13, 2023

FTR: 👀Firefox is actually interested in tracking this PR at bug 1841840.

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) July 19, 2023 20:50
@cwfitzgerald cwfitzgerald merged commit fd5550c into gfx-rs:trunk Jul 19, 2023
20 checks passed
@Aaron1011 Aaron1011 deleted the opt-power-preference branch September 21, 2023 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants