Skip to main content

GpuContext

Struct GpuContext 

Source
pub struct GpuContext { /* private fields */ }
Expand description

A GPU device and queue owned by one render host.

Cloning is cheap and shares one device: wgpu’s adapter, device, and queue are handles, and a clone also observes the diagnostic handler installed through GpuContext::set_diagnostic_handler. Two clones are one GPU device, not two, so a caller that wants an independent device requests one.

§The queue (wgpu interop)

The queue is not a field. Every wgpu call that can reach the native queue is a method here, and takes the shared-queue lock when the context has one: submit, Self::on_submitted_work_done and map_async (both flush writes still pending from a submission wgpu rejected), and present. Dropping the last clone drops the queue under the lock too, because wgpu waits for the native queue to go idle there. queue hands out the handle for everything else (writes, timestamps, backend interop), and the clippy configuration of every crate that uses wgpu refuses the queue-reaching calls on it. Those methods, and the ones that adopt or hand out the device and adapter, are the wgpu-interop feature’s.

Implementations§

Source§

impl GpuContext

Source

pub fn on_submitted_work_done(&self, callback: impl FnOnce() + Send + 'static)

Calls callback once the work submitted so far completes, holding the shared-queue lock when one is set.

wgpu flushes writes still pending here, and they are pending after a submission it rejected: that flush is a native submission.

Source

pub async fn request() -> Result<Self, GpuError>

Requests a surface-independent device.

§Errors

Returns GpuError when adapter or device acquisition fails.

Source

pub async fn request_high_performance() -> Result<Self, GpuError>

Requests a surface-independent device, preferring a discrete/high-performance adapter.

WGPU_POWER_PREF still takes precedence when it is explicitly set.

§Errors

Returns GpuError when adapter or device acquisition fails.

Source

pub fn set_diagnostic_handler( &self, handler: impl Fn(GpuDiagnostic) + Send + Sync + 'static, )

Routes uncaptured errors and device-loss notifications to handler.

Without a handler, uncaptured errors are dropped in release builds and panic in debug builds or under ALPHA2_GPU_STRICT=1, as wgpu’s default handler does; device loss is dropped. The driver may invoke the handler from an arbitrary thread, so it must not block. Installing a handler replaces any previous one. On wasm32 the browser owns these callbacks and the handler is never invoked.

Source

pub fn clear_diagnostic_handler(&self)

Drops the installed diagnostic handler, if any.

Source

pub fn capabilities(&self) -> &Capabilities

Returns immutable capability decisions.

Source

pub fn with_rgba8_intermediate(&self) -> Self

This device, with renderers made on it storing their intermediate pictures in Rgba8Unorm, as they do on an adapter that cannot render, filter, and copy half floats.

Every adapter supports the 8-bit format, so the fallback can be run, tested, and compared with half float on any device. The returned context shares the device, queue, and diagnostic handler with self, as a clone does; only its capabilities differ.

Source

pub fn with_tier(&self, tier: CapabilityTier) -> Self

This device, reported as tier: renderers made on it apply that tier’s limits, as they do on an adapter of that tier (a WebGL2 or GL ES one for Tier B).

So the downlevel policy can be run and tested on any device, as Self::with_rgba8_intermediate lets the 8-bit fallback be. The returned context shares the device, queue, and diagnostic handler with self; only its capabilities differ.

Trait Implementations§

Source§

impl Clone for GpuContext

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 GpuContext

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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,