i9-14900K + RX 9070 XT at a59f3e5: 6.5 fps standing still; the card is busy ~54% and the submitting thread waits on fences ~43% (profile) #163

Open
opened 2026-11-26 03:36:58 +00:00 by github-bot · 2 comments
Owner

@⁠ThiagoTodeschini on GitHub · 2026-11-25 18:02 UTC · original

Thanks for a59f3e5: on this machine it took the same spot from 4.5 to 6.5 fps. Here is where the time goes now, in case it helps with the next step.

Machine: Intel Core i9-14900K (8 performance + 16 efficiency cores, 32 threads), AMD Radeon RX 9070 XT 16 GB (driver 32.0.32029.2010), 32 GB DDR5-4800, Windows 11 (26200), Series X profile.
Build: a59f3e5 merged into a fork whose only code changes place threads on hybrid processors (https://github.com/ThiagoTodeschini/VIctory-AMD-Intel; standing still they make no measurable difference), diag profile with -C target-cpu=native, shader cache warm.
Scene: the same save, standing still at the same spot, about 4,800 to 5,000 draws a frame. Medians of the 5-second summary lines:

fps ms a frame preparing copies on the GPU copying back
01aadd1 4.5 224 94 47 93 34
a59f3e5 6.5 153 49 22 11 11

The card: the process's 3D engine is busy about 54% (Windows "GPU Engine" counter, 6 s sample), so the frame is not bound by the GPU.

VICTORY_PROFILE (one 20 s window, 11,682 samples of the submitting thread):

  • 62% between submissions, 38% in one
  • 43% in Host::wait_fence (host.rs:1186) under Timeline::step (timeline.rs:186), reached from queue::execute and queue::signal2_x
  • 12% in Mutex::lock_contended on self.submitted (host.rs:1286), and 9% under drain_in_flight_locked (host.rs:1294)
  • then bindless_plan about 6%, Shadow::update_lazily 6%, Shadow::copy_back 6%, watch::writes_guarded 4%, Instant::now with the performance counter about 3%, and 1.2% in ZwCreateThreadEx (the scoped threads in_parallel starts on each call)

Threads (CPU time over 20 s): the process uses about 4.3 cores; one title thread at about 74% of a core (41% of it in the kernel), five at 47 to 49%, one at 27%; victory-queues 8%.

So the submitting thread and the card mostly take turns. With async submission the title's recording overlaps the card, but execute_inner still drains the previous submission before prepare touches the shared host copies, so the next submission's preparation and the card's work do not overlap. Versioned (double-buffered) host copies for the ranges an in-flight submission reads, or per-range hazard tracking so a prepare waits only when it touches what the in-flight lists read, look like the next step; you know the constraints far better.

Tried here without gain (01aadd1 unless noted, same spot):

  • refreshes of sparse copies cut into 1 MiB pieces on 4 threads: the summed copy time doubled and the frame did not move (the threads queue on the tracking: the per-tile lock, the journal, VirtualQuery, ReadProcessMemory)
  • upload fills shared out between 4 threads: here they are about 7 MB a frame
  • VICTORY_SHADER_LOOP_LIMIT=4096: no change, so the GPU time is not runaway loops
  • a release build without diagnostics (a59f3e5): no change
  • --console series-s: +13%, for a softer picture

The profile file and the logs are available if useful.

**@⁠ThiagoTodeschini** on GitHub · 2026-11-25 18:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/163) Thanks for a59f3e5: on this machine it took the same spot from 4.5 to 6.5 fps. Here is where the time goes now, in case it helps with the next step. **Machine**: Intel Core i9-14900K (8 performance + 16 efficiency cores, 32 threads), AMD Radeon RX 9070 XT 16 GB (driver 32.0.32029.2010), 32 GB DDR5-4800, Windows 11 (26200), Series X profile. **Build**: a59f3e5 merged into a fork whose only code changes place threads on hybrid processors (https://github.com/ThiagoTodeschini/VIctory-AMD-Intel; standing still they make no measurable difference), `diag` profile with `-C target-cpu=native`, shader cache warm. **Scene**: the same save, standing still at the same spot, about 4,800 to 5,000 draws a frame. Medians of the 5-second summary lines: | | fps | ms a frame | preparing | copies | on the GPU | copying back | |---|---:|---:|---:|---:|---:|---:| | 01aadd1 | 4.5 | 224 | 94 | 47 | 93 | 34 | | a59f3e5 | 6.5 | 153 | 49 | 22 | 11 | 11 | **The card**: the process's 3D engine is busy about 54% (Windows "GPU Engine" counter, 6 s sample), so the frame is not bound by the GPU. **`VICTORY_PROFILE`** (one 20 s window, 11,682 samples of the submitting thread): - 62% between submissions, 38% in one - 43% in `Host::wait_fence` (host.rs:1186) under `Timeline::step` (timeline.rs:186), reached from `queue::execute` and `queue::signal2_x` - 12% in `Mutex::lock_contended` on `self.submitted` (host.rs:1286), and 9% under `drain_in_flight_locked` (host.rs:1294) - then `bindless_plan` about 6%, `Shadow::update_lazily` 6%, `Shadow::copy_back` 6%, `watch::writes_guarded` 4%, `Instant::now` with the performance counter about 3%, and 1.2% in `ZwCreateThreadEx` (the scoped threads `in_parallel` starts on each call) **Threads** (CPU time over 20 s): the process uses about 4.3 cores; one title thread at about 74% of a core (41% of it in the kernel), five at 47 to 49%, one at 27%; `victory-queues` 8%. So the submitting thread and the card mostly take turns. With async submission the title's recording overlaps the card, but `execute_inner` still drains the previous submission before `prepare` touches the shared host copies, so the next submission's preparation and the card's work do not overlap. Versioned (double-buffered) host copies for the ranges an in-flight submission reads, or per-range hazard tracking so a prepare waits only when it touches what the in-flight lists read, look like the next step; you know the constraints far better. **Tried here without gain** (01aadd1 unless noted, same spot): - refreshes of sparse copies cut into 1 MiB pieces on 4 threads: the summed copy time doubled and the frame did not move (the threads queue on the tracking: the per-tile lock, the journal, `VirtualQuery`, `ReadProcessMemory`) - upload fills shared out between 4 threads: here they are about 7 MB a frame - `VICTORY_SHADER_LOOP_LIMIT=4096`: no change, so the GPU time is not runaway loops - a release build without `diagnostics` (a59f3e5): no change - `--console series-s`: +13%, for a softer picture The profile file and the logs are available if useful.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:58 +00:00
Author
Owner

@⁠ySKELLETONX on GitHub · 2026-11-26 13:01 UTC · original

Thanks for the profile. I read the path it points at on main 4f62c2a; here is where the 43% in wait_fence seems to come from, and a direction to ask about before anyone writes it.

Where the submitting thread waits

queue::signal / signal2_x push an Op::Signal, and Timeline::step (timeline.rs) runs it on the calling thread:

Some(Op::Signal(fence, value)) => Box::new(move || {
    crate::host::wait_in_flight_if_ready();   // waits for the host GPU, then reap_completed
    fence.signal(value);
}),

Op::Work does the same. So with VICTORY_ASYNC_SUBMIT, execute_title returns before the card is done, but the title's next Signal on that queue blocks the title's thread until the card has finished and the copy-back (finish_submission) is done. The asynchronous part covers only the time between ExecuteCommandLists and the following Signal, which for this title is usually right after. That fits "the submitting thread and the card mostly take turns", and the 12% contention on submitted (wait_fence takes it on the title's thread while other paths want it).

A direction: title fences signalled by a completion thread

Instead of waiting in the op, a Signal that follows unfinished work would be handed to one thread that:

  1. waits on the host fence of the submission before it (SetEventOnCompletion),
  2. takes submitted and runs reap_completed (copy-back, bottom-of-pipe writes, burying), as wait_fence does now,
  3. then signals the title's fence.

The order the title can see stays the same (its fence is reached only after what the work wrote is back in its memory), but Signal returns at once, and the title's thread goes on recording while the card runs. Op::Wait on another queue already re-checks fence.reached, so it would just wait for the completion thread instead of finishing the work itself (finish in step).

What I don't know and you do:

  • whether anything relies on a Signal having finished the work by the time it returns (the comment at signal2_x says "our submissions are complete when they return");
  • how it combines with execute_inner still draining the previous submission before prepare. If the title waits on the fence it just signalled before recording more, the gain is small, and the double-buffered host copies you mention would be the bigger step. A trace of the title's Signal and Wait values in one frame would show which it is.

If that direction sounds right, I can prototype it on a branch with correctness tests (ordering, copy-back before the signal, a lost device while a signal is pending), and @⁠ThiagoTodeschini could measure it at the same spot. I can't measure in the world myself.

A small piece now

In the same profile, 1.2% went to ZwCreateThreadEx: in_parallel starts its threads with std::thread::scope on every call. I opened #253 to keep five threads instead. Start and join per call goes from about 280 µs to under 1 µs here (Ryzen 7 5700X3D, release).

**@⁠ySKELLETONX** on GitHub · 2026-11-26 13:01 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/163#issuecomment-7192769728) Thanks for the profile. I read the path it points at on `main` 4f62c2a; here is where the 43% in `wait_fence` seems to come from, and a direction to ask about before anyone writes it. **Where the submitting thread waits** `queue::signal` / `signal2_x` push an `Op::Signal`, and `Timeline::step` (timeline.rs) runs it on the calling thread: ```rust Some(Op::Signal(fence, value)) => Box::new(move || { crate::host::wait_in_flight_if_ready(); // waits for the host GPU, then reap_completed fence.signal(value); }), ``` `Op::Work` does the same. So with `VICTORY_ASYNC_SUBMIT`, `execute_title` returns before the card is done, but the title's next `Signal` on that queue blocks the title's thread until the card has finished and the copy-back (`finish_submission`) is done. The asynchronous part covers only the time between `ExecuteCommandLists` and the following `Signal`, which for this title is usually right after. That fits "the submitting thread and the card mostly take turns", and the 12% contention on `submitted` (`wait_fence` takes it on the title's thread while other paths want it). **A direction: title fences signalled by a completion thread** Instead of waiting in the op, a `Signal` that follows unfinished work would be handed to one thread that: 1. waits on the host fence of the submission before it (`SetEventOnCompletion`), 2. takes `submitted` and runs `reap_completed` (copy-back, bottom-of-pipe writes, burying), as `wait_fence` does now, 3. then signals the title's fence. The order the title can see stays the same (its fence is reached only after what the work wrote is back in its memory), but `Signal` returns at once, and the title's thread goes on recording while the card runs. `Op::Wait` on another queue already re-checks `fence.reached`, so it would just wait for the completion thread instead of finishing the work itself (`finish` in `step`). What I don't know and you do: - whether anything relies on a `Signal` having finished the work by the time it returns (the comment at `signal2_x` says "our submissions are complete when they return"); - how it combines with `execute_inner` still draining the previous submission before `prepare`. If the title waits on the fence it just signalled before recording more, the gain is small, and the double-buffered host copies you mention would be the bigger step. A trace of the title's `Signal` and `Wait` values in one frame would show which it is. If that direction sounds right, I can prototype it on a branch with correctness tests (ordering, copy-back before the signal, a lost device while a signal is pending), and @⁠ThiagoTodeschini could measure it at the same spot. I can't measure in the world myself. **A small piece now** In the same profile, 1.2% went to `ZwCreateThreadEx`: `in_parallel` starts its threads with `std::thread::scope` on every call. I opened #253 to keep five threads instead. Start and join per call goes from about 280 µs to under 1 µs here (Ryzen 7 5700X3D, release).
Author
Owner

@⁠ySKELLETONX on GitHub · 2026-11-26 14:12 UTC · original

@⁠ThiagoTodeschini, you offered the profile file: could you attach it (or the VICTORY_PROFILE output with the stacks)? Two things I can't settle from the summary:

  1. Instant::now at about 3%. It costs about 35 ns a call here (Ryzen 7 5700X3D), so 3% of a 153 ms frame would be on the order of 130,000 calls a frame on the submitting thread. The timing I can find on the release path runs once or twice per copy step, refreshed range or title-memory copy (run_deferred, update, watch::writing): thousands a frame, well under 0.1 ms. The diag build adds one per copy_mapped (copystat), and the title's own QueryPerformanceCounter calls would land in the same frame, so the callers decide whether there is anything to take out. You also saw no change in fps with a release build without diagnostics, which points the same way.
  2. Shadow::update_lazily, Shadow::copy_back (6% each) and watch::writes_guarded (4%). Which callers they come from, and whether it is a few large ranges or many small ones, would show where to look next.

Meanwhile the two smaller pieces are up: #258 (wait_fence no longer holds submitted while it waits for the card, the 12% contention) and #253 (in_parallel on kept threads, the 1.2% in ZwCreateThreadEx). If you get the chance, the same spot with them would show what they give back in the world; I can't measure there.

**@⁠ySKELLETONX** on GitHub · 2026-11-26 14:12 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/163#issuecomment-7194425965) @⁠ThiagoTodeschini, you offered the profile file: could you attach it (or the `VICTORY_PROFILE` output with the stacks)? Two things I can't settle from the summary: 1. **`Instant::now` at about 3%.** It costs about 35 ns a call here (Ryzen 7 5700X3D), so 3% of a 153 ms frame would be on the order of 130,000 calls a frame on the submitting thread. The timing I can find on the release path runs once or twice per copy step, refreshed range or title-memory copy (`run_deferred`, `update`, `watch::writing`): thousands a frame, well under 0.1 ms. The `diag` build adds one per `copy_mapped` (`copystat`), and the title's own `QueryPerformanceCounter` calls would land in the same frame, so the callers decide whether there is anything to take out. You also saw no change in fps with a release build without `diagnostics`, which points the same way. 2. **`Shadow::update_lazily`, `Shadow::copy_back` (6% each) and `watch::writes_guarded` (4%).** Which callers they come from, and whether it is a few large ranges or many small ones, would show where to look next. Meanwhile the two smaller pieces are up: #258 (`wait_fence` no longer holds `submitted` while it waits for the card, the 12% contention) and #253 (`in_parallel` on kept threads, the 1.2% in `ZwCreateThreadEx`). If you get the chance, the same spot with them would show what they give back in the world; I can't measure there.
This discussion has been locked. Commenting is limited to contributors.
No description provided.