GPU: loose windows can sit in video memory the CPU writes #2873

Open
Luislariosss wants to merge 3 commits from upstream-pr/2875 into main
Luislariosss commented 2026-11-25 22:54:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-25T22:54:56Z.


Why

The non-local segment - the memory budget the system's memory manager gives the GPU, half of system RAM - is the ceiling every long run dies at on a machine with as much card as RAM: measured on one (16 GB card, 15.2 GB RAM, 7,465 MB budget), the segment was pinned at 103-104% in every long run, and at that ceiling the run died two ways - a host command list's Close() returning E_OUTOFMEMORY, or a staging allocation the runtime could not make feeding the title a value it dereferenced (its own missing check; our failure is the trigger either way). The loose windows are that segment's bulk (878 of them, 3,926 MB, never freed, in the run before this change), while the card's own memory sat half empty.

What

VICTORY_LOOSE_IN_GPU_UPLOAD=1 (off by default) puts each new loose window in a GPU upload heap - video memory the CPU maps write-combined, where the host has one - moving them out of the system-memory segment into the card's own. A card without the heap, or an allocation it refuses, falls back to the system-memory buffer there today. The one cost is the CPU's: reading such a window back (snapshots, copy-backs) is uncached bus traffic, so every read of one is counted and warned of once, and the periodic lines carry the count. Stacked on #2856, whose reuse and window lines this builds on.

Measured (one hardware run, same machine as above)

without with
non-local segment 7,733 of 7,465 MB (104%, pinned) 4,104 of 7,465 MB (55%)
staging buffers that failed to allocate 5,058-11,744 a run 0
committed resources returning E_OUTOFMEMORY 1,393-2,508 a run 0
either fatal failure family every long run died none
in-world samples before the run ended 14-22 48
in-world frame rate 0.22-0.48 fps average 0.48 fps average (1.8 peak)
CPU reads of write-combined windows - 90,861, counted, frame rate held
card's own memory ~50% 97% (its eviction pressure path, designed for exactly that, held the run alive)

The run outlived every same-build run before it and moved its wall to process commit (a 4 MiB host allocation failed at 28 GB of private memory): the shared segment's ceiling is gone from this machine's list of killers.

Verification

  • cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features variant: clean (on the branch this stacks on; the last commit alone adds two clippy-clean files).
  • cargo test --workspace --locked: green.
  • One hardware run with the switch on (the table above) and several without (the comparison column).

No shader bytes, hashes, or program names from any title (asset policy).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5500583086 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-25T22:54:56Z. --- ### Why The non-local segment - the memory budget the system's memory manager gives the GPU, half of system RAM - is the ceiling every long run dies at on a machine with as much card as RAM: measured on one (16 GB card, 15.2 GB RAM, 7,465 MB budget), the segment was pinned at 103-104% in every long run, and at that ceiling the run died two ways - a host command list's Close() returning E_OUTOFMEMORY, or a staging allocation the runtime could not make feeding the title a value it dereferenced (its own missing check; our failure is the trigger either way). The loose windows are that segment's bulk (878 of them, 3,926 MB, never freed, in the run before this change), while the card's own memory sat half empty. ### What `VICTORY_LOOSE_IN_GPU_UPLOAD=1` (off by default) puts each new loose window in a GPU upload heap - video memory the CPU maps write-combined, where the host has one - moving them out of the system-memory segment into the card's own. A card without the heap, or an allocation it refuses, falls back to the system-memory buffer there today. The one cost is the CPU's: reading such a window back (snapshots, copy-backs) is uncached bus traffic, so every read of one is counted and warned of once, and the periodic lines carry the count. Stacked on #2856, whose reuse and window lines this builds on. ### Measured (one hardware run, same machine as above) | | without | with | |---|---|---| | non-local segment | 7,733 of 7,465 MB (104%, pinned) | 4,104 of 7,465 MB (55%) | | staging buffers that failed to allocate | 5,058-11,744 a run | 0 | | committed resources returning E_OUTOFMEMORY | 1,393-2,508 a run | 0 | | either fatal failure family | every long run died | none | | in-world samples before the run ended | 14-22 | 48 | | in-world frame rate | 0.22-0.48 fps average | 0.48 fps average (1.8 peak) | | CPU reads of write-combined windows | - | 90,861, counted, frame rate held | | card's own memory | ~50% | 97% (its eviction pressure path, designed for exactly that, held the run alive) | The run outlived every same-build run before it and moved its wall to process commit (a 4 MiB host allocation failed at 28 GB of private memory): the shared segment's ceiling is gone from this machine's list of killers. ### Verification - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` variant: clean (on the branch this stacks on; the last commit alone adds two clippy-clean files). - `cargo test --workspace --locked`: green. - One hardware run with the switch on (the table above) and several without (the comparison column). No shader bytes, hashes, or program names from any title (asset policy).
AwsAli05 commented 2026-11-25 23:06:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T23:06:49Z.

