Search Unity

Question How to retrieve specific GPU usage time from Profiler in code?

Discussion in 'Editor & General Support' started by Superark, May 29, 2023.

  1. Superark

    Superark

    Joined:
    Mar 2, 2018
    Posts:
    2
    How can I obtain the consumption time of a specific row under GPU usage in Unity 2021.3, for example, the time taken by ParticleSystem.Draw as illustrated in the image below.
     

    Attached Files:

  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,452
    Hi there,
    The GPU profiler, when using the Graphic APIs and configurations with which it works, shows GPU costs associated with commands issued from the CPU as attributed into a CPU like hierarchy of calls that lead to the calls issuing the command.

    That is to say, not all of the entries you see have actual GPU Markers associated with them using the same name. That is only true for the commands that are issued. Some of the samples shown are essentially from higher order CPU markers around the code that issued the commands and the hierarchy of the CPU samples bubbles the GPU cost up the hierarchy.

    That said, some of these totally do have GPU marker equivalents that can be queried from code using ProfilerRecorders together with the ProfilerRecorderOptions.GpuRecorder to record these. And you can use ProfilerRecorderHandle.GetAvailable to get the full list of supported metrics and filter it to GPU markers via ProfilerRecorderHandle.GetDescription(handle).Flags.HasFlag(MarkerFlag.SampleGPU)