gfx-rs / wgpu

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

DX12: Memory leaks with intel gpu & 30+ driver #6143

Open xiaopengli89 opened 2 months ago

xiaopengli89 commented 2 months ago

Description DX12 backend has memory leaks on some Intel drivers.

Repro steps

  1. Intel integrated gpu
  2. Setup intel 30+ gpu driver, e.g. 31.0.101.2128
  3. Running water example with dx12 backend

Extra materials

image

20240822-163346

Platform Windows 10, wgpu 22.0

teoxoy commented 2 months ago

Is this a new leak?

xiaopengli89 commented 2 months ago

Is this a new leak?

No, it can be reproduced on older versions of wgpu, but there is no leak on the 27.x.x.x driver, maybe it's a driver bug.

jimblandy commented 1 month ago

I understand that the water example is a reproducer, so that's in principle all we need to look into this. But if you're able to, it would be nice to get a smaller test case, since water is one of the most complex of the examples.

cprkv commented 1 month ago

I have the same problem, but I'm using wgpu-native.
Specs:

RTX 3090 TI
WGPU version: 22.1.0.5
Backend: Vulkan, DX12 (doesn't depend on particular backend)

It looks like wgpu-core\src\device\queue.rs::PendingWrites::temp_resources was not released somewhere. I don't know rust and can't tell the reason.

Allocation stack trace: image

cprkv commented 1 month ago

I made reproduction example in rust https://github.com/cprkv/wgpu_mem_leak (in wgpu-native I do same things, so it has no difference, situation reproduces).

My guess is that uniform buffer is being used by GPU when I write to it. I took this approach from wgpu examples, and there is no comment if it does something wrong. I don't know if there is a correct example of how to do queue_write_buffer right.

I have to add this after some experiments:
It happens to both backends (Vulkan and DX12) in wgpu-native, but for some reason everything is fine for DX12 in wgpu (rust). Only Vulkan backend has noticeable leakage. I also tried using triple buffering technique (create 3 buffers and use it in round-robin manner), it doesn't help.