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
impl GpuContext
Sourcepub fn on_submitted_work_done(&self, callback: impl FnOnce() + Send + 'static)
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.
Sourcepub async fn request_high_performance() -> Result<Self, GpuError>
pub async fn request_high_performance() -> Result<Self, GpuError>
Sourcepub fn set_diagnostic_handler(
&self,
handler: impl Fn(GpuDiagnostic) + Send + Sync + 'static,
)
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.
Sourcepub fn clear_diagnostic_handler(&self)
pub fn clear_diagnostic_handler(&self)
Drops the installed diagnostic handler, if any.
Sourcepub fn capabilities(&self) -> &Capabilities
pub fn capabilities(&self) -> &Capabilities
Returns immutable capability decisions.
Sourcepub fn with_rgba8_intermediate(&self) -> Self
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.
Sourcepub fn with_tier(&self, tier: CapabilityTier) -> Self
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.