GPU: skip pending copy-backs and clear saved snapshots on remapped pages #2612
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2612
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2612"
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?
@ashrafsdrop on GitHub · 2026-11-25 16:47 UTC · original
ashrafsdrop:gpu/remap-skips-pending-copy-back→main· +789 −34 · 6 files · 7 commits · openSummary
Addresses
FIND-14: when title memory is unmapped or remapped (watch::title_memory_remapped) while a submission's copy-back is still pending, stale pre-remap GPU writes must not be diffed and written back over the newly mapped memory.Saved::remappedviaChanged::remappedfromtitle_memory_remapped, cleararmedand saved pre-writebytesfor those pages, exposeTracked::was_remapped, and clear per-submission remap state inChanged::takenandTracked::disarm.was_remappedpages inShadow::copy_back_or_notso new title memory is preserved and the page remains dirty (changed) for the nextShadow::update.watch::tests::remapping_clears_saved_bytes_and_marks_page_remappedshadow::tests::remapping_while_copy_back_is_pending_keeps_new_title_bytesshadow::tests::remapping_after_title_write_discards_saved_bytes_for_marked_copy_backVerification
cargo test -p victory-gpu --lib watch— 13 passed, 0 failedcargo test -p victory-gpu --lib shadow— 10 passed, 0 failedcargo test -p victory-gpu --lib -- --skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view— 197 passed, 0 failed, 1 ignored, 1 filtered out (a_texture_written_in_one_format_reads_in_another_through_a_placed_viewfails identically onorigin/main67e8ae1on this host without Agility SDK)cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings— cleancargo run -p xtask -- policy— 184 files okgit diff --check— cleand687c71faeto4f47bdcf10@ashrafsdrop on GitHub · 2026-11-25 17:03 UTC · original
Addressed in
d687c71— good catch on that window.Changes
MAPPING) with a thread-reentrant RAII guardvictory_gpu::title_memory_remapping()incrates/victory-gpu/src/watch.rs(re-exported incrates/victory-gpu/src/lib.rs).XMemMapPhysicalPagesandmap_alias(crates/victory-hle/src/modules/xmem.rs) andUpload::drop(crates/victory-gpu/src/list.rs) holdtitle_memory_remapping()across both the OS map/unmap/VirtualFreecalls andtitle_memory_remapped; standalonetitle_memory_remappedcalls acquire it directly.watch::write_back, which acquiresMAPPING, re-checksTracked::was_remappedfor[at, at + len), and executeswrite_mappedinsidewatch::writingwithout releasingMAPPING. Routedcopy_back_page,copy_back_or_not, andcopy_back_marked(crates/victory-gpu/src/shadow.rs) through it, and filteredwas_remappedpages underMAPPINGinsideTracked::takenso a remap betweenwrite_backandtakencannot clearchanged.crates/victory-gpu/src/shadow.rs:shadow::tests::remapping_after_copy_back_check_before_write_skips_write_back(pausescopy_back_or_notafter the initial check, remaps on another thread, resumes)shadow::tests::remapping_after_marked_snapshot_taken_before_write_skips_write_back(pausescopy_back_markedaftert.saved()moved the snapshot out, remaps on another thread, resumes)shadow::tests::copy_back_write_waits_for_in_flight_remapping_guard(holdstitle_memory_remapping()on another thread while copy-back enterswrite_back, then remaps and releases)Verification
cargo test -p victory-gpu --lib -- --skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view— 200 passed, 0 failed, 1 ignored, 1 filtered out (the skipped test fails identically onorigin/main67e8ae1on this host without Agility SDK)cargo test -p victory-hle xmem— 11 passed, 0 failedcargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings— cleancargo run -p xtask -- policy— 184 files okgit diff --check— clean@cloph-dsp on GitHub · 2026-11-25 17:15 UTC · original
Independent Windows verification of PR #2612 (head
d687c71) on a native RTX 5060 Laptop (driver 621.24) and on WARP.Toolchain: rustc/cargo 1.100.0, Windows MSVC (the repo pins 1.98.1 in
rust-toolchain.toml; no clippy component is available locally). Synthetic tests only, no game data, no source edits.cargo test --locked -p victory-gpu --lib remapping -- --test-threads=1on the PR head: 6 passed, 196 filtered. The three named regressions pass:watch::tests::remapping_clears_saved_bytes_and_marks_page_remapped,shadow::tests::remapping_while_copy_back_is_pending_keeps_new_title_bytes,shadow::tests::remapping_after_title_write_discards_saved_bytes_for_marked_copy_back.watch::tests13 passed,shadow::tests13 passed on the PR head.67e8ae1: the sameremappingfilter reports 0 tests (the new tests are absent).VICTORY_D3D12_WARP=1,--features diagnostics,--test-threads=1, skipping only the known placed-view flakea_texture_written_in_one_format_reads_in_another_through_a_placed_view): 203 passed, 1 ignored, 1 filtered, 0 failed.VICTORY_D3D12_WARP=0) full lib initially reported 201 passed, 2 failed:descriptor::host::tests::dynamic_slots_are_held_until_released(host.rs:2030,NumDescriptors >= HEAP_VIEWS) andmemory::tests::lists_share_a_table_and_copies_keep_their_views(memory.rs:767, 'past the dynamic slots'). Both reproduce on unmodified base67e8ae1with WARP=0, so they are pre-existing hardware-specific failures, not regressions from this PR. Rerunning while skipping those two plus the placed-view flake: 201 passed, 0 failed, 1 ignored, 3 filtered.No competing implementation or PR. AI-assisted (Hy4 flash).
@oni-swr on GitHub · 2026-11-25 17:15 UTC · original
WARP verification of
d687c71merged cleanly ontoorigin/main13f91ca(detached checkout). I first tested the earlier head4112fd7, then re-ran everything ond687c71after it landed.Environment: Windows 11. No physical GPU device was created:
VICTORY_D3D12_WARP=1,VICTORY_WARP=1,cargo -j 4, separateCARGO_TARGET_DIR.Commands and results (head
d687c71):cargo clippy -j 4 -p victory-gpu -p victory-hle --features victory-gpu/diagnostics --all-targets: clean.cargo test -j 4 -p victory-gpu --features diagnostics --lib: 204 passed, 0 failed, 1 ignored (origin/main: 198).a_texture_written_in_one_format_reads_in_another_through_a_placed_viewpasses on WARP here, so no skip was needed.cargo test -j 4 -p victory-hle --lib xmem: 11 passed, 0 failed.d687c71: removing thewas_remappedrecheck inwatch::write_backmakesremapping_after_copy_back_check_before_write_skips_write_back,remapping_after_marked_snapshot_taken_before_write_skips_write_backandcopy_back_write_waits_for_in_flight_remapping_guardfail. On the earlier4112fd7, removing theshadow.rsskip failsremapping_while_copy_back_is_pending_keeps_new_title_bytes.ok, not skipped), so they do exercise the code.Review notes:
watch.rs(needs a manual merge). #2434 (shadow.rsonly) merges textually clean. I did not build or test either combination.MAPPINGis taken bytitle_memory_remapping(reentrant per thread), butwrite_backandTracked::takencallMAPPING.lock()directly (non-reentrant). A thread that holds aRemappingguard and then reaches either one would self-deadlock. I found no such path inxmem.rs,Upload::dropor the tests (the tests' hook runs before the lock is taken), but it is worth a comment. Inxmem.rsthe order isphysical()thenMAPPING; I found nothing taking them the other way round.memory::a_submission_that_missed_leaves_the_copies_at_oncefailed in about 4 of 20 full runs on both this PR andorigin/main.Not tested: physical GPU, real remap races under load, or a retail title. The pause-and-remap tests are deterministic stand-ins for the race.
Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used.
@ashrafsdrop on GitHub · 2026-11-25 17:48 UTC · original
Thanks
@cloph-dspand@oni-swrfor the independent RTX 5060 / WARP verifications and negative-control checks!Re
@oni-swr's note: confirmed —title_memory_remapping()is only held aroundXMemMapPhysicalPages,map_alias,Upload::drop, andtitle_memory_remapped, none of which enterwrite_backorTracked::taken(andRemappingis!Send), soMAPPINGcannot self-deadlock. Happy to add that invariant note if maintainers want a follow-up touch; leavingd687c71untouched for now so the existing checks and approval stay intact.@kotekompotek on GitHub · 2026-11-25 17:51 UTC · original
Reviewed: two coordinated fixes — the copy-back write is now gated through
watch::write_backunder the remapping lock (so a remap during the write can't leave stale bytes), and pages that were remapped while tracked are skipped entirely on refresh (was_remapped) plus pending copy-backs dropped — matching 'remapped memory is new memory' on the free path. The remap/notify ordering under one lock closes the TOCTOU. CI green.@r4tedx on GitHub · 2026-11-25 21:52 UTC · original
Thanks for this. We had been writing the same fix (per-page remap state checked by every copy-back) and will not open a competing PR. We ran #2612's head (
d687c71f) on WARP with our own tests ported onto it, changing none of its code. Results below.What it covers. We checked each case with a test where another thread writes a byte and then reports the page through
title_memory_remappedwhile the copy-back is pending:d687c71fcopy_back)copy_back_marks→copy_back_marked)copy_back_page)copy_back_pagereturns 0 and leaves the page alone (passed)cargo test -p victory-gpu --features diagnostics --lib, WARP)The mapping lock around
XMemMapPhysicalPagesandmap_aliasalso closes the window betweenMapViewOfFile3and the report. Our version left that window open as a documented shortcut, so #2612 is the stronger of the two there.What it leaves out.
XMemVirtualAllocdoes not report new memory. Suppose the title frees memory a copy holds with the host'sVirtualFree(VIctory does not see that call) and then allocates at the same address withXMemVirtualAlloc. The tracker still holds the page as taken and guarded, but the new memory has no guard, so title writes there do not fault and are never copied. This is the same "remapped under a tracker" class, reached through allocation instead of a page mapping. Ond687c71f, the test below shows the write is missed while unreported (passed: the unreported case asserts the miss). With the one-line report our branch adds toXMemVirtualAlloc, it is taken again and guarded again (passed; here the test makes the report itself, asXMemVirtualAllocwould). The change is incrates/victory-hle/src/modules/xmem.rson our branch:title_memory_remapped(at, end - at)after a successfulVirtualAlloc2.Repro:
memory_allocated_again_is_taken_again_once_reported(watch.rs tests)Skips are not visible. Remap skips in
copy_back_markedandcopy_back_pageare counted as "the title wrote it" (MarkedKept, or the once-logged warning), and the snapshot-path skip is not counted at all. A title run therefore cannot tell how often this happens. Our branch counts every skip and prints the total on the diagnostics copy line (N copy-back pages left alone for a remap (in all)), plus one log line the first time.The six-page test used for the table (
pages_remapped_while_shaders_write_keep_the_new_memory, shadow.rs tests; needs the smallhost::tests::no_submissionhelper so parallel tests do not take its marks)Our commit is on fork
r4tedx/VIctory, branchmem/remap-epochs, 6ce84a1c ("GPU: copy-backs skip pages remapped since their submission; new title memory is reported to the watch"). You are welcome to take any of it into #2612:XMemVirtualAllocreport;no_submission(which also lets the two existing marked-page tests hold the submission lock while they set marks).If you take them, please keep the credit our commit gives: the #1633 finding, and @alessiodeia's rule from #2283 that every path removing a mapped view must move the epoch.
The title was not used in these tests.
AI-assisted
@Marvisak on GitHub · 2026-11-25 22:15 UTC · original · edited 2026-11-26 05:38 UTC
Automated triage for the maintainers.
Merge candidate. This closes a real race: a copy-back writing the GPU's stale bytes over title memory that was remapped while a submission was pending. It does this through
watch::write_back(recheck ofwas_remappedunder theMAPPINGlock),Tracked::takenfiltering remapped pages, and atitle_memory_remapping()guard held inXMemMapPhysicalPages,map_aliasandUpload::dropacross the unmap and the report. The pause-and-remap tests inshadow.rsexercise both copy-back paths.On your reply: both requested changes are in
8103a00.Shadow::copy_back_or_notcalls main'smerge_writebackagain and gates only the write onwrite_back. Otherwise it matches main: written and synced on a successful write, synced without a write unless the page was remapped.Tracked::takenandwatch::write_backnow document that they lockMAPPINGnon-reentrantly and must not be reached while aRemappingguard is held.For the maintainer: as commenters note, a free followed by reuse that is never reported to
title_memory_remapped(XMemFreeDefault,XMemVirtualAlloc) is still open. It is addressed separately by #2824 and offered as commits on r4tedx's fork. This PR is the base those build on, and #3036 targets the same defect with weaker coverage.CI: running at the time of this triage (
checkin progress on8103a00). The previous head passed.Recommending a look, not approving.
Generated by Claude Code
@pawrenity on GitHub · 2026-11-26 04:41 UTC · original
I compared this PR with #3036 (same defect, FIND-14) on an RTX 4070: #3036. In short, this PR is the stronger base. It tracks remaps per page and rechecks under the remap lock, and it passes the remap and release-without-free cases that #3036 fails. A free followed by reuse that is never reported to
title_memory_remappedstill writes stale bytes on all three copy-back paths. From reading,XMemFreeDefaultandXMemVirtualAllocdon't report; having them report would close that through this PR's existing check, though I haven't tested that.AI-assisted (Claude Code).
@pawrenity on GitHub · 2026-11-26 04:45 UTC · original
Follow-up to my comparison above: the "free followed by reuse that is never reported" gap is the subject of open PR #2824. It makes
XMemFreeDefault's 32-bit branch release through a newvictory_gpu::release_title_allocationthat clears stale guarded pages and reports the remap, andXMemAllocDefaultreports new 32-bit allocations. With #2824, anXMemFree-then-reuse goes through this PR's remap check. The 64-bit heap branch rightly reports nothing: heap memory has no trackers, and its pages are shared with live neighbours. What stays open after both, from reading only: a range fromXMemVirtualAllocthat the title releases with the host's ownVirtualFree, which xmem never sees (a hook like #2921's would be needed). So the FIND-14 set looks like #2612 + #2824, with #3036's test carried over.AI-assisted (Claude Code).
@ashrafsdrop on GitHub · 2026-11-26 04:49 UTC · original
Addressed the triage feedback in
e35dc8b:merge_writeback:Shadow::copy_back_or_notnow callsmerge_writeback(title, host, old)directly, gating thewrite_mappedwrite onwatch::write_back.Tracked::takenandwatch::write_backstating that both lockMAPPINGnon-reentrantly and must not be called while holding aRemappingguard.Verification
cargo test -p victory-gpu --lib watch: 16 passed, 0 failedcargo test -p victory-gpu --lib shadow: 16 passed, 0 failedcargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: cleancargo run -p xtask -- policy: asset policy: 191 files ok@r4tedx on GitHub · 2026-11-26 05:02 UTC · original
Thanks @pawrenity for the side-by-side with #3036. It pins down the remaining gap: a free followed by reuse that nobody reports.
The free path that needed a report is
XMemFreeDefault(xmem.rs:334). It is reached directly, or throughXMemFreewhen the title has no allocation hook, and committed resources free their memory through it too. Neither of its two paths reported anything:XMemAllocDefault;XMemVirtualAlloc.The other paths need no change, or cannot get one.
XMemFreePhysicalPagesnever hands pages out again, andunmapalready reports. The host'sVirtualFree/NtFreeVirtualMemoryand a title's own allocator hook are not seen.Offer: fork
r4tedx/VIctory, branchmem/2612-free-report, two commits on your head 8a998fcf (they also merge cleanly onto 8103a00e, yourmerge_writebackrestore):e23b47ae:XMemFreeDefaultcallstitle_memory_remappedbefore it frees, undertitle_memory_remapping()(asUpload::dropdoes). It reports the 32-bit reservation whole. For a heap block it reports only the host pages the block fills, so live neighbours on its edge pages keep their copy-backs and frees inside one page cost nothing. Tests:freed_memory_is_reported_to_the_gpu_side(xmem) checks the ranges reported.memory_freed_and_allocated_again_keeps_the_new_bytes_once_reported(shadow) is your R1–R3 in one test: snapshot, marked and computed-address pages, freed and allocated again at the same address. Reported, all three keep the title's0xEE. Unreported, all three get the shaders'0x99(the test's control).c9feb1d4: theXMemVirtualAllocreport from our earlier offer, with its test.Results on WARP (
--features diagnostics,--test-threads 1): victory-gpu lib 254 passed, 0 failed, 1 ignored; victory-hle xmem 15 passed; clippy-D warningsclean with and withoutdiagnostics.Credit runs both ways. #2612's per-page check and mapping lock do the work; these commits only give them two more reports. If you take them, please keep the credit from our earlier P-E offer: the #1633 finding, and @alessiodeia's rule from #2283 that every path that removes mapped memory must move the epoch.
The title was not used in these tests.
AI-assisted
@ashrafsdrop on GitHub · 2026-11-26 05:17 UTC · original · edited 2026-11-26 05:25 UTC
Thanks @r4tedx and @pawrenity. Cherry-picked both commits cleanly onto the PR branch:
cd60351(e23b47a):XMemFreeDefaultreports freed memory undertitle_memory_remapping()before release, including the xmem range check and shadow remap-after-free regression test.540d2d4(c9feb1d):XMemVirtualAllocreports allocated virtual ranges so trackers and guards reset.Full credit preserved: author attribution retained on both commits, crediting the #1633 finding, and @alessiodeia's rule from #2283 that every path that removes mapped memory must move the epoch.
Local verification:
cargo test -p victory-hle xmem: 15 passed, 0 failed.cargo test -p victory-gpu --lib shadow: 17 passed, 0 failed.cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings: clean.cargo run -p xtask -- policy: 191 files ok.@HoLa-Lee on GitHub · 2026-11-26 06:19 UTC · original
A test this PR does not have, and that fails on it: the release-and-re-take case.
title_memory_remappedcovers the reported remaps. It does not cover the titlereleasing a range and taking the same addresses again - which is what
watch.rscalls out ("memory freed and allocated again while a tracker holds it is not
seen"). I wrote the deterministic test for it while working FIND-14, and it fails
on this PR's head:
What it does: register a page of title memory, take the submission's snapshot,
let a shader write one byte into the copy, then
unregister+VirtualFreetherange, take the same addresses again with
VirtualAllocfilled with0xEE, andrun the copy-back. No game, no GPU work beyond the register, and it observes only
when the allocator hands the same address back (it says so and returns when it
does not).
Two things I am not saying: that this is the same report as FIND-14's
remap case (it is a different trigger), or that this PR is wrong. This PR is the
right shape - it hooks the runtime's own signal instead of guessing - and the
suggestion is only that the same treatment is needed on the free side:
Memory'sDrop(committed resources and heaps) and the upload block'sDropbefore
VirtualFreeare where the addresses really go away, which is also what@Machad3x describes in #3036.
The test is yours to take as-is or to adapt; I am closing #3036 and not pushing a
second fix for the same finding. If you would rather I open it as a separate
"test only" PR against
mainso it can land beside yours, say which and I will.@r4tedx on GitHub · 2026-11-26 06:36 UTC · original
Thanks @HoLa-Lee for the test. It caught a mistake of ours.
Our earlier comment was wrong. We wrote that committed resources free their memory through
XMemFreeDefault, and that its heap-block report covers them. Neither is right:4f47bdc).Memory'sDrop(resource.rs:688) goes throughXMemFree→XMemFreeDefaultonly for a committed resource served by the runtime's allocator, and only when the title has no allocation hook. Heaps (resource.rs:728), descriptor heaps (descriptor.rs:768) and the fallback path free withdeallocdirectly (resource.rs:693). The upload block'sDropalready reports before itsVirtualFree(list.rs:1308).watch.rs,runtime_pages). No tracker holds heap memory, sotitle_memory_remappedrecords nothing for it, and the copy-back has nothing to check.XMemFreeDefaultcommit (bea9ae4fhere) therefore reaches no copy.Memory'sDrop(a 1 MiB block, so the heap gives it back to the system and the same address can be taken again), and added a report in thatDrop. It still gets153.What does pass. Your test as written frees with the host's bare
VirtualFreeandVirtualAlloc, which nothing in VIctory sees, and it fails on our branch too (153). When the addresses are taken back throughXMemVirtualAlloc, which reports what it allocates (4f47bdc), the copy-back leaves the new memory alone (238).Branch
mem/2612-free-report-2on forkr4tedx/VIctory, on your head4f47bdc:36541fab:XMemFreeDefaultreports only its 32-bit blocks, whichXMemVirtualAllocwrite-watches. The heap-block report goes, and its doc states the heap gap.6641ced0: your test, credited, with the addresses taken back throughXMemVirtualAlloc's report.Results on WARP (
--features diagnostics,--test-threads 1): victory-gpu lib 255 passed, 0 failed, 1 ignored; victory-hle xmem 15 passed; clippy-D warningsclean with and withoutdiagnostics.Closing the heap case needs remap state that copies without a tracker can check, and it has to reach copies that are already unregistered but still held by pending lists. We can write that if you want it here or as a follow-up.
The title was not used in these tests.
AI-assisted
@HoLa-Lee on GitHub · 2026-11-26 06:47 UTC · original
As offered above, the test now exists as its own PR so it can land beside yours rather than only in a comment: #3077 (test only, #[ignore]d, +60 lines in shadow.rs's test module, no production change).
It is the _pending_copy_back_does_not_write_into_memory_the_title_took_back test verbatim, and it fails on this PR's head
4f47bdcthe same way it fails on main - ␀x99 landing in the ␀xEE the title's next allocation holds. Whoever adds the free-side hook (as @Machad3x describes) deletes the #[ignore] and it turns green.Nothing to do on your side unless you want the file: if you would rather carry the test inside #2612, say so and I will close #3077 - the fix belongs there either way.
@alessiodeia on GitHub · 2026-11-26 12:27 UTC · original
Thanks @r4tedx and @ashrafsdrop for carrying the #2283 rule over, and for keeping the credit.
A coordination note, since this PR and #2283 touch the same spot. Each merges cleanly onto current
mainon its own. Together they conflict in two trivial places:pub use watch::{…}list inlib.rs;title_memory_remappedinwatch.rs, where #2283 addsREMAP_EPOCHandtitle_memory_unmapped.Whichever of the two lands second, I'll rebase #2283 on top. If this one goes in first, the result is consistent by construction. #2283 moves the epoch inside
title_memory_remapped, so the newXMemFreeDefaultandXMemVirtualAllocreports move it too, with no extra change.On "after the release" for those two new paths: #2283 caches a range as committed only when it consists entirely of
MEM_MAPPEDviews. Memory freed throughXMemFreeDefaultor newly allocated byXMemVirtualAllocis private memory, so it is never cached and is asked again on every refresh. Your report before the release is therefore enough for #2283. The second bump after the operation, liketitle_memory_unmappedafterUnmapViewOfFile2, is needed only where a mapped view goes away.@DrDarkDK on GitHub · 2026-11-25 16:57 UTC · original · requested changes
In
copy_back_or_not,was_remappedcan return false and the page can then be remapped beforewrite_mapped. The write still targets the same virtual address, so it can land in the replacement mapping.copy_back_markedhas a similar window.t.saved()takes ownership of the old snapshot. Once that happens, a remap that clears the tracker can’t invalidate the snapshot already in use.Could the final copy-back write and the actual mapping change share synchronization? A regression test that pauses copy-back after the check, remaps the page, then resumes would exercise the window the current tests miss.
Static review only.
AI-assisted with Codex.
@DrDarkDK on GitHub · 2026-11-25 17:07 UTC · original · approved these changes
@fuzeofficlal on GitHub · 2026-11-26 14:28 UTC · original · requested changes
Reviewed
4f47bdcf109aa9e38576e4a684ea6e8dc0aab040(base63bcca43c6a0) and tested on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP,VICTORY_D3D12_DEBUG=1, Rust1.98.1).The lock ordering (
Host::submitted -> Shadow::before -> MAPPING -> GUARDS -> Changed.{0,1}andPHYSICAL -> MAPPING -> GUARDS -> Changed.{0,1}),!SendRemappingguard, and#[cfg(windows)]module scoping forxmemall look sound, and the existing tests pass (victory-hlexmem::: 15/15;victory-gpuwatch:: shadow:: list::: 37/37 on RTX 5090, RTX 5090 + Debug Layer, and WARP +diagnostics+ Debug Layer; clippy clean on default and--all-features).However, there is a blocking correctness regression on valid copy-backs after a prior remap, plus two issues in
xmem.rsthat should be cleaned up before merge:1. Blocking: Stale
Saved::remappedsilently drops valid partial-page unmarked GPU copy-backs after a prior remap (crates/victory-gpu/src/watch.rs:120,167,566,893,913,crates/victory-gpu/src/shadow.rs:444-450,460)title_memory_remappedrecordspageinSaved::remappedunconditionally—even when no submission is pending—andSaved::remappedis only cleared by whole-pageChanged::taken(page)or end-of-submissionTracked::disarm().In production, unmarked declared UAV paths (
draw.rs:216-221root UAVs,draw.rs:882-885title-memory root UAVs, anddraw.rs:1904-1912unmarked descriptor-table UAVs) refresh and snapshot their exact(address, len)rather than expanding topage_range. When a 64 KiB page inside a persistent trackedShadow(e.g., a GPU heap) is remapped before submissionS1starts (viaXMemMapPhysicalPages,map_alias, orXMemVirtualAlloc), andS1writes a sub-64 KiB or unaligned range inside that page:copy.update(p + 0x1000, 0x1000)copies the fresh post-remap title bytes into the shadow buffer, butTracked::take_splitleaveswholeempty for the partial page, soChanged::takenis not called andSaved::remappedstill retainsp / PAGE.copy.writing(p + 0x1000, 0x1000, false)snapshots the fresh post-remap bytes intoself.before, and the GPU writes valid output (with zero remaps duringS1).copy.copy_back(p + 0x1000, 0x1000)hitst.was_remapped((start + at) / PAGE)atshadow.rs:447(andwatch::write_backatwatch.rs:899) and returns0, silently discardingS1's valid GPU writes.Deterministic reproducer verified on both RTX 5090 and WARP (
VICTORY_D3D12_DEBUG=1):origin/main(63bcca43):copied=4096 written=4096 title_byte=0xcc(both RTX 5090 and WARP).#2612(4f47bdcf):copied=4096 written=0 title_byte=0x11(both RTX 5090 and WARP — valid GPU write completely dropped).Scoping remap invalidation to remaps that occur after the refresh/snapshot begins (for example, tracking a per-page or global remap epoch captured before copying/snapshotting and comparing it under
MAPPINGinwrite_back/taken, rather than a sticky pre-submissionBTreeSetonly cleared on whole-pagetaken) fixes this cleanly without reopening the in-flight remap window.2.
XMemFreeDefaultheap-block branch mixesHOST_PAGE = 4 KiBwithwatch::PAGE = 64 KiB(crates/victory-hle/src/modules/xmem.rs:364-376,383)xmem.rs:383definesconst HOST_PAGE: usize = 4 << 10;with the comment "the GPU side's unit of change tracking", whereaswatch::PAGEis64 << 10(64 KiB) andtitle_memory_remappedrounds[at, at + len)outward to 64 KiB pages. As noted earlier in the thread,std::allocheap allocations are untrackedMEM_COMMIT | MEM_PRIVATEmemory anyway—so this branch takes the globalMAPPINGandGUARDSlocks acrossdealloc()on every>= 8 KiBheap free for no benefit, and if a tracker ever did span a page viaruntime_pages's reserved-region shortcut, freeing a 4–8 KiB heap block would wrongly mark the entire enclosing 64 KiB page (and any live neighbors in it) remapped. Removing the non-32-bit heap-block report and keeping only the write-watched 32-bit reservation path avoids both issues.3. Minor race window in
XMemVirtualAlloc(crates/victory-hle/src/modules/xmem.rs:175-181)Unlike
XMemFreeDefault,Upload::drop,XMemMapPhysicalPages, andmap_alias,XMemVirtualAlloccallstitle_memory_remappedafterVirtualAlloc2without holdingtitle_memory_remapping()across the allocation and notification. If the title freed a range via uninterceptedVirtualFreeand immediately re-allocated the same address viaXMemVirtualAlloc, a pending copy-back can write stale GPU bytes into the newly zero-initialized pages betweenVirtualAlloc2andtitle_memory_remappedbeforeXMemVirtualAllocreturns.@ashrafsdrop on GitHub · 2026-11-26 15:33 UTC · original
Addressed in
c697424— excellent review and catch on the partial-page UAV window, @fuzeofficlal.Changes
crates/victory-gpu/src/watch.rs,crates/victory-gpu/src/shadow.rs):REMAP_EPOCHcounter inwatch.rs.title_memory_remappedincrements the epoch undertitle_memory_remapping(), andSaved::remappedrecordspage -> remap_epoch(HashMap<usize, u64>).Shadow::writingrecords the current epoch alongside snapshot segments(start, bytes, epoch), andShadowtracksrefreshed_epochfromShadow::update.Tracked::was_remapped_since(page, since_epoch)checks if a remap happened after that snapshot/refresh epoch.watch::write_backandTracked::takenre-verify underMAPPINGusing the captured epoch, so prior remaps no longer drop subsequent valid partial-page copy-backs while concurrent remaps remain strictly synchronized.XMemFreeDefault(crates/victory-hle/src/modules/xmem.rs):XMemFreeDefaultand updated tests to reflect only the write-watched 32-bit reservation path.XMemVirtualAllocallocation window (crates/victory-hle/src/modules/xmem.rs):let _remap = victory_gpu::title_memory_remapping();across bothallocateandtitle_memory_remapped.shadow::tests::unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes: reproduces the unmarked partial-page UAV write after a prior remap, verifyingwritten == 4096andtitle_byte == 0xCC.Verification
cargo test -p victory-gpu --lib watch— 17 passed, 0 failedcargo test -p victory-gpu --lib shadow— 18 passed, 0 failedcargo test -p victory-hle xmem— 15 passed, 0 failedcargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings— cleancargo run -p xtask -- policy— 191 files okgit diff --check— clean@fuzeofficlal on GitHub · 2026-11-26 15:54 UTC · original · requested changes
Re-reviewed
c697424762e8e8be3a9ac12c976488dcf2fcdf1bon Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP,VICTORY_D3D12_DEBUG=1, Rust1.98.1).The three items from the previous pass are cleanly resolved:
copied=4096 written=4096 title_byte=0xccon both RTX 5090 and WARP, matching the newunmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytestest).XMemFreeDefaultis removed and documented as ashortcut:, andXMemVirtualAllocholdstitle_memory_remapping()across allocation and notification (crates/victory-hle/src/modules/xmem.rs:156).xtask policy:191 files ok;clippydefault &--all-featuresclean;victory-hlexmem:::15/15;victory-gpuwatch:: shadow:: list:::38/38on both RTX 5090 + Debug Layer and WARP +diagnostics+ Debug Layer).However, the new epoch tracking in
Shadow::writingintroduces two blocking regressions where stale GPU bytes overwrite a remapped page (both of which safely preserved0x22on the previous head4f47bdcf):1. Blocking: Merging adjacent/overlapping snapshot segments in
Shadow::writingdiscards the earlier segment's epoch (crates/victory-gpu/src/shadow.rs:351,372,379)When
Shadow::writingmerges touching or overlapping ranges:@ashrafsdrop on GitHub · 2026-11-26 16:14 UTC · original
Addressed in 72a7197 — sharp catch on the merge and sampling windows, @fuzeofficlal.
crates/victory-gpu/src/shadow.rs):Shadow::writingmerges adjacent or touching segments (first..last), it takes the minimum epoch among all drained segments via.fold(refreshed_epoch, u64::min), preserving the earliest snapshot epoch across the combined range.Shadow::writingnow initializes its base epoch fromself.refreshed_epoch.load(Ordering::Acquire)rather thancurrent_epoch(). Sinceself.dataholds bytes fromrefreshed_epoch, any remap occurring afterupdatebut beforewritingis caught bywas_remapped_since.shadow::tests::merging_overlapping_snapshot_segments_preserves_earlier_epoch(exercises merge discarding earlier remap).shadow::tests::remap_between_update_and_writing_preserves_new_title_bytes(exercises remap betweenupdateandwriting).Verification:
cargo test -p victory-gpu --lib shadow: 20 passed, 0 failedcargo test -p victory-gpu --lib watch: 17 passed, 0 failedcargo test -p victory-hle xmem: 15 passed, 0 failedcargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings: cleancargo run -p xtask -- policy: 191 files okgit diff --check: clean@fuzeofficlal on GitHub · 2026-11-26 16:20 UTC · original · approved these changes
Re-reviewed
72a719727c27eff7ce5ff02b623b9c772762b412on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP,VICTORY_D3D12_DEBUG=1, Rust1.98.1).Both blocking regressions from
c6974247are cleanly fixed:crates/victory-gpu/src/shadow.rs:351,:364:Shadow::writingnow anchors new snapshot segments toself.refreshed_epoch.load(Ordering::Acquire)rather thancurrent_epoch()and folds merged segments withu64::min, closing both theupdate -> remap -> writingwindow and the touching/overlapping segment-merge epoch clobber, backed by the two new regression tests (merging_overlapping_snapshot_segments_preserves_earlier_epochandremap_between_update_and_writing_preserves_new_title_bytes).Shadow::refreshed_epochis still shared across all pages of aShadow, so if a future refinement wants per-page isolation when one page is served fromBatch::currentwhile another page in the sameShadowcallsupdate(), switching to per-page refresh epochs can tighten that narrow case too.Verification
cargo run -p xtask -- policy(191 files ok)cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings(default &--all-features)cargo test -p victory-hle --lib -- modules::xmem::: 15/15 passedvictory-gpuwatch:: shadow:: list::withVICTORY_D3D12_DEBUG=1: 40/40 passed on RTX 5090; 40/40 passed (--features diagnostics) on WARP.VICTORY_D3D12_DEBUG=1): prior-remap partial-page unmarked UAV (written=4096, 0xcc), touching-page merge across remap (written=0, 0x22), same-page sub-page merge across remap (written=0, 0x22), and remap betweenupdateandwriting(written=0, 0x22) — all four passed cleanly.@pickles976 on GitHub · 2026-11-26 18:44 UTC · original
Independent Wine verification of updated production head
72a719727c27eff7ce5ff02b623b9c772762b412: 9 targeted shadow lifecycle tests passed, 0 failed/ignored, 0.75 s after fresh 9.16 s compilation from the selected worktree.Environment: Linux, Wine 11.0, Rust 1.98.1 Windows MSVC target, 16 GiB RAM, physical NVIDIA GeForce RTX 4060 Laptop GPU / driver 590.48.1,
DXVK_CONFIG='dxgi.hideNvidiaGpu = False'. vkd3d-proton 3.2.02576c0b4adfae4a+is our diagnostic-relaxed build, not stock certification. Single test thread, 9 GiB memory / 512 MiB swap cgroup limits, 180 s timeout.Only local changes: replace the nine selected fixtures' no-host early returns with panics (including required mark bitmap where used). Production code unchanged. The log identifies the real NVIDIA adapter; missing host buffers cannot silently pass these runs.
The four
remapping_cases, reported free/reallocation, mapping-lock exclusion, partial-page write after an earlier remap, merged snapshot epoch, and remap between update and writing all passed. In particular, the latest three epoch regressions now pass on this Wine/NVIDIA host, supplementing the existing native-Windows feedback.Scope: real D3D12-backed shadow allocations plus Win32 tracking/copy-back semantics. These tests inject bytes into host copies; this is not shader-dispatch, gameplay, or memory-peak proof. No old failure was rerun merely to reconfirm it, and there is no new matched-parent performance comparison. This does not certify every resource release path or imply that an unreported release/re-take is protected; the separate free-side notification coverage discussed in #3077 still needs its own evidence.
Maintainer suggestion: retain the new epoch fixtures and make host availability explicit in hardware CI, so an adapter/allocation failure cannot masquerade as passing remap coverage. The current local nine-line fail-closed strengthening can be reproduced without changing production behavior.
Local log:
.compat-runtime/logs/verify-pr2612-evening-wine-remap.log. No title launch or game assets. AI-assisted verification/source review (OpenAI GPT-6 Astra).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.