Repository navigation
D3D12.X: XCL_SHADER_MEM_STATS counts shader accesses through the windows - #3630
Royalflamejlh wants to merge 4 commits into
Conversation
|
Review (head 3e09e2f, diff read, not a merge-check; draft, checks red):
Fine: the flag is masked everywhere the window count is read ( AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
3e09e2f to
6da4db5
Compare
|
Thanks. Fixed at 6da4db5: a final negative offset counts its own page (new GPU test, not yet run on a card). The placement table, with AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply. |
|
Follow-up review (head 6da4db5, since 3e09e2f, diff read, not a merge-check; draft, checks red):
New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
6da4db5 to
5b16d60
Compare
|
Follow-up review (head 5b16d60, since 6da4db5, 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. |
5b16d60 to
2ef753d
Compare
|
Follow-up review (head 2ef753d, since 5b16d60, diff read, not a merge-check; checks red):
New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
bmjask
left a comment
There was a problem hiding this comment.
Review of 2ef753d9: 1 finding(s) (1 critical), most severe first.
- Critical
crates/xcl/src/hle/d3d12x/console_heap.rs:534: With the switch on, the shared heap's allocation cursor starts at MEM_NULL_STORE + 2 = 23, an odd index, but the heap relies on SRVs sitting at even indexes and UAVs at odd ones. (inline)
These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
| cap, | ||
| // the memory windows and their two out-of-range null UAVs come first | ||
| next: crate::gpu::recomp::MEM_NULL_STORE + 1, | ||
| next: crate::gpu::recomp::MEM_NULL_STORE + 1 + super::shader_mem::enabled() as u32, |
There was a problem hiding this comment.
Critical: With the switch on, the shared heap's allocation cursor starts at MEM_NULL_STORE + 2 = 23, an odd index, but the heap relies on SRVs sitting at even indexes and UAVs at odd ones. With XCL_HEAP_WINDOWS=1 XCL_SHADER_MEM_STATS=1, page_descriptors() always takes an even count from next, so every page range starts at an odd index and each console slot's SRV lands at an odd one. fill_nulls (the initial fill, retired ranges) and resource_gone() pick the null view by absolute index, so SRV positions get null Texture2D UAVs and UAV positions get null SRVs. A shader that samples an unwritten or destroyed slot then reads a descriptor of the wrong type, which is undefined behaviour, and the code's own comments note NVIDIA hangs on SRV/UAV mismatches. This also happens with a single window, where no shader uses the stats slot. Reserving 2 descriptors (+ 2 * enabled() as u32), or a fixed even-sized block regardless of the env var, would keep the parity.
There was a problem hiding this comment.
Right: with the switch on, the cursor started at 23, so each console slot's SRV sat at an odd index, where the null fill and resource_gone() put UAVs. Fixed at 1606490f: the statistics slot takes two descriptors (first_free in console_heap.rs), so the first slot handed out is 24, as it is with the switch off (22). the_first_slot_handed_out_starts_at_an_even_descriptor_with_or_without_the_stats_slot failed without the fix and passed with it (1 run each, under Wine). The PRs above are rebased onto it.
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. |
2ef753d to
1606490
Compare
|
Follow-up review of In short: Since Medium
Nit
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>
1606490 to
1484829
Compare
AI use: Claude Code (Claude Opus 5.5) edited the description and wrote this reply. |
|
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
148482997: the shared heap's first slot stays at an even descriptor with the switch on, so SRVs keep the even indexes (second review);crash_partreads no switch for the first time. Onmain38ad22d.)Stacked on #3629 (
memory/write-log), on #3628, on #3627; only the top commit belongs here. It needs only #3627 for its lines, and #3628 for one part of a crash report line; it sits on the write log so the stack is one line.XCL_WINDOW_STATSsees what the CPU hands the GPU; it cannot see the pointers shaders load from memory and follow. WithXCL_SHADER_MEM_STATS=1(heap windows only), the direct DXIL translator adds, where an access picks its window (Lw::window_at):The 8 MB buffer is a custom heap in system memory, at a heap descriptor after the windows' null views (
MEM_STATS_SLOT), and the CPU reads it on eachXCL_WINDOW_STATSline: the window lines gain the GPU reads and writes since the line before, and the outside line the accesses outside and the new pages (the first 32 logged with what lies there). A register's crash report line gets its page's counts.MEM_STATSis a flag in the windows count, so it is part of the translated caches' keys asHEAP_FLATis; 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).It is 515 changed lines (484+/31-), over the ~400 target: about 340 added lines of code and 100 of tests, the rest blank lines and the README. The instrumentation shows nothing without its readback, and the readback has nothing to read without the instrumentation. The crash-report part is about 12 of those lines (
page_partand its call incrash_part); the CPU page counts it reads are also #3642's placement table's. The placement table per allocation is now its own PR, #3642, stacked on #3631. (Edited: head6da4db5d0fixes the review's points: a final negative offset counts its own page, with a GPU test;end()and the placement table moved out.)What is in it
gpu/dxil/lower_window.rs:count_access, the buffer layout;lower_mem.rs,lower.rs,kernel.rs: the calls and fields.gpu/recomp/mod.rs,pso.rs,shaders.rs:MEM_STATS,MEM_STATS_SLOT, the switch, the flag masked where the window count is read.hle/d3d12x/shader_mem.rs(new),console_heap.rs,window_stats.rs: the buffer, its view and the lines.gpu/recomp/runner.rs: the test runner can read the buffer back.gpu_mem_stats_name_only_the_page_outside_the_windows(GPU); the graphics stages translate and validate with the flag; unit tests of page numbering, uploads split at page ends, and the lines.README.md: the switch and its cost.Tested
148482997: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.the_first_slot_handed_out_starts_at_an_even_descriptor_with_or_without_the_stats_slotfailed without the fix.5653fd69, with this PR's commit as5b16d606: before the review fixesfirst_freeand the newcrash_part):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 shader_mem window_stats heap_window write_log eh:: kernelx: 108 passed, 0 failed, 1 ignored in 1 of 3 runs; 107 passed and 1 failed (kernelx::tests::gpu_visible_fallback_memory_is_write_watched) in the other 2. One of threekernelxtests that share process-wide state fails in some runs: two of them failed the same way on the branch at the bottom of this stack (D3D12.X: XCL_WINDOW_STATS logs each memory window's traffic #3627), which does not touchkernelx.gpu_mem_stats_name_only_the_page_outside_the_windowsprintedSKIPPED: no GPU.cargo test ... --lib -- --test-threads=8 gpu::at the top of the stack (with D3D12.X: XCL_SHADER_MEM_STATS keeps each page's last storing programs #3631): 1,003 passed, 1 failed, 26 ignored, against 1,001 / 1 / 26 with only D3D12.X: XCL_WINDOW_STATS logs each memory window's traffic #3627; the failure on both isround_tests::directed_reference_basics, which fails under Wine here onmaintoo.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
main.