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

Closed
github-bot wants to merge 661 commits from github-bot/gh-414 into main AGit
Owner

@⁠safesearch77 on GitHub · 2026-11-28 13:26 UTC · original
safesearch77:feat/vram-headroom → main · +60158 −5432 · 206 files · 661 commits · closed without merging

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.
**@⁠safesearch77** on GitHub · 2026-11-28 13:26 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/414) `safesearch77:feat/vram-headroom` → `main` · +60158 −5432 · 206 files · 661 commits · closed without merging `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.
VICTORY_VRAM_HEADROOM_MB (off by default, at most 8,192) takes that many
MB off the card's budget in Host::video_memory, so every rule that asks
how much room the card has (the 80 to 97 % shares and the eviction of
vram_keep) works from what is left.

Under Proton the budget is about this process's use plus all of the
card's free memory, and nothing moves this process's memory aside for
the desktop compositor as WDDM does. On an 8 GB RTX 4070 Laptop the title
used 5,823 MB of a 5,823 MB budget and the compositor could not allocate
its next buffer. The variable leaves that room free; 1024 is a starting
value there. The log's video memory line names the headroom when it is
set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 13:37:01 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 11:35 UTC · original

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.

**@⁠TaynanGT** on GitHub · 2026-11-29 11:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7255219164) 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.
Saturating a positive own.Budget to 0 tripped the budget == 0 unknown-budget sentinel in vram_keep_for and vram_idle_for, relaxing eviction to 5,000 ms (IDLE_MS / NORMAL_MS) instead of urgent eviction (1,500 ms / 1,000 ms). Preserve 0 only when the adapter itself reports 0, and clamp positive budgets to at least 1 byte.
Author
Owner

@⁠safesearch77 on GitHub · 2026-11-29 13:20 UTC · original

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).

**@⁠safesearch77** on GitHub · 2026-11-29 13:20 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7256460383) 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`).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 13:24 UTC · original

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** on GitHub · 2026-11-29 13:24 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7256512696) 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.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-30 17:08 UTC · original

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.

**@⁠TaynanGT** on GitHub · 2026-11-30 17:08 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/414#issuecomment-7285780250) `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.
github-bot closed this pull request 2026-11-30 17:14:25 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.