fix: count every loose window copy against VICTORY_WINDOW_BUDGET_MB #466

Merged
KainanP merged 2 commits from upstream-pr/466 into main 2026-11-27 12:56:31 +00:00
KainanP commented 2026-11-27 00:11:06 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-27T00:11:06Z.


Fixes #450.

The bug, on the Vice-Tay base (b6d86cf8)

#454 brought the window budget back (VICTORY_WINDOW_BUDGET_MB, in shadow.rs), and the problem FunWithFlagsDev found on the combined base is there too.

  1. Only eligible copies were counted. let_go_idle() filters LOOSE down to the copies that can go (strong count 1, idle for idle_ms and 4 frames, COM references 1). window_victims() then compared the budget with the bytes of those copies alone. Copies held by a list or a slot, or used recently, never counted. In the issue's row (3,072 MiB held plus 1,536 MiB idle against a 2,048 MiB budget), nothing went.
  2. A budget kept more than having none. With no budget, or in the Calm band, every eligible copy goes. In Watch or High, only the eligible bytes over the budget went, so idle copies that the plain sweep would release stayed whenever they fit under the budget.

Both are confirmed against main's window_victims. The issue's row gives [] where all three idle copies should go, and two due copies under a budget they fit in give [] where the sweep without a budget releases both.

