GPU: list calls can translate on worker threads (VICTORY_DEFER_LISTS, opt-in) #3184

Open
github-bot wants to merge 3 commits from github-bot/gh-3184 into main AGit
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 11:27 UTC · original
AurumCarlos:perf/defer-list-translation → main · +719 −14 · 6 files · 3 commits · open

First step for #2586: record list calls on the title's threads and translate them on worker threads. Off by default; VICTORY_DEFER_LISTS=<workers> turns it on.

What it does

A list made while the variable is set gets method tables whose entries log the call instead of translating it (crates/victory-gpu/src/list/later.rs). The title's thread copies the arguments, including what they point to (barriers, viewports, scissors, constants, copy locations, rectangles, clear values, heaps, vertex views, render target handles, barrier group headers), and goes on. Workers take the log in batches of 32 and run the existing methods, unchanged, in the order the title made the calls. Each list is translated by one worker at a time, and different lists in parallel.

Lists made without the variable keep today's tables, so the default path does not change. Every entry still calls the same functions.

What stays on the title's thread:

  • methods that return something the title reads: list type, QueryInterface, upload memory (0x4a0), driver hints;
  • Reset, ResetX and the last Release, which first wait for the list's logged calls. They free what those calls read: upload memory, the draw state and the host lists;
  • ExecuteCommandLists waits for its lists before it takes the held-work lock, so other queues are not held up meanwhile. crate::external::{host_texture, record} (host libraries recording into a title list) wait too.

Translation now reads title memory (descriptors, buffers, textures) after the call instead of during it, but still before the submission. On the console the GPU reads it even later, when the list runs, so a title cannot depend on the earlier read.

The 5-second report gets one line when the variable is set: calls translated by workers per frame, and how long title threads waited for them.

Tests

  • list::later::tests::each_log_runs_its_calls_in_order_on_workers: four logs filled at once. Each runs its calls in order, none on the logging thread, all of them by the time it settles.
  • resource::tests::deferred_lists_waiting_for_another_queues_write_read_what_it_wrote: the existing two-queue test (wait, write, copies) with deferred lists. It calls through the tables as a title does. After the copy call it clears the copy location it passed, so the test fails if an argument is read later instead of copied (checked: it fails with the copy removed).
  • every_inline_command_falls_back_to_the_table now resets through the table, as a title does. It called reset directly while Close went through the table, so with deferred lists the reset ran before the logged Close.

Run on an RX 9070 XT, Wine 11.22 (staging) with vkd3d-proton 3.1, cross-built for x86_64-pc-windows-gnu:

  • cargo test -p victory-gpu --lib: 201 passed. The same 30 tests fail on main (63bcca4) in this environment and pass or fail identically on this branch.
  • The same suite with VICTORY_DEFER_LISTS=4, so every list in every test is deferred: 200 passed, same 30 failures. Three tests are left out:
    • pipeline::depth_bounds_test: records on the host list directly between table calls and submits it itself, which a deferred list cannot support. The title cannot do this.
    • frame::waits_end_on_ticks_and_count_frames: timing-sensitive. Passes alone with and without deferral.
    • queue::aliased_present_planes_preserve_the_host_texture_state: hangs under Wine on main too.
  • cargo clippy -p victory-gpu --lib --tests -D warnings (Windows target, with and without diagnostics), cargo xtask policy.

Numbers

The benchmark from #2820 (list_calls: 5 threads, about 8,300 calls each per frame, release), on this branch. I added a timer around its submit-and-wait locally (not part of this PR). Same machine as above. Median of 5 runs, ms per frame:

workers title thread in calls (wall) title thread CPU submit + wait frame (record + submit)
main off 8.82 6.80 1.68 10.70
2 5.91 2.40 5.57 11.88
4 8.78 3.20 2.36 11.47
6 9.48 3.40 1.85 11.54
with #2821 off 5.69 5.00 1.65 7.48
2 2.91 2.00 6.92 10.12
4 3.15 2.00 5.22 8.61
6 3.17 2.00 3.99 7.36

