GPU: reuse scratch for marked-page write-back #3604

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3604 into main
andrewpozdnakov7-jpg commented 2026-11-27 20:22:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T20:22:23Z.


Keep a temporary read buffer for the serial marked-page write-back loop. Grow it when the next clipped page interval needs more bytes. Each read uses a slice the size of its interval, and the existing read returns before the merge on failure. Windows read API

Synthetic Windows WARP fixture Pages read Main allocations Patched allocations or growths
Full pages, containing two changed pages plus unchanged controls 31 31 1
Cross-page UAV, clipped to 256 then 512 bytes 2 2 2

The existing assertions for GPU writes, later CPU writes and neighbouring bytes passed. The temporary allocation observer was removed. This measures buffer allocations for the copy-back path discussed in #3590.

The full diagnostics suite passed 246 project GPU tests plus the SDK identity check, with one ignored. Strict GPU Clippy passed with default and all features, and the asset policy check passed.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5532633623 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3604). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T20:22:23Z. --- Keep a temporary read buffer for the serial marked-page write-back loop. Grow it when the next clipped page interval needs more bytes. Each read uses a slice the size of its interval, and the existing read returns before the merge on failure. [Windows read API](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-readprocessmemory) | Synthetic Windows WARP fixture | Pages read | Main allocations | Patched allocations or growths | | --- | ---: | ---: | ---: | | Full pages, containing two changed pages plus unchanged controls | 31 | 31 | 1 | | Cross-page UAV, clipped to 256 then 512 bytes | 2 | 2 | 2 | The existing assertions for GPU writes, later CPU writes and neighbouring bytes passed. The temporary allocation observer was removed. This measures buffer allocations for the copy-back path discussed in #3590. The full diagnostics suite passed 246 project GPU tests plus the SDK identity check, with one ignored. Strict GPU Clippy passed with default and all features, and the asset policy check passed.
andrewpozdnakov7-jpg commented 2026-11-27 20:26:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T20:26:11Z.


Windows CI passed on 63bd11f634f8e4170f17bf45288f41048397ea05. CI job

On app-local Windows WARP the 31-full-page fixture made 31 scratch allocations on the parent and one on this commit. Both revisions passed the GPU-byte and CPU-neighbour assertions. The clipped 256- and 512-byte pages needed two allocations or growths on each revision and passed the cross-page shader readback. This measures allocations in the synthetic write-back path. The next step is maintainer review.

If you cherry-pick or rebase this commit, please retain its Git author. If you fold it into another commit, please include Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7227503684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3604#issuecomment-7227503684). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T20:26:11Z. --- Windows CI passed on `63bd11f634f8e4170f17bf45288f41048397ea05`. [CI job](https://github.com/Marvisak/VIctory/actions/runs/46063188996/job/140722130920) On app-local Windows WARP the 31-full-page fixture made 31 scratch allocations on the parent and one on this commit. Both revisions passed the GPU-byte and CPU-neighbour assertions. The clipped 256- and 512-byte pages needed two allocations or growths on each revision and passed the cross-page shader readback. This measures allocations in the synthetic write-back path. The next step is maintainer review. If you cherry-pick or rebase this commit, please retain its Git author. If you fold it into another commit, please include `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
upipibi commented 2026-11-27 22:54:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-27T22:54:59Z.


Overlap, for whoever picks between them (read from the diffs, not run): three open PRs replace the same per-page vec![0u8; n] in Shadow::copy_back_marked with a reused buffer.

  • #3246 (lhnizdo, opened 26 Nov): a thread-local buffer inside copy_back_marked, plus a test that a partial marked page after a whole one takes none of the first page's bytes (a_partial_marked_page_after_a_whole_one_takes_none_of_its_bytes). neonbyte1 measured it in game: copy-back 47.8 → 44.4 ms (comment).
  • #3320 (danielibabet): the copy-back third of that PR passes a pooled(PAGE) buffer from copy_back_marks, and also batches taken (the lost-write window KainanP reported there).
  • This PR: a Vec owned by copy_back_marks and passed down, grown to the largest clipped interval.

This PR and #3246 change the same lines of copy_back_marked, so whichever goes in first, the other conflicts with it. #3341 (parallel copy-back with one scratch per worker) also replaces this allocation; neonbyte1 measured it 5-7 ms slower on copy-back (comment).

AI-assisted (Claude Code, Claude Opus 5.5 read the four diffs).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7229722375 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3604#issuecomment-7229722375). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-27T22:54:59Z. --- Overlap, for whoever picks between them (read from the diffs, not run): three open PRs replace the same per-page `vec![0u8; n]` in `Shadow::copy_back_marked` with a reused buffer. - #3246 (lhnizdo, opened 26 Nov): a thread-local buffer inside `copy_back_marked`, plus a test that a partial marked page after a whole one takes none of the first page's bytes (`a_partial_marked_page_after_a_whole_one_takes_none_of_its_bytes`). neonbyte1 measured it in game: copy-back 47.8 → 44.4 ms ([comment](https://github.com/Marvisak/VIctory/pull/3246#issuecomment-7212139954)). - #3320 (danielibabet): the copy-back third of that PR passes a `pooled(PAGE)` buffer from `copy_back_marks`, and also batches `taken` (the lost-write window KainanP reported there). - This PR: a `Vec` owned by `copy_back_marks` and passed down, grown to the largest clipped interval. This PR and #3246 change the same lines of `copy_back_marked`, so whichever goes in first, the other conflicts with it. #3341 (parallel copy-back with one scratch per worker) also replaces this allocation; neonbyte1 measured it 5-7 ms slower on copy-back ([comment](https://github.com/Marvisak/VIctory/pull/3341#issuecomment-7212142663)). AI-assisted (Claude Code, Claude Opus 5.5 read the four diffs).
andrewpozdnakov7-jpg commented 2026-11-27 23:07:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T23:07:47Z.


