Vixen
c7401864
csharp
public sealed class GpuProfiler

Records a frame's passes into a device's query pools and reads them back once the GPU has caught up.

Read the guide page for this →

Remarks

Doc 20 says the GPU profiler is the one item in E4 that "cannot start with the panel", and this is what it was waiting for. The RHI now has a query pool, a WriteTimestamp and a resolve path; what this class owns is the part above them — which pool a frame writes into, when it is safe to read one back, and how a pair of readings becomes a named region.

⚠ It lives beside the RHI and not in the editor, because the thing being measured is a game's frame. A profiler a game cannot reference is a profiler that can only ever report on the editor, and the editor's frame is not the frame anybody ships. The panels that draw a GpuFrame stay in Vixen.Editor.Profiler; what moved down here is only the instrument.

⚠ One pool per frame in flight, and it is not an optimisation. A single pool written every frame is one the GPU is still writing while the CPU reads it, so the readings are a mixture of two frames — which draws as passes that overlap impossibly. With FramesInFlight pools, the frame being recorded and the frame being read are never the same object.

⚠ Reading never waits. Resolve asks for the oldest pool and takes for an answer, because the alternative is a stall on the frame thread once per frame — a profiler that halves the frame rate it is reporting. The first few frames after attaching therefore produce nothing, which is correct and is why Latest starts empty.

Fields and properties (6)

  • public const int DefaultScopeCapacity

    How many regions one frame may record when no ceiling is given.

  • public int ScopeCapacity

    How many regions one frame may record.

  • public float Period

    The device's nanoseconds per tick.

  • public GpuFrame Latest

    The most recent frame that has come back from the GPU.

  • public int Abandoned

    How many frames were recorded but never read, because the panel closed first.

  • public int Dropped

    How many regions the frame being recorded asked for beyond ScopeCapacity.

Methods (6)

  • public GpuProfiler(IGraphicsDevice device, int scopeCapacity = 256)

    Attaches to a device.

  • public void BeginFrame(ICommandList commands, int frameIndex)

    Starts recording a frame's regions into the next pool.

  • public int? Begin(ICommandList commands, string name)

    Opens a named region.

  • public void Close(ICommandList commands, int? token)

    Closes a region.

  • public bool Resolve()

    Reads back whatever the GPU has finished, without waiting for it.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Used by (3)

  • AppGraphicsVixen.App.Hosting
  • GpuProfilerTestsVixen.Graphics.Tests
  • EditorHostVixen.Editor.Host