D3D12.X: XCL_SHADER_MEM_STATS counts shader accesses through the windows #3630

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

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


(Edited: head f2677d830, rebased with #3627's commit on main 395405e4c; 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_part reads no switch for the first time. On main 38ad22da.)

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

  • an access outside every window (and not the code's constant data) stores its 64 KiB page number in a slot by a hash of the page;
  • console lane 0 adds one to its page's read or write counter (16 windows × 65,536 pages, and one pair for everything outside them).

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 each XCL_WINDOW_STATS line: 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_STATS is a flag in the windows count, so it is part of the translated caches' keys as HEAP_FLAT is; 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_part and its call in crash_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: head 6da4db5d0 fixes 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.
  • Tests: 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

  • At 148482997: 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. the_first_slot_handed_out_starts_at_an_even_descriptor_with_or_without_the_stats_slot 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 this PR's commit as 5b16d606: before the review fixes first_free and the new crash_part): 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: 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 three kernelx tests 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 touch kernelx. gpu_mem_stats_name_only_the_page_outside_the_windows printed SKIPPED: 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 is round_tests::directed_reference_basics, which fails under Wine here on main too.
  • In 4 title runs on our development tree (2 with the switch on, 2 off), the warm run with it on found a 1.34 GB GPU heap in a coherent window (system memory) that shaders read about 1.14 billion times (lane 0) while the CPU wrote 256 K pages of it, marked "video memory"; #3619 moves that heap to video memory. That run logged 779 pages reached outside every window. Against runs with it off (not the same commit): 8.1 against 29.8 fps in the intro and 0.7 against 1.9 fps in the world with warm caches; with cold caches the pipelines took 1,114 s to prepare against about 105 s.

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: f2677d830246d1c7c25b7449c5290418f996c80f
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1567 (PresentX 1567)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15336 MB

Not tested

  • The GPU test on a card (it skipped here: the card was in use), native Windows, AMD, the whole suite (it needs a card), the switch in a run from this branch (the runs were on our development tree, which carries other changes).

AI use

  • Claude Code, Claude Opus 5.5: wrote the change, its tests and this description, made the title runs, and ported it to main.
<!-- greyfinch-sync:ivall/xcl:issue:5597695678 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T01:06:14Z. --- (Edited: head `f2677d830`, rebased with #3627's commit on `main` 395405e4c; 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_part` reads no switch for the first time. On `main` 38ad22da.) 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_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`): - an access outside every window (and not the code's constant data) stores its 64 KiB page number in a slot by a hash of the page; - console lane 0 adds one to its page's read or write counter (16 windows × 65,536 pages, and one pair for everything outside them). 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 each `XCL_WINDOW_STATS` line: 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_STATS` is a flag in the windows count, so it is part of the translated caches' keys as `HEAP_FLAT` is; 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_part` and its call in `crash_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: head `6da4db5d0` fixes 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. - Tests: `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** - At `148482997`: `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. `the_first_slot_handed_out_starts_at_an_even_descriptor_with_or_without_the_stats_slot` 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 this PR's commit as `5b16d606`: before the review fixes `first_free` and the new `crash_part`): `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`: 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 three `kernelx` tests 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 touch `kernelx`. `gpu_mem_stats_name_only_the_page_outside_the_windows` printed `SKIPPED: 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 is `round_tests::directed_reference_basics`, which fails under Wine here on `main` too. - In 4 title runs on our development tree (2 with the switch on, 2 off), the warm run with it on found a 1.34 GB GPU heap in a coherent window (system memory) that shaders read about 1.14 billion times (lane 0) while the CPU wrote 256 K pages of it, marked "video memory"; #3619 moves that heap to video memory. That run logged 779 pages reached outside every window. Against runs with it off (not the same commit): 8.1 against 29.8 fps in the intro and 0.7 against 1.9 fps in the world with warm caches; with cold caches the pipelines took 1,114 s to prepare against about 105 s. **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: f2677d830246d1c7c25b7449c5290418f996c80f gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 1567 (PresentX 1567) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15336 MB ``` **Not tested** - The GPU test on a card (it skipped here: the card was in use), native Windows, AMD, the whole suite (it needs a card), the switch in a run from this branch (the runs were on our development tree, which carries other changes). **AI use** - Claude Code, Claude Opus 5.5: wrote the change, its tests and this description, made the title runs, and ported it to `main`.
Foniass commented 2026-12-02 01:12:39 +00:00 (Migrated from github.com)

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

  • Runs with the switch off and can create the UMA region. shader_mem::end() (shader_mem.rs ~274) does not check enabled() and calls crate::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, including host.rs ~317 (after the title loads, before its entry point) and DLL_PROCESS_DETACH under the loader lock. That goes against the description's "off, nothing is emitted" and uma::existing()'s rule that observability must not allocate it; checking enabled() and using existing() fixes it.
  • The placement table counts pages twice and keeps freed allocations. allocated (~110) inserts every traced route and never removes one. A reservation (kernelx.rs ~979 / ~1013) and a later VirtualAlloc (sparse commit) inside it (~946) both become rows, and write_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 through trace_mem with got = 1.
  • Off by one page for a final negative offset. In window_at a negative constant Ea::S that is the last term is not added to lo (lower_window.rs ~111, if has_more), but stat_at (~149) records that lo, 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.
  • The new GPU code has never run. The only test that runs the instrumentation printed SKIPPED: no GPU, the whole suite was not run on a GPU, the title runs came from another tree, and the xcl-smoke blocks are owed (the reason PR description is red).
  • Size. The top commit is 586 changed lines, over ~400; the placement table with its kernelx.rs hook and the crash-report page_part could 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.

<!-- greyfinch-sync:ivall/xcl:comment:7331438981 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7331438981). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T01:12:39Z. --- Review (head 3e09e2f2, diff read, not a merge-check; draft, checks red): - **Runs with the switch off and can create the UMA region.** `shader_mem::end()` (`shader_mem.rs` ~274) does not check `enabled()` and calls `crate::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, including `host.rs` ~317 (after the title loads, before its entry point) and `DLL_PROCESS_DETACH` under the loader lock. That goes against the description's "off, nothing is emitted" and `uma::existing()`'s rule that observability must not allocate it; checking `enabled()` and using `existing()` fixes it. - **The placement table counts pages twice and keeps freed allocations.** `allocated` (~110) inserts every traced route and never removes one. A reservation (`kernelx.rs` ~979 / ~1013) and a later `VirtualAlloc (sparse commit)` inside it (~946) both become rows, and `write_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 through `trace_mem` with `got = 1`. - **Off by one page for a final negative offset.** In `window_at` a negative constant `Ea::S` that is the last term is not added to `lo` (`lower_window.rs` ~111, `if has_more`), but `stat_at` (~149) records that `lo`, 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. - **The new GPU code has never run.** The only test that runs the instrumentation printed `SKIPPED: no GPU`, the whole suite was not run on a GPU, the title runs came from another tree, and the `xcl-smoke` blocks are owed (the reason `PR description` is red). - **Size.** The top commit is 586 changed lines, over ~400; the placement table with its `kernelx.rs` hook and the crash-report `page_part` could 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.
Royalflamejlh commented 2026-12-02 02:55:50 +00:00 (Migrated from github.com)

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, with end() returning when the switch is off and using uma::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.

<!-- greyfinch-sync:ivall/xcl:comment:7333346313 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7333346313). Originally posted by [Royalflamejlh](https://github.com/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, with `end()` returning when the switch is off and using `uma::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.
Foniass commented 2026-12-02 03:01:06 +00:00 (Migrated from github.com)

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


Follow-up review (head 6da4db5d, since 3e09e2f2, diff read, not a merge-check; draft, checks red):

  • shader_mem::end() runs with the switch off and calls uma::get(): fixed here. end() and its report::write_final hook moved out; take() reads the buffer only when AT is set and only the XCL_WINDOW_STATS thread calls it (window_stats.rs ~234); crash_part uses uma::existing() (~123). The end() now in #3642 checks enabled() and uses existing().
  • The placement table counts pages twice and keeps freed allocations: moved to #3642 (not this PR any more). The description says the placement table is in #3631, but it is in #3642.
  • Off by one page for a final negative offset: fixed. window_at adds a final negative Ea::S to lo when mem_stats is on (lower_window.rs ~111), and gpu_mem_stats_count_a_negative_offset_on_the_page_below (heap_window_tests.rs) expects page 1, not 2.
  • No GPU run: still open. Neither GPU test has run on a card, the whole suite was not run on a GPU, and the xcl-smoke blocks are owed (the reason PR description is red).
  • Size: partly fixed. The own commit is now 501 lines with a reason given; the crash-report 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.

<!-- greyfinch-sync:ivall/xcl:comment:7333439089 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7333439089). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:01:06Z. --- Follow-up review (head 6da4db5d, since 3e09e2f2, diff read, not a merge-check; draft, checks red): - **`shader_mem::end()` runs with the switch off and calls `uma::get()`:** fixed here. `end()` and its `report::write_final` hook moved out; `take()` reads the buffer only when `AT` is set and only the `XCL_WINDOW_STATS` thread calls it (`window_stats.rs` ~234); `crash_part` uses `uma::existing()` (~123). The `end()` now in #3642 checks `enabled()` and uses `existing()`. - **The placement table counts pages twice and keeps freed allocations:** moved to #3642 (not this PR any more). The description says the placement table is in #3631, but it is in #3642. - **Off by one page for a final negative offset:** fixed. `window_at` adds a final negative `Ea::S` to `lo` when `mem_stats` is on (`lower_window.rs` ~111), and `gpu_mem_stats_count_a_negative_offset_on_the_page_below` (`heap_window_tests.rs`) expects page 1, not 2. - **No GPU run:** still open. Neither GPU test has run on a card, the whole suite was not run on a GPU, and the `xcl-smoke` blocks are owed (the reason `PR description` is red). - **Size:** partly fixed. The own commit is now 501 lines with a reason given; the crash-report `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.
Foniass commented 2026-12-02 03:40:14 +00:00 (Migrated from github.com)

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


Follow-up review (head 5b16d606, since 6da4db5d, diff read, not a merge-check; draft):

  • Earlier points: unchanged. git range-diff shows the own commit (5b16d606) identical to 6da4db5d; 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.

<!-- greyfinch-sync:ivall/xcl:comment:7334119556 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7334119556). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:40:14Z. --- Follow-up review (head 5b16d606, since 6da4db5d, diff read, not a merge-check; draft): - **Earlier points:** unchanged. `git range-diff` shows the own commit (`5b16d606`) identical to `6da4db5d`; 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.
Foniass commented 2026-12-02 13:47:41 +00:00 (Migrated from github.com)

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


