List translation: a bench of a frame's list calls, a draw's retirements under one lock, per-thread draw counts, dropped draws by reason #2006

Closed
github-bot wants to merge 6 commits from github-bot/gh-2006 into main AGit
Owner

@⁠binarycleric on GitHub · 2026-11-29 07:07 UTC · original
up/list-translation-cpu → main · +1285 −34 · 12 files · 6 commits · closed without merging

What it changes

Why

Turning the title's list calls into D3D12 calls costs about 6.2 µs a call in
play logs of 2026-11-28: about 280 ms of CPU a frame across the eight
threads that do it. Those are the title's own recording threads, or with
VICTORY_THIN=1 our victory-list-* threads, whose work the submissions
then wait for. There was no way to measure that cost outside a play run, and
no profile of where it goes.

The 5-second line also put every dropped draw under "without a host
pipeline". That was 300 to 1,400 draws a frame, and nobody could tell
missing pipelines from draws that failed to bind.

What

Commits 1, 2, 4: a bench of the list calls (list/bench.rs, #[ignore])

  • What it runs: eight threads record 25 lists of 30 draws each a frame
    (about 23,500 calls) through the same list::state calls as a translating
    thread.
  • Pipelines: the title's own, the first 160 of early-pipelines.txt,
    made from an earlier run's known-pipelines.bin and known-shaders.bin
    (pipeline/known.rs bench_pipelines).
  • Tables: they hold what the shaders read:
    • textures, three in four of them views of title-placed memory;
    • raw buffer views over 512 buffers;
    • constant buffers and samplers.
  • Per draw: root constants, root views, and vertex and index buffers from
    a mesh pool; each thread has its own render targets and depth target.
  • Timing: each frame's lists are submitted afterwards, untimed, so
    textures upload once, as in a run. The bench prints ns and cycles per call
    (QueryThreadCycleTime), CPU ms and wall ms a frame.
  • VICTORY_BENCH_PROFILE=1: samples the threads every quarter
    millisecond (suspend, RtlVirtualUnwind, dbghelp with inline frames; no
    admin rights needed) and prints where they were.
  • VICTORY_BENCH_AB=<switch>,..: turns toggled! switches off and on
    frame by frame in one run and prints the median on/off ratio of 30 frame
    pairs.
    • Why: between separate runs, the numbers moved 30 % and more with the
      machine's other load.
    • In test builds without diagnostics, toggled! checks this variable
      once. Other builds are unchanged.
  • Run:
    VICTORY_BENCH_CACHE=<copy of the cache folder's pipelines\ and shaders\> cargo test --release -p victory-gpu --lib list::bench -- --ignored --nocapture --test-threads=1
    
    Use a copy, because the bench writes to its shaders folder.

Profile (bench, 8 threads, before the changes below)

  • About 45–50 %: fresh (constant buffer) tables: make_listed /
    make_null → HostHeap::keep → retire_resource, plus the driver's
    descriptor calls. retire_resource alone was 14.6 %, nearly all of it
    waiting for the RETIRED lock.
  • 15–20 %: texture work (readable, upload_from with texture::staging's
    STAGING lock, hosted, transition).
  • 11 %: placed_texture.
  • About 3 %: views_read; 3–5 %: shadow::lookup / find_any.

Commit 3: a draw's retirements go to the shared line in one go (VICTORY_RETIRE_BATCH, on)

  • Before: a fresh table retires what each of its dynamic slots showed
    before, about 20,000 resources a frame. Each was pushed onto RETIRED
    under its lock and counted in a shared atomic, by all eight threads.
  • Now: State::tables holds a host::Retiring, during which
    retire_resource keeps each object, with the submission count it was
    retired at, in a thread-local list. At the end the list goes onto
    RETIRED under one lock, with one atomic add.
  • Lifetimes: no object is dropped earlier than before, since its count
    is the same; at worst it waits one more bury.
  • Nesting and fallback: a nested Retiring leaves its objects to the
    outer one. If the thread's local storage is gone, the object goes straight
    to the line.
  • VICTORY_RETIRE_BATCH=0 retires one object at a time, as before.

Commit 5: draw counts per thread (VICTORY_SPREAD_COUNTS, on)

  • Before: every draw added to two or three atomics shared by the whole
    process (DRAWS, DRAWS_EVER, then DRAWN, DROPPED or DISPATCHED).
    Their cache lines moved between cores with every draw.
  • Now (counts.rs): each thread has its own counters, on lines of their
    own, written only by that thread with a plain load and store.
    • total() sums every thread's counters, including threads that have
      ended.
    • take() replaces the old swap with 0.
    • The readers are the frame lines, the warm-up watcher and the panel, at
      most once per present.
  • VICTORY_SPREAD_COUNTS=0 goes back to the shared atomics. Non-Windows
    builds keep the old statics.

Commit 6: dropped draws counted by reason

  • Each drop now also counts under one reason:
    • left out on purpose: the pipeline's left_out, the structure
      builder while it is off, or a pipeline skipped in diagnostics builds;
    • no host pipeline: being made, or refused;
    • could not be bound: the pipeline exists, but prepare() or bind()
      refused (no free table slots, a root SRV without a view, an index buffer
      not found, the wrong kind of pipeline).
  • pipeline::host_missing() tells these apart without waiting for the
    pipeline, and it runs only for a dropped draw.
  • The line now reads "dropped N (A without a host pipeline, M being made; B
    that could not be bound; C left out on purpose)".
  • It changes no behaviour, so it has no switch.

