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.

Clones are cheap and share the same device and diagnostic handler (GpuContext::set_diagnostic_handler).

§The queue (wgpu interop)

Every wgpu call that can reach the native queue is a method here and takes the shared-queue lock when there is one: submit, Self::on_submitted_work_done and map_async (both may flush pending writes), and present. Dropping the last clone also drops the queue under the lock, because wgpu waits for the native queue to idle there. queue hands out the handle for everything else, and each crate’s clippy configuration forbids queue-reaching calls on it.

Implementations§

Source§

impl GpuContext

Source

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

Calls callback once submitted work completes, holding the shared-queue lock.

wgpu flushes pending writes here, which 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_product() -> Result<Self, GpuError>

Requests the product device with the default request (Self::request_product_with).

§Errors

Returns GpuError when no adapter opens a device.

Source

pub async fn request_product_with( request: &ProductRequest, ) -> Result<Self, GpuError>

Requests the product device on product_backends: the adapter ALPHA2_GPU_ADAPTER pins, else the first in high-performance order that opens a device.

A DX12 group that lists no adapter is a failed instance, since WARP is always listed. GL adapters older than GL 4.3 or GLES 3.1 are refused. WGPU_POWER_PREF is ignored.

§Errors

Returns GpuError for an unmatched pin, a failed DX12 instance, no hardware adapter under SoftwareAdapters::Refuse, or the first device error.

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 and panic in debug or under ALPHA2_GPU_STRICT=1; device loss is dropped. The handler may run on any thread and must not block. It replaces any previous handler and is never invoked on wasm32.

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 rate(&self) -> &Arc<GpuRate> ⓘ

This device’s throughput rate.

Source

pub fn with_rgba8_intermediate(&self) -> Self

This device with an Rgba8Unorm intermediate format, so the 8-bit fallback can be tested on any device. Shares the device, queue and handler with self.

Source

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

This device reported as tier, so downlevel policy can be tested on any device. Shares the device, queue and handler with self.

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,