GPU: back indirect arguments in VRAM, use RwLock for SHADER_HEAPS, and batch copy_back_marks #3320

Open
danielibabet wants to merge 3 commits from upstream-pr/3320 into main
danielibabet commented 2026-11-26 17:42:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T17:42:04Z.


Summary

Three independent CPU/GPU contention and barrier fixes on top of main:

  1. VRAM-backed indirect argument buffers + drop redundant post-clamp UAV barrier (indirect.rs, host.rs)
    • Add Host::uav_buffer (D3D12_HEAP_TYPE_DEFAULT, ALLOW_UNORDERED_ACCESS, COMMON) and back HostList::arguments in VRAM instead of L0 system memory (shared_buffer), avoiding PCIe round-trips for both clamp UAV stores and ExecuteIndirect reads.
    • Remove the redundant uav_barrier() (pResource = None) right before transitioning out from UNORDERED_ACCESS to INDIRECT_ARGUMENT in indirect::bound (the resource transition already synchronizes out, and the next bound call issues the pre-dispatch uav_barrier() for budget).
    • Update indirect::tests::clamped and argument_buffers_move_from_their_current_states to read back out via readback.
  2. Eliminate SHADER_HEAPS mutex contention during descriptor mirroring (descriptor.rs)
    • Switch SHADER_HEAPS from Mutex to RwLock: mirror (title threads), sync_heaps (submission thread), and all read-only queries take .read(), while Drop and create take .write(), so sync_heaps no longer stalls title threads writing descriptors (MirrorWaitUs).
  3. Reuse scratch buffer and batch Tracked::taken in copy_back_marks (shadow.rs)
    • Reuse a single pooled(PAGE) scratch buffer across all marked pages in copy_back_marks instead of heap-allocating and zeroing vec![0u8; n] per 64 KiB page.
    • Batch t.taken(&list) once per Shadow instead of calling VirtualProtect / taking the GUARDS lock page by page.

Verification

  • cargo test -p victory-gpu --locked -- --test-threads=1 --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views: 229 passed; 0 failed; 1 ignored; 2 filtered out
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings
  • cargo run -p xtask --locked -- policy: asset policy: 191 files ok
