microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.48k stars 393 forks source link

FindPageForAlloc out of memory #55

Closed MattFiler closed 5 years ago

MattFiler commented 5 years ago

I'm currently trying to load a large SDKMesh and getting an out of memory throw in LinearAllocator's FindPageForAlloc. Is there any defined maximum size an SDKMesh can be, or is that something which is system dependant?

walbourn commented 5 years ago

Please build and then run the sdkmeshdump.cpp tool on your sdkmesh and post the results here so I can get a sense of the size of resources you need.

MattFiler commented 5 years ago

Here's what I got back for the model I'm having issues with.

walbourn commented 5 years ago

Also, are you calling GraphicsMemory::Commit each rendering frame? It's critical for the memory reclamation.

MattFiler commented 5 years ago

Yeah, I call it at the end of every render. I'm also utilising GraphicsMemory::GarbageCollect in-between loading models to try and help, but it doesn't seem to make much difference.

MattFiler commented 5 years ago

I'm calling DeviceResources::WaitForGpu before GraphicsMemory::GarbageCollect as the function states the GPU must be idled before using for best effects - is this correct?

walbourn commented 5 years ago

I think the question is what is your overall memory usage. The LinearAllocator used by GraphicsMemory grows the heap on-demand so it's not a fixed size. That said, it can't grow the heap larger than the amount of memory that your DirectX 12 driver supports for UPLOAD type heaps.

Are you loading a lot of models? Are you using LoadStaticBuffers to convert the UPLOAD VB/IB to DEFAULT? Are you using x64 native or 32-bit?

MattFiler commented 5 years ago

The issue occurs usually when switching between models - I use one large model for each of our environments. When changing environments I unload it, then load the next. They're all of a similar size to the dump I posted. The environments have a few other models loaded within them but they're all pretty small (~3K verts). When loading the models I do call LoadStaticBuffers, I guess this is correct?

walbourn commented 5 years ago

Did you close this because you were able to resolve the issue?

MattFiler commented 5 years ago

Utilising GraphicsMemory::GarbageCollect after a call to DeviceResources::WaitForGpu following a reset of model resources did the trick for my runtime model swapping issue. To solve the initial "out of memory" loading issue I simply split my model into two SDKMESH files to load-in which seems to work fine. Up to you if you keep the issue open - it might be worth exploring the problem further as it is repeatable with large individual SDKMESHes.

walbourn commented 5 years ago

Thanks. I'll keep an eye out for future problems.

I did add some more debugging output in this commit.

BTW, are you using 32-bit or 64-bit native?

MattFiler commented 5 years ago

Appreciate the help! I'm using 64-bit.