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
impl Instance
sourcepub fn new(instance_desc: InstanceDescriptor) -> Instance
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 wgpu will use.
sourcepub fn enumerate_adapters(&self, backends: Backends) -> impl ExactSizeIterator
pub fn enumerate_adapters(&self, backends: Backends) -> impl ExactSizeIterator
sourcepub fn request_adapter(
&self,
options: &RequestAdapterOptions<&Surface>
) -> impl Future<Output = Option<Adapter>> + WasmNotSend
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.
sourcepub unsafe fn create_adapter_from_hal<A>(
&self,
hal_adapter: ExposedAdapter<A>
) -> Adapterwhere
A: HalApi,
pub unsafe fn create_adapter_from_hal<A>(
&self,
hal_adapter: ExposedAdapter<A>
) -> Adapterwhere
A: HalApi,
sourcepub unsafe fn create_surface<W>(
&self,
window: &W
) -> Result<Surface, CreateSurfaceError>where
W: HasRawWindowHandle + HasRawDisplayHandle,
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_handlemust be a valid object to create a surface upon.raw_window_handlemust remain valid until after the returnedSurfaceis 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_handledoes not properly refer to a canvas element.
sourcepub fn poll_all(&self, force_wait: bool) -> bool
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.
sourcepub fn generate_report(&self) -> GlobalReport
pub fn generate_report(&self) -> GlobalReport
Generates memory report.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Instance
impl Send for Instance
impl Sync for Instance
impl Unpin for Instance
impl !UnwindSafe for Instance
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
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
source§impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
source§fn convert_into(self) -> U
fn convert_into(self) -> U
source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains the unclamped color. Read more