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

Closed
AurumCarlos wants to merge 5 commits from upstream-pr/3184 into main
AurumCarlos commented 2026-11-26 11:27:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T11:27:31Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5509187406 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T11:27:31Z. --- 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)
Dukestar69 commented 2026-11-26 12:09:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:09:28Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6073885769 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#pullrequestreview-6073885769). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:09:28Z. **Review:** APPROVED --- 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).
steven-seagull27 commented 2026-11-26 13:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T12:14:44Z.


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
<!-- greyfinch-sync:Marvisak/VIctory:comment:7191753515 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7191753515). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T12:14:44Z. --- 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 ```
AurumCarlos commented 2026-11-26 13:04:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T12:30:47Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7192097400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7192097400). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T12:30:47Z. --- 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.
naorleizer commented 2026-11-26 20:46:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by naorleizer on 2026-11-26T20:46:38Z.


Tried to get the NVIDIA numbers this PR is missing, on an 8 GB card. I couldn't — but the reason is worth recording, because it says where this switch can be measured at all.

Machine: RTX 3070 Ti 8 GB, i9-10850K, 32 GB RAM, driver 621.24, Windows 11, Series X dump 1.0.2.1, clean build of bca3908 (cargo build --release -p victory, rust 1.98.1), VICTORY_RELAY=2 VICTORY_CARD_BUFFERS_MIN_MB=1, VICTORY_DEFER_LISTS unset.

Result: the tree never finishes loading, so there is no deferral number to report. Two attempts, both ended the same way:

  • attempt 1: a single 15,025 ms frame (812.9 MB of copies in it), then DXGI_ERROR_DEVICE_REMOVED on the following submission — exit 0x887A0005.
  • attempt 2, with VICTORY_SHADER_LOOP_LIMIT=256 added: host GPU device removed after a submission of 30 lists, same exit code, ~6 minutes in.

Neither run reached gameplay: draws/frame stayed in single digits (4–13) the whole time, so my 4K-target card never got far enough to exercise list translation on a real frame.

Why this isn't a verdict on the PR: upstream's default path can't survive the first load on 8 GB here — that 15-second frame is the TDR watchdog's cue, and nothing in this tree caps the copy-back the 8 GB forks are built around. The forks (fxceless and friends) carry COPY_PLAIN / BACK_OWN_VIEW / LATE_WAIT etc.; upstream has none of those (VICTORY_* switch audit on bca3908: only SHADER_LOOP_LIMIT and your DEFER_LISTS exist), so "upstream on 8 GB" is an untested configuration in general, not just for this PR.

So for what it's worth from this rig: upstream bca3908 + no deferral = device removed during load on an 8 GB NVIDIA card. Correctness is already covered by steven-seagull27's 5080/WARP fixture runs; what's still missing is a frame-time delta on a tree that can reach the world on this class of card.

Happy to run a paired baseline/DEFER_LISTS=4 comparison — same binary, same cache, six minutes of world each, and I'll quote the PR's own "list calls translated by workers / title threads waited" line — if you point me at a branch where 8 GB survives the load (a fork branch carrying this change would do). I also have the fuller logs if any of the numbers above need drilling into.

AI-assisted (GLM 5.3 via Hermes Agent) on my own machine, private research use; no game files, dumps or title memory shared.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203061618 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7203061618). Originally posted by [naorleizer](https://github.com/naorleizer) on 2026-11-26T20:46:38Z. --- Tried to get the NVIDIA numbers this PR is missing, on an 8 GB card. I couldn't — but the reason is worth recording, because it says where this switch can be measured at all. **Machine**: RTX 3070 Ti 8 GB, i9-10850K, 32 GB RAM, driver 621.24, Windows 11, Series X dump 1.0.2.1, clean build of `bca3908` (`cargo build --release -p victory`, rust 1.98.1), `VICTORY_RELAY=2 VICTORY_CARD_BUFFERS_MIN_MB=1`, `VICTORY_DEFER_LISTS` unset. **Result: the tree never finishes loading, so there is no deferral number to report.** Two attempts, both ended the same way: - attempt 1: a single 15,025 ms frame (812.9 MB of copies in it), then `DXGI_ERROR_DEVICE_REMOVED` on the following submission — exit `0x887A0005`. - attempt 2, with `VICTORY_SHADER_LOOP_LIMIT=256` added: `host GPU device removed after a submission of 30 lists`, same exit code, ~6 minutes in. Neither run reached gameplay: draws/frame stayed in single digits (4–13) the whole time, so my 4K-target card never got far enough to exercise list translation on a real frame. **Why this isn't a verdict on the PR**: upstream's default path can't survive the first load on 8 GB here — that 15-second frame is the TDR watchdog's cue, and nothing in this tree caps the copy-back the 8 GB forks are built around. The forks (fxceless and friends) carry `COPY_PLAIN` / `BACK_OWN_VIEW` / `LATE_WAIT` etc.; upstream has none of those (`VICTORY_*` switch audit on `bca3908`: only `SHADER_LOOP_LIMIT` and your `DEFER_LISTS` exist), so "upstream on 8 GB" is an untested configuration in general, not just for this PR. So for what it's worth from this rig: **upstream `bca3908` + no deferral = device removed during load on an 8 GB NVIDIA card.** Correctness is already covered by steven-seagull27's 5080/WARP fixture runs; what's still missing is a frame-time delta on a tree that can reach the world on this class of card. Happy to run a paired baseline/`DEFER_LISTS=4` comparison — same binary, same cache, six minutes of world each, and I'll quote the PR's own "list calls translated by workers / title threads waited" line — if you point me at a branch where 8 GB survives the load (a fork branch carrying this change would do). I also have the fuller logs if any of the numbers above need drilling into. *AI-assisted (GLM 5.3 via Hermes Agent) on my own machine, private research use; no game files, dumps or title memory shared.*
latentdev commented 2026-11-26 22:26:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by latentdev on 2026-11-26T22:26:29Z.


In-game numbers on an RTX 4090 (Windows): slower with deferral on this stack

Setup:

  • RTX 4090, Ryzen 9 7950X3D, Windows 11, Series X profile, the prologue cutscene.
  • Diagnostics build of main 63bcca4 + this PR at bca3908. It applied cleanly onto our NVIDIA stack: #439, #2121, #2312, #3102, #2821, #2178 and others, plus the views' and title-memory bitmaps in video memory.
  • Two 9-minute runs of the same build, one after the other, each starting from an empty pipeline library. The only difference is VICTORY_DEFER_LISTS.

Medians of the frame-rate lines from 300 s into the world (180 s gives the same picture):

VICTORY_DEFER_LISTS ms/frame preparing GPU copying back
unset 734 130 515 76
4 1069 392 528 75

With 4 workers, the report line reads list calls translated by workers: ~44,000/frame; title threads waited ~55 ms/frame for them. GPU and copy-back are unchanged. The extra time is all in the submissions' preparing, which roughly triples.

I haven't profiled where it goes. My guess is workers contending with the submitting thread on the shared views and copy locks, or ExecuteCommandLists waiting out the workers. Both runs kept written copies in system memory (VICTORY_GPU_UPLOAD_WRITES=0, which this PC needs to stay within memory), so the absolute GPU time is higher than usual. The switch was the only difference between them.

The PR's tests pass here (list::, including list::later::tests).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204679984 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7204679984). Originally posted by [latentdev](https://github.com/latentdev) on 2026-11-26T22:26:29Z. --- ### In-game numbers on an RTX 4090 (Windows): slower with deferral on this stack **Setup:** - RTX 4090, Ryzen 9 7950X3D, Windows 11, Series X profile, the prologue cutscene. - Diagnostics build of `main` 63bcca4 + this PR at bca3908. It applied cleanly onto our NVIDIA stack: #439, #2121, #2312, #3102, #2821, #2178 and others, plus the views' and title-memory bitmaps in video memory. - Two 9-minute runs of the same build, one after the other, each starting from an empty pipeline library. The only difference is `VICTORY_DEFER_LISTS`. Medians of the frame-rate lines from 300 s into the world (180 s gives the same picture): | `VICTORY_DEFER_LISTS` | ms/frame | preparing | GPU | copying back | |---|---:|---:|---:|---:| | unset | 734 | 130 | 515 | 76 | | 4 | 1069 | 392 | 528 | 75 | With 4 workers, the report line reads `list calls translated by workers: ~44,000/frame; title threads waited ~55 ms/frame for them`. GPU and copy-back are unchanged. The extra time is all in the submissions' preparing, which roughly triples. I haven't profiled where it goes. My guess is workers contending with the submitting thread on the shared views and copy locks, or `ExecuteCommandLists` waiting out the workers. Both runs kept written copies in system memory (`VICTORY_GPU_UPLOAD_WRITES=0`, which this PC needs to stay within memory), so the absolute GPU time is higher than usual. The switch was the only difference between them. The PR's tests pass here (`list::`, including `list::later::tests`).
AurumCarlos commented 2026-11-26 22:34:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T22:34:23Z.


Thanks both, these are the first in-game numbers for this switch.

@latentdev that's a clear result: with 4 workers, preparing goes from 130 to 392 ms while GPU and copy-back stay flat, so on your stack the deferral costs more than it saves. ~44,000 calls/frame with ~55 ms of waiting suggests the handoff per batch (queueing, waking a worker, the submitting thread waiting at execute) outweighs the translation it moves off the title threads, possibly made worse by the shared view/copy locks. I'll profile where the extra preparing time goes before asking for anything here. Until then the switch stays off by default, so nothing changes unless VICTORY_DEFER_LISTS is set.

@naorleizer thanks for trying and for writing down why it couldn't be measured on 8 GB; I don't have a fork branch that survives the load on that class of card, so I'd rather not send you on a detour. latentdev's run already answers the main question for now.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204797981 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7204797981). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T22:34:23Z. --- Thanks both, these are the first in-game numbers for this switch. @latentdev that's a clear result: with 4 workers, preparing goes from 130 to 392 ms while GPU and copy-back stay flat, so on your stack the deferral costs more than it saves. ~44,000 calls/frame with ~55 ms of waiting suggests the handoff per batch (queueing, waking a worker, the submitting thread waiting at execute) outweighs the translation it moves off the title threads, possibly made worse by the shared view/copy locks. I'll profile where the extra preparing time goes before asking for anything here. Until then the switch stays off by default, so nothing changes unless `VICTORY_DEFER_LISTS` is set. @naorleizer thanks for trying and for writing down why it couldn't be measured on 8 GB; I don't have a fork branch that survives the load on that class of card, so I'd rather not send you on a detour. latentdev's run already answers the main question for now.
AurumCarlos commented 2026-11-26 23:14:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T23:14:55Z.


@latentdev following up on your 4090 numbers. Reading the code, the likeliest cause is lock contention during preparation: descriptor::sync_heaps holds SHADER_HEAPS for the whole sync and takes VIEWS plus the heap's kept/made per slot, which are the same locks the workers take for every draw-table entry they translate. Four workers doing nothing else make the single preparing thread queue behind them.

eaf2a20 tests that: workers now pause between batches while Host::execute prepares a submission (a RwLock they read per batch and the preparation writes). VICTORY_DEFER_PAUSE=0 turns the pause off, so one build gives both sides. The frame line also reports how long submissions waited for the workers to pause.

If you have time, the same prologue runs as before would answer it:

  • VICTORY_DEFER_LISTS unset
  • VICTORY_DEFER_LISTS=4
  • VICTORY_DEFER_LISTS=4 VICTORY_DEFER_PAUSE=0

Ideally with the diagnostics breakdown of preparing (SyncHeapsUs, UploadsUs, PreludeUs), which would show where the extra time goes even if the pause doesn't fix it. The PR's tests pass with 0/1/4 workers and the pause on or off (Wine + vkd3d-proton on an RX 9070 XT here; no in-game run on my side).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205380108 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7205380108). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T23:14:55Z. --- @latentdev following up on your 4090 numbers. Reading the code, the likeliest cause is lock contention during preparation: `descriptor::sync_heaps` holds `SHADER_HEAPS` for the whole sync and takes `VIEWS` plus the heap's `kept`/`made` per slot, which are the same locks the workers take for every draw-table entry they translate. Four workers doing nothing else make the single preparing thread queue behind them. `eaf2a20` tests that: workers now pause between batches while `Host::execute` prepares a submission (a `RwLock` they read per batch and the preparation writes). `VICTORY_DEFER_PAUSE=0` turns the pause off, so one build gives both sides. The frame line also reports how long submissions waited for the workers to pause. If you have time, the same prologue runs as before would answer it: - `VICTORY_DEFER_LISTS` unset - `VICTORY_DEFER_LISTS=4` - `VICTORY_DEFER_LISTS=4 VICTORY_DEFER_PAUSE=0` Ideally with the diagnostics breakdown of preparing (`SyncHeapsUs`, `UploadsUs`, `PreludeUs`), which would show where the extra time goes even if the pause doesn't fix it. The PR's tests pass with 0/1/4 workers and the pause on or off (Wine + vkd3d-proton on an RX 9070 XT here; no in-game run on my side).
latentdev commented 2026-11-26 23:24:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by latentdev on 2026-11-26T23:24:04Z.


@AurumCarlos thanks, the pause is a good test of that reading. I'll run eaf2a20 with the same three settings and the preparing breakdown (SyncHeapsUs, UploadsUs, PreludeUs).

It won't be right away, though. The title runs close to this PC's memory limit and a first attempt was stopped when memory ran low, so I'll run them when the machine is free for it.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205509434 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7205509434). Originally posted by [latentdev](https://github.com/latentdev) on 2026-11-26T23:24:04Z. --- @AurumCarlos thanks, the pause is a good test of that reading. I'll run eaf2a20 with the same three settings and the preparing breakdown (`SyncHeapsUs`, `UploadsUs`, `PreludeUs`). It won't be right away, though. The title runs close to this PC's memory limit and a first attempt was stopped when memory ran low, so I'll run them when the machine is free for it.
fuzeofficlal commented 2026-11-27 00:28:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:28:28Z.

Review: CHANGES_REQUESTED


Tested eaf2a208efa90f3bda519f5e88bd69ee3298c535 across RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1) with both VICTORY_DEFER_LISTS=0 and VICTORY_DEFER_LISTS=4 (cargo xtask policy, cargo clippy --tests default & --features diagnostics, list::, waiting_for_another_queues_write, and --ignored overlapping_copies_across_worker_batches_survive_a_queue_wait all pass with 0 Debug Layer errors).

The batching and pause design is clean, but three memory-safety issues in crates/victory-gpu/src/list/later.rs need to be fixed before merging:

  1. Cross-thread use-after-free when title COM objects are released before worker translation (crates/victory-gpu/src/list/later.rs:235-253, 320-349, 452-455)

    • Deferred closures capture raw This pointers (pipeline, signature, heaps, dst, src, resource, heap, buffer) without retaining a COM reference, relying on the assumption that "D3D12 has them live until the list has run" (later.rs:236-237).
    • That does not hold for all recorded objects: D3D12 permits titles to release ID3D12PipelineState / ID3D12CommandSignature / ID3D12DescriptorHeap immediately after recording (before Close() or ExecuteCommandLists — see draw.rs:654 and host.rs:1008-1010), and transient resources can also be released before submission.
    • Without deferral, synchronous translation dereferences the title object and clones/keeps the underlying host COM object before the recording method returns. With deferral enabled, calls sit untranslated in log.open / ready, so pipeline::release / signature::release / descriptor::heap_release / resource::release immediately frees Box<T> via object::release_boxed, and the worker then dereferences freed memory when draining the batch.
    • Please retain a COM reference (AddRef on enqueue, Release after the worker runs the call — e.g. via an RAII guard for non-null This arguments) for title objects captured by deferred closures.
  2. TOCTOU use-after-free on concurrent Release of a deferring list (crates/victory-gpu/src/list/later.rs:367-372)

    extern "system" fn release(this: This) -> u32 {
        if !this.is_null() && crate::object::refs(this) == 1 {
            drain(this);
        }
        super::list_release(this)
    }
    
    • If two threads hold references to the same list (refs == 2) and call Release concurrently, both can observe refs(this) == 2, skip drain(this), and let the second super::list_release(this) drop the count 1 -> 0 and free Box<List> while a worker thread is still dereferencing this.
    • drain(this) needs to run only after the atomic refcount decrement reaches 0 (before Box::from_raw frees List), or unconditionally before decrementing.
  3. Undefined behavior in copied() when count == 0 with a non-null misaligned/dangling pointer (crates/victory-gpu/src/list/later.rs:287-293)

    • copied() checks items.is_null() but passes (items, 0) straight to std::slice::from_raw_parts. In D3D12, callers regularly pass count = 0 (e.g., NumRects = 0 on ClearRenderTargetView / ClearDepthStencilView / ClearUnorderedAccessView* or count = 0 on RSSetScissorRects / RSSetViewports) alongside a non-null unaligned or uninitialized pointer.
    • Confirmed live: calling copied::<u32>(1usize as *const u32, 0) aborts immediately in debug builds (0xc0000409) at crates/victory-gpu/src/list/later.rs:292:19:
      unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null...
    • Returning Some(Vec::new()) when count == 0 (after checking items.is_null()) avoids calling from_raw_parts on a zero-length pointer.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081962896 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#pullrequestreview-6081962896). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:28:28Z. **Review:** CHANGES_REQUESTED --- Tested `eaf2a208efa90f3bda519f5e88bd69ee3298c535` across RTX 5090 and WARP (`VICTORY_D3D12_DEBUG=1`) with both `VICTORY_DEFER_LISTS=0` and `VICTORY_DEFER_LISTS=4` (`cargo xtask policy`, `cargo clippy --tests` default & `--features diagnostics`, `list::`, `waiting_for_another_queues_write`, and `--ignored overlapping_copies_across_worker_batches_survive_a_queue_wait` all pass with 0 Debug Layer errors). The batching and pause design is clean, but three memory-safety issues in `crates/victory-gpu/src/list/later.rs` need to be fixed before merging: 1. **Cross-thread use-after-free when title COM objects are released before worker translation (`crates/victory-gpu/src/list/later.rs:235-253, 320-349, 452-455`)** - Deferred closures capture raw `This` pointers (`pipeline`, `signature`, `heaps`, `dst`, `src`, `resource`, `heap`, `buffer`) without retaining a COM reference, relying on the assumption that *"D3D12 has them live until the list has run"* (`later.rs:236-237`). - That does not hold for all recorded objects: D3D12 permits titles to release `ID3D12PipelineState` / `ID3D12CommandSignature` / `ID3D12DescriptorHeap` immediately after recording (before `Close()` or `ExecuteCommandLists` — see `draw.rs:654` and `host.rs:1008-1010`), and transient resources can also be released before submission. - Without deferral, synchronous translation dereferences the title object and clones/keeps the underlying host COM object before the recording method returns. With deferral enabled, calls sit untranslated in `log.open` / `ready`, so `pipeline::release` / `signature::release` / `descriptor::heap_release` / `resource::release` immediately frees `Box<T>` via `object::release_boxed`, and the worker then dereferences freed memory when draining the batch. - Please retain a COM reference (`AddRef` on enqueue, `Release` after the worker runs the call — e.g. via an RAII guard for non-null `This` arguments) for title objects captured by deferred closures. 2. **TOCTOU use-after-free on concurrent `Release` of a deferring list (`crates/victory-gpu/src/list/later.rs:367-372`)** ```rust extern "system" fn release(this: This) -> u32 { if !this.is_null() && crate::object::refs(this) == 1 { drain(this); } super::list_release(this) } ``` - If two threads hold references to the same list (`refs == 2`) and call `Release` concurrently, both can observe `refs(this) == 2`, skip `drain(this)`, and let the second `super::list_release(this)` drop the count `1 -> 0` and free `Box<List>` while a worker thread is still dereferencing `this`. - `drain(this)` needs to run only after the atomic refcount decrement reaches `0` (before `Box::from_raw` frees `List`), or unconditionally before decrementing. 3. **Undefined behavior in `copied()` when `count == 0` with a non-null misaligned/dangling pointer (`crates/victory-gpu/src/list/later.rs:287-293`)** - `copied()` checks `items.is_null()` but passes `(items, 0)` straight to `std::slice::from_raw_parts`. In D3D12, callers regularly pass `count = 0` (e.g., `NumRects = 0` on `ClearRenderTargetView` / `ClearDepthStencilView` / `ClearUnorderedAccessView*` or `count = 0` on `RSSetScissorRects` / `RSSetViewports`) alongside a non-null unaligned or uninitialized pointer. - Confirmed live: calling `copied::<u32>(1usize as *const u32, 0)` aborts immediately in debug builds (`0xc0000409`) at `crates/victory-gpu/src/list/later.rs:292:19`: `unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null...` - Returning `Some(Vec::new())` when `count == 0` (after checking `items.is_null()`) avoids calling `from_raw_parts` on a zero-length pointer.
latentdev commented 2026-11-27 01:47:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by latentdev on 2026-11-27T01:47:55Z.


@AurumCarlos here are eaf2a20's three settings. Setup: RTX 4090, our stack, warm shader cache, VICTORY_GPU_UPLOAD_WRITES=0 (our low-memory setting), the BVH builder held, one ~7.5 min prologue run each. Values are medians of the world's frame lines from 20 s in (20–26 lines per run).

setting ms/frame preparing GPU copy-back heap texture uploads state preludes heap slots the title copied title threads waited for workers submissions waited for the pause
unset 788 145 511 75 22.1 2.0 70.9 – –
VICTORY_DEFER_LISTS=4 1865 653 742 92 33.5 2.5 61.5 669 50.9
VICTORY_DEFER_LISTS=4 VICTORY_DEFER_PAUSE=0 1357 298 625 80 26.6 2.8 58.6 685 0

All in ms/frame. Workers translated about 38,000–44,000 calls/frame.

  • The pause makes it worse here: preparing goes from 298 ms (no pause) to 653 ms (pause), and submissions wait about 51 ms/frame for the workers to pause.
  • The heap sync isn't where the extra time goes: it's 59–71 ms in all three settings, a bit lower with workers than without.
  • The largest number is the title threads waiting for the workers: about 670–690 ms/frame with either setting.

One caveat. Two of the runs (unset, and no pause) had stretches of 10 s frames. In those, the queue's safety valve released a GREATER_EQUAL value wait that hadn't held for 10 s (18 and 12 of them); those frames are left out above. The 4-worker run with the pause had none. A control run on our base without the PR lost the device about 95 s into the world, close to where the unset run's stalls began (88 s). So I don't think the stalls come from the PR, but with one run each I can't rule that out.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207585905 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7207585905). Originally posted by [latentdev](https://github.com/latentdev) on 2026-11-27T01:47:55Z. --- @AurumCarlos here are `eaf2a20`'s three settings. Setup: RTX 4090, our stack, warm shader cache, `VICTORY_GPU_UPLOAD_WRITES=0` (our low-memory setting), the BVH builder held, one ~7.5 min prologue run each. Values are medians of the world's frame lines from 20 s in (20–26 lines per run). | setting | ms/frame | preparing | GPU | copy-back | heap texture uploads | state preludes | heap slots the title copied | title threads waited for workers | submissions waited for the pause | |---|---|---|---|---|---|---|---|---|---| | unset | 788 | 145 | 511 | 75 | 22.1 | 2.0 | 70.9 | – | – | | `VICTORY_DEFER_LISTS=4` | 1865 | 653 | 742 | 92 | 33.5 | 2.5 | 61.5 | 669 | 50.9 | | `VICTORY_DEFER_LISTS=4 VICTORY_DEFER_PAUSE=0` | 1357 | 298 | 625 | 80 | 26.6 | 2.8 | 58.6 | 685 | 0 | All in ms/frame. Workers translated about 38,000–44,000 calls/frame. - The pause makes it worse here: preparing goes from 298 ms (no pause) to 653 ms (pause), and submissions wait about 51 ms/frame for the workers to pause. - The heap sync isn't where the extra time goes: it's 59–71 ms in all three settings, a bit lower with workers than without. - The largest number is the title threads waiting for the workers: about 670–690 ms/frame with either setting. One caveat. Two of the runs (unset, and no pause) had stretches of 10 s frames. In those, the queue's safety valve released a `GREATER_EQUAL` value wait that hadn't held for 10 s (18 and 12 of them); those frames are left out above. The 4-worker run with the pause had none. A control run on our base without the PR lost the device about 95 s into the world, close to where the unset run's stalls began (88 s). So I don't think the stalls come from the PR, but with one run each I can't rule that out.
AurumCarlos commented 2026-11-27 01:50:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-27T01:50:27Z.


@latentdev thanks for the careful runs, that settles it.

  • It rules out my reading: the heap sync stays at 59–71 ms in all three runs, and the pause makes things worse (preparing 298 → 653 ms, 1357 → 1865 ms/frame).
  • The cost is the title threads waiting for the workers, about 670–690 ms/frame with or without the pause. Even without it, VICTORY_DEFER_LISTS=4 is 1357 ms/frame against 788 unset, so translating off the title's threads costs more than it saves on this title.
  • Agreed on the stalls: the run with the pause had none and your base control lost the device around the same point, so they don't look like the PR's.

Unless I find why the workers are that much slower, I'm inclined to withdraw the PR rather than keep an opt-in that only slows things down. I'll confirm tomorrow; the option stays off by default meanwhile.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207619180 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7207619180). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-27T01:50:27Z. --- @latentdev thanks for the careful runs, that settles it. - It rules out my reading: the heap sync stays at 59–71 ms in all three runs, and the pause makes things worse (preparing 298 → 653 ms, 1357 → 1865 ms/frame). - The cost is the title threads waiting for the workers, about 670–690 ms/frame with or without the pause. Even without it, `VICTORY_DEFER_LISTS=4` is 1357 ms/frame against 788 unset, so translating off the title's threads costs more than it saves on this title. - Agreed on the stalls: the run with the pause had none and your base control lost the device around the same point, so they don't look like the PR's. Unless I find why the workers are that much slower, I'm inclined to withdraw the PR rather than keep an opt-in that only slows things down. I'll confirm tomorrow; the option stays off by default meanwhile.
AurumCarlos commented 2026-11-27 07:09:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-27T07:09:09Z.


Closing this: it doesn't pay off. Thanks @latentdev, @naorleizer, @fuzeofficlal and @Dukestar69 for measuring, testing and reviewing it.

What the measurements showed (RTX 4090, prologue): VICTORY_DEFER_LISTS=4 is slower in every run, 1357 ms/frame against 788 with it off, and 1865 with the pause. The heap sync isn't the cost (59–71 ms in all three runs); the title threads waiting for the workers is, about 670–690 ms/frame. My best guess is that translation takes shared locks (heaps, views, tables) on nearly every call, so the workers mostly queue behind each other. Making this pay would first need translation with much less shared locking, which is a different change.

99190ad fixes the three memory-safety issues from the last review, so the branch is a sound starting point if anyone tries this again.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7212192400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3184#issuecomment-7212192400). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-27T07:09:09Z. --- Closing this: it doesn't pay off. Thanks @latentdev, @naorleizer, @fuzeofficlal and @Dukestar69 for measuring, testing and reviewing it. What the measurements showed (RTX 4090, prologue): `VICTORY_DEFER_LISTS=4` is slower in every run, 1357 ms/frame against 788 with it off, and 1865 with the pause. The heap sync isn't the cost (59–71 ms in all three runs); the title threads waiting for the workers is, about 670–690 ms/frame. My best guess is that translation takes shared locks (heaps, views, tables) on nearly every call, so the workers mostly queue behind each other. Making this pay would first need translation with much less shared locking, which is a different change. `99190ad` fixes the three memory-safety issues from the last review, so the branch is a sound starting point if anyone tries this again.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3182
No description provided.