Review: COMMENTED


I independently checked the allocation request from buffer_in on an RTX 5070 Ti with the D3D12 debug layer requested. Options16 reported GPU upload heaps supported. A 4 MiB committed GPU_UPLOAD buffer created with COMMON and ALLOW_UNORDERED_ACCESS succeeded, and Map returned a non-null pointer.

That confirms the allocation path on this device. The next useful comparison would be a matched world run with the option on and off, recording local and non-local memory along with frame time. CPU readback volume would help explain any frame-time regression, since a count of readbacks treats small and large ranges alike.

AI-assisted review and synthetic D3D12 probe.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066206699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#pullrequestreview-6066206699). Originally posted by [AwsAli05](https://github.com/AwsAli05) on 2026-11-25T23:06:49Z. **Review:** COMMENTED --- I independently checked the allocation request from `buffer_in` on an RTX 5070 Ti with the D3D12 debug layer requested. Options16 reported GPU upload heaps supported. A 4 MiB committed `GPU_UPLOAD` buffer created with `COMMON` and `ALLOW_UNORDERED_ACCESS` succeeded, and `Map` returned a non-null pointer. That confirms the allocation path on this device. The next useful comparison would be a matched world run with the option on and off, recording local and non-local memory along with frame time. CPU readback volume would help explain any frame-time regression, since a count of readbacks treats small and large ranges alike. AI-assisted review and synthetic D3D12 probe.
kotekompotek commented 2026-11-25 23:36:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:36:07Z.

Review: COMMENTED


Sound: opt-in WC-heap residency for loose windows trades uncached readback for freeing system RAM (the documented small-RAM ceiling), the OPTIONS16 probe plus allocation-failure fallback degrade safely to system memory, and WC_READS makes the cost observable. Off by default is the right rollout for a latency-sensitive path. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066488577 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#pullrequestreview-6066488577). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:36:07Z. **Review:** COMMENTED --- Sound: opt-in WC-heap residency for loose windows trades uncached readback for freeing system RAM (the documented small-RAM ceiling), the OPTIONS16 probe plus allocation-failure fallback degrade safely to system memory, and WC_READS makes the cost observable. Off by default is the right rollout for a latency-sensitive path. LGTM.
fuzeofficlal commented 2026-11-25 23:37:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:37:13Z.

Review: COMMENTED


Verified head 25c02cd2 cleanly merged onto origin/main (63bcca43) on Windows 11 x64 across both a GPU Upload Heaps capable adapter (NVIDIA GeForce RTX 5090, GPUUploadHeapSupported == true) and a fallback adapter (D3D12 WARP, GPUUploadHeapSupported == false), with VICTORY_D3D12_DEBUG=1.