The change

  • The budget is compared with the unique bytes of every loose copy, eligible or not (loose_bytes, deduplicated by copy identity like the diagnostic memory()). The oldest eligible copies go until that total fits or none are left. Copies that can't go stay; the target isn't always reachable, and that's accepted.

  • Copies in place (crate::inplace) hold no copy of their own, so they count as 0 bytes (copy_bytes). They're never chosen to meet the budget, but they still go once due.

  • Copies that have been idle for the time the sweep uses without a budget (ram_idle_ms) are marked due and go whatever the budget, so a budget never keeps more than no budget would. The band's shorter idle time (10 s in Watch, 2 s in High) only adds candidates for meeting the budget.

  • A copy that stands under several keys goes under all of them. Before, only one key was removed while its bytes were counted as freed. In practice the strong_count == 1 filter keeps such a copy out of the eligible list, but the accounting now matches what it frees.

  • The let-go tally (second commit, after akimfomin's review): LET_GO[1] stays the title memory the windows let go spanned, in-place windows included. A new LET_GO[2] counts the host-copy bytes they owned (copy_bytes). The memory line and the sweep: trail line print both, so a 4 MiB in-place window plus an 8 MiB copy reads as 12 MiB spanned and 8 MiB owned, not as 12 MiB let go. Test: let_go_tally_keeps_span_and_owned_copy_bytes_apart.

Behaviour changes

  • VICTORY_WINDOW_BUDGET_MB unset, or the Calm band: unchanged.
  • Watch or High with a budget: more idle window copies go, namely the ones over the budget counted against all copies, plus every copy idle for the plain sweep's time. Nothing that is held or recently used goes; the eligibility checks are unchanged. The cost is more window copies made and copied again if the title comes back to them soon.
  • Mapped windows (window_mapped_for, card memory the CPU writes) count as copies, the same as before. Only in-place ones are excluded.

Tests (rule 5)

shadow::window_tests:

  • window_budget_counts_the_copies_that_cannot_go: the issue's row. 3,072 held + 1,536 idle against 2,048 MiB means all idle copies go; against 4,096 MiB only the oldest goes; under the budget nothing goes.
  • window_budget_never_keeps_what_the_sweep_lets_go_without_one: due copies go even when everything fits; over the budget the rest go oldest first.
  • window_budget_passes_over_copies_in_place.
  • The two existing tests run on the new signature. window_budget_counts_one_copy_under_several_keys_once now expects the shared copy under both of its keys ([0, 1] instead of [0]), for the reason above.

The first two encode cases that main's window_victims gets wrong (checked with a throwaway test on main: [] for both).

Run here (RTX 4060 Laptop GPU, Intel UHD iGPU, WARP). Rerun on 1399bff6 (rebased on main b62053fe): 503 passed in 10 of 10 runs on RTX, 2 of 2 on Intel UHD, and 6 of 7 on WARP; the other WARP run had one watch.rs timing failure (what_the_kernel_writes_through_is_not_guarded_for_another_view). The table is from the first head:

result
cargo test -p victory-gpu --lib --release --features diagnostics, RTX 480 passed in 38 of 40 full runs (25 in a row). Two runs had one failure each in a watch.rs write-watch timing test (what_is_put_in_beside_the_guards_is_told_at_every_view, no_write_is_lost_with_port_7), and both passed on rerun. watch.rs isn't touched here; main shows the same kind of failure (nothing_is_guarded_between_our_forgetting_it_and_its_unmapping, 1 in 112 runs)
same, VICTORY_D3D12_ADAPTER=Intel 480 passed
same, VICTORY_D3D12_WARP=1 480 passed
cargo clippy -p victory-gpu --lib --tests no new warnings (the same overlay.rs one as main)
cargo xtask policy 285 files ok
cargo build --release --workspace --exclude anyxboxx-launcher ok

No launcher-visible change: the launcher sets no window budget.

Asking for an A/B

The budget only acts in the Watch and High RAM bands, so the useful run is on a machine that gets there. That means 16 GB of RAM, or an 8 GB card where Windows spills into shared memory. If you have one, please run with VICTORY_WINDOW_BUDGET_MB set (for example 2048) on main and on this branch, and compare private bytes and commit, how many window copies go and are made again (sweep: trail lines, the memory line), and frame times (VICTORY_FRAMETIME_DUMP=1).

Credit: FunWithFlagsDev for the analysis and the test row in #450. Thanks to akimfomin for the review of the memory work on #449.

AI use: code, tests and this description written with Claude Code; tests run locally on RTX, Intel UHD and WARP; nothing was run in game.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5518949736 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/466). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T00:11:06Z. --- Fixes #450. ## The bug, on the Vice-Tay base (`b6d86cf8`) #454 brought the window budget back (`VICTORY_WINDOW_BUDGET_MB`, in `shadow.rs`), and the problem FunWithFlagsDev found on the combined base is there too. 1. **Only eligible copies were counted.** `let_go_idle()` filters `LOOSE` down to the copies that can go (strong count 1, idle for `idle_ms` and 4 frames, COM references 1). `window_victims()` then compared the budget with the bytes of those copies alone. Copies held by a list or a slot, or used recently, never counted. In the issue's row (3,072 MiB held plus 1,536 MiB idle against a 2,048 MiB budget), nothing went. 2. **A budget kept more than having none.** With no budget, or in the Calm band, every eligible copy goes. In Watch or High, only the eligible bytes *over* the budget went, so idle copies that the plain sweep would release stayed whenever they fit under the budget. Both are confirmed against main's `window_victims`. The issue's row gives `[]` where all three idle copies should go, and two due copies under a budget they fit in give `[]` where the sweep without a budget releases both. ## The change - The budget is compared with the **unique bytes of every loose copy**, eligible or not (`loose_bytes`, deduplicated by copy identity like the diagnostic `memory()`). The oldest **eligible** copies go until that total fits or none are left. Copies that can't go stay; the target isn't always reachable, and that's accepted. - Copies **in place** (`crate::inplace`) hold no copy of their own, so they count as 0 bytes (`copy_bytes`). They're never chosen to meet the budget, but they still go once due. - Copies that have been idle for the time the sweep uses without a budget (`ram_idle_ms`) are marked `due` and go whatever the budget, so a budget never keeps more than no budget would. The band's shorter idle time (10 s in Watch, 2 s in High) only adds candidates for meeting the budget. - A copy that stands under several keys goes under all of them. Before, only one key was removed while its bytes were counted as freed. In practice the `strong_count == 1` filter keeps such a copy out of the eligible list, but the accounting now matches what it frees. - **The let-go tally** (second commit, after akimfomin's review): `LET_GO[1]` stays the title memory the windows let go *spanned*, in-place windows included. A new `LET_GO[2]` counts the host-copy bytes they *owned* (`copy_bytes`). The memory line and the `sweep:` trail line print both, so a 4 MiB in-place window plus an 8 MiB copy reads as 12 MiB spanned and 8 MiB owned, not as 12 MiB let go. Test: `let_go_tally_keeps_span_and_owned_copy_bytes_apart`. ### Behaviour changes - `VICTORY_WINDOW_BUDGET_MB` unset, or the Calm band: **unchanged**. - Watch or High with a budget: more idle window copies go, namely the ones over the budget counted against all copies, plus every copy idle for the plain sweep's time. Nothing that is held or recently used goes; the eligibility checks are unchanged. The cost is more window copies made and copied again if the title comes back to them soon. - Mapped windows (`window_mapped_for`, card memory the CPU writes) count as copies, the same as before. Only in-place ones are excluded. ## Tests (rule 5) `shadow::window_tests`: - `window_budget_counts_the_copies_that_cannot_go`: the issue's row. 3,072 held + 1,536 idle against 2,048 MiB means all idle copies go; against 4,096 MiB only the oldest goes; under the budget nothing goes. - `window_budget_never_keeps_what_the_sweep_lets_go_without_one`: due copies go even when everything fits; over the budget the rest go oldest first. - `window_budget_passes_over_copies_in_place`. - The two existing tests run on the new signature. `window_budget_counts_one_copy_under_several_keys_once` now expects the shared copy under both of its keys (`[0, 1]` instead of `[0]`), for the reason above. The first two encode cases that main's `window_victims` gets wrong (checked with a throwaway test on main: `[]` for both). Run here (RTX 4060 Laptop GPU, Intel UHD iGPU, WARP). Rerun on `1399bff6` (rebased on `main` b62053fe): 503 passed in 10 of 10 runs on RTX, 2 of 2 on Intel UHD, and 6 of 7 on WARP; the other WARP run had one `watch.rs` timing failure (`what_the_kernel_writes_through_is_not_guarded_for_another_view`). The table is from the first head: | | result | |---|---| | `cargo test -p victory-gpu --lib --release --features diagnostics`, RTX | 480 passed in 38 of 40 full runs (25 in a row). Two runs had one failure each in a `watch.rs` write-watch timing test (`what_is_put_in_beside_the_guards_is_told_at_every_view`, `no_write_is_lost_with_port_7`), and both passed on rerun. `watch.rs` isn't touched here; main shows the same kind of failure (`nothing_is_guarded_between_our_forgetting_it_and_its_unmapping`, 1 in 112 runs) | | same, `VICTORY_D3D12_ADAPTER=Intel` | 480 passed | | same, `VICTORY_D3D12_WARP=1` | 480 passed | | `cargo clippy -p victory-gpu --lib --tests` | no new warnings (the same `overlay.rs` one as main) | | `cargo xtask policy` | 285 files ok | | `cargo build --release --workspace --exclude anyxboxx-launcher` | ok | No launcher-visible change: the launcher sets no window budget. ## Asking for an A/B The budget only acts in the Watch and High RAM bands, so the useful run is on a machine that gets there. That means 16 GB of RAM, or an 8 GB card where Windows spills into shared memory. If you have one, please run with `VICTORY_WINDOW_BUDGET_MB` set (for example 2048) on `main` and on this branch, and compare private bytes and commit, how many window copies go and are made again (`sweep:` trail lines, the memory line), and frame times (`VICTORY_FRAMETIME_DUMP=1`). Credit: FunWithFlagsDev for the analysis and the test row in #450. Thanks to akimfomin for the review of the memory work on #449. _AI use: code, tests and this description written with Claude Code; tests run locally on RTX, Intel UHD and WARP; nothing was run in game._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
akimfomin commented 2026-11-27 01:17:55 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by akimfomin on 2026-11-27T01:17:55Z.


