WIP: fix(host): host writes that zero imported guest memory mark it; late pages are found when a capture is taken; RX_VK_MEM_CHECK counts where memory sync breaks its rules #1360
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1360
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:fix/memory-sync"
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?
Type: fix · Risk: medium · Tested on: Linux, RTX 3090 · Needs: a Windows build and run; an integrated GPU
Why
"Stale or wrong data after the GPU writes" keeps being fixed one case at a time: each is two of the renderer's tables disagreeing about which copy of a page is newest (guest memory, a capture, a mirror, a shadow). Track B of the renderer rework plan. A design study of
vk_memory.cppfound two things to do first, and this pull request does both: close the host writes the renderer is never told about, and count where the sync breaks its own rules on a running game. Stacked on #1309: review the commits after it. See #1034, which fixes the same three writes with its measurement tools; this one is the fix alone, with a check that keeps it fixed.What changed
The fix
host/hos_mem.cdiscard_pagesandFreeMemoryPages,host/hos_svc.cUnmapPhysicalMemory: each zeroed pages the renderer had imported, with no write mark. The renderer's mirrors, capture entries and write-back shadows kept the old bytes, and a write-back could put them back over the zeros. They now write throughhos_guest_fill(host/hos.h), which marks after the bytes.DiscardVirtualMemoryorMEM_RESETunder the GPU's mapping. The test also runs before the large-pages early return.nvnTextureReadTexelscopying texels into a buffer the game chose (host/nvn_native.c), and the renderer's own guest allocation (host/rx_backend.c).tests/test_host_free_marks.py(new) compiles the realhos_mem.cand checks imported pages read zero and are marked.tests/test_host_guest_writes.py(new) scanshost/*.cfor amemset/memcpy/memmoveinto guest memory that no mark follows; 52 sites are allowed, each with its reason (out-parameters, audio, input records, the guest stack).The late-at-replay fix
memory_take_capturenow completes the capture's late list from the write-backs recorded by then (gpu/vk/late_replay.h): takes are in submit order, so every earlier submission is recorded. Such a page keeps the capture's words and takes a GPU word only where a write-back newer than the capture stamped it; it compares no CPU value, so a counter the CPU set back to zero keeps its zero. The argument and its two remaining exposures are abovecapture_late_at_replay.gen_nowand every copy of it) is 64 bits.The checker
RX_VK_MEM_CHECK=1, off unset (gpu/vk/mem_check.h, hooks invk_memory.cppandvk_replay.cpp): one flag test a hook when off. On, it counts and logs the first eight of each: a capture taken or marks collected while a recording is open; a take that gets another submission's capture; a mirror sync that copies a capture's page over a newer GPU write not marked late; a sync over words only the GPU writes; live reads by cause; the generation counter's speed. Onevk: mem check:line every 600 submits. Nothing aborts.docs/development/memory-check.md(new).Measurements
Verdict: no change in fps, and no visible bug shown fixed. What the checker can say for certain, over about 160,000 submits through three areas:
With
RX_VK_LATE_AT_REPLAY=0:candidates by path: 10316 no write-back, 0 in place, 2640 mirror write-back not late.Hardware: CachyOS (kernel 7.3.3), RTX 3090 24 GB, NVIDIA 620.70, Ryzen 9 7900X, 32 GB; 2560x1440, no upscaler, Threaded rendering Auto (on). Sessions through the job queue, timing mode for the fps pairs.
Flags and settings
RX_VK_MEM_CHECK(diagnostic, off unset) andRX_VK_LATE_AT_REPLAY(the way back from the late-at-replay fix, on unset), each with its row and its doc.Testing
Tested: Linux, RTX 3090 (NVIDIA 620.70): two sessions through Kokiri Forest, Hyrule Field and the Market, one with the checker on; the scenes drew with main's draw counts and frame rates, no error line.
Not tested:
tests/run_all.pyand the three new checks: not run on this PC.test_host_free_marks.pycompiles all ofhos_mem.cover stand-ins and has never been compiled.Must be tested:
@Beanstalk windows nvidia and windows amd: main against this PR, Kokiri Forest, Hyrule Field, the Market, three area changes)Risks
What could break: on Windows, imported pages that were discarded are now zeroed in place, which costs a memset and a lock at each region free. A mark that was missing now causes a capture and a mirror sync of the zeroed pages, which is the point, and is new work at an area change.
Turning it off: the checker is off unless set. The fix has no switch; revert the commit.
Compatibility: none: no cache is rebuilt,
MKWVK_API_VERSIONstays.Issues
See #1034
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). Not run on this PC; left to the forge's checks.third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
https://claude.ai/code/session_017vw8dzCsAL3UdW7ft8ptL9
Tested in game: Linux, RTX 3090, NVIDIA 620.70: two sessions through Kokiri Forest, Hyrule Field and the Market at 2560x1440, one with RX_VK_MEM_CHECK=1; scenes drew as main, and the checker counted 3,122 syncs over newer GPU writes in 174,600 submits.
Possibly related, for context:
A caution on the second commit (the late-at-replay fix), from its author. Its evidence was the checker's count of syncs that replaced GPU-written words going from 57 to 0. A later experiment showed that count cannot tell a GPU write wrongly overwritten from a counter the game resets each frame by writing zero: a sync that kept such words (not in this branch) doubled the GPU's time, so most of what the checker called losses were probably resets. The late-at-replay fix showed no fps change, but it is being re-argued against that case before this pull request leaves WIP. The first commit (host writes that zero imported memory now mark it) is not affected.
WIP: fix(host): host writes that zero imported guest memory mark it, and RX_VK_MEM_CHECK counts where memory sync breaks its rulesto WIP: fix(host): host writes that zero imported guest memory mark it; late pages are found when a capture is taken; RX_VK_MEM_CHECK counts where memory sync breaks its rulesFolded into #1339, which is now the one pull request for memory (budget and sync). The commits are unchanged apart from being rebased into one stack and carrying the fixes the check suite asked for; nothing was dropped.
Pull request closed