Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPU: improve lifecyle management of resources #32148

Open
gterzian opened this issue Apr 26, 2024 · 2 comments
Open

WebGPU: improve lifecyle management of resources #32148

gterzian opened this issue Apr 26, 2024 · 2 comments
Labels
A-content/webgpu The WebGPU implementation. B-feature-tracking This issue tracks a particular high-level feature

Comments

@gterzian
Copy link
Member

Proposed follow-up for #31995

I think there are two problems:

  1. Too much individual IPC messages, and back and forth to free IDs, makes it hard to reason about what is going on, and I think also make clean shut down dependent on ignoring IPC channel errors(when the backend sends a free msg to script).
  2. Drop of dom structs, see Drop impls for DOM types should be forbidden #26488

Instead I propose we centralize resource management, and loosely integrate with the DOM lifecyle.

We should centralize all logic around the gpu_id_hub, which is shared per global

pub fn wgpu_id_hub(&self) -> Arc<Mutex<Identities>> {

and then used by dom struct to get new id, for example

let bind_group_id = self

So the individual dom struct should not manage their own IDs, the global should keep some kind of map of id to weak ref of dom object(see weakref.rs).

Then, we can integrate the gpu_id_hub into perform_a_dom_garbage_collection_checkpoint, where we loop over all Ids, collect those that need to be freed, and then:

  1. locally free them in script, and
  2. send a single IPC message for all to freed in the backend(no need to send anything back, script already freed them).
@gterzian gterzian added B-feature-tracking This issue tracks a particular high-level feature C-untriaged New issues that haven't been triaged yet labels Apr 26, 2024
@sagudev sagudev added A-content/webgpu The WebGPU implementation. and removed C-untriaged New issues that haven't been triaged yet labels Apr 26, 2024
@sagudev
Copy link
Member

sagudev commented Apr 26, 2024

Cleanup usually goes something like this in firefox:

  if (!bridge) {
    return;
  }

  if (bridge->CanSend()) {
    bridge->SendBufferDrop(mId);
  }

  wgpu_client_free_buffer_id(bridge->GetClient(), mId);

so we can probably move id freeing to script completely.

IDEA: Instead of having global lock for all hubs it might be worth to have separate locks per each hub or even for each type we are assigning.

What if instead of cleaning up with GC we just use RC to keep id alive and then on drop we free their ids?

@gterzian
Copy link
Member Author

gterzian commented Apr 29, 2024

so we can probably move id freeing to script completely.

Right.

What if instead of cleaning up with GC we just use RC to keep id alive and then on drop we free their ids?

The idea is to avoid using Drop, and also to batch all the freeing via the checkpoint.

IDEA: Instead of having global lock for all hubs it might be worth to have separate locks per each hub or even for each type we are assigning.

Maybe, if there is actual lock contention...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/webgpu The WebGPU implementation. B-feature-tracking This issue tracks a particular high-level feature
Projects
Status: To do
Development

No branches or pull requests

2 participants