pub struct Instance { /* private fields */ }unstable-wgpu-27 only.Expand description
Contains the various entry points to start interacting with the system’s GPUs.
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(desc: &InstanceDescriptor) -> Instance
pub fn new(desc: &InstanceDescriptor) -> Instance
Create an new instance of wgpu using the given options and enabled backends.
§Panics
- If no backend feature for the active target platform is enabled,
this method will panic; see
Instance::enabled_backend_features().
Sourcepub const fn enabled_backend_features() -> Backends
pub const fn enabled_backend_features() -> Backends
Returns which backends can be picked for the current build configuration.
The returned set depends on a combination of target platform and enabled features. This does not do any runtime checks and is exclusively based on compile time information.
InstanceDescriptor::backends does not need to be a subset of this,
but any backend that is not in this set, will not be picked.
Sourcepub fn wgsl_language_features(&self) -> WgslLanguageFeatures
pub fn wgsl_language_features(&self) -> WgslLanguageFeatures
Returns the set of WGSL language extensions supported by this instance.
Sourcepub fn enumerate_adapters(&self, backends: Backends) -> Vec<Adapter>
pub fn enumerate_adapters(&self, backends: Backends) -> Vec<Adapter>
Sourcepub fn request_adapter(
&self,
options: &RequestAdapterOptions<&Surface<'_>>,
) -> impl Future<Output = Result<Adapter, RequestAdapterError>> + WasmNotSend
pub fn request_adapter( &self, options: &RequestAdapterOptions<&Surface<'_>>, ) -> impl Future<Output = Result<Adapter, RequestAdapterError>> + 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 satisfy all the “hard” options, an error is returned.
When targeting WebGL2, a compatible_surface
must be specified; using RequestAdapterOptions::default() will not succeed.
Sourcepub fn create_surface<'window>(
&self,
target: impl Into<SurfaceTarget<'window>>,
) -> Result<Surface<'window>, CreateSurfaceError>
pub fn create_surface<'window>( &self, target: impl Into<SurfaceTarget<'window>>, ) -> Result<Surface<'window>, CreateSurfaceError>
Creates a new surface targeting a given window/canvas/surface/etc..
Internally, this creates surfaces for all backends that are enabled for this instance.
See SurfaceTarget for what targets are supported.
See Instance::create_surface_unsafe for surface creation with unsafe target variants.
Most commonly used are window handles (or provider of windows handles)
which can be passed directly as they’re automatically converted to SurfaceTarget.
Sourcepub unsafe fn create_surface_unsafe<'window>(
&self,
target: SurfaceTargetUnsafe,
) -> Result<Surface<'window>, CreateSurfaceError>
pub unsafe fn create_surface_unsafe<'window>( &self, target: SurfaceTargetUnsafe, ) -> Result<Surface<'window>, CreateSurfaceError>
Creates a new surface targeting a given window/canvas/surface/etc. using an unsafe target.
Internally, this creates surfaces for all backends that are enabled for this instance.
See SurfaceTargetUnsafe for what targets are supported.
See Instance::create_surface for surface creation with safe target variants.
§Safety
- See respective
SurfaceTargetUnsafevariants for safety requirements.
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) -> Option<GlobalReport>
pub fn generate_report(&self) -> Option<GlobalReport>
Generates memory report.
Returns None if the feature is not supported by the backend
which happens only when WebGPU is pre-selected by the instance creation.
Source§impl Instance
Interop with wgpu-hal.
impl Instance
Interop with wgpu-hal.
Sourcepub unsafe fn from_hal<A>(hal_instance: <A as Api>::Instance) -> Instancewhere
A: Api,
pub unsafe fn from_hal<A>(hal_instance: <A as Api>::Instance) -> Instancewhere
A: Api,
Create an new instance of wgpu from a wgpu-hal instance. This is often useful when you need to do backend specific logic, or interop with an existing backend instance.
§Types
The type of A::Instance depends on the backend:
hal::api::Vulkanuseshal::vulkan::Instancehal::api::Metaluseshal::metal::Instancehal::api::Dx12useshal::dx12::Instancehal::api::Glesuseshal::gles::Instance
§Safety
- The
hal_instancemust be a valid and usable instance of the backend specified byA. - wgpu will act like it has complete ownership of this instance, and will destroy it when the last reference to the instance, internal or external, is dropped.
Sourcepub unsafe fn as_hal<A>(&self) -> Option<&<A as Api>::Instance>where
A: Api,
pub unsafe fn as_hal<A>(&self) -> Option<&<A as Api>::Instance>where
A: Api,
Get the wgpu_hal instance from this Instance.
Find the Api struct corresponding to the active backend in wgpu_hal::api,
and pass that struct to the to the A type parameter.
Returns a guard that dereferences to the type of the hal backend
which implements A::Instance.
§Types
hal::api::Vulkanuseshal::vulkan::Instancehal::api::Metaluseshal::metal::Instancehal::api::Dx12useshal::dx12::Instancehal::api::Glesuseshal::gles::Instance
§Errors
This method will return None if:
- The instance is not from the backend specified by
A. - The instance is from the
webgpuorcustombackend.
§Safety
- The returned resource must not be destroyed unless the guard is the last reference to it and it is not in use by the GPU. The guard and handle may be dropped at any time however.
- All the safety requirements of wgpu-hal must be upheld.
Sourcepub unsafe fn create_adapter_from_hal<A>(
&self,
hal_adapter: ExposedAdapter<A>,
) -> Adapterwhere
A: Api,
pub unsafe fn create_adapter_from_hal<A>(
&self,
hal_adapter: ExposedAdapter<A>,
) -> Adapterwhere
A: Api,
Converts a wgpu-hal hal::ExposedAdapter to a wgpu Adapter.
§Types
The type of hal_adapter.adapter depends on the backend:
hal::api::Vulkanuseshal::vulkan::Adapterhal::api::Metaluseshal::metal::Adapterhal::api::Dx12useshal::dx12::Adapterhal::api::Glesuseshal::gles::Adapter
§Safety
hal_adapter must be created from this instance internal handle.
Trait Implementations§
Source§impl Default for Instance
impl Default for Instance
Source§fn default() -> Instance
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.
§Panics
If no backend feature for the active target platform is enabled,
this method will panic, see Instance::enabled_backend_features().
Source§impl Ord for Instance
impl Ord for Instance
Source§impl PartialOrd for Instance
impl PartialOrd for Instance
impl Eq for Instance
Auto Trait Implementations§
impl Freeze for Instance
impl !RefUnwindSafe for Instance
impl Send for Instance
impl Sync for Instance
impl Unpin for Instance
impl !UnwindSafe for Instance
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.