Skip to content

Give each GPU pass of a profile to the frame that submitted it, where it ran - #10

Merged
tomaszbk merged 2 commits into
mainfrom
profiler/gpu-pass-frames
Nov 15, 2026
Merged

tomaszbk merged 2 commits into
mainfrom
profiler/gpu-pass-frames

Conversation

@5hif7y

@5hif7y 5hif7y commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Closes #5.

Rebuilt on main 8c5a2a6 after the review; the comment below answers it point by point.

Changes

Give each GPU pass of a profile to the frame that submitted it

A host frame can submit more than once (a capture, a thumbnail, a UI
texture besides the window), and the renderer kept only the timings of
the last submission the GPU finished: a recorded frame lost the passes of
its other submissions and was still counted as measured.

  • rhi.frame_timings also returns the rhi frame those timings measured
    (Vulkan and Metal), and whether the slot had submitted one.
  • render copies the timings of every submission into a list
    (renderer_gpu_submissions) that the host takes and clears each frame.
  • host gives each submission to the recorded frame whose range of rhi
    frames holds it. A frame is measured once all of its submissions came
    back; a recording runs up to PROFILE_GPU_LATE frames past its last one,
    keeping no zones, until they do. Passes keep where they ran, on the
    clock of the zones.
  • editor: the result structs of main gain gpu_measured, gpu_frames and
    the start_ms of a pass; GPU numbers leave out unmeasured frames.
    profile.export writes a GPU thread. The profiler panel draws passes
    where they ran and says when a frame was not measured.

Merge order

Merge first of the profiler chain: #10, then #12, then #13. All six PRs were merged together onto main with no conflict, and the steps of checks.yml pass on that tree (mirai check on 135 packages, 18 test suites without a GPU).

Not tested

🤖 Generated with Claude Code

@5hif7y

5hif7y commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Needs more testing as a user before merging.

The tests and the sessions listed in the description cover the engine side only. My lead and I will adapt it as needed, and tomorrow I will test it with a separate agent acting as a Mirai user.

@tomaszbk

Copy link
Copy Markdown
Member

Review: merge after fixes. Current main still reports the GPU time of the last frame the GPU finished, so this change is still needed. The branch is far behind main and needs a rebase: it conflicts in editor/api_profile.odin, plugins/profiler/editor/profiler.odin and rhi/vulkan_device.odin.

  1. Timings are lost when one host frame has more than one submission.
    • profile_gpu_take (host/profile.odin:269) reads the renderer stats once per host frame.
    • read_stats (render/frame.odin:171) overwrites r.stats.timings on every frame_begin.
    • So when an offscreen capture or a preview renders in the same host frame, the passes of the first submission are lost. The frame is still marked as measured, with a gpu_ms that is too low.
    • The new host test calls profile_gpu_add once per submission, so it does not catch this.
  2. Conflict with main. The PR extends Profile_Pass_Out and Profile_Frame_Stats_Out (editor/api_profile.odin:69, :116). main removed those copies in 67b5aca: the profile methods now answer with their result structs.

A host frame can submit more than once (a capture, a thumbnail, a UI
texture besides the window), and the renderer kept only the timings of
the last submission the GPU finished: a recorded frame lost the passes of
its other submissions and was still counted as measured.

- rhi.frame_timings also returns the rhi frame those timings measured
  (Vulkan and Metal), and whether the slot had submitted one.
- render copies the timings of every submission into a list
  (renderer_gpu_submissions) that the host takes and clears each frame.
- host gives each submission to the recorded frame whose range of rhi
  frames holds it. A frame is measured once all of its submissions came
  back; a recording runs up to PROFILE_GPU_LATE frames past its last one,
  keeping no zones, until they do. Passes keep where they ran, on the
  clock of the zones.
- editor: the result structs of main gain gpu_measured, gpu_frames and
  the start_ms of a pass; GPU numbers leave out unmeasured frames.
  profile.export writes a GPU thread. The profiler panel draws passes
  where they ran and says when a frame was not measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@5hif7y

5hif7y commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Rebuilt on main 8c5a2a6 as one commit, 5811c8d5, force-pushed to profiler/gpu-pass-frames. It merges into main cleanly.

  1. Timings lost when one host frame submits more than once. Fixed at the source.
    • rhi.frame_timings now also returns the rhi frame it measured (Vulkan and Metal).
    • render copies the timings of every submission into renderer_gpu_submissions. The host takes that list each frame and clears it, so read_stats no longer overwrites anything that matters.
    • profile_frame_end gives each submission to the recorded frame whose range of rhi frames holds it.
    • A frame counts as measured only once all of its submissions are back. A recording runs up to PROFILE_GPU_LATE frames past its last frame, keeping no zones, while it waits for them.
    • New test: a_recorded_frame_keeps_the_gpu_passes_of_every_submission. It replaces the test that called profile_gpu_add once per submission.
  2. Conflict with 67b5aca. There are no *_Out copies left. The result structs of main gain gpu_measured, gpu_frames and the start_ms of a pass. GPU numbers leave out unmeasured frames.

Not tested:

@5hif7y
5hif7y requested a review from tomaszbk November 15, 2026 01:26
@5hif7y

5hif7y commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Follow-up: a live run of the "Not tested" item. Run on all six PRs merged onto main 8c5a2a6, demo, RX 580, a headless --copy session.

  • The run: a 12-frame recording (advance:false), with a capture RPC after the 4th frame, then profile.export.
  • Result: each of the 12 recorded frames has its own 20 GPU passes and is measured. Frames 5–11 show 3.9–4.3 ms of GPU, the same as before the capture.
  • The capture's settling renders (≈3.5 s of offscreen frames) land in no recorded frame: they run between host frames, not inside one. On main, read_stats would have handed the timings of the capture's last submission to the next recorded frame.
  • Not covered live: a host frame that submits twice inside itself. The capture RPC in a manual headless session runs between frames, so that case is still covered by a_recorded_frame_keeps_the_gpu_passes_of_every_submission only.

@5hif7y

5hif7y commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Follow-up: bench compare now runs on this machine (with #84), and this is what it measures.

Setup:

Run frame p50 Δ Δ per pair GPU Δ Δ per pair CPU main Δ
head vs base, 1 +0.056 ms (+1.2 %) +0.055 to +0.095 +0.050 ms +0.045 to +0.080 −0.062 (pairs disagree)
head vs base, 2 +0.055 ms (+1.2 %) +0.040 to +0.068 +0.053 ms +0.038 to +0.068 +0.024 (pairs disagree)
base vs base +0.024 ms (+0.5 %) −0.425 to +0.027 +0.023 ms −0.126 to +0.035 −0.020 (pairs disagree)

How I read it:

… ones a failed begin collected

- rhi: a slot with no query pool, or whose times the device could not read,
  is not measured (Vulkan and Metal), instead of measured with no passes.
- render keeps the timings a frame_begin collected before it failed, once per
  rhi frame.
- host waits for the GPU times of any recorded frame still missing them, not
  only of the last one.
- The GPU test of the profile has its own file, so --no-gpu runs the others.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attribute GPU pass timings to the frame that submitted them

2 participants