<!-- greyfinch-sync:Marvisak/VIctory:issue:5514706825 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320). Originally posted by [danielibabet](https://github.com/danielibabet) on 2026-11-26T17:42:04Z. --- ### Summary Three independent CPU/GPU contention and barrier fixes on top of `main`: 1. **VRAM-backed indirect argument buffers + drop redundant post-clamp UAV barrier (`indirect.rs`, `host.rs`)** - Add `Host::uav_buffer` (`D3D12_HEAP_TYPE_DEFAULT`, `ALLOW_UNORDERED_ACCESS`, `COMMON`) and back `HostList::arguments` in VRAM instead of `L0` system memory (`shared_buffer`), avoiding PCIe round-trips for both `clamp` UAV stores and `ExecuteIndirect` reads. - Remove the redundant `uav_barrier()` (`pResource = None`) right before transitioning `out` from `UNORDERED_ACCESS` to `INDIRECT_ARGUMENT` in `indirect::bound` (the resource transition already synchronizes `out`, and the next `bound` call issues the pre-dispatch `uav_barrier()` for `budget`). - Update `indirect::tests::clamped` and `argument_buffers_move_from_their_current_states` to read back `out` via `readback`. 2. **Eliminate `SHADER_HEAPS` mutex contention during descriptor mirroring (`descriptor.rs`)** - Switch `SHADER_HEAPS` from `Mutex` to `RwLock`: `mirror` (title threads), `sync_heaps` (submission thread), and all read-only queries take `.read()`, while `Drop` and `create` take `.write()`, so `sync_heaps` no longer stalls title threads writing descriptors (`MirrorWaitUs`). 3. **Reuse scratch buffer and batch `Tracked::taken` in `copy_back_marks` (`shadow.rs`)** - Reuse a single `pooled(PAGE)` scratch buffer across all marked pages in `copy_back_marks` instead of heap-allocating and zeroing `vec![0u8; n]` per 64 KiB page. - Batch `t.taken(&list)` once per `Shadow` instead of calling `VirtualProtect` / taking the `GUARDS` lock page by page. ### Verification - `cargo test -p victory-gpu --locked -- --test-threads=1 --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views`: `229 passed; 0 failed; 1 ignored; 2 filtered out` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: 0 warnings - `cargo run -p xtask --locked -- policy`: `asset policy: 191 files ok`
Dukestar69 commented 2026-11-26 17:48:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:48:34Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Backing indirect argument buffers in VRAM (with CopyBufferRegion readback in tests), switching SHADER_HEAPS to RwLock, and reusing title_buf + batching t.taken(&synced) in copy_back_marks are clean and sound.
  • cargo test -p victory-gpu --lib indirect:: -- --test-threads=1 (RTX 5090): 6 passed, 0 failed.
  • cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released (RTX 5090): 21 passed, 0 failed.
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1 (RTX 5090): 10 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6078605074 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#pullrequestreview-6078605074). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T17:48:34Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Backing indirect argument buffers in VRAM (with `CopyBufferRegion` readback in tests), switching `SHADER_HEAPS` to `RwLock`, and reusing `title_buf` + batching `t.taken(&synced)` in `copy_back_marks` are clean and sound. - `cargo test -p victory-gpu --lib indirect:: -- --test-threads=1` (RTX 5090): 6 passed, 0 failed. - `cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released` (RTX 5090): 21 passed, 0 failed. - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1` (RTX 5090): 10 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
andrewpozdnakov7-jpg commented 2026-11-26 17:54:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T17:54:10Z.


I checked the DEFAULT-heap argument buffers with the #3307 + #3197 + #2996 composition. They conflict in allocation and in tests that directly mapped the argument buffer. Exact integration 6be1c86 keeps the DEFAULT heap, cached width and shared argument state, and uses a real readback copy for those tests.

Verified app-local Agility 1.620.2/WARP 1.0.22 passed all 15 indirect tests. The mixed test alternates window and single clamps in one list, grows the buffer with 6,000 records, checks the output, and replays transitions back to COMMON. The translated 24-group mesh test and full GPU diagnostics (259 passed, 0 failed, 1 ignored) passed with VICTORY_CLAMP_WINDOW=0 and 1. Strict GPU Clippy passed with default and all features. Asset policy passed. This verifies DEFAULT-heap behavior on WARP. Discrete-GPU placement and PCIe timing still need a hardware run.

@danielibabet the integration is available if #3307 lands first. Please retain its Git author if using the resolution, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7199825808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7199825808). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T17:54:10Z. --- I checked the DEFAULT-heap argument buffers with the [#3307 + #3197 + #2996 composition](https://github.com/Marvisak/VIctory/pull/3307#issuecomment-7199517376). They conflict in allocation and in tests that directly mapped the argument buffer. [Exact integration `6be1c86`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/6be1c86e642c281375cd13908a5f6376dc9b097c) keeps the DEFAULT heap, cached width and shared argument state, and uses a real readback copy for those tests. Verified app-local Agility 1.620.2/WARP 1.0.22 passed all 15 indirect tests. The mixed test alternates window and single clamps in one list, grows the buffer with 6,000 records, checks the output, and replays transitions back to COMMON. The translated 24-group mesh test and full GPU diagnostics (259 passed, 0 failed, 1 ignored) passed with `VICTORY_CLAMP_WINDOW=0` and `1`. Strict GPU Clippy passed with default and all features. Asset policy passed. This verifies DEFAULT-heap behavior on WARP. Discrete-GPU placement and PCIe timing still need a hardware run. @danielibabet the integration is available if #3307 lands first. Please retain its Git author if using the resolution, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted with Codex.
danielibabet commented 2026-11-26 18:20:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T18:20:26Z.


Thanks @andrewpozdnakov7-jpg for verifying against #3307 + #3197 + #2996 and preparing the integration (\6be1c86)! If #3307 lands before #3320, we'll rebase #3320 onto it and make sure to preserve your Git authorship / \Co-authored-by.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7200343489 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7200343489). Originally posted by [danielibabet](https://github.com/danielibabet) on 2026-11-26T18:20:26Z. --- Thanks @andrewpozdnakov7-jpg for verifying against #3307 + #3197 + #2996 and preparing the integration (\6be1c86\)! If #3307 lands before #3320, we'll rebase #3320 onto it and make sure to preserve your Git authorship / \Co-authored-by\.
borosf commented 2026-11-26 19:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T19:03:34Z.


Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head 332461e:

cargo test -p victory-gpu --lib --locked --no-fail-fast -- --test-threads=1
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings
cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings

Result: victory-gpu lib: 2 known baseline failures; the waits_end_on_ticks timing test is flaky under load (this PR does not touch frame.rs).

Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions.

Synthetic tests only; no game data used. Full log kept locally. — borosf

<!-- greyfinch-sync:Marvisak/VIctory:comment:7201150665 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7201150665). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T19:03:34Z. --- Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head `332461e`: ``` cargo test -p victory-gpu --lib --locked --no-fail-fast -- --test-threads=1 cargo clippy -p victory-gpu --all-targets --locked -- -D warnings cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings ``` Result: victory-gpu lib: 2 known baseline failures; the waits_end_on_ticks timing test is flaky under load (this PR does not touch frame.rs). Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions. Synthetic tests only; no game data used. Full log kept locally. — borosf
danielibabet commented 2026-11-26 19:06:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T19:06:12Z.


Thanks @borosf for verifying on Intel Arc B580!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7201197588 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7201197588). Originally posted by [danielibabet](https://github.com/danielibabet) on 2026-11-26T19:06:12Z. --- Thanks @borosf for verifying on Intel Arc B580!
Machad3x commented 2026-11-26 20:44:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-26T20:44:55Z.


A data point on the SHADER_HEAPS RwLock change, measured on one Windows machine (RTX 3080 Ti, Ryzen 7 5700X) running a commercial title:

We tried the same idea on our branch: SHADER_HEAPS as an RwLock, with readers taking a shared lock.

Metric (per measurement window) Mutex RwLock
Wait on view writes 209 ms 0 ms
Heap sync time 43 ms 160 ms
Frame time 309-321 ms 408-445 ms

So we dropped it. Our reading: the contention moved into the per-heap sync instead of disappearing, and frame time got worse overall.

We are now testing per-slot locks (64 striped locks, atomic "made" keys with a busy sentinel) together with the RwLock, and will report numbers.

This work was done with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203032199 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7203032199). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-26T20:44:55Z. --- A data point on the `SHADER_HEAPS` `RwLock` change, measured on one Windows machine (RTX 3080 Ti, Ryzen 7 5700X) running a commercial title: We tried the same idea on our branch: `SHADER_HEAPS` as an `RwLock`, with readers taking a shared lock. | Metric (per measurement window) | Mutex | RwLock | |---|---|---| | Wait on view writes | 209 ms | 0 ms | | Heap sync time | 43 ms | 160 ms | | Frame time | 309-321 ms | 408-445 ms | So we dropped it. Our reading: the contention moved into the per-heap sync instead of disappearing, and frame time got worse overall. We are now testing per-slot locks (64 striped locks, atomic "made" keys with a busy sentinel) together with the `RwLock`, and will report numbers. This work was done with AI assistance (Claude).
danielibabet commented 2026-11-26 21:19:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T21:19:48Z.


Thanks for sharing those real-title numbers @Machad3x! Moving contention into per-heap sync and regressing frame time (309-321 ms -> 408-445 ms) is definitely not worth keeping.

I've reverted the SHADER_HEAPS RwLock change from this PR in 3afe123 (descriptor.rs back to main), leaving just the VRAM-backed indirect argument buffers and batched copy_back_marks (verified with cargo clippy -p victory-gpu --all-targets -- -D warnings and cargo xtask policy — 191 files ok).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203619964 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7203619964). Originally posted by [danielibabet](https://github.com/danielibabet) on 2026-11-26T21:19:48Z. --- Thanks for sharing those real-title numbers @Machad3x! Moving contention into per-heap sync and regressing frame time (309-321 ms -> 408-445 ms) is definitely not worth keeping. I've reverted the `SHADER_HEAPS` `RwLock` change from this PR in `3afe123` (`descriptor.rs` back to `main`), leaving just the VRAM-backed indirect argument buffers and batched `copy_back_marks` (verified with `cargo clippy -p victory-gpu --all-targets -- -D warnings` and `cargo xtask policy` — 191 files ok).
fuzeofficlal commented 2026-11-26 22:00:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:00:32Z.

Review: APPROVED


Clean, focused change now that the SHADER_HEAPS RwLock edit has been reverted in 3afe123b.

