GPU: leave shader writes to large write-combined buffers on the card (VICTORY_WC_NO_BACK, port of NVIDIA), fixes the #90 spikes #462
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
needs-logs
old-names
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!462
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-462"
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?
@cafeoh on GitHub · 2026-11-29 23:32 UTC · original
cafeoh:pr/wc-no-back→main· +60214 −5433 · 206 files · 661 commits · closed without mergingFixes the "spikes" of #90 (one-frame stretched triangles on characters) and makes frames faster.
What
XMemVirtualAllocnow records memory the title reserves write-combined (0x400), and forgets it when freed or decommitted. WithVICTORY_WC_NO_BACK=1, what shaders write into a card copy that lies wholly in such memory and is at leastVICTORY_WC_NO_BACK_MIN_KBlarge is not declared, compared, fetched or copied back into title memory: the title's CPU does not read write-combined memory, so the card's copy is the truth.scripts/play.ps1turns it on withVICTORY_WC_NO_BACK_MIN_KB=1024.50c15a145+2f81d0c85(GPL-3.0); their launcher has it on.VICTORY_WC_BARis not ported.Why it fixes #90
With submissions sent ahead, a flight's copy-back of the skinning output (~25 MB, write-combined) can land after the title has already written the next frame's data into the same memory. That one frame of mixed old and new data is the spikes. With no copy-back for these buffers there is nothing late to land.
Evidence (RTX 2080 Ti, Ryzen 7 7800X3D, Windows 10, Series S, RT on)
VICTORY_WC_NO_BACK=0alone, the spikes come back.https://github.com/user-attachments/assets/990936ca-9a5d-445c-981d-30467e6d855c
Speed (scripted runs, warm caches, one change only)
fe7c6e5+ this PR), last 60 sKnown limits
VICTORY_WC_NO_BACK_MIN_KB=0(every size left on the card) breaks things: small write-combined buffers the CPU does read, or that share 4 KiB parts with CPU writes, stay wrong (broken meshes that persist; NVIDIA saw dark cutscenes). The launcher uses 1024.Checks
cargo build --release(0 warnings), both CI clippy variants with-D warnings,cargo test -p victory-gpu -p victory-hle(incl. the new registry test).@Kal0s-design on GitHub · 2026-11-30 00:00 UTC · original · reviewed
Read the diff against main and ran it here (Windows,
victory-gpulib tests, clippy with--all-features): clean, 529 passing. One correctness gap in the registry, with a test and a small fix.A write-combined commit inside a plain reservation outlives the reservation.
title_memory_write_combinedrecords whatXMemVirtualAllocreturns, so aMEM_COMMITwith0x400inside a reservation made without it is recorded as its own region, starting inside the reservation. On release,title_memory_freed(at, 0)callswrite_combined_freed(at, 0), which drops only regions withfrom == at. The inner region stays. If another allocation later takes those addresses without0x400, its copies count as write-combined and their shader writes are left on the card. That's the failure this switch must never cause: the title's CPU reading stale bytes in memory that isn't write-combined.Repro (fails on this branch with "stale after the reservation's release"):
Fix:
title_memory_freedalready finds the allocation's extent for a release (allocation_end, beforeVirtualFree). Forget write-combined regions over that extent instead of passing the 0:With that change, the test above and NVIDIA's
write_combined_regionsboth pass, the 529 lib tests pass, and clippy is clean. Rounding a decommit up to a whole 64 KiB block can only forget more, which falls back to the copy-back.Whether GTA VI actually commits write-combined inside a plain reservation, I haven't checked. With
VICTORY_WC_NO_BACKon by default inplay.ps1, I'd still close the hole before it lands. Smaller notes, not blocking:Shadow::wcis found once per copy and kept. That's fine as long as a copy never outlives the memory it was made for, which I believe holds here, since copies go with their buffers.XMemVirtualAlloc) is never recorded, so it keeps the copy-back. That's the safe side.AI-assisted: yes
@cafeoh on GitHub · 2026-11-30 00:25 UTC · original
@Kal0s-design Thanks, confirmed and fixed in
320d657be:title_memory_freednow finds the freed extent first and forgets write-combined regions over all of it. Your test is in and passes, with NVIDIA'swrite_combined_regions. I haven't checked either whether GTA VI commits write-combined inside a plain reservation. Agreed on both notes: copies go with their buffers, and views the title maps keep the copy-back.@Kal0s-design on GitHub · 2026-11-30 01:00 UTC · original
Checked
320d657b: thetitle_memory_freedchange and the test are what I ran here, and CI is green on it. Nothing further from me on this PR.AI-assisted: yes
@Garu667 on GitHub · 2026-11-30 02:06 UTC · original
Tested on an RTX 3080 10 GB (Windows 11, Series S profile, DLSS quality, 1080p output), on our local tree with both commits cherry-picked cleanly. Scripted prologue runs, warm caches, alternating off/on, only this switch changed (
VICTORY_WC_NO_BACK_MIN_KB=1024when on):Better in all three pairs, prep time down 6-10 ms per frame. No new image defects seen in the captures we checked. Thanks for porting this!
@Indy2l on GitHub · 2026-11-30 04:05 UTC · original
Tested on RTX 3060 12 GB, i5-12400F, 16 GB, Windows 11, driver 621.40, Series S,
-Machine 3060, ray tracing off, prologue (prison) route. Build:fe7c6e5+ #395 (static samplers in one order, so the pipeline cache stays warm between launches) + this PR's two commits, withplay.ps1'sVICTORY_WC_NO_BACK=1andVICTORY_WC_NO_BACK_MIN_KB=1024. Seven runs on the one executable: four with the switch on, three with-More @{VICTORY_WC_NO_BACK='0'}. All recorded; recordings stay local.Speed, as you found: standing still at the cell window, 14.25 fps against 12.5 without the PR (same base, an earlier run). Walking to the crowded room, 12.2 against about 10.3-11. The copy-back fell from 37-38 ms to 17-19 ms a frame. Memory unchanged.
Spikes: with the switch on, the stretched triangles that are all over the inmates in the crowded room without it were mostly gone. In one run a single large stretched spike showed for a fraction of a second; I can't tell whether it was the same kind. With the switch off on the same executable they were back as before.
Probably caused by the switch, intermittently: the inmates' clothes. In 2 of the 4 switch-on runs, every orange prison jumpsuit, the player's and all the inmates', looked dark red-brown, glossy and blotchy, as if wet, with the "INMATE" print on the back hard to read. When it happened it was there from the cell onwards and stayed, at least to the crowded room about 4.5 minutes later; in the other two runs the clothes were normal throughout. In the 3 switch-off runs on the same executable, and in every run we've made without the PR, the jumpsuits were normal, matte orange. Seven runs aren't proof, and this PC also has textures that arrive late and wrong for a while, but the split points at the switch. It would fit your third listed risk, with timing deciding it: another host copy of the same bytes (a texture placed in that memory, say) made from the bytes before the shader writes that stay on the card. If that's it, a larger
VICTORY_WC_NO_BACK_MIN_KBwouldn't help, since copies are 4 MiB windows or larger. I can run a build that logs overlaps between ranges left on the card and other host copies on this route, if that helps.AI-assisted: yes
@Indy2l on GitHub · 2026-11-30 04:45 UTC · original
A correction to the clothing part of my report above: the link to this PR is weaker than I said.
I ran three more switch-on runs on the same base, with local logging added on top of this PR. The logging recorded:
All three runs had normal clothes, so the tally is now 2 of 7 switch-on runs with the wet-looking jumpsuits, against 0 of 3 with the switch off. In all three logged runs, the only overlaps were the written buffers themselves: no texture and no second card copy over memory whose writes stayed on the card. So your third listed risk doesn't show up on this route, and the clothes may well be an unrelated texture problem that happened to land on two switch-on runs. Speed and the spikes stand as reported.
AI-assisted: yes
@cafeoh on GitHub · 2026-11-30 07:12 UTC · original
Thanks both, and thanks @Garu667 for the three pairs.
@Indy2l: we see glossy, blotchy materials too (faces mostly), and we had them long before we tried this switch, so I'd also call the jumpsuits a separate texture problem. Two things that caused it here:
VICTORY_PRELUDE_RECHECK=1: a "texture upload over a host write" warning), and their commite530c00fixes it (VICTORY_UPLOAD_GUARD=1+VICTORY_PLACED_COPIED=1). With both off we got clear garbage on a face in the café; with them on, none in our runs since. Neither is in Vice-Tay main yet.If the recheck warning fires in a run where the jumpsuits turn, that would point at the first one.
AI-assisted: yes
@TaynanGT on GitHub · 2026-11-30 17:05 UTC · original
mainhas moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the currentmainand open a new PR; I'll review it there.@Indy2l on GitHub · 2026-11-30 17:45 UTC · original
Thanks, that matches what we see: the three switches you named are on by default on the new
main, and none of our earlier runs had them, so we'll watch whether the jumpsuits ever turn again.One thing from this PR didn't make it into the new
main: your follow-up commit 8f4e0a95 (a write-combined commit inside a plain reservation is forgotten with the reservation, found by Kal0s-design, with their test).watch::title_memory_freedstill passes the release's length 0 on toshadow::write_combined_freed, which then only drops regions starting at the allocation base. WithVICE_TAY_WC_NO_BACK=1now on by default, a stale region left there would keep shader writes on the card for whatever memory comes next at that address.The commit replays onto current
mainalmost unchanged (only the test's calls neededcrate::shadow::paths); the test fails without the fix and passes with it. Would you like to open it as a new PR yourself? If you'd rather not, I can open it with you as the commit's author and Kal0s-design credited.AI-assisted: yes
@cafeoh on GitHub · 2026-11-30 17:53 UTC · original
Thanks for checking and replaying it. Yes, please open it, with the commit under my name and Kal0s-design credited for finding the bug and for the test. I looked at the current
maintoo:write_combined_freedwith length 0 still only drops a region that starts at the allocation base, so a write-combined commit inside a plain reservation stays registered after the release, as you say.#357 can stay closed: we no longer use that merge.
Pull request closed