feat(perf): page-granular texture detile for watched memory #489
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!489
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-489"
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?
@cerealfordinner on GitHub · 2026-12-04 18:19 UTC · original
cerealfordinner:pr-texture-detile-fix→main· +22 −12 · 2 files · 2 commits · openOnly detile texture levels whose hashes actually changed, instead of detiling the whole texture whenever any page is written. Uses the existing refresh_levels() infrastructure that already tracks per-level hashes and versions. Falls back to full detile when constraints aren't met (non-Tex2D, >32 footprints, etc.).
Note: on real write-watched memory this path still takes the whole-detile fallback.
refresh_levelsneedsinplace::texture_stampfor every level, and that only answers when runtime section views cover the whole range;GetWriteWatchrefuses view ranges. Untiltexture_stampcovers watched allocations this is correctness-preserving groundwork with no perf change in the watched case.Signed-off-by: cerealfordinner [email protected]
@Kal0s-design on GitHub · 2026-12-04 19:03 UTC · original
Checked
3fc3ab4on native Windows (one NVIDIA desktop card plus WARP, real GetWriteWatch, didn't run the game).cargo test -p victory-gpu --libis the same here as on main. 348 pass on both, and the same 5 fail on both, all of them ones that already fail natively for me (the twoindirect::host_list_*, the twopipeline::hostlibrary loads, one watch test).As far as I can tell the new branch never runs on real write-watched memory.
refresh_levelsneedsinplace::texture_stampfor every level (texture.rs:1708), and that only answers when runtime section views cover the whole range (inplace.rs:586). GetWriteWatch only works onMEM_WRITE_WATCHallocations, and those aren't views. A view range can't get into the ahead journal either, because GetWriteWatch refuses it (watch.rs:681, 1003). So the watched path always getsLevels::Wholeand does the old whole detile.I tested it with a throwaway test. It sets up a tiled 1024x1024 BC7 Tex2D with 11 mips (6 of them in the tail) in write-watched memory and writes into mip 0, mip 1, mip 3 and the tail. I ran it with and without
ask_once, and also with the texture asked together with other ranges. Every write still copies and detiles all 1,400,832 bytes, the same as main, and the staging buffer matches a full detile. NVIDIA and WARP with the debug layer give the same result.If the branch did run, I think it would be slower than main. texture.rs:1864 resets
lastwheneverlast.levelsisn't empty, andrefresh_levelsalways fillslast.levels(1714). So after oneDone, every later check starts withaskedat 0 and no level hashes, skips the "nothing written" return at 1867, and copies, hashes and detiles every level again. I forced the branch by also registering the write-watched range as a runtime view in the test. On this branch it read 1,400,832 bytes and marked every level dirty on all 9 checks, including the 4 with nothing written. Main read 0 bytes on those 4. Because of that reset I couldn't check whether a write to only one level, or only to the tail, gets detected on this path.One more thing, from reading only.
previousislast.askedafter it has already been set tonow(1870-1871). So thecleantest inrefresh_levels(1725) treats every written page as clean. The reset hides this right now. But if someone fixes only the reset, writes could get skipped. The view branch passes the oldaskedand setsasked = nowonly afterDone(1904-1906).The
[profile.perf]fat LTO change in Cargo.toml isn't related to the rest of the PR. I'd split it out.AI-assisted: yes
@cerealfordinner on GitHub · 2026-12-04 22:15 UTC · original
Thanks for the detailed review — all three points are fixed in this branch now:
Watched path never triggers — confirmed the cause:
inplace::texture_stampneeds every page covered by runtime section views, andGetWriteWatchrefuses view ranges (watch.rs:749). On real write-watched memory this path still can't run untilinplace::texture_stampitself covers watched allocations; that's outside this PR's scope, but nothing regresses here.Performance regression — removed
if !last.levels.is_empty() { *last = Last::default(); }from the write-watch path (texture.rs:1864). Level hashes now persist across checks, so levels with nothing written since the last refresh skip via the "nothing written" early return at 1867 instead of re-detiling everything.clean-test bug — capture
let previous = last.asked;beforelast.asked = now;and pass it asprevioustorefresh_levels(...), so the clean test compares writes against the previous asked watermark rather than the current one.Unrelated Cargo.toml change — dropped the
[profile.perf]fat LTO block from Cargo.toml entirely.Build passes (
cargo build --release -p victory, exit 0, warnings only).Pushed to
cerealfordinner:victory-xmem-hw-rt@pr-texture-detile-fix.Signed-off-by: cerealfordinner [email protected]
@Kal0s-design on GitHub · 2026-12-04 22:20 UTC · original
Read
cad3ed4, thanks. The two fixes look right to me.previousis now taken beforeaskedmoves, the level state survives between checks, and the Whole arm clearslevelsafter a full detile so a later partial refresh doesn't trust stale hashes. The perf profile is gone too.I didn't rerun it, because as you say the new arm still can't be reached on write-watched memory, so on the path the PR targets it does the same work as main. Maybe say that in the description until
texture_stampcovers watched allocations, so nobody expects a saving from it yet.AI-assisted: yes
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.