Checked both remaining parts:

  • Backing HostList::arguments with a DEFAULT-heap UAV buffer (crates/victory-gpu/src/host.rs:2252, 2715) and dropping the redundant post-clamp uav_barrier() before the UNORDERED_ACCESS -> INDIRECT_ARGUMENT transition (crates/victory-gpu/src/indirect.rs:232-236): bound still opens with [uav_barrier(), COMMON -> UNORDERED_ACCESS] (ordering both earlier title UAV writes and previous budget writes), the explicit transition synchronizes out for ExecuteIndirect and capture::read_indirect, and done() transitions out back to COMMON.
  • Reusing a single pooled(PAGE) scratch buffer and batching t.taken(&list) per Shadow in copy_back_marks (crates/victory-gpu/src/shadow.rs:491, 949-986) matches copy_back_or_not's batching model and keeps title_buf[..n] within PAGE.

Verification on origin/main (63bcca43):

  • cargo xtask policy: ok (191 files ok)
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean
  • cargo test --locked -p victory-gpu --features diagnostics -- indirect:: shadow:: capture:: --test-threads=1 with VICTORY_D3D12_DEBUG=1: 27/27 passed on RTX 5090 and 27/27 passed on WARP
  • Additional live probe running two back-to-back indirect::bound -> capture::read_indirect -> indirect::done cycles on the same DEFAULT-heap arguments buffer under VICTORY_D3D12_DEBUG=1: zero debug layer errors on both RTX 5090 and WARP.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080937851 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#pullrequestreview-6080937851). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:00:32Z. **Review:** APPROVED --- Clean, focused change now that the `SHADER_HEAPS` `RwLock` edit has been reverted in `3afe123b`. Checked both remaining parts: - Backing `HostList::arguments` with a `DEFAULT`-heap UAV buffer (`crates/victory-gpu/src/host.rs:2252, 2715`) and dropping the redundant post-clamp `uav_barrier()` before the `UNORDERED_ACCESS -> INDIRECT_ARGUMENT` transition (`crates/victory-gpu/src/indirect.rs:232-236`): `bound` still opens with `[uav_barrier(), COMMON -> UNORDERED_ACCESS]` (ordering both earlier title UAV writes and previous `budget` writes), the explicit transition synchronizes `out` for `ExecuteIndirect` and `capture::read_indirect`, and `done()` transitions `out` back to `COMMON`. - Reusing a single `pooled(PAGE)` scratch buffer and batching `t.taken(&list)` per `Shadow` in `copy_back_marks` (`crates/victory-gpu/src/shadow.rs:491, 949-986`) matches `copy_back_or_not`'s batching model and keeps `title_buf[..n]` within `PAGE`. Verification on `origin/main` (`63bcca43`): - `cargo xtask policy`: ok (`191 files ok`) - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`): clean - `cargo test --locked -p victory-gpu --features diagnostics -- indirect:: shadow:: capture:: --test-threads=1` with `VICTORY_D3D12_DEBUG=1`: 27/27 passed on RTX 5090 and 27/27 passed on WARP - Additional live probe running two back-to-back `indirect::bound` -> `capture::read_indirect` -> `indirect::done` cycles on the same `DEFAULT`-heap arguments buffer under `VICTORY_D3D12_DEBUG=1`: zero debug layer errors on both RTX 5090 and WARP.
andrewpozdnakov7-jpg commented 2026-11-26 22:02:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T22:02:04Z.


I retested the integration with your 3afe123 lock rollback in 6229e40. In the combined tree, descriptor.rs is byte-for-byte identical to main. The default-heap argument buffer, shared clamp state, mesh flattening and batch copy-back changes are still present.

On app-local WARP, all 15 indirect tests and the 24-group mesh readback passed with VICTORY_CLAMP_WINDOW=0 and 1. The full GPU suite reported 259 passed and one ignored under each setting. Strict GPU Clippy in both configurations and the asset policy check passed. These results verify the buffer and draw behavior on a synthetic workload. The real-title frame times are from @Machad3x's measurement above.

@danielibabet, this updates the previous combined branch if #3307 lands first. Please keep the Git author or use Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if you fold the resolution into another commit.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204292100 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7204292100). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T22:02:04Z. --- I retested the integration with your `3afe123` lock rollback in [`6229e40`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/6229e40812b7921726b86f4d994f2a3ef29a2d35). In the combined tree, `descriptor.rs` is byte-for-byte identical to main. The default-heap argument buffer, shared clamp state, mesh flattening and batch copy-back changes are still present. On app-local WARP, all 15 indirect tests and the 24-group mesh readback passed with `VICTORY_CLAMP_WINDOW=0` and `1`. The full GPU suite reported 259 passed and one ignored under each setting. Strict GPU Clippy in both configurations and the asset policy check passed. These results verify the buffer and draw behavior on a synthetic workload. The real-title frame times are from @Machad3x's measurement above. @danielibabet, this updates the previous combined branch if #3307 lands first. Please keep the Git author or use `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if you fold the resolution into another commit.
neonbyte1 commented 2026-11-27 07:05:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T07:05:52Z.


