Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Optimal usage of temporary RTHandle's after upgrading to URP 14.X

Discussion in 'General Graphics' started by james_work, Jul 28, 2023.

  1. james_work

    james_work

    Joined:
    Oct 2, 2020
    Posts:
    10
    Hi All,

    We recently upgraded our development environment to Unity 2022.3.3f1, and subsequently upgraded to URP 14.0.8. We have some Renderer Features that we are currently upgrading to work with the new RTHandle system, but are having some trouble figuring out how to handle temporary RTHandle's.

    Before upgrading, we were using
    CommandBuffer::GetTemporaryRT(...)
    to get temporary render textures, and when we are doing with it we used
    CommandBuffer::ReleaseTemporaryRT(...)
    to release it.

    However, for URP 14 it's recommended to use RTHandles, and so we are now using
    RenderingUtils.ReAllocateIfNeeded(...)
    to get temporary render textures. However it's not clear how to properly release them. In the example here the RTHandle's are being released only during the Dispose() call, which is not called every frame.

    So my question is; is calling
    RenderingUtils.ReAllocateIfNeeded(...)
    to get a RTHandle and only releasing it when the RenderPass is Disposed the only way to handle temporary Render Textures?. With this approach, it looks like each Renderer Feature is creating, and then holding onto it's own RenderTexture during it's lifetime. This is a waste of memory and we were hoping to be able to get and release a RenderTexture per Renderer Feature.

    Is getting a RTHandle with
    RenderingUtils.ReAllocateIfNeeded(...)
    , performing some rendering work, and then releasing it immediately during
    ScriptableRenderPass::OnCameraCleanup
    using
    RTHandle::Release()
    incorrect?

    Kind regards,
    James
     
    Last edited: Jul 28, 2023
  2. james_work

    james_work

    Joined:
    Oct 2, 2020
    Posts:
    10
    Still haven't been able to figure this out... The documentation is very vague and all the examples I can find in the Unity source code seem to create RTHandles with ReAllocateIfNeeded and hold on to them until Dispose is called...
     
  3. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    1,042
    I'm also curious about this and have mostly the same questions plus a few more. I ended up just using the depreciated stuff for now since I at least know how to use them and they aren't causing me issues like the new and very unintuitive methods and objects.