Vixen
02b45cc4
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.

No guide page documents this yet — the page shows what the code says about itself.

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.

⚠ 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 (5)

  • 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.

Methods (6)

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

    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 End(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 (2)

  • EditorHostVixen.Editor.Host
  • GpuProfilerTestsVixen.Editor.Profiler.Tests