[enhancement][memory] Central manager for video memory: stay under the card's budget without refusing textures #19
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
What you would like
Re-filed from an earlier CodeFloe issue (that repo is gone; nothing was migrated, including its 18 comments).
One owner for the whole card memory budget: one figure for "in use" and one line to keep under, which every part that makes or moves card memory asks. The plan comes in small steps, each its own PR behind its own switch, off by default. Where main already does a step, the step is to test main.
This plan was first filed as an earlier issue ("One owner for the whole card budget") and then re-filed under this title; the text and the switches still call the manager "the owner" (
DARNER_CARD_OWNER). Comments copied into the earlier issue are not repeated here.Status, 2026-12-02. Steps 1a-1d, step 2 and a first version of steps 3 and 4 run on our branch, all off by default. The branch (17189c902) is on main
58a9c07a0(40 commits; main has moved on since, not pushed as a PR). The played runs below are on this branch; the earlier runs are on earlier bases, named with each result.DARNER_CARD_OWNER_COLD=1) did: 0 % of memory lines over in 2 of 2 runs, against 100 % in 2 of 2 with the owner off. The other owner arms stayed at 100 %. (Two runs per arm, branch d5507f55e on main972388856; provisional.) This did not hold in the first played runs with frame generation (FSR 3 x2,darner play's switches with a few named changes, one run per arm): on the same heavy route the card was over its budget in 41 of 238 readings with the owner off and in 50 of 243 withCOLD. No benefit from the owner there (see the "Earlier discussion (ours)" section below).darner play's switches and with frame generation off, the card was already under its budget with the owner off, so the owner helped nothing there, and shared PC memory was about 0.2-0.5 GB higher on average with it on (10 scored runs). With frame generation on and a heavier route it can go over with the owner off too (the line above).act=DARNER_CARD_OWNER=read,shadow,act;gateadds the drain gate and the PC-memory owner;COLDalso lowers textures from 64 KiB up; details in the "Earlier discussion (ours)" section below). The owner arms ran at lower fps than off, butactandCOLDalso made 18-25 % more draws a frame on average (gateabout 6 % more, and one of its two runs fewer than off), so the fps cost is unresolved. 89 % of the texturesCOLDlowered in the one run traced grew back. In the played run (one run, with the sampled marks on), with a counter of the reason, 2,241 regrowths were counted against 2,909 lowered, nearly all because a shader had read the texture again, not because of the "used" mark we suspected.DARNER_TEX_PARK=1and the owner off had 631 MB of RAM free at its lowest. So the plan now prefers lowering quality over moving textures to PC memory. Details are in the "Earlier discussion (ours)" section below.The code facts in this post were checked on b97efa767, after the texture and video-memory rework (merge 415f3d854), and have not been re-checked on today's main (nor against its newer park commits
d8a3dec23, "play: DARNER_TEX_PARK_LESS_SETTLE=1 with frame generation on from the start", and9c6fe0c71, "texture park: 16 GB cards no longer held back twice with frame generation"), so line numbers and limits may have moved. Main has since restarted its history (02c896968). Measurements keep the names they ran under (VICTORY_*,victory play); main's are nowDARNER_*anddarner play.Who it affects. We measured on 8 GB cards. Two earlier GitHub reports, now gone, showed 12 GB cards under pressure too: 10.9 of 12 GB in use with heavy stutter (Series X profile, DLSS frame generation), and a crash report titled "exceeding 12GB VRAM" with no figures. Skanzinho's 12 GB card lost the device at about 1.5 minutes with 356 MB of RAM free on a 32 GB PC (
DARNER_KEEP_RAM_GB=22and a 6 GB card limit, v2026.12.01.02), and ran 16 minutes clean without them; one run each, and more than that differed (earlier comments, not copied here). On a 24 GB card the old fixed park target left the card unused instead (an earlier issue on the old host, not re-filed). Ray tracing, frame generation and higher resolutions may reach the budget sooner on any card (not measured).Goals
Predicted benefits. Each is "measured" (build, date) or "estimate" (why).
victory play(the park), 28 minutes: over the budget in 0 % of 916 memory lines, always at least 501 MB under. The old main's memory defaults on our fork's build, 31 minutes: over in 10 % of 1,097 lines, by up to 314 MB, from about 3 minutes in. Not like for like (another exe; the test build started with an empty pipeline cache), and both runs are before b97efa767: main itself was not run. The owner's line should also cover the script launcher's path, which went over on an older build ("Two launch paths"): estimate, not measured.37ff585), with its nine tenths, untried844 measured on a later save (an earlier comment, not copied here): three runs of 12-23 minutes, no device loss, over the budget in 0 of 704, 445 and 839 memory lines, card use 19.8-20.2 GB, and 1.2-7.1 GB parked at the end. So the card fills, but on a late save several GB can still be parked, not at most 1.9 GB.What main already does (read in its code).
VICTORY_TEX_PARK=1, on invictory play): a texture with no card room is made whole in PC memory instead of waiting behind a gray stand-in (target: step 1b).VICTORY_TEX_PARK=2moves the least-used card copies to PC memory, emptiest block first, and back when there is room;VICTORY_DEMOTE=1drops two levels from long-unused textures. Both work without the texture-use marks, but thenDEMOTEkeeps the textures shaders pick by index.What is still missing (our reading of main). There is no single owner.
Host::video_memory(host.rs, 44 call sites in 21 files) asksQueryVideoMemoryInfotwice (card and shared) on every call, with no cache and no budget-change event.Two launch paths on cards with a budget of 8 GiB or less.
victory play(the menu launcher): park on, tiled levels off (LEVELS_ON_DEMAND=0),POOL_SMALL=0.scripts/play-nvidia.ps1(the script launcher):LEVELS_ON_DEMAND=auto(tiled levels on at this budget) andPOOL_SMALL=1. Tiled levels switch off the park,SMALL_WHEN_FULLandTEXTURE_QUALITYfor those textures. As before the rework, a refused texture waits about 4 s behind a gray stand-in and is asked again. The 512 MiB first-upload margin still refuses there (its log line: "refused by an explicit byte limit").POOL_SMALLon, runs uploaded 18.9-21.5 GB and ended at 7.8-8.4 GB card use against a budget of about 7.1 GB; with both off, 2.0-2.4 GB and 6.6-6.7 GB. The script launcher still sets both, so this may still apply; it needs a fresh run on main.Another 8 GB card. CuteBooty's RTX 3070 8 GB (a whole 28-minute campaign mission, v2026.11.30.01 with mcozcan's compaction, DLSS frame generation x2) stayed under its budget, but the margin fell from 869 MB to 22 MB, render-target copies grew from 1.34 to 1.61 GB, all still held, and texture blocks grew from 2.75 to 3.2 GB while 481-835 MB sat free inside them.
What others do. One count of what is held, and one line under the OS budget. Dawn caps its D3D12 use at 95 % of the OS budget minus its own outside reservation (Dawn source). Unreal's DX12 back end aims at 90 % of it, to allow for fragmentation (Epic forum thread quoting UE 5.6). D3D12MA and VMA cache the budget, count what they make and free, and ask the OS again after 30 allocation or block operations (VMA also each frame,
vmaSetCurrentFrameIndex). Over budget, Unreal's texture streamer drops one mip at a time until the plan fits, least recently seen unseen textures first, and DXVK (Vulkan, discrete cards) retries a refused card allocation in system memory. The park is the DXVK answer,DEMOTEthe Unreal one.How to read the data lines. Each "Data" line gives its date and build. All are from our card unless a name is given, and from before the rework unless the build is the test build. "Fork" is our fork's diag build on upstream v2026.11.30.02 with opt-in ports. "Our settings" means our launcher's memory switches, not main's:
POOL_SMALL=0,SLOT_EVICT=0,TEXTURE_KEEP_FREE_MB=0,ROOM_BY_BLOCKS=1,CARD_ROOM_FOR_TARGETS_MB=1280. "Old-main defaults" is the same exe with the old main's script-launcher memory switches (POOL_SMALL=1,SLOT_EVICT=1, the rest unset). Single sessions, not repeated.Proposed steps. A ticked item is on main and was checked in its code; each item says where.
cardledger.rson main, from Remorce's ledger PR, applied ase2675de0d: card bytes by kind, frees counted, a 5 s summary by default (DARNER_CARD_LEDGER=0turns it off; our test report was an earlier comment, not copied here). It "only counts and logs; nothing is decided from it"; step 1 would make it the owner's ledger.DEMOTEand slot eviction one figure and one line.VICTORY_CARD_OWNER=read(off): DXGI is asked at most once a frame and never twice within 16 ms; the budget-change event wakes a reading, debounced, and budget moves under 128 MiB are ignored; between readings, use is estimated from texture blocks and committed textures made or freed, as D3D12MA and VMA do; acard owner:line once a second logs the reading, the estimate and its error. It folds in andrewpozdnakov7-jpg's race fix and follow-up commit, under his name. Our GitHub PR (branchup-card-read) was closed with a request to rewrite it on the new main. The rewrite is implemented on our branch (asDARNER_CARD_OWNER=read), not yet a PR. Thehost.rssize question (an earlier issue) is settled: main lists the file as an exception (55722bd9b).read, no frame generation, an 81 s load then ~7 minutes standing: at most 63 readings a second on the loading screen for up to 2,349 asks a second; in the world a median of 17.6 a second at 18.3 fps, so one a frame. Estimate within 1 MB in 95 % of 316card owner:lines, at most 67 MB; the largest drift, 219 MB, came in the second the budget fell from 7,221 to 6,671 MB. 6,267 event wake-ups for 2 budget moves. No panic or device removal; four shots looked normal. Not run with the switch off.QueryVideoMemoryInfotakes a median 546 ns for one memory group, 1,102 ns for both.37ff585): the test build at 20,000 MB filled the card and still parked 8.7 GB, and lost the device in both sessions; main at its nine tenths (19,798-20,351 MB) ran three sessions without a device loss and parked 1.2-7.1 GB.DARNER_CARD_OWNER=read,shadow,act), not yet a PR; later results in the "Earlier discussion (ours)" section below, first results in an earlier comment, not copied here.SAMPLED_EVICT=pressure) let go 677 more textures, but only 49 MB, and card use stayed at 5,840-5,873 MB. No idle render-target copy was free to go: about 100 were idle (280-400 MB), all held by a list or a slot. Textures stayed refused (118,000-187,000 refused asks per line at first, 9,000-94,000 in the last three), and so did the white stand-ins.TEX_PARK=2) andDEMOTE. The use marks cost about 10 ms a frame on an RTX 3090 at 1440p (main's play.rs: 62.8 against 52.1 ms), sovictory playhas them off (SAMPLED_MARKS=0).targets_room_kept, up to 2.5 GiB at a budget of 8 GiB or less).retire_resource, which keeps a COM reference until running lists finish, and the same call then demandsreferences(&host.texture) == 1(resource.rs:5027; descriptor/host.rs:5248). That was bug 1 in nidea1's follow-up fix PR on GitHub (closed for a rewrite); a smallest version on main is bug 1 plus the slot path's unmapped check. Two of its other fixes are partly on main.ALIAS_TARGETS=2, about 0.8 GB) were on in the test build and are off again on main after testers saw streaks and halos (c7f736c06). This class has no other lever on main.Evict()of 8 heaps of 64 MiB cut DXGI's card use by 512 MB at once, even over budget, andMakeResident()restored it at once. A heap atMINIMUMresidency priority still counted in full, so priority only orders what Windows moves out. A GPU read of an evicted heap removes the device, soEvict()suits only objects nothing references. Not shown: the cost ofMakeResident()after a real page-out.DARNER_CARD_BLOCKS=1) is implemented on our branch, not yet a PR; its first run found a bug (an earlier comment, not copied here).VICTORY_COMPACT_SPARSE, merge 8dd9dad2a (8dd9dad2a)). It acts only when DXGI use is over the budget or PC commit is short. Our 8 GB run with the park never went over the budget, so it never fired; it may need the owner's line as its trigger.COMPACT_WHOLE) is not on main.TEX_PARK=2already picks the emptiest block first.SAMPLED_MARKS=1, whichvictory playsets to 0, so as written it would do nothing there. A new version needs a reason to turn the marks on, or a trigger without them. Whether to rewrite either of mcozcan's PRs on the new main is mcozcan's call.SAMPLED_EVICT(off). 530 MB of them had no shader read within their idle time at the end (1.4 GB at 1 minute).victory playby the park. Still open on the script launcher's tiled path on 8 GB (see "Two launch paths").VICTORY_TEXTURE_BUDGET_MB=2500: the cap is compared with all host textures on the card (4,631 MB at the end), so once they passed it, first uploads were refused (154,114 in the last log window). White and black textures were seen (refusals the likely cause, not proven), and use was still 8,638 MB against a 7,080 MB budget: a cap that refuses is not a degrade.VICTORY_DEMOTE=1exists (off): test it before building anything.TEXTURE_QUALITYis not this step: it cuts levels from large textures for the whole run, used or not, and does nothing under tiled levels.Our 8 GB port (warpGTAIV's VIctory-8GB policy, on our fork) is mostly not on main: 64 MiB texture blocks only, no 1 GiB card windows below an 8,192 MiB budget, no budget/3 texture line, no buffers-first rule. Its textures-outside-blocks mode works against the park, and upstream's loading-crash fix (console_insn.rs) supersedes its own. Anything from it would come as fresh single PRs.
Related work and credit. The steps build on what is merged: the 512 MiB first-upload margin, slot eviction, nidea1's render-target reclaim, the park, Remorce's ledger (step 0), Lyrnc's commit floor (merge b0335dff8: a lower texture line while PC commit is under 4,096 MB,
VICTORY_TEXTURE_COMMIT_FLOOR_MB) and an earlier version of the first commit of nidea1's host-written-records PR (merge ae5d78f38). The GitHub PRs below are gone; I'll link any that is re-filed here.KEEP_SHOWN=2is on invictory play), and nidea1's early-Z with sampled marks.Spec dependence
37ff585(earlier comments, not copied here).Earlier discussion (ours). Our own comments from the earlier issue that are saved locally, summarised. Other people's comments are not copied; where this post names one of them, it is by name.
Correction, 2026-12-02: three played runs with frame generation show no benefit from the owner. Build: our branch 17189c902 (40 commits on main
58a9c07a0), diag build. Played by hand by one person, the same save, 6 minutes in the world each, one run per arm, in this order: (1) owner off, lighter route; (2)COLD(DARNER_CARD_OWNER=read,shadow,act+DARNER_CARD_OWNER_COLD=1), heavy route; (3) owner off again over run 2's heavy route (same route by the player's words). All three: Series S, DLSS Performance, FSR 3 frame generation x2, mouse and keyboard,darner play's switches set through the script launcher withDARNER_SAMPLED_MARKS=1,DARNER_AMBIENT_SPECULAR=1,DARNER_SLOT_FLIPS=1andDARNER_PC_OWNER=read. The switch lists differ only in the two owner switches; the player also changed two F1 settings (DARNER_SHARPEN,DARNER_PANEL) during the series.COLDwith moves to PC memory (RAM_TIGHT),COLDwith the stricter mark, every repeat. No settle run: four tries were each ended by our free-RAM guard (about a minute in; free RAM 628, 577, 640 and, for the fourth after a rule change to "10 seconds in a row under 700 MB, or at once under 300 MB", a lowest of 422 MB). That rule then held for every run of the series, the same for both arms, set before any scored run. A 942-second preload stands in for the settle run; we have not checked that it is equal. A first played try (owner off, 209 MB free 11 seconds into the world) was stopped and not scored.COLD, heavy routeDARNER_TEXTURE_ROOM_PERCENT=80with frame generation, and the owner's target is the smaller of its own line and 80 % of the budget (5,591 MB of 6,989 here). But its drain may run only once DXGI's own reading is within about 64 MB of the budget. So the owner's sum was over its line in all 241 readings from 20:09:49Z on (5.8-7.4 GB against 5.5-5.8 GB) and it refused every first upload (0 allowed, 495,028 asks refused), while the drain was held back until 20:13:14Z. After that it ran in 78 of 243 readings, gave up 9 times, and lowering freed 661 MB in the whole run. This does not make all 495,028 refusals the owner's doing: main's own rule, worked out beside it, would have refused 444,752 of the same asks. In run 3, with the owner off, main's rule refused 278,306 and allowed 9,925; the routes differ, so the totals are not a comparison.COLDlowered 2,909 textures (659 MB in the ten-second lines) and 2,241 regrowths were counted (77 %, not necessarily different textures). The reason counter says a shader had read the texture again 2,139 times, the "used" mark 120 times (a texture can count under both). So the stricter mark would change little on that run.aa2bd4b6a, on main; it applies only when the budget is under 7.5 GiB andDARNER_VRAM_BUDGET_MBis not set) with the owner off, on against=0, on the heavy route; whether the owner is still needed on 8 GB after it is open. Every number here is one played run per arm, no settle run, one 8 GB card; GPU clock state not recorded for these runs.Related: #1 (open, same reporter as the small-card change: RTX 4050 Laptop 6 GB, frame generation leaves textures 1.4 GB). Same area as the
TEXTURE_ROOM_PERCENT=80frame-generation line above; not a duplicate.Are you working on a fix?
Yes, I'm on it, on our 8 GB card.
DARNER_CARD_OWNERandDARNER_CARD_BLOCKSare off by default; withactthe owner also turns onDEMOTEunlessDARNER_DEMOTE=0. First: test the small-card headroom by DonatelloCANNCAN (aa2bd4b6aon main, now in main4a92569fb; it applies only when the budget is under 7.5 GiB andDARNER_VRAM_BUDGET_MBis not set; 512 MB,DARNER_SMALL_CARD_HEADROOM_MB) on our card with the owner off, on against=0. It aims at the same thing on 8 GB, so it may decide what of this plan is still needed there. Then:DARNER_USED_STRICT). Committed (17189c902) and built. The counter has run in one game run (above); the stricter mark has not been switched on in any.DARNER_RAM_TIGHT). Committed (17189c902) and in the build the played runs used, but not switched on in any run. With it on, buffers the owner refuses ask the PC-memory owner first (so far they go to PC memory with no RAM check; untested). One known gap is left: the PC-side line does not count a working-set minimum (DARNER_KEEP_RAM_GB).COLDonly,COLDwith moves to PC memory, andCOLDwith the stricter mark, two runs each. Run so far, played by hand: off,COLDonly, off again. The other arms and the repeats were not run. First the owner's line with frame generation has to be made to agree with when its drain may run (see the "Earlier discussion (ours)" section below).If you are already on one of the steps, please say so here so we don't duplicate it. Runs on other cards are very welcome.
Drafted with AI assistance (Claude Code).
darner rig, F1 AUTO-DETECT row, per-start switches (DARNER_AUTO_SWITCHES, on by default, =0 turns it off) #25