D3D12.X: XCL_SHADER_MEM_STATS keeps each page's last storing programs #3631

Open
Royalflamejlh wants to merge 5 commits from upstream-pr/3631 into main
Royalflamejlh commented 2026-12-02 01:06:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T01:06:19Z.


(Edited: head b0bbbb189, rebased with #3627's commit on main 395405e4c; this commit unchanged.)

(Edited: head ca0d3da75: a program number two shaders share is named as shared, not as either (second review). On main 38ad22da.)

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=1 each 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: each XCL_WINDOW_STATS line 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_of adds them.
  • gpu/recomp/runner.rs: the test runner can start the statistics buffer with contents.
  • Tests: 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

  • At ca0d3da75: cargo check with 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_neither failed without the fix.
  • RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, debug, at the top of this stack (#3642, head 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; 28 SKIPPED lines (wave64 tests: no wave64 on this card; heap-window tests without XCL_HEAP_WINDOWS=1; no D3D12 debug layer). The stack's GPU tests (gpu_mem_stats_*, the writer and geometry-pass tests) ran and passed.
  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, Rust 1.98.0, 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 of window_stats eh:: kernelx, kernelx::tests::an_address_keeps_the_page_the_title_mapped_there_last failed, as it does on the bottom branch (#3627). Both gpu_mem_stats_* tests printed SKIPPED: no GPU.
  • cargo test ... --lib -- --test-threads=8 gpu::: 1,003 passed, 1 failed, 26 ignored, against 1,001 / 1 / 26 on main with only #3627 (this PR's GPU test and #3630's). The failure is round_tests::directed_reference_basics on both, which fails under Wine here on main too.
  • 1 title run on our development tree (1,501 s, the switch on from 639 s) had no unhandled exception, so the writer lines have not yet been printed at a crash.

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:

xcl-smoke v1
commit: 395405e4c0ed814afde0610a724dc96a3af329de
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1522 (PresentX 1522)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16017 MB

this PR's head:

xcl-smoke v1
commit: b0bbbb189de1105e767da6523ed4f5036edd1f46
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1569 (PresentX 1569)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15363 MB

Not tested

  • A real crash, AMD.

AI use

  • Claude Code, Claude Opus 5.5: wrote the change, its tests and this description, and ported it to main.
<!-- greyfinch-sync:ivall/xcl:issue:5597696662 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T01:06:19Z. --- (Edited: head `b0bbbb189`, rebased with #3627's commit on `main` 395405e4c; this commit unchanged.) (Edited: head `ca0d3da75`: a program number two shaders share is named as shared, not as either (second review). On `main` 38ad22da.) 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=1` each 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`: each `XCL_WINDOW_STATS` line 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_of` adds them. - `gpu/recomp/runner.rs`: the test runner can start the statistics buffer with contents. - Tests: `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** - At `ca0d3da75`: `cargo check` with 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_neither` failed without the fix. - RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, debug, at the top of this stack (#3642, head `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; 28 `SKIPPED` lines (wave64 tests: no wave64 on this card; heap-window tests without `XCL_HEAP_WINDOWS=1`; no D3D12 debug layer). The stack's GPU tests (`gpu_mem_stats_*`, the writer and geometry-pass tests) ran and passed. - RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, Rust 1.98.0, `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 of `window_stats eh:: kernelx`, `kernelx::tests::an_address_keeps_the_page_the_title_mapped_there_last` failed, as it does on the bottom branch (#3627). Both `gpu_mem_stats_*` tests printed `SKIPPED: no GPU`. - `cargo test ... --lib -- --test-threads=8 gpu::`: 1,003 passed, 1 failed, 26 ignored, against 1,001 / 1 / 26 on `main` with only #3627 (this PR's GPU test and #3630's). The failure is `round_tests::directed_reference_basics` on both, which fails under Wine here on `main` too. - 1 title run on our development tree (1,501 s, the switch on from 639 s) had no unhandled exception, so the writer lines have not yet been printed at a crash. **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`: ``` xcl-smoke v1 commit: 395405e4c0ed814afde0610a724dc96a3af329de gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 1522 (PresentX 1522) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 16017 MB ``` this PR's head: ``` xcl-smoke v1 commit: b0bbbb189de1105e767da6523ed4f5036edd1f46 gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 1569 (PresentX 1569) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15363 MB ``` **Not tested** - A real crash, AMD. **AI use** - Claude Code, Claude Opus 5.5: wrote the change, its tests and this description, and ported it to `main`.
Foniass commented 2026-12-02 01:15:58 +00:00 (Migrated from github.com)

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):

  • The crash path can now create the UMA arena with the switch off. shader_mem::writers (shader_mem.rs ~216) calls the initialising crate::gpu::uma::get() before it checks at.is_null(), so every write_log::writers_of call 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 with XCL_SHADER_MEM_STATS off. The other crash-path helpers (eh::title_region, window_stats::crash_part) use uma::existing(); checking at first and using existing() fixes it. It is the same pattern as #3630's shader_mem::end(), now on the crash path.
  • Some stores are never noted or never named. lw.program is set only in kernel::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), whose program_id matches no program name_programs registers, and name_programs is passed the synthetic geometry_key_blob (~1664), not a console container, so those writers always show as shader not named.
  • No GPU run. The only test of the atomic exchange chain, gpu_mem_stats_name_the_last_writers_of_a_page, printed SKIPPED: no GPU, the whole suite was not run, and the xcl-smoke blocks are owed (the reason PR description is red).

Fine: the top commit is 210+/12- and opt-in; the slot layout (STAT_WRITERS, 4 × (STAT_PAGES + 1)) matches slots() and page_of; note_writer stops 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.

<!-- greyfinch-sync:ivall/xcl:comment:7331500780 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7331500780). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T01:15:58Z. --- Review (head a6c5dec1, diff read, not a merge-check; draft, checks red): - **The crash path can now create the UMA arena with the switch off.** `shader_mem::writers` (`shader_mem.rs` ~216) calls the initialising `crate::gpu::uma::get()` before it checks `at.is_null()`, so every `write_log::writers_of` call 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 with `XCL_SHADER_MEM_STATS` off. The other crash-path helpers (`eh::title_region`, `window_stats::crash_part`) use `uma::existing()`; checking `at` first and using `existing()` fixes it. It is the same pattern as #3630's `shader_mem::end()`, now on the crash path. - **Some stores are never noted or never named.** `lw.program` is set only in `kernel::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), whose `program_id` matches no program `name_programs` registers, and `name_programs` is passed the synthetic `geometry_key_blob` (~1664), not a console container, so those writers always show as `shader not named`. - **No GPU run.** The only test of the atomic exchange chain, `gpu_mem_stats_name_the_last_writers_of_a_page`, printed `SKIPPED: no GPU`, the whole suite was not run, and the `xcl-smoke` blocks are owed (the reason `PR description` is red). Fine: the top commit is 210+/12- and opt-in; the slot layout (`STAT_WRITERS`, 4 × (`STAT_PAGES` + 1)) matches `slots()` and `page_of`; `note_writer` stops 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.
Royalflamejlh commented 2026-12-02 02:55:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T02:55:52Z.


Thanks. Fixed at aa6822a11: writers uses uma::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.

<!-- greyfinch-sync:ivall/xcl:comment:7333346682 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7333346682). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T02:55:52Z. --- Thanks. Fixed at aa6822a11: `writers` uses `uma::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.
Foniass commented 2026-12-02 03:04:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T03:04:23Z.


Follow-up review (head aa6822a1, since a6c5dec1, diff read, not a merge-check; draft, checks red):

  • shader_mem::writers calls the initialising uma::get() on the crash path: fixed. It now uses uma::existing() (shader_mem.rs ~201), so write_log::writers_of from the exception filter no longer creates or blocks on the arena.
  • Per-lane and geometry stores never noted or named: fixed. lower_dxil::compute_with (~481-492) sets lw.program from the same program slice name_programs hashes (pso.rs ~1336-1338), and console_geometry_cs_with (~1659-1661) names the joined VS+GS code's program_id by the GS container's hash before the cache lookup; the_geometry_pass_is_named_by_its_gs covers the geometry part.
  • No GPU run: still open; gpu_mem_stats_name_the_last_writers_of_a_page still only printed SKIPPED: no GPU, and the xcl-smoke blocks are owed (the reason PR description is red).

New:

  • The per-lane writer noting has no test. The only writer-slot test translates through kernel::translate, so nothing fails if compute_with (lower_dxil.rs ~489) stops setting lw.program under XCL_PER_LANE=1.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7333500993 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7333500993). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:04:23Z. --- Follow-up review (head aa6822a1, since a6c5dec1, diff read, not a merge-check; draft, checks red): - **`shader_mem::writers` calls the initialising `uma::get()` on the crash path:** fixed. It now uses `uma::existing()` (`shader_mem.rs` ~201), so `write_log::writers_of` from the exception filter no longer creates or blocks on the arena. - **Per-lane and geometry stores never noted or named:** fixed. `lower_dxil::compute_with` (~481-492) sets `lw.program` from the same program slice `name_programs` hashes (`pso.rs` ~1336-1338), and `console_geometry_cs_with` (~1659-1661) names the joined VS+GS code's `program_id` by the GS container's hash before the cache lookup; `the_geometry_pass_is_named_by_its_gs` covers the geometry part. - **No GPU run:** still open; `gpu_mem_stats_name_the_last_writers_of_a_page` still only printed `SKIPPED: no GPU`, and the `xcl-smoke` blocks are owed (the reason `PR description` is red). New: - **The per-lane writer noting has no test.** The only writer-slot test translates through `kernel::translate`, so nothing fails if `compute_with` (`lower_dxil.rs` ~489) stops setting `lw.program` under `XCL_PER_LANE=1`. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Royalflamejlh commented 2026-12-02 03:36:43 +00:00 (Migrated from github.com)

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 if compute_with stops setting lw.program. Head 044997138; the xcl-smoke blocks for it are in the description.

AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7334059049 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7334059049). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T03:36:43Z. --- Added `a_per_lane_store_notes_its_program_among_the_writers` (`lower_dxil.rs`), which fails if `compute_with` stops setting `lw.program`. Head 044997138; the `xcl-smoke` blocks for it are in the description. AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply.
Foniass commented 2026-12-02 03:40:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T03:40:30Z.


Follow-up review (head 04499713, since aa6822a1, diff read, not a merge-check; draft):

  • The per-lane writer noting has no test: fixed. a_per_lane_store_notes_its_program_among_the_writers (lower_dxil.rs ~1560) translates a store through compute_with with MEM_STATS and checks that the DXIL has an atomicBinOp exchange of that program's program_id.
  • No GPU run: still open; gpu_mem_stats_name_the_last_writers_of_a_page has 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.

<!-- greyfinch-sync:ivall/xcl:comment:7334124306 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7334124306). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:40:30Z. --- Follow-up review (head 04499713, since aa6822a1, diff read, not a merge-check; draft): - **The per-lane writer noting has no test:** fixed. `a_per_lane_store_notes_its_program_among_the_writers` (`lower_dxil.rs` ~1560) translates a store through `compute_with` with `MEM_STATS` and checks that the DXIL has an `atomicBinOp` exchange of that program's `program_id`. - **No GPU run:** still open; `gpu_mem_stats_name_the_last_writers_of_a_page` has 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.
Foniass commented 2026-12-02 13:47:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:47:57Z.


Follow-up review (head 75708679, since 04499713, diff read, not a merge-check; checks red):

  • Earlier points: unchanged. git range-diff shows the own commit changed only where main moved under it (the XCL_WAVE64_IDIOMS warm setting and cache tag now sit next to this PR's own in shaders.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.

<!-- greyfinch-sync:ivall/xcl:comment:7347477717 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7347477717). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T13:47:57Z. --- Follow-up review (head 75708679, since 04499713, diff read, not a merge-check; checks red): - **Earlier points:** unchanged. `git range-diff` shows the own commit changed only where `main` moved under it (the `XCL_WAVE64_IDIOMS` warm setting and cache tag now sit next to this PR's own in `shaders.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.
gut0to commented 2026-12-02 16:30:31 +00:00 (Migrated from github.com)

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 25

