Search Unity

Question Best way to profile GPU usage?

Discussion in 'Editor & General Support' started by Guedez, Jul 2, 2022.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    So how do I go about profiling the actual GPU usage (not frame time) of individual components of my game?
    The best measure I have of how much of my GPU is my game using is MSI Afterburner (which actually gives me the total system usage, which includes anything I have open right now on the machine), but at the same time it can give me reasonable guesses on what uses a ton of GPU if I watch the graph and toggle stuff on and off.
    The issue is that I get at best some vague 'this seems to be about 8~12% usage' which is not really all that helpful besides comparing to other components, but that can't really be used to compare "Component A version 1 with Component A version 2" since the differences are bound to be very minimal. It is also very unreliable as stuff will start using the GPU randomly and I need to measure the bumps many times over to get any semblance of accuracy.

    The "CPU Usage/Rendering" seems to be completely useless for that, since it likely only gets me how much the CPU spent dispatching stuff to the GPU, and I can't figure out what the "GPU Usage" graph even means, since a clear 10% GPU usage shows in the graph as a conversion of Shadow/Depth to Opaque usage and a very minor total reduction on the GPU usage.

    upload_2022-7-2_10-43-14.png

    One way to test it might be disabling the frame rate limits and let it rip on my GPU and measure the max frame rate I can get, but my 2014 laptop tends to restart if I let the GPU usage go over 80% for longer than 2 minutes. So that's not an option for me.

    TLDR: How to accurately measure individual components of my game for Frame Time and GPU Usage? I want to lower both of those but I am not sure they are perfectly 1-1 equivalents.
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hiya, what pipeline are you using, and what is the target hardware? Also how exactly is the grass made and rendered? It looks to me it could be both a CPU and GPU hit. Hard to tell because draw calls are a CPU hit as those are main thread stalls but show up as GPU. Then there's the GPU side like vertex pressure, shader used etc.

    A depth prepass is a very fast render of objects to prevent overdraw, but it is bad on mobile (tile deferred hardware). I would advise watching www.youtube.com/watch?v=wavnKZNSYqU to get a better understanding of vegetation on desktop or console hardware.

    In addition there's https://unity.com/how-to/10-tips-optimizing-console-game-graphics which goes into vegetation optimisations.

    The TLDR is:
    • no tessellation
    • use depth prepass with cutout
    • recycle your grass objects (use less of them)
     
  3. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    Well, the question for this thread is more of a overall generic question. I have many things that I need to optimize and the grass is simply the one that is most likely to be the biggest culprit, hence why it was used as an example of what I am doing right now.

    The target platform is PC, the version is 2020.3.f14 and the render pipeline is the built in render pipeline.

    OBS: The grass is the exact same 4 triangle mesh being rendered a ton of times through instancing and being animated/converted into flowers/bent and cut in the instancing setup() + vertex shader