2022.3.50 DX12 HDRP, Huge memory usage and leaks by on demand and realtime lights

Hello
I’ve recently noticed that some scenes in our game go over memory limit and crash on some devices. While testing, it became clear that “On Demand” lights we’re using are taking much more memory than expected.

I created a simple project where this can easily be reproduced and sent it over the blind FTP under the name “lights-memory-tests.zip”. It’s just a basic HDRP project with ~1500 cubes and 20 lights in it and a script to request shadow map rendering.

After opening “OutdoorsScene” scene and running a build on PC with DX12 this can be observed:

  • If you disable lights in the scene before build, it takes about 1GB of RAM
  • If you leave lights enabled, i takes about 1.3GB of RAM, which already seems bigger than expected shadow atlas size
  • If you call “RequestShadowMapRendering()” on every light by pressing “Space”, you will notice memory usage going up. If you keep pressing space, memory usage will keep going up, to about 2GB.

The more cubes there are in the scene the more memory will be used (with 4200 it goes over 2.6GB).
Realtime lights are affected in some way too.
This doesn’t seem to happen on DX11 builds but switching is not an option for us, on a device that’s most affected by this bug.

2 Likes

I can confirm that their is a huge memory leak problem in DX12. I haven’t done a simplified scene yet, (I’m about too) but have been looking in debug mode at the logs and it’s quite a significant issue.

It also causes many crashes in Editor and Builds.

Here is my Crash.dmp:

Exception Code :0xc0000005
Exception Information: "The thread tried to read from or write to a virtual address for which it does not have the appropriate access."

Editor.Log

UnityEngine.Debug:ExtractStackTraceNoAlloc (byte*,int,string)
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.AllocatorManager/AllocatorHandle,long,int) (at ./Library/PackageCache/com.unity.collections/Unity.Collections/Memory.cs:89)

I have started to see numerous posts on Reddit Unity threads in the last few days Unity all with the same issues, all memory/burst/jobs related with DX12, usually with the same The thread tried to read from or write to a virtual address for which it does not have the appropriate access."

I don’t think anyone at Unity has ever actually used DX12 unfortunately.

I will try and also make a simple test scene to demonstrate with logs, in the hope that someone at Unity sees it. It’s quite an unusable mess currently in Unity6 DX12.

1 Like

I have same problem, hdrp in dx12 memory leak when switch between scene, deserved and untracked memory inscrease obviously