Struct WgpuSurfaceBundle

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

Reusable GPU context plus an optional host-owned surface attachment.

The target passed to Self::new_with_surface_target or Self::reattach_surface_target is stored by wgpu’s surface so its raw handles remain valid for the entire attachment lifetime.

§Examples

use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

assert!(std::mem::size_of::<WgpuSurfaceBundle>() > 0);

Implementations§

Source§

impl WgpuSurfaceBundle

Source

pub fn new_with_surface_target<T>( target: Arc<T>, size: PhysicalExtent, transparent: bool, bootstrap: SurfaceBootstrapConfig, pre_present: Option<Arc<dyn Fn() + Send + Sync>>, ) -> Result<Self, RendererError>
where T: HasWindowHandle + HasDisplayHandle + Send + Sync + 'static,

Creates a renderer bundle from any owned raw-window-handle provider.

The physical size is clamped to at least one pixel per dimension in the resulting surface configuration. Adapter candidates are tried in stable device/backend/name order.

§Errors

Returns an error when no compatible adapter/device can be opened, the raw handles cannot create a surface, or every candidate rejects surface configuration.

§Panics

Pipeline creation may panic if the selected device rejects the renderer shaders or layouts. Native surface-configuration panics are caught and cause the next adapter candidate to be tried.

§Examples
use std::sync::Arc;
use ailloli_ui_render_wgpu::{
    pipeline_cache::{SurfaceBootstrapConfig, WgpuSurfaceBundle},
    PhysicalExtent, RendererError,
};

fn create<T>(target: Arc<T>) -> Result<WgpuSurfaceBundle, RendererError>
where
    T: wgpu::rwh::HasWindowHandle
        + wgpu::rwh::HasDisplayHandle
        + Send
        + Sync
        + 'static,
{
    WgpuSurfaceBundle::new_with_surface_target(
        target,
        PhysicalExtent::new(1280, 720),
        false,
        SurfaceBootstrapConfig::default(),
        None,
    )
}
Source

pub fn context(&self) -> &SurfaceGpuContext

Returns the reusable device-bound context.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::{SurfaceGpuContext, WgpuSurfaceBundle};

fn context(bundle: &WgpuSurfaceBundle) -> &SurfaceGpuContext {
    bundle.context()
}
Source

pub fn attachment(&self) -> Option<&SurfaceAttachment>

Borrows the native attachment, or returns None while detached.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::{SurfaceAttachment, WgpuSurfaceBundle};

fn attachment(bundle: &WgpuSurfaceBundle) -> Option<&SurfaceAttachment> {
    bundle.attachment()
}
Source

pub fn attachment_state(&self) -> SurfaceAttachmentState

Reports whether a native surface is attached.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::{
    SurfaceAttachmentState, WgpuSurfaceBundle,
};

fn attached(bundle: &WgpuSurfaceBundle) -> bool {
    bundle.attachment_state() == SurfaceAttachmentState::Attached
}
Source

pub fn device(&self) -> &Device

Returns the logical device, including while the surface is detached.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

fn device(bundle: &WgpuSurfaceBundle) -> &wgpu::Device {
    bundle.device()
}
Source

pub fn queue(&self) -> &Queue

Returns the submission queue, including while the surface is detached.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

fn queue(bundle: &WgpuSurfaceBundle) -> &wgpu::Queue {
    bundle.queue()
}
Source

pub fn pipelines(&self) -> &PipelineCache

Returns the format-specific pipeline cache retained across detachments.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::{PipelineCache, WgpuSurfaceBundle};

fn pipelines(bundle: &WgpuSurfaceBundle) -> &PipelineCache {
    bundle.pipelines()
}
Source

pub fn format(&self) -> TextureFormat

Returns the color format expected by all cached pipelines.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

fn format(bundle: &WgpuSurfaceBundle) -> wgpu::TextureFormat {
    bundle.format()
}
Source

pub fn extent(&self) -> PhysicalExtent

Returns the configured physical-pixel extent or the last attached extent.

The remembered value remains available while detached and may contain a zero dimension only if the caller originally supplied one before any successful surface configuration.

§Examples
use ailloli_ui_render_wgpu::{pipeline_cache::WgpuSurfaceBundle, PhysicalExtent};

fn extent(bundle: &WgpuSurfaceBundle) -> PhysicalExtent {
    bundle.extent()
}
Source

pub fn config(&self) -> Option<&SurfaceConfiguration>

Returns the active surface configuration, or None while detached.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

fn configured_width(bundle: &WgpuSurfaceBundle) -> Option<u32> {
    bundle.config().map(|config| config.width)
}
Source

pub fn detach_surface(&mut self) -> bool

Drops only native presentation resources while retaining the GPU context.

Returns true when an attachment was dropped and false when the bundle was already detached. The last configured physical extent is retained.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::{
    SurfaceAttachmentState, WgpuSurfaceBundle,
};

fn detach(bundle: &mut WgpuSurfaceBundle) {
    let _had_surface = bundle.detach_surface();
    assert_eq!(bundle.attachment_state(), SurfaceAttachmentState::Detached);
}
Source

pub fn reattach_surface_target<T>( &mut self, target: Arc<T>, size: PhysicalExtent, pre_present: Option<Arc<dyn Fn() + Send + Sync>>, ) -> Result<SurfaceReattachOutcome, RendererError>
where T: HasWindowHandle + HasDisplayHandle + Send + Sync + 'static,

Attaches a new raw-window-handle target.

The existing context is tried first. If its adapter or pipeline format cannot present to the new surface, a complete context bootstrap is used as a correctness fallback and the outcome tells the renderer to rebuild every device-bound cache.

The existing attachment, if any, is dropped before the new target is tried. size is in physical pixels.

§Errors

