Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Camera Clear Flags On Performance

Discussion in 'Graphics Dev Blitz Day 2023 - Q&A' started by Jack-Tag-Games, May 25, 2023.

  1. Jack-Tag-Games

    Jack-Tag-Games

    Joined:
    Nov 12, 2018
    Posts:
    3
    Is there a best practice when choosing the camera clear flags, and does this vary per platform?

    My naive assumption is that not clearing the screen would be faster as it would do less work, however I have read that this can be detrimental on mobile hardware (in this blog post from John Carmack) and that it is faster to clear the screen as it can avoid storing and loading data that is no longer needed.
     
    mandisaw and sabojako like this.
  2. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    932
    Hi, I don't have the answer for mobile, but on console, it is faster to not clear the color buffer / Gbuffer as we rewritte it fully.
     
    mandisaw likes this.
  3. Jack-Tag-Games

    Jack-Tag-Games

    Joined:
    Nov 12, 2018
    Posts:
    3
    Thanks for taking the time to reply, interesting to hear thats the case for console and will be good to know for the future.
    I should have specified that mobile is the main area of concern at the moment, but its not like clearing or not is the render feature getting in the way of hitting performance targets.
     
  4. ManueleB

    ManueleB

    Unity Technologies

    Joined:
    Jul 6, 2020
    Posts:
    110
    clearing the screen on mobile is not done using cmd.ClearRenderTargets, which is pretty expensive, but it is done on tile (by using Clear load actions) which is pretty fast. So yeah, as the article you linked mentions, Clear or DontCare load actions are cheap and recommended on mobile, Load operations are very expensive, especially on high res + MSAA targets.

    So to summarize, on mobile, as long as you clear using the Clear load action (URP does that for its cameras) and not using cmd.ClearRenderTarget, clearing is very cheap and safe to use
     
    mandisaw and wwWwwwW1 like this.
  5. Jack-Tag-Games

    Jack-Tag-Games

    Joined:
    Nov 12, 2018
    Posts:
    3
    I really appreciate you both taking the time to respond, thanks for all the information!
     
    ManueleB likes this.