PortBridge checked this head against the pinned receiving main 5a08a334ef216eff98d2c7d9a9166f94c9ef70ed: Git reports a clean merge, with shadow.rs as the only changed file. For the one-change A/B I kept your merge base b6d86cf8 separate from that later receiving commit.

PortBridge Lab #109 now has your synthetic test and the Watch/High-only acceptance criteria. I shared it with a Vice-Tay reporter who already measured the separate 16 GB RAM throttle. There is no new hardware result yet. If a volunteer submits one, I'll return the aggregates here with their attribution.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7207175840 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/466#issuecomment-7207175840). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-27T01:17:55Z. --- PortBridge checked this head against the pinned receiving main `5a08a334ef216eff98d2c7d9a9166f94c9ef70ed`: Git reports a clean merge, with `shadow.rs` as the only changed file. For the one-change A/B I kept your merge base `b6d86cf8` separate from that later receiving commit. [PortBridge Lab #109](https://github.com/akimfomin/PortBridge/issues/109#issuecomment-7207139616) now has your synthetic test and the Watch/High-only acceptance criteria. I shared it with a Vice-Tay reporter who already measured the separate 16 GB RAM throttle. There is no new hardware result yet. If a volunteer submits one, I'll return the aggregates here with their attribution.
akimfomin commented 2026-11-27 02:25:31 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by akimfomin on 2026-11-27T02:25:31Z.


