Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

HDRP Memory Issue with RenderTextures not Rescaling

Discussion in 'High Definition Render Pipeline' started by zoooom, Apr 27, 2020.

  1. zoooom

    zoooom

    Joined:
    Feb 8, 2012
    Posts:
    50
    Hello,

    I'm rendering from a Camera to a RenderTexture at 8k resolution, so I can super-sample it when drawing to a second Camera to display on screen (at 1080p).

    The problem I am encountering happens if I drop the RT resolution at runtime, it doesn't seem to free up texture memory, even doing all manner of DiscardContents(), Release() etc.

    I've dug in using the Profiler a bit and seems like the HDRP buffers aren't being downscaled, main offender being volumetric lighting which uses about 4gb at 8k resolution. Just wondering if there is a way I can force these to clear from memory and refresh if I change the RT resolution down to 2k for example.



    Here's a screenshot of the profiler showing where the RT res is switched from 2k resolution to 8k and then back again to 2k. As you can see the buffers are all still at 7680x4320 or the equivalent of (VBuffer is 1/4 screen size on High quality setting).

    Any ideas would be much appreciated, cheers :)
     
  2. Julien_Unity

    Julien_Unity

    Unity Technologies

    Joined:
    Nov 17, 2015
    Posts:
    68
    This is indeed an expected behavior of the system. Basically the systems will allocate for the worse case and then share render texture between different cameras. That was done in a context where for example a game would render to 1080p and off screen cameras would render in small resolution.
    That being said, the case of super sampling once and then freeing allocated memory sounds useful, but in your case, are you doing this every frame? Beause if that's so then that would not solve the issue.
    If what you want is restore a smaller "max resolution" in a dynamc way then I guess we can see if we can add an API for that (but keep in mind that doing this kind of things will inevitably result in a longer frame when everything realloates).
     
  3. zoooom

    zoooom

    Joined:
    Feb 8, 2012
    Posts:
    50
    Hi Julien,

    Thanks for your reply, makes perfect sense. And what you mentioned at the end is exactly what I'm trying to do - dynamically setting the max resolution. The longer frame when the reallocation is occuring wouldn't be an issue at all in this use case.
     
  4. zoooom

    zoooom

    Joined:
    Feb 8, 2012
    Posts:
    50
    Also we would be doing it very infrequently, certainly not every frame :)
     
  5. Julien_Unity

    Julien_Unity

    Unity Technologies

    Joined:
    Nov 17, 2015
    Posts:
    68
    Ok, such an API should be possible to expose to users. We'll look into it.
     
    zoooom likes this.
  6. zoooom

    zoooom

    Joined:
    Feb 8, 2012
    Posts:
    50
    That would be great, thanks Julien!