D3D12.X: XCL_SHADER_MEM_STATS counts shader accesses through the windows #3630
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3630"
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:06:14Z.
(Edited: head
f2677d830, rebased with #3627's commit onmain395405e4c; this commit unchanged.)(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. Onmain38ad22da.)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 (#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 (#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 #3631): 1,003 passed, 1 failed, 26 ignored, against 1,001 / 1 / 26 with only #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.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T01:12:39Z.
Review (head
3e09e2f2, diff read, not a merge-check; draft, checks red):shader_mem::end()(shader_mem.rs~274) does not checkenabled()and callscrate::gpu::uma::get(), which reserves and commits the UMA region if nothing has yet.report::write_final(None)(report.rs~307) calls it on every non-crash exit, includinghost.rs~317 (after the title loads, before its entry point) andDLL_PROCESS_DETACHunder the loader lock. That goes against the description's "off, nothing is emitted" anduma::existing()'s rule that observability must not allocate it; checkingenabled()and usingexisting()fixes it.allocated(~110) inserts every traced route and never removes one. A reservation (kernelx.rs~979 / ~1013) and a laterVirtualAlloc (sparse commit)inside it (~946) both become rows, andwrite_table(~236) sums each row on its own, so the same accesses show under two allocations; freed and reused memory keeps the old row and gets the new owner's counts.VirtualFree (GPU view, …)(kernelx.rs~1278) also goes throughtrace_memwithgot = 1.window_ata negative constantEa::Sthat is the last term is not added tolo(lower_window.rs~111,if has_more), butstat_at(~149) records thatlo, so an access just below a 64 KiB boundary is counted on the next page, and stored as that page in its fault slot if it is outside every window.SKIPPED: no GPU, the whole suite was not run on a GPU, the title runs came from another tree, and thexcl-smokeblocks are owed (the reasonPR descriptionis red).kernelx.rshook and the crash-reportpage_partcould each be their own PR on top of the counting.Fine: the flag is masked everywhere the window count is read (
kernel.rs,recomp/mod.rs,pso.rs,shaders.rs) and is part of the cache keys; the descriptor slot is reserved only when the feature is on; the buffer layout and hash keep the fault slots within the 4096 entries; the stack is declared.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:50Z.
Thanks. Fixed at
6da4db5d0: a final negative offset counts its own page (new GPU test, not yet run on a card). The placement table, withend()returning when the switch is off and usinguma::existing(), a nested page counted once, released allocations dropped and VirtualFree's result of 1 ignored, is now its own PR on top of #3631: #3642. This one is 501 lines; the description says why.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:01:06Z.
Follow-up review (head
6da4db5d, since3e09e2f2, diff read, not a merge-check; draft, checks red):shader_mem::end()runs with the switch off and callsuma::get(): fixed here.end()and itsreport::write_finalhook moved out;take()reads the buffer only whenATis set and only theXCL_WINDOW_STATSthread calls it (window_stats.rs~234);crash_partusesuma::existing()(~123). Theend()now in #3642 checksenabled()and usesexisting().window_atadds a final negativeEa::Stolowhenmem_statsis on (lower_window.rs~111), andgpu_mem_stats_count_a_negative_offset_on_the_page_below(heap_window_tests.rs) expects page 1, not 2.xcl-smokeblocks are owed (the reasonPR descriptionis red).page_part(window_stats.rs~127) could still be its own PR.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 Foniass on 2026-12-02T03:40:14Z.
Follow-up review (head
5b16d606, since6da4db5d, diff read, not a merge-check; draft):git range-diffshows the own commit (5b16d606) identical to6da4db5d; the push only carries #3629's change below it. Still open: no GPU run of the new tests, and the description still names #3631 for the placement table, which is in #3642.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 Foniass on 2026-12-02T13:47:41Z.
Follow-up review (head
2ef753d9, since5b16d606, diff read, not a merge-check; checks red):git range-diffshows the own commit changed only wheremainmoved under it (theXCL_WAVE64_IDIOMSwarm setting and cache tag now sit next to this PR's own inshaders.rs/kernel.rs); this push is a rebase.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:46:57Z.
Code review location:
crates/xcl/src/hle/d3d12x/console_heap.rs; line 534Critical: 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 fromnext, 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) andresource_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.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:46:57Z.
Review: COMMENTED
Review of
2ef753d9: 1 finding(s) (1 critical), most severe first.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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:47:00Z.
@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 Royalflamejlh on 2026-12-02T20:47:01Z.
Code review location:
crates/xcl/src/hle/d3d12x/console_heap.rs; line 534Right: 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 at1606490f: the statistics slot takes two descriptors (first_freeinconsole_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_slotfailed 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T20:56:17Z.
Follow-up review of
1606490f, since2ef753d9(code reading only, not a merge-check;PR descriptionred) · 1 medium, 1 nitIn short: Since
2ef753d9the stack was rebased ontomain38ad22da, and the PR's own commit has two real changes. WithXCL_SHADER_MEM_STATS=1, the first descriptor the shared heap hands out is now even, with a unit test.crash_partno longer waits on either switch's first read. The new code is right and no earlier code finding is open. Thexcl-smokeblock still names2ef753d9, which is whyPR descriptionis red. The whole-suite GPU run was made on an earlier version of this commit (5b16d606, inside #3642's5653fd69), which has neither change.Medium
crash_partinwindow_stats.rs~129,page_partinshader_mem.rs~171) could be its own PR on top of the counting. At least correct the count.Nit
5653fd69"carries this PR's commit unchanged", but that head has5b16d606withoutfirst_freeand the newcrash_part. Say which version ran, or rerun it.Checked and fine
shader_mem::end()ran with the switch off and calleduma::get().take()now reads the buffer only whenATis set, andcrash_partusesuma::existing().window_atadds a final negativeEa::S, covered bygpu_mem_stats_count_a_negative_offset_on_the_page_below.first_free(console_heap.rs~546) returns 22 with the switch off and 24 with it on, so console slots keep the even SRV / odd UAV pairing. The new test checks both.crash_partreadsSECONDS.get()without initialising it.page_partreads onlyATand returns an empty string while no buffer exists, so a crash report reads no switch and allocates nothing.MEM_STATSis still masked wherever the window count is read and is part of the cache keys. With the switch off nothing is emitted.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:31Z.
page_partand its call incrash_part, about 12 lines. The CPU page counts it reads also feed #3642's placement table, so splitting it off would not bring the commit near 400. I left it in and the description says so.5653fd69had5b16d606, beforefirst_freeand the newcrash_part. A whole-suite run at the stack's new top (head here14848299, which only moved with #3627 and #3629 below it) is queued on Windows, and its counts go in when it ends.AI use: Claude Code (Claude Opus 5.5) edited the description and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:34:21Z.
Follow-up review of
14848299, since1606490f(code reading only, not a merge-check;PR descriptionred) · no new findingsIn 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 (
git range-diff). Tested now says which earlier version of this commit the GPU run was made on. Nothing new. The smoke block names an earlier head (PR descriptionis red).Checked and fine
OVERLAPPED) are reviewed on those PRs.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:34:47Z.
Follow-up review of
f2677d83, since14848299(code reading only, not a merge-check) · 1 mediumIn short: This push only rebases the stack onto
main. This PR's own commit changed only in context (git range-diff), and #3627 underneath followsmain's newUploadCopyjobs. The size point from earlier is unchanged.Medium
crash_partinwindow_stats.rs,page_partinshader_mem.rs) could be its own PR on top of the counting.Checked and fine
14848299apart from context.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.