Falcor icon indicating copy to clipboard operation
Falcor copied to clipboard

Memory leak in D3D12DescriptorSet for Debug build

Open R2RT opened this issue 5 years ago • 2 comments

Hi,

I was just trying Falcor for the first time, so I don't know too much of its guts. But ShaderToy demo did not work for me in DebugD3D12 configuration. FPS goes wild (up to 200 without debugger attached) and heavy memory leak is occuring (~10MB per second). No problem in ReleaseD3D12 nor VK.

I've taken 20s distant memory snapshots in Visual Studio and here are results

Object type Count Diff. Size Diff. (Bytes) New Allocation Count Count Size (Bytes)
ShaderToy.exe!std::_Container_proxy +16,664 +266,624 +26,946 29,508 472,128
ShaderToy.exe!std::_Ref_countFalcor::D3D12DescriptorHeap::Allocation +16,664 +399,936 +26,920 26,940 646,560
ShaderToy.exe!std::_Ref_count_objFalcor::DescriptorSetApiData +16,663 +1,066,432 +26,920 26,940 1,724,160
ShaderToy.exe!Falcor::D3D12DescriptorHeap::Allocation +16,664 +666,560 +26,920 26,940 1,077,600
unsigned int +9,999 +39,996 +16,153 16,179 64,716
unsigned int[] +6,665 +66,652 +10,767 10,773 107,720
ShaderToy.exe!Falcor::FencedPool<_com_ptr_t<_com_IIID <ID3D12CommandAllocator,&_GUID_6102dee4_af59_4b09_b999_b44d73f09b24> > >::Data +2,117 +33,872 +2,117 3,146 50,336
ShaderToy.exe!std::_Ref_countFalcor::D3D12DescriptorHeap::Chunk +419 +10,056 +419 685 16,440
ShaderToy.exe!Falcor::D3D12DescriptorHeap::Chunk +419 +6,704 +419 685 10,960
ShaderToy.exe!std::_List_node<std::pair<unsigned __int64 const ,std::unique_ptr<Falcor::ResourceAllocator::PageData, std::default_deleteFalcor::ResourceAllocator::PageData > >,void *> +333 +10,656 +538 540 17,280
ShaderToy.exe!Falcor::ResourceAllocator::PageData +333 +13,320 +333 540 21,600

Majority of allocations are shared_ptr related stuff, but somehow does not have same origin:

#1 ShaderToy.exe!std::_Container_proxy and #3 ShaderToy.exe!std::_Ref_count_obj<Falcor::DescriptorSetApiData> origins from ShaderToy.exe!Falcor::DescriptorSet::apiInit() - Line 49

image

Then #2 ShaderToy.exe!std::_Ref_count<Falcor::D3D12DescriptorHeap::Allocation> and #4 ShaderToy.exe!Falcor::D3D12DescriptorHeap::Allocation comes from line 66:

with callstack:

image

Next two entries, #5 int and #6 int[] point at vector::resize in ShaderToy.exe!Falcor::DescriptorSet::apiInit() - Line 57 (even though resize call is in line 55, maybe some optimization)

I don't know yet if I will dive into Falcor, so this is the best I can provide for now.

Leaks in both VS2017 and 2019. Memory snapshots were collected in the newest VS2019.

Let me know if there is some more diagnostics I can collect.

R2RT avatar May 29 '19 07:05 R2RT

I can't reproduce it. I ran ShaderToy for 20 minutes and the memory consumption stays stable. We re-wrote the descriptor set allocation logic in a private development branch. It's more optimized and can handle array allocations better. We will release it as part of our next major version.

nbentyNV avatar May 30 '19 17:05 nbentyNV

Great news, I will do recheck then. But there is also chance that the issue is caused by flaw of my VS environment. I have strange issues in other projects as well, so I switched to clang as main compiler. But in here I'd have to add CMake support I guess... I might look into it.

R2RT avatar Jun 03 '19 09:06 R2RT