Title textures: the write watch scans in a few calls, not thousands #551
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!551
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/551/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?
@duudiis on GitHub · 2026-11-24 01:41 UTC · original
duudiis:pr-watch-gap→main· +22 −9 · 1 files · 1 commits · merged 2026-11-24 10:06 UTCBefore each submit,
title_textures::refreshasks the write watch which pages the CPU wrote. The watched ranges (title textures and mapped sparse tiles) were merged only across gaps under 1 MiB, so on a retail game that streams its world the look made thousands ofGetWriteWatchcalls before every submit. A call costs about 3.5 µs however little it covers, while one call over 2 GiB of committed pages takes about 1.3 ms (a smallGetWriteWatchbenchmark on this machine), so the calls, not the bytes, were the cost: sampling the title's threads during its intro video put the submitting thread at 42 % inGetWriteWatch(on a local build with other changes, not on main).This merges ranges up to 64 MiB apart into one scan. The pages in a gap are reported as written too, which the uploads already tolerate: they keep to the textures and tiles they track. The merged ranges are also clipped to the write-watched regions with a binary search per region instead of a pass over every merged range for each region; both lists run to thousands while a game streams.
I searched open and closed PRs for "write watch", "WATCH_GAP", "watch_ranges" and "GetWriteWatch calls" first. #486 (skip unchanged uploads) and #440 / #451 / #455 / #458 / #465 (faster detile and upload) work on the uploads after the look; none of them changes the look itself, so this should stack with them.
What is in it
crates/xcl/src/hle/d3d12x/title_textures.rs:WATCH_GAP1 MiB → 64 MiB (with the measurements in its comment);watch_rangesclips withpartition_pointper region;watch_ranges_clip_and_mergechecks the new gap, a merged range over two regions given in either order, and a region between and past the merged ranges.Tested
cargo build --workspacethencargo test --workspace --release -- --test-threads=4on712bbbe: 677 passed, 0 failed, 41 ignored (lib 637 / 0 / 21).gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).scripts/smoke.ps1 -Seconds 60, main and this PR in turns, five pairs (frames shown, main → PR): 469 → 536, 561 → 369, 555 → 524, 547 → 556, 944 → 1517. No device removal or crash in any of the ten runs; the PR's peak commit was at or below main's each time (14,604 – 15,067 MB vs 15,057 – 15,962 MB).Regression run
main:
this PR's head:
Not tested
AI use
GetWriteWatchbenchmark, wrote the change, its test and this description. I ran the tests and the smoke runs on the hardware above.@thehollowedone on GitHub · 2026-11-24 01:44 UTC · original
I checked the boundary where a merged range produces more dirty pages than the 16,384-entry buffer. A scratch test used XCL’s
watch_rangeson a Windows write-watch allocation with two one-page ranges separated by just under 64 MiB. They merged into one range. After writing all 16,385 pages, repeatedGetWriteWatchcalls with reset reported 16,384 pages, then 1, then 0. The returned addresses matched every written page exactly once. Tested commit 712bbbeWith the scratch test added,
cargo test --offline --locked -p xcl --lib watch_ -- --test-threads=1 --nocapturereported 2 passed, 0 failed, 0 ignored, including the PR’s range test. Windows 11 build 26300, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug. This run checked clipping and the Windows reset batches. It did not measure upload performance, run the full workspace, or use retail data.AI use
Codex with GPT-6.2 Sol wrote and ran the scratch check and drafted this report.
@Kalmarv on GitHub · 2026-11-24 02:07 UTC · original
One point on the wider gap, not covered by the boundary test above: a write to a page in a merged gap is reset by a look that watches it for nobody. If the page is wanted later, the first look that watches it no longer reports that write. With a 1 MiB gap the same happens only within 1 MiB of a watched range.
The test below, CPU only, on
main508a0c7with this PR (712bbbe) merged:pbetween them;pis written, then looked at once throughwatch_ranges(asrefresh_oncedoes), and then added to the wanted ranges;p.It passes on
mainand fails with this PR:test (in title_textures.rs's tests)
Where XCL relies on that report (from the code on
508a0c7; not run on a GPU):sparse::before_executeuploads only pages of tiles that already have video memory (sparse.rs:1368). Any other page a look reports is dropped, and its watch state has been reset.take_tilefinds no video memory,ensure_mappedstops (sparse.rs:724). The committed pages after that have no tile.place_buffermaps such tiles later (sparse.rs:1458), without copying what the CPU wrote there.MapTitlePhysicalPages, the page's contents are copied toat(kernelx.rs:1198) beforesparse::committed(at)gives its tile video memory (kernelx.rs:1204). A look on another thread between the two reports and resets the copied page and then drops it.pending).Question for @duudiis: does "the uploads keep to what they track" in the new
WATCH_GAPcomment mean to cover tiles mapped after a write? If not, one option is for a tile that gets video memory late to have its CPU pages uploaded at mapping time. That would also cover the 1 MiB case onmain. The other is to keep the 1 MiB gap where a range ends next to committed pages without a tile. I have not tried either.The cost side, on a retail title (RTX 5070 Ti, Ryzen 9 9950X, release, 60 s of the first menus with no input, one run each;
main508a0c7and508a0c7with this PR merged,04d7261):mainms a lookmainand 19 calls over 2,218 MB with this PR. A third run,mainwith only counters added (7a8255c, local), took 0.83 ms in the same phase, so the spread between runs is larger than the difference: no saving here, and no loss either. The title has 69 ranges in this phase; the PR's case is thousands.Tested
main508a0c7: passes;main+ this PR (712bbbe), merge9a6cf82: fails as quoted.Not tested
🤖 Claude Opus 5.5
@duudiis on GitHub · 2026-11-24 02:45 UTC · original
Thanks, both of you. @Kalmarv, you're right: "the uploads keep to what they track" does not cover a tile that gets video memory after its page was written. A look that watches that page for nothing resets its report, and
sparse::before_executedrops pages of tiles without video memory, so the write only reaches the GPU when the page is written again. The wider gap makes that window much larger, and your numbers show no gain onmainto pay for it.I'm turning this into a draft. The fix I'm testing follows your first option: each tile
ensure_mappedgives video memory is noted, and at the nextbefore_executeall of its committed pages go throughscan_page, so only what differs from what the GPU has is sent. That also covers the 1 MiB case onmainand theMapTitlePhysicalPagescopy-then-map race. Its unit test writes a page before its tile is mapped and checks that the page is sent once the tile is mapped, only committed pages are sent, and nothing is sent twice. I'll push it here, with your test and fresh smoke runs, once I can rerun them on the title. Until then the PR stays a draft.AI use: Claude Code with Claude Opus 5.5 checked the review against the code, wrote the fix and its test, and drafted this reply.
@MesshM on GitHub · 2026-11-24 02:46 UTC · original
Test run of
712bbbe4e5163b5fe479cccfa0b3ff636ecf8fd8on AMD RDNA4; the PR was tested on NVIDIA only. I merged it onto currentmain3db536elocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 686 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 646 passed, 0 failed, 21 ignoredSKIPPED;watch_ranges_clip_and_mergepasses.Review: The new loop gives the same pieces as the old one: each region looks up the first merged range ending after its base and takes those starting before its end, so every piece stays inside one region, now with a binary search instead of a pass over all merged ranges per region. A question rather than a finding:
refreshcallsGetWriteWatchwithWRITE_WATCH_FLAG_RESET(title_textures.rs:687), so with 64 MiB gaps the pages in a gap get their write bits reset too. That is fine for pages nothing tracks yet only if whatever starts tracking them later (a texture placed there, a sparse tile mapped there) uploads its contents fully at that point rather than relying on earlier write-watch bits. I did not trace every path that starts tracking, so I cannot say it always does.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@Chrysana on GitHub · 2026-11-24 02:48 UTC · original
Test report for
712bbbeon an AMD GPU and an AMD CPU, which Not tested lists: no regression, and no measurable gain on this machine, wheremainalready holds 30 fps through the intro video.Setup: AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008, AMD Ryzen 7 9800X3D, 31 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.0
x86_64-pc-windows-msvc, DXC 1.9.2602.17. Retail title 1.0.2.1. Debug build for the tests, release builds for the runs.Tests:
cargo test --workspace --no-fail-fast -- --test-threads=4at712bbbe: 677 passed, 0 failed, 41 ignored, the same counts as in the description.SKIPPED: the two debug-layer tests (the D3D12 debug layer isn't installed here).Title runs:
scripts/smoke.ps1 -Game <folder> -Seconds 60withXCL_PRESS_A_AT=14,17,21, same saved state.712bbbe's base7ebf1b8doesn't have #451, so it was also merged ontomain9ce2070(clean, local mergeeba6025, not pushed):main9ce2070712bbbemerged onto9ce2070712bbbe(its own base, video at ~6 fps without #451)main, so a cost the change removes can't show in frames here. I have no direct measure of the time inGetWriteWatchfromtitle_textures: XCL'ssparse windows timing: write-watchlog line is the sparse-window path, which this PR doesn't change.Regression run:
main:PR merged onto
main:PR head:
Not tested: the time spent in
GetWriteWatchitself (no profile taken); world streaming past the intro; Kalmarv's point about writes in a merged gap.AI use: Claude Code with Claude Opus 5.5 built the commits, ran the tests and the title runs, read the logs, and wrote this report. The runs were made on my machine.
@Kalmarv on GitHub · 2026-11-24 02:59 UTC · original
@Chrysana, thanks for the AMD runs. One correction: the
sparse windows timing: write-watch N ms (M dirty pages)line is this PR's own look.refresh_oncetimes itsGetWriteWatchloop (title_textures.rs:673–700at712bbbe) and records it withsparse::note_watch(sparse.rs:1339; printed atsparse.rs:1410). So that line onmainagainst the PR is the direct measure of the call-count change. Our per-look numbers on an RTX 5070 Ti are in the review above. On the first menus (sparse submits 1024 → 4096) a look took 0.94 ms onmainand 0.96 ms with this PR, within the spread between runs.🤖 Claude Opus 5.5
@iggyvilla on GitHub · 2026-11-24 05:30 UTC · original
Test report for
712bbbe4e5163b5fe479cccfa0b3ff636ecf8fd8on an AMD RDNA2 card (Navi 23), testing the current draft head against its merge base7ebf1b8044bef8f0ef296eb36e85010cceb4633a(not merged onto currentmain).Tested
stable-x86_64-pc-windows-msvc; noXCL_SAMPLE_*set.712bbbeand base7ebf1b8.cargo build --workspacethencargo test --workspace --no-fail-fast -- --test-threads=4on712bbbe(debug): 674 passed, 3 failed, 41 ignored, exit 101.xcllib: 634 passed, 3 failed, 21 ignored.placed_title_textures_share_vram_and_preserve_pixels(3D 64x64x64 4 mips: subresource 2 mismatch, #470) and twoPoisonErrorcascades it causes intransitions_apply_when_their_list_is_submitted(title_textures.rs:1327) andd32s8_targets_take_their_own_size_of_video_memory(vram.rs:778, fixed by #673). The PR adds no failure.SKIPPEDlines at this head on this card.scripts/smoke.ps1 -Seconds 60withXCL_NETWORK=0, base and head built release from their own worktrees, two pairs (base → head, then head → base):7ebf1b8frames712bbbeframesAll four runs: exit
0x0, 0 device removals, 0 crashes, onAMD Radeon RX 6650 XT. Head is at or above base in both pairs within normal run-to-run variance; peak commit is within 5 MB. No regression is measurable here.sparse windows timing: write-watchon the last log line of pair 2: head1984 ms (274779 dirty pages)(787 frames), base1957 ms (268066 dirty pages)(751 frames) — a 1.4 % difference, within noise. These 60 s runs end on the start screen / loading before the intro video (~2.6 GB watched), so the call-count saving is not exercised yet; this run checks only that nothing regresses.Base block (pair 1):
Head block (pair 1):
Not tested
main; head and base were tested on7ebf1b8.AI use
opencode with DeepSeek V4.1 Flash (
opencode-go/deepseek-v4.1-flash) ran the build, the tests and the smoke runs and drafted this report.@milas6669 on GitHub · 2026-11-24 06:01 UTC · original
Regression run of
712bbbe4e516(PR head, built as it is, not merged onto main) againstmaine50836b, on a retail title.Tested
scripts/smoke.ps1 -Seconds 60, the same title and time for both, one run each, main first:main (
e50836b):this PR (
712bbbe):What this does and does not say
Not tested
cargo teston this head (I did not run the test suite for this report)AI use
@milas6669 on GitHub · 2026-11-24 06:47 UTC · original · edited 2026-11-24 06:53 UTC
Correction: please disregard the speed-up and write-watch numbers in my first version of this comment. I attributed them to this PR and that was wrong. The earlier text is replaced by what I can actually support.
I ran this PR merged onto
mainbeaa245(clean merge, onlytitle_textures.rsdiffers) on a retail title, and compared it withmainbeaa245without the PR. The firstmainrun was the one that looked slow. I then ran the samemainbinary again (checked byte for byte), and it behaves like the PR build.Tested
XCL_NETWORK=0,scripts/smoke.ps1with 600 s (main) and a memory watchdog that kills the run at 24 GB (PR) / 27 GB (main, second run)sparse windows timing)main, 1st run (after a rebuild)main+ this PRmainagain, same binary as the 1st runmaintoo, when it is run again. They come from something that differs between the first run after a rebuild and the later runs, most likely the on-disk translation and driver pipeline caches being cold the first time; I did not confirm that. They do not show anything about this PR, and I cannot say from these runs whether the PR changes the write-watch cost at all.mainalone passes 27 GB (13.8 GB of local video memory on an 8 GB card) in the same way. That is the title's memory use once it gets further than the slow first run does, and it looks like what #560 / #542 describe.Not tested
cargo teston this head; AMD / wave64 hardware; visual correctnessAI use
@AlexLopezDevelop on GitHub · 2026-11-24 09:55 UTC · original
Tested on RTX 2080 Ti (Turing, driver 621.24) + Intel i9-9900K, Windows 11, 32 GB, retail 1.0.2.1, merged onto #891 + #631 (
XCL_PSO_WAIT_MS=50), DXC 1.9.2609, first-run setup walked by hand. One run each, so treat the numbers as indicative.600 frames presented, 6.8 fps over the last 300with this PR, against 2.0-4.0 fps over the same part of the walk on #891 + #631 without it (and 3.4 fps onmain). The window caption showed 6 fps through the menus, where it showed 2-3 before.+0x23cf683), as in my #582 follow-up, so on this machine that sparse-window look is what remains; no crash in XCL itself.Not tested: the full
cargo testsuite; asmoke.ps1pair (an unattended run stays before the first-run setup).AI-assisted (Claude Code, Claude Opus 5.5).
@ivall on GitHub · 2026-11-24 10:06 UTC · original
Merged (
02bfd1d), from the draft: AlexLopezDevelop's run shows the menus going from 2-4 to ~6.8 fps on a CPU where the look dominates, and it stacks with #693. Checked on main02bfd1dtogether with #891, #693, #551 and #631:cargo test --workspace -- --test-threads=4green (685 lib tests), and a retail run through the menus and intro into the start of the world load withXCL_PSO_WAIT_MS=50: no crash, no device removal.