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

Large overhead using OnRenderImage or Graphics.Blit

Discussion in 'iOS and tvOS' started by BrianND, Nov 7, 2017.

  1. BrianND

    BrianND

    Joined:
    May 14, 2015
    Posts:
    79
    We use Graphics.Blit to simply copy the frame buffer to a texture. I noticed that adding OnRenderImage Graphics.Blit can reduce my framerate 20-30fps on high res iPad devices. On my iphone 5s it is having a 4-5ms cost and even higher on high res devices. I saw this issue

    https://forum.unity.com/threads/big-performance-issue-with-unity5-on-android.338847/

    Not sure if it's related because it says Android.

    I did a bit of debugging and it looks like Hidden/BlitCopy takes up most of the GPU time. It also looks like it's doing a copy of the depth and stencil possibly.

    I'm doing a simple Blit to a lower res texture no post processing effects.
     
  2. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,121
    We are actually having the same issue. We are blitting a small texture to perform some work on it (128x128), we are blitting it 4 times and 2 of those are just blit copies. Just a simple blit copy takes 0.25ms.
     
  3. TheJimz

    TheJimz

    Joined:
    Jun 26, 2015
    Posts:
    50
    When using OnRenderImage, you are forcing unity to render the camera into a RenderTexture instead of directly to the framebuffer, which can possibly double your fill rate (one draw into a rendertexture, a second draw to the framebuffer).

    iPad's have high resolution and typically have fill-rate issues. You would see less of a slowdown of lower resolution devices.
     
  4. BrianND

    BrianND

    Joined:
    May 14, 2015
    Posts:
    79
  5. BrianND

    BrianND

    Joined:
    May 14, 2015
    Posts:
    79
    I looked at the decompiled metal shader and I notice there is color Globals multiply. Can this be removed @Aras @Alexey? It looks like it requires a cast and a multiply. Maybe that could shave off some millisecs? I actually tested it by recompiling the shader and the results look same.

    Code (CSharp):
    1. struct Mtl_FragmentOut
    2. {
    3.     half4 SV_Target0 [[ color(0) ]];
    4. };
    5.  
    6. fragment Mtl_FragmentOut xlatMtlMain(
    7.     constant Globals_Type& Globals [[ buffer(0) ]],
    8.     texture2d<half, access::sample > _MainTex [[ texture (0) ]] ,
    9.     sampler sampler_MainTex [[ sampler (0) ]] ,
    10.     Mtl_FragmentIn input [[ stage_in ]])
    11. {
    12.     Mtl_FragmentOut output;
    13.     float4 u_xlat0;
    14.     half4 u_xlat16_0;
    15.     u_xlat16_0 = _MainTex.sample(sampler_MainTex, input.TEXCOORD0.xy);
    16.     u_xlat0 = float4(u_xlat16_0) * Globals._Color; << What is Globals?
    17.     output.SV_Target0 = u_xlat16_0;
    18.     return output;
    19. }