What it shows:

  • DrawIndexedInstanced on the title's thread goes from about 3.8 µs to about 0.1 µs. Title-thread CPU time drops by 50-65%.
  • On main, the wall time does not follow. The descriptor writes that stay on the title's thread (CreateConstantBufferView, a device method) now wait for the workers on the locks #2820 found: 1.0 µs to 4.3 µs per call. With #2821, which removes those waits, title-thread time drops 45% at every worker count.
  • In this benchmark the threads only record, so nothing overlaps the translation, and the whole frame is no faster: equal with #2821 and 6 workers, slower with fewer. The gain this is meant for is time given back to the title's threads, which in a game have their own work. That needs a run of the game to measure, and I have not made one yet. The default stays off for that reason.

During measurements, one benchmark run through cargo test hung until its timeout, before the submission fix above. It did not happen again in 50 later runs (2, 4, 6 and 8 workers), and I have no explanation for it.

Not done here

  • Device methods the title calls while recording (view creation, descriptor copies) stay synchronous.
  • Splitting one list's log at barriers so that two workers translate it.
  • Reusing translations across frames (#2590).

No game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠AurumCarlos** on GitHub · 2026-11-26 11:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3184) `AurumCarlos:perf/defer-list-translation` → `main` · +719 −14 · 6 files · 3 commits · open First step for #2586: record list calls on the title's threads and translate them on worker threads. Off by default; `VICTORY_DEFER_LISTS=<workers>` turns it on. ## What it does A list made while the variable is set gets method tables whose entries log the call instead of translating it (`crates/victory-gpu/src/list/later.rs`). The title's thread copies the arguments, including what they point to (barriers, viewports, scissors, constants, copy locations, rectangles, clear values, heaps, vertex views, render target handles, barrier group headers), and goes on. Workers take the log in batches of 32 and run the existing methods, unchanged, in the order the title made the calls. Each list is translated by one worker at a time, and different lists in parallel. Lists made without the variable keep today's tables, so the default path does not change. Every entry still calls the same functions. What stays on the title's thread: - methods that return something the title reads: list type, `QueryInterface`, upload memory (0x4a0), driver hints; - `Reset`, `ResetX` and the last `Release`, which first wait for the list's logged calls. They free what those calls read: upload memory, the draw state and the host lists; - `ExecuteCommandLists` waits for its lists before it takes the held-work lock, so other queues are not held up meanwhile. `crate::external::{host_texture, record}` (host libraries recording into a title list) wait too. Translation now reads title memory (descriptors, buffers, textures) after the call instead of during it, but still before the submission. On the console the GPU reads it even later, when the list runs, so a title cannot depend on the earlier read. The 5-second report gets one line when the variable is set: calls translated by workers per frame, and how long title threads waited for them. ## Tests - `list::later::tests::each_log_runs_its_calls_in_order_on_workers`: four logs filled at once. Each runs its calls in order, none on the logging thread, all of them by the time it settles. - `resource::tests::deferred_lists_waiting_for_another_queues_write_read_what_it_wrote`: the existing two-queue test (wait, write, copies) with deferred lists. It calls through the tables as a title does. After the copy call it clears the copy location it passed, so the test fails if an argument is read later instead of copied (checked: it fails with the copy removed). - `every_inline_command_falls_back_to_the_table` now resets through the table, as a title does. It called `reset` directly while `Close` went through the table, so with deferred lists the reset ran before the logged Close. Run on an RX 9070 XT, Wine 11.22 (staging) with vkd3d-proton 3.1, cross-built for `x86_64-pc-windows-gnu`: - `cargo test -p victory-gpu --lib`: 201 passed. The same 30 tests fail on `main` (63bcca4) in this environment and pass or fail identically on this branch. - The same suite with `VICTORY_DEFER_LISTS=4`, so every list in every test is deferred: 200 passed, same 30 failures. Three tests are left out: - `pipeline::depth_bounds_test`: records on the host list directly between table calls and submits it itself, which a deferred list cannot support. The title cannot do this. - `frame::waits_end_on_ticks_and_count_frames`: timing-sensitive. Passes alone with and without deferral. - `queue::aliased_present_planes_preserve_the_host_texture_state`: hangs under Wine on `main` too. - `cargo clippy -p victory-gpu --lib --tests -D warnings` (Windows target, with and without `diagnostics`), `cargo xtask policy`. ## Numbers The benchmark from #2820 (`list_calls`: 5 threads, about 8,300 calls each per frame, release), on this branch. I added a timer around its submit-and-wait locally (not part of this PR). Same machine as above. Median of 5 runs, ms per frame: | | workers | title thread in calls (wall) | title thread CPU | submit + wait | frame (record + submit) | |---|---|---|---|---|---| | main | off | 8.82 | 6.80 | 1.68 | 10.70 | | | 2 | 5.91 | 2.40 | 5.57 | 11.88 | | | 4 | 8.78 | 3.20 | 2.36 | 11.47 | | | 6 | 9.48 | 3.40 | 1.85 | 11.54 | | with #2821 | off | 5.69 | 5.00 | 1.65 | 7.48 | | | 2 | 2.91 | 2.00 | 6.92 | 10.12 | | | 4 | 3.15 | 2.00 | 5.22 | 8.61 | | | 6 | 3.17 | 2.00 | 3.99 | 7.36 | What it shows: - `DrawIndexedInstanced` on the title's thread goes from about 3.8 µs to about 0.1 µs. Title-thread CPU time drops by 50-65%. - On `main`, the wall time does not follow. The descriptor writes that stay on the title's thread (`CreateConstantBufferView`, a device method) now wait for the workers on the locks #2820 found: 1.0 µs to 4.3 µs per call. With #2821, which removes those waits, title-thread time drops 45% at every worker count. - In this benchmark the threads only record, so nothing overlaps the translation, and the whole frame is no faster: equal with #2821 and 6 workers, slower with fewer. The gain this is meant for is time given back to the title's threads, which in a game have their own work. That needs a run of the game to measure, and I have not made one yet. The default stays off for that reason. During measurements, one benchmark run through `cargo test` hung until its timeout, before the submission fix above. It did not happen again in 50 later runs (2, 4, 6 and 8 workers), and I have no explanation for it. ## Not done here - Device methods the title calls while recording (view creation, descriptor copies) stay synchronous. - Splitting one list's log at barriers so that two workers translate it. - Reusing translations across frames (#2590). No game data. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
First step for #2586. A list made while VICTORY_DEFER_LISTS=<workers> is
set gets method tables that copy each call's arguments into a log; worker
threads run the existing methods from it, in order, one list at a time.
Lists made without it keep today's tables.

