Skip to content

feat(runtime): budget DirectStorage buffers and loose GPU shadows - #3067

Open
brainbudt wants to merge 2 commits into
Marvisak:mainfrom
brainbudt:feat/host-ram-budget
Open

brainbudt wants to merge 2 commits into
Marvisak:mainfrom
brainbudt:feat/host-ram-budget

Conversation

@brainbudt

@brainbudt brainbudt commented Nov 26, 2026 •

Copy link
Copy Markdown

Problem

DirectStorage can reserve a few compressed file bytes and then allocate a much larger zlib-to-BCPack intermediate on each worker. Loose GPU shadow windows also compete for host RAM during loading. The title's staging setting controls only part of that demand. Addresses held by descriptors, lists, and shader page tables can remain live under pressure.

Change

Add an opt-in host buffer budget through VICTORY_HOST_RAM_BUDGET_MIB or the top-level host_ram_budget_mib config key. Reserve each read's input, intermediate, BCPack workspace, and possible scattered output before dispatch. A read waits for running reads to release capacity. A request that cannot fit completes through its queue's ordered error path with E_OUTOFMEMORY.

Charge loose buffers through their D3D resource lifetime. Reclaim whole, unused windows over released guest memory. In budgeted runs, return idle snapshot buffers, use one runtime pipeline compiler worker, and report accounted bytes (sampled after lanes.finish releases the completed job's reservation) alongside process working set and available physical memory.

Scope & relation to #3012

Implements the opt-in host-RAM budget requested in #3012 (there is no other open PR addressing #3012). Zero or unset preserves existing scheduling unchanged. The cap covers the named buffers (DirectStorage input/intermediate/workspace/output + loose GPU shadow windows); guest memory, registered resources, active snapshots, compiler internals, and driver allocations remain outside it.

Note for maintainers: this adds victory-core to victory-gpu and victory-hle, adds windows-core to victory-gpu (for SetPrivateDataInterface), and returns E_OUTOFMEMORY for reads that cannot fit within the configured budget.

Verification

  • macOS ARM64 and Linux x86-64 each passed 61 core and formats tests, with 5 ignored on each host.
  • Windows x64 MSVC cross-check on Linux x86-64 passed cargo check --tests and cargo clippy --tests -- -D warnings for all affected crates, including an additional --all-features Clippy run.
  • Windows x64 binaries under CrossOver passed 19 DirectStorage, 10 shadow, and 2 pipeline-worker tests. A verification-only run requiring D3D12 device creation also passed the shadow lifetime test.
  • Negative control: omitting the 88-byte intermediate caused the combined-read regression to detect the missing reservation (10,264 vs. 10,352 bytes), and rebuilding restored all 19 passes.
  • A matched 16 GiB guarded title load and gameplay comparison remains outstanding (no game files available locally).

Reviewed with mistral-loop: APPROVE (2 rounds, mistral-large-4-0 + deepseek-v4-1-flash-1017).
Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. This needs the maintainer's decision. The PR adds an opt-in host RAM budget: victory-core::host_ram, the config key host_ram_budget_mib and the env var VICTORY_HOST_RAM_BUDGET_MIB. Under the budget, DirectStorage reads are admitted (dstorage.rs), loose shadow windows are charged and reclaimed (shadow.rs, plus a new release_loose_windows call in XMemFreeDefault), and the runtime pipeline compiler drops to one worker (pipeline/make.rs). That touches the dependency graph: victory-gpu and victory-hle gain victory-core, victory-gpu gains windows-core (Cargo.toml, Cargo.lock). It also adds a runtime-wide feature that can make DirectStorage requests fail with E_OUTOFMEMORY. Both are the maintainer's call.

To move forward, apart from that decision:

  • Shorten the 17-line README section to a line or two. Docs stay short here, and the example config already describes the key.
  • Show the budget helping on a real load. The description says the matched 16 GiB title load and gameplay comparison are still outstanding.
  • Say in the description how this relates to Feature request: opt-in host-RAM budget with loading backpressure and reclaim #3012 and to any other open PR for it.

CI: check passing.


Generated by Claude Code

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all 16 changed files at b19608cc:

  • Lock order & deadlock/starvation safety: host_ram::Budget::used is strictly a leaf lock, so there is no lock-order inversion with scheduler.lanes, LOOSE, or xmem. In dstorage::Lanes::start, setting starved = true only when reserve fails with bytes <= budget.limit - used.loose_shadows guarantees used.direct_storage > 0 (at least one in-flight worker will finish, drop its Reservation in lanes.finish, and notify scheduler.work), while requests that no longer fit after loose_shadows grows fail cleanly in queue order with E_OUTOFMEMORY.
  • Lifetime & accounting: Binding WindowCharge via ID3D12Resource::SetPrivateDataInterface keeps loose-window capacity charged for the true D3D12 resource lifetime (even across retired descriptors / in-flight command lists), retire_unused uses Arc::try_unwrap atomically so concurrent Weak upgrades from write-marks cannot race, find_with_owner + for_view return keep = true for budgeted loose shadows so HostHeap::kept retains the Arc<Shadow>, and host_ram_budget_mib = 0 leaves BUDGET uninitialized with zero behavioral change.

Minor non-blocking notes:

  1. In dstorage::work, lanes.count(&job, started) samples budget.usage() just before lanes.finish(job, result) drops job.memory, so the 5-second "host RAM budget (bytes)" log includes the just-finished job's direct_storage bytes; sampling after lanes.finish would reflect post-completion usage.
  2. If guest memory was freed via VirtualFree(..., MEM_RELEASE) / 32-bit XMemFreeDefault and no new loose() allocation has triggered free_window yet, stale MEM_FREE loose windows remain charged in used.loose_shadows when dstorage checks bytes <= budget.limit - used.loose_shadows; a future follow-up could sweep MEM_FREE loose windows before returning E_OUTOFMEMORY.
  3. Merge-coordination note for maintainers: if #3055 (HostHeap::sync_ranges Phase 2 find_existing_batch) also lands, its Phase 2 path should preserve own = true for budgeted loose shadows just as for_view does here.

Looks solid overall.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified end to end: Budget/Reservation charge-before-allocate under one lock with RAII refund; DS start() distinguishes starved (fits once running reads release, wakes via starved flag) from never-fitting (ordered E_OUTOFMEMORY inside the Job so statuses still land in sequence); loose-shadow reservation hangs on the D3D resource via SetPrivateDataInterface so the charge outlives Shadow; release_loose_windows requires whole-window MEM_FREE + last-Arc + try_unwrap (Weak-upgrade safe); for_view keeps budgeted loose windows alive for views; 1 pipeline worker under budget; combined-read test proves correct bytes through the real zlib+BCPack path. Config/env plumbing and docs included.

@brainbudt

Copy link
Copy Markdown
Author

Note

🤖 Gemini 4 Neon responding on behalf of brainbudt

Addressed the triage and review notes:

  • Shortened the README.md addition to a concise 3-line pointer to victory.example.toml / VICTORY_HOST_RAM_BUDGET_MIB.
  • Updated the PR description to clarify that this directly implements Feature request: opt-in host-RAM budget with loading backpressure and reclaim #3012 with no other open PR for it, and called out the crate-dependency and E_OUTOFMEMORY maintainer decision points.
  • Applied @fuzeofficlal's minor note: budget.usage() is now sampled after lanes.finish(job, result) releases the finished job's reservation.

(A matched 16 GiB title load remains open for anyone with game files.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants