hecrj / wgpu_glyph

A fast text renderer for wgpu (https://github.com/gfx-rs/wgpu)
https://docs.rs/wgpu_glyph
MIT License
443 stars 77 forks source link

Stutter/hangups from displaying dynamic message #40

Closed glalonde closed 4 years ago

glalonde commented 4 years ago

I've been investigating frame stutter in a game and it seems to happen when drawing dynamic characters in this library. "dynamic" meaning characters that change every frame, e.g. FPS counter or score.

I've found that it takes ~10-50ms of CPU time sometimes, which is too much. According to Nvidia's profiler, this is coming from a vkAllocateMemory call. Any ideas what is going on here? I assume this has something to do with caching because of the dynamic aspect, but even when all I am doing is flipping between 0 and 1 displayed in alternating frames it takes 10s of ms. But when I show 0 twice or 1 twice, the second time doesn't cause stutter.

Could also be a faulty gpu memory allocator in wgpu/gfx-rs I suppose, but curious if you know offhand what this might be.

hecrj commented 4 years ago

I have noticed this myself too. The issue seems to trigger whenever we allocate a staging buffer to reupload vertices here:

https://github.com/hecrj/wgpu_glyph/blob/91249b81916ed7f776f0d0185a7414aef3f18f64/src/pipeline.rs#L146-L149

There is an issue open in wgpu that I think may be related: https://github.com/gfx-rs/wgpu-rs/issues/261. As mentioned there, downgrading gfx-memory to 0.1.1 seems to fix the issue.

I think it may be a good idea to come up with an SSCCE that reproduces the issue with only wgpu as a dependency and report it there.

glalonde commented 4 years ago

Oh k, yeah that's definitely an allocator issue, thanks. I think you could fix this by persisting the staging buffer : p