Methods that return what the title reads stay on its thread. Reset,
ResetX and the last Release wait for the list's logged calls first, as do
ExecuteCommandLists (before it takes the held-work lock) and host
libraries recording into the list. The 5-second report gets a line with
the calls workers translated and how long title threads waited.

Tests: log ordering on workers, and the two-queue test with deferred
lists (it clears an argument after the call to catch uncopied ones).
every_inline_command_falls_back_to_the_table now resets through the
table, as a title does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:33:10 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 12:09 UTC · original · approved these changes

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: 5/5 passed (including list::later::tests::each_log_runs_its_calls_in_order_on_workers).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Clean opt-in VICTORY_DEFER_LISTS worker-thread translation for command list calls.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 12:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3184#pullrequestreview-6073885769) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib list:: -- --test-threads=1`: 5/5 passed (including `list::later::tests::each_log_runs_its_calls_in_order_on_workers`). - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Clean opt-in `VICTORY_DEFER_LISTS` worker-thread translation for command list calls. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

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

I ran the two-queue fixture on native Windows at 768dcfa0, using an RTX 5080 and Windows' built-in WARP with the D3D12 debug layer. I expanded the pre-wait copy into 261 overlapping 8-byte writes through the title's command-list table. This crosses eight 32-call batch boundaries and leaves five writes in the final partial batch.

VICTORY_DEFER_LISTS Calls counted on workers RTX 5080 WARP
0 0 1,024/1,024 pre-wait bytes and 64/64 texture bytes correct same
1 267 1,024/1,024 and 64/64 same
4 267 1,024/1,024 and 64/64 same

Each setting gave the same result in two fresh processes per adapter. The pre-wait check observes VIctory's submission-time host-buffer copies. The separate texture check observes the graphics queue's write after the wait. Before the graphics submission, all 1,024 destination bytes still held the sentinel and the flag was 0. After submission, the flag was 1 and all four 16-byte rows matched. Omitting only the last five copies in a local control produced exactly 40 wrong pre-wait bytes on each adapter.