Measurements

All from the bench, with frames alternating off and on in one run. Each
figure is the median of 30 pair ratios (on/off), and below 1 is better.
Other sessions loaded the machine throughout.

Change Cycles per call Thread time per call
Retire batching (3 runs) 1.000, 0.951, 0.896 0.997, 0.926, 0.885
Per-thread counts (2 runs) 0.967, 0.972 0.971, 1.023
Both together (2 runs) 0.862, 0.932 0.875, 0.930
  • With both on, a call went from 5.7–5.8 µs to 5.1–5.4 µs.
  • Retire batching gained most on the quietest run (31 ms frames): from
    7.2 µs to 6.2 µs a call.
  • The bench ran at about 7.5 µs a call before the changes, against 6.2 µs in
    play.

Not tried in play. None of this has run in the game yet: every number
above is from the bench. Both behaviour changes can be turned off
(VICTORY_RETIRE_BATCH=0, VICTORY_SPREAD_COUNTS=0).

Tried and left out, because the bench measured no gain:

  • a per-list cache of texture lookups: cycles 1.05–1.09, then 1.01–1.02
    after a rework;
  • a faster hash for byte keys: cycles 0.96–1.00, thread time 0.96–1.04.

Leads not taken here

These are all in the fresh-table path:

  • the COM reference each dynamic slot takes on the resource it shows;
  • the global STAGING lock, taken per texture on a list's first use (about
    6 %);
  • State::fresh_tables starting empty in every list (2–7 %).

How it was tested

  • GPU and profile: RTX 5070 Ti 16 GB, Ryzen 9 7900X; Series X profile, 1440p native, DLSS off, frame generation off; ray-tracing passes left out (no structure builder) (play numbers), plus the list-call bench (above)
  • Before: in play before these commits, about 44,850 list calls a frame in about 280 ms on all threads (6.2 µs each)
  • After: in play with them, 32,700–34,300 calls a frame in 173–174 ms on all threads (about 5.2 µs each) at 26–28 fps; dropped draws now say why ("0 without a host pipeline, 0 being made; 0 that could not be bound; 462 left out on purpose"). Different builds and scenes, so the bench numbers above are the measurement of this PR
  • cargo test passed for the crates it touches: yes. Rebased onto main e1f2eb60: cargo test --release -p victory-gpu --lib, 592 passed, 0 failed, 45 ignored

Tests

  • host::retiring_tests:
    • inside a Retiring, objects are kept alive by the thread, with counts
      no later than when retired;
    • a nested Retiring leaves them to the outer one;
    • at the end they are in the line, still alive;
    • outside a Retiring, they go to the line at once.
  • counts::tests: eight threads' adds all count; take gives what came
    since the last take.
  • draw::dropped_tests: each drop counts in the total and under its reason.
  • list::bench is #[ignore]d: it needs an earlier run's cache folder.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1735 (counts repeated lists and draws in the thin path; different counters). Nothing else found for the draw retirements or the drop reasons.
