d3d12-gpu: physical-page writes reach every view heap's texture pass (D3D12-GPU-PAGE-WRITES-PER-HEAP) #2852
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2852"
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 ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-01T09:22:41Z.
Claimed in the coordination issue as: D3D12-GPU-PAGE-WRITES-PER-HEAP (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7277779259)
What and why
Physical-page writes behind the guards' back (
page_writtenind3d12/crates/leonida-gpu/src/descriptor/host.rs, mostly DirectStorage reads into physical pages) were kept in one list,PAGE_WRITTEN, and the ones retained for one-shot bakes in another,BAKE_PAGE_WRITTEN. The first view heap whose texture pass ran took each list whole. When the title binds more than one view heap, the placed textures of the others kept the bytes from before until something else made their slots due.The remapped ranges already have a cursor per heap (
RemapQueue, from fxceless/victory-fork 42be495). This gives the page writes the same treatment:PAGE_WRITTENbecomes a list per view heap that holds placed textures, keyed by the heap'slease_id. A heap gets its list at its first placed texture, andDrop for HostHeapremoves it.page_writtenappends to every list, with the same joining andcompactas before.bake_page_written);texture_newslooks at the heap's own lists.This ports TaynanGT's fix from the sibling VIctory tree (TaynanGT/Vice-Tay
bc44a9f, GPL-3.0), credited as co-author.Tested
descriptor::host::tests::a_page_write_reaches_each_view_heap: two heaps with an uploaded placed texture at the same address, onepage_written; after each heap's pass both slots are due (and withLEONIDA_PAGE_WRITES=guards, both bakes find them). Onmain(3bf2844a5) it fails: the second heap's slot never becomes due (left: [],right: [3]). With the change it passes, with the defaultLEONIDA_PAGE_WRITESand withguards.cargo test -p leonida-gpu --lib: 600 passed, 0 failed, 55 ignored (main: 599).cargo clippy -p leonida-gpu --lib --tests: no warning in the changed lines.GPUs tested: n/a (unit tests; no game run)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T09:33:22Z.
Verified on Windows: the crate is green with it, and it adds one test - measured against
main's own file.main7fbcd456e, cherry-picked (one commit,merge-base3bf2844a5),cargo 1.98.1:So the change is tied to its test and nothing else in the crate moved. Existence control, not mutation: I did not break the view-heap walk to watch a specific test fail.
What the crate passing does say, and it is more than usual for a descriptor change: the 600 tests that were already there exercise the host descriptor paths hard, and 97 added lines through
descriptor/host.rsdid not disturb any of them. That file has now been touched twice today (#2766gave the sampler heaps every slot the shaders can reach, this one the physical-page writes), and both times the suite stayed green - which is the argument for the suite being worth its 14 seconds.What I could not test: what "physical-page writes reach every view heap" means for a title - that needs the game writing through a view it made before the page moved. The unit tests are what I ran.
AI-assisted: yes - DeepSeek v4.1 (flash), both arms on the machine above.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T15:19:07Z.
Verified by MoonEyes (another person than the author) on head
c4e286fdfmerged withmaincd0c52fcf: I read the whole diff.cargo test -p leonida-gpu: the only failure seen,committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers, fails in 2 of 5 parallel runs of plainmaintoo. Withheaps.values_mut()cut to the first heap,a_page_write_reaches_each_view_heapfails.In-game run with the six others of a batch on
main21e6bbf4b: RTX 4060 8 GB, NVIDIA 610.88, Windows 11 26300,-SeriesS -FrameGen 2, about 860 s in the world, then a second one of about 440 s, 0 device lost, 0 panic; pictures of the same scene compared withmain, same. Black surfaces in early cutscenes while the PC's memory is full are there on plainmaintoo.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T15:34:32Z.
I tested
c4e286fdtogether with #28410729d56don0ff8a532f, Win64 MSVC target under Wine 11.22 on Radeon Raphael (RADV 26.3.1) and RTX 4070 SUPER (620.73.04). The combined stock selection passed on both GPUs.A separate late-view-heap lifecycle check uses real host view heaps and synthetic placed-texture descriptors. Two adjacent writes inside the same texture coalesced per heap. Draining the first heap kept the second heap’s pending range. Dropping that second heap removed its pending entry, and an uploaded view in a newly enrolled heap received only the next write. The isolated test passed on both GPUs with LEONIDA_PAGE_WRITES=slots (scheduled refresh) and with 0 (bake refresh).
Removing only the lease-entry deletion in Drop failed that same isolated test at the cleanup assertion. The dropped lease still held the coalesced range. MEASURED with synthetic descriptors. AI-assisted (Codex).
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T17:52:13Z.
Review: COMMENTED
The per-heap split is right, and the test kills the obvious regression: mutating
heaps.values_mut()to.take(1)fails it withleft: [] right: [3]athost.rs:7815, and the crate stays 600/0/55. The storage and consumption paths match the description (map at:1024-1026, append/join/compact at:1062-1078, own list at:2921-2927, per-heap bake at:315-319/:2702-2713, registration at the first placed view:3775-3777), and there is no lock inversion:PAGE_WRITTENis never held while takingplaced/textures.Two gaps:
Dropcleanup has no coverage — deleting theremove(&self.lease_id)body leaves all 600 tests green, because the new test never drops a heap after a write. Either merzleckeier's lifecycle test belongs in this PR, or the cleanup is an untested leak fix; as it stands a future change can leak a dead heap's list forever.Worth stating in the body: every page write now takes the single global mutex and appends to every live heap, and each list can hold
MOST = 1<<18ranges (~4 MB), so retention and lock work now scale with the number of live heaps where the old single list did not. AlsoPAGE_WRITES[1](the compaction stat) now increments per heap, which changes what that counter means.Merge is clean against current main (383 behind, and main still has the global list, so this is not fixed elsewhere). #2908 overlaps this file but merges cleanly; #2834 conflicts only in
d3d12/docs/switches.md.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T23:09:38Z.
In-game RUN of head
c4e286fdf, merged with #2857 (2451b4744) onto main1abef08d0(tree 32b6b8c23). RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11, -SeriesS -NoDlss -NoFrameGen.cargo test -p leonida-gpu --lib --locked: 647 passed, 0 failed.AI-assisted: Claude Code (oreofr-agent).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T23:12:30Z.
Merging (added to the merge queue). Head
c4e286fdfmerges cleanly with main913b88b90; since my test main gained only #2973, #2858, #2882, #2788, #2876 and #2884, none of which touches this pull request's file. Claim: D3D12-GPU-PAGE-WRITES-PER-HEAP (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7277779259). Red/green: MoonEyes (cutting heaps.values_mut() to the first heap fails a_page_write_reaches_each_view_heap), KelboLive review on this head (.take(1) mutation fails at host.rs:7815, crate 600/0/55), merzleckeier (with #2841 under Wine on two GPUs). I ran: #2857 and #2852 together on main1abef08d0, leonida-gpu 647 passed / 0 failed, and a 900 s warm in-game run on an RTX 4070 Laptop (621.40): 0 device lost, private memory flat at 24.0-24.3 GB (details in my RUN comment above). CI: green on head and main; the queue runs the full CI before merging. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR.Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-12-01T23:17:06Z.
Independent native Windows 11 + RTX 3090 verification (
VERIFY-2852-RTX3090, claimed in #2570): PASSc4e286fdfmerged cleanly ontomainc4ca57615(diagnostics,mimalloc,exe_sha16:628a7632ac7e626b).610.88).python -I scripts/check_no_game_data.pypassed ondescriptor/host.rs.cargo test -p leonida-gpu --locked --lib -- a_page_write_reaches_each_view_heap --test-threads=1):c4ca57615with new test: 0 passed, 1 failed (second view heap received an empty slot list where[3]was expected).--features diagnostics): 1 passed, 0 failed in both configurations.scripts/game-gate.ps1, Series X 1080–1440p,-NoFrameGen,gate_drivermode=roam, same free-roam template asmainbaseline):PASS(reasons=[],warnings=[],exit=clean,stop=target,cache_saved=true,GATE CONTROLfired withmoved=1.67 m, maxfrom_control_m=1.7 m,0GATE FAIL).world_s=300.6s,world+60s, 6,024 presents, 4,184 median draws):25.36 FPSmedian,21.00 FPSp5,47.63 msp95 frame time,0.237 slongest present gap,0missed pipeline waits,25,739 MBmax private memory,3,185 MBmin commit left,7,639 MBmax VRAM (0 sover budget).3,001(vs2,001onmainroam-stress and#2896roam; all three hit the 300-entry late-warning cap), so single-run roaming stability is confirmed cleanly without claiming recheck elimination from this single run (draw counts also differed:4,184vs7,450).AI-assisted: yes (Gemini 4 Neon orchestrator; Codex GPT-6.2 Astra build, unit tests, and serialized RTX 3090 gate execution).
Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T00:11:53Z.
VERIFY-2852 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files
Verdict: PASS on what I could check, and the red/green question could not be settled here. The change is a per-heap table of physical-page writes, and nothing that passed before fails now — but the new test cannot run on this machine's device, so I could not see it turn from red to green.
Head
c4e286fd, base the currentmain, merge base3bf2844a, 1 file, +97/−25:d3d12/crates/leonida-gpu/src/descriptor/host.rs.1. What it changes
PAGE_WRITTENwas one global list of the address ranges that title memory wrote behind the guards' back (DirectStorage's reads into physical pages, at the addresses the title has them mapped). A texture pass took those ranges —std::mem::take— so with more than one view heap the first heap's pass took them and the other heaps' placed textures kept the bytes from before. The change gives each heap its own list, keyed by the heap'slease_id:with the heap remembering whether it has an entry (
page_writes_kept) and keeping its ownbake_page_writtenlist. This is the same shape theRemapQueuefix already had for the remapped ranges, and the change says so.2. What the tests do here
leonida-gpudoes not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it forx86_64-pc-windows-gnuand ran the tests under Wine 11.21:watch::many_askers_tests::holes_are_known_until_the_runtime_tells,watch::many_askers_tests::no_mapping_is_lost_between_askersandwatch::tests::what_is_left_alone_is_no_known_hole3. Why the new test could not be judged here
The new test is
descriptor::host::tests::a_page_write_reaches_each_view_heap. It builds two view heaps, writes a page and checks that each heap's placed texture is woken. The red side (the merge base with only this pull request's tests) builds and the test passes there — which is not a result, because the test never gets that far on this machine. I put a probe in it:HostHeap::new(false, 8)givesNonehere (the same early return the other device-dependent tests have), so the test passes without asserting anything. The same is true of the head's copy. So the red→green that the repository's own verifier would look for cannot be shown on this machine: it needs a host GPU that makes a view heap.4. What I did not check
lease_idis unique per view heap for the whole run. The change keys the table by it; I did not trace where the ids come from.AI-assisted: MiniMax M3.1 Flash.
Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T00:19:30Z.
VERIFY-2852 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files
Verdict: PASS on what I could check, and the red/green question could not be settled here. The change is a per-heap table of physical-page writes, and nothing that passed before fails now — but the new test cannot run on this machine's device, so I could not see it turn from red to green.
Head
c4e286fd, base the currentmain, merge base3bf2844a, 1 file, +97/−25:d3d12/crates/leonida-gpu/src/descriptor/host.rs.1. What it changes
PAGE_WRITTENwas one global list of the address ranges that title memory wrote behind the guards' back (DirectStorage's reads into physical pages, at the addresses the title has them mapped). A texture pass took those ranges —std::mem::take— so with more than one view heap the first heap's pass took them and the other heaps' placed textures kept the bytes from before. The change gives each heap its own list, keyed by the heap'slease_id:with the heap remembering whether it has an entry (
page_writes_kept) and keeping its ownbake_page_writtenlist. This is the same shape theRemapQueuefix already had for the remapped ranges, and the change says so.2. What the tests do here
leonida-gpudoes not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it forx86_64-pc-windows-gnuand ran the tests under Wine 11.21:watch::many_askers_tests::holes_are_known_until_the_runtime_tells,watch::many_askers_tests::no_mapping_is_lost_between_askersandwatch::tests::what_is_left_alone_is_no_known_hole3. Why the new test could not be judged here
The new test is
descriptor::host::tests::a_page_write_reaches_each_view_heap. It builds two view heaps, writes a page and checks that each heap's placed texture is woken. The red side (the merge base with only this pull request's tests) builds and the test passes there — which is not a result, because the test never gets that far on this machine. I put a probe in it:HostHeap::new(false, 8)givesNonehere (the same early return the other device-dependent tests have), so the test passes without asserting anything. The same is true of the head's copy. So the red→green that the repository's own verifier would look for cannot be shown on this machine: it needs a host GPU that makes a view heap.4. What I did not check
lease_idis unique per view heap for the whole run. The change keys the table by it; I did not trace where the ids come from.AI-assisted: MiniMax M3.1 Flash.