Skip to content

feat(gpu): report how long threads are held by host GPU work, by what ran it - #446

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
Nick233x:diag/blocked-in-host-work
Nov 27, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
Nick233x:diag/blocked-in-host-work

Conversation

@Nick233x

Copy link
Copy Markdown
Contributor

A measurement that comes before a design question: how long the title's threads are held inside VIctory's GPU work each frame.

Why

When the title calls ExecuteCommandLists, the call runs whatever held work may run then (crate::hold, through queue::pump). That work is Host::execute: the preparation, the host submission, the wait for the GPU and the copy-back. The call returns to the title only after all of it. The same happens when the title signals or waits on a queue, sets a fence from the CPU, or presents. A thread that only polls (GetCompletedValue, SetEventOnCompletion) uses try_lock and is not held when another thread is pumping.

On the console, ExecuteCommandLists returns at once and the GPU works alongside. Here the title's thread waits through the GPU work itself, about 140–260 ms of a 450–1,060 ms world frame on M5 Pros in #131 and #409, plus VIctory's preparation. If the title would otherwise spend that time on its own work, submitting without waiting could save up to the GPU time. Preparing on another thread could save more. But the change would be deep. crate::hold tests queue waits against values the copy-back writes, and much of shadow.rs relies on "a submission waits for the one before it". So it is only worth designing if the title really is held there and not waiting anyway. Nothing measures that today. SUBMISSION_US counts preparation and GPU time, but not who was held by them.

What changes

  • queue.rs keeps two counters for each Why, in microseconds:

    • the time waiting for the queues' lock (held_for, through the small lock_timed);
    • the time in the pump, the host submissions included.
  • The callers that block are the title's submissions, its queues' Signals and Waits, pump_held for CPU fence signals and presents, and our 2 ms timer thread. They take the lock through held_for(why). pump times its body, now pump_work, unchanged.

  • The 5 s frame report in host.rs adds one line, in every build, since it costs a clock read or two per pump:

    threads held by host GPU work per frame, ms waiting for the queues' lock + running it: title submissions 0.0 + 0.0, queue signals 0.0 + 0.0, queue waits 0.0 + 0.0, fence calls 0.0 + 0.0, presents 0.0 + 0.0, our timer 0.0 + 0.0
    

    The zeros show the format, not a measurement. "our timer" is VIctory's own thread, so time there holds no title thread.

How to read it

  • Large "title submissions" (and "presents") times next to the frame time mean the title's render thread spends that part of the frame waiting on host GPU work. That is the case for submitting without waiting.
  • If most of the time sits under "fence calls" or "our timer", the title was waiting for the GPU anyway, or VIctory's own thread did the work. Submitting without waiting would then gain little.
  • Lock-wait time means two threads met at the queues' lock: one held while another ran work.

Tested

On an M5 Pro, macOS 26.6.2, GPTK 4.0 beta 3, Wine built by setup.sh:

  • tools/macos/test-wine.sh -p victory-gpu --lib: 363 passed, 0 failed. The one new test is queue::tests::a_timed_lock_counts_its_wait.
  • cargo test -p victory-gpu --lib queue::tests (native): 6 passed.
  • cargo clippy --target x86_64-pc-windows-gnullvm --workspace --all-targets: no warnings. The native clippy count is unchanged from main.

I have not seen the new line in a game run, since I have no game files. It needs someone's world run, ideally next to the existing ms/frame line from the same report.

AI-assisted, prepared with Claude Code.

🤖 Generated with Claude Code

… ran it

A title thread that submits, signals or waits on a queue, calls a fence or
presents runs the held work that may run then (crate::hold), the host
submissions with their preparation, GPU wait and copy-back included. It
goes on with its frame only after that. The 5 s frame report now gives,
per frame and per trigger, the milliseconds spent waiting for the queues'
lock and running the work, so a world run shows how much of a frame the
title spends held there rather than on its own work: the figure that says
whether submitting without waiting would pay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur
pragyaangaur merged commit 170b7a4 into pragyaangaur:main Nov 27, 2026
1 check passed
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.

2 participants