-
Notifications
You must be signed in to change notification settings - Fork 953
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
Dropped devices leak memory on Windows dx12 #3498
Comments
Hmm, both the driver and nature of issue (memory leak, maybe refcounting issue?) Seem like they might be related to #3485? |
I've also seen similar issues on Windows. I didn't have time to investigate them yet, so I don't have any details, but definitely something like that happens. |
Disabling dx12 suballocation makes the test pass on my system. --- a/wgpu/Cargo.toml
+++ b/wgpu/Cargo.toml
@@ -142,7 +142,7 @@ hal = { workspace = true }
hal = { workspace = true, features = ["renderdoc"] }
[target.'cfg(windows)'.dependencies]
-hal = { workspace = true, features = ["dxc_shader_compiler", "renderdoc", "windows_rs"] }
+hal = { workspace = true, features = ["dxc_shader_compiler", "renderdoc"] } If you have a non-test reproduction, gpu-allocator should be outputting |
I turned your test code into an example and shoved a println! into edit: More testing, device::exit() seems to only run if the instance creation is in the loop. Note that with instance out of the loop (like in the OP), |
Some more context: The texture seems to be freed properly (println debugging shows The issue is that when you create a new |
Ironically, the reasoning behind my original code creating many |
Firefox needs to be able to create endless numbers of devices without leaking, because device creation is under web content's control. We could decouple WebGPU API Devices from wgpu Devices, but it seems just as easy to fix wgpu, and that'd help a broader audience.
Creating separate devices for isolation seems like something that ought to work. |
Tests for memory leaks could potentially use https://crates.io/crates/sysinfo to get such information, but it would not help the case where we're leaking gpu memory. |
Are the applications calling poll properly? It seems like |
In the situation which prompted me to file this issue, they were — each device belonged to a headless render test, so it would poll to retrieve the rendered image. Of course, the test doesn't poll after it completes, and won't poll if it somehow panics before getting to that point. If all that is needed to avoid a leak is to poll after the resources are garbage, maybe wgpu should automatically poll just before creating a device? |
This seems to be fixed on wgpu 0.19. |
I have just learned that the WebGPU specification says that you can only |
Right, D3D12 will also give you back the same device from the same adapter (they are singletons per adapter). |
@teoxoy I think you misunderstand. I'm saying that, according to the WebGPU specification, calling So, the original test code in principle ought to be rewritten to repeatedly call |
I agree we should implement the validation, I was trying to provide relevant info as to why we are leaking without having the validation implemented. After all, this validation is in the spec most likely because of D3D12's behavior. |
#5943 fixed this but I'll leave this open since the original issue hasn't been solved. |
Description
If I repeatedly create devices with substantial resources, then eventually I will get a failure to create a device (or, if one of the existing devices is used further, an allocation failure within it) even if the devices are dropped.
(This was discovered inside my application's test suite — I recognize that creating many devices is an irregular situation.)
Repro steps
Stick this test case in
wgpu/tests/
and run it (branch with needed changes @ master...kpreid:wgpu:winleak):The leak does not (visibly) occur if the same textures are created and dropped while using a single device.
Platform
wgpu
0.15 or git master (b534379).The text was updated successfully, but these errors were encountered: