memory: landing a structure asks our table whether its page is on the card #382
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!382
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-382"
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?
@mateozariquiey on GitHub · 2026-12-03 21:59 UTC · original
mateozariquiey:pr/land-table→main· +11 −3 · 2 files · 2 commits · merged 2026-12-05 17:26 UTCCause. With ray tracing on,
Memory::landruns for each address the title's structure builder is given, some 133 times a frame, on the submitting thread and under the mutex. It askedcommittedwhether the address's 64 KiB page is there. A page on the card is not in the working set, socommittedends up reading a byte of each of its 16 kernel pages over the bus: 56 us a call, about 8 ms a frame (stats: copies run_ms).Change. One line:
landaskstexture::gpu_mapped, which looks in the table of pages on the card first (um::resident) and askscommittedabout everything else. Only the question whether the page is there is answered otherwise: the header is read from title memory at every call, as before, and alone decides whether a structure is known, new or another one.Tested. i7-10700K, RX 9070, RADV, 3840x2160 output, ray tracing on, an interior scene, three runs a side interleaved, on a tree based on
842767a:copies run_mspreparing_ms(mean)No errors, no dropped draws, captures alike. A diagnostic run asked both ways at every call:
committednever said no where the table said yes. Thememory::tests pass on6064c04.Limits. No gain in frame rate here: the card is the limit in that scene, and the submitting thread waits for it instead. It frees CPU time, which may show where the processor is the limit. Where a view goes (
unalias), its bits are cleared just after the mapping is removed: in betweenlandreads a header of zeros, which is no structure, and may take zeros into the young copy of a page the title has just freed. The same could happen before between the question and the read.@Kal0s-design on GitHub · 2026-12-04 07:30 UTC · original
Looked at
fabe229against main. I think this is fine.gpu_mappedisum::resident(..) || committed(..)(texture.rs:2309-2311), so it can only accept more pages than before, never fewer. No structure that landed on main stops landing here.The extra pages it accepts are the ones whose bits are set in VRAM_PTES. Those bits are only set in
um::mapaftershow_ashas succeeded (um.rs:1306-1310), and only for non-paged pools (um.rs:1166). Mapped throughaliasthat means a READ_WRITE CPU view of the card memory, which main also accepted, just through the slow one-byte read per 4 KiB page inreadable_plain. The lazily bound case maps with protection 0 when the page hasn't been touched (lazy.rs:496-497), butcommittedalready said yes there too becauselazy::therecounts Pending as Through (lazy.rs:356). So I couldn't find a steady state where the new check says yes and main said no on a page the CPU can't read.The one gap is a stale bit.
unaliashides the mapping first and clears the bits after, inforget(um.rs:1404-1405, cleared at um.rs:1379), andresidentreads the atomics without the um state lock (um.rs:1473-1480). Alandlanding in that window passes the check on a page that is already gone. That doesn't fault, becausepacked_atgoes throughcopy_mapped(memory.rs:959) and a failed read falls back toread_pieces, which writes zeros (host.rs:7363-7378). The header then failspacked_lenand only young pages are re-taken. Main has the same race betweencommittedandpacked_at, and the record path at memory.rs:1702 already reads the header with no check at all. So this doesn't add a new class of problem, it just moves the window a little.To make sure the zero fallback really holds when the table is wrong, I wrote a throwaway local test (not pushed) that sets the VRAM bits by hand over a 64 KiB committed PAGE_NOACCESS block and over a reserve-only block. In both cases
committedstayed false,gpu_mappedwent true, and an 8-bytecopy_mappedread back 0 without faulting. On a normal RW block both stayed true and the header read back correctly.Small note, not blocking. When
put_in_placedoes not take it,placestill callscommitted(memory.rs:1046), so the first landing of a new structure on a card page still pays the slow path. Only repeat landings get faster.Tests ran natively on Windows (MSVC, not Wine).
cargo test -p victory-gpu --lib memorygave 23 passed, 0 failed, 2 ignored. Thecommitted,um::andtexture::filters gave 3, 2 and 11 passed with no failures.AI-assisted: yes
@fsrajner on GitHub · 2026-12-04 08:14 UTC · original
Tested on top of main together with the other PRs listed below. RT is on in this scene, but we could not see a change in ms/frame. Our frames here are GPU-bound, so time saved on the submitting thread may not show up. Our
stats: framelines do not reportcopies run_ms, so I could not check that counter directly.Setup: RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's
setup.sh. Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro); the game stops 120 s after the first press. The figures come from the 5 sstats: framewindows after loading. 2 runs per variant; main =0fd7614. The PR build is main + #382 + #392 + #393 + #408 + #445 + #369 together. #398 was left out because it conflicts with #369 in the residency planning. The #369 merge conflicted only with local counters.VICTORY_TEXTURE_BARRIERS=1VICTORY_CARD_KEPT_MB=9216The first run of main and of the PR build each began by re-preparing shaders after a translator change. That is likely where the 48 ms run and the 82.9 ms worst window come from. Otherwise the spread between runs is about ±1 ms/frame, so all of these are within noise. In this scene the card is the limit (about 21-24 ms of GPU wait per frame).
@Luxuride on GitHub · 2026-12-04 12:03 UTC · original
Best of the batch: six lines, measured, and it removes ~8 ms a frame of ray-tracing work from the submitting thread. Take it after a rebase and one doc fix.
The doc fix:
texture::gpu_mapped()'s own comment (texture.rs:2305-2309) says it is "For consumers asking if GPU backing exists, not for validation of a CPU load", andland()does then do a CPU load of the header (memory.rs:962,copy_mapped→ReadProcessMemory). On a card page that is not CPU-readable the read yields zeros and the code falls into the "anything else" branch (memory.rs:979-990), merging a page of bytes it never read. Update that comment in this PR, since the predicate now has a CPU-load caller by design.The other one: your evidence is exactly right and it lives only in the commit message (copies 8.3-8.7 ms → 0.45-0.48 ms, preparing 13.9-19.5 ms → 5.6-7.2 ms, three interleaved runs a side on i7-10700K / RX 9070 / 4K / RT on). Move it into the PR body so it survives in
git logwhere the reviewer looks.The check-to-use window you disclosed in the commit message is unchanged and honestly stated — no action.
fabe229f32to8979da1e67@mateozariquiey on GitHub · 2026-12-04 19:18 UTC · original
Rebased onto
b2449c4and rewordedgpu_mapped's comment in a second commit (8979da1): it says whether the backing exists, not that a CPU load of it will succeed, and it now namesMemory::landas the caller that reads a header after asking (a page gone by then reads as zeros, which is no structure).The figures are in the PR body already, in the table under "Tested"; the commit message has the same ones.
The
memory::tests pass on the rebased branch (23 passed, under Wine with RADV).