GPU: shrink default loose shadow window to 1 MiB and reuse containing spans #3437

Open
Luislariosss wants to merge 1 commit from upstream-pr/3437 into main
Luislariosss commented 2026-11-27 01:44:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-27T01:44:18Z.


Summary

Reduces host RAM / private commit spent on loose shadow windows (crates/victory-gpu/src/shadow.rs) in two small, self-contained ways:

  1. 1 MiB default loose window (down from 4 MiB), configurable via VICTORY_LOOSE_WINDOW_KB (power of two in 64..=16384 KiB): cuts rounding slack by up to 4× on scattered small allocations outside buffer objects.
  2. Containment lookup in LOOSE: previously loose() only checked map.get(&(start, len)), so accessing a sub-range of an already-allocated multi-window loose shadow allocated a duplicate overlapping shared_buffer. loose() now reuses any existing loose shadow whose [s_start, s_start + s_len) already covers [address, end).

Tested

  • cargo test -p victory-gpu shadow::: all tests pass, including new loose_window_defaults_to_1_mib_and_reuses_containing_spans.
  • cargo clippy -p victory-gpu --tests: 0 warnings.
  • cargo check --workspace: clean.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5519731798 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3437). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-27T01:44:18Z. --- ## Summary Reduces host RAM / private commit spent on loose shadow windows (`crates/victory-gpu/src/shadow.rs`) in two small, self-contained ways: 1. **1 MiB default loose window (down from 4 MiB)**, configurable via `VICTORY_LOOSE_WINDOW_KB` (power of two in `64..=16384` KiB): cuts rounding slack by up to 4× on scattered small allocations outside buffer objects. 2. **Containment lookup in `LOOSE`**: previously `loose()` only checked `map.get(&(start, len))`, so accessing a sub-range of an already-allocated multi-window loose shadow allocated a duplicate overlapping `shared_buffer`. `loose()` now reuses any existing loose shadow whose `[s_start, s_start + s_len)` already covers `[address, end)`. ## Tested - `cargo test -p victory-gpu shadow::`: all tests pass, including new `loose_window_defaults_to_1_mib_and_reuses_containing_spans`. - `cargo clippy -p victory-gpu --tests`: 0 warnings. - `cargo check --workspace`: clean.
Dukestar69 commented 2026-11-27 01:47:00 +00:00 (Migrated from github.com)

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

Review: APPROVED


LGTM — verified on Windows (RTX 5090):

  • Shrinking the default loose shadow window to 1 MiB (configurable via VICTORY_LOOSE_WINDOW_KB, clamped to power-of-two 64..=16384 KiB) and reusing containing loose spans is clean and avoids duplicate overlapping host buffers
  • cargo test -p victory-gpu --lib shadow:: passed (11/11, including loose_window_defaults_to_1_mib_and_reuses_containing_spans)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6082408995 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3437#pullrequestreview-6082408995). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T01:47:00Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090): - Shrinking the default loose shadow window to 1 MiB (configurable via `VICTORY_LOOSE_WINDOW_KB`, clamped to power-of-two `64..=16384` KiB) and reusing containing loose spans is clean and avoids duplicate overlapping host buffers - `cargo test -p victory-gpu --lib shadow::` passed (11/11, including `loose_window_defaults_to_1_mib_and_reuses_containing_spans`) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-27 02:00:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:00:23Z.

Review: APPROVED


Looks good to me — clean, focused reduction in loose shadow rounding slack with solid span-reuse handling.

Review & Verification Notes

  • crates/victory-gpu/src/shadow.rs:1058-1102: shrinking DEFAULT_LOOSE_WINDOW to 1 MiB and parsing VICTORY_LOOSE_WINDOW_KB with clamping to 64 KiB..=16 MiB and power-of-two rounding keeps loose_span alignment and saturating_sub(start).max(window) sound across all inputs, while find_containing_loose cleanly avoids allocating overlapping host buffers when an existing loose span already covers [address, end).
  • Verified locally on 9d85a52f:
    • cargo xtask policy passes (191 files ok).
    • cargo clippy -p victory-gpu (--lib, --tests, and --features diagnostics --tests, -D warnings) is clean.
    • victory-gpu shadow::tests and draw::tests pass (30/30) on both discrete D3D12 hardware (VICTORY_D3D12_DEBUG=1, VICTORY_D3D12_GBV=1) and WARP (--features diagnostics, VICTORY_D3D12_DEBUG=1, VICTORY_D3D12_WARP=1).
<!-- greyfinch-sync:Marvisak/VIctory:review:6082523528 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3437#pullrequestreview-6082523528). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T02:00:23Z. **Review:** APPROVED --- Looks good to me — clean, focused reduction in loose shadow rounding slack with solid span-reuse handling. ### Review & Verification Notes - `crates/victory-gpu/src/shadow.rs:1058-1102`: shrinking `DEFAULT_LOOSE_WINDOW` to 1 MiB and parsing `VICTORY_LOOSE_WINDOW_KB` with clamping to `64 KiB..=16 MiB` and power-of-two rounding keeps `loose_span` alignment and `saturating_sub(start).max(window)` sound across all inputs, while `find_containing_loose` cleanly avoids allocating overlapping host buffers when an existing loose span already covers `[address, end)`. - Verified locally on `9d85a52f`: - `cargo xtask policy` passes (`191 files ok`). - `cargo clippy -p victory-gpu` (`--lib`, `--tests`, and `--features diagnostics --tests`, `-D warnings`) is clean. - `victory-gpu` `shadow::tests` and `draw::tests` pass (`30/30`) on both discrete D3D12 hardware (`VICTORY_D3D12_DEBUG=1`, `VICTORY_D3D12_GBV=1`) and WARP (`--features diagnostics`, `VICTORY_D3D12_DEBUG=1`, `VICTORY_D3D12_WARP=1`).
borosf commented 2026-11-27 11:33:53 +00:00 (Migrated from github.com)

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