@@ -4,8 +4,27 @@
 
 use super::lower::{Lw, VAR_WIN};
 use super::module::{CastOp, Pred, Value};
+use super::ops::AtomicOp;
+use super::shader::RawUav;
 use crate::gpu::rdna2::Decoded;
 
+/// The shader memory statistics buffer (`recomp::MEM_STATS`), in dwords: `STAT_FAULTS` slots
+/// that take the 64 KiB page number (+ 1) of an access outside every window, by a hash of the
+/// page; then a (reads, writes) pair for each 64 KiB page of the windows, and a last pair for
+/// the accesses outside them; then the same pages' last `STAT_SLOTS` writers (`program_id`),
+/// newest first.
+pub const STAT_FAULTS: u32 = 4096;
+pub const STAT_PAGES: u32 = (crate::gpu::uma::MAX_HEAP_WINDOWS as u32) << 16;
+pub const STAT_SLOTS: u32 = 4;
+pub const STAT_WRITERS: u32 = STAT_FAULTS + 2 * (STAT_PAGES + 1);
+pub const STAT_DWORDS: u32 = STAT_WRITERS + STAT_SLOTS * (STAT_PAGES + 1);
+
+/// The number a program counting its accesses (`recomp::MEM_STATS`) writes in a page's writers:
+/// of its console code; never 0, an empty slot.
+pub fn program_id(code: &[u8]) -> u32 {
+    (crate::gpu::shader::fnv64(code) as u32).max(1)

Could this ID retain more bits or detect collisions before truncating the hash? shader_mem::named stores one [SHADER] hash per u32 ID, 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772806761 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#discussion_r4772806761). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-02T16:30:31Z. **Code review location:** `crates/xcl/src/gpu/dxil/lower_window.rs`; line 25 ~~~~diff @@ -4,8 +4,27 @@ use super::lower::{Lw, VAR_WIN}; use super::module::{CastOp, Pred, Value}; +use super::ops::AtomicOp; +use super::shader::RawUav; use crate::gpu::rdna2::Decoded; +/// The shader memory statistics buffer (`recomp::MEM_STATS`), in dwords: `STAT_FAULTS` slots +/// that take the 64 KiB page number (+ 1) of an access outside every window, by a hash of the +/// page; then a (reads, writes) pair for each 64 KiB page of the windows, and a last pair for +/// the accesses outside them; then the same pages' last `STAT_SLOTS` writers (`program_id`), +/// newest first. +pub const STAT_FAULTS: u32 = 4096; +pub const STAT_PAGES: u32 = (crate::gpu::uma::MAX_HEAP_WINDOWS as u32) << 16; +pub const STAT_SLOTS: u32 = 4; +pub const STAT_WRITERS: u32 = STAT_FAULTS + 2 * (STAT_PAGES + 1); +pub const STAT_DWORDS: u32 = STAT_WRITERS + STAT_SLOTS * (STAT_PAGES + 1); + +/// The number a program counting its accesses (`recomp::MEM_STATS`) writes in a page's writers: +/// of its console code; never 0, an empty slot. +pub fn program_id(code: &[u8]) -> u32 { + (crate::gpu::shader::fnv64(code) as u32).max(1) ~~~~ --- Could this ID retain more bits or detect collisions before truncating the hash? `shader_mem::named` stores one `[SHADER]` hash per `u32` ID, 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.
gut0to commented 2026-12-02 16:30:31 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:review:6154940835 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#pullrequestreview-6154940835). Originally posted by [gut0to](https://github.com/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.
bmjask commented 2026-12-02 16:53:47 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7352611091 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7352611091). Originally posted by [bmjask](https://github.com/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.
Royalflamejlh commented 2026-12-02 20:47:11 +00:00 (Migrated from github.com)

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 25

@@ -4,8 +4,27 @@
 
 use super::lower::{Lw, VAR_WIN};
 use super::module::{CastOp, Pred, Value};
+use super::ops::AtomicOp;
+use super::shader::RawUav;
 use crate::gpu::rdna2::Decoded;
 
+/// The shader memory statistics buffer (`recomp::MEM_STATS`), in dwords: `STAT_FAULTS` slots
+/// that take the 64 KiB page number (+ 1) of an access outside every window, by a hash of the
+/// page; then a (reads, writes) pair for each 64 KiB page of the windows, and a last pair for
+/// the accesses outside them; then the same pages' last `STAT_SLOTS` writers (`program_id`),
+/// newest first.
+pub const STAT_FAULTS: u32 = 4096;
+pub const STAT_PAGES: u32 = (crate::gpu::uma::MAX_HEAP_WINDOWS as u32) << 16;
+pub const STAT_SLOTS: u32 = 4;
+pub const STAT_WRITERS: u32 = STAT_FAULTS + 2 * (STAT_PAGES + 1);
+pub const STAT_DWORDS: u32 = STAT_WRITERS + STAT_SLOTS * (STAT_PAGES + 1);
+
+/// The number a program counting its accesses (`recomp::MEM_STATS`) writes in a page's writers:
+/// of its console code; never 0, an empty slot.
+pub fn program_id(code: &[u8]) -> u32 {
+    (crate::gpu::shader::fnv64(code) as u32).max(1)

Two programs can share an ID. The GPU writes it with a 32-bit atomic exchange, so the ID stays 32 bits. Instead named now notices a second shader under the same ID, and the line says two or more shaders have this number rather than naming either one (shader_mem.rs). a_program_number_two_shaders_share_names_neither failed without it and passed with it. Head 1e6d4479.

AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775813514 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#discussion_r4775813514). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:47:11Z. **Code review location:** `crates/xcl/src/gpu/dxil/lower_window.rs`; line 25 ~~~~diff @@ -4,8 +4,27 @@ use super::lower::{Lw, VAR_WIN}; use super::module::{CastOp, Pred, Value}; +use super::ops::AtomicOp; +use super::shader::RawUav; use crate::gpu::rdna2::Decoded; +/// The shader memory statistics buffer (`recomp::MEM_STATS`), in dwords: `STAT_FAULTS` slots +/// that take the 64 KiB page number (+ 1) of an access outside every window, by a hash of the +/// page; then a (reads, writes) pair for each 64 KiB page of the windows, and a last pair for +/// the accesses outside them; then the same pages' last `STAT_SLOTS` writers (`program_id`), +/// newest first. +pub const STAT_FAULTS: u32 = 4096; +pub const STAT_PAGES: u32 = (crate::gpu::uma::MAX_HEAP_WINDOWS as u32) << 16; +pub const STAT_SLOTS: u32 = 4; +pub const STAT_WRITERS: u32 = STAT_FAULTS + 2 * (STAT_PAGES + 1); +pub const STAT_DWORDS: u32 = STAT_WRITERS + STAT_SLOTS * (STAT_PAGES + 1); + +/// The number a program counting its accesses (`recomp::MEM_STATS`) writes in a page's writers: +/// of its console code; never 0, an empty slot. +pub fn program_id(code: &[u8]) -> u32 { + (crate::gpu::shader::fnv64(code) as u32).max(1) ~~~~ --- Two programs can share an ID. The GPU writes it with a 32-bit atomic exchange, so the ID stays 32 bits. Instead `named` now notices a second shader under the same ID, and the line says `two or more shaders have this number` rather than naming either one (`shader_mem.rs`). `a_program_number_two_shaders_share_names_neither` failed without it and passed with it. Head `1e6d4479`. AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
Foniass commented 2026-12-02 20:52:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T20:52:45Z.


Follow-up review of 1e6d4479, since 75708679 (code reading only, not a merge-check; PR description red) · 1 nit

In short: Since 75708679 the 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. The xcl-smoke block for this PR still names 75708679, not this head. The other changes in the range belong to the stacked PRs (#3627, #3629, #3630).

Nit

  1. The description is out of date in two places.
    • Tested says the run at 5653fd69 "carries this PR's commit unchanged". That head has 04499713, an earlier version of this commit without the shared-number change, on an older main. The GPU side is the same, so the run still counts, but the sentence should say which version ran.
    • Not tested still lists "the GPU test on a card" and "the whole suite", which Tested now reports as run.
Checked and fine
  • Earlier finding fixed: there was no GPU run. gpu_mem_stats_name_the_last_writers_of_a_page and 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 uses try_lock on the crash path.
  • a_program_number_two_shaders_share_names_neither fails against the old insert, which kept the last hash.
  • The geometry pass's naming does not collide with the change.
  • Everything new is still behind XCL_SHADER_MEM_STATS=1.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7358461671 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7358461671). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T20:52:45Z. --- **Follow-up review** of `1e6d4479`, since `75708679` (code reading only, not a merge-check; `PR description` red) · 1 nit **In short:** Since `75708679` the 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. The `xcl-smoke` block for this PR still names `75708679`, not this head. The other changes in the range belong to the stacked PRs (#3627, #3629, #3630). #### Nit 1. **The description is out of date in two places.** - **Tested** says the run at `5653fd69` "carries this PR's commit unchanged". That head has `04499713`, an earlier version of this commit without the shared-number change, on an older `main`. The GPU side is the same, so the run still counts, but the sentence should say which version ran. - **Not tested** still lists "the GPU test on a card" and "the whole suite", which **Tested** now reports as run. <details><summary>Checked and fine</summary> - Earlier finding fixed: there was no GPU run. `gpu_mem_stats_name_the_last_writers_of_a_page` and 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 uses `try_lock` on the crash path. - `a_program_number_two_shaders_share_names_neither` fails against the old `insert`, which kept the last hash. - The geometry pass's naming does not collide with the change. - Everything new is still behind `XCL_SHADER_MEM_STATS=1`. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Royalflamejlh commented 2026-12-02 21:32:33 +00:00 (Migrated from github.com)

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 5653fd69 had 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. Head ca0d3da7 (it moved only with the fixes below it).

AI use: Claude Code (Claude Opus 5.5) edited the description and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7359426767 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7359426767). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T21:32:33Z. --- Both fixed in the description. **Tested** now says the run at `5653fd69` had 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. Head `ca0d3da7` (it moved only with the fixes below it). AI use: Claude Code (Claude Opus 5.5) edited the description and wrote this reply.
Foniass commented 2026-12-02 21:34:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:34:37Z.


Follow-up review of ca0d3da7, since 1e6d4479 (code reading only, not a merge-check; PR description red) · no new findings

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 (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 description is red).

Checked and fine
  • The own commit is unchanged since the last review, so the points made there still apply.
  • The stack's lower changes (#3627's window runs, #3629's reset 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.

<!-- greyfinch-sync:ivall/xcl:comment:7359476310 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7359476310). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T21:34:37Z. --- **Follow-up review** of `ca0d3da7`, since `1e6d4479` (code reading only, not a merge-check; `PR description` red) · no new findings **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 (`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 description` is red). <details><summary>Checked and fine</summary> - The own commit is unchanged since the last review, so the points made there still apply. - The stack's lower changes (#3627's window runs, #3629's reset `OVERLAPPED`) are reviewed on those PRs. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Foniass commented 2026-12-03 02:35:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T02:35:03Z.


Follow-up review of b0bbbb18, since ca0d3da7 (code reading only, not a merge-check) · no new findings

In 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 following main's new UploadCopy jobs. Nothing new, and nothing blocks it.

Checked and fine
  • The own commit is unchanged since the last review.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7365628570 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3631#issuecomment-7365628570). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T02:35:03Z. --- **Follow-up review** of `b0bbbb18`, since `ca0d3da7` (code reading only, not a merge-check) · no new findings **In 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 following `main`'s new `UploadCopy` jobs. Nothing new, and nothing blocks it. <details><summary>Checked and fine</summary> - The own commit is unchanged since the last review. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3631:upstream-pr/3631'
git switch 'upstream-pr/3631'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3631'
git switch 'upstream-pr/3631'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3631'
git switch 'upstream-pr/3631'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3631'
git switch 'main'
git merge --squash 'upstream-pr/3631'
git switch 'main'
git merge --ff-only 'upstream-pr/3631'
git switch 'main'
git merge 'upstream-pr/3631'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3631
No description provided.