**@⁠binarycleric** on GitHub · 2026-11-29 07:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2006) `up/list-translation-cpu` → `main` · +1285 −34 · 12 files · 6 commits · closed without merging ## What it changes ### Why Turning the title's list calls into D3D12 calls costs about 6.2 µs a call in play logs of 2026-11-28: about 280 ms of CPU a frame across the eight threads that do it. Those are the title's own recording threads, or with `VICTORY_THIN=1` our `victory-list-*` threads, whose work the submissions then wait for. There was no way to measure that cost outside a play run, and no profile of where it goes. The 5-second line also put every dropped draw under "without a host pipeline". That was 300 to 1,400 draws a frame, and nobody could tell missing pipelines from draws that failed to bind. ### What **Commits 1, 2, 4: a bench of the list calls** (`list/bench.rs`, `#[ignore]`) - **What it runs:** eight threads record 25 lists of 30 draws each a frame (about 23,500 calls) through the same `list::state` calls as a translating thread. - **Pipelines:** the title's own, the first 160 of `early-pipelines.txt`, made from an earlier run's `known-pipelines.bin` and `known-shaders.bin` (`pipeline/known.rs` `bench_pipelines`). - **Tables:** they hold what the shaders read: - textures, three in four of them views of title-placed memory; - raw buffer views over 512 buffers; - constant buffers and samplers. - **Per draw:** root constants, root views, and vertex and index buffers from a mesh pool; each thread has its own render targets and depth target. - **Timing:** each frame's lists are submitted afterwards, untimed, so textures upload once, as in a run. The bench prints ns and cycles per call (`QueryThreadCycleTime`), CPU ms and wall ms a frame. - **`VICTORY_BENCH_PROFILE=1`:** samples the threads every quarter millisecond (suspend, `RtlVirtualUnwind`, dbghelp with inline frames; no admin rights needed) and prints where they were. - **`VICTORY_BENCH_AB=<switch>,..`:** turns `toggled!` switches off and on frame by frame in one run and prints the median on/off ratio of 30 frame pairs. - Why: between separate runs, the numbers moved 30 % and more with the machine's other load. - In test builds without `diagnostics`, `toggled!` checks this variable once. Other builds are unchanged. - **Run:** ``` VICTORY_BENCH_CACHE=<copy of the cache folder's pipelines\ and shaders\> cargo test --release -p victory-gpu --lib list::bench -- --ignored --nocapture --test-threads=1 ``` Use a copy, because the bench writes to its `shaders` folder. ### Profile (bench, 8 threads, before the changes below) - About 45–50 %: fresh (constant buffer) tables: `make_listed` / `make_null` → `HostHeap::keep` → `retire_resource`, plus the driver's descriptor calls. `retire_resource` alone was 14.6 %, nearly all of it waiting for the `RETIRED` lock. - 15–20 %: texture work (`readable`, `upload_from` with `texture::staging`'s `STAGING` lock, `hosted`, `transition`). - 11 %: `placed_texture`. - About 3 %: `views_read`; 3–5 %: `shadow::lookup` / `find_any`. **Commit 3: a draw's retirements go to the shared line in one go** (`VICTORY_RETIRE_BATCH`, on) - **Before:** a fresh table retires what each of its dynamic slots showed before, about 20,000 resources a frame. Each was pushed onto `RETIRED` under its lock and counted in a shared atomic, by all eight threads. - **Now:** `State::tables` holds a `host::Retiring`, during which `retire_resource` keeps each object, with the submission count it was retired at, in a thread-local list. At the end the list goes onto `RETIRED` under one lock, with one atomic add. - **Lifetimes:** no object is dropped earlier than before, since its count is the same; at worst it waits one more bury. - **Nesting and fallback:** a nested `Retiring` leaves its objects to the outer one. If the thread's local storage is gone, the object goes straight to the line. - `VICTORY_RETIRE_BATCH=0` retires one object at a time, as before. **Commit 5: draw counts per thread** (`VICTORY_SPREAD_COUNTS`, on) - **Before:** every draw added to two or three atomics shared by the whole process (`DRAWS`, `DRAWS_EVER`, then `DRAWN`, `DROPPED` or `DISPATCHED`). Their cache lines moved between cores with every draw. - **Now** (`counts.rs`): each thread has its own counters, on lines of their own, written only by that thread with a plain load and store. - `total()` sums every thread's counters, including threads that have ended. - `take()` replaces the old swap with 0. - The readers are the frame lines, the warm-up watcher and the panel, at most once per present. - `VICTORY_SPREAD_COUNTS=0` goes back to the shared atomics. Non-Windows builds keep the old statics. ### Commit 6: dropped draws counted by reason - Each drop now also counts under one reason: - **left out on purpose:** the pipeline's `left_out`, the structure builder while it is off, or a pipeline skipped in diagnostics builds; - **no host pipeline:** being made, or refused; - **could not be bound:** the pipeline exists, but `prepare()` or `bind()` refused (no free table slots, a root SRV without a view, an index buffer not found, the wrong kind of pipeline). - `pipeline::host_missing()` tells these apart without waiting for the pipeline, and it runs only for a dropped draw. - The line now reads "dropped N (A without a host pipeline, M being made; B that could not be bound; C left out on purpose)". - It changes no behaviour, so it has no switch. ### Measurements All from the bench, with frames alternating off and on in one run. Each figure is the median of 30 pair ratios (on/off), and below 1 is better. Other sessions loaded the machine throughout. | Change | Cycles per call | Thread time per call | |---|---|---| | Retire batching (3 runs) | 1.000, 0.951, 0.896 | 0.997, 0.926, 0.885 | | Per-thread counts (2 runs) | 0.967, 0.972 | 0.971, 1.023 | | Both together (2 runs) | **0.862, 0.932** | **0.875, 0.930** | - With both on, a call went from 5.7–5.8 µs to 5.1–5.4 µs. - Retire batching gained most on the quietest run (31 ms frames): from 7.2 µs to 6.2 µs a call. - The bench ran at about 7.5 µs a call before the changes, against 6.2 µs in play. **Not tried in play.** None of this has run in the game yet: every number above is from the bench. Both behaviour changes can be turned off (`VICTORY_RETIRE_BATCH=0`, `VICTORY_SPREAD_COUNTS=0`). Tried and left out, because the bench measured no gain: - a per-list cache of texture lookups: cycles 1.05–1.09, then 1.01–1.02 after a rework; - a faster hash for byte keys: cycles 0.96–1.00, thread time 0.96–1.04. ### Leads not taken here These are all in the fresh-table path: - the COM reference each dynamic slot takes on the resource it shows; - the global `STAGING` lock, taken per texture on a list's first use (about 6 %); - `State::fresh_tables` starting empty in every list (2–7 %). ## How it was tested - GPU and profile: RTX 5070 Ti 16 GB, Ryzen 9 7900X; Series X profile, 1440p native, DLSS off, frame generation off; ray-tracing passes left out (no structure builder) (play numbers), plus the list-call bench (above) - Before: in play before these commits, about 44,850 list calls a frame in about 280 ms on all threads (6.2 µs each) - After: in play with them, 32,700–34,300 calls a frame in 173–174 ms on all threads (about 5.2 µs each) at 26–28 fps; dropped draws now say why ("0 without a host pipeline, 0 being made; 0 that could not be bound; 462 left out on purpose"). Different builds and scenes, so the bench numbers above are the measurement of this PR - `cargo test` passed for the crates it touches: yes. Rebased onto main e1f2eb60: `cargo test --release -p victory-gpu --lib`, 592 passed, 0 failed, 45 ignored ### Tests - `host::retiring_tests`: - inside a `Retiring`, objects are kept alive by the thread, with counts no later than when retired; - a nested `Retiring` leaves them to the outer one; - at the end they are in the line, still alive; - outside a `Retiring`, they go to the line at once. - `counts::tests`: eight threads' adds all count; `take` gives what came since the last take. - `draw::dropped_tests`: each drop counts in the total and under its reason. - `list::bench` is `#[ignore]`d: it needs an earlier run's cache folder. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1735 (counts repeated lists and draws in the thin path; different counters). Nothing else found for the draw retirements or the drop reasons.
There was no way to time the translation of the title's list calls outside
a play session. list/bench.rs makes a gameplay frame's worth of them, about
23,000 calls (6,000 draws in 200 lists), on eight threads of ours through the
list methods the VICTORY_THIN threads call:
- the title's own pipelines: the first 160 graphics pipelines of an earlier
  run's early list, made from known-pipelines.bin (pipeline/known.rs
  bench_pipelines);
