Leave a share of the card's memory to other processes on request #414

Closed
safesearch77 wants to merge 661 commits from upstream-pr/414 into main
safesearch77 commented 2026-11-28 13:26:31 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by safesearch77 on 2026-11-28T13:26:31Z.


VICTORY_VRAM_HEADROOM_MB is off by default and capped at 8,192. It takes that many MB off the card's budget in Host::video_memory(), so every rule that asks how much room the card has works from what is left:

  • the 80–97% shares
  • vram_keep eviction
  • card_limits
  • the staging budget
  • the texture floor
  • the panel

video_memory_groups() still reports the system's figure, and the video-memory log line names the headroom when it is set. (Note: victory-hle's dlss.rs reads NGX parameters.video_memory(), not Host::video_memory().)

Why: under Proton + vkd3d-proton, the reported DXGI budget is roughly this process's use plus all of the card's free memory, and nothing pages this process's memory aside for the desktop compositor the way WDDM does. On an 8 GB RTX 4070 Laptop under Proton, the title used 5,823 MB of a 5,823 MB DXGI budget, leaving 0 MB free on the card; the compositor could not allocate its next buffer (nvidia-drm: Failed to allocate NVKMS memory for GEM object) and the desktop session crashed. 1024 is a starting value for that setup.

What it doesn't cover:

  • Render targets, the tiles pool, and vkd3d-proton's own allocations stay outside these rules.
  • The texture floor can still pull card use past the clamped budget (5,684 / 4,865 MB in steady state), while 701–972 MB of free space remains inside partially-empty 64 MiB texture pool blocks.
  • On Windows the variable does nothing unless it's set.

