Skip to main content

Gpu

Struct Gpu 

Source
pub struct Gpu(/* private fields */);
Expand description

The GPU objects an app’s windows share: one instance, adapter, device and queue.

Two devices cannot see each other’s buffers or textures, so every window of an app draws through the same Gpu. A single-window app never names it: Renderer::new opens a private one. A second window takes the first renderer’s Renderer::gpu and opens through Renderer::new_in. Cloning a Gpu clones a handle to the same device.

Implementations§

Source§

impl Gpu

Source

pub async fn new( target: impl Into<SurfaceTarget<'static>>, ) -> Result<(Self, Surface<'static>), Box<dyn Error>>

Opens a device that can present to target, and returns the surface it was chosen for.

The first window’s surface has to exist before an adapter can be picked, so it comes back with the device; later windows get theirs from Gpu::create_surface. Most runners call Renderer::new instead, which does both and builds the renderer. On Windows only the D3D12 backend is enabled unless WGPU_BACKEND names another; for GpuOptions::transparent, a list naming D3D12 among others is narrowed to it (see_through_by_visual_with).

Source

pub async fn new_with( target: impl Into<SurfaceTarget<'static>>, options: GpuOptions, ) -> Result<(Self, Surface<'static>), Box<dyn Error>>

Gpu::new with options: what every surface opened on this device must be able to do.

Source

pub fn lost(&self) -> bool

Whether the device is gone (a driver update or a GPU reset took it).

Nothing on a lost device works again: open a new Gpu and a new renderer on it for every window. Renderer::render reports the same condition as RenderError::DeviceLost.

Source

pub fn mark_lost(&self)

Loses the device on purpose, as a driver update or a GPU reset would, so a runner can test its reopening path without one.

On D3D12 the device is really removed (ID3D12Device5::RemoveDevice) and the loss lands on its next use through the lost callback, as a real one does; elsewhere the device is only marked lost.

Source

pub fn create_surface( &self, target: impl Into<SurfaceTarget<'static>>, ) -> Result<Surface<'static>, CreateSurfaceError>

A surface for another window on the same instance, which is what Renderer::new_in draws into.

Source

pub fn options(&self) -> GpuOptions

What the device was opened for (Gpu::new_with).

Source

pub fn instance(&self) -> &Instance

The wgpu instance the device was opened on.

Source

pub fn adapter(&self) -> &Adapter

The adapter the device was requested from.

Source

pub fn device(&self) -> &Device

The device, for a runner that creates resources of its own on it.

Source

pub fn queue(&self) -> &Queue

The queue the renderer submits to.

Source

pub fn dual_source(&self) -> bool

Whether this device blends per channel (dual-source blending), so LCD subpixel glyphs draw with per-channel coverage rather than their union.

Trait Implementations§

Source§

impl Clone for Gpu

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Gpu

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Gpu

§

impl !UnwindSafe for Gpu

§

impl Freeze for Gpu

§

impl Send for Gpu

§

impl Sync for Gpu

§

impl Unpin for Gpu

§

impl UnsafeUnpin for Gpu

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,