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
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 submitted work completes, holding the shared-queue lock.
wgpu flushes pending writes here, which is a native submission.
Sourcepub async fn request_product() -> Result<Self, GpuError>
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.
Sourcepub async fn request_product_with(
request: &ProductRequest,
) -> Result<Self, GpuError>
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.
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 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.
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 an Rgba8Unorm intermediate format, so the 8-bit fallback can be tested
on any device. Shares the device, queue and handler with self.
Sourcepub fn with_tier(&self, tier: CapabilityTier) -> Self
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.