- their tables filled from what their shaders read: textures (4,000, a few
  in most tables), raw buffer views over 512 buffers, constants, samplers;
- root constants and root views per draw, vertex and index buffers from a
  pool of meshes, two render targets and a depth target per thread;
- each frame's lists run on the card after it, untimed, so that textures
  are uploaded once and dynamic slots come back, as in a run.

It reports per call the threads' time (waits included) and their processor
cycles, and the frame's wall time. VICTORY_BENCH_PROFILE=1 samples the
threads every quarter millisecond (suspend, unwind, dbghelp with inlined
frames) and prints functions inclusive and self, and lines.

Ignored by default: it needs a copy of a cache folder
(VICTORY_BENCH_CACHE). At 1120dd7's settings it measures about 7.5 us a
call, against the 6.2 us of the 04:11 play log.

Test helpers: resource::test_texture, descriptor::test_heap,
VertexView::new and IndexView::new.
Between separate runs the bench's numbers moved by 30 % and more with what
else the machine was doing (other builds and tests), more than the changes
it is meant to measure.

Now VICTORY_BENCH_AB=<switch>[,<switch>..] names switches of toggled! that
the bench turns on and off itself: measured frames come in pairs, one with
them off and one on, in either order by turns. It prints each side's
medians and the median of the pairs' ratios (on/off) of thread time,
cycles and wall time. Load that changes over seconds falls on both sides.