Measured in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache; base is main plus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart).

Merged here as its current head 3afe123b reduced to the part that still applies on this stack: indirect arguments in VRAM plus the dropped post-clamp UAV barrier (the copy-back third overlaps #3246/#3341, and the RwLock part was withdrawn).

Frame Preparing Copy-back
control 402 ms 81 ms 53 ms
+ this PR (reduced) 409 ms 83 ms 52.7 ms

No gain here. Two test regressions on the GPU (vkd3d-proton, RTX 5090), both passing on the base: indirect::tests::clamped_records_hold_every_word (indirect.rs:838) and indirect::tests::spread_records_split_large_x_and_keep_small_unspread (:1074) fail with Map → 0x80070057. The argument buffer moved to a DEFAULT heap (Host::uav_buffer), and these two tests still map it directly; a third site, read_words(out, …) at :1396 in hoisted_transitions…, has the same pattern but is masked by an unrelated failure. They need the read-back copy the PR already uses elsewhere. Test-only: no production path maps an argument buffer.

AI-assisted (Claude); measured on my machine, no game data shared.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7212139435 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7212139435). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T07:05:52Z. --- Measured in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache; base is `main` plus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart). Merged here as its current head `3afe123b` reduced to the part that still applies on this stack: indirect arguments in VRAM plus the dropped post-clamp UAV barrier (the copy-back third overlaps #3246/#3341, and the `RwLock` part was withdrawn). | | Frame | Preparing | Copy-back | |---|---|---|---| | control | 402 ms | 81 ms | 53 ms | | + this PR (reduced) | 409 ms | 83 ms | 52.7 ms | No gain here. **Two test regressions** on the GPU (vkd3d-proton, RTX 5090), both passing on the base: `indirect::tests::clamped_records_hold_every_word` (`indirect.rs:838`) and `indirect::tests::spread_records_split_large_x_and_keep_small_unspread` (`:1074`) fail with `Map` → `0x80070057`. The argument buffer moved to a DEFAULT heap (`Host::uav_buffer`), and these two tests still map it directly; a third site, `read_words(out, …)` at `:1396` in `hoisted_transitions…`, has the same pattern but is masked by an unrelated failure. They need the read-back copy the PR already uses elsewhere. Test-only: no production path maps an argument buffer. _AI-assisted (Claude); measured on my machine, no game data shared._
andrewpozdnakov7-jpg commented 2026-11-27 08:29:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T08:29:13Z.


Thanks @neonbyte1. I checked the named tests against upstream 63bcca4, #3320 3afe123, #3307 f23c88f and our published combination. None of those trees contains the three test functions from your report. The two readbacks in #3320 itself already use the copy to a readback heap.

Could you link the commit or branch that adds clamped_records_hold_every_word and spread_records_split_large_x_and_keep_small_unspread? The test-source commit is enough. That will give us a base for a test-only follow-up using the existing readback path.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7213588834 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7213588834). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T08:29:13Z. --- Thanks @neonbyte1. I checked the named tests against upstream `63bcca4`, #3320 `3afe123`, #3307 `f23c88f` and our [published combination](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/6229e40812b7921726b86f4d994f2a3ef29a2d35). None of those trees contains the three test functions from your report. The two readbacks in #3320 itself already use the copy to a readback heap. Could you link the commit or branch that adds `clamped_records_hold_every_word` and `spread_records_split_large_x_and_keep_small_unspread`? The test-source commit is enough. That will give us a base for a test-only follow-up using the existing readback path. AI-assisted with Codex.
KainanP commented 2026-11-27 11:53:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T11:53:59Z.


One concern with the copy_back_marks batching at head 3afe123b (read from the code, not run).

A title write can be lost between a page's copy-back and its batched taken.

  • shadow.rs:525-530: when copy_back_marked writes page P back, it holds watch::writing(from, n). Drop for Writing (watch.rs:786-793) calls changed(), which marks P changed and gives it write access back. The page is then only pushed onto synced.
  • shadow.rs:959-971 / :980-985: t.taken(&list) runs only when the loop reaches a page of another Shadow, or at the end. taken (watch.rs:545-560) protects the pages and then does changed.remove(&page) and self.changed.taken(page).

Scenario: P is copied back and left open. The loop goes on to P+1 … P+k of the same Shadow. Each of those costs a 64 KiB read_into, a compare or merge, maybe a write_mapped, and two guard-lock rounds. Meanwhile a title thread writes P. P is open, so there is no fault and the write isn't recorded anywhere. Then taken([P, …]) clears P's changed mark. The host copy keeps the shaders' bytes and never picks up the title's write. Nothing re-marks it later, because the page is guarded again and clean.

main has the same race. There, though, taken runs right after each page's write, so the window is a few microseconds. Here it lasts as long as the rest of that Shadow's marked pages take, which can be thousands of pages per frame on the scenes in #3425.

Possible fixes, keeping most of the gain:

  • Call t.taken(&[page]) right away for pages where written.is_some(), and batch only the pages that were already equal (those were never opened, so there is no window).
  • Or hold the Writing guards until the batched taken, so P stays in busy and a title write is seen through changed. This needs checking against protect's busy filter, which would then skip P.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217603700 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7217603700). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T11:53:59Z. --- One concern with the `copy_back_marks` batching at head `3afe123b` (read from the code, not run). **A title write can be lost between a page's copy-back and its batched `taken`.** - `shadow.rs:525-530`: when `copy_back_marked` writes page P back, it holds `watch::writing(from, n)`. `Drop for Writing` (`watch.rs:786-793`) calls `changed()`, which marks P changed and gives it write access back. The page is then only pushed onto `synced`. - `shadow.rs:959-971` / `:980-985`: `t.taken(&list)` runs only when the loop reaches a page of another `Shadow`, or at the end. `taken` (`watch.rs:545-560`) protects the pages and then does `changed.remove(&page)` and `self.changed.taken(page)`. Scenario: P is copied back and left open. The loop goes on to P+1 … P+k of the same `Shadow`. Each of those costs a 64 KiB `read_into`, a compare or merge, maybe a `write_mapped`, and two guard-lock rounds. Meanwhile a title thread writes P. P is open, so there is no fault and the write isn't recorded anywhere. Then `taken([P, …])` clears P's changed mark. The host copy keeps the shaders' bytes and never picks up the title's write. Nothing re-marks it later, because the page is guarded again and clean. `main` has the same race. There, though, `taken` runs right after each page's write, so the window is a few microseconds. Here it lasts as long as the rest of that `Shadow`'s marked pages take, which can be thousands of pages per frame on the scenes in #3425. Possible fixes, keeping most of the gain: - Call `t.taken(&[page])` right away for pages where `written.is_some()`, and batch only the pages that were already equal (those were never opened, so there is no window). - Or hold the `Writing` guards until the batched `taken`, so P stays in `busy` and a title write is seen through `changed`. This needs checking against `protect`'s `busy` filter, which would then skip P. _AI use: Claude Code (Claude Opus 5.5)._
danielibabet commented 2026-12-01 09:33:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-12-01T09:33:08Z.


Thanks @KainanP — great catch!

Pushed 352164f to pr/perf-copyback-heaps-indirect:

  • copy_back_marks now calls .taken(&[page / PAGE]) immediately whenever written > 0, closing the re-opened-page race window.
  • Only written == 0 (already equal, never re-opened) whole pages are batched per Shadow.
  • Added regression test copy_back_marks_takes_written_pages_immediately (shadow::tests, 10/10 passed).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7306864854 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7306864854). Originally posted by [danielibabet](https://github.com/danielibabet) on 2026-12-01T09:33:08Z. --- Thanks @KainanP — great catch! Pushed 352164f to pr/perf-copyback-heaps-indirect: - copy_back_marks now calls .taken(&[page / PAGE]) immediately whenever written > 0, closing the re-opened-page race window. - Only written == 0 (already equal, never re-opened) whole pages are batched per Shadow. - Added regression test copy_back_marks_takes_written_pages_immediately (shadow::tests, 10/10 passed).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3320:upstream-pr/3320'
git switch 'upstream-pr/3320'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3320'
git switch 'upstream-pr/3320'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3320'
git switch 'upstream-pr/3320'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3320'
git switch 'main'
git merge --squash 'upstream-pr/3320'
git switch 'main'
git merge --ff-only 'upstream-pr/3320'
git switch 'main'
git merge 'upstream-pr/3320'
git push origin 'main'
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!3320
No description provided.