Returns an error when the raw handles cannot create a surface or neither reuse nor full GPU bootstrap can produce a configured attachment.

§Panics

Rebuild may panic if wgpu rejects renderer pipeline creation.

§Examples
use std::sync::Arc;
use ailloli_ui_render_wgpu::{
    pipeline_cache::{SurfaceReattachOutcome, WgpuSurfaceBundle},
    PhysicalExtent, RendererError,
};

fn reattach<T>(
    bundle: &mut WgpuSurfaceBundle,
    target: Arc<T>,
) -> Result<SurfaceReattachOutcome, RendererError>
where
    T: wgpu::rwh::HasWindowHandle
        + wgpu::rwh::HasDisplayHandle
        + Send
        + Sync
        + 'static,
{
    bundle.reattach_surface_target(target, PhysicalExtent::new(800, 600), None)
}
Source

pub fn resize(&mut self, new_size: PhysicalExtent)

Best-effort resize that discards the detailed outcome or error.

Prefer Self::try_resize when the host must react to deferred surface capabilities or request surface recreation. new_size is in physical pixels; a zero dimension is skipped.

§Examples
use ailloli_ui_render_wgpu::{pipeline_cache::WgpuSurfaceBundle, PhysicalExtent};

fn resize(bundle: &mut WgpuSurfaceBundle) {
    bundle.resize(PhysicalExtent::new(1024, 768));
}
Source

pub fn try_resize( &mut self, new_size: PhysicalExtent, ) -> Result<ResizeOutcome, RendererError>

Reconfigures an attached surface only when its physical extent changed.

§Errors

Returns RendererError::RenderTargetUnavailable while detached, RendererError::SurfaceRecreationRequired if the retained pipeline format is no longer supported, or a configuration error if wgpu rejects the update. Zero-sized requests return ResizeOutcome::SkippedZero before attachment state is inspected.

§Examples
use ailloli_ui_render_wgpu::{
    pipeline_cache::{ResizeOutcome, WgpuSurfaceBundle},
    PhysicalExtent, RendererError,
};

fn resize(bundle: &mut WgpuSurfaceBundle) -> Result<ResizeOutcome, RendererError> {
    bundle.try_resize(PhysicalExtent::new(1024, 768))
}
Source

pub fn try_reconfigure( &mut self, new_size: PhysicalExtent, ) -> Result<ResizeOutcome, RendererError>

Reconfigures the presentation surface even when its physical extent is unchanged.

§Errors

Returns the same attachment, format, and wgpu configuration errors as Self::try_resize. A zero dimension is still skipped.

§Examples
use ailloli_ui_render_wgpu::{
    pipeline_cache::{ResizeOutcome, WgpuSurfaceBundle},
    PhysicalExtent, RendererError,
};

fn recover(bundle: &mut WgpuSurfaceBundle) -> Result<ResizeOutcome, RendererError> {
    bundle.try_reconfigure(PhysicalExtent::new(1024, 768))
}
Source

pub fn reconfigure(&mut self) -> Result<ResizeOutcome, RendererError>

Forces recovery configuration using the current remembered extent.

§Errors

Returns the same errors as Self::try_reconfigure.

§Examples
use ailloli_ui_render_wgpu::{
    pipeline_cache::{ResizeOutcome, WgpuSurfaceBundle},
    RendererError,
};

fn recover(bundle: &mut WgpuSurfaceBundle) -> Result<ResizeOutcome, RendererError> {
    bundle.reconfigure()
}
Source

pub fn surface_capabilities(&self) -> SurfaceCapabilities

Queries current capabilities or returns an empty set while detached.

The empty detached value is a sentinel; use Self::attachment_state when that distinction matters.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

fn format_count(bundle: &WgpuSurfaceBundle) -> usize {
    bundle.surface_capabilities().formats.len()
}
Source

pub fn adapter_info(&self) -> AdapterInfo

Queries information about the retained adapter.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

fn backend(bundle: &WgpuSurfaceBundle) -> wgpu::Backend {
    bundle.adapter_info().backend
}
Source

pub fn surface_config_deferred_reason( &self, ) -> Option<SurfaceConfigDeferredReason>

Returns the current reason configuration must wait, if any.

Detachment is reported explicitly. An attached surface returns SurfaceConfigDeferredReason::NoFormats or SurfaceConfigDeferredReason::NoPresentModes for transient empty capabilities, otherwise None.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::{
    SurfaceConfigDeferredReason, WgpuSurfaceBundle,
};

fn deferred(bundle: &WgpuSurfaceBundle) -> Option<SurfaceConfigDeferredReason> {
    bundle.surface_config_deferred_reason()
}
Source

pub fn pre_present_notify(&self)

Invokes the host callback associated with the active attachment.

This is a no-op while detached or when no callback was supplied.

§Examples
use ailloli_ui_render_wgpu::pipeline_cache::WgpuSurfaceBundle;

fn notify(bundle: &WgpuSurfaceBundle) {
    bundle.pre_present_notify();
}

Trait Implementations§

Source§

impl RenderTarget for WgpuSurfaceBundle

Source§

fn size(&self) -> PhysicalExtent

Returns the current physical-pixel extent. Read more
Source§

fn format(&self) -> TextureFormat

Returns the texture format of subsequently acquired frames. Read more
Source§

fn acquire_frame(&mut self) -> Result<RenderFrame, RendererError>

Acquires one renderable frame or a typed renderer error. Read more
Source§

fn pre_present_notify(&self)

Gives the host a chance to notify its window system before presentation. Read more
Source§

fn try_resize( &mut self, _size: PhysicalExtent, ) -> Result<ResizeOutcome, RendererError>

Requests a new physical-pixel extent. 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
§

impl<T> Downcast<T> for T

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,