PortBridge checked one detail that matters for the requested 16 GB A/B. At 02bc88444ba29bfe47d44b2c76537839117ab2aa, the budget correctly charges zero for an in-place window, but the existing sweep adds its full logical length to LET_GO[1] and reports that length before retirement. In a two-window CPU check, letting go of a 4 MiB in-place mapping plus an 8 MiB allocated copy produces a 12 MiB logical tally for 8 MiB of owned copies. Neither number proves that resident RAM fell immediately. This is a measurement caveat, separate from whether the victim selection is correct.

For PortBridge Lab #109, compare process private bytes and free RAM in the same warm interval, alongside re-copy count and frame time. Treat the sweep byte count as window span. If copy-byte telemetry is wanted, reporting the two amounts separately would preserve the existing diagnostic. PortBridge also surfaced VIctory #1250: its double reservation is for GPU upload/staging fallback, a separate accounting rule from #466's held host copies. Budget accounting · Sweep tally and retirement

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7208112675 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/466#issuecomment-7208112675). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-27T02:25:31Z. --- PortBridge checked one detail that matters for the requested 16 GB A/B. At `02bc88444ba29bfe47d44b2c76537839117ab2aa`, the budget correctly charges zero for an in-place window, but the existing sweep adds its full logical length to `LET_GO[1]` and reports that length before retirement. In a two-window CPU check, letting go of a 4 MiB in-place mapping plus an 8 MiB allocated copy produces a 12 MiB logical tally for 8 MiB of owned copies. Neither number proves that resident RAM fell immediately. This is a measurement caveat, separate from whether the victim selection is correct. For [PortBridge Lab #109](https://github.com/akimfomin/PortBridge/issues/109#issuecomment-7207139616), compare process private bytes and free RAM in the same warm interval, alongside re-copy count and frame time. Treat the sweep byte count as window span. If copy-byte telemetry is wanted, reporting the two amounts separately would preserve the existing diagnostic. PortBridge also surfaced [VIctory #1250](https://github.com/fxceless/victory-fork/pull/1250): its double reservation is for GPU upload/staging fallback, a separate accounting rule from #466's held host copies. [Budget accounting](https://github.com/LooperSalty/AnyXboxX/blob/02bc88444ba29bfe47d44b2c76537839117ab2aa/third_party/victory/crates/victory-gpu/src/shadow.rs#L3267-L3277) · [Sweep tally and retirement](https://github.com/LooperSalty/AnyXboxX/blob/02bc88444ba29bfe47d44b2c76537839117ab2aa/third_party/victory/crates/victory-gpu/src/shadow.rs#L3384-L3396)
KainanP commented 2026-11-27 10:45:25 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-27T10:45:25Z.


@akimfomin, thanks, you're right. The budget charged an in-place window nothing, but the sweep's tally still added the window's whole logical length, so your two-window case printed 12 MiB for 8 MiB of owned copies. I took your suggestion and now report the two amounts separately.