Ran it on Intel Arc B580 with the game to see whether the RAM claim shows up. Short version: the change is fine and its tests pass here, but the 4 MiB → 1 MiB default is below what this tree can measure, and I would not merge it as a performance claim without a counter. The containment-reuse half is worth having on its own.

Setup. 223ac4b9 (= origin/main 63bcca43 + #2958, our measured baseline) with this PR's commit alone on top, --profile diag --features diagnostics, title 1.0.2.1 --console series-x, VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1, 110 s, 20 frame lines, 0 device removals, 0 title crashes.

Tests here: cargo test -p victory-gpu --lib shadow:: --features diagnostics → 11 passed, 0 failed.

Why I cannot confirm the RAM saving. Process commit at the end of a 110 s run, same tree changed only by this PR:

run tree commit
main-alone-4 baseline 16,643 MB
this PR baseline + #3437 16,665 MB
main-alone-1 baseline 16,811 MB
ctl-with-2 baseline + #2703 16,827 MB

The spread between two runs of unmodified baseline is ~170 MB, so a 22 MB difference is not signal. Across all my captures the same-tree spread is ±4 GB, because commit tracks how far the world has streamed (16.6 GB at 110 s, 28.6 GB at 200 s), not a fixed budget.

The one counter that does see the loose path disagrees in direction, which is why I am not claiming either way: at 110 s the baseline reports 3,543 live in 4 shared buffers (41.6 MB held) while this build reports 835 live in 2 shared buffers (20.7 MB held); fewer shared buffers is the containment reuse working, but held / live is 24.8 KB here against 11.8 KB on the baseline, and the asked for/frame differ by 3,000× between the two runs, so the scenes are not comparable.

What would make this mergeable on evidence: one counter for loose-window bytes (allocated and slack), printed in the same block as buffer views off their copy's elements: … (MB held), or a unit test that asserts held bytes fall when a second view of a sub-range is taken — the new test proves the reuse happens, not that it saves anything. With that, the 1 MiB default either shows a number or does not, and the decision stops depending on scene variance.

For the record on the second half: reuse of a containing loose span is a correctness win regardless of the default — duplicate overlapping shared_buffers for the same title memory are a bug worth avoiding, and that part needs nothing from the above.

Synthetic tests only in the tree; the runs are my own dump. Machine: Windows 11 x64, Ryzen 5 5600, 32 GB, Arc B580 12 GB.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217219307 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3437#issuecomment-7217219307). Originally posted by [borosf](https://github.com/borosf) on 2026-11-27T11:33:53Z. --- **Ran it on Intel Arc B580 with the game to see whether the RAM claim shows up.** Short version: the change is fine and its tests pass here, but **the 4 MiB → 1 MiB default is below what this tree can measure**, and I would not merge it as a performance claim without a counter. The containment-reuse half is worth having on its own. **Setup.** `223ac4b9` (= `origin/main` 63bcca43 + #2958, our measured baseline) with this PR's commit alone on top, `--profile diag --features diagnostics`, title 1.0.2.1 `--console series-x`, `VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1`, 110 s, 20 frame lines, 0 device removals, 0 title crashes. **Tests here:** `cargo test -p victory-gpu --lib shadow:: --features diagnostics` → **11 passed, 0 failed**. **Why I cannot confirm the RAM saving.** Process `commit` at the end of a 110 s run, same tree changed only by this PR: | run | tree | commit | |---|---|---| | `main-alone-4` | baseline | 16,643 MB | | **this PR** | baseline + #3437 | **16,665 MB** | | `main-alone-1` | baseline | 16,811 MB | | `ctl-with-2` | baseline + #2703 | 16,827 MB | The spread between two runs of *unmodified* baseline is ~170 MB, so a 22 MB difference is not signal. Across all my captures the same-tree spread is ±4 GB, because `commit` tracks how far the world has streamed (16.6 GB at 110 s, 28.6 GB at 200 s), not a fixed budget. **The one counter that does see the loose path disagrees in direction**, which is why I am not claiming either way: at 110 s the baseline reports `3,543 live in 4 shared buffers (41.6 MB held)` while this build reports `835 live in 2 shared buffers (20.7 MB held)`; fewer shared buffers is the containment reuse working, but `held / live` is 24.8 KB here against 11.8 KB on the baseline, and the `asked for/frame` differ by 3,000× between the two runs, so the scenes are not comparable. **What would make this mergeable on evidence:** one counter for loose-window bytes (allocated and slack), printed in the same block as `buffer views off their copy's elements: … (MB held)`, or a unit test that asserts held bytes fall when a second view of a sub-range is taken — the new test proves the *reuse* happens, not that it saves anything. With that, the 1 MiB default either shows a number or does not, and the decision stops depending on scene variance. For the record on the second half: reuse of a containing loose span is a correctness win regardless of the default — duplicate overlapping `shared_buffer`s for the same title memory are a bug worth avoiding, and that part needs nothing from the above. Synthetic tests only in the tree; the runs are my own dump. Machine: Windows 11 x64, Ryzen 5 5600, 32 GB, Arc B580 12 GB.
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/3437:upstream-pr/3437'
git switch 'upstream-pr/3437'

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