aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gpudevice.rs
diff options
context:
space:
mode:
authorSamson <16504129+sagudev@users.noreply.github.com>2024-06-17 14:47:25 +0200
committerGitHub <noreply@github.com>2024-06-17 12:47:25 +0000
commitcbc9304c2002fb0d5c8cdade39eddfe117b12053 (patch)
treeffb9afd683f8ec9d6eda26e3ba395d3214718b72 /components/script/dom/gpudevice.rs
parent3381f2a70442aa6a6c31a0bc4a4c3601299631f5 (diff)
downloadservo-cbc9304c2002fb0d5c8cdade39eddfe117b12053.tar.gz
servo-cbc9304c2002fb0d5c8cdade39eddfe117b12053.zip
webgpu: Implement device lost (#32354)
* device lost promise should be init at creation of device object * device lost impl * lock for device poll workaround for wgpu deadlocks * expect * Less lost reason reasoning in script
Diffstat (limited to 'components/script/dom/gpudevice.rs')
-rw-r--r--components/script/dom/gpudevice.rs42
1 files changed, 21 insertions, 21 deletions
diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs
index 01c2b0a54a8..9e7c8c76b09 100644
--- a/components/script/dom/gpudevice.rs
+++ b/components/script/dom/gpudevice.rs
@@ -84,8 +84,9 @@ pub struct GPUDevice {
#[no_trace]
device: webgpu::WebGPUDevice,
default_queue: Dom<GPUQueue>,
+ /// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-lost>
#[ignore_malloc_size_of = "promises are hard"]
- lost_promise: DomRefCell<Option<Rc<Promise>>>,
+ lost_promise: DomRefCell<Rc<Promise>>,
valid: Cell<bool>,
}
@@ -100,6 +101,7 @@ impl GPUDevice {
device: webgpu::WebGPUDevice,
queue: &GPUQueue,
label: String,
+ lost_promise: Rc<Promise>,
) -> Self {
Self {
eventtarget: EventTarget::new_inherited(),
@@ -111,7 +113,7 @@ impl GPUDevice {
label: DomRefCell::new(USVString::from(label)),
device,
default_queue: Dom::from_ref(queue),
- lost_promise: DomRefCell::new(None),
+ lost_promise: DomRefCell::new(lost_promise),
valid: Cell::new(true),
}
}
@@ -131,9 +133,18 @@ impl GPUDevice {
let queue = GPUQueue::new(global, channel.clone(), queue);
let limits = GPUSupportedLimits::new(global, limits);
let features = GPUSupportedFeatures::Constructor(global, None, features).unwrap();
+ let lost_promise = Promise::new(global);
let device = reflect_dom_object(
Box::new(GPUDevice::new_inherited(
- channel, adapter, extensions, &features, &limits, device, &queue, label,
+ channel,
+ adapter,
+ extensions,
+ &features,
+ &limits,
+ device,
+ &queue,
+ label,
+ lost_promise,
)),
global,
);
@@ -206,18 +217,11 @@ impl GPUDevice {
}
/// <https://gpuweb.github.io/gpuweb/#lose-the-device>
- pub fn lose(&self, reason: GPUDeviceLostReason) {
- if let Some(ref lost_promise) = *self.lost_promise.borrow() {
- let global = &self.global();
- let msg = match reason {
- GPUDeviceLostReason::Unknown => "Unknown reason for your device loss.",
- GPUDeviceLostReason::Destroyed => {
- "Device self-destruction sequence activated successfully!"
- },
- };
- let lost = GPUDeviceLostInfo::new(global, msg.into(), reason);
- lost_promise.resolve_native(&*lost);
- }
+ pub fn lose(&self, reason: GPUDeviceLostReason, msg: String) {
+ let ref lost_promise = *self.lost_promise.borrow();
+ let global = &self.global();
+ let lost = GPUDeviceLostInfo::new(global, msg.into(), reason);
+ lost_promise.resolve_native(&*lost);
}
}
@@ -248,10 +252,8 @@ impl GPUDeviceMethods for GPUDevice {
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-lost>
- fn GetLost(&self, comp: InRealm) -> Fallible<Rc<Promise>> {
- let promise = Promise::new_in_current_realm(comp);
- *self.lost_promise.borrow_mut() = Some(promise.clone());
- Ok(promise)
+ fn Lost(&self) -> Rc<Promise> {
+ self.lost_promise.borrow().clone()
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer>
@@ -1000,8 +1002,6 @@ impl GPUDeviceMethods for GPUDevice {
if self.valid.get() {
self.valid.set(false);
- self.lose(GPUDeviceLostReason::Destroyed);
-
if let Err(e) = self
.channel
.0