Verification (Linux, GE-Proton11-14 Wine runner, x86_64-pc-windows-msvc)

  • Scope of the Wine runs: CPU-side tests pass under Wine. GPU-backed tests return early because crate::host::host() is None there. The 3 new tests are pure CPU tests, so they do run.
  • New tests: the_vram_headroom_is_read_in_mib_and_is_off_unless_set, the_card_budget_leaves_the_headroom_free, a_full_card_is_trimmed_below_the_headroom (all pass).
  • cargo +1.98.1 test -p victory-gpu --lib (Wine): 525 passed (default) / 591 passed (--features diagnostics), matching untouched main (fe7c6e5).
  • cargo +1.98.1 clippy -p victory-gpu --all-targets -- -D warnings: clean, default and diagnostics.
  • cargo +1.98.1 xtask policy: asset policy: 322 files ok.
  • Live on/off verification (RTX 4070 Laptop 8 GB, CachyOS, GE-Proton11-14-viewtree, Wayland, vkd3d-proton, Series S, DLSS Quality):
    • Headroom off: DXGI 5,823 / 5,823 MB (0 MB free), compositor hit nvidia-drm: Failed to allocate NVKMS memory for GEM object.
    • VICTORY_VRAM_HEADROOM_MB=1024 (4m 03s): clamped budget 4,865 / 5,889 MB, 5,684 MB DXGI use (205 MB DXGI free), shadow obeyed clamp (40 buffers turned down), nvidia-smi peaked at 7,549 MiB (309 MiB free) and plateaued at 7,527 MiB (331 MiB free), 0 NVKMS errors.
    • FPS is unchanged at matched load: 13.4–16.8 fps at 4,000–6,200 draws/frame with the headroom on, in line with the run without it. The headroom keeps the compositor alive; it is not a speed change.
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5540584402 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/414). Originally posted by [safesearch77](https://github.com/safesearch77) on 2026-11-28T13:26:31Z. --- `VICTORY_VRAM_HEADROOM_MB` is off by default and capped at 8,192. It takes that many MB off the card's budget in `Host::video_memory()`, so every rule that asks how much room the card has works from what is left: - the 80–97% shares - `vram_keep` eviction - `card_limits` - the staging budget - the texture floor - the panel `video_memory_groups()` still reports the system's figure, and the video-memory log line names the headroom when it is set. *(Note: `victory-hle`'s `dlss.rs` reads NGX `parameters.video_memory()`, not `Host::video_memory()`.)* Why: under Proton + `vkd3d-proton`, the reported DXGI budget is roughly this process's use plus all of the card's free memory, and nothing pages this process's memory aside for the desktop compositor the way WDDM does. On an 8 GB RTX 4070 Laptop under Proton, the title used `5,823 MB` of a `5,823 MB` DXGI budget, leaving `0 MB` free on the card; the compositor could not allocate its next buffer (`nvidia-drm: Failed to allocate NVKMS memory for GEM object`) and the desktop session crashed. `1024` is a starting value for that setup. What it doesn't cover: - Render targets, the tiles pool, and `vkd3d-proton`'s own allocations stay outside these rules. - The texture floor can still pull card use past the clamped budget (`5,684 / 4,865 MB` in steady state), while `701–972 MB` of free space remains inside partially-empty 64 MiB texture pool blocks. - On Windows the variable does nothing unless it's set. ### Verification (Linux, `GE-Proton11-14` Wine runner, `x86_64-pc-windows-msvc`) - **Scope of the Wine runs:** CPU-side tests pass under Wine. GPU-backed tests return early because `crate::host::host()` is `None` there. The 3 new tests are pure CPU tests, so they do run. - New tests: `the_vram_headroom_is_read_in_mib_and_is_off_unless_set`, `the_card_budget_leaves_the_headroom_free`, `a_full_card_is_trimmed_below_the_headroom` (all pass). - `cargo +1.98.1 test -p victory-gpu --lib` (Wine): `525 passed` (default) / `591 passed` (`--features diagnostics`), matching untouched `main` (`fe7c6e5`). - `cargo +1.98.1 clippy -p victory-gpu --all-targets -- -D warnings`: clean, default and diagnostics. - `cargo +1.98.1 xtask policy`: `asset policy: 322 files ok`. - **Live on/off verification** (RTX 4070 Laptop 8 GB, CachyOS, `GE-Proton11-14-viewtree`, Wayland, `vkd3d-proton`, Series S, DLSS Quality): - Headroom off: DXGI `5,823 / 5,823 MB` (`0 MB` free), compositor hit `nvidia-drm: Failed to allocate NVKMS memory for GEM object`. - `VICTORY_VRAM_HEADROOM_MB=1024` (`4m 03s`): clamped budget `4,865 / 5,889 MB`, `5,684 MB` DXGI use (`205 MB` DXGI free), `shadow` obeyed clamp (`40` buffers turned down), `nvidia-smi` peaked at `7,549 MiB` (`309 MiB` free) and plateaued at `7,527 MiB` (`331 MiB` free), `0` `NVKMS` errors. - FPS is unchanged at matched load: `13.4–16.8 fps` at `4,000–6,200` draws/frame with the headroom on, in line with the run without it. The headroom keeps the compositor alive; it is not a speed change.
TaynanGT commented 2026-11-29 11:35:47 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:35:47Z.


Thanks for making VRAM headroom explicit and opt-in. Please test the case where the requested reserve approaches or exceeds the reported budget, so no underflow or misleading available-memory value reaches the admission rules.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7255219164 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7255219164). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:35:47Z. --- Thanks for making VRAM headroom explicit and opt-in. Please test the case where the requested reserve approaches or exceeds the reported budget, so no underflow or misleading available-memory value reaches the admission rules.
safesearch77 commented 2026-11-29 13:20:03 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by safesearch77 on 2026-11-29T13:20:03Z.


