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. Dismiss Notice

URP Android Canvas.RenderSubBatch takes 62% GPU time

Discussion in 'Universal Render Pipeline' started by MorSw, Feb 14, 2021.

  1. MorSw

    MorSw

    Joined:
    Apr 3, 2019
    Posts:
    2
    Hi,
    Were trying to update to using URP and have encountered strange performance issues.
    As you can see in the picture below Canvas.RendererSubBatch is taking up 62% of GPU time.
    This happens on Android build. In editor no such problem.
    Also in the build on android before using the standard rendering pipeline we had no such issues.
    We are using unity 2019.4.15f and URP 7.5.3
    Any help would be appreciated.

    Capture.PNG


    This is before updating to URP using standard rendering pipeline

    old Render.PNG
     
    abbabon, migsil88 and galbartouv89 like this.
  2. galbartouv89

    galbartouv89

    Joined:
    Jul 12, 2016
    Posts:
    2
    had a similar issue would also like an answer to this
     
  3. abbabon

    abbabon

    Joined:
    Mar 19, 2018
    Posts:
    5
    Did you manage to find a solution?
     
  4. abbabon

    abbabon

    Joined:
    Mar 19, 2018
    Posts:
    5
    I've seen @MartinTilo answering similar questions in the past, maybe he can shed some light on what's going on here. These GPU times are not making any sense.
     
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,159
    Sorry, I don't really have any deep knowledge on these markers and what is going on here and the only thing I can recommend for further context here is to use Platform Specific Profiler's like Arm Mobile Studio or Snapdragon profilers as well as RenderDoc.
     
  6. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    I'm reviving this thread to see if anybody has a solution. I'm experiencing the same issue and it looks like SRP Batching is not working with anything Canvas Related.

    Screen Shot 2022-01-18 at 19.35.36.png
     
  7. revolute

    revolute

    Joined:
    Jul 28, 2014
    Posts:
    50
    Are you using world space for canvas? The read I'm getting is that it is not overlay draw calls.

    Code (CSharp):
    1.  
    2. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
    3.  
    4. Shader "UI/Default"
    5. {
    6.     Properties
    7.     {
    8.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    9.         _Color ("Tint", Color) = (1,1,1,1)
    10.  
    11.         _StencilComp ("Stencil Comparison", Float) = 8
    12.         _Stencil ("Stencil ID", Float) = 0
    13.         _StencilOp ("Stencil Operation", Float) = 0
    14.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
    15.         _StencilReadMask ("Stencil Read Mask", Float) = 255
    16.  
    17.         _ColorMask ("Color Mask", Float) = 15
    18.  
    19.         [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
    20.     }
    21.  
    22.     SubShader
    23.     {
    24.         Tags
    25.         {
    26.             "Queue"="Transparent"
    27.             "IgnoreProjector"="True"
    28.             "RenderType"="Transparent"
    29.             "PreviewType"="Plane"
    30.             "CanUseSpriteAtlas"="True"
    31.         }
    32.  
    33.         Stencil
    34.         {
    35.             Ref [_Stencil]
    36.             Comp [_StencilComp]
    37.             Pass [_StencilOp]
    38.             ReadMask [_StencilReadMask]
    39.             WriteMask [_StencilWriteMask]
    40.         }
    41.  
    42.         Cull Off
    43.         Lighting Off
    44.         ZWrite Off
    45.         ZTest [unity_GUIZTestMode]
    46.         Blend SrcAlpha OneMinusSrcAlpha
    47.         ColorMask [_ColorMask]
    48.  
    49.         Pass
    50.         {
    51.             Name "Default"
    52.         CGPROGRAM
    53.             #pragma vertex vert
    54.             #pragma fragment frag
    55.             #pragma target 2.0
    56.  
    57.             #include "UnityCG.cginc"
    58.             #include "UnityUI.cginc"
    59.  
    60.             #pragma multi_compile_local _ UNITY_UI_CLIP_RECT
    61.             #pragma multi_compile_local _ UNITY_UI_ALPHACLIP
    62.  
    63.             struct appdata_t
    64.             {
    65.                 float4 vertex   : POSITION;
    66.                 float4 color    : COLOR;
    67.                 float2 texcoord : TEXCOORD0;
    68.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    69.             };
    70.  
    71.             struct v2f
    72.             {
    73.                 float4 vertex   : SV_POSITION;
    74.                 fixed4 color    : COLOR;
    75.                 float2 texcoord  : TEXCOORD0;
    76.                 float4 worldPosition : TEXCOORD1;
    77.                 UNITY_VERTEX_OUTPUT_STEREO
    78.             };
    79.  
    80.             sampler2D _MainTex;
    81.             fixed4 _Color;
    82.             fixed4 _TextureSampleAdd;
    83.             float4 _ClipRect;
    84.             float4 _MainTex_ST;
    85.  
    86.             v2f vert(appdata_t v)
    87.             {
    88.                 v2f OUT;
    89.                 UNITY_SETUP_INSTANCE_ID(v);
    90.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
    91.                 OUT.worldPosition = v.vertex;
    92.                 OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
    93.  
    94.                 OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    95.  
    96.                 OUT.color = v.color * _Color;
    97.                 return OUT;
    98.             }
    99.  
    100.             fixed4 frag(v2f IN) : SV_Target
    101.             {
    102.                 half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
    103.  
    104.                 #ifdef UNITY_UI_CLIP_RECT
    105.                 color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
    106.                 #endif
    107.  
    108.                 #ifdef UNITY_UI_ALPHACLIP
    109.                 clip (color.a - 0.001);
    110.                 #endif
    111.  
    112.                 return color;
    113.             }
    114.         ENDCG
    115.         }
    116.     }
    117. }
    118.  
    Unity's built-in doesn't really match SRP batching requirements so it's perfectly normal.
     
  8. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    It's a "Screen Space - Camera" canvas but I switched to overlay and it didn't help.

    Maybe I'm missing something obvious I'm using URP for this project instead of built-in. If this is normal, how do you batch all the GUI rendering in URP projects?
     
  9. revolute

    revolute

    Joined:
    Jul 28, 2014
    Posts:
    50
    Batching for UI is done by ui system itself. You can use UI Profiler to see how its being done internally.
     
    farbridgedamon likes this.