Struct nannou::wgpu::Instance

source ·
pub struct Instance { /* private fields */ }
Expand description

Context for all other wgpu objects. Instance of wgpu.

This is the first thing you create when using wgpu. Its primary use is to create Adapters and Surfaces.

Does not have to be kept alive.

Corresponds to WebGPU GPU.

Implementations§

source§

impl Instance

source

pub fn new(instance_desc: InstanceDescriptor) -> Instance

Create an new instance of wgpu.

Arguments
  • instance_desc - Has fields for which backends wgpu will choose during instantiation, and which [DX12 shader compiler][Dx12Compiler] wgpu will use.
source

pub unsafe fn from_hal<A>(hal_instance: <A as Api>::Instance) -> Instance
where A: HalApi,

Create an new instance of wgpu from a wgpu-hal instance.

Arguments
  • hal_instance - wgpu-hal instance.
Safety

Refer to the creation of wgpu-hal Instance for every backend.

source

pub unsafe fn as_hal<A>(&self) -> Option<&<A as Api>::Instance>
where A: HalApi,

Return a reference to a specific backend instance, if available.

If this Instance has a wgpu-hal Instance for backend A, return a reference to it. Otherwise, return None.

Safety
  • The raw instance handle returned must not be manually destroyed.
source

pub unsafe fn from_core(core_instance: Instance) -> Instance

Create an new instance of wgpu from a wgpu-core instance.

Arguments
  • core_instance - wgpu-core instance.
Safety

Refer to the creation of wgpu-core Instance.

source

pub fn enumerate_adapters(&self, backends: Backends) -> impl ExactSizeIterator

Retrieves all available Adapters that match the given Backends.

Arguments
  • backends - Backends from which to enumerate adapters.
source

pub fn request_adapter( &self, options: &RequestAdapterOptions<&Surface> ) -> impl Future<Output = Option<Adapter>> + WasmNotSend

Retrieves an Adapter which matches the given RequestAdapterOptions.

Some options are “soft”, so treated as non-mandatory. Others are “hard”.

If no adapters are found that suffice all the “hard” options, None is returned.

source

pub unsafe fn create_adapter_from_hal<A>( &self, hal_adapter: ExposedAdapter<A> ) -> Adapter
where A: HalApi,

Converts a wgpu-hal ExposedAdapter to a wgpu Adapter.

Safety

hal_adapter must be created from this instance internal handle.

source

pub unsafe fn create_surface<W>( &self, window: &W ) -> Result<Surface, CreateSurfaceError>
where W: HasRawWindowHandle + HasRawDisplayHandle,

Creates a surface from a raw window handle.

If the specified display and window handle are not supported by any of the backends, then the surface will not be supported by any adapters.

Safety
  • raw_window_handle must be a valid object to create a surface upon.
  • raw_window_handle must remain valid until after the returned Surface is dropped.
Errors
  • On WebGL2: Will return an error if the browser does not support WebGL2, or declines to provide GPU access (such as due to a resource shortage).
Panics
  • On macOS/Metal: will panic if not called on the main thread.
  • On web: will panic if the raw_window_handle does not properly refer to a canvas element.
source

pub fn poll_all(&self, force_wait: bool) -> bool

Polls all devices.

If force_wait is true and this is not running on the web, then this function will block until all in-flight buffers have been mapped and all submitted commands have finished execution.

Return true if all devices’ queues are empty, or false if there are queue submissions still in flight. (Note that, unless access to all Queues associated with this Instance is coordinated somehow, this information could be out of date by the time the caller receives it. Queues can be shared between threads, and other threads could submit new work at any time.)

On the web, this is a no-op. Devices are automatically polled.

source

pub fn generate_report(&self) -> GlobalReport

Generates memory report.

Trait Implementations§

source§

impl Debug for Instance

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Instance

source§

fn default() -> Instance

Creates a new instance of wgpu with default options.

Backends are set to Backends::all(), and FXC is chosen as the dx12_shader_compiler.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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<T, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. 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.

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

§

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