D3D12.X: XCL_SHADER_MEM_STATS keeps each page's last storing programs #3631
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3631"
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:19Z.
(Edited: head
b0bbbb189, rebased with #3627's commit onmain395405e4c; this commit unchanged.)(Edited: head
ca0d3da75: a program number two shaders share is named as shared, not as either (second review). Onmain38ad22da.)Stacked on #3630 (
d3d12x/shader-mem-stats), on #3629, #3628 and #3627; only the top commit belongs here.The write log names XCL's own CPU writes into the title's memory; a GPU store to a wrong address leaves nothing. With
XCL_SHADER_MEM_STATS=1each 64 KiB window page now also keeps its last four writing programs, newest first: in the counted store, console 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 crash report lists them after XCL's own writes for each page a register points into, each with its[SHADER]hash and the frame it was last seen writing.What is in it
gpu/dxil/lower_window.rs:program_id,note_writer, the writer slots after the counters (16 MB more of the buffer);lower.rs,kernel.rs: the program's number.gpu/recomp/pso.rs: the shader cache names each program's number by its[SHADER]hash while the switch is on.hle/d3d12x/shader_mem.rs: eachXCL_WINDOW_STATSline reads the slots of the pages written since the line before and keeps when each writer was last seen;writers(va, len)gives them as lines;hle/write_log.rs:writers_ofadds them.gpu/recomp/runner.rs: the test runner can start the statistics buffer with contents.gpu_mem_stats_name_the_last_writers_of_a_page(GPU: a store moves the writers on, a read leaves them, the oldest goes); a unit test of the frames kept and the line.README.md: what the switch now keeps and costs.Tested
ca0d3da75: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.a_program_number_two_shaders_share_names_neitherfailed 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 shader_mem window_stats heap_window write_log eh:: kernelx dstorage: 149 passed, 0 failed, 1 ignored in 3 of 3 runs; in a separate run ofwindow_stats eh:: kernelx,kernelx::tests::an_address_keeps_the_page_the_title_mapped_there_lastfailed, as it does on the bottom branch (#3627). Bothgpu_mem_stats_*tests printedSKIPPED: no GPU.cargo test ... --lib -- --test-threads=8 gpu::: 1,003 passed, 1 failed, 26 ignored, against 1,001 / 1 / 26 onmainwith only #3627 (this PR's GPU test and #3630's). The failure isround_tests::directed_reference_basicson both, 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:15:58Z.
Review (head
a6c5dec1, diff read, not a merge-check; draft, checks red):shader_mem::writers(shader_mem.rs~216) calls the initialisingcrate::gpu::uma::get()before it checksat.is_null(), so everywrite_log::writers_ofcall from the exception filter (eh.rs~123) creates the arena if it does not exist yet, or blocks if the faulting thread is inside that init, even withXCL_SHADER_MEM_STATSoff. The other crash-path helpers (eh::title_region,window_stats::crash_part) useuma::existing(); checkingatfirst and usingexisting()fixes it. It is the same pattern as #3630'sshader_mem::end(), now on the crash path.lw.programis set only inkernel::translate_on_this_thread(kernel.rs~338), so the per-lane compute form (lower_dxil.rs~73,XCL_PER_LANE=1) counts its stores but never fills the writer slots. The geometry pass translates the joined VS+GS code (pso.rs~1658), whoseprogram_idmatches no programname_programsregisters, andname_programsis passed the syntheticgeometry_key_blob(~1664), not a console container, so those writers always show asshader not named.gpu_mem_stats_name_the_last_writers_of_a_page, printedSKIPPED: no GPU, the whole suite was not run, and thexcl-smokeblocks are owed (the reasonPR descriptionis red).Fine: the top commit is 210+/12- and opt-in; the slot layout (
STAT_WRITERS, 4 × (STAT_PAGES+ 1)) matchesslots()andpage_of;note_writerstops at the slot the program held; 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:52Z.
Thanks. Fixed at
aa6822a11:writersusesuma::existing(); per-lane programs note their stores, and a geometry pass is named by its GS's hash (the_geometry_pass_is_named_by_its_gs, red without the fix). The per-lane case has no test of its own yet.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:04:23Z.
Follow-up review (head
aa6822a1, sincea6c5dec1, diff read, not a merge-check; draft, checks red):shader_mem::writerscalls the initialisinguma::get()on the crash path: fixed. It now usesuma::existing()(shader_mem.rs~201), sowrite_log::writers_offrom the exception filter no longer creates or blocks on the arena.lower_dxil::compute_with(~481-492) setslw.programfrom the same program slicename_programshashes (pso.rs~1336-1338), andconsole_geometry_cs_with(~1659-1661) names the joined VS+GS code'sprogram_idby the GS container's hash before the cache lookup;the_geometry_pass_is_named_by_its_gscovers the geometry part.gpu_mem_stats_name_the_last_writers_of_a_pagestill only printedSKIPPED: no GPU, and thexcl-smokeblocks are owed (the reasonPR descriptionis red).New:
kernel::translate, so nothing fails ifcompute_with(lower_dxil.rs~489) stops settinglw.programunderXCL_PER_LANE=1.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-02T03:36:43Z.
Added
a_per_lane_store_notes_its_program_among_the_writers(lower_dxil.rs), which fails ifcompute_withstops settinglw.program. Head044997138; thexcl-smokeblocks for it are in the description.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:40:30Z.
Follow-up review (head
04499713, sinceaa6822a1, diff read, not a merge-check; draft):a_per_lane_store_notes_its_program_among_the_writers(lower_dxil.rs~1560) translates a store throughcompute_withwithMEM_STATSand checks that the DXIL has anatomicBinOpexchange of that program'sprogram_id.gpu_mem_stats_name_the_last_writers_of_a_pagehas not run on a card and the whole suite has not run 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 Foniass on 2026-12-02T13:47:57Z.
Follow-up review (head
75708679, since04499713, 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 gut0to on 2026-12-02T16:30:31Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_window.rs; line 25Could this ID retain more bits or detect collisions before truncating the hash?
shader_mem::namedstores one[SHADER]hash peru32ID, so two different programs with the same low 32 FNV bits overwrite the label.writers()then attributes both programs to whichever hash was registered last, and the GPU writer slots cannot distinguish them. Could collisions be detected and reported as ambiguous, or could the writer ID preserve a wider key? AI-assisted review (model: GPT-6); I traced the ID from the translator through the name registry.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T16:30:31Z.
Review: COMMENTED
AI-assisted review (model: GPT-6). I traced the program ID from translation through the writer-name registry.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:53:47Z.
@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:11Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_window.rs; line 25Two programs can share an ID. The GPU writes it with a 32-bit atomic exchange, so the ID stays 32 bits. Instead
namednow notices a second shader under the same ID, and the line saystwo or more shaders have this numberrather than naming either one (shader_mem.rs).a_program_number_two_shaders_share_names_neitherfailed without it and passed with it. Head1e6d4479.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:52:45Z.
Follow-up review of
1e6d4479, since75708679(code reading only, not a merge-check;PR descriptionred) · 1 nitIn short: Since
75708679the PR's own commit changed in one place. A program number named by two different[SHADER]hashes is now shown as shared ("two or more shaders have this number") instead of keeping whichever shader named it last, and a new test covers it. The earlier GPU-run point is covered by the RTX 5070 Ti run in the description. Nothing in the code blocks this. Thexcl-smokeblock for this PR still names75708679, not this head. The other changes in the range belong to the stacked PRs (#3627, #3629, #3630).Nit
5653fd69"carries this PR's commit unchanged". That head has04499713, an earlier version of this commit without the shared-number change, on an oldermain. The GPU side is the same, so the run still counts, but the sentence should say which version ran.Checked and fine
gpu_mem_stats_name_the_last_writers_of_a_pageand the whole suite ran on an RTX 5070 Ti. Since then the commit changed only CPU-side naming (named,name_of,writer_line), so that coverage still holds.named(shader_mem.rs~106) keeps the first hash. Naming again with the same hash leaves it. A different hash makes it shared for good.writers(~207-217) tells the three cases apart (not named, shared, named) and still usestry_lockon the crash path.a_program_number_two_shaders_share_names_neitherfails against the oldinsert, which kept the last hash.XCL_SHADER_MEM_STATS=1.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:33Z.
Both fixed in the description. Tested now says the run at
5653fd69had an earlier version of this commit, and Not tested no longer lists the GPU test or the whole suite. A whole-suite run at the stack's new top is queued on Windows. Headca0d3da7(it moved only with the fixes below it).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:37Z.
Follow-up review of
ca0d3da7, since1e6d4479(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:35:03Z.
Follow-up review of
b0bbbb18, sinceca0d3da7(code reading only, not a merge-check) · no new findingsIn short: This push only rebases the stack onto
main. This PR's own commit is identical (git range-diff); the only change underneath is #3627 followingmain's newUploadCopyjobs. Nothing new, and nothing blocks it.Checked and fine
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.