Add opt-in VRAM-first residency and ReBAR pool scaling #522
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!522
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-522"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ayphex on GitHub · 2026-12-04 21:29 UTC · original
Ayphex:exp/vram-first-residency→main· +1764 −111 · 16 files · 2 commits · closed without mergingSummary
Adds an opt-in, configurable VRAM-first residency mode (
VICTORY_VRAM_FIRST=1) for Linux + AMD RADV GPUs with full Resizable BAR (ReBAR / SAM) (whereumloads), while keepingVICTORY_VRAM_FIRST=0(default) bit-for-bit identical to baseline and safely falling back on native Windows, NVIDIA, and WARP.Key Changes
crates/victory-gpu/src/um/vram_policy.rs):VICTORY_VRAM_FIRST,VICTORY_VRAM_BUDGET_MB,VICTORY_VRAM_CLASSES(tiles,textures,rt,bvh,buffersor bitmask),VICTORY_VRAM_REBAR, andVICTORY_VRAM_STATS.VICTORY_TILE_TAINT(sticky|backoff|off, defaultsticky),VICTORY_TILE_QUIESCE_TICKS(default15ticks /3.0 s), andVICTORY_TILE_PROMOTE_CAP_MB(default16MiB/tick).13,808 MiBon a 16 GiB card) and live kernel VRAM + free-VRAM gating to preventVK_ERROR_OUT_OF_DEVICE_MEMORY.[vram-first]telemetry logging and F3 HUD status/counters (gtt_fallbacks,held_back,cpu_read_demotions,cold_wc_demotions, plustile[tainted_tile_ranges, taint_skips, quiescent_promotions, paced_deferrals, peak_tiles_mb, avg_tiles_mb]).residency.rs,safecopy.rs,resource.rs):10 -> 40 -> 160 -> permanentbackoff) prevents repeatedly demotedPhysicalTilespages from churning through retire/promote/fault cycles, and clears cleanly (along withclass,quiesce, andSTRIKES) when a physical tile page is unmapped, remapped, or freed.TEX_SOURCE, GPU-SEENPhysicalTilespages afterVICTORY_TILE_QUIESCE_TICKSquiet ticks, resetting the countdown on CPU touch, hostread_through, and pool-windowwrote_through.VICTORY_TILE_PROMOTE_CAP_MB) caps quiescent tile migrations per 200 ms pass with async kicks to protect 1% lows.PhysicalTilesunderVramClasses::TILES(fixingbuffersleaking into tiles and accurately attributingup_tiles), and avoids double-applyingroom_percent(86%) on top ofvf_budgetinresource::room().lazy.rs,um.rs,xmem.rs,draw.rs,records.rs,texture.rs,memory.rs):XMemVirtualAllocpools as pagedCommittedBuffers(lazy::register_committed) whenVramClasses::BUFFERSis enabled, withVICTORY_VRAM_FIRST=0gated cleanly for exact baseline parity.VICTORY_VRAM_REBAR=0fallback (bypasses direct ReBAR upload pools).vkd3d-protonReBAR Pool Scaling (patches/vkd3d.patch):rebar_budgetfromheap/16(~1 GiB) up tomin(heap/4, 3072 MiB)(bounded byVICTORY_VRAM_BUDGET_MB / 4) whenVICTORY_VRAM_FIRST=1, disables HVV upload whenVICTORY_VRAM_REBAR=0, and matches Rust's boolean env parsing (1|true|on|yes/0|false|off|no, trimmed, case-insensitive).docs/SETTINGS.md,run.conf.default): Documented all switches and Linux + AMD RADV ReBAR scope.Benchmarks (RX 6800 XT 16 GB Full ReBAR, i9-12900K,
VICTORY_BENCH=nort, 3840x2160 FSR4 Quality, 60 s timed window)Back-to-Back Head-to-Head (
origin/mainvs. A1786f5c7vs. A1.504763db)CLASSESmainmaintilesVRAM (Peak / Last-60s)cpu_read_demotionstaint_skipsgtt_fallbacksorigin/main3fe840cbuffers04763dbbuffersbuffers786f5c7buffersall786f5c7allall(default)04763dball9,048quiet up)(In an earlier daytime/twilight run on the same build, A1.5
CLASSES=allpeaked at 26.7 FPS avg / 13.2 1% low / 188.3 W / 681 MB tiles in VRAM, with steady-state in-world demotions at11–43per 10 s.)Verification
git apply --check patches/vkd3d.patchpasses cleanly againstdeps/vkd3dHEAD../build.shcompiles with0warnings /0errors.PKG=victory-gpu ./build.sh test --lib -- um::passes12/12tests under Wine (including sticky taint,10 -> 40 -> 160 -> permanentbackoff, unmap/remap clearing, quiescence reset on CPU touch/write, pacing cap + deferral accounting, class attribution, and knob parsing).cargo xtask policypasses (359 files ok) and branch merges cleanly onto currentorigin/main(b581f7e).@Kal0s-design on GitHub · 2026-12-04 22:07 UTC · original
Checked
786f5c7on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). It merges cleanly onto current main.In short, on native D3D12 the VRAM-first path is almost entirely inert, because everything it steers lives behind
um, andum::loadonly takes an AMD adapter with the RADV alias extension (um.rs:592, thevkMapMemory2probes after it). On NVIDIA and WARPum::get()is None, sopool/pool_classifiedreturn None,init_budget(only caller um.rs:517) never runs andactive_budget_bytes()stays 0. I confirmed that with a throwaway test withVICTORY_VRAM_FIRST=1: both pool calls return None, budget 0, snapshot total/budget 0. So the committed-pool promotion test I wanted to write isn't possible here, there are no pools to promote.Tests
cargo test -p victory-gpu --lib(env unset), PR vs main: same 5 failures on both (the twoindirect::host_list_*, the twopipeline::hostlibrary loads, the flakywatchone), nothing new. Main shows a couple more passes only because the PR branch is a few commits behind (main's newer framegen tests).VICTORY_VRAM_FIRST=1 VICTORY_VRAM_STATS=1: identical result. The PR's own 6 tests (um::vram_policy::tests,um::residency::tests) pass natively too.victory-hle --libwithVICTORY_NATIVE_INPUT=0: 162 passed, same as main.victory-gpulib with--features diagnostics,VICTORY_D3D12_DEBUG=1andVICTORY_VRAM_FIRST=1 VICTORY_VRAM_REBAR=0 VICTORY_VRAM_STATS=1, on the card and on WARP, PR vs main: same failures (on WARP plus the usualdescriptor::hostviews test), nothing new and no debug-layer errors from the new path.Native answers to the ReBAR/budget questions
usage_full(um.rs:849), not DXGI. Nothing in the PR callsQueryVideoMemoryInfoor usesD3D12_HEAP_TYPE_GPU_UPLOAD, so there's no OPTIONS16 check to miss. Natively it falls back safely, no divide by zero, and it can't switch on for WARP or an integrated part sinceumnever loads there.resource::room(resource.rs:1787), but withactive_budget_bytes()at 0 it keeps the DXGI budget unchanged.upload_bufferwithVICTORY_VRAM_FIRST=1 VICTORY_VRAM_REBAR=0(host.rs:7543), which takes the existingupload_in(size, true)CUSTOM / WRITE_BACK / L0 heap thattexture_stagingalready uses. I checked it: heap comes back CUSTOM, CPU write and read back fine, a GPU copy into a readback buffer matches byte for byte, and the debug layer stays quiet, on the card and on WARP. With REBAR left at 1 it's a plain UPLOAD heap as before.Off path (env unset) vs main
Mostly gated, but not quite bit-for-bit
unbindnow needs HELD before theVirtualFree(MEM_PRESERVE_PLACEHOLDER), with no switch check. On main any BOUND page with REAL or KEPT gets its placeholder back. I couldn't find a normal path where a bound page lacks HELD (binds land in placeholders thatlazy::reservedmarks), so probably no visible change, but a page bound in a placeholder that wasn't marked would now keep its private commit and the next bind there would fail. A dedicated bit for registered committed pages, or gating onvram_policy::has(BUFFERS), would keep main's behaviour exact.liveread at line 807 instead of re-readingLIVE_VRAMlike main did. Only a few microseconds of staleness, but not identical.unbackcallsunregister_committedunconditionally, a lock/unlock per 64K page on every free. It shouldn't match anything with the switch off, it's just extra work.classarray in every paged pool (residency.rs:311), three new page bitmaps, an extra load inhidden()(residency.rs:395),add_tier2/sub_tier2inplaced()(residency.rs:551) and on pool close,usage_fullplus four stores each tick (residency.rs:801), asnapshot()per panel frame.VICTORY_VRAM_STATS=1alone, with FIRST unset, changes the HUD xmem row and prints a stats line (natively that line is all zeros). Probably intended, just noting it.On path, read only (couldn't run it here)
gtt_fallbacksmixes units. Intickit addsheld_backevery pass (residency.rs:1052), which is a count of pages waiting right now, so summing it each tick grows with time rather than with events. Incard_roomit adds 1 per refused pool (um.rs:924 onwards). The 3 in the benchmark table probably means "pools refused", but the in-game counter will look a lot bigger after a while.pool_to_cardretags the pool as WriteCombined and adds its bytes to the WC counter (um.rs:1280, um.rs:1311), but pages that were promoted under the old kind stay counted there, and the saturatingsub_tier2hides the drift. Telemetry only.classbits per page are never cleared, so a pool page that once held a BVH stays BVH-weighted after the title reuses it.card_roomunder the switch compares kernelusedplus the request against budget minus 512 MiB (um.rs:941), not against what's actually free. Isusedper process or the whole heap? If it's per process, another app holding VRAM wouldn't be seen.yes, any case, trimmed) and the vkd3d patch (exact1/true/on), so e.g.VICTORY_VRAM_FIRST=yesturns on the residency policy but not the larger ReBAR upload budget.kick(true)sets HIDDEN, residency.rs:1152) matches what the mesa patch does with HIDDEN on a PLACE kick, so that looks right.AI-assisted: yes
@Ayphex on GitHub · 2026-12-04 23:16 UTC · original
Thanks a ton @Kal0s-design for testing
786f5c7on native Windows / NVIDIA / WARP and for the detailed audit — every one of those catches was spot-on.Pushed follow-up commit
04763dbonto this branch addressing all of the review items plus the A1.5 tile-residency iteration (without rewriting786f5c7so review history stays intact):Review Fixes in
04763dbVICTORY_VRAM_FIRST=0parity:lazy.rsunbind(): gated theHELD/ committed-page branch onvram_policy::has(VramClasses::BUFFERS)so baselineVirtualFree(MEM_PRESERVE_PLACEHOLDER)behavior is exact when off.xmem.rsunback(): gatedunregister_committed()onvram_policy::has(VramClasses::BUFFERS)to avoid per-page lock/unlock work on the off path.residency.rs: re-readsLIVE_VRAM.load(Ordering::Relaxed)in the off branch ofspace, and gates theTEX_SOURCEclear inhidden()onVramClasses::TEXTURES.gtt_fallbacksmixed units: keptgtt_fallbacksstrictly as pool-level fallback events (card_room) and movedheld_backto its own gauge (held_back=in[vram-first]telemetry).classbits:clear_tile_state()now clearsclass(along withtaint,quiesce,STRIKES,hits,age) whenever aPhysicalTilespage is unmapped or freshly remapped.pool_to_cardaccounting: subtracts any previously promoted bytes returned byresidency::closed(id)fromold_kindandLIVE_VRAMbefore addingWriteCombinedbytes.card_roomfree-VRAM check: checks againstbudget.min(total) - 512 MiBso global kernel VRAM pressure (e.g. other apps) is respected even iftotal < budget.patches/vkd3d.patchenv parsing: alignedvictory_vram_first_enabled/victory_vram_rebar_disabledwith Rust'sparse_bool_env(1|true|on|yesand0|false|off|no, trimmed, case-insensitive).docs/SETTINGS.mdand the PR description thatVICTORY_VRAM_FIRST=1targets Linux + AMD RADV ReBAR (whereumloads) and safely falls back on native Windows / NVIDIA / WARP.A1.5 Tile Quiescence + Sticky CPU-Read Taint + Pacing
VICTORY_TILE_TAINT=sticky|backoff|off), write/read-quiescence promotion for untainted GPU-SEENPhysicalTiles(VICTORY_TILE_QUIESCE_TICKS=15), per-tick promotion pacing (VICTORY_TILE_PROMOTE_CAP_MB=16), cleanPhysicalTilesvs.CommittedBuffersclass isolation, and a fix for double-headroom reduction inresource::room().VICTORY_BENCH=nort, 60 s) verification:origin/main22.6 FPS(9.81% low) -> A1all23.9 FPS(11.81% low,169 MBtiles) -> A1.5all24.2 FPS(+7.1%,11.81% low+20.4%,577 MBtiles in VRAM,478ktaint skips,0fallbacks).12/12um::unit tests pass,0build warnings,cargo xtask policypasses,patches/vkd3d.patchapplies cleanly, and the branch merges cleanly onto currentorigin/main(b581f7e).@Kal0s-design on GitHub · 2026-12-05 00:02 UTC · original
Re-checked
04763dbon native Windows (one NVIDIA desktop card plus WARP, didn't run the game). It still merges cleanly onto current main.Most of the earlier points are fixed. With the env unset,
unbindis back to main's condition (lazy.rs:590, the new branch at :598 only runs under BUFFERS),unregister_committedis gated (xmem.rs:281), the off branch ofspacere-readsLIVE_VRAM(residency.rs:1242), and theTEX_SOURCEclear inhidden()is gated (residency.rs:504).held_backhas its own gauge now (residency.rs:1274), sogtt_fallbacksonly counts refused pools (um.rs:948). Thepool_to_cardaccounting subtracts what was already on the card (um.rs:1291-1295), and the vkd3d patch parses the env the same way asparse_bool_env.A few things left.
card_room(um.rs:942).budget.min(total)doesn't change anything in practice, becausecompute_budget_withalready keeps the budget at least the headroom below total. So my question is still open: isusedfrom the RADV usage query per process or for the whole heap? If it's per process, other apps' VRAM still isn't seen.clear_tile_state(residency.rs:399) only runs for PhysicalTiles pages with FIRST on. In CommittedBuffers and WC pools the bits still stay set until the pool is freed. A staleCLASS_BVHstill changes the weight and the cold threshold, and a staleCLASS_BUFkeeps a page out ofis_texture_only(residency.rs:567).clear_tile_statealso doesflags.fetch_and(ON_CARD)on remap, so RETIRED, CROWDED and the strike count reset along with the taint. Fine if that's on purpose, just pointing it out since main keeps strikes for the page's lifetime.umloads, so nothing here touches native D3D12. The newtaintandquiescearrays sit next toclassin every paged pool (residency.rs:314-316).closed()walkstaintfor tile pools (residency.rs:346).add_tier2/sub_tier2run inplaced()(residency.rs:662/667),usage_fullplusupdate_kernel_usagerun every tick (residency.rs:965), andnote_promotion/note_cpu_read_demotionrun per moved page (residency.rs:1347, 1360, 1375). All cheap. The one new call that does reach native isresidency::wrote_throughinsafecopy::through(safecopy.rs:180). It returns at theenabled()check (residency.rs:764), so it's one call plus a cached load per write-through chunk.VICTORY_VRAM_STATS=1alone now also samples the tile counters on each pass (residency.rs:995). Harmless.tile_taint_mode()/tile_quiesce_ticks(), which return Off/0 when FIRST is off. Everything else is behindvram_first, so I found nothing new on the off path apart from the items above.Tests
cargo test -p victory-gpu --lib, env unset, PR vs main: same 5 known failures on both (twoindirect::host_list_*, twopipeline::hostlibrary loads, the flakywatchone). In one of three PR runs,host::refresh_tests::unchanged_ranges_are_knownalso failed (write-watch, "written on its last page"). It passed the other two full runs and 5 runs on its own, and host.rs isn't touched, so I think it's just flaky under parallel tests.VICTORY_VRAM_FIRST=1: same 5, nothing new. The newum::residencytests (taint, backoff, quiescence, cap) pass natively.victory-hle --libwithVICTORY_NATIVE_INPUT=0: 162 passed, same as main.manual_checked_divisionat vram_policy.rs:532 (theavg_tilesdivision).checked_div(samples).unwrap_or(0)would clear it.AI-assisted: yes
@luisaugustz on GitHub · 2026-12-05 13:30 UTC · original
Measured on RX 9070 XT 16 GB + Ryzen 7 5800X, RADV with full ReBAR, 3840x2160 output with FSR 4 Performance, ray tracing on (
VICTORY_BVH_IN_PLACE=1). I applied it by hand on top ofb581f7e: five hunks inum/residency.rsconflicted with local changes, and thevkd3d.patchpart was left out.downtownroute (#554)VICTORY_VRAM_FIRST=1VICTORY_VRAM_CLASSES=tiles,textures,rt,bvhVICTORY_VRAM_CLASSES=bvhCity: title memory goes off the card. In the city, VRAM-first seems to move almost all title memory off the card:
xmem poolon the cardAt 4K the card's total use is already above the computed 13,744 MB budget, so I think the pass stays "pressed" and keeps demoting.
The first minute looks faster, but isn't. The first minute of each VRAM-first run looked much faster (25+ fps), but it also drew far fewer draws, about 5–6k against 7–10k. That looks like streaming lagging behind, not a speedup.
Two problems:
VICTORY_VRAM_CLASSES=bvh:amdgpulogged agfxhubpage fault (SQC (data),MAPPING_ERROR,PERMISSION_FAULTS: 0x3) from thevkd3d_queuethread, then device removed (0x887A0005). This was withVICTORY_BVH_IN_PLACE=1.Full tables are in #591.
Pull request closed