Addressed the edge case where VICTORY_VRAM_HEADROOM_MB approaches or exceeds own.Budget in budget_less_headroom (noting #414 is already integrated into #439 at 112df69; this follow-up cherry-picks cleanly onto cfd5ebd):

  • Audited all Host::video_memory() callers (host::vram_keep_for, host::vram_idle_for, resource::room, resource::texture_floor_bytes, resource::targets_room_kept, pool::spares_for, shadow.rs, draw::staging_budget_per_frame, copystat.rs, panel.rs).
  • Found that saturating a positive own.Budget all the way to 0 tripped the budget == 0 ("adapter reported no budget") fallback in vram_keep_for and vram_idle_for, relaxing eviction to 5_000 ms (IDLE_MS / NORMAL_MS) instead of urgent 1_500 ms / 1_000 ms eviction.
  • Fixed budget_less_headroom to preserve 0 when own.Budget == 0 and keep a 1-byte floor (budget.saturating_sub(headroom).max(1)) when own.Budget > 0. Direct unit tests verify budget_less_headroom, vram_keep_for, and vram_idle_for stay in urgent eviction without underflow when headroom approaches, equals, or exceeds a positive budget; code inspection across admission callers (resource::room, resource::texture_floor_bytes, shadow.rs) shows they likewise clamp down (log prints 0 MB) without underflow.
  • Added saturated_headroom_keeps_urgent_eviction_active and expanded the_card_budget_leaves_the_headroom_free covering approaching, equal, exceeding, and 0-budget cases.

Verified with Wine victory-gpu --lib -- headroom (4/4 pass), victory-gpu --lib -- vram_ (5/5 pass), clippy --all-targets -- -D warnings, and cargo xtask policy (322 files ok).

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7256460383 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7256460383). Originally posted by [safesearch77](https://github.com/safesearch77) on 2026-11-29T13:20:03Z. --- Addressed the edge case where `VICTORY_VRAM_HEADROOM_MB` approaches or exceeds `own.Budget` in `budget_less_headroom` (noting `#414` is already integrated into `#439` at `112df69`; this follow-up cherry-picks cleanly onto `cfd5ebd`): - Audited all `Host::video_memory()` callers (`host::vram_keep_for`, `host::vram_idle_for`, `resource::room`, `resource::texture_floor_bytes`, `resource::targets_room_kept`, `pool::spares_for`, `shadow.rs`, `draw::staging_budget_per_frame`, `copystat.rs`, `panel.rs`). - Found that saturating a positive `own.Budget` all the way to `0` tripped the `budget == 0` ("adapter reported no budget") fallback in `vram_keep_for` and `vram_idle_for`, relaxing eviction to `5_000 ms` (`IDLE_MS` / `NORMAL_MS`) instead of urgent `1_500 ms` / `1_000 ms` eviction. - Fixed `budget_less_headroom` to preserve `0` when `own.Budget == 0` and keep a `1`-byte floor (`budget.saturating_sub(headroom).max(1)`) when `own.Budget > 0`. Direct unit tests verify `budget_less_headroom`, `vram_keep_for`, and `vram_idle_for` stay in urgent eviction without underflow when `headroom` approaches, equals, or exceeds a positive budget; code inspection across admission callers (`resource::room`, `resource::texture_floor_bytes`, `shadow.rs`) shows they likewise clamp down (log prints `0 MB`) without underflow. - Added `saturated_headroom_keeps_urgent_eviction_active` and expanded `the_card_budget_leaves_the_headroom_free` covering approaching, equal, exceeding, and `0`-budget cases. Verified with Wine `victory-gpu --lib -- headroom` (`4/4` pass), `victory-gpu --lib -- vram_` (`5/5` pass), `clippy --all-targets -- -D warnings`, and `cargo xtask policy` (`322 files ok`).
TaynanGT commented 2026-11-29 13:24:18 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T13:24:18Z.


Thanks for catching the distinction between an exhausted budget and an unreported budget. I integrated the positive-budget floor and its regression cases locally. Keeping the urgent eviction path active when the reserve exceeds the budget is the intended behavior; I still need to validate the tests on Windows.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7256512696 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7256512696). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T13:24:18Z. --- Thanks for catching the distinction between an exhausted budget and an unreported budget. I integrated the positive-budget floor and its regression cases locally. Keeping the urgent eviction path active when the reserve exceeds the budget is the intended behavior; I still need to validate the tests on Windows.
TaynanGT commented 2026-11-30 17:08:24 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:08:24Z.


main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285780250 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7285780250). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:08:24Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

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
TaynanGT/Vice-Tay!414
No description provided.