mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-01-10 21:28:12 -05:00
remove Dropped & ReplacedCallback variants of DeviceLostReason
This commit is contained in:
@@ -625,56 +625,6 @@ static DEVICE_DESTROY_THEN_LOST: GpuTestConfiguration = GpuTestConfiguration::ne
|
||||
);
|
||||
});
|
||||
|
||||
#[gpu_test]
|
||||
static DEVICE_DROP_THEN_LOST: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(TestParameters::default().expect_fail(FailureCase::webgl2()))
|
||||
.run_sync(|ctx| {
|
||||
// This test checks that when the device is dropped (such as in a GC),
|
||||
// the provided DeviceLostClosure is called with reason DeviceLostReason::Dropped.
|
||||
// Fails on webgl because webgl doesn't implement drop.
|
||||
static WAS_CALLED: std::sync::atomic::AtomicBool = AtomicBool::new(false);
|
||||
|
||||
// Set a LoseDeviceCallback on the device.
|
||||
let callback = Box::new(|reason, message| {
|
||||
WAS_CALLED.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
assert_eq!(reason, wgt::DeviceLostReason::Dropped);
|
||||
assert_eq!(message, "Device dropped.");
|
||||
});
|
||||
ctx.device.set_device_lost_callback(callback);
|
||||
|
||||
drop(ctx);
|
||||
|
||||
assert!(
|
||||
WAS_CALLED.load(std::sync::atomic::Ordering::SeqCst),
|
||||
"Device lost callback should have been called."
|
||||
);
|
||||
});
|
||||
|
||||
#[gpu_test]
|
||||
static DEVICE_LOST_REPLACED_CALLBACK: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(TestParameters::default())
|
||||
.run_sync(|ctx| {
|
||||
// This test checks that a device_lost_callback is called when it is
|
||||
// replaced by another callback.
|
||||
static WAS_CALLED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
// Set a LoseDeviceCallback on the device.
|
||||
let callback = Box::new(|reason, _m| {
|
||||
WAS_CALLED.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
assert_eq!(reason, wgt::DeviceLostReason::ReplacedCallback);
|
||||
});
|
||||
ctx.device.set_device_lost_callback(callback);
|
||||
|
||||
// Replace the callback.
|
||||
let replacement_callback = Box::new(move |_r, _m| {});
|
||||
ctx.device.set_device_lost_callback(replacement_callback);
|
||||
|
||||
assert!(
|
||||
WAS_CALLED.load(std::sync::atomic::Ordering::SeqCst),
|
||||
"Device lost callback should have been called."
|
||||
);
|
||||
});
|
||||
|
||||
#[gpu_test]
|
||||
static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(TestParameters::default())
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
},
|
||||
command::{self, CommandBuffer},
|
||||
conv,
|
||||
device::{bgl, life::WaitIdleError, DeviceError, DeviceLostClosure, DeviceLostReason},
|
||||
device::{bgl, life::WaitIdleError, DeviceError, DeviceLostClosure},
|
||||
global::Global,
|
||||
hal_api::HalApi,
|
||||
id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
|
||||
@@ -2083,8 +2083,7 @@ impl Global {
|
||||
self.hub.devices.remove(device_id);
|
||||
}
|
||||
|
||||
// This closure will be called exactly once during "lose the device",
|
||||
// or when it is replaced.
|
||||
/// This closure will be called exactly once during "lose the device".
|
||||
pub fn device_set_device_lost_closure(
|
||||
&self,
|
||||
device_id: DeviceId,
|
||||
@@ -2092,22 +2091,15 @@ impl Global {
|
||||
) {
|
||||
let device = self.hub.devices.get(device_id);
|
||||
|
||||
let old_device_lost_closure = device
|
||||
device
|
||||
.device_lost_closure
|
||||
.lock()
|
||||
.replace(device_lost_closure);
|
||||
|
||||
if let Some(old_device_lost_closure) = old_device_lost_closure {
|
||||
old_device_lost_closure.call(DeviceLostReason::ReplacedCallback, "".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn device_unregister_device_lost_closure(&self, device_id: DeviceId) {
|
||||
let device = self.hub.devices.get(device_id);
|
||||
let closure = device.device_lost_closure.lock().take();
|
||||
if let Some(closure) = closure {
|
||||
closure.call(DeviceLostReason::ReplacedCallback, "".to_string());
|
||||
}
|
||||
device.device_lost_closure.lock().take();
|
||||
}
|
||||
|
||||
pub fn device_destroy(&self, device_id: DeviceId) {
|
||||
|
||||
@@ -149,10 +149,6 @@ impl Drop for Device {
|
||||
fn drop(&mut self) {
|
||||
resource_log!("Drop {}", self.error_ident());
|
||||
|
||||
if let Some(closure) = self.device_lost_closure.lock().take() {
|
||||
closure.call(DeviceLostReason::Dropped, String::from("Device dropped."));
|
||||
}
|
||||
|
||||
// SAFETY: We are in the Drop impl and we don't use self.zero_buffer anymore after this point.
|
||||
let zero_buffer = unsafe { ManuallyDrop::take(&mut self.zero_buffer) };
|
||||
// SAFETY: We are in the Drop impl and we don't use self.fence anymore after this point.
|
||||
|
||||
@@ -7673,18 +7673,4 @@ pub enum DeviceLostReason {
|
||||
Unknown = 0,
|
||||
/// After Device::destroy
|
||||
Destroyed = 1,
|
||||
/// After Device::drop
|
||||
///
|
||||
/// WebGPU does not invoke the device lost callback when the device is
|
||||
/// dropped to prevent garbage collection from being observable. In wgpu,
|
||||
/// we invoke the callback on drop to help with managing memory owned by
|
||||
/// the callback.
|
||||
Dropped = 2,
|
||||
/// After replacing the device_lost_callback
|
||||
///
|
||||
/// WebGPU does not have a concept of a device lost callback, but wgpu
|
||||
/// does. wgpu guarantees that any supplied callback will be invoked
|
||||
/// exactly once before it is dropped, which helps with managing the
|
||||
/// memory owned by the callback.
|
||||
ReplacedCallback = 3,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user