Optimizing resource lifetime tracking #1629
Labels
area: ecosystem
Help the connected projects grow and prosper
area: performance
How fast things go
type: enhancement
New feature or request
type: question
Further information is requested
This is copy-pasted from what I wrote on the wgpu Matrix. I'm putting it here so it doesn't get lost. The context is wanting to reduce lifetime tracking overhead as much as possible compared to wgpu-hal (preferably: as close to zero as possible, if the tracking requirements are not complex).
It's kind of awkward actually, it seems like there are two good options at two ends of the tradeoff space in terms of reducing overhead for tracking:
So (2) is basically what I want to use, but it conflicts significantly with the WebGPU spec in the following sense:
There are other possibilities besides what I suggested for trying to reduce overhead in common cases, but so far I haven't been able to figure out anything that isn't just a benchmark hack, or has other bad tradeoffs (e.g. if you acquire a version speculatively when you create a command buffer, and then hold onto it randomly for the rest of your program, we probably don't want that to infinitely delay collection of any resources for command buffers created afterwards).
Additionally, what I just said is I think the most efficient safe way to do resource lifetime tracking (short of asking submitted objects to stay alive across multiple frames and manually specifying a blocking cleanup scope [which some people claim is a common gamedev pattern but I don't believe them] or some related "rooting" scheme that seems likely even more complicated to use). But for buffers and textures (as featured in bunnymark) we also lose overhead to state/conflict tracking, and I still am not sure what the best way to deal with that is... and I think probably the "best" solutions to reduce overhead will conflict with the WebGPU spec even more significantly than needing to know command buffer order ahead of time. If we already need to use hashmaps anyway on a large percentage of the resources we track, then I suspect that will probably dominate the overhead of lifetime tracking in most cases.
So... what I'm thinking is, it would be nice if wgpu somehow made its Rust API able to support both modes of use (refcounting a la Metal, or version tracking and delaying it until queue submission). But I don't know what the best way to do that would be. IMO you can probably do more and fancier optimizations if you can just specify the version up front, while also being more ergonomic than holding resources borrowed for the length of a whole queue submission. But this more outwardly conflicts with the wgpu API, while just having more restricted lifetime constraints technically doesn't.
Currently, with what I'm working on (eliminating hubs), mode (1) is going to be the easiest approach to implement. But I want to make sure we keep mode (2) open, hence I don't want to remove the lifetime constraints just yet with my changes.
The text was updated successfully, but these errors were encountered: