Repository navigation
D3D12.X: XCL_SHADER_MEM_STATS writes a placement table per allocation - #3642
Royalflamejlh wants to merge 6 commits into
Conversation
|
Review (head 6bd290d, diff read, not a merge-check; draft, checks red):
Fine: a page held by two allocations at different bases is now counted once ( AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
6bd290d to
65c4381
Compare
|
All five fixed at 65c4381: a commit inside a reservation counts as the reservation ( AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply. |
|
Follow-up review (head 65c4381, since 6bd290d, diff read, not a merge-check; draft):
New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
65c4381 to
5653fd6
Compare
|
Fixed at 5653fd6: at exit AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply. |
|
Follow-up review (head 5653fd6, since 65c4381, diff read, not a merge-check; draft, checks red):
New: none; only that line and its comment changed. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
merge-check Tested on the unmodified PR head The PR head stayed at
Placement-table check A separate 90 s release smoke on the exact head used default placement with Reproducing the missing allocation row
Regression run Pinned main, default Local merge, default Exact PR head, diagnostic enabled |
5653fd6 to
f0fdb02
Compare
|
Follow-up review (head f0fdb02, since 5653fd6, diff read, not a merge-check; checks red):
New: none. Rows are now removed only after a release succeeds: the AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
@mokkamokacaffe Not tested: Windows; the AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply. |
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
gut0to
left a comment
There was a problem hiding this comment.
AI-assisted review: GPT-6 helped inspect this change; I verified the range-classification path and the current PR diff.
| } | ||
|
|
||
| fn given_in(u: &Uma, path: Path, va: u64, len: u64) { | ||
| if place(u, va as usize).is_some() { |
There was a problem hiding this comment.
Low: This only classifies the starting address with place(va), so a span beginning near the end of a window and extending past its boundary is treated as fully inside and omitted from OUTSIDE. That hides the out-of-window portion from the stats (for example, va = window_start + window_len - 1, len = 2). Could given_in require the entire half-open range to fit in one window, with a test for a boundary-crossing descriptor? AI-assisted review: GPT-6 helped inspect the telemetry path; I checked place and the UMA window tests.
There was a problem hiding this comment.
Right. given_in is #3627's, and it placed only the first byte. A range now counts as outside unless its last byte is in the same window as its first, and its log line says only its start does, in window N. traffic_adds_to_its_window_and_addresses_in_one_are_not_outside now gives a 2-byte range across the coherent window's end (counted) and one that ends on it (not counted); it failed without the fix. The fix is in #3627's commit (2580976a), and this PR's own commit changed only where the commits below moved. Head d39753cb.
AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
f0fdb02 to
d39753c
Compare
|
Follow-up review of In short: The PR writes Checked and fine
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point. |
An address the title gives the GPU outside every memory window is no GPU memory, and nothing said so: with 4 windows the title's GPU views lay outside them and the world's mesh programs read empty meshlet lists (xcl-dev#3565). With XCL_WINDOW_STATS=<seconds>, every that many seconds: - a line for each window: kind, range, bytes with memory on the GPU (tiles of a sparse or view window, the committed bytes of a coherent one), and since the line before the bytes uploaded into it, the pages the write watch found written, the bytes read back and the GPU-view tiles filled; - a line with the addresses given outside every window, by view_want::Path, and the pages written outside them. The first 8 addresses of each path outside every window are logged with their size and what lies there (a GPU view of the title's memory, a graphics reservation, plain memory, nothing committed). The counters are relaxed atomics where the uploads, read-backs, write-watch looks, mirror fills and view_want asks already happen; off, each is one load. Nothing is remapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An unhandled exception logged the page events at the pages the registers point into, and only where there were some. A crash where a register held an address in a memory window with no page events, the case of memory the title corrupted in a coherent window, said nothing about where that address lay. Each register that points into a memory window (sparse, coherent, view), a view of a pair or a graphics reservation now gets one line: the region, the 64 KiB page, its page events, and what XCL_WINDOW_STATS counted for its window when it is on. Other registers keep the line they had. Locks are only tried on this path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title can find its own heap overwritten (a pool block header holding float data) and fault long after the write. Nothing said whether XCL wrote there: page copies in kernelx, DirectStorage data, file reads into title buffers, texture downloads, sparse copies back and the writes made after the GPU all land in title memory without a trace. hle::write_log keeps the last 16 384 of them (start, length, reason, time, thread) in a ring without a lock, oldest overwritten first, and writers_of(start, len) gives the ones that overlap a range as lines, newest first, the newest 32 of them a line each and the rest counted. A write takes its slot only from an older one and not while another is written there, so a slot's fields are always one write's. Recorded: kernelx page maps, moves, copies home and the zeroing decommit in a committed window; DirectStorage writes (virtual, by page number, BCPack fills, the parallel path); ReadFile reads into graphics memory once they finish, with the bytes read (a failed one not at all; an overlapped one at the first look that finds it done, or when its OVERLAPPED is used for another read, while it still holds this one's result, or with the bytes asked for when the caller has reset it); title_textures' WriteProcessMemory runs; sparse copy_back pages and immediates; cpu_writes' labels, fences and 64-bit values; the frame index write. An unhandled exception now logs, for each 64 KiB page of title memory a register points into, the writes kept there. A record cost 70 ns on one thread under Wine, and 19-25 ns of wall time per record with 8 threads recording at once (2 M records, 3 runs); a query that matched all 16 384 kept writes 0.35-0.47 ms. It is on without a switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XCL_WINDOW_STATS sees what the CPU hands the GPU; it cannot see the pointers shaders load from memory and follow. With XCL_SHADER_MEM_STATS=1 (heap windows only) the direct DXIL translator adds, where an access picks its window (Lw::window_at, counted where the access runs with its own guard): - an access whose window is out of range (outside every window; not the code's constant data) stores its 64 KiB page number in a slot by a hash of the page: a plain store in a branch, in every lane that runs it; - in console lane 0 an atomic add to its page's read or write counter (16 windows x 65536 pages, and one pair for everything outside them). The buffer (8 MB) is a custom heap in system memory at a heap descriptor after the windows' null views (MEM_STATS_SLOT), read by the CPU on each XCL_WINDOW_STATS line: the window lines gain the GPU reads and writes since the line before, the outside line the accesses outside and the new pages, the first 32 pages logged with what lies there. A register's line in the crash report gets its window page's GPU reads and writes and CPU pages written and KB uploaded. MEM_STATS is a flag in the windows count, so it is part of the translated caches' keys like HEAP_FLAT; off, nothing is emitted and translation is unchanged. The HLSL path ignores it. Nothing is moved. The fault slots follow the scheme of mandy's GPU memory tracker (GPL-3.0, no code taken): page numbers in a host-visible buffer by a hash of the page, read and cleared by the CPU. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The write log names XCL's own CPU writes into the title's memory; a GPU store to a wrong address leaves nothing. The memory statistics already count, per 64 KiB window page, the reads and writes of console lane 0 of each wave in translated programs. Each page now also keeps its last four writers, newest first: in the counted store, lane 0 exchanges the program's number (the low dword of FNV-64 of its console code, never 0) into the page's first slot and moves the old one on, as far as the slot that held it. A program storing again to the same page costs one atomic exchange; a new writer up to four. The statistics buffer grows by 16 MB (4 slots of 1 M pages). The shader cache names each program's number by its [SHADER] hash as the switch is on (the per-lane form, XCL_PER_LANE=1, notes its stores too; a geometry pass, the VS and GS joined, is named by its GS's hash; a number that two shaders' codes share, 32 bits of a hash, is named as shared, not as either), and each XCL_WINDOW_STATS line reads the slots of the pages written since the line before and keeps, per page, the frame each writer was last seen writing it. shader_mem::writers(va, len) gives them as lines; write_log::writers_of adds them after XCL's own writes, so the crash report lists them for each page a register points into. The test runner can start the statistics buffer with contents, so a GPU test checks the move of the writers; a test of the per-lane form checks that its store exchanges the program's number in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shader memory statistics count GPU accesses per 64 KiB window page, and the window statistics the CPU's writes and uploads; neither says which of the title's allocations they belong to, or whether that memory sits in the wrong kind of window. Each XCL_WINDOW_STATS line, and the end of the run, now writes placement_<n>.tsv: per allocation of the title's in the windows (kernelx's routes, as XCL_TRACE_MEM names them) and per window for the pages none holds, the GPU accesses, the CPU pages written and KB uploaded, and a suggestion by the PCIe bytes it would cost in the other kind of memory, with a margin of 4. A commit inside a recorded allocation (the title reserves, then commits from the reservation's base) counts as that allocation and keeps its route; a page two allocations hold otherwise is counted once, in the first by address. A released allocation (VirtualFree with MEM_RELEASE, XMemFree) leaves the table with every one inside it once the release has succeeded: a rejected one (a nonzero size on a sparse reservation) keeps its row. A reused address takes the new route. The counts are the page's since the start of the run. A decommit, which kernelx traces with a result of 1, is no allocation. Noting a release keeps the title's last error, as XCL_TRACE_MEM does. The table at exit is written only with the switch on, from the UMA region that exists, and only if no other thread holds the counts or the allocations: report::write_final runs under the loader lock at DLL_PROCESS_DETACH, where a thread ended inside them never lets go. The counts' lock is not held while the table is built and written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d39753c to
f1ae90e
Compare
|
Follow-up review of In short: This push only rebases onto the new commits of #3627 and #3629 below it. This PR's own commit is the same apart from context ( Checked and fine
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point. |
(Edited: head
f1ae90ebb, rebased onto the second review's fixes below it; this PR's own commit changed only where the lines below moved. The approval was given atf0fdb029, before this head. The review's range point is fixed in #3627's commit, wheregiven_inlives.)Stacked on #3631, on #3630, on #3629, on #3628, on #3627; only the top commit belongs here. It needs #3630 for the GPU access counts and #3627 for the CPU's writes and uploads per page; it sits on #3631 to keep the stack in one line.
With
XCL_SHADER_MEM_STATS=1, eachXCL_WINDOW_STATSline and the end of the run writeplacement_<n>.tsv: per allocation of the title's in the windows (kernelx's routes, asXCL_TRACE_MEMnames them) and per window for the pages none holds, the GPU accesses, the CPU pages written and KB uploaded, and a suggestion, video memory or coherent, by the PCIe bytes the other kind would cost (margin 4). It answers "is this allocation in the wrong kind of window": on a development tree it named a 1.34 GB write-combined GPU heap in a coherent window that shaders read over the bus every frame (what #3619 moves).Split out of #3630 at review. A commit inside a recorded allocation (reserve, then commit from the reservation's base) counts as that allocation and keeps its route; a page two allocations hold otherwise counts once, in the first by address. A release (VirtualFree with MEM_RELEASE, XMemFree) that succeeds removes the allocation and every one inside it, and a reused address takes the new route; a decommit is no allocation. Noting a release keeps the title's last error, as
XCL_TRACE_MEMdoes. The table at exit is written only with the switch on, from the UMA region that exists, and only if no other thread holds the counts or the allocations (it runs under the loader lock); the counts' lock is let go before the table is built and written. Off, nothing changes.What is in it
hle/d3d12x/shader_mem.rs: the allocations, the table, its rows and the suggestion;kernelx.rs: allocations and releases noted;window_stats.rs,report.rs: written per line and at exit.a_page_held_by_two_allocations_is_counted_in_the_first,a_commit_in_a_reservation_counts_as_the_reservation,a_release_takes_every_allocation_inside_it_and_the_address_takes_a_new_route,the_suggestion_weighs_what_would_cross_pcie,a_rejected_release_keeps_the_allocation.README.md: the file.Tested
f1ae90ebb:cargo checkwith and without--tests, no errors; Under Wine on Mesa's CPU Vulkan driver, release, 1 run:cargo test --lib -- window_stats file_reads write_log shader_mem console_heap eh::at the top of the stack (D3D12.X: XCL_SHADER_MEM_STATS writes a placement table per allocation #3642,f1ae90ebb): 62 passed, 0 failed.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.cargo check -p xclwith and without--tests;cargo test --lib -- --test-threads=8 file_reads write_log shader_mem window_stats lower_dxil kernelxon this head: 116 passed, 0 failed, 1 ignored in 2 of 3 runs; in the thirdkernelx::tests::an_address_keeps_the_page_the_title_mapped_there_lastfailed once and passed on its own.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
Claude Code (Claude Opus 5.5) wrote the change, its tests and this description.