Skip to main content

WGPUBackend

Struct WGPUBackend 

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

The wgpu-backed Backend implementation. Inserted as a resource once init finishes (see the Backend trait docs for how that’s driven); everything in super that uploads to the GPU (Res<WGPUBackend> in an Asset::upload impl) reads device/queue directly off this.

device/queue/surface/config are pub(crate) — every builder in wgpu::prelude that needs the device takes &WGPUBackend directly instead of a raw &wgpu::Device. Surface dimensions/format are exposed via surface_width/surface_height/ surface_format instead of the raw wgpu::SurfaceConfiguration.

Implementations§

Source§

impl WGPUBackend

Source

pub fn surface_width(&self) -> u32

Current surface width in pixels.

Source

pub fn surface_height(&self) -> u32

Current surface height in pixels.

Source

pub fn surface_format(&self) -> TextureFormat

The format the surface was negotiated at (a preferred sRGB format, chosen when the backend initializes).

Source

pub fn sample_count(&self) -> u32

The multisample count ColorTarget::Default rendering (the window surface) currently uses — 1 (no MSAA) until set_msaa is called. A material meant to render into the default target needs Material { sample_count: backend.sample_count(), .. } to match.

Source

pub fn set_msaa(&mut self, sample_count: u32)

Turns on (sample_count > 1) or off (sample_count: 1) multisampled rendering into the window surface. Builds — or rebuilds, matching the current surface size — an internal multisampled color texture that ColorTarget::Default renders into and automatically resolves from into the real surface; resize keeps it matched to the surface size afterward. Call this once at startup (or whenever you want to change the sample count), before building any material meant to render into the default target — see sample_count. Any depth attachment used alongside it needs a matching TextureBuilder::sample_count.

Source§

impl WGPUBackend

Source

pub fn create_command_encoder(&self, label: Option<&str>) -> CommandEncoder

Starts a command encoder for standalone GPU work not tied to an acquired frame — a compute dispatch outside SystemStage::Render, say. Begin a ComputePass on it via CommandEncoder::compute_pass, then hand it to submit when done. Render passes don’t need this — ActiveFrame::begin_pass manages its own frame-tied encoder internally.

Source

pub fn submit(&self, encoder: CommandEncoder)

Finishes and submits encoder’s recorded commands to the queue.

Trait Implementations§

Source§

impl Asset<WGPUBackend> for GPUCompute

Source§

type Source = Compute

The raw source representation stored in Assets.
Source§

type Deps<'a> = ()

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.
Source§

fn upload<'a>( source: &Compute, backend: &WGPUBackend, _deps: &(), ) -> Option<Self>

Convert source into a processed asset using backend and deps. Read more
Source§

impl Asset<WGPUBackend> for GPUCubemap

Source§

type Source = Cubemap

The raw source representation stored in Assets.
Source§

type Deps<'a> = Res<'a, MipmapGenerator>

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.
Source§

fn upload<'a>( source: &Cubemap, backend: &WGPUBackend, mipmap_generator: &Res<'a, MipmapGenerator>, ) -> Option<Self>

Convert source into a processed asset using backend and deps. Read more
Source§

impl<T> Asset<WGPUBackend> for GPUBindingInstance<T>
where T: BindGroupTarget + 'static + Send + Sync,

Source§

type Source = BindingInstance<T>

The raw source representation stored in Assets.
Source§

type Deps<'a> = (Res<'a, ProcessedAssets<T>>, Res<'a, ProcessedAssets<GPUTexture>>, Res<'a, ProcessedAssets<GPUTextureArray>>, Res<'a, ProcessedAssets<GPUCubemap>>, Res<'a, GlobalSamplers>)

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.
Source§

fn upload<'a>( source: &Self::Source, backend: &WGPUBackend, deps: &Self::Deps<'a>, ) -> Option<Self>

Convert source into a processed asset using backend and deps. Read more
Source§

impl Asset<WGPUBackend> for GPUMaterial

Source§

type Source = Material

The raw source representation stored in Assets.
Source§

type Deps<'a> = ()

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.
Source§

fn upload<'a>( source: &Material, backend: &WGPUBackend, _deps: &(), ) -> Option<Self>

Convert source into a processed asset using backend and deps. Read more
Source§

impl Asset<WGPUBackend> for GPUMesh

Source§

type Source = Mesh

The raw source representation stored in Assets.
Source§

type Deps<'a> = ()

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.
Source§

fn upload<'a>(source: &Mesh, backend: &WGPUBackend, _deps: &()) -> Option<Self>

Convert source into a processed asset using backend and deps. Read more
Source§

impl Asset<WGPUBackend> for GPUTextureArray

Source§

type Source = TextureArray

The raw source representation stored in Assets.
Source§

type Deps<'a> = Res<'a, MipmapGenerator>

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.
Source§

fn upload<'a>( source: &TextureArray, backend: &WGPUBackend, mipmap_generator: &Res<'a, MipmapGenerator>, ) -> Option<Self>

Convert source into a processed asset using backend and deps. Read more
Source§

impl Asset<WGPUBackend> for GPUTexture

Source§

type Source = Texture

The raw source representation stored in Assets.
Source§

type Deps<'a> = Res<'a, MipmapGenerator>

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.
Source§

fn upload<'a>( source: &Texture, backend: &WGPUBackend, mipmap_generator: &Res<'a, MipmapGenerator>, ) -> Option<Self>

Convert source into a processed asset using backend and deps. Read more
Source§

impl Backend for WGPUBackend

Source§

fn init( handle: impl GPUSurfaceHandle, width: u32, height: u32, sender: InitSender<Self>, )

Native blocks the calling thread on init_async via pollster::block_on (fine here — this only runs once, during App::build, and there’s no other work competing for the thread yet). Web can’t block its single thread, so it hands init_async to wasm_bindgen_futures::spawn_local instead and returns immediately — GraphicsPlugin polls the resulting sender/InitReceiver pair every tick either way, so callers don’t need to know which path ran. A second Backend implementation should follow the same split if it also needs to run on both targets.

Source§

type Frame = WGPUFrame

The per-frame type that exposes rendering operations.
Source§

fn resize(&mut self, width: u32, height: u32)

Called when the window is resized. Override to recreate the swapchain.
Source§

fn acquire(&mut self) -> Result<Self::Frame, AcquireError>

Acquire the next frame for rendering. Read more
Source§

fn present(&mut self, frame: Self::Frame)

Present the completed frame to the display.
Source§

impl LazyResource<WGPUBackend> for MipmapGenerator

Source§

type Deps<'a> = ()

Other resources this singleton needs before it can be built. Use () if none are needed.
Source§

fn construct<'a>(backend: &WGPUBackend, _deps: &()) -> Option<Self>

Attempt to construct this singleton. Return None if construction can’t succeed yet for a reason not already covered by Deps readiness (e.g. a transient condition) — the plugin will retry next tick.
Source§

impl LazyResource<WGPUBackend> for GlobalSamplers

Source§

type Deps<'a> = ()

Other resources this singleton needs before it can be built. Use () if none are needed.
Source§

fn construct<'a>(backend: &WGPUBackend, _deps: &()) -> Option<Self>

Attempt to construct this singleton. Return None if construction can’t succeed yet for a reason not already covered by Deps readiness (e.g. a transient condition) — the plugin will retry next tick.

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> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more