gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.57k stars 920 forks source link

Remove IDs and Registries #5121

Open nical opened 9 months ago

nical commented 9 months ago

This is a meta issue to describe the long-ish term vision for wgpu-core's resource management and track the steps towards it.

Registries and IDs

Internally, all wgpu-core resources are stored behind Arcs. Externally, they are exposed as non-clonable structs containing an ID which conceptually corresponds to a single reference to the Arc of a resource.

The goal

Instead of having wgpu public types wrap a non-clonabe ID, we would like them to wrap the Arc to the internal resource directly (and be clonable).

TODO

sagudev commented 5 months ago

(Firefox): Stop providing the IDs during resource creation and do ID mapping in the gecko-side bindings.

How exactly would that look like? Would that be something like hashmap that would map id to Arc of wgpu object that would live in WebGPU thread?

I'm mostly asking for servo, as it would be nice to share ID mapping stuff.

nical commented 5 months ago

(Firefox): Stop providing the IDs during resource creation and do ID mapping in the gecko-side bindings.

How exactly would that look like? Would that be something like hashmap that would map id to Arc of wgpu object that would live in WebGPU thread?

Yes, that's the general idea. Depending on how you generate the IDs you could get away with arrays instead of hash maps (like wgpu-core currently does).