The existing aliased_present_planes_preserve_the_host_texture_state test also completed on both native Windows adapters with four workers selected. I haven't measured game frame times.

Test-only commit on this PR head. To rerun it in PowerShell, choose 0, 1, or 4 for the worker count and 0 (hardware) or 1 (WARP) for the adapter, then run:

$env:VICTORY_DEFER_LISTS = '4'
$env:VICTORY_D3D12_WARP = '1'
$env:VICTORY_D3D12_DEBUG = '1'
cargo test -p victory-gpu --lib --all-features overlapping_copies_across_worker_batches_survive_a_queue_wait -- --ignored --test-threads=1
**@⁠steven-seagull27** on GitHub · 2026-11-26 12:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7191753515) I ran the two-queue fixture on native Windows at `768dcfa0`, using an RTX 5080 and Windows' built-in WARP with the D3D12 debug layer. I expanded the pre-wait copy into 261 overlapping 8-byte writes through the title's command-list table. This crosses eight 32-call batch boundaries and leaves five writes in the final partial batch. | `VICTORY_DEFER_LISTS` | Calls counted on workers | RTX 5080 | WARP | |---|---:|---|---| | `0` | 0 | 1,024/1,024 pre-wait bytes and 64/64 texture bytes correct | same | | `1` | 267 | 1,024/1,024 and 64/64 | same | | `4` | 267 | 1,024/1,024 and 64/64 | same | Each setting gave the same result in two fresh processes per adapter. The pre-wait check observes VIctory's submission-time host-buffer copies. The separate texture check observes the graphics queue's write after the wait. Before the graphics submission, all 1,024 destination bytes still held the sentinel and the flag was 0. After submission, the flag was 1 and all four 16-byte rows matched. Omitting only the last five copies in a local control produced exactly 40 wrong pre-wait bytes on each adapter. The existing `aliased_present_planes_preserve_the_host_texture_state` test also completed on both native Windows adapters with four workers selected. I haven't measured game frame times. [Test-only commit on this PR head](https://github.com/steven-seagull27/VIctory/commit/3b148e13ee4d0ff4082b4aa7e88e874f47990af1). To rerun it in PowerShell, choose `0`, `1`, or `4` for the worker count and `0` (hardware) or `1` (WARP) for the adapter, then run: ```powershell $env:VICTORY_DEFER_LISTS = '4' $env:VICTORY_D3D12_WARP = '1' $env:VICTORY_D3D12_DEBUG = '1' cargo test -p victory-gpu --lib --all-features overlapping_copies_across_worker_batches_survive_a_queue_wait -- --ignored --test-threads=1 ```
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 12:30 UTC · original

The check failure on 3b148e1 is not from this change. The one failing test is frame::tests::waits_end_on_ticks_and_count_frames in victory-gpu (frame.rs:231): with 2 ms ticks, a zero-timeout poll right after a wait got S_OK instead of TIMEOUT because the next tick had already passed on the runner. This PR doesn't touch frame.rs, the new commit only adds tests in resource.rs, and the previous head (768dcfa) passed. A re-run should clear it.

**@⁠AurumCarlos** on GitHub · 2026-11-26 12:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7192097400) The check failure on 3b148e1 is not from this change. The one failing test is `frame::tests::waits_end_on_ticks_and_count_frames` in victory-gpu (`frame.rs:231`): with 2 ms ticks, a zero-timeout poll right after a wait got `S_OK` instead of `TIMEOUT` because the next tick had already passed on the runner. This PR doesn't touch `frame.rs`, the new commit only adds tests in `resource.rs`, and the previous head (768dcfa) passed. A re-run should clear it.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3184/head:github-bot/gh-3184'
git switch 'github-bot/gh-3184'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3184'
git switch 'github-bot/gh-3184'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3184'
git switch 'github-bot/gh-3184'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3184'
git switch 'main'
git merge --squash 'github-bot/gh-3184'
git switch 'main'
git merge --ff-only 'github-bot/gh-3184'
git switch 'main'
git merge 'github-bot/gh-3184'
git push origin 'main'
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/Marvisak--VIctory!3184
No description provided.