d3d12: keep GPU-written placed textures on the GPU until title memory is looked at (#300, draft) #413
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/413"
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?
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T20:57:37Z.
Draft, off by default (
TUXBOX_GPU_OWNED=1turns it on; it was on unless0before). Rebuilt on currentmain(28717263). The write watch went in as #430; what's left is ownership, 7 commits. Earlier comments on this PR describe the old version.What it does
A placed texture the GPU wrote stays on the GPU, with its title pages closed to the CPU, until something reads or writes its memory. Nothing is read back until then.
What changed since the last version
refused-*andsharedcan be compared with what's really copied back.Still copied back
Textures with bytes in common with another placed texture or under an imported buffer, plain XMem allocations, arena pages, unmapped mips, NV12, and textures looked at four times. Each new import on a page is a look, which may keep engagement low.
Relies on
GPU reads through an imported buffer staying inside its declared width, as
gpu_writesalready does. That may not hold for raw root addresses: in ProjectScarlett we're investigating GPU faults on reads just past a root SRV's mapped window, with no cause established. If such reads are real, a read past an import would see stale texels of an owned page here.Known gaps
A title's own
ReadFileorVirtualProtecton closed pages. A queue the title gates with its own CPU fence: 10 s, then stale memory, logged.Expected benefit: unknown
Runs of the earlier version by four people showed
owned=0, or next to it. This version hasn't been run in the game. The counters that decide it, with the switch on and off on one build:owned-mibandbesideup,eager-mibdown by about as much,timed-out0.shared-mib,refused-held-mib,refused-imported-mib,refused-foreign-mib: if most bytes stay there, close this.Most readback in a world window we logged was of mips that hadn't changed (about 90% of published MiB), so narrowing what counts as written may matter more than ownership. Which pipelines still count the whole heap isn't established yet.
Tested
python tuxbox.py check --no-gpu: all steps passed.gpu-owned-beside,gpu-owned-import), the full check on AMD and NVIDIA, the game. Not run on Windows.🤖 Generated with Claude Code
Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-28T22:48:50Z.
Tested draft
#413(aef121f) in ProjectScarlett (1.0.2.1, 3840×2160, offline) on AMD Radeon RX 6900 XT (1002:73bf, RADV NAVI21, Mesa 26.3.1, Linux 7.3.6,GE-Proton11-14), merged cleanly on top ofmain(b8355fa) +#424+ local BLAS lifetime fixes +#389+#390+#408.Results (2 runs:
354.6sunprofiled,481.9swithTUXBOX_SUBMIT_PROFILE=1)#413: 1 frame every 13–16 s (~14.5 s/frame), 8 frames before stall watchdog.#413: 2 frames every 13–14 s unprofiled (13 consecutive 3D frames) and 2 frames every 16–20 s withTUXBOX_SUBMIT_PROFILE=1(25 consecutive 3D frames).placement watch: unwritten=492542/141880.4MiB), bringingplacement digestdown to94.8 msandplacement waitsto9.4 ms.faulted=0,timed-out=0,raced=0in steady state; 8 small textures (160×90,256×256,8×8,1×1) hit the 4-touch fallback cleanly.7.4 s/8.9 swindow, 83.5% of frame time):Almost every big render-target/UAV texture stayed on eager readback (
owned=0in steady state):Steady-state 5 s windows showed the exact same split:
shared=852–1129(~54% of eager textures share a 64 KiB page with another placed texture, e.g. aliased/transient targets in the render-target pool).refused=592–779(1,445–1,910 MiB, ~50% of all readback bytes):refused-held=348–457(pages under an XMem host import hold)refused-foreign=73–96(non-XMem memory)171–226uncategorized (XMem guard codes4/5/7/8—REFUSED_OWN,REFUSED_NO_VIEW,REFUSED_FAILED,REFUSED_GUARDED— aren't tallied separately inownership.rs:470)refused-unmapped=0,refused-section=0held=110–146(all dropped cleanly viakept=108–146),struck=26–34.Hope these RADV numbers help when iterating on
#413(and splitting out the write watch, which is already a huge standalone win!).Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T22:50:02Z.
@DrArroway, thank you: this is the first measurement of it in the game, and the
copied backsplit is the useful part. I've put a summary in the description, marked as your numbers.What I take from it:
owned=0in steady state is the expected outcome, not noise.I'm treating these as the two design questions for ownership: whether a page-sharing group of transient targets can be owned as a group, and whether an import hold on a title-memory page can be read without giving up the guard. I don't have an answer to either yet, and I haven't run this in the game myself.
On your side: if you can keep one log with
TUXBOX_SUBMIT_PROFILE=1from a steady window, I'd use it to pick the first case to fix.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-28T22:56:18Z.
Here is one complete steady-state 3D-world window (frame
3944, ~15 frames into the world) from thatTUXBOX_SUBMIT_PROFILE=1run — including the matchingplaced texture readback top 1..8, ledgers, andxmembacking stats (the full persistent log is also saved locally if you need another window later):Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-28T23:04:28Z.
A second AMD data point, on a smaller card. I merged this draft (
aef121f) locally onto #409 atce620c7with no conflicts, so without #408, #389, #390 or #424. I ran it twice, withTUXBOX_GPU_OWNEDon and off, and compared with my run ofce620c7alone. My results match DrArroway's split: ownership doesn't change anything here, and the gain comes from the write watch.Setup: RX 6600 (
1002:73ff, RDNA2, 8 GB), 32 GB RAM + 34 GB swap, Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, default settings, warm caches.lanes-selftestpasses 28 of 28, including the new GPU-written texture cases. No GPU fault or reset in any of the three runs.ce620c7TUXBOX_GPU_OWNED=0Not enough memory for command submission!unmapped=0,sources=heap-uav. That matches thesharedandrefused-heldcases in DrArroway's split. Two 160x90 textures hit the 4-touch fallback.If it's useful, I can do a run with
TUXBOX_SUBMIT_PROFILE=1to get thecopied backsplit on an 8 GB card, and run the write watch PR alone once it's split out.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T23:19:35Z.
Thank you both, this is exactly what I needed, and it corrects one of my own numbers.
readers. @DrArroway, your window has 90 ms over 22 batches, about 4 ms per batch. Ours looked like 44–80 ms; that was a trace-enabled vkd3d-proton of ours, which makes every COMQueryInterfaceabout 12 times slower. The last commit on this branch (d3770e9) removes those calls. I've corrected the description.@1093i3511, thank you for both runs. The GTT figure is the most useful part for me: with ownership off the kernel refused submissions, and ownership on didn't lower GTT. I'd take the
TUXBOX_SUBMIT_PROFILE=1run on 8 GB, and the write-watch PR alone once it's open. I'll also look at why GTT grows by 6 GB in the first 50 s: the write watch and held pages are the first suspects on our side, but I haven't checked.Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-28T23:27:45Z.
@NickStallman, here's the
TUXBOX_SUBMIT_PROFILE=1run on the RX 6600 (8 GB) you asked for. It's the same build as my comment above: #409 atce620c7plus this draft ataef121f, so withoutd3770e9. Default settings. It ended after 415 s on the watchdog: mission at frame 1,122, crash at frame 1,128, so 6 world frames again. No fault, oneNot enough memory for command submission!in the kernel log.Where the 6 GB of GTT come from
On your question about the GTT growth: in this run it matches the readback buffers created in the first world windows, almost one to one.
That's 6.3 GB of new readback buffers in about 19 s, with 4 reuses. Over the same time the process's resident GTT (
/proc/<pid>/fdinfo, sampled every 10 s) went:The card's GTT is 16 GB, so at 00:15:43 the process was asking for more than exists. That points at readback buffers that are created per window and kept rather than reused. The write watch's
heldcount also moves a lot between windows (held=4798/327.9MiBup toheld=108680/16712.8MiB), but I can't tell from here what it adds to GTT.The split matches DrArroway's
Two steady windows in the world:
About 54%
sharedand about 50% of the bytesrefused(mostlyrefused-held, somerefused-foreign, and 57–124 that aren't in a separate counter).owned=0. The same proportions as on the 6900 XT, so the two design questions apply to this card unchanged.On 8 GB the readback itself is the cost
The difference from DrArroway's numbers is how long the copy takes:
placement readbackplacement publicationThe same 504 textures take 25–40 times longer per MiB here. In the second window a single batch spent 7.0 s in placement, 6.5 s of it in the readback. At the same time GTT was full and swap was growing (table above). So I think the copy goes slow because system memory is full and paging, but the profile doesn't show that directly. On this card both are expensive: publication, as you found for the 6900 XT, and the readback itself.
The write watch does its job here too:
The full log is saved locally if you'd like a different window. I can rerun at
d3770e9, and with the write-watch PR alone once it's open.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T23:49:32Z.
@1093i3511, thank you. That's the first time anyone has tied the GTT growth to something, and I think you've found a real gap in my own #392: it reuses a readback buffer only when the earlier publication on that queue has finished, so when the worker lags, the in-flight set is unbounded. I haven't checked how much #392's own keeping of buffers adds to the peak.
I'm looking at two things with your and DrArroway's numbers: bounding the outstanding readback memory without breaking the publication order, and not copying textures that nobody wrote (
unchangedis most of the mips in both of your logs). I don't have a result yet.The write-watch PR should be up after its checks; a run of that alone on your card is the comparison I'd like most.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T23:55:04Z.
The write watch on its own is now #430 (15 commits, on current
main; the full check passed on both cards). @1093i3511, that's the one I'd like yourTUXBOX_PLACEMENT_WATCH=0comparison of, on the 8 GB card. This draft (#413) keeps the ownership work, and I'll rebase it onto #430.Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-29T00:10:35Z.
@NickStallman, thanks. I'll do the #430 comparison on the RX 6600 (normal, and with
TUXBOX_PLACEMENT_WATCH=0) tomorrow. #430 is on main with the BVH walk translation, so it needs a full prepare first, and I'll add #409 on top for the fault fix. Expect both runs in the next day. It's already pretty late here and I was already about to call it a day.Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T01:28:52Z.
I ran this in ProjectScarlett tonight. In short, GPU ownership never engaged in the game.
Setup: #413's head merged onto current
main, which already has #430's final version, #425 and #432. That gave 19 conflicts, mostly this branch adding code wheremainhas none; I took this branch's side for all of them. Release build,TUXBOX_SUBMIT_PROFILE=1, RTX 4070 Ti SUPER on NVIDIA's driver, Proton, offline.What happened: it reached the title screen (72 FPS) and the prologue scene. The prologue ran at about 0.3 FPS, and I stopped it after about 5 minutes because host swap was nearly full.
Ownership, from the last two 5 s windows of
submit profile placement:owned=0in every window: no texture stayed on the GPU, and 3–4 GB per window was still read back eagerly.refused-held: textures over pages under a host import hold.sharedis large too, so many written textures share a page with another placed texture.Memory (measured, cause not isolated): the process reached about 23 GB (10 GB resident plus 12 GB swapped). Before tonight's merges it was 17–18 GB. Readback buffers held 3.3 GB of system memory. I haven't separated what this branch contributes from #430 (now on
main) and a large batch of newly compiled shaders in the same run, so I'm not attributing the increase to this branch. A run of plainmainis next.Not tested: AMD, Windows, any CPU timing comparison.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T01:49:48Z.
@brcly, thanks for trying it on
main. Three runs on three cards now say the same thing:owned=0, and the bytes are insharedandrefused-held. I'll leave this draft as a record of the approach and not try to make it engage until it handles those two cases; the write watch that did help is already inmainas #430.On memory: the readback buffers you saw (3.3 GB) fit 1093i3511's finding that they are created faster than they are retired. Your
c92559b6should cut the number, since most of those textures aren't written. I have a follow-up for the publication side too (skip unchanged mips, share one readback buffer between a queue's in-flight publications), on a branch, unrun in the game; I'll only open it if it still helps on top of yours.If your plain-
mainrun shows the memory too, that would settle whether it's this branch.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T04:32:32Z.
@brcly, after your run I said I'd leave this as a record. I've rebuilt it on current
mainafter all, without the parts #430 covered, and off by default. It now tries the two cases your run showed: textures sharing a 64 KiB page (no shared bytes) and textures over imported pages (no buffer over their bytes, NVIDIA only, behind a probe). Not run on a GPU or in the game, so it's still a draft and I claim nothing for it.Correction (edited): I first suggested here that
DispatchRaysand rayExecuteIndirectstill counting the whole heap as written could explain youreager=2092 eager-mib=3896.4window. Our logs say the game doesn't use either: no ray state object is ever created in the runs that trace them, so please disregard that. By reading, other paths still fall back to the whole heap (null compute stand-ins, programs whose image stores can't be traced, tables not resolved). I haven't measured which, or whether any of this applies in your window. If you have thetexturesandlargestvalues from its readback lines, they'd help: on our older build, withoutc92559b6, they were 504 textures and 939 MiB per batch.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T09:04:43Z.
Tested updated
#413(0038fe83) on AMD Radeon RX 6900 XT (1002:73bf, RADV NAVI21, Mesa 26.3.1, Linux 7.3.6,GE-Proton11-14).main(2871726) +#455(guest-memory BLAS lifetime) +#441(root SRV/UAV reach, keeping bothheld/pages_held()andhold/covers()inruntime/d3d12/src/device/heap/import.rs) +#413(0038fe83).1. Targeted Lanes on
1002:73bf(TUXBOX_GPU_OWNED=1)7/7 passed (
exit=0,passed=1vialanes.exe --selftest <scenario> --adapter 1002:73bf --report):gpu-owned-idle,gpu-owned-read,gpu-owned-write,gpu-owned-alias,gpu-owned-held,gpu-owned-beside,gpu-owned-import2. ProjectScarlett Same-Binary A/B (
TUXBOX_SUBMIT_PROFILE=1,TUXBOX_GPU_OWNED=0vs1)host imports disturb the write watch on game memoryhost imports are not tried on game memory closed to the CPUTUXBOX_GPU_OWNED=0(460.2stotal,93D world windows /18placement publicationprofile windows =156.2s)TUXBOX_GPU_OWNED=1(437.8stotal,113D world windows /22placement publicationprofile windows =183.2s)TUXBOX_GPU_OWNED=0TUXBOX_GPU_OWNED=119frames /151s(7.95 s/frame; steady8.50 s/frame,0.118 FPS)22frames /185s(8.41 s/frame; steady8.40 s/frame,0.119 FPS)placement publication127.16s(81.4%wall, avg652.1 ms,64,701.3 MiB)150.73s(82.3%wall, avg669.9 ms,78,142.3 MiB)placement own0.00s4.08s(2.2%wall, avg8.9 ms, max300.1 ms)owned/owned-mib/beside0/0.0 MiB/00/0.0 MiB/0(owned=3/0.2 MiBonce pre-3D)held/kept0/02,919/2,976(~45.2 MiB,0.06%ofeager-mib)eager/eager-mib37,098/68,516.8 MiB41,292/76,165.1 MiBshared/shared-mib0/0.0 MiB4,379/14,048.8 MiB(18.4%ofeager-mib)struck/struck-mib0/0.0 MiB632/24.6 MiB(0.03%)refused/refused-mib0/0.0 MiB33,348/62,046.5 MiB(81.5%ofeager-mib)refused-unmapped/refused-section0/00(0.0 MiB) /0(0.0 MiB)refused-held09,068(27.2%ofrefusedcount)raced/acquired/faulted/timed-out0/0/0/014/16(18total) /0/0VK_ERROR_DEVICE_LOST00(both runs ended on unrelated title CPU exceptions)Notes
99.94%ofeager-mibis still copied back (81.5%inrefused-mib+18.4%inshared-mib), and the ~145textures/window kept on label-wait batches (kept=2,976) only covered~45.2 MiBacross183.2s(beside=0). Since RADV does not try imports on closed pages by design, an NVIDIA run where the closed-page probe passes could still see differentrefused-held/refused-importednumbers.runtime/d3d12/src/device/placement/ownership.rs(window_lines),submit profile placement copied back:packs 25 fields into a ~450-character line, so Wine'sOutputDebugStringAtruncates every line right afterrefused-held=<N> refused-hel.... That hidesrefused-held-mib,refused-imported(-mib),refused-foreign(-mib),refused-own,refused-no-view, andrefused-other(which cover the remaining24,280refused textures). Splitting that line in two would make the full breakdown readable under Proton/Wine.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T09:19:58Z.
Thank you, that's a clear result: no gain on RADV, as it's meant to fall back there, and the owned path did almost nothing in your run. I'd read it as no reason to merge this for AMD.
The truncated line makes the one interesting number (why 24,280 textures were refused) unreadable, so I'll split it when I next rebase this. It stays a draft, and it conflicts with
mainat the moment. An NVIDIA A/B isn't scheduled: I'm on two other faults first.Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-29T10:20:22Z.
@NickStallman, here is the #430 comparison on 8 GB that you asked for, plus the
texturesandlargestvalues. Everything is plainmain2871726(with #409, #430 andc92559b6, without #413) on the RX 6600 (8 GB, RADV, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14), default settings except where noted, warm Mesa shader cache, offline.Runs
TUXBOX_PLACEMENT_WATCHNot enough memory for command submission!(5×), the compositor's submission rejected (-12), compositor aborted, game gone00Not enough memory for command submission!(12×), compositor aborted, game goneA cold-cache run before these (default) took 39 min to reach the world and ended on the watchdog with GTT at 15.5 GB.
1. The write watch slows the start on this card. Frames presented per 10 s, from the first window after startup (the Rockstar logo and the scenes after it):
With the watch on, the logo animation plays visibly slower (about 2/3 to 3/4 speed) and its audio drops out at the start. With
TUXBOX_PLACEMENT_WATCH=0it plays normally. From the third window on, the watch costs 3–4× in presents. I haven't profiled where the time goes.2. In the world, the watch makes no difference to the batches. Every world window in all four runs had the same batch: 504–509 textures,
largest=939.3MiB/504 textures, about 1–4.8 GB copied per 5 s, withbuffers createdof 1–5 GB per window and few reuses. Soc92559b6doesn't shrink this batch in this title: these are the numbers from our build without it. The largest textures are 2560x1440 with one mip,sources=heap-uav,queues=direct. Example from run 1:3. On 8 GB, the readback buffers now end the whole desktop session. Within 15–40 s of world entry, card GTT goes from about 9–10 GB to the full 16 GB. Then the kernel refuses command submissions, including the compositor's, which aborts. Runs 1 and 4 lost the desktop this way, with no GPU fault and no ring reset. Run 4 lasted longest in the world (28 windows, about 140 s, a frame every 10–16 s): GTT went up and down between 12.5 and 16 GB for two minutes before it ran out. RAM peaked at 30.7 of 32 GB and swap at 13.4 GB. Bounding the outstanding readback memory, as you planned, would help here first.
4. One GPU fault (run 3, watch off): 10 gfxhub page faults from the game's
vkd3d_queueon ring 24, host pages0x8001dddb0000,0x8001dddb1000and0x8001dddb3000(TCP, status0x00501031), thengfx_0.0.0timeout and a successful ring reset; the title's watchdog ended the game 30 s later. It didn't happen in run 4 with the same setting, nor in runs 1 and 2. These are host addresses like the freed-storage faults in #403 (cause 2), which #455 targets; I can't tell from the kernel log alone which structure it was.I can run #455 on top of
mainon this card if that helps, or aTUXBOX_SUBMIT_PROFILE=1run to see where the watch spends its time before the world.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T10:49:52Z.
Thank you, that's a lot of careful work, and it corrects a hope of mine:
c92559b6doesn't shrink the world batch here either. Your 939.3 MiB/504 is the same set I measured on a 5090.For the memory, the PRs to try are #439, #460 and #462 (which contains both). On a 4070 Ti SUPER brcly measured pinned readback in the world load going from 2.5–4.4 GiB to 0.29 GiB with all three, and no whole-heap batch; DrArroway got 216–712 MiB on an RX 6900 XT. I haven't run it on 8 GB, so a run of #462 on your card would say more than anything I can offer. I'd still bound what's outstanding, but after that, not before.
The slow start with the watch on is new to me, and I don't have a guess I'd trust: a
TUXBOX_SUBMIT_PROFILE=1run of the first minutes, watch on and off, would be very useful. For the fault, yes, #455 onmainis the one to try.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T19:34:32Z.
Closing this: it no longer has enough value to justify its size.
TUXBOX_XMEM_PRIVATE_VIEWS=1.Keeping textures on the GPU with section pages would need all mappings of a page closed at once, which is a new design rather than a rebase. If someone wants to take that up, the branch rebases onto
2d6dc338(unit tests andcheck --no-gpupass, no GPU run since), and I can push it. Thanks to everyone who tested or reviewed it.Pull request closed