New commit 1399bff6 (rebased on main b62053fe; the #450 commit is now 4228f760):

  • LET_GO[1] keeps its meaning, and its doc now says what that is: the title memory the windows let go spanned, in-place windows included.
  • LET_GO[2] is new: of that span, the bytes of host copies the windows owned (copy_bytes; none for a window in place). That's the same rule the budget charges.
  • The memory line prints both: N windows outside buffers X MB spanned (Y MB of owned host copies; a window in place owns none). The sweep's sweep: trail line gives both in KiB.
  • The doc also says that neither number shows resident memory falling at once, since a copy goes through retire. For the A/B, private bytes and free RAM in the same warm interval remain the measure, as you wrote in Lab #109.
  • Test let_go_tally_keeps_span_and_owned_copy_bytes_apart is your case: a 4 MiB in-place window plus an 8 MiB copy gives 2 windows, 12 MiB spanned, 8 MiB owned.

Tests on 1399bff6:

result
cargo test -p victory-gpu --lib --release --features diagnostics, RTX 4060 Laptop 503 passed in 10 of 10 runs
same, VICTORY_D3D12_ADAPTER=Intel 503 passed, 2 of 2
same, VICTORY_D3D12_WARP=1 503 passed in 6 of 7 runs. The other run had one failure in watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view, a write-watch timing test in watch.rs, which this PR doesn't touch (the same kind of intermittent failure as noted in the description)
cargo clippy -p victory-gpu --all-targets --features diagnostics the same single warning as main (manual implementation of .is_multiple_of())
cargo xtask policy 289 files ok
ruff check --select W605,F,E9 clean

Noted on VIctory #1250: its double reservation is GPU upload/staging fallback, a separate rule from the held host copies here, so nothing changes in this PR for it.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7216267623 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/466#issuecomment-7216267623). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T10:45:25Z. --- @akimfomin, thanks, you're right. The budget charged an in-place window nothing, but the sweep's tally still added the window's whole logical length, so your two-window case printed 12 MiB for 8 MiB of owned copies. I took your suggestion and now report the two amounts separately. New commit `1399bff6` (rebased on `main` b62053fe; the #450 commit is now `4228f760`): - `LET_GO[1]` keeps its meaning, and its doc now says what that is: the title memory the windows let go **spanned**, in-place windows included. - `LET_GO[2]` is new: of that span, the bytes of host copies the windows **owned** (`copy_bytes`; none for a window in place). That's the same rule the budget charges. - The memory line prints both: `N windows outside buffers X MB spanned (Y MB of owned host copies; a window in place owns none)`. The sweep's `sweep:` trail line gives both in KiB. - The doc also says that neither number shows resident memory falling at once, since a copy goes through `retire`. For the A/B, private bytes and free RAM in the same warm interval remain the measure, as you wrote in Lab #109. - Test `let_go_tally_keeps_span_and_owned_copy_bytes_apart` is your case: a 4 MiB in-place window plus an 8 MiB copy gives 2 windows, 12 MiB spanned, 8 MiB owned. Tests on `1399bff6`: | | result | |---|---| | `cargo test -p victory-gpu --lib --release --features diagnostics`, RTX 4060 Laptop | 503 passed in 10 of 10 runs | | same, `VICTORY_D3D12_ADAPTER=Intel` | 503 passed, 2 of 2 | | same, `VICTORY_D3D12_WARP=1` | 503 passed in 6 of 7 runs. The other run had one failure in `watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view`, a write-watch timing test in `watch.rs`, which this PR doesn't touch (the same kind of intermittent failure as noted in the description) | | `cargo clippy -p victory-gpu --all-targets --features diagnostics` | the same single warning as `main` (`manual implementation of .is_multiple_of()`) | | `cargo xtask policy` | 289 files ok | | `ruff check --select W605,F,E9` | clean | Noted on VIctory #1250: its double reservation is GPU upload/staging fallback, a separate rule from the held host copies here, so nothing changes in this PR for it. _AI use: Claude Code (Claude Opus 5.5)._
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
LooperSalty/AnyXboxX!466
No description provided.