mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
Make RequestAdapterOptions.power_preference optional (#3903)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
parent
db87ee8f20
commit
fd5550cc89
@ -46,7 +46,8 @@ Bottom level categories:
|
||||
#### Misc Breaking Changes
|
||||
|
||||
- Change `AdapterInfo::{device,vendor}` to be `u32` instead of `usize`. By @ameknite in [#3760](https://github.com/gfx-rs/wgpu/pull/3760)
|
||||
- Remove the `backend_bits` parameter in `initialize_adapter_from_env` and `initialize_adapter_from_env_or_default` - use [InstanceDescriptor::backends](https://docs.rs/wgpu/latest/wgpu/struct.InstanceDescriptor.html#structfield.backends) instead. By @fornwall in [#3904](https://github.com/gfx-rs/wgpu/pull/3904)
|
||||
- Remove the `backend_bits` parameter in `initialize_adapter_from_env` and `initialize_adapter_from_env_or_default` - use [InstanceDescriptor::backends](https://docs.rs/wgpu/latest/wgpu/struct.InstanceDescriptor.html#structfield.backends) instead. By @fornwall in [#3904](https://github.com/gfx-rs/wgpu/pull/3904)
|
||||
- Make `RequestAdapterOptions.power_preference` optional. By @Aaron1011 in [#3903](https://github.com/gfx-rs/wgpu/pull/3903)
|
||||
- Add a `compatible_surface` parameter to `initialize_adapter_from_env` and use that to make `initialize_adapter_from_env_or_default` always respect its `compatible_surface` parameter. By @fornwall in [#3905](https://github.com/gfx-rs/wgpu/pull/3905)
|
||||
|
||||
#### Vulkan
|
||||
|
@ -64,7 +64,7 @@ fn main() {
|
||||
let adapter = global
|
||||
.request_adapter(
|
||||
&wgc::instance::RequestAdapterOptions {
|
||||
power_preference: wgt::PowerPreference::LowPower,
|
||||
power_preference: wgt::PowerPreference::None,
|
||||
force_fallback_adapter: false,
|
||||
#[cfg(feature = "winit")]
|
||||
compatible_surface: Some(surface),
|
||||
|
@ -193,7 +193,7 @@ impl Corpus {
|
||||
}
|
||||
let adapter = match global.request_adapter(
|
||||
&wgc::instance::RequestAdapterOptions {
|
||||
power_preference: wgt::PowerPreference::LowPower,
|
||||
power_preference: wgt::PowerPreference::None,
|
||||
force_fallback_adapter: false,
|
||||
compatible_surface: None,
|
||||
},
|
||||
|
@ -896,6 +896,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
// hardware GPU (integrated or discrete).
|
||||
PowerPreference::LowPower => integrated.or(discrete).or(other).or(virt).or(cpu),
|
||||
PowerPreference::HighPerformance => discrete.or(integrated).or(other).or(virt).or(cpu),
|
||||
PowerPreference::None => {
|
||||
let option_min = |a: Option<usize>, b: Option<usize>| {
|
||||
if let (Some(a), Some(b)) = (a, b) {
|
||||
Some(a.min(b))
|
||||
} else {
|
||||
a.or(b)
|
||||
}
|
||||
};
|
||||
// Pick the lowest id of these types
|
||||
option_min(option_min(discrete, integrated), other)
|
||||
}
|
||||
};
|
||||
|
||||
let mut selected = preferred_gpu.unwrap_or(0);
|
||||
|
@ -130,16 +130,18 @@ impl Backend {
|
||||
/// Corresponds to [WebGPU `GPUPowerPreference`](
|
||||
/// https://gpuweb.github.io/gpuweb/#enumdef-gpupowerpreference).
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
|
||||
pub enum PowerPreference {
|
||||
/// Adapter that uses the least possible power. This is often an integrated GPU.
|
||||
#[default]
|
||||
LowPower = 0,
|
||||
/// Power usage is not considered when choosing an adapter.
|
||||
None = 0,
|
||||
/// Adapter that uses the least possible power. This is often an integrated GPU.
|
||||
LowPower = 1,
|
||||
/// Adapter that has the highest performance. This is often a discrete GPU.
|
||||
HighPerformance = 1,
|
||||
HighPerformance = 2,
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
|
@ -986,10 +986,15 @@ impl crate::context::Context for Context {
|
||||
//assert!(backends.contains(wgt::Backends::BROWSER_WEBGPU));
|
||||
let mut mapped_options = web_sys::GpuRequestAdapterOptions::new();
|
||||
let mapped_power_preference = match options.power_preference {
|
||||
wgt::PowerPreference::LowPower => web_sys::GpuPowerPreference::LowPower,
|
||||
wgt::PowerPreference::HighPerformance => web_sys::GpuPowerPreference::HighPerformance,
|
||||
wgt::PowerPreference::None => None,
|
||||
wgt::PowerPreference::LowPower => Some(web_sys::GpuPowerPreference::LowPower),
|
||||
wgt::PowerPreference::HighPerformance => {
|
||||
Some(web_sys::GpuPowerPreference::HighPerformance)
|
||||
}
|
||||
};
|
||||
mapped_options.power_preference(mapped_power_preference);
|
||||
if let Some(mapped_pref) = mapped_power_preference {
|
||||
mapped_options.power_preference(mapped_pref);
|
||||
}
|
||||
let adapter_promise = self.0.request_adapter_with_options(&mapped_options);
|
||||
|
||||
MakeSendFuture::new(
|
||||
|
Loading…
Reference in New Issue
Block a user