Code Review

  • Covering-window reuse in Shadow::loose (map.range(..(start, u64::MAX)).rev()) cleanly reuses any wider loose window (including same-start wider windows) and keeps opt-in risk low via VICTORY_LOOSE_IN_GPU_UPLOAD=1 with automatic fallback to shared_buffer.
  • Minor notes (non-blocking):
    • In Shadow::update_tracked, the busy / sync_before path that reads self.data does not call wc_read(), so write-combined read accounting omits that path while copy_back_page, take_snapshot, and compare_snapshot do count it.
    • The new loose windows: ... meter log line prints unconditionally on Windows even without --features diagnostics (worth confirming that's desired alongside the existing meter output).

Local Verification (VICTORY_D3D12_DEBUG=1)

  • RTX 5090 (default): shadow::tests 10/10 passed.
  • RTX 5090 (VICTORY_LOOSE_IN_GPU_UPLOAD=1, GPU Upload Heaps active): shadow::tests 10/10 passed (including a_wider_loose_window_covers_a_later_smaller_ask and bytes_off_the_runtimes_memory_are_copied_at_each_use, zero debug-layer errors).
  • WARP (VICTORY_LOOSE_IN_GPU_UPLOAD=1, fallback path): shadow::tests 10/10 passed.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.

Looks good.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066498808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#pullrequestreview-6066498808). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:37:13Z. **Review:** COMMENTED --- Verified head `25c02cd2` cleanly merged onto `origin/main` (`63bcca43`) on Windows 11 x64 across both a GPU Upload Heaps capable adapter (**NVIDIA GeForce RTX 5090**, `GPUUploadHeapSupported == true`) and a fallback adapter (**D3D12 WARP**, `GPUUploadHeapSupported == false`), with `VICTORY_D3D12_DEBUG=1`. ### Code Review - Covering-window reuse in `Shadow::loose` (`map.range(..(start, u64::MAX)).rev()`) cleanly reuses any wider loose window (including same-start wider windows) and keeps opt-in risk low via `VICTORY_LOOSE_IN_GPU_UPLOAD=1` with automatic fallback to `shared_buffer`. - **Minor notes (non-blocking)**: - In `Shadow::update_tracked`, the `busy` / `sync_before` path that reads `self.data` does not call `wc_read()`, so write-combined read accounting omits that path while `copy_back_page`, `take_snapshot`, and `compare_snapshot` do count it. - The new `loose windows: ...` meter log line prints unconditionally on Windows even without `--features diagnostics` (worth confirming that's desired alongside the existing meter output). ### Local Verification (`VICTORY_D3D12_DEBUG=1`) - **RTX 5090 (default)**: `shadow::tests` **10/10 passed**. - **RTX 5090 (`VICTORY_LOOSE_IN_GPU_UPLOAD=1`, GPU Upload Heaps active)**: `shadow::tests` **10/10 passed** (including `a_wider_loose_window_covers_a_later_smaller_ask` and `bytes_off_the_runtimes_memory_are_copied_at_each_use`, zero debug-layer errors). - **WARP (`VICTORY_LOOSE_IN_GPU_UPLOAD=1`, fallback path)**: `shadow::tests` **10/10 passed**. - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`191 files ok`): clean. Looks good.
ZeOs360 commented 2026-11-26 05:04:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-26T04:12:21Z.


Matched on/off run of 25c02cd (merged onto main 63bcca4; diagnostics build), on a second machine: RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, 64 GB page file, Windows 11. GPU upload heaps are available here (on=true). One binary, two runs from a cold start into the prologue, unattended, capped at 12 minutes; only VICTORY_LOOSE_IN_GPU_UPLOAD differs. World samples are the periodic lines with at least 500 draws.

=0 =1
run length 482 s 664 s
first E_OUTOFMEMORY 143 s none
no shared buffer lines 75,407 0
non-local segment, peak 8,114 of 7,620 MB (106%) 4,114 of 7,845 MB (52%)
card's own memory, peak 13,306 of 15,594 MB (85%) 15,608 of 15,602 MB (100%)
loose windows at the end 950 (4,329 MB) 1,444 (6,891 MB)
world fps, before 143 s (samples) 0.89 (9) 0.28 (6)
world fps, after 143 s (samples) 0.27 (47) 0.31 (59)
ms/frame on the GPU, before / after 143 s 223 / 1,150 236 / 210
ms/frame copying back, whole run 96 445
snapshots, per sample with any (58 / 79) 349 MB in 60 ms 701 MB in 2,450 ms
marked copy-back, samples with >500 pages (57 / 78) 35 us/page 161 us/page
write-combined reads counted - 91,659
how it ended title breakpoint at image+0x5149aec title breakpoint at image+0x63966f

What I read from it:

  • The non-local wall is gone here too: no allocation failed in the =1 run, while from 143 s on the =0 run failed 75k shared-buffer allocations.
  • It does not make the GPU faster: before =0 hit that wall, GPU time was the same (223 vs 236 ms/frame) and =1 ran at about a third of the frame rate. What it prevents is the collapse past the wall: =0's GPU time went to 1,150 ms/frame and its frame rate fell below =1's.
  • The cost is the CPU reading the windows: snapshots went from about 0.17 to 3.5 ms per MB, and most of those bytes come from one 64 MiB registered buffer that stays in system memory, so per byte of loose window it is slower still. The marked copy-back went from 35 to 161 us per page.
  • The counter undercounts: Shadow::copy_back_marked reads the window too (it compares the window's bytes with title memory, and loose windows are tracked) but does not call wc_read(), so that cost is not in the 91,659.
  • The card's memory held at 100% only through texture eviction past 90% of the budget, which logs nothing: the host textures made from title memory went from about 4 GB to 226 MB by the end. The loose windows grew 2.5 GB more than in =0, whose windows stopped growing when shared buffers began to fail at 143 s. A card with less memory than this one would likely hit its own wall.
  • Both runs ended at a breakpoint in the title. The +0x63966f one also ended a run of a different build (no #2875) after 9 minutes here, so I don't attribute it to this PR.

No game data, shader names or screenshots, per docs/asset-policy.md.

AI-assisted: measured and written with Claude Code (Claude Opus 5.5), cross-checked by Gemini 4 Neon. I ran both runs on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182388439 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#issuecomment-7182388439). Originally posted by [ZeOs360](https://github.com/ZeOs360) on 2026-11-26T04:12:21Z. --- **Matched on/off run of `25c02cd`** (merged onto `main` `63bcca4`; diagnostics build), on a second machine: RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, 64 GB page file, Windows 11. GPU upload heaps are available here (`on=true`). One binary, two runs from a cold start into the prologue, unattended, capped at 12 minutes; only `VICTORY_LOOSE_IN_GPU_UPLOAD` differs. World samples are the periodic lines with at least 500 draws. | | `=0` | `=1` | |---|---|---| | run length | 482 s | 664 s | | first E_OUTOFMEMORY | 143 s | none | | `no shared buffer` lines | 75,407 | 0 | | non-local segment, peak | 8,114 of 7,620 MB (106%) | 4,114 of 7,845 MB (52%) | | card's own memory, peak | 13,306 of 15,594 MB (85%) | 15,608 of 15,602 MB (100%) | | loose windows at the end | 950 (4,329 MB) | 1,444 (6,891 MB) | | world fps, before 143 s (samples) | 0.89 (9) | 0.28 (6) | | world fps, after 143 s (samples) | 0.27 (47) | 0.31 (59) | | ms/frame on the GPU, before / after 143 s | 223 / 1,150 | 236 / 210 | | ms/frame copying back, whole run | 96 | 445 | | snapshots, per sample with any (58 / 79) | 349 MB in 60 ms | 701 MB in 2,450 ms | | marked copy-back, samples with >500 pages (57 / 78) | 35 us/page | 161 us/page | | write-combined reads counted | - | 91,659 | | how it ended | title breakpoint at `image+0x5149aec` | title breakpoint at `image+0x63966f` | What I read from it: - The non-local wall is gone here too: no allocation failed in the `=1` run, while from 143 s on the `=0` run failed 75k shared-buffer allocations. - It does not make the GPU faster: before `=0` hit that wall, GPU time was the same (223 vs 236 ms/frame) and `=1` ran at about a third of the frame rate. What it prevents is the collapse past the wall: `=0`'s GPU time went to 1,150 ms/frame and its frame rate fell below `=1`'s. - The cost is the CPU reading the windows: snapshots went from about 0.17 to 3.5 ms per MB, and most of those bytes come from one 64 MiB registered buffer that stays in system memory, so per byte of loose window it is slower still. The marked copy-back went from 35 to 161 us per page. - The counter undercounts: `Shadow::copy_back_marked` reads the window too (it compares the window's bytes with title memory, and loose windows are tracked) but does not call `wc_read()`, so that cost is not in the 91,659. - The card's memory held at 100% only through texture eviction past 90% of the budget, which logs nothing: the host textures made from title memory went from about 4 GB to 226 MB by the end. The loose windows grew 2.5 GB more than in `=0`, whose windows stopped growing when shared buffers began to fail at 143 s. A card with less memory than this one would likely hit its own wall. - Both runs ended at a breakpoint in the title. The `+0x63966f` one also ended a run of a different build (no #2875) after 9 minutes here, so I don't attribute it to this PR. No game data, shader names or screenshots, per `docs/asset-policy.md`. AI-assisted: measured and written with Claude Code (Claude Opus 5.5), cross-checked by Gemini 4 Neon. I ran both runs on my machine.
Marvisak commented 2026-11-26 05:04:10 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs work. The opt-in VICTORY_LOOSE_IN_GPU_UPLOAD (loose windows in a GPU upload heap, Host::loose_buffer) is reasonable and the hardware tables are encouraging, but the branch still carries both commits of #2856; please rebase once that lands so only the last commit remains. Shadow::copy_back_marked reads the window without calling wc_read(), so the new counter undercounts. The second run also showed the CPU cost (snapshots about 20x slower per MB); please note that trade-off in the README entry.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182607892 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#issuecomment-7182607892). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:27:11Z. --- <!-- victory-triage v1 head=25c02cd2221d4effb942fb0a3dd1856e073a447b verdict=needs-work at=2026-11-26T04:27:04Z --> Automated triage for the maintainers. **Needs work.** The opt-in `VICTORY_LOOSE_IN_GPU_UPLOAD` (loose windows in a GPU upload heap, `Host::loose_buffer`) is reasonable and the hardware tables are encouraging, but the branch still carries both commits of #2856; please rebase once that lands so only the last commit remains. `Shadow::copy_back_marked` reads the window without calling `wc_read()`, so the new counter undercounts. The second run also showed the CPU cost (snapshots about 20x slower per MB); please note that trade-off in the README entry. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
potatoe0100 commented 2026-11-26 15:02:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by potatoe0100 on 2026-11-26T14:21:27Z.


A note for 8 GB cards, from reading 25c02cd2 (and an RTX 4060 8 GB test run: cargo test -p victory-gpu --lib merged onto main 63bcca4 gives 230 passed, with only the 2 known NVIDIA heap-cap failures that main also has).

loose_buffer puts every new loose window in GPU_UPLOAD while the switch is on, and only falls back when the allocation fails. On WDDM that allocation usually succeeds past the local budget, and the memory manager then demotes or evicts other resources. On this 4060 the local budget is 7,537 MB, and the README says the world wants about 10 GB, so moving the 3.9 GB of windows from your run onto the card would make the 8 GB case worse. Your 16 GB card already sat at 97 %. Could new windows go to system memory once local CurrentUsage passes a share of Budget (from QueryVideoMemoryInfo)? Or the README entry could say it is for cards with spare video memory.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194694482 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#issuecomment-7194694482). Originally posted by [potatoe0100](https://github.com/potatoe0100) on 2026-11-26T14:21:27Z. --- A note for 8 GB cards, from reading `25c02cd2` (and an RTX 4060 8 GB test run: `cargo test -p victory-gpu --lib` merged onto `main` `63bcca4` gives 230 passed, with only the 2 known NVIDIA heap-cap failures that `main` also has). `loose_buffer` puts every new loose window in `GPU_UPLOAD` while the switch is on, and only falls back when the allocation fails. On WDDM that allocation usually succeeds past the local budget, and the memory manager then demotes or evicts other resources. On this 4060 the local budget is 7,537 MB, and the README says the world wants about 10 GB, so moving the 3.9 GB of windows from your run onto the card would make the 8 GB case worse. Your 16 GB card already sat at 97 %. Could new windows go to system memory once local `CurrentUsage` passes a share of `Budget` (from `QueryVideoMemoryInfo`)? Or the README entry could say it is for cards with spare video memory. AI-assisted (Claude).
ZeOs360 commented 2026-11-26 18:38:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-26T18:38:31Z.


Follow-up to my matched run above: in gameplay, most of a frame went to the CPU reading loose windows the GPU wrote. Keeping those windows in system memory made frames 5.2× faster.

Same machine (RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11), diagnostics build of main 63bcca4 + 25c02cd + #2644, VICTORY_LOOSE_IN_GPU_UPLOAD=1. My earlier runs all stopped at the title's pool breakpoint from #698 after 8–11 minutes. To get past it I used #2644's VICTORY_STEP_OVER=5149aec,63966f,1fa88e4. Two runs, both to my 30-minute cap:

  • A: the build as above.

  • B: the same build plus a local experiment, which is not in this PR. A loose window is made in system memory (shared_buffer) instead of loose_buffer when the lookup that makes it is for a GPU write. Those lookups are:

    • root UAV descriptors, both root_views and the root descriptors State::bind hands to shaders that use title memory;
    • unordered and writable placed buffer views (buffer_uav, and view_copy when the descriptor is written).

    Every other window still goes to GPU upload memory.

Neither run ran out of memory, and in both I could move the character. The gameplay samples are the periodic lines with at least 4,000 draws, from 16 minutes in for A (77 samples) and from 4 minutes in for B (251 samples). B reached gameplay much earlier, and then played further into heavier scenes (more draws, larger snapshots), so the comparison, if anything, favours A. Medians:

A: #2875 as is B: written windows in system memory
ms/frame 4,816 929
preparing 2,396 367
snapshots 328 MB in 1,752 ms 488 MB in 193 ms
on the GPU 310 252
copying back 2,025 308
"copying back compared", samples where it ran (A 46, B 236) 62 MB in 1,955 ms 51 MB in 96 ms
draws/frame 4,919 6,296

What I read from it:

  • In A, most of the frame is the CPU reading write-combined memory. Snapshots are the largest part of "preparing", and the declared-range comparison makes up most of "copying back". In A's top-6 snapshot breakdown, the largest copy is a 64 MiB registered title buffer, which stays in system memory and is cheap. The others are 4 MiB loose windows, read at a median of about 47 MB/s. The comparison read about 32 MB/s.
  • B does the same work in a fraction of the time. It snapshots more bytes per frame than A, with more draws, in about a ninth of the time. GPU time is about the same in both, so the gain is on the CPU side.
  • Card memory stays within budget, and system memory has room. B's card peaked at 14,527 MB of a 15,033 MB budget, against 15,457 MB of 15,027 MB in A. Heap texture uploads fell from about 460 ms to about 20 ms per frame. The non-local segment peaked at 4,947 MB of 7,845 in B, against 4,285 in A. B ended with 1,219 loose windows (5,516 MB, in both memory kinds), against 1,686 (7,646 MB) in A.
  • B never hit the pool breakpoints. It stepped over 0 of them in 30 minutes, while A first stepped over at about 9 minutes. It's one run, but it fits the reading in #698 that the pools overflow because the opening cutscene runs slowly.

Some reads of these windows are still not counted, because they skip wc_read(). Besides Shadow::copy_back_marked (named above), sync_before and Shadow::copy (through Tracked::refreshed) also read the window's bytes without it.

The experiment does not catch every written window. A window first made by a read and written later, a window served by a wider one that already exists, and memory shaders write at computed addresses all stay in GPU upload memory. B still counted 79,219 write-combined reads, against 204,992 in A. It is a local hack, not a proposal for how to structure it. A thread-local flag around those lookups, read in loose(), is enough to try it. I can share the diff if useful.

No game data, shader names or screenshots, per docs/asset-policy.md.

AI-assisted: measured and written with Claude Code (Claude Opus 5.5), cross-checked by Gemini 4 Neon. I ran both runs on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7200691205 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#issuecomment-7200691205). Originally posted by [ZeOs360](https://github.com/ZeOs360) on 2026-11-26T18:38:31Z. --- **Follow-up to my matched run above: in gameplay, most of a frame went to the CPU reading loose windows the GPU wrote. Keeping those windows in system memory made frames 5.2× faster.** Same machine (RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11), diagnostics build of `main` `63bcca4` + `25c02cd` + #2644, `VICTORY_LOOSE_IN_GPU_UPLOAD=1`. My earlier runs all stopped at the title's pool breakpoint from #698 after 8–11 minutes. To get past it I used #2644's `VICTORY_STEP_OVER=5149aec,63966f,1fa88e4`. Two runs, both to my 30-minute cap: - **A:** the build as above. - **B:** the same build plus a local experiment, which is not in this PR. A loose window is made in system memory (`shared_buffer`) instead of `loose_buffer` when the lookup that makes it is for a GPU write. Those lookups are: - root UAV descriptors, both `root_view`s and the root descriptors `State::bind` hands to shaders that use title memory; - unordered and writable placed buffer views (`buffer_uav`, and `view_copy` when the descriptor is written). Every other window still goes to GPU upload memory. Neither run ran out of memory, and in both I could move the character. The gameplay samples are the periodic lines with at least 4,000 draws, from 16 minutes in for A (77 samples) and from 4 minutes in for B (251 samples). B reached gameplay much earlier, and then played further into heavier scenes (more draws, larger snapshots), so the comparison, if anything, favours A. Medians: | | A: #2875 as is | B: written windows in system memory | |---|---|---| | ms/frame | 4,816 | 929 | | preparing | 2,396 | 367 | | snapshots | 328 MB in 1,752 ms | 488 MB in 193 ms | | on the GPU | 310 | 252 | | copying back | 2,025 | 308 | | "copying back compared", samples where it ran (A 46, B 236) | 62 MB in 1,955 ms | 51 MB in 96 ms | | draws/frame | 4,919 | 6,296 | What I read from it: - **In A, most of the frame is the CPU reading write-combined memory.** Snapshots are the largest part of "preparing", and the declared-range comparison makes up most of "copying back". In A's top-6 snapshot breakdown, the largest copy is a 64 MiB registered title buffer, which stays in system memory and is cheap. The others are 4 MiB loose windows, read at a median of about 47 MB/s. The comparison read about 32 MB/s. - **B does the same work in a fraction of the time.** It snapshots more bytes per frame than A, with more draws, in about a ninth of the time. GPU time is about the same in both, so the gain is on the CPU side. - **Card memory stays within budget, and system memory has room.** B's card peaked at 14,527 MB of a 15,033 MB budget, against 15,457 MB of 15,027 MB in A. Heap texture uploads fell from about 460 ms to about 20 ms per frame. The non-local segment peaked at 4,947 MB of 7,845 in B, against 4,285 in A. B ended with 1,219 loose windows (5,516 MB, in both memory kinds), against 1,686 (7,646 MB) in A. - **B never hit the pool breakpoints.** It stepped over 0 of them in 30 minutes, while A first stepped over at about 9 minutes. It's one run, but it fits the reading in #698 that the pools overflow because the opening cutscene runs slowly. Some reads of these windows are still not counted, because they skip `wc_read()`. Besides `Shadow::copy_back_marked` (named above), `sync_before` and `Shadow::copy` (through `Tracked::refreshed`) also read the window's bytes without it. The experiment does not catch every written window. A window first made by a read and written later, a window served by a wider one that already exists, and memory shaders write at computed addresses all stay in GPU upload memory. B still counted 79,219 write-combined reads, against 204,992 in A. It is a local hack, not a proposal for how to structure it. A thread-local flag around those lookups, read in `loose()`, is enough to try it. I can share the diff if useful. No game data, shader names or screenshots, per `docs/asset-policy.md`. AI-assisted: measured and written with Claude Code (Claude Opus 5.5), cross-checked by Gemini 4 Neon. I ran both runs on my machine.
ZeOs360 commented 2026-11-28 23:31:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-28T23:31:49Z.


On the CPU cost the triage noted (snapshots about 20x slower per MB with VICTORY_LOOSE_IN_GPU_UPLOAD=1): most of it
goes away when the window is read with streaming loads. Two commits on top of this PR's head, if they help:
ZeOs360/VIctory claude/2875-wc-read (4396ea9, 71690a8 on 25c02cd).

The four places that read a window on the CPU (copy_back_page, the snapshot in writing, copy_back_or_not,
copy_back_marked) read it with plain loads, one at a time over the bus, and merge_writeback read and wrote it byte by
byte. The commits:

  • copy the bytes out once with MOVNTDQA (SSE4.1, a plain copy without it) into a buffer;
  • compare and merge there;
  • write a merged piece back to the window in one copy (writes to it are fast);
  • leave copies that are not write-combined as they were (the mapping is used in place);
  • add the wc_read() in copy_back_marked that the triage found missing.

Two other reads of a window still use plain loads and are not counted: sync_before in update_tracked and
Shadow::copy -> refreshed. I left them out; they are smaller, and the same helper would cover them.

One pair of runs, back to back, 10 minutes each from a cold start, VICTORY_LOOSE_IN_GPU_UPLOAD=1 only. Diagnostics
build of main 63bcca4 with this PR merged, RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11:

this PR this PR + the two commits
snapshots of what submissions write 72.5 GB in 339 s (214 MB/s) 243 GB in 108 s (2,250 MB/s)
copy-back compare 1.5 GB in 47 s (31 MB/s) 28.2 GB in 81 s (348 MB/s)
marked pages compared 327,000 in 27 s 1,640,000 in 52 s
median frame in gameplay (of it, preparing) 2,561 ms (1,913) 787 ms (290)
frames in the 10 minutes 2,303 2,702

Totals are the periodic per-frame figures times the frames of each report. The median is over the gameplay reports
(from minute 4, at least 4,000 draws a frame: 56 and 62 of them). The second run got further in the same time, so its
later frames are other scenes and it moved more data; the per-MB rates compare directly.

In a larger tree of mine (this PR with the ray-tracing PRs and local changes), five 10-minute runs without the commits
peaked at 10-29 s a frame. With them, four runs peaked at 2.6-5.7 s; a fifth lost the GPU device (0x887A0004) at 2
minutes 48 s, which I have not traced.

A note for the rebase: this branch is based on f3578e3. Built that way, both runs stopped about 90 and 100 s in, at a
read of 0x30 in resource::alias_source, which 219878a ("a null shader view has no alias source") fixed on main;
merged onto 63bcca4 they ran the full 10 minutes.

Tests:

  • write_combined_reads_copy_every_byte: every alignment, lengths around the 16- and 64-byte steps;
  • partial_refresh_under_marked_range_through_a_write_combined_copy: the existing marked-range test again on a copy
    marked write-combined, through the snapshot, the marked pages' copy-back and the range copy-back;
  • cargo test -p victory-gpu --lib: 231 passed; clippy clean with and without diagnostics.

AI-assisted: written by Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon; the tests and runs were made on my
machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247492040 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2875#issuecomment-7247492040). Originally posted by [ZeOs360](https://github.com/ZeOs360) on 2026-11-28T23:31:49Z. --- On the CPU cost the triage noted (snapshots about 20x slower per MB with `VICTORY_LOOSE_IN_GPU_UPLOAD=1`): most of it goes away when the window is read with streaming loads. Two commits on top of this PR's head, if they help: ZeOs360/VIctory `claude/2875-wc-read` (`4396ea9`, `71690a8` on `25c02cd`). The four places that read a window on the CPU (`copy_back_page`, the snapshot in `writing`, `copy_back_or_not`, `copy_back_marked`) read it with plain loads, one at a time over the bus, and `merge_writeback` read and wrote it byte by byte. The commits: - copy the bytes out once with `MOVNTDQA` (SSE4.1, a plain copy without it) into a buffer; - compare and merge there; - write a merged piece back to the window in one copy (writes to it are fast); - leave copies that are not write-combined as they were (the mapping is used in place); - add the `wc_read()` in `copy_back_marked` that the triage found missing. Two other reads of a window still use plain loads and are not counted: `sync_before` in `update_tracked` and `Shadow::copy` -> `refreshed`. I left them out; they are smaller, and the same helper would cover them. One pair of runs, back to back, 10 minutes each from a cold start, `VICTORY_LOOSE_IN_GPU_UPLOAD=1` only. Diagnostics build of `main` `63bcca4` with this PR merged, RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11: | | this PR | this PR + the two commits | |---|---|---| | snapshots of what submissions write | 72.5 GB in 339 s (214 MB/s) | 243 GB in 108 s (2,250 MB/s) | | copy-back compare | 1.5 GB in 47 s (31 MB/s) | 28.2 GB in 81 s (348 MB/s) | | marked pages compared | 327,000 in 27 s | 1,640,000 in 52 s | | median frame in gameplay (of it, preparing) | 2,561 ms (1,913) | 787 ms (290) | | frames in the 10 minutes | 2,303 | 2,702 | Totals are the periodic per-frame figures times the frames of each report. The median is over the gameplay reports (from minute 4, at least 4,000 draws a frame: 56 and 62 of them). The second run got further in the same time, so its later frames are other scenes and it moved more data; the per-MB rates compare directly. In a larger tree of mine (this PR with the ray-tracing PRs and local changes), five 10-minute runs without the commits peaked at 10-29 s a frame. With them, four runs peaked at 2.6-5.7 s; a fifth lost the GPU device (0x887A0004) at 2 minutes 48 s, which I have not traced. A note for the rebase: this branch is based on `f3578e3`. Built that way, both runs stopped about 90 and 100 s in, at a read of 0x30 in `resource::alias_source`, which `219878a` ("a null shader view has no alias source") fixed on `main`; merged onto `63bcca4` they ran the full 10 minutes. Tests: - `write_combined_reads_copy_every_byte`: every alignment, lengths around the 16- and 64-byte steps; - `partial_refresh_under_marked_range_through_a_write_combined_copy`: the existing marked-range test again on a copy marked write-combined, through the snapshot, the marked pages' copy-back and the range copy-back; - `cargo test -p victory-gpu --lib`: 231 passed; clippy clean with and without `diagnostics`. AI-assisted: written by Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon; the tests and runs were made on my machine.
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/2875:upstream-pr/2875'
git switch 'upstream-pr/2875'

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