gfx-rs / wgpu

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

[WebGL] huge memory usage when loading 4K 12bits textures #5777

Open VincentJousse opened 3 months ago

VincentJousse commented 3 months ago

Description I use wgpu to develop a video player. when rendering 4K 12bits textures, the browser's developer tools shows very high memory usage. It seems that some texture memory is not freed.

Repro steps I can try to extract an example if needed.

Expected vs observed behavior I would have expected a constant memory footprint, but I reach 3.5Go after 192 frames displayed.

Platform linux, wgpu: 0.15 and 0.20

mikialex commented 3 months ago

Did you use a new texture in every frame? if so, the old texture should call destroy explicitly before being dropped on the web platform. maybe this issue is related https://github.com/gfx-rs/wgpu/issues/4092

VincentJousse commented 3 months ago

I call device.create_texture() at initialization only, and queue.write_texture() for each frame.

cwfitzgerald commented 3 months ago

I've seen this before in my wgpu/webgl codebase. It's something to do with the retention of write_buffer/texture intermediate buffers. they balloon out of control then randomly snap back to normal. I have yet to be able to track down what is going on inside of wgpu, but it's definitely within wgpu. You can see it if you pull stack traces of all live large allocations using a custom allocator.

VincentJousse commented 3 months ago

@cwfitzgerald Have you found a workaround ? Or may I contribute to wgpu if you give me some help ?