Wgpu: Memory issue

Created on 24 Nov 2020  路  10Comments  路  Source: gfx-rs/wgpu

Seeing this on latest wgpu-rs:

thread 'main' panicked at 'Memory must not be used anywhere: Memory { heap: Public(MemoryTypeId(1), <GFX9AMD_MtlBuffer: 0x7fb98b808a60>
    label = <none> 
    length = 33554432 
    cpuCacheMode = MTLCPUCacheModeDefaultCache 
    storageMode = MTLStorageModeShared 
    hazardTrackingMode = MTLHazardTrackingModeTracked 
    resourceOptions = MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModeShared MTLResourceHazardTrackingModeTracked  
    purgeableState = MTLPurgeableStateNonVolatile), size: 33554432 }', /Users/ln/.cargo/git/checkouts/wgpu-53e70f8674b08dd4/549ea00/wgpu-core/src/device/alloc.rs:227:46
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d9a105fdd46c926ae606777a46dd90e5b838f92f/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/d9a105fdd46c926ae606777a46dd90e5b838f92f/library/core/src/panicking.rs:92:14
   2: core::option::expect_none_failed
             at /rustc/d9a105fdd46c926ae606777a46dd90e5b838f92f/library/core/src/option.rs:1268:5
   3: gpu_alloc::linear::LinearAllocator<M>::dealloc
   4: gpu_alloc::allocator::GpuAllocator<M>::dealloc
   5: wgpu_core::device::life::LifetimeTracker<B>::cleanup
   6: wgpu_core::device::Device<B>::maintain
   7: wgpu_core::device::queue::<impl wgpu_core::hub::Global<G>>::queue_submit
   8: <wgpu::backend::direct::Context as wgpu::Context>::queue_submit

I'll get a trace.

help wanted bug

Most helpful comment

Found the issue.
Last block that gets deallocated was holding another clone of the Arc.
Fixed in https://github.com/zakarumych/gpu-alloc/commit/d07be73f9439a37c89f5b72f2500cbf0eb4ff613

All 10 comments

Closing in favor of opening issue on wgpu directly

@lordnoriyuki no need, we can transfer issues between repos

@zakarumych anything we missed, still, in the linear allocator?

This happens if Memory's clone is still around when allocator returns it to device.

With gfx backend gpu-alloc operate with 'Arc\

All blocks should be deallocated when memory object gets deallocated, but user of MemoryBlock could clone its parent 'Arc\

Trace attached.

trace.zip

And it was doing a lot of work - performance was really bad before it died (1000 fps in this particular scenario normally was <200 fps).

@zakarumych this is our wrapper - https://github.com/gfx-rs/wgpu/blob/master/wgpu-core/src/device/alloc.rs
It doesn't expose Arc<Memory> to the outside, and just a fairly boring wrapper.
Could this issue also be caused by a logic flow in gpu-alloc itself?

It can be anything.
gpu-alloc clones memory only when new block is allocated.

It is possible that gpu-alloc tries to deallocate memory before all blocks are freed.
Printing whole Allocator can reveal if this is the case.

Found the issue.
Last block that gets deallocated was holding another clone of the Arc.
Fixed in https://github.com/zakarumych/gpu-alloc/commit/d07be73f9439a37c89f5b72f2500cbf0eb4ff613

Confirmed if I patch the new gpu-alloc everything is working now.

Was this page helpful?
0 / 5 - 0 ratings