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
impl Gpu
Sourcepub async fn new(
target: impl Into<SurfaceTarget<'static>>,
) -> Result<(Self, Surface<'static>), Box<dyn Error>>
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).
Sourcepub async fn new_with(
target: impl Into<SurfaceTarget<'static>>,
options: GpuOptions,
) -> Result<(Self, Surface<'static>), Box<dyn Error>>
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.
Sourcepub fn lost(&self) -> bool
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.
Sourcepub fn mark_lost(&self)
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.
Sourcepub fn create_surface(
&self,
target: impl Into<SurfaceTarget<'static>>,
) -> Result<Surface<'static>, CreateSurfaceError>
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.
Sourcepub fn options(&self) -> GpuOptions
pub fn options(&self) -> GpuOptions
What the device was opened for (Gpu::new_with).
Sourcepub fn device(&self) -> &Device
pub fn device(&self) -> &Device
The device, for a runner that creates resources of its own on it.
Sourcepub fn dual_source(&self) -> bool
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.