Proper GPUDevice cleanup (#32520)

* Make device cleanup right

* Use weakref for GPUDevice in globalscope

* No need to destroy device on drop

* DeviceReason early return

* make remove_gpu_device to be the only way to remove device
This commit is contained in:
Samson 2024-06-20 07:56:59 +02:00 committed by GitHub
parent 256c55eb81
commit bf99cf7f30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 89 additions and 43 deletions

View file

@ -92,7 +92,7 @@ use style::dom::OpaqueNode;
use style::thread_state::{self, ThreadState};
use time::precise_time_ns;
use url::Position;
use webgpu::WebGPUMsg;
use webgpu::{WebGPUDevice, WebGPUMsg};
use webrender_api::DocumentId;
use webrender_traits::WebRenderScriptApi;
@ -2423,7 +2423,14 @@ impl ScriptThread {
fn handle_msg_from_webgpu_server(&self, msg: WebGPUMsg) {
match msg {
WebGPUMsg::FreeAdapter(id) => self.gpu_id_hub.lock().kill_adapter_id(id),
WebGPUMsg::FreeDevice(id) => self.gpu_id_hub.lock().kill_device_id(id),
WebGPUMsg::FreeDevice {
device_id,
pipeline_id,
} => {
self.gpu_id_hub.lock().kill_device_id(device_id);
let global = self.documents.borrow().find_global(pipeline_id).unwrap();
global.remove_gpu_device(WebGPUDevice(device_id));
},
WebGPUMsg::FreeBuffer(id) => self.gpu_id_hub.lock().kill_buffer_id(id),
WebGPUMsg::FreePipelineLayout(id) => self.gpu_id_hub.lock().kill_pipeline_layout_id(id),
WebGPUMsg::FreeComputePipeline(id) => {