Follow-up review (head 2ef753d9, since 5b16d606, 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:7347470138 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7347470138). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T13:47:41Z. --- Follow-up review (head 2ef753d9, since 5b16d606, 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.
bmjask commented 2026-12-02 16:46:57 +00:00 (Migrated from github.com)

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 534

@@ -531,7 +531,7 @@ pub unsafe fn shared_heap(dev: &ID3D12Device) -> bool {
             heap,
             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,

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772998386 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#discussion_r4772998386). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:46:57Z. **Code review location:** `crates/xcl/src/hle/d3d12x/console_heap.rs`; line 534 ~~~~diff @@ -531,7 +531,7 @@ pub unsafe fn shared_heap(dev: &ID3D12Device) -> bool { heap, 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, ~~~~ --- **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.
bmjask commented 2026-12-02 16:46:57 +00:00 (Migrated from github.com)

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.

  1. 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.

<!-- greyfinch-sync:ivall/xcl:review:6155179150 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#pullrequestreview-6155179150). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:46:57Z. **Review:** COMMENTED --- Review of `2ef753d9`: 1 finding(s) (1 critical), most severe first. 1. **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._
bmjask commented 2026-12-02 16:47:00 +00:00 (Migrated from github.com)

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.

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

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 534

@@ -531,7 +531,7 @@ pub unsafe fn shared_heap(dev: &ID3D12Device) -> bool {
             heap,
             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,

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775811445 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#discussion_r4775811445). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:47:01Z. **Code review location:** `crates/xcl/src/hle/d3d12x/console_heap.rs`; line 534 ~~~~diff @@ -531,7 +531,7 @@ pub unsafe fn shared_heap(dev: &ID3D12Device) -> bool { heap, 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, ~~~~ --- 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.
Foniass commented 2026-12-02 20:56:17 +00:00 (Migrated from github.com)

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


Follow-up review of 1606490f, since 2ef753d9 (code reading only, not a merge-check; PR description red) · 1 medium, 1 nit

In short: Since 2ef753d9 the stack was rebased onto main 38ad22da, and the PR's own commit has two real changes. With XCL_SHADER_MEM_STATS=1, the first descriptor the shared heap hands out is now even, with a unit test. crash_part no longer waits on either switch's first read. The new code is right and no earlier code finding is open. The xcl-smoke block still names 2ef753d9, which is why PR description is red. The whole-suite GPU run was made on an earlier version of this commit (5b16d606, inside #3642's 5653fd69), which has neither change.

Medium

  1. Size (still open). The PR's own commit is now 515 changed lines (484+/31-), and the description says 501. The ~400 target still applies. The crash-report part (crash_part in window_stats.rs ~129, page_part in shader_mem.rs ~171) could be its own PR on top of the counting. At least correct the count.

Nit

  1. Tested names an older commit. The description says the run at 5653fd69 "carries this PR's commit unchanged", but that head has 5b16d606 without first_free and the new crash_part. Say which version ran, or rerun it.
Checked and fine
  • Earlier finding fixed: shader_mem::end() ran with the switch off and called uma::get(). take() now reads the buffer only when AT is set, and crash_part uses uma::existing().
  • Earlier finding fixed: the placement table counted pages twice and kept freed allocations. It moved to #3642, and the description says so.
  • Earlier finding fixed: a final negative offset was counted one page off. window_at adds a final negative Ea::S, covered by gpu_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_part reads SECONDS.get() without initialising it. page_part reads only AT and returns an empty string while no buffer exists, so a crash report reads no switch and allocates nothing.
  • MEM_STATS is 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.

<!-- greyfinch-sync:ivall/xcl:comment:7358553013 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7358553013). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T20:56:17Z. --- **Follow-up review** of `1606490f`, since `2ef753d9` (code reading only, not a merge-check; `PR description` red) · 1 medium, 1 nit **In short:** Since `2ef753d9` the stack was rebased onto `main` `38ad22da`, and the PR's own commit has two real changes. With `XCL_SHADER_MEM_STATS=1`, the first descriptor the shared heap hands out is now even, with a unit test. `crash_part` no longer waits on either switch's first read. The new code is right and no earlier code finding is open. The `xcl-smoke` block still names `2ef753d9`, which is why `PR description` is red. The whole-suite GPU run was made on an earlier version of this commit (`5b16d606`, inside #3642's `5653fd69`), which has neither change. #### Medium 1. **Size (still open).** The PR's own commit is now 515 changed lines (484+/31-), and the description says 501. The ~400 target still applies. The crash-report part (`crash_part` in `window_stats.rs` ~129, `page_part` in `shader_mem.rs` ~171) could be its own PR on top of the counting. At least correct the count. #### Nit 2. **Tested names an older commit.** The description says the run at `5653fd69` "carries this PR's commit unchanged", but that head has `5b16d606` without `first_free` and the new `crash_part`. Say which version ran, or rerun it. <details><summary>Checked and fine</summary> - Earlier finding fixed: `shader_mem::end()` ran with the switch off and called `uma::get()`. `take()` now reads the buffer only when `AT` is set, and `crash_part` uses `uma::existing()`. - Earlier finding fixed: the placement table counted pages twice and kept freed allocations. It moved to #3642, and the description says so. - Earlier finding fixed: a final negative offset was counted one page off. `window_at` adds a final negative `Ea::S`, covered by `gpu_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_part` reads `SECONDS.get()` without initialising it. `page_part` reads only `AT` and returns an empty string while no buffer exists, so a crash report reads no switch and allocates nothing. - `MEM_STATS` is still masked wherever the window count is read and is part of the cache keys. With the switch off nothing is emitted. </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:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:32:31Z.


  1. The count is corrected to 515 (484+/31-). About 340 of the added lines are code and 100 are tests; the rest are blank lines and the README. The crash-report part is only page_part and its call in crash_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.
  2. Tested now says the run at 5653fd69 had 5b16d606, before first_free and the new crash_part. A whole-suite run at the stack's new top (head here 14848299, 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.

<!-- greyfinch-sync:ivall/xcl:comment:7359425957 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7359425957). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T21:32:31Z. --- 1. The count is corrected to 515 (484+/31-). About 340 of the added lines are code and 100 are tests; the rest are blank lines and the README. The crash-report part is only `page_part` and its call in `crash_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. 2. **Tested** now says the run at `5653fd69` had `5b16d606`, before `first_free` and the new `crash_part`. A whole-suite run at the stack's new top (head here `14848299`, 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.
Foniass commented 2026-12-02 21:34:21 +00:00 (Migrated from github.com)

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


Follow-up review of 14848299, since 1606490f (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:7359469729 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7359469729). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T21:34:21Z. --- **Follow-up review** of `14848299`, since `1606490f` (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:34:47 +00:00 (Migrated from github.com)

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


Follow-up review of f2677d83, since 14848299 (code reading only, not a merge-check) · 1 medium

In short: This push only rebases the stack onto main. This PR's own commit changed only in context (git range-diff), and #3627 underneath follows main's new UploadCopy jobs. The size point from earlier is unchanged.

Medium

  1. Size (still open). The PR's own commit is about 515 changed lines, over the ~400 target. The crash-report part (crash_part in window_stats.rs, page_part in shader_mem.rs) could be its own PR on top of the counting.
Checked and fine
  • The own commit's code is the same as at 14848299 apart from context.

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

<!-- greyfinch-sync:ivall/xcl:comment:7365623385 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3630#issuecomment-7365623385). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T02:34:47Z. --- **Follow-up review** of `f2677d83`, since `14848299` (code reading only, not a merge-check) · 1 medium **In short:** This push only rebases the stack onto `main`. This PR's own commit changed only in context (`git range-diff`), and #3627 underneath follows `main`'s new `UploadCopy` jobs. The size point from earlier is unchanged. #### Medium 1. **Size (still open).** The PR's own commit is about 515 changed lines, over the ~400 target. The crash-report part (`crash_part` in `window_stats.rs`, `page_part` in `shader_mem.rs`) could be its own PR on top of the counting. <details><summary>Checked and fine</summary> - The own commit's code is the same as at `14848299` apart from context. </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/3630:upstream-pr/3630'
git switch 'upstream-pr/3630'

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/3630'
git switch 'upstream-pr/3630'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3630'
git switch 'upstream-pr/3630'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3630'
git switch 'main'
git merge --squash 'upstream-pr/3630'
git switch 'main'
git merge --ff-only 'upstream-pr/3630'
git switch 'main'
git merge 'upstream-pr/3630'
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!3630
No description provided.