Shaders, Loader: programs follow the pages the game remaps #8
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/ThatRecompDev--five-star-recomp!8
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/8/head"
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?
@marquezinii on GitHub · 2026-11-24 18:15 UTC · original
marquezinii:shaders/address-map-remaps→main· +521 −187 · 18 files · 3 commits · merged 2026-11-24 19:47 UTCThe fix for #4. Translated programs now reach the frame the CPU sees after the game remaps a page under a placed buffer. Before, reads saw the old frame and writes changed whatever owned it next. Two commits:
Shaders: look up a V# access at base + offset.
buf_viewused to take the view of the base's 64 KiB page and add the access offset inside it. That works only while the following pages belong to the same desktop buffer and keep their frames.buf_viewnow takes the offset, adds it to the base in 64 bits (ptr_add) and looks that address up. Loads, stores, formatted accesses, atomics ands_buffer_loaduse the view of their own address.base_hi == 0(heap-index V#s) the result is unchanged.Loader: the address map follows XMem remaps. Every map, remap and unmap now rewrites that page's map entry, at its GPU-only alias if it has one, else at its CPU address.
SectionHeaps) for slot 133 and the map. A section over 1 GiB takes a heap per 1 GiB window (the windows from84e20e5, folded in), and each view stays inside its window.ObservePagestakes several observers. Before, the second registration replacedStaleGpuPages.What still keeps the old frames: desktop views, copies and indirect arguments made on a slot-133 buffer. The
[gpu pages]log from #5 still reports those. One related case changes behaviour: a slot-133 buffer that had no mapped page when it was made gets a committed buffer of its own. Once the game maps pages there, programs reach those pages, while desktop copies and views on the resource keep the committed memory. physical-memory.md describes both.Tests, all on Windows with an RTX 5070 (driver 621.40):
cs_root_descriptor(WARP, dxc and the DXIL backend) now reads and writes across a page boundary into a second buffer. Same program text, so the assembled .bin is unchanged. It fails on main.A_program_reaches_the_frame_the_game_remapped_under_a_placed_buffer(DxcFact, loader tests) compiles a program againstrdna_prelude.hlsliand runsPtrStore/PtrLoadthrough the shim's map. A page is remapped under a slot-133 buffer and its old frame mapped into another range. Without the loader commit the load reads the old frame and the store is lost.dotnet buildhas no warnings.dotnet test: 511 passed, 0 failed; the skipped tests need a dump or a full-wave GPU.I have no dump, so this hasn't run in a boot.
Closes #4.
@ThatRecompDev on GitHub · 2026-11-24 18:52 UTC · original
Thanks for this one, it's the proper fix for #4 and I like that each access now looks up its own page like the hardware does. It merges cleanly onto main, builds without warnings and everything passes here too.
One thing before we merge. The heap index in
buf_view(and ingpu_rwfor the pointer paths) can now differ between lanes of a wave, whenever lanes land in different views. HLSL needs that marked withNonUniformResourceIndex, otherwise NVIDIA and AMD are free to use one lane's descriptor for the whole wave. WARP won't show it. The pointer path already had this gap before your change, so it isn't new, but now it covers every buffer access. Could you wrap those indices? If you'd rather not, I'm happy to add it on top.I'll also run a boot with it on our side, since you don't have a dump. For what it's worth, the
[gpu pages]check from #5 hasn't seen a remap under a live buffer in any boot so far, so this is mostly about being correct rather than fixing a crash we see right now.@marquezinii on GitHub · 2026-11-24 19:05 UTC · original
Done in 894035d: every heap access through a view the map hands out is now
NonUniformResourceIndex. That coversBufLoad,BufLoadRW,BufStore,FmtLoad,FmtStore,PtrLoad,PtrStore, and the buffer and global atomics in the emitter (thegpu_rwpath). The DXIL backend already lowers the intrinsic, and the tests pass with both it and dxc.I also ran
cs_root_descriptoron an RTX 5070 instead of WARP, both with and without the marking. It passes both ways there, so this NVIDIA driver didn't show the problem. The marking is what the spec requires, though, and other drivers are free to differ.Thanks for running a boot with it.
@ThatRecompDev on GitHub · 2026-11-24 19:29 UTC · original
Thanks for adding the NonUniformResourceIndex markers, that's exactly what I meant.
Bad timing on our side though: main moved under you in the same spot. We just merged a change that opens sections bigger than 1 GiB as heaps through 1 GiB windows, plus read-only buffers over mapped pages that nothing covers, all in
XboxPlacedResources(84e20e5). YourSectionHeapsdoes the same job with 512 MiB windows, so it'd be great to fold ours into yours rather than have two. Could you rebase onto current main?One more reason to get this in: with that change, the
[gpu pages]check now sees 500+ remaps under live buffers during the story load, so your fix matters for us right now. I'll boot it as soon as it's rebased.@marquezinii on GitHub · 2026-11-24 19:38 UTC · original
Rebased onto current main, and your windows are folded in.
SectionHeapsis now the one place that opens heaps over XMem sections:MapViewOfFile3view, as yourWindowHeapdid.XboxPlacedResourcesasks it for the heap holding a run's offset and refuses a run that crosses the window end or sits off a 64 KiB boundary, so your two checks are kept.CoverMappedPageskeeps your run limits, reading the window size fromSectionHeaps.WindowBytes. The address map's section views go through the same heaps, and each view ends with its window.That last part matters for the 6 GiB pool. My earlier version opened whole sections, so the remapped pages there would have read as zeros. I checked it with a local run of the DxcFact test that allocates a 17,000-page section, places a buffer over a frame in window 0, and remaps the page to a frame past 1 GiB: the program reads and writes the new frame. I left that variant out of the suite because it commits over 1 GiB.
dotnet test: 511 passed, 0 failed on WARP (Windows, RTX 5070 machine), no build warnings. Good to hear[gpu pages]sees the remaps; I'm curious what the boot shows.@marquezinii on GitHub · 2026-11-24 19:39 UTC · original
Main moved again while I was posting (
1ea5bce), so this is rebased once more. WithCoverMappedPagesgone, my note about its run limits no longer applies; the rest stands. Slot 133 and the address map shareSectionHeapswith your 1 GiB windows, and 511 tests pass on the new main.On the constant pools: with this PR, programs that read those pages through root descriptors, V#s or pointers follow the remaps via the address map. The CBV copy in the upload ring from
1ea5bceis separate and still needed, since desktop CBVs don't go through the map.@ThatRecompDev on GitHub · 2026-11-24 19:47 UTC · original
Merged, thanks a lot! Really nice work, and thanks for rebasing twice while main kept moving under you. This lands right when we need it, since the story load now remaps pages under live buffers.