pub enum GpuPreference {
Auto,
LowPower,
HighPerformance,
Device(GpuId),
Custom(Arc<dyn Fn(&[GpuAdapterInfo]) -> Option<usize> + Send + Sync>),
}Expand description
Which GPU an application prefers the renderer to run on.
The device is process-wide and chosen once, before the first window (decision 0008), so this is
stated on the application rather than per window. The default is LowPower: on
a hybrid laptop the panel is wired to the integrated GPU, so rendering on the discrete one keeps
it powered for the window’s lifetime and crosses PCIe on every frame.
Variants§
Auto
Today’s ranking: the compositor’s hint, then device type (discrete, integrated, other, virtual, CPU), then backend.
LowPower
Prefer the integrated adapter. The default.
HighPerformance
Prefer the discrete adapter.
Device(GpuId)
A named adapter, matched by its permanent part and, when it carries one, its session handle.
One that is not present falls back to [Auto].
Custom(Arc<dyn Fn(&[GpuAdapterInfo]) -> Option<usize> + Send + Sync>)
A predicate that picks one adapter from the enumerated list.
The closure receives every adapter the platform reports and returns the index of the one it
wants, or None when none will do. It chooses a GPU; it does not rank them.
use std::sync::Arc;
use gpui_platform::{GpuAdapterInfo, GpuDeviceType, GpuPreference};
let preference = GpuPreference::Custom(Arc::new(|gpus: &[GpuAdapterInfo]| {
// A producer that must share a dma-buf with the renderer names its GPU first, and
// otherwise takes the integrated one — where the panel is wired on a hybrid laptop.
gpus.iter()
.position(|gpu| gpu.device_id() == Some(0x1346))
.or_else(|| {
gpus.iter()
.position(|gpu| gpu.device_type == GpuDeviceType::Integrated)
})
}));The adapter named is tried first. If the display cannot be configured on it, the remaining
adapters follow in Auto’s order — this is a preference, not a pin. An
application that must know what it got reads GpuAdapterInfo back through the app’s
active-GPU accessor.
None, or an index outside the list, fails the window with an error naming the shortfall: the
application saw the same list, so the two disagreeing is a bug worth surfacing rather than
silently drawing on a GPU the application did not choose.
Trait Implementations§
Source§impl Clone for GpuPreference
impl Clone for GpuPreference
Source§fn clone(&self) -> GpuPreference
fn clone(&self) -> GpuPreference
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GpuPreference
impl Debug for GpuPreference
Source§impl Default for GpuPreference
impl Default for GpuPreference
Source§fn default() -> GpuPreference
fn default() -> GpuPreference
Auto Trait Implementations§
impl !RefUnwindSafe for GpuPreference
impl !UnwindSafe for GpuPreference
impl Freeze for GpuPreference
impl Send for GpuPreference
impl Sync for GpuPreference
impl Unpin for GpuPreference
impl UnsafeUnpin for GpuPreference
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().