Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Every Graphics.Blit causes RenderTexture.ResolveAA if MSAA enabled which is killing framerate.

Discussion in 'AR/VR (XR) Discussion' started by syenet, Feb 22, 2017.

  1. syenet

    syenet

    Joined:
    May 13, 2013
    Posts:
    47
    HTC Vive, Unity 5.4.4f1, Single Pass Stereo.

    Because the amount of pixels need to render is huge, post processing is heavy on performance already. Now each Graphics.Blit requires an extra 0.14ms with 4x MSAA enabled? From profiler I see Unity is using rendertextures named "ImageEffects Temp" to do each process, is it really necessary? I thought only the VR camera needs resolve once after rendering the scene, after that, post effects only process the "resolved" rendertexture, and no more multisampling involved. So maybe each rendertexture "ImageEffects Temp" should be created setting aa to 1(disabled)?
     
  2. syenet

    syenet

    Joined:
    May 13, 2013
    Posts:
    47
    In non-VR rendering, Graphics.Blit triggers Camera.AAResolve->RenderTexture.GrabPixels, killing framerate as well. But in that case I can create temporary rendertextures and set Camera.targetTexture to it, and manually render each frame without OnRenderImage, this is a workaround. But in VR, this method no longer works. I wonder if there's any feasible workaround approaches in VR, thanks.
     
  3. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    48
    In the profiler it looks like Unity is doing VR.Blit, but I don't think we have access to this function.
     
  4. syenet

    syenet

    Joined:
    May 13, 2013
    Posts:
    47
    Well, I think I've figured out how Unity internally handles post processing in VR rendering (Single Pass Stereo).

    When you use "OnRenderImage(RenderTexture source, RenderTexture destination)", Unity internally creates a RenderTexture "ImageEffects Temp" as the "source", and its antialiasing property is set to your current "QualitySettings.antiAliasing", and this "source" is created even if you do nothing in "OnRenderImage".

    If you ever use Graphics.Blit("whatever", destination) in "OnRenderImage", Unity internally creates RenderTexture "RTEyeTextureDoubleWide" as the "destination", and its antialiasing property is set to your current "QualitySettings.antiAliasing" as well. This one will eventually sent to HMD I think.

    Graphics.Blit->RenderTexture.ResolveAA will occur on both "source" and "destination" because their antialiasing type. The resolve on "source" is unavoidable, because you need to multisample your render result to get the rendertexture your camera just rendered. About the resolve on "destination", I doubt if that is truly necessary.

    If you have several post processing script, with "OnRenderImage" on each one of them, there will be a lot of "RenderTexture.ResolveAA", most of which to me are unnecessary. To avoid that overhead, you can just use a single post processing script with only one "OnRenderImage", and you creates your own rendertextures with antialiasing disabled, and you can then use Graphics.Blit(rt1, rt2) as many times as you wish. This can guarantee that only two "RenderTexture.ResolveAA" in total will occur, one for "source", one for "destination".

    Hope this helps.
     
    sewy likes this.
  5. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    48
    Too bad there is nothing we can improve if only one image effect is being used, it would be nice to get that bit of time back.
     
  6. naiwen_xie

    naiwen_xie

    Joined:
    Mar 11, 2017
    Posts:
    12
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Still the case with latest URP. I checked the frame debugger and the resolves are clearly out of control.
     
    JSmithIR and daneobyrd like this.