In test builds without diagnostics, toggled! looks for its name in
VICTORY_BENCH_AB once, like VICTORY_AB in diagnostics builds: a OnceLock
and, for a named switch, one atomic load. Other builds are unchanged.

The bench's wall time no longer includes the untimed submission after
each frame.
A table made afresh retires what each of its dynamic slots showed before
(the slots go round): about 20,000 resources a frame, each pushed onto
RETIRED under its lock and counted in a shared atomic. All eight
translating threads do this for every fresh table. In the list call bench
(8 threads, the title's pipelines), retire_resource was 14.6 % of the
threads' samples, nearly all of it waiting for that lock.

Now State::tables holds a host::Retiring while it runs. Inside it,
retire_resource keeps what it retires in a thread-local list, each object
with the submission count it was retired at. When the Retiring ends, the
list goes onto RETIRED under one lock, with one atomic add. An object is
never dropped earlier than before: its count is the same, and bury only
looks at the line, so at worst it waits one more bury. Nested Retirings
leave their objects to the outer one. Outside a Retiring, and with
VICTORY_BURY_LAG=0 when nothing runs, nothing changes. If the thread's
local storage is already gone, the object goes straight to the line.

VICTORY_RETIRE_BATCH=0 retires one at a time, as before.

Bench, frames alternating off/on in one run (VICTORY_BENCH_AB), median of
30 pair ratios, three runs with the machine under other sessions' load:
cycles per call 1.000, 0.951, 0.896; thread time 0.997, 0.926, 0.885. The
quietest run (31 ms frames) gained the most: 7.2 to 6.2 us a call.

Test (host::retiring_tests): inside, objects are held alive by the thread
with counts no later than when retired; a nested Retiring leaves them to
the outer one; at its end they are in the line, still alive; outside, at
once.
The title's streamed and interface textures are views of memory it placed
them in (device 0x230). Those go through placed_texture: the shared
PLACED_TEXTURES map, want_level, and alias_of's TARGETS_AT. The bench had
only views of committed textures, so it never took that way.

Now three of four texture views in its tables are placed views, of 4,000
textures 64 KiB apart in one stretch of title memory. With them,
placed_texture is 11 % of the threads' samples.
Every draw added to two or three atomics shared by the whole process: the
title's draw counts (list.rs count_draw: DRAWS, DRAWS_EVER) and the host's
(DRAWN, or DROPPED; DISPATCHED for dispatches). All eight translating
threads did this, so those cache lines moved from core to core with every
draw.

Now counts.rs keeps the counters per thread, each thread's on lines of its
own, and only that thread writes them (a load and a store, no locked add).
total() sums all threads' (a thread's stay when it ends). take() is total
less what was taken before, as the swap with 0 was. Readers are the frame
lines, the warm-up watcher and the panel: per present or rarer.

VICTORY_SPREAD_COUNTS=0 uses the shared atomics, as before. Non-Windows
builds keep the old statics.

Bench, frames alternating off/on in one run (VICTORY_BENCH_AB), median of
30 pair ratios over two runs: cycles per call 0.967 and 0.972, thread time
0.971 and 1.023 (the machine was under other sessions' load).

Test (counts::tests): eight threads' adds all count; take gives what came
since the last take.
DROPPED counted every draw, mesh dispatch and dispatch that did not run on
the host: no host pipeline, a pipeline left out on purpose, and every
failure in prepare() and bind(). The 5-second line called all of them
"without a host pipeline". In play that was 300 to 1,400 draws a frame,
and nobody could tell missing pipelines from draws that failed to bind.

Each drop now also counts under one of three reasons (counts.rs):
- left out on purpose: the pipeline's left_out, the structure builder
  while it is off, and a pipeline skipped in diagnostics builds;
- no host pipeline: being made, or refused;
- could not be bound: the pipeline is there, but prepare() or bind() said
  no (a table without free slots, a root SRV without a view, an index
  buffer not found, the wrong kind of pipeline).

pipeline::host_missing() tells the first two apart from the third without
waiting for the pipeline. It is asked only for a dropped draw.

The line now reads "dropped N (A without a host pipeline, M being made; B
that could not be bound; C left out on purpose)". This is not a behaviour
change, so it has no switch.

Test (draw::dropped_tests): each drop counts in all and under its reason.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 07:10:40 +00:00
github-bot closed this pull request 2026-11-29 07:16:12 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2006
No description provided.