D3D12.X: XCL_WINDOW_STATS logs each memory window's traffic #3627
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3627"
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?
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T01:05:59Z.
(Edited: head
60b0c1672, rebased onmain395405e4c: #3702 replaced the staged-copy list insubmit_upload, so the upload counts now come from itsUploadCopyjobs (window and bytes).cargo test -p xcl --libunder Wine on the CPU, the touched modules: 190 passed, 0 failed, 3 ignored.)(Edited: head
bdec29f9ftakes the second reviews:XCL_WINDOW_STATSuses the UMA region only once it exists,0is off, and an address range counts as outside when it runs past its run of adjacent windows of one kind (a root view, whose size is not known, is placed by its start). Onmain38ad22da.)An address the title gives the GPU outside every memory window is no GPU memory, and nothing said so (#3565: with 4 windows the title's GPU views lay outside them). With
XCL_WINDOW_STATS=<seconds>, every that many seconds XCL logs a line for each memory window and one for the addresses given to the GPU outside every window, by path; the first 8 of each path are logged with what lies there. Off by default; then each counter is one load. Nothing is remapped.What is in it
hle/d3d12x/window_stats.rs(new): per window its kind, range, bytes with memory on the GPU, and since the line before the bytes uploaded, the pages the write watch found written, the bytes read back and the GPU-view tiles filled; perview_want::Paththe addresses outside every window, the first 8 placed (a GPU view of the title's memory, a graphics reservation, plain memory, nothing committed). Relaxed atomics, a logging thread started fromhost.rs.sparse.rs(uploads, copy back, view tiles filled;mapped_by_window),title_textures.rs(pages the write watch found),view_want.rsandbind.rs(addresses outside every view window, root views).README.md: the switch.Tested
bdec29f9f: Under Wine on Mesa's CPU Vulkan driver, release, 1 run:window_stats5 passed, 0 failed;cargo test --lib -- window_stats file_reads write_log shader_mem console_heap eh::at the top of the stack (#3642,f1ae90ebb): 62 passed, 0 failed.zero_seconds_is_offand the outside-range case oftraffic_adds_to_its_window_and_addresses_in_one_are_not_outsidefailed without the fix.5653fd69, with an earlier version of this PR's commit, before the second review's fixes):cargo test --workspace -- --test-threads=4, 2,931 passed, 0 failed, 51 ignored, 1 run; 28SKIPPEDlines (wave64 tests: no wave64 on this card; heap-window tests withoutXCL_HEAP_WINDOWS=1; no D3D12 debug layer). The stack's GPU tests (gpu_mem_stats_*, the writer and geometry-pass tests) ran and passed.x86_64-pc-windows-gnu, release. Tests under Wine on Mesa's CPU Vulkan driver (no card: the card was running a title).cargo check -p xcl --release --target x86_64-pc-windows-gnu, with and without--tests: no errors, no new warnings.cargo test -p xcl --release --target x86_64-pc-windows-gnu --lib -- --test-threads=8 window_stats view_want hle::d3d12x::bind sparse title_textures gpu::uma: 361 passed, 0 failed, 2 ignored; 3 GPU tests printedSKIPPED: no GPU. The new tests place addresses in the 16- and 4-window layouts and check the lines.XCL_SHADER_MEM_STATS(stacked after this), its lines and placement table showed a 1.34 GB GPU heap in a coherent window (system memory) that shaders read far more than the CPU wrote it; #3619 moves that heap to video memory.Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
AI use
mainand made the title runs.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T01:11:51Z.
Review (head
9a0ac0a5, diff read, not a merge-check; draft, checks red):window_stats::uploaded(runs)is called whenupload_dirty_with_timeoutstarts (sparse.rs~4559), before the!uploads_orderedreturn, before theXCL_SPARSE_LAZYstarved runs are dropped (~4593), and before theWait/RetryRequiredreturns (~4580, ~4612, ~4630, ~4665). A run that getsWaitis scanned and sent again later (continue 'prepare~5541,retry_journal~7997), so the same bytes are counted twice and the per-window upload figure this PR exists to supply is too high under upload pressure. Counting what goes into a submitted batch (submit_upload/staged) avoids it.copy_back(~4252) counts the wholelenon entry, while the loop below leaves outLAZYtiles, holes and tiles whosegenchanged.place()and the line formatting; nothing checks which slotcount,given,uploadedorwrittenadd to, thatgivenignores an address inside a window, or thatlog/mapped_by_windowadd up per window.xcl-smokeblocks (the reasonPR descriptionis red), and Tested is a filtered--librun under Wine.Fine: off by default, each hook is one
OnceLockload when off, andwant_view/want_root_viewsreturn the same results as before;place()is right for the 4- and 16-window layouts; the sparse lock is taken throughlock_state/holdinglike the module's other readers.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T02:55:48Z.
Thanks. Fixed at
4e2d2887b: KB up counts the copies of a submitted upload (submit_upload, after the submit succeeds), KB read back counts whatcopy_backlands, and two tests cover the counters' slots,giveninside a window, and the per-window lines and mapped sums. #3628 is rebased onto it (bc55ba1fe) with no other change.AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T03:00:17Z.
Follow-up review (head
4e2d2887, since9a0ac0a5, diff read, not a merge-check; draft):submit_upload(sparse.rs~4762) countsstagedonly whensubmit_dirty_batchreturnsOk, so copies dropped by aWait/RetryRequiredreturn or by the starved-run drop are not counted.copy_back(~4267) counts each page inside the branch that lands it.traffic_adds_to_its_window_and_addresses_in_one_are_not_outside(window_stats.rs~255) andmapped_bytes_add_up_per_window_without_lazy_tiles(sparse.rs~11345) cover the slot choice,given_in,linesandby_window.xcl-smokeblocks are in (1665 vs 1620 frames, peak commit 111 %), andPR descriptionpasses; Tested is still a filtered--librun under Wine, not the whole suite on a GPU.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T11:15:03Z.
merge-check
base:
1c8b551475head:
4e2d2887b4merge: clean (fast-forward onto base, commit
4e2d2887b4, git diff --check clean)build: cargo build --workspace ok; cargo build --release -p xcl ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture (43 targets): 2914 passed, 0 failed, 51 ignored (+5 new tests vs main baseline). All 5 new unit tests passed with 0 skips: hle::d3d12x::sparse::tests::mapped_bytes_add_up_per_window_without_lazy_tiles and all 4 hle::d3d12x::window_stats::tests (an_address_is_placed_in_its_window_or_none, a_view_address_with_four_windows_is_in_no_window, traffic_adds_to_its_window_and_addresses_in_one_are_not_outside, the_lines_name_the_window_and_the_paths_outside). 28 SKIPPED lines (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)).
review: Read the full merged diff (+367/-7 across README.md, host.rs, and 6 files in crates/xcl/src/hle/d3d12x/). Adds opt-in
XCL_WINDOW_STATS=<seconds>(parsed with.max(1)into aOnceLock<Option<u64>>, off by default so no background thread spawns and every hook short-circuits in one branch). Counts per-window uploads, written pages, readbacks, and filled view tiles using relaxedAtomicU64counters plus out-of-window GPU addresses byview_want::Path(logging the first 8 per path with region classification). Insparse.rs, iteratingstaged.iter()beforesubmit_dirty_batchand callingstaged.clear()unconditionally after recordingwindow_stats::uploaded(staged)onOkpreserves cleanup without early-return leaks, andby_windowexcludesLAZYtiles cleanly underlock_state(). The 5 new unit tests verify 16-window and 4-window placement, traffic/outside deltas, line formatting, and lazy-tile exclusion. No scope creep, lock-order issues, or UB.performance: Paired 60 s retail smoke (title: 29640639): default (unset) 1654 frames (+13.1% vs
1c8b5514baseline 1462 frames), 14630 MB peak commit (-8.8% vs 16043 MB), 0 removals, 0 crashes; opt-inXCL_WINDOW_STATS=101655 frames, 14604 MB peak commit, 0 removals, 0 crashes (livexcl.logconfirmed startup banner, 10 s periodic lines for windows 0..3 and outside-every-window traffic, plusviews by addressoutside-window entries).Default (
XCL_WINDOW_STATSunset):Opt-in (
XCL_WINDOW_STATS=10):verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:46:53Z.
Follow-up review (head
4b7c148b, since4e2d2887, diff read, not a merge-check; checks red):git range-diffshows the own commit identical to the previous one; this push only rebases the stack onto the currentmain.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:30:42Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:04:22Z.
Follow-up review of
2580976a, since4b7c148b(code reading only, not a merge-check;PR descriptionred) · 1 mediumIn short: This push reworks the PR's own commit:
XCL_WINDOW_STATS=0now turns the stats off;uma::existing());The new end check also counts ranges that are inside the memory windows: ranges that cross between two adjacent sparse or view windows, and root views near a window's end, checked against an assumed 64 KiB. The smoke blocks name
4b7c148b, and the whole-suite GPU run predates this push (PR descriptionis red).Medium
Ranges that cross between windows of the same region count as "outside every window".
given_in(window_stats.rs~111) treats a range as inside only when its first and last byte fall in the same 4 GiB window index.uma.rs~440: "one contiguous range of 11.5 GiB"). GPU views can cross view windows too. A view or copy crossing a 4 GiB line inside a title reservation is then logged as "only its start does, in window 0".want_root_views(bind.rs~1615) passesROOT_VIEW_BYTES(64 KiB), an assumed size, so every root view in the last 64 KiB before a 4 GiB line, or of the coherent window's committed bytes, is flagged the same way.Fix: accept an end in the same run of adjacent windows of one kind, and check only the start of root views. Add a test with a range that crosses from window 0 into window 1.
Checked and fine
submit_dirty_batchreturnsOk(sparse.rs~4765).traffic_adds_to_its_window_and_addresses_in_one_are_not_outsideandmapped_bytes_add_up_per_window_without_lazy_tiles.everyreturnsNonefor0and for text that is not a number (zero_seconds_is_off).on()andlog()useuma::existing(), so the stats never create the UMA region.end - 1is counted, one atend - 2is not.givenstill returns early for address 0, and the end arithmetic cannot overflow.OnceLockload when off.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:32:28Z.
Right: the sparse windows hold one contiguous title reservation, and root views pass an assumed 64 KiB. Fixed at
bdec29f9. A range is inside when its last byte lies in its start's window or in the windows of the same kind that run on from it without a gap (in_run,window_stats.rs). A root view is placed by its start alone. The test now has a range from window 0 into window 1 (inside), from sparse window 2 into the coherent window and past the last view window (both outside), and a 64 KiB root view at the coherent window's last byte (inside). It failed without the fix, 1 run under Wine.AI use: Claude Code (Claude Opus 5.5) made the changes and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:33:33Z.
Follow-up review of
bdec29f9, since2580976a(code reading only, not a merge-check;PR descriptionred) · no new findingsIn short: This push fixes the window-crossing count from my last review. A range now counts as inside when its last byte lies in the same window or in the adjacent windows of the same kind that run on from it (
in_run,window_stats.rs). A root view, whose size is not known, is placed by its start only. The test covers ranges crossing 0→1, 2→3 and past the last window. The smoke blocks name4b7c148b(PR descriptionis red).Checked and fine
in_runacceptslastin windowsk..=endwhen every window in between has the same kind and is full-size (u.window(j).1 == WINDOW), so a reservation spanning sparse or view windows counts as inside.Path::RootViewnow useslast = va.XCL_WINDOW_STATS=0,uma::existing()) are unchanged.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T02:33:59Z.
Follow-up review of
60b0c167, sincebdec29f9(code reading only, not a merge-check) · no new findingsIn short: This push rebases onto
main, where the sparse upload now buildsUploadCopyjobs. The window statistics follow it:uploadedtakes(address, bytes)pairs and is fed fromjobsaftersubmit_dirty_batchsucceeds. Nothing else changed (git range-diff), and nothing blocks it.Checked and fine
UploadCopy::windowis the title address of the copy (sparse.rs~4678, ~4840), soadd(u, a, Traffic::Up, n)charges the same window as before.submit_dirty_batchreturnsOk(~4747-4749), so the earlier fix holds.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.