mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
invalidate Device on OOM errors with the exception of buffer, texture, query set and acceleration structure creation
This commit is contained in:
parent
c49620d1a2
commit
c144f2a697
@ -8,7 +8,7 @@ use crate::lock::rank;
|
||||
use crate::resource::{Fallible, TrackingData};
|
||||
use crate::snatch::Snatchable;
|
||||
use crate::{
|
||||
device::{Device, DeviceError},
|
||||
device::Device,
|
||||
global::Global,
|
||||
id::{self, BlasId, TlasId},
|
||||
lock::RwLock,
|
||||
@ -109,7 +109,7 @@ impl Device {
|
||||
allow_compaction: false,
|
||||
})
|
||||
}
|
||||
.map_err(DeviceError::from_hal)?;
|
||||
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;
|
||||
|
||||
let handle = unsafe {
|
||||
self.raw()
|
||||
@ -177,7 +177,7 @@ impl Device {
|
||||
allow_compaction: false,
|
||||
})
|
||||
}
|
||||
.map_err(DeviceError::from_hal)?;
|
||||
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;
|
||||
|
||||
let instance_buffer_size =
|
||||
self.alignments.raw_tlas_instance_size * desc.max_instances.max(1) as usize;
|
||||
@ -190,7 +190,7 @@ impl Device {
|
||||
memory_flags: hal::MemoryFlags::PREFER_COHERENT,
|
||||
})
|
||||
}
|
||||
.map_err(DeviceError::from_hal)?;
|
||||
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;
|
||||
|
||||
Ok(Arc::new(resource::Tlas {
|
||||
raw: Snatchable::new(raw),
|
||||
|
||||
@ -363,8 +363,8 @@ impl Device {
|
||||
|
||||
pub fn handle_hal_error(&self, error: hal::DeviceError) -> DeviceError {
|
||||
match error {
|
||||
hal::DeviceError::OutOfMemory => {}
|
||||
hal::DeviceError::Lost
|
||||
hal::DeviceError::OutOfMemory
|
||||
| hal::DeviceError::Lost
|
||||
| hal::DeviceError::ResourceCreationFailed
|
||||
| hal::DeviceError::Unexpected => {
|
||||
self.lose(&error.to_string());
|
||||
@ -373,6 +373,13 @@ impl Device {
|
||||
DeviceError::from_hal(error)
|
||||
}
|
||||
|
||||
pub fn handle_hal_error_with_nonfatal_oom(&self, error: hal::DeviceError) -> DeviceError {
|
||||
match error {
|
||||
hal::DeviceError::OutOfMemory => DeviceError::from_hal(error),
|
||||
error => self.handle_hal_error(error),
|
||||
}
|
||||
}
|
||||
|
||||
/// Run some destroy operations that were deferred.
|
||||
///
|
||||
/// Destroying the resources requires taking a write lock on the device's snatch lock,
|
||||
@ -679,8 +686,8 @@ impl Device {
|
||||
usage,
|
||||
memory_flags: hal::MemoryFlags::empty(),
|
||||
};
|
||||
let buffer =
|
||||
unsafe { self.raw().create_buffer(&hal_desc) }.map_err(|e| self.handle_hal_error(e))?;
|
||||
let buffer = unsafe { self.raw().create_buffer(&hal_desc) }
|
||||
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;
|
||||
|
||||
let timestamp_normalization_bind_group = Snatchable::new(
|
||||
self.timestamp_normalizer
|
||||
@ -1100,7 +1107,7 @@ impl Device {
|
||||
};
|
||||
|
||||
let raw_texture = unsafe { self.raw().create_texture(&hal_desc) }
|
||||
.map_err(|e| self.handle_hal_error(e))?;
|
||||
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;
|
||||
|
||||
let clear_mode = if hal_usage
|
||||
.intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE | wgt::TextureUses::COLOR_TARGET)
|
||||
@ -3862,7 +3869,7 @@ impl Device {
|
||||
let hal_desc = desc.map_label(|label| label.to_hal(self.instance_flags));
|
||||
|
||||
let raw = unsafe { self.raw().create_query_set(&hal_desc) }
|
||||
.map_err(|e| self.handle_hal_error(e))?;
|
||||
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;
|
||||
|
||||
let query_set = QuerySet {
|
||||
raw: ManuallyDrop::new(raw),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user