Skip to main content

Device

Struct Device 

Source
pub struct Device { /* private fields */ }
Expand description

Structure describing a logical device. Some members are internally mutable, stored behind mutexes.

Implementations§

Source§

impl Device

Source

pub unsafe fn as_hal<A: Api>( self: Arc<Self>, ) -> Option<impl Deref<Target = A::Device>>

§Safety
  • The raw device handle must not be manually destroyed
Source

pub unsafe fn fence_as_hal<A: Api>( self: Arc<Self>, ) -> Option<impl Deref<Target = A::Fence>>

§Safety
  • The raw fence handle must not be manually destroyed
Source§

impl Device

Source

pub fn require_acceleration_structures(&self) -> Result<(), MissingFeatures>

Requires any feature that allows acceleration structures as they can be provided by multiple extensions.

Source

pub fn create_blas( self: &Arc<Self>, blas_desc: &BlasDescriptor<'_>, sizes: BlasGeometrySizeDescriptors, ) -> (Arc<Blas>, Option<CreateBlasError>)

Source

pub fn create_tlas( self: &Arc<Self>, desc: &TlasDescriptor<'_>, ) -> (Arc<Tlas>, Option<CreateTlasError>)

Source

pub fn create_ray_tracing_pipeline( self: &Arc<Self>, desc: RayTracingPipelineDescriptor<'_>, ) -> (Arc<RayTracingPipeline>, Option<CreatePipelineError>)

Source

pub fn create_ray_tracing_pipeline_inner( self: &Arc<Self>, desc: RayTracingPipelineDescriptor<'_>, ) -> Result<Arc<RayTracingPipeline>, CreatePipelineError>

Source§

impl Device

Source

pub fn features(&self) -> &Features

Source

pub fn limits(&self) -> &Limits

Source

pub fn downlevel(&self) -> &DownlevelCapabilities

Source

pub fn adapter_info(&self) -> AdapterInfo

Source§

impl Device

Source

pub fn require_features(&self, feature: Features) -> Result<(), MissingFeatures>

Source

pub unsafe fn start_graphics_debugger_capture(&self)

§Safety
Source

pub unsafe fn stop_graphics_debugger_capture(&self)

§Safety
Source§

impl Device

Source

pub fn late_init_resources_with_queue( self: &Arc<Self>, ) -> Result<(), RequestDeviceError>

Source

pub fn backend(&self) -> Backend

Returns the backend this device is using.

Source

pub fn adapter(&self) -> &Arc<Adapter> ⓘ

Returns a reference to the adapter this device was created from.

Source

pub fn is_valid(&self) -> bool

Return true if self is still valid.

Note that a false result here does not guarantee that no further activity will occur on the Device. A Device can be marked invalid at any time, even while locks are held, meaning that operations begun before the Device was marked invalid will still generally run to completion. This is a consequence of making Device::valid an AtomicBool. It could be avoided by making Device::valid an ordinary bool field protected by the same locks that all other operations acquire, but we use an AtomicBool because there are many device validity checks and we want those to be cheap.

Source

pub fn check_is_valid(&self) -> Result<(), DeviceError>

Return Err(DeviceError) if self is not valid. Otherwise, return Ok(()).

Note that an Err result here does not guarantee that no further activity will occur on the Device. See the documentation for is_valid for details.

Source

pub fn take_trace(&self) -> Option<Box<dyn Trace + Send + Sync + 'static>>

Available on crate feature trace only.

Stop tracing and return the trace object.

This is mostly useful for in-memory traces.

Source

pub fn lose_if_oom(&self)

Checks that we are operating within the memory budget reported by the native APIs.

If we are not, the device gets invalidated.

The budget might fluctuate over the lifetime of the application, so it should be checked somewhat frequently.

Source

pub fn handle_hal_error(&self, error: DeviceError) -> DeviceError

Source

pub fn handle_hal_error_with_nonfatal_oom( &self, error: DeviceError, ) -> DeviceError

Source

pub fn get_queue(&self) -> Option<Arc<Queue>>

Source

pub fn set_queue(&self, queue: &Arc<Queue>)

Source

pub fn poll( &self, poll_type: PollType<SubmissionIndex>, ) -> Result<PollStatus, WaitIdleError>

Check device for freeable resources and completed buffer mappings.

Source

pub fn create_buffer_inner( self: &Arc<Self>, desc: &BufferDescriptor<'_>, ) -> Result<Arc<Buffer>, CreateBufferError>

Source

pub fn create_buffer( self: &Arc<Self>, desc: &BufferDescriptor<'_>, ) -> Arc<Buffer> ⓘ

Source

pub fn set_buffer_data( self: &Arc<Self>, buffer: &Arc<Buffer>, offset: BufferAddress, data: &[u8], mode: MapMode, ) -> BufferAccessResult

Available on crate feature replay only.
Source

pub unsafe fn create_texture_from_hal( self: &Arc<Self>, hal_texture: Box<dyn DynTexture>, desc: &TextureDescriptor<'_>, initial_state: TextureUses, cleared: bool, ) -> (Arc<Texture>, Option<CreateTextureError>)

§Safety
  • hal_texture must be created from device_id corresponding raw handle.
  • hal_texture must be created respecting desc
  • hal_texture must be initialized
  • The initial_state must match the actual driver-side state of the wrapped resource at the moment of wrap.
Source

pub unsafe fn create_buffer_from_hal( self: &Arc<Self>, hal_buffer: Box<dyn DynBuffer>, desc: &BufferDescriptor<'_>, ) -> (Arc<Buffer>, Option<CreateBufferError>)

§Safety
  • hal_buffer must have been created on this device.
  • hal_buffer must have been created respecting desc (in particular, the size, which must always be a multiple of 4, and may be subject to other requirements).
  • hal_buffer must be initialized.
  • hal_buffer must not have zero size.
Source

pub fn validate_texture_descriptor( self: &Arc<Self>, desc: &TextureDescriptor<'_>, ) -> Result<(), CreateTextureError>

Validate a texture descriptor.

This applies the same validation as Self::create_texture, without actually creating a texture.

Source

pub fn create_texture( self: &Arc<Self>, desc: &TextureDescriptor<'_>, ) -> Arc<Texture> ⓘ

Source

pub fn create_texture_error( self: &Arc<Self>, desc: &TextureDescriptor<'_>, ) -> Arc<Texture> ⓘ

Creates a texture that is guaranteed to be invalid

Source

pub fn create_external_texture( self: &Arc<Self>, desc: &ExternalTextureDescriptor<'_>, planes: &[Arc<TextureView>], ) -> Arc<ExternalTexture> ⓘ

Source

pub fn create_sampler( self: &Arc<Self>, desc: &SamplerDescriptor<'_>, ) -> Arc<Sampler> ⓘ

Source

pub fn create_shader_module<'a>( self: &Arc<Self>, desc: &ShaderModuleDescriptor<'a>, source: ShaderModuleSource<'a>, ) -> Arc<ShaderModule> ⓘ

Source

pub unsafe fn create_shader_module_passthrough<'a>( self: &Arc<Self>, desc: &ShaderModuleDescriptorPassthrough<'a>, ) -> Arc<ShaderModule> ⓘ

§Safety

This function passes source code or binary to the backend as-is and can potentially result in a driver crash.

Source

pub fn create_command_encoder( self: &Arc<Self>, desc: &CommandEncoderDescriptor<Label<'_>>, ) -> Arc<CommandEncoder> ⓘ

Source

pub fn create_render_bundle_encoder( self: &Arc<Self>, desc: &RenderBundleEncoderDescriptor<'_>, ) -> Box<RenderBundleEncoder>

Source

pub fn create_bind_group_layout<BGLE>( self: &Arc<Self>, desc: &BindGroupLayoutDescriptor<'_, BGLE>, ) -> Arc<BindGroupLayout> ⓘ

Source

pub fn create_bind_group( self: &Arc<Self>, desc: &BindGroupDescriptor<'_>, ) -> Arc<BindGroup> ⓘ

Source

pub fn create_bind_group_inner( self: &Arc<Self>, desc: &BindGroupDescriptor<'_>, ) -> Result<Arc<BindGroup>, CreateBindGroupError>

Source

pub fn create_pipeline_layout( self: &Arc<Self>, desc: &PipelineLayoutDescriptor<'_>, ) -> Arc<PipelineLayout> ⓘ

Source

pub fn create_compute_pipeline( self: &Arc<Self>, desc: ComputePipelineDescriptor<'_>, ) -> Arc<ComputePipeline> ⓘ

Creates a compute pipeline. If the creation fails, it will handle error in device and return an invalid compute pipeline.

Corresponds to GPUDevice.createComputePipeline

Source

pub fn create_compute_pipeline_or_error( self: &Arc<Self>, desc: ComputePipelineDescriptor<'_>, ) -> Result<Arc<ComputePipeline>, CreatePipelineError>

Creates a compute pipeline without raising any error to device. Device lost errors will be mapped to invalid compute pipeline as required by specification.

Corresponds to GPUDevice.createComputePipelineAsync

Source

pub fn create_render_pipeline( self: &Arc<Self>, desc: ResolvedGeneralRenderPipelineDescriptor<'_>, ) -> Arc<RenderPipeline> ⓘ

Creates a render pipeline. If the creation fails, it will handle error in device and return an invalid render pipeline.

Corresponds to GPUDevice.createRenderPipeline

Source

pub fn create_render_pipeline_or_error( self: &Arc<Self>, desc: ResolvedGeneralRenderPipelineDescriptor<'_>, ) -> Result<Arc<RenderPipeline>, CreatePipelineError>

Creates a render pipeline without raising any error to device. Device lost errors will be mapped to invalid render pipeline as required by specification.

Corresponds to GPUDevice.createRenderPipelineAsync

Source

pub unsafe fn create_pipeline_cache( self: &Arc<Self>, desc: &PipelineCacheDescriptor<'_>, ) -> (Arc<PipelineCache>, Option<CreatePipelineCacheError>)

§Safety

The data field on desc must have previously been returned from pipeline::PipelineCache::get_data

Source

pub fn create_query_set( self: &Arc<Self>, desc: &QuerySetDescriptor<'_>, ) -> Arc<QuerySet> ⓘ

Source

pub fn set_device_lost_closure(&self, device_lost_closure: DeviceLostClosure)

device_lost_closure might never be called.

Source

pub fn destroy(self: &Arc<Self>)

Source

pub fn get_internal_counters(&self) -> InternalCounters

Source

pub fn get_hal_counters(&self) -> HalCounters

Source

pub fn generate_allocator_report(&self) -> Option<AllocatorReport>

Source§

impl Device

Source§

impl Device

Source

pub fn error_sink(&self) -> &ErrorSink

Source§

impl Device

Source

pub fn handle_error( &self, source: impl WebGpuError + WasmNotSendSync + 'static, label: Option<&str>, fn_ident: &'static str, )

Source

pub fn handle_error_nolabel( &self, source: impl WebGpuError + WasmNotSendSync + 'static, fn_ident: &'static str, )

Source§

impl Device

Trait Implementations§

Source§

impl Debug for Device

Source§

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

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

impl Drop for Device

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Labeled for Device

Source§

fn label(&self) -> &str

Returns a string identifying this resource for logging and errors. Read more
Source§

fn error_ident(&self) -> ResourceErrorIdent

Source§

impl ResourceType for Device

Source§

const TYPE: &'static str = "Device"

Source§

impl Send for Device

Available on send_sync only.
Source§

impl Sync for Device

Available on send_sync only.

Auto Trait Implementations§

§

impl !Freeze for Device

§

impl !RefUnwindSafe for Device

§

impl !UnwindSafe for Device

§

impl Forget for Device

§

impl Move for Device

§

impl Unpin for Device
where Align8<*mut Waiter>: Unpin, *const ArcInner<Queue> is !null: Unpin, Box<dyn DynBuffer>: Unpin, Box<dyn DynBindGroupLayout>: Unpin, *const u8 is !null: Unpin, Align1<u8>: Unpin, Box<dyn DynCommandEncoder>: Unpin, InternalBitFlags: Unpin, Align8<usize>: Unpin, Align8<u64>: Unpin, Box<dyn DynFence>: Unpin, Box<dyn FnOnce(DeviceLostReason, String) + Send>: Unpin, NonZero<u64>: Unpin, Box<dyn Error + Sync + Send>: Unpin, Arc<dyn UncapturedErrorHandler<Output = ()>>: Unpin, InternalBitFlags: Unpin, *const ArcInner<Buffer> is !null: Unpin, (): Unpin, InternalBitFlags: Unpin, *const (Range<u32>, TextureUses) is !null: Unpin, (Range<u32>, TextureUses): Unpin, *const ArcInner<Texture> is !null: Unpin, TextureSelector: Unpin, Arc<SharedTrackerIndexAllocator>: Unpin, InternalBitFlags: Unpin, InternalBitFlags: Unpin, NonZero<u32>: Unpin, Arc<OnceCell<Weak<BindGroupLayout>>>: Unpin, InternalBitFlags: Unpin, InternalBitFlags: Unpin, InternalBitFlags: Unpin, InternalBitFlags: Unpin, *const ArcInner<TextureView> is !null: Unpin, *const ArcInner<BindGroup> is !null: Unpin, Box<dyn FnOnce(Result<MapMode, BufferAccessError>) + Send>: Unpin, Box<DeviceMismatch>: Unpin, &'static str: Unpin, String: Unpin, InternalBitFlags: Unpin, InternalBitFlags: Unpin, InternalBitFlags: Unpin, Arc<Buffer>: Unpin, Arc<Texture>: Unpin, Box<dyn DynShaderModule>: Unpin, Box<dyn DynPipelineLayout>: Unpin, Box<dyn DynComputePipeline>: Unpin, Box<dyn DynBindGroup>: Unpin, Box<dyn DynDevice>: Unpin, Arc<Adapter>: Unpin, Box<dyn Trace + Sync + Send>: Unpin,

§

impl UnsafeUnpin for Device
where Align8<*mut Waiter>: UnsafeUnpin, *const ArcInner<Queue> is !null: UnsafeUnpin, *const dyn DynBuffer is !null: UnsafeUnpin, PhantomData<dyn DynBuffer>: UnsafeUnpin, *const dyn DynBindGroupLayout is !null: UnsafeUnpin, PhantomData<dyn DynBindGroupLayout>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, Align1<u8>: UnsafeUnpin, PhantomData<Box<dyn DynCommandEncoder>>: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, Align8<usize>: UnsafeUnpin, Align8<u64>: UnsafeUnpin, *const dyn DynFence is !null: UnsafeUnpin, PhantomData<dyn DynFence>: UnsafeUnpin, *const dyn FnOnce(DeviceLostReason, String) + Send is !null: UnsafeUnpin, PhantomData<dyn FnOnce(DeviceLostReason, String) + Send>: UnsafeUnpin, PhantomData<(ThreadId, Vec<ErrorScope>)>: UnsafeUnpin, *const ArcInner<dyn UncapturedErrorHandler<Output = ()>> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn UncapturedErrorHandler<Output = ()>>>: UnsafeUnpin, PhantomData<BufferUses>: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, PhantomData<Option<Weak<Buffer>>>: UnsafeUnpin, PhantomData<PendingTransition<BufferUses>>: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, PhantomData<TextureUses>: UnsafeUnpin, PhantomData<fn() -> FxHasher>: UnsafeUnpin, PhantomData<(usize, ComplexTextureState)>: UnsafeUnpin, PhantomData<Option<Weak<Texture>>>: UnsafeUnpin, PhantomData<PendingTransition<TextureUses>>: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, *const ArcInner<SharedTrackerIndexAllocator> is !null: UnsafeUnpin, PhantomData<ArcInner<SharedTrackerIndexAllocator>>: UnsafeUnpin, PhantomData<(EntryMap, Arc<OnceCell<Weak<BindGroupLayout>>>)>: UnsafeUnpin, NonZeroU64Inner: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, PhantomData<DeferredDestroy>: UnsafeUnpin, PhantomData<(Option<Box<dyn FnOnce(Result<MapMode, BufferAccessError>) + Send>>, Result<MapMode, BufferAccessError>)>: UnsafeUnpin, PhantomData<(BufferUsageScope, TextureUsageScope)>: UnsafeUnpin, *const dyn DynShaderModule is !null: UnsafeUnpin, PhantomData<dyn DynShaderModule>: UnsafeUnpin, *const dyn DynPipelineLayout is !null: UnsafeUnpin, PhantomData<dyn DynPipelineLayout>: UnsafeUnpin, *const dyn DynComputePipeline is !null: UnsafeUnpin, PhantomData<dyn DynComputePipeline>: UnsafeUnpin, *const dyn DynBindGroup is !null: UnsafeUnpin, PhantomData<dyn DynBindGroup>: UnsafeUnpin, PhantomData<BufferPoolEntry>: UnsafeUnpin, *const dyn DynDevice is !null: UnsafeUnpin, PhantomData<dyn DynDevice>: UnsafeUnpin, *const ArcInner<Adapter> is !null: UnsafeUnpin, PhantomData<ArcInner<Adapter>>: UnsafeUnpin, *const dyn Trace + Sync + Send is !null: UnsafeUnpin, PhantomData<dyn Trace + Sync + Send>: UnsafeUnpin,

Blanket Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

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.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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