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

Create an new instance of wgpu.

Arguments
Available on non-WebAssembly or crate feature emscripten only.

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.

Available on non-WebAssembly or crate feature webgl only.

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.
Available on non-WebAssembly or crate feature webgl only.

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.

Available on non-WebAssembly or crate feature emscripten only.

Retrieves all available Adapters that match the given Backends.

Arguments
  • backends - Backends from which to enumerate adapters.

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.

Available on non-WebAssembly or crate feature emscripten only.

Converts a wgpu-hal ExposedAdapter to a wgpu Adapter.

Safety

hal_adapter must be created from this instance internal handle.

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.

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.

Available on non-WebAssembly or crate feature emscripten only.

Generates memory report.

Trait Implementations§

Formats the value using the given formatter. Read more

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§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.