-
Notifications
You must be signed in to change notification settings - Fork 983
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
Weakly-counted types #6989
Comments
I like the idea as such, but the main issue I see is that in the long run we'd actually wanted to be able to leverage the existing tracking inside of wgpu-core more. Allowing weak referencing on top will make such future efforts a lot more complicated & constrained.
Probably worth diving more into this: can you describe use-cases for which weak references would be useful for wgpu resources? |
I had a use case for weak references, which was “poll this Another use cases I can imagine would be caching/memoizing derived resources, e.g. “given this |
I use weakly-counted types to keep weak references to lazily-loaded resources like textures. In an async function, I would, for example, await a web request, and after it finishes I would write to a texture, but I do not want to keep a strong reference to that texture, to avoid unnecessary writes if the texture was already destroyed. This is also why I've said that the necessity of stuff like |
We talked about this briefly in the weekly wgpu maintainer meeting. Conclusion was that we're right now a little bit too nervous of introducing weak handles since there's still too much churn on the registries inside of wgpu-core: Right now there's an extra That said, it's more likely than not that we then can just use weak handles to those Long story short: we want this, but first the extra layer of |
Since the introduction of clonable types in wgpu 24.0, I've been able to remove all my
Arc<T>
wrappers around types likeBuffer
,Texture
, but there are no correspondingWeak<T>
types, which is a bit of an issue.I've decided to add weakly-counted reference types under the feature
weak-references
for most of the dispatch types, skippingDispatchSurface
(it's wrapperSurface
is notClone
) andDispatchSurfaceOutputDetail
(it's wrapper containssuboptimal
andpresented
, and those could be mutated independently of the non-weakSurfaceTexture
itself), but the necessity of some of those types, likeAdapterWeak
is a bit dubious, and this is why I've not opened a PR for this. I'm also uncertain about the naming of the types which are reponsible for the weak <-> strong transfers, (itsas_weak
andupgrade
for now,as_weak
is also an associated functions unlike the one inArc
). Adding more docs is not an issue.This is the fork in which I've implemented the feature:
https://github.com/szostid/wgpu
PS: its my first time making a commit like this, any suggestions are helpful
The text was updated successfully, but these errors were encountered: