Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Measuring GPU elapsed time/load?

Discussion in 'Graphics Experimental Previews' started by Kolyasisan, Mar 13, 2020.

  1. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    HDRP supports "software dynamic resolution", which basically makes the camera render into a part of a render target via viewport resize (which is not like the "hardware dynamic resolution" which scales the entire texture). We are also in the process of writing a custom SRP with such a feature and we want to ideally support it on all of our target platforms (PC (SM5.0 GPUs) and consoles).

    However, there is a problem. There seemingly is no universal way to estimate how much time it takes for the GPU to render the frames. There is a FrameTimingManager which allows you to get such info, but it only works on platforms/APIs that support hardware dynamic resolution (so it's useless on Windows DX11, for example).

    Trying to solve this issue I experimented with the PlayerLoop API, but there is seemingly no way to measure GPU timing from there. On DX11, Unity executes the VSync wait in the PostLateUpdate.FinishFrameRendering event, but that alone doesn't give anything to us.

    So I ask this question: is it possible to estimate the GPU elapsed time or its load without using FrameTimingManager? If not, then what's the point in HDRP's dynamic resolution on Windows DX11 if you can't even get data on which you basis your scaling logic?
     
    Last edited: Mar 13, 2020
    SamFernGamer4k likes this.
  2. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Bump?
     
    SamFernGamer4k likes this.
  3. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Bump? (i'm sorry)
     
    SamFernGamer4k likes this.
  4. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    I don't know any definite answer to that question, but I have asked a similar one to myself.

    As far as I know, Unity will not provide anything to measure precisely the GPU load.
    I'm pretty sure we have to rely on other software, such as some Intel or Nvidia advanced tools, but unfortunately it's unlikely those will be working on any hardware, and it's unlikely that different such tools will provide measures which can be compared to each other.
     
    SamFernGamer4k likes this.
  5. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Those tools were designed for debugging only, so those aren't suited for a runtime routine like getting the GPU execution time.

    And on the other side, Unity can already measure GPU execution time with its profiler, even with different segments. It says that "the feature is not supported on all the hardware/drivers", but in my case it accurately worked on virtually every SM5.0 GPU I had, both from Nvidia and AMD.

    Unity also provides timing info for platforms that support dynamic resolution, those being Metal, Vulkan on Android, PS4, DX11 (on XONE), DX12 and Nintendo Switch. I doubt they can't bring this feature simply because of different architectures or APIs on SM5.0 hardware. Doom 2016 can do it, Titanfall can do it, UE4 can do it, so what's the problem here?
     
    Last edited: Mar 17, 2020
    SamFernGamer4k likes this.
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
  7. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Oh yeah, just saw that in the 2020.1 beta blogpost. Haven't experimented with it yet, but I wonder whether it'll work on release builds (since it's under the profiling namespace) and what the overhead will be. Can someone from the development team clarify this please?

    It won't work for our project unfortunately, we plan to ship it with 2019.4 LTS, but I'll still experiment with it.
     
    SamFernGamer4k likes this.
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    SamFernGamer4k likes this.
  9. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    SamFernGamer4k likes this.
  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    maybe? absolutely not my area of expertise, sorry :/
     
    SamFernGamer4k and Kolyasisan like this.
  11. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Alright. Thank you so much for clarifying.
     
    SamFernGamer4k likes this.
  12. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    bit of an update on that note, 2021.2 will very likely have this working on all platforms and Graphics APIs.
     
  13. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    900
    That's great news that it will likely work on all platforms in 2021.2, but what about the ability to access something like this at runtime in release builds so that we can dynamically tune performance?
     
    projectorgames_unity likes this.
  14. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Some of these are available in Release but depending on the Graphics API, getting such measurements can be costly (looking at you, OpenGL, you'll probably not want to use these in VR + OpenGL), so it is limited to a few high-level stats and markers. For dynamically tuning performance and cross platform compatibility, Frame Timing Managed has been adjusted to use GPU Markers and ProfilerRecorders as it's backend and therefore supports these measurements on the same breadth of platforms. More actually, as Metal is a bit trickier and doesn't yet support GPU measurements properly. But please check out this thread for more details on all that and raise your questions about Frame Timing Manager and GPU measurements in there :)
     
    Claytonious likes this.
  15. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    900
    Thanks for the info @MartinTilo ! I am reading that thread now!
     
    MartinTilo likes this.