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
impl WGPUBackend
Sourcepub fn surface_width(&self) -> u32
pub fn surface_width(&self) -> u32
Current surface width in pixels.
Sourcepub fn surface_height(&self) -> u32
pub fn surface_height(&self) -> u32
Current surface height in pixels.
Sourcepub fn surface_format(&self) -> TextureFormat
pub fn surface_format(&self) -> TextureFormat
The format the surface was negotiated at (a preferred sRGB format, chosen when the backend initializes).
Sourcepub fn sample_count(&self) -> u32
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.
Sourcepub fn set_msaa(&mut self, sample_count: u32)
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
impl WGPUBackend
Sourcepub fn create_command_encoder(&self, label: Option<&str>) -> CommandEncoder
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.
Sourcepub fn submit(&self, encoder: CommandEncoder)
pub fn submit(&self, encoder: CommandEncoder)
Finishes and submits encoder’s recorded commands to the queue.
Trait Implementations§
Source§impl Asset<WGPUBackend> for GPUCompute
impl Asset<WGPUBackend> for GPUCompute
Source§impl Asset<WGPUBackend> for GPUCubemap
impl Asset<WGPUBackend> for GPUCubemap
Source§type Deps<'a> = Res<'a, MipmapGenerator>
type Deps<'a> = Res<'a, MipmapGenerator>
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>
fn upload<'a>( source: &Cubemap, backend: &WGPUBackend, mipmap_generator: &Res<'a, MipmapGenerator>, ) -> Option<Self>
Source§impl<T> Asset<WGPUBackend> for GPUBindingInstance<T>
impl<T> Asset<WGPUBackend> for GPUBindingInstance<T>
Source§type Source = BindingInstance<T>
type Source = BindingInstance<T>
Assets.Source§type Deps<'a> = (Res<'a, ProcessedAssets<T>>, Res<'a, ProcessedAssets<GPUTexture>>, Res<'a, ProcessedAssets<GPUTextureArray>>, Res<'a, ProcessedAssets<GPUCubemap>>, Res<'a, GlobalSamplers>)
type Deps<'a> = (Res<'a, ProcessedAssets<T>>, Res<'a, ProcessedAssets<GPUTexture>>, Res<'a, ProcessedAssets<GPUTextureArray>>, Res<'a, ProcessedAssets<GPUCubemap>>, Res<'a, GlobalSamplers>)
B itself) required to perform the conversion.
Use () when there are no extra dependencies.Source§impl Asset<WGPUBackend> for GPUMaterial
impl Asset<WGPUBackend> for GPUMaterial
Source§impl Asset<WGPUBackend> for GPUMesh
impl Asset<WGPUBackend> for GPUMesh
Source§impl Asset<WGPUBackend> for GPUTextureArray
impl Asset<WGPUBackend> for GPUTextureArray
Source§type Source = TextureArray
type Source = TextureArray
Assets.Source§type Deps<'a> = Res<'a, MipmapGenerator>
type Deps<'a> = Res<'a, MipmapGenerator>
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>
fn upload<'a>( source: &TextureArray, backend: &WGPUBackend, mipmap_generator: &Res<'a, MipmapGenerator>, ) -> Option<Self>
Source§impl Asset<WGPUBackend> for GPUTexture
impl Asset<WGPUBackend> for GPUTexture
Source§type Deps<'a> = Res<'a, MipmapGenerator>
type Deps<'a> = Res<'a, MipmapGenerator>
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>
fn upload<'a>( source: &Texture, backend: &WGPUBackend, mipmap_generator: &Res<'a, MipmapGenerator>, ) -> Option<Self>
Source§impl Backend for WGPUBackend
impl Backend for WGPUBackend
Source§fn init(
handle: impl GPUSurfaceHandle,
width: u32,
height: u32,
sender: InitSender<Self>,
)
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§fn resize(&mut self, width: u32, height: u32)
fn resize(&mut self, width: u32, height: u32)
Source§impl LazyResource<WGPUBackend> for MipmapGenerator
impl LazyResource<WGPUBackend> for MipmapGenerator
Source§impl LazyResource<WGPUBackend> for GlobalSamplers
impl LazyResource<WGPUBackend> for GlobalSamplers
Auto Trait Implementations§
impl !Freeze for WGPUBackend
impl !RefUnwindSafe for WGPUBackend
impl !UnwindSafe for WGPUBackend
impl Send for WGPUBackend
impl Sync for WGPUBackend
impl Unpin for WGPUBackend
impl UnsafeUnpin for WGPUBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Component for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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