We recently found out that the hook for telling wgpu-core users that allocate their own IDs that an index is safe to reuse has been refactored away at some point. So Gecko currently never reuse any index. Oops.
We could re-introduce a hook for communicating reusable registry indices, but I'd like to simplify things to the point that we don't have to.
Currently the Drop impl for ResourceInfo is what tells the registry that an index can be reused. It is called when the reference-counted resource struct is dropped which in principle should happen after we call wgpu-core's <resource>_drop function... Except if the resource's Arc is moved out of the registry before <resource>_drop in which case the index might be made reusable to soon. That's what causing the headaches in #5141.
My main issue with the current system is that by having reference-counting in between the registry and its recycling logic, we introduced an invariant that was easy to break and broke it without noticing. Instead I would like the registry to completely own the ID reuse logic without being affected by reference counting that is hard to predict.
Proposal
As soon as the wgpu-core resource_drop functions are called, we make the ID reusable. To do this we need:
We recently found out that the hook for telling wgpu-core users that allocate their own IDs that an index is safe to reuse has been refactored away at some point. So Gecko currently never reuse any index. Oops.
We could re-introduce a hook for communicating reusable registry indices, but I'd like to simplify things to the point that we don't have to.
Currently the
Dropimpl forResourceInfois what tells the registry that an index can be reused. It is called when the reference-counted resource struct is dropped which in principle should happen after we call wgpu-core's<resource>_dropfunction... Except if the resource'sArcis moved out of the registry before<resource>_dropin which case the index might be made reusable to soon. That's what causing the headaches in #5141.My main issue with the current system is that by having reference-counting in between the registry and its recycling logic, we introduced an invariant that was easy to break and broke it without noticing. Instead I would like the registry to completely own the ID reuse logic without being affected by reference counting that is hard to predict.
Proposal
As soon as the wgpu-core resource_drop functions are called, we make the ID reusable. To do this we need:
<resource>_drop. For Gecko this means we have a simple rule for when it is safe to reuse IDs.