pub struct Device { /* private fields */ }Expand description
Structure describing a logical device. Some members are internally mutable, stored behind mutexes.
Implementations§
Source§impl Device
impl Device
Source§impl Device
impl Device
Sourcepub fn require_acceleration_structures(&self) -> Result<(), MissingFeatures>
pub fn require_acceleration_structures(&self) -> Result<(), MissingFeatures>
Requires any feature that allows acceleration structures as they can be provided by multiple extensions.
pub fn create_blas( self: &Arc<Self>, blas_desc: &BlasDescriptor<'_>, sizes: BlasGeometrySizeDescriptors, ) -> (Arc<Blas>, Option<CreateBlasError>)
pub fn create_tlas( self: &Arc<Self>, desc: &TlasDescriptor<'_>, ) -> (Arc<Tlas>, Option<CreateTlasError>)
pub fn create_ray_tracing_pipeline( self: &Arc<Self>, desc: RayTracingPipelineDescriptor<'_>, ) -> (Arc<RayTracingPipeline>, Option<CreatePipelineError>)
pub fn create_ray_tracing_pipeline_inner( self: &Arc<Self>, desc: RayTracingPipelineDescriptor<'_>, ) -> Result<Arc<RayTracingPipeline>, CreatePipelineError>
Source§impl Device
impl Device
pub fn features(&self) -> &Features
pub fn limits(&self) -> &Limits
pub fn downlevel(&self) -> &DownlevelCapabilities
pub fn adapter_info(&self) -> AdapterInfo
Source§impl Device
impl Device
pub fn require_features(&self, feature: Features) -> Result<(), MissingFeatures>
Sourcepub unsafe fn start_graphics_debugger_capture(&self)
pub unsafe fn start_graphics_debugger_capture(&self)
§Safety
- See wgpu::Device::start_graphics_debugger_capture for details the safety.
Sourcepub unsafe fn stop_graphics_debugger_capture(&self)
pub unsafe fn stop_graphics_debugger_capture(&self)
§Safety
- See wgpu::Device::stop_graphics_debugger_capture for details the safety.
Source§impl Device
impl Device
pub fn late_init_resources_with_queue( self: &Arc<Self>, ) -> Result<(), RequestDeviceError>
Sourcepub fn adapter(&self) -> &Arc<Adapter> ⓘ
pub fn adapter(&self) -> &Arc<Adapter> ⓘ
Returns a reference to the adapter this device was created from.
Sourcepub fn is_valid(&self) -> bool
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.
Sourcepub fn check_is_valid(&self) -> Result<(), DeviceError>
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.
Sourcepub fn take_trace(&self) -> Option<Box<dyn Trace + Send + Sync + 'static>>
Available on crate feature trace only.
pub fn take_trace(&self) -> Option<Box<dyn Trace + Send + Sync + 'static>>
trace only.Stop tracing and return the trace object.
This is mostly useful for in-memory traces.
Sourcepub fn lose_if_oom(&self)
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.
pub fn handle_hal_error(&self, error: DeviceError) -> DeviceError
pub fn handle_hal_error_with_nonfatal_oom( &self, error: DeviceError, ) -> DeviceError
pub fn get_queue(&self) -> Option<Arc<Queue>>
pub fn set_queue(&self, queue: &Arc<Queue>)
Sourcepub fn poll(
&self,
poll_type: PollType<SubmissionIndex>,
) -> Result<PollStatus, WaitIdleError>
pub fn poll( &self, poll_type: PollType<SubmissionIndex>, ) -> Result<PollStatus, WaitIdleError>
Check device for freeable resources and completed buffer mappings.
pub fn create_buffer_inner( self: &Arc<Self>, desc: &BufferDescriptor<'_>, ) -> Result<Arc<Buffer>, CreateBufferError>
pub fn create_buffer( self: &Arc<Self>, desc: &BufferDescriptor<'_>, ) -> Arc<Buffer> ⓘ
pub fn set_buffer_data( self: &Arc<Self>, buffer: &Arc<Buffer>, offset: BufferAddress, data: &[u8], mode: MapMode, ) -> BufferAccessResult
replay only.Sourcepub 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>)
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_texturemust be created fromdevice_idcorresponding raw handle.hal_texturemust be created respectingdeschal_texturemust be initialized- The
initial_statemust match the actual driver-side state of the wrapped resource at the moment of wrap.
Sourcepub unsafe fn create_buffer_from_hal(
self: &Arc<Self>,
hal_buffer: Box<dyn DynBuffer>,
desc: &BufferDescriptor<'_>,
) -> (Arc<Buffer>, Option<CreateBufferError>)
pub unsafe fn create_buffer_from_hal( self: &Arc<Self>, hal_buffer: Box<dyn DynBuffer>, desc: &BufferDescriptor<'_>, ) -> (Arc<Buffer>, Option<CreateBufferError>)
§Safety
hal_buffermust have been created on this device.hal_buffermust have been created respectingdesc(in particular, the size, which must always be a multiple of 4, and may be subject to other requirements).hal_buffermust be initialized.hal_buffermust not have zero size.
Sourcepub fn validate_texture_descriptor(
self: &Arc<Self>,
desc: &TextureDescriptor<'_>,
) -> Result<(), CreateTextureError>
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.
Sourcepub fn create_texture(
self: &Arc<Self>,
desc: &TextureDescriptor<'_>,
) -> Arc<Texture> ⓘ
pub fn create_texture( self: &Arc<Self>, desc: &TextureDescriptor<'_>, ) -> Arc<Texture> ⓘ
Sourcepub fn create_texture_error(
self: &Arc<Self>,
desc: &TextureDescriptor<'_>,
) -> Arc<Texture> ⓘ
pub fn create_texture_error( self: &Arc<Self>, desc: &TextureDescriptor<'_>, ) -> Arc<Texture> ⓘ
Creates a texture that is guaranteed to be invalid
pub fn create_external_texture( self: &Arc<Self>, desc: &ExternalTextureDescriptor<'_>, planes: &[Arc<TextureView>], ) -> Arc<ExternalTexture> ⓘ
pub fn create_sampler( self: &Arc<Self>, desc: &SamplerDescriptor<'_>, ) -> Arc<Sampler> ⓘ
pub fn create_shader_module<'a>( self: &Arc<Self>, desc: &ShaderModuleDescriptor<'a>, source: ShaderModuleSource<'a>, ) -> Arc<ShaderModule> ⓘ
Sourcepub unsafe fn create_shader_module_passthrough<'a>(
self: &Arc<Self>,
desc: &ShaderModuleDescriptorPassthrough<'a>,
) -> Arc<ShaderModule> ⓘ
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.
pub fn create_command_encoder( self: &Arc<Self>, desc: &CommandEncoderDescriptor<Label<'_>>, ) -> Arc<CommandEncoder> ⓘ
pub fn create_render_bundle_encoder( self: &Arc<Self>, desc: &RenderBundleEncoderDescriptor<'_>, ) -> Box<RenderBundleEncoder>
pub fn create_bind_group_layout<BGLE>(
self: &Arc<Self>,
desc: &BindGroupLayoutDescriptor<'_, BGLE>,
) -> Arc<BindGroupLayout> ⓘwhere
BGLE: TryInto<BindGroupLayoutEntry> + Copy + Into<BindGroupLayoutEntry>,
CreateBindGroupLayoutError: From<<BGLE as TryInto<BindGroupLayoutEntry>>::Error>,
pub fn create_bind_group( self: &Arc<Self>, desc: &BindGroupDescriptor<'_>, ) -> Arc<BindGroup> ⓘ
pub fn create_bind_group_inner( self: &Arc<Self>, desc: &BindGroupDescriptor<'_>, ) -> Result<Arc<BindGroup>, CreateBindGroupError>
pub fn create_pipeline_layout( self: &Arc<Self>, desc: &PipelineLayoutDescriptor<'_>, ) -> Arc<PipelineLayout> ⓘ
Sourcepub fn create_compute_pipeline(
self: &Arc<Self>,
desc: ComputePipelineDescriptor<'_>,
) -> Arc<ComputePipeline> ⓘ
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
Sourcepub fn create_compute_pipeline_or_error(
self: &Arc<Self>,
desc: ComputePipelineDescriptor<'_>,
) -> Result<Arc<ComputePipeline>, CreatePipelineError>
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
Sourcepub fn create_render_pipeline(
self: &Arc<Self>,
desc: ResolvedGeneralRenderPipelineDescriptor<'_>,
) -> Arc<RenderPipeline> ⓘ
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
Sourcepub fn create_render_pipeline_or_error(
self: &Arc<Self>,
desc: ResolvedGeneralRenderPipelineDescriptor<'_>,
) -> Result<Arc<RenderPipeline>, CreatePipelineError>
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
Sourcepub unsafe fn create_pipeline_cache(
self: &Arc<Self>,
desc: &PipelineCacheDescriptor<'_>,
) -> (Arc<PipelineCache>, Option<CreatePipelineCacheError>)
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
pub fn create_query_set( self: &Arc<Self>, desc: &QuerySetDescriptor<'_>, ) -> Arc<QuerySet> ⓘ
Sourcepub fn set_device_lost_closure(&self, device_lost_closure: DeviceLostClosure)
pub fn set_device_lost_closure(&self, device_lost_closure: DeviceLostClosure)
device_lost_closure might never be called.
pub fn destroy(self: &Arc<Self>)
pub fn get_internal_counters(&self) -> InternalCounters
pub fn get_hal_counters(&self) -> HalCounters
pub fn generate_allocator_report(&self) -> Option<AllocatorReport>
Source§impl Device
impl Device
pub fn on_uncaptured_error(&self, handler: Arc<dyn UncapturedErrorHandler>)
Sourcepub fn push_error_scope(&self, filter: ErrorFilter)
pub fn push_error_scope(&self, filter: ErrorFilter)
Source§impl Device
impl Device
pub fn handle_error( &self, source: impl WebGpuError + WasmNotSendSync + 'static, label: Option<&str>, fn_ident: &'static str, )
pub fn handle_error_nolabel( &self, source: impl WebGpuError + WasmNotSendSync + 'static, fn_ident: &'static str, )
Source§impl Device
impl Device
pub fn push_error_scope_with_index(&self, filter: ErrorFilter) -> u32
pub fn pop_error_scope_checked(&self, index: u32) -> Option<Error>
Trait Implementations§
Source§impl Labeled for Device
impl Labeled for Device
Source§fn label(&self) -> &str
fn label(&self) -> &str
fn error_ident(&self) -> ResourceErrorIdent
impl Send for Device
send_sync only.impl Sync for Device
send_sync only.