Thanks for checking the overlap. #3246 covers the same allocation and was opened first. It already has a regression for a partial page following a full one and a reported copy-back improvement from 47.8 ms to 44.4 ms on the same RTX 5090 test setup. Independent measurement

These are competing changes to the same loop. #3246 is the tested choice for maintainers to review first. The scratch in #3604 belongs to the submission, which is relevant if the maintainers prefer that lifetime.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7229894309 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3604#issuecomment-7229894309). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T23:07:47Z. --- Thanks for checking the overlap. #3246 covers the same allocation and was opened first. It already has a regression for a partial page following a full one and a reported copy-back improvement from 47.8 ms to 44.4 ms on the same RTX 5090 test setup. [Independent measurement](https://github.com/Marvisak/VIctory/pull/3246#issuecomment-7212139954) These are competing changes to the same loop. #3246 is the tested choice for maintainers to review first. The scratch in #3604 belongs to the submission, which is relevant if the maintainers prefer that lifetime. AI-assisted with OpenAI Codex.
Desamodeth commented 2026-11-27 23:10:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-27T23:10:23Z.


I ran the serial marked-page write-back on main (63bcca43), #3604 (63bd11f6) and #3246 (c2e4507c) at a fixed 256 × 64 KiB per sample. Batching explains where the two scratch lifetimes differ. Median total milliseconds for the same 16 MiB, with half the pages changed on the shader side and a neighbouring CPU byte changed on one in sixteen:

Pages per call main #3604 #3246
1 2.352 2.348 2.111
16 2.313 2.201 2.076
256 2.304 2.067 2.059

With one page per call, #3246 beat main in all 12 paired blocks (median 9.9% less time). #3604 had no consistent gain there. With 256 pages per call, both saved about 10% against main and the difference between them changed sign across blocks. When every marked page contained identical bytes, single-page calls showed the same split (1.096 / 1.099 / 0.997 ms).

Windows, Ryzen 7 9800X3D, software WARP, Rust 1.98.1, diag. Six build orders run twice, eight measured iterations after two warm-ups. Timed only copy_back_marks; checked all bytes in title and shadow memory and all consumed mark bits after every iteration. A pages-per-call histogram from a title trace would show which rows matter most in practice. Reproducible test · frame profile. AI-assisted with Codex Astra 6.2 High.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7229929555 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3604#issuecomment-7229929555). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-27T23:10:23Z. --- I ran the serial marked-page write-back on `main` (`63bcca43`), #3604 (`63bd11f6`) and #3246 (`c2e4507c`) at a fixed 256 × 64 KiB per sample. Batching explains where the two scratch lifetimes differ. Median total milliseconds for the same 16 MiB, with half the pages changed on the shader side and a neighbouring CPU byte changed on one in sixteen: | Pages per call | main | #3604 | #3246 | |---:|---:|---:|---:| | 1 | 2.352 | 2.348 | 2.111 | | 16 | 2.313 | 2.201 | 2.076 | | 256 | 2.304 | 2.067 | 2.059 | With one page per call, #3246 beat main in all 12 paired blocks (median 9.9% less time). #3604 had no consistent gain there. With 256 pages per call, both saved about 10% against main and the difference between them changed sign across blocks. When every marked page contained identical bytes, single-page calls showed the same split (1.096 / 1.099 / 0.997 ms). Windows, Ryzen 7 9800X3D, software WARP, Rust 1.98.1, `diag`. Six build orders run twice, eight measured iterations after two warm-ups. Timed only `copy_back_marks`; checked all bytes in title and shadow memory and all consumed mark bits after every iteration. A pages-per-call histogram from a title trace would show which rows matter most in practice. [Reproducible test](https://github.com/Desamodeth/VIctory/commit/851a18acf4c49c67b4dc2b393f1c704b131d067d) · [frame profile](https://github.com/Marvisak/VIctory/issues/3425). AI-assisted with Codex Astra 6.2 High.
futurepro62 commented 2026-11-29 18:03:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-29T18:03:56Z.


Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 63bd11f (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 866 passed, 0 failed, 10 ignored.
  • No new #[test] functions in the diff.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7260181355 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3604#issuecomment-7260181355). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-29T18:03:56Z. --- Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `63bd11f` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **866 passed, 0 failed, 10 ignored**. - No new `#[test]` functions in the diff. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
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/3604:upstream-pr/3604'
git switch 'upstream-pr/3604'

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