D3D12.X: XCL_SHADER_MEM_STATS writes a placement table per allocation #3642

Open
Royalflamejlh wants to merge 6 commits from upstream-pr/3642 into main
Royalflamejlh commented 2026-12-02 02:55:36 +00:00 (Migrated from github.com)

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


(Edited: head f1ae90ebb, rebased onto the second review's fixes below it; this PR's own commit changed only where the lines below moved. The approval was given at f0fdb029, before this head. The review's range point is fixed in #3627's commit, where given_in lives.)

Stacked on #3631, on #3630, on #3629, on #3628, on #3627; only the top commit belongs here. It needs #3630 for the GPU access counts and #3627 for the CPU's writes and uploads per page; it sits on #3631 to keep the stack in one line.

With XCL_SHADER_MEM_STATS=1, each XCL_WINDOW_STATS line and the end of the run write placement_<n>.tsv: per allocation of the title's in the windows (kernelx's routes, as XCL_TRACE_MEM names them) and per window for the pages none holds, the GPU accesses, the CPU pages written and KB uploaded, and a suggestion, video memory or coherent, by the PCIe bytes the other kind would cost (margin 4). It answers "is this allocation in the wrong kind of window": on a development tree it named a 1.34 GB write-combined GPU heap in a coherent window that shaders read over the bus every frame (what #3619 moves).

Split out of #3630 at review. A commit inside a recorded allocation (reserve, then commit from the reservation's base) counts as that allocation and keeps its route; a page two allocations hold otherwise counts once, in the first by address. A release (VirtualFree with MEM_RELEASE, XMemFree) that succeeds removes the allocation and every one inside it, and a reused address takes the new route; a decommit is no allocation. Noting a release keeps the title's last error, as XCL_TRACE_MEM does. The table at exit is written only with the switch on, from the UMA region that exists, and only if no other thread holds the counts or the allocations (it runs under the loader lock); the counts' lock is let go before the table is built and written. Off, nothing changes.

What is in it

  • hle/d3d12x/shader_mem.rs: the allocations, the table, its rows and the suggestion; kernelx.rs: allocations and releases noted; window_stats.rs, report.rs: written per line and at exit.
  • Tests: a_page_held_by_two_allocations_is_counted_in_the_first, a_commit_in_a_reservation_counts_as_the_reservation, a_release_takes_every_allocation_inside_it_and_the_address_takes_a_new_route, the_suggestion_weighs_what_would_cross_pcie, a_rejected_release_keeps_the_allocation.
  • README.md: the file.

Tested

  • At f1ae90ebb: 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.
  • RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, debug, at this head: 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, x86_64-pc-windows-gnu, release, CPU Vulkan: cargo check -p xcl with and without --tests; cargo test --lib -- --test-threads=8 file_reads write_log shader_mem window_stats lower_dxil kernelx on this head: 116 passed, 0 failed, 1 ignored in 2 of 3 runs; in the third kernelx::tests::an_address_keeps_the_page_the_title_mapped_there_last failed once and passed on its own.

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

this PR's head:

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

Not tested

  • The table from a title run at this head (the version before the review fixes ran on our development tree); the exit path with a thread ended inside the locks; AMD; Windows.

AI use
Claude Code (Claude Opus 5.5) wrote the change, its tests and this description.

<!-- greyfinch-sync:ivall/xcl:issue:5598889242 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T02:55:36Z. --- (Edited: head `f1ae90ebb`, rebased onto the second review's fixes below it; this PR's own commit changed only where the lines below moved. The approval was given at `f0fdb029`, before this head. The review's range point is fixed in #3627's commit, where `given_in` lives.) Stacked on #3631, on #3630, on #3629, on #3628, on #3627; only the top commit belongs here. It needs #3630 for the GPU access counts and #3627 for the CPU's writes and uploads per page; it sits on #3631 to keep the stack in one line. With `XCL_SHADER_MEM_STATS=1`, each `XCL_WINDOW_STATS` line and the end of the run write `placement_<n>.tsv`: per allocation of the title's in the windows (kernelx's routes, as `XCL_TRACE_MEM` names them) and per window for the pages none holds, the GPU accesses, the CPU pages written and KB uploaded, and a suggestion, video memory or coherent, by the PCIe bytes the other kind would cost (margin 4). It answers "is this allocation in the wrong kind of window": on a development tree it named a 1.34 GB write-combined GPU heap in a coherent window that shaders read over the bus every frame (what #3619 moves). Split out of #3630 at review. A commit inside a recorded allocation (reserve, then commit from the reservation's base) counts as that allocation and keeps its route; a page two allocations hold otherwise counts once, in the first by address. A release (VirtualFree with MEM_RELEASE, XMemFree) that succeeds removes the allocation and every one inside it, and a reused address takes the new route; a decommit is no allocation. Noting a release keeps the title's last error, as `XCL_TRACE_MEM` does. The table at exit is written only with the switch on, from the UMA region that exists, and only if no other thread holds the counts or the allocations (it runs under the loader lock); the counts' lock is let go before the table is built and written. Off, nothing changes. **What is in it** - `hle/d3d12x/shader_mem.rs`: the allocations, the table, its rows and the suggestion; `kernelx.rs`: allocations and releases noted; `window_stats.rs`, `report.rs`: written per line and at exit. - Tests: `a_page_held_by_two_allocations_is_counted_in_the_first`, `a_commit_in_a_reservation_counts_as_the_reservation`, `a_release_takes_every_allocation_inside_it_and_the_address_takes_a_new_route`, `the_suggestion_weighs_what_would_cross_pcie`, `a_rejected_release_keeps_the_allocation`. - `README.md`: the file. **Tested** - At `f1ae90ebb`: `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. - RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, debug, at this head: `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, x86_64-pc-windows-gnu, release, CPU Vulkan: `cargo check -p xcl` with and without `--tests`; `cargo test --lib -- --test-threads=8 file_reads write_log shader_mem window_stats lower_dxil kernelx` on this head: 116 passed, 0 failed, 1 ignored in 2 of 3 runs; in the third `kernelx::tests::an_address_keeps_the_page_the_title_mapped_there_last` failed once and passed on its own. **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: 5eaadb54c14e0fc29597b2a1689d7dbd83491303 gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 1575 (PresentX 1575) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15670 MB ``` this PR's head: ``` xcl-smoke v1 commit: f0fdb029d23ca8d16d90a0b20b0209ce7fcad756 gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 1634 (PresentX 1634) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 15172 MB ``` **Not tested** - The table from a title run at this head (the version before the review fixes ran on our development tree); the exit path with a thread ended inside the locks; AMD; Windows. **AI use** Claude Code (Claude Opus 5.5) wrote the change, its tests and this description.
Foniass commented 2026-12-02 03:04:39 +00:00 (Migrated from github.com)

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


Review (head 6bd290df, diff read, not a merge-check; draft, checks red):

  • A commit at a reservation's base replaces the reservation's row. allocated (shader_mem.rs ~114) inserts keyed by base, so a title that reserves at X and commits from X (VirtualAlloc (sparse commit), kernelx.rs ~946, returns X) overwrites the VirtualAlloc (graphics reserve, sparse) row with the commit's size and route; the reservation's route and extent drop out of the table and its pages past that commit go to (no allocation recorded). "Counted in the first by address" does not hold for equal bases, the usual reserve-then-commit pattern.
  • A release removes only the row at its own base. freed (~121, from kernelx.rs ~1230) removes &at only, so rows added by commits inside a released reservation (at X + k) stay, and once the address space is reused a stale row that comes first by address claims the new memory's pages under the old route.
  • end() takes blocking locks at DLL_PROCESS_DETACH. write_final uses lock_within (try-lock) because a holder may never release, but shader_mem::end() (report.rs ~308) calls take, which does SEEN.lock().unwrap() (~185) and ALLOCATIONS.lock().unwrap() (~220) and now holds SEEN while it builds the table over every window page and writes the file. If ExitProcess ends the XCL_WINDOW_STATS thread inside take, or a thread inside allocated / freed, the exit path waits forever under the loader lock.
  • freed changes the title's last error with the switch off. VirtualFree (kernelx.rs ~1230) and XMemFreeDefault (~1478) call freed, whose enabled() reads XCL_SHADER_MEM_STATS through env::var on first use, not wrapped in keep_last_error; on the default path that is often the first read, so the first MEM_RELEASE / XMemFree of a run can leave the last error at 203. trace_mem guards against exactly this.
  • The tests the description lists are not in the commit. It lists tests for "a release leaves the table, a reused address takes the new route, … the lines"; the commit adds only a_page_held_by_two_allocations_is_counted_in_the_first (distinct bases) and the_suggestion_weighs_what_would_cross_pcie. Nothing covers allocated / freed, the equal-base case or reuse.
  • Checks. The xcl-smoke blocks are owed (the reason PR description is red), and Tested is cargo check and module tests under Wine.

Fine: a page held by two allocations at different bases is now counted once (held); the VirtualFree (GPU view, …) trace with got = 1 adds no row (page_of(1) is None); end() returns with the switch off and uses uma::existing(); the suggestion's margin logic matches its test; about 175 changed lines.

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

<!-- greyfinch-sync:ivall/xcl:comment:7333505849 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7333505849). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:04:39Z. --- Review (head 6bd290df, diff read, not a merge-check; draft, checks red): - **A commit at a reservation's base replaces the reservation's row.** `allocated` (`shader_mem.rs` ~114) inserts keyed by base, so a title that reserves at `X` and commits from `X` (`VirtualAlloc (sparse commit)`, `kernelx.rs` ~946, returns `X`) overwrites the `VirtualAlloc (graphics reserve, sparse)` row with the commit's size and route; the reservation's route and extent drop out of the table and its pages past that commit go to `(no allocation recorded)`. "Counted in the first by address" does not hold for equal bases, the usual reserve-then-commit pattern. - **A release removes only the row at its own base.** `freed` (~121, from `kernelx.rs` ~1230) removes `&at` only, so rows added by commits inside a released reservation (at `X + k`) stay, and once the address space is reused a stale row that comes first by address claims the new memory's pages under the old route. - **`end()` takes blocking locks at `DLL_PROCESS_DETACH`.** `write_final` uses `lock_within` (try-lock) because a holder may never release, but `shader_mem::end()` (`report.rs` ~308) calls `take`, which does `SEEN.lock().unwrap()` (~185) and `ALLOCATIONS.lock().unwrap()` (~220) and now holds `SEEN` while it builds the table over every window page and writes the file. If `ExitProcess` ends the `XCL_WINDOW_STATS` thread inside `take`, or a thread inside `allocated` / `freed`, the exit path waits forever under the loader lock. - **`freed` changes the title's last error with the switch off.** `VirtualFree` (`kernelx.rs` ~1230) and `XMemFreeDefault` (~1478) call `freed`, whose `enabled()` reads `XCL_SHADER_MEM_STATS` through `env::var` on first use, not wrapped in `keep_last_error`; on the default path that is often the first read, so the first `MEM_RELEASE` / `XMemFree` of a run can leave the last error at 203. `trace_mem` guards against exactly this. - **The tests the description lists are not in the commit.** It lists tests for "a release leaves the table, a reused address takes the new route, … the lines"; the commit adds only `a_page_held_by_two_allocations_is_counted_in_the_first` (distinct bases) and `the_suggestion_weighs_what_would_cross_pcie`. Nothing covers `allocated` / `freed`, the equal-base case or reuse. - **Checks.** The `xcl-smoke` blocks are owed (the reason `PR description` is red), and **Tested** is `cargo check` and module tests under Wine. Fine: a page held by two allocations at different bases is now counted once (`held`); the `VirtualFree (GPU view, …)` trace with `got = 1` adds no row (`page_of(1)` is `None`); `end()` returns with the switch off and uses `uma::existing()`; the suggestion's margin logic matches its test; about 175 changed lines. 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:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T03:36:44Z.


All five fixed at 65c43819: a commit inside a reservation counts as the reservation (hold); a release removes every row inside its range (release); at exit take only try-locks and lets go of SEEN before building and writing the table; VirtualFree / XMemFreeDefault call freed inside keep_last_error; two tests added for the equal-base case and release/reuse (the exit locking and the last error have no test of their own), and the description's Tests line names the commit's four. The xcl-smoke blocks for this head are in.

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

<!-- greyfinch-sync:ivall/xcl:comment:7334059365 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7334059365). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T03:36:44Z. --- All five fixed at 65c43819: a commit inside a reservation counts as the reservation (`hold`); a release removes every row inside its range (`release`); at exit `take` only try-locks and lets go of `SEEN` before building and writing the table; `VirtualFree` / `XMemFreeDefault` call `freed` inside `keep_last_error`; two tests added for the equal-base case and release/reuse (the exit locking and the last error have no test of their own), and the description's Tests line names the commit's four. The `xcl-smoke` blocks for this head are in. AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply.
Foniass commented 2026-12-02 03:40:46 +00:00 (Migrated from github.com)

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


Follow-up review (head 65c43819, since 6bd290df, diff read, not a merge-check; draft):

  • A commit at a reservation's base replaced the reservation's row: fixed. hold (shader_mem.rs ~127) skips a range the allocation below or at the same base already covers, and a_commit_in_a_reservation_counts_as_the_reservation (~445) covers the equal base and an inner commit.
  • A release removed only the row at its own base: fixed. release (~134) removes every row whose base is inside the released range, and a_release_takes_every_allocation_inside_it_and_the_address_takes_a_new_route (~463) covers it and reuse of the address.
  • end() takes blocking locks at DLL_PROCESS_DETACH: partly fixed. SEEN and ALLOCATIONS are now only tried at exit (~201, ~238) and SEEN is released before the table is built, but while SEEN is held the final take still logs new outside pages through window_stats::region (~233), which calls mirrors::source (kernelx.rs ~301, STATE.lock()) and in_graphics_reservation (~161, GRAPHICS_RESERVATIONS.lock()). A thread ExitProcess ended inside VirtualAlloc / VirtualFree while holding one of them still hangs the exit when the last read finds new outside pages. Narrow, but the same class of hang.
  • freed changed the last error with the switch off: fixed; both calls are wrapped in keep_last_error (kernelx.rs ~1230, ~1478).
  • Tests the description listed were missing: fixed.
  • Checks: partly fixed. Both xcl-smoke blocks are in and PR description passes on its latest run (1670 vs 1620 frames, peak commit 114 %); Tested is still cargo check and a filtered --lib run under Wine.

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:7334128846 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7334128846). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:40:46Z. --- Follow-up review (head 65c43819, since 6bd290df, diff read, not a merge-check; draft): - **A commit at a reservation's base replaced the reservation's row:** fixed. `hold` (`shader_mem.rs` ~127) skips a range the allocation below or at the same base already covers, and `a_commit_in_a_reservation_counts_as_the_reservation` (~445) covers the equal base and an inner commit. - **A release removed only the row at its own base:** fixed. `release` (~134) removes every row whose base is inside the released range, and `a_release_takes_every_allocation_inside_it_and_the_address_takes_a_new_route` (~463) covers it and reuse of the address. - **`end()` takes blocking locks at `DLL_PROCESS_DETACH`:** partly fixed. `SEEN` and `ALLOCATIONS` are now only tried at exit (~201, ~238) and `SEEN` is released before the table is built, but while `SEEN` is held the final `take` still logs new outside pages through `window_stats::region` (~233), which calls `mirrors::source` (`kernelx.rs` ~301, `STATE.lock()`) and `in_graphics_reservation` (~161, `GRAPHICS_RESERVATIONS.lock()`). A thread `ExitProcess` ended inside `VirtualAlloc` / `VirtualFree` while holding one of them still hangs the exit when the last read finds new outside pages. Narrow, but the same class of hang. - **`freed` changed the last error with the switch off:** fixed; both calls are wrapped in `keep_last_error` (`kernelx.rs` ~1230, ~1478). - **Tests the description listed were missing:** fixed. - **Checks:** partly fixed. Both `xcl-smoke` blocks are in and `PR description` passes on its latest run (1670 vs 1620 frames, peak commit 114 %); **Tested** is still `cargo check` and a filtered `--lib` run under Wine. New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Royalflamejlh commented 2026-12-02 03:57:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T03:57:08Z.


Fixed at 5653fd69: at exit take logs no new outside page, so window_stats::region (and kernelx's STATE / GRAPHICS_RESERVATIONS locks) is not reached while SEEN is held. A whole-suite run on an RTX 5070 Ti at this head and its smoke blocks are running.

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

<!-- greyfinch-sync:ivall/xcl:comment:7334404438 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7334404438). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T03:57:08Z. --- Fixed at 5653fd69: at exit `take` logs no new outside page, so `window_stats::region` (and kernelx's `STATE` / `GRAPHICS_RESERVATIONS` locks) is not reached while `SEEN` is held. A whole-suite run on an RTX 5070 Ti at this head and its smoke blocks are running. AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
Foniass commented 2026-12-02 03:58:05 +00:00 (Migrated from github.com)

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


Follow-up review (head 5653fd69, since 65c43819, diff read, not a merge-check; draft, checks red):

  • end() takes blocking locks at DLL_PROCESS_DETACH: fixed. At exit take now logs no new outside page (shader_mem.rs ~231), so it no longer reaches window_stats::region and kernelx's STATE / GRAPHICS_RESERVATIONS locks; SEEN and ALLOCATIONS were already only tried.
  • Tested: unchanged (a filtered --lib run under Wine).

New: none; only that line and its comment changed.

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

<!-- greyfinch-sync:ivall/xcl:comment:7334419963 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7334419963). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:58:05Z. --- Follow-up review (head 5653fd69, since 65c43819, diff read, not a merge-check; draft, checks red): - **`end()` takes blocking locks at `DLL_PROCESS_DETACH`:** fixed. At exit `take` now logs no new outside page (`shader_mem.rs` ~231), so it no longer reaches `window_stats::region` and kernelx's `STATE` / `GRAPHICS_RESERVATIONS` locks; `SEEN` and `ALLOCATIONS` were already only tried. - **Tested:** unchanged (a filtered `--lib` run under Wine). New: none; only that line and its comment changed. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
mokkamokacaffe commented 2026-12-02 13:14:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-12-02T13:14:23Z.


merge-check
base: df0cfef638
head: 5653fd690b
merge: clean (local merge 73de2c26eb525b9c2afedde248fc222e82fb7b41)
build: cargo build --locked --workspace passed on the head and merge (Windows MSVC, debug).
tests: cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture exited 101 on main, head and merge. On each, 42 completed harnesses reported 148 passed, 0 failed, 20 ignored. The remaining library harness terminated with 0x80004005 after “sparse upload preparation still failed after bounded retries”, before it could report totals. Each run printed 24 SKIPPED notices (22 wave64, 2 heap windows off). The same termination occurred with one test thread on the head and merge.
review: With placement stats on, a rejected VirtualFree removes the row for a still-live sparse reservation. Reproduced twice on the head with a local test-only addition; steps below.
performance: Default-placement 60 s release smokes, base then merge, fresh separate caches and data roots: 1,597 vs 1,641 frames, peak commit 16,182 vs 16,156 MB. Both exited normally with zero crashes or device removals. One pair is insufficient to claim a speedup.
verdict: not yet: keep the allocation recorded when a release fails and add a regression test. The workspace abort also reproduces on pinned main.
hardware / tool and model: RTX 4080 SUPER (16 GB), NVIDIA 621.40, Core i9-14900KF, Windows 11 24H2 build 26100.9711, Rust 1.100.1 (x86_64-pc-windows-msvc), DXC 1.9.2609.5, Agility SDK 620 / OpenAI Codex (GPT-6) ran the tests, wrote the extra assertion and prepared this report.

Tested on the unmodified PR head

The PR head stayed at 5653fd69 throughout. Upstream main advanced from the tested base to d71578f8 before publication. The clean merge, workspace comparison and default smoke pair below refer to the pinned base above. The placement-table reproduction and diagnostic smoke used the submitted head itself.

  • With XCL_HEAP_WINDOWS=1, cargo test --locked -p xcl --lib -- --test-threads=4 --nocapture ::shader_mem:: gpu_mem_stats_ returned 10 passed, 0 failed, 0 ignored, no skips. All four placement-table regressions and all three GPU instrumentation tests executed.
  • A broader one-thread run with filters file_reads write_log shader_mem window_stats lower_dxil kernelx gpu_mem_stats_ returned 119 passed, 0 failed, 1 ignored, including 15 explicit wave64 skips. The kernelx page-mapping test previously reported as intermittent passed.
  • During the four-thread suite the head also failed a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads; main and the merge failed a_reset_while_the_last_submit_runs_records_on_another_pc_list. Both tests passed individually on all three trees. An initial run had additional temporary-cache failures; those disappeared with separate writable temp directories. The suite results above use those directories.

Placement-table check

A separate 90 s release smoke on the exact head used default placement with XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=all XCL_SHADER_MEM_STATS=1 XCL_WINDOW_STATS=10. All 11 TSVs had the expected ten-column header and row width. The last contained 27 rows, including 23 named allocation rows, with 168,373,549 sampled GPU reads in total. Neither default smoke emitted a table. The 90 s sample did not identify the 1,277 MiB candidate or measure guest CPU reads. Its frame count should not be used as the default-placement comparison.

Reproducing the missing allocation row

  1. In a fresh test process with heap windows and shader-memory stats enabled, call guest VirtualAlloc(NULL, 65536, MEM_GRAPHICS | MEM_RESERVE, PAGE_READWRITE). Confirm the returned address is a sparse reservation and is present in the placement allocation map.
  2. Call guest VirtualFree(base, 4096, MEM_RELEASE). It returns 0 as expected. sparse_reservation(base) still succeeds, but the placement map has already lost the base. A subsequent valid VirtualFree(base, 0, MEM_RELEASE) succeeds.
  3. I checked this in a separate checkout with only the local test added. The assertion that the row survived the rejected release failed in 2/2 fresh processes. The production hook calls shader_mem::freed before reservation_part rejects the nonzero size. Please remove the row only when the corresponding release succeeds. VirtualFree on the tested head

Regression run

Pinned main, default

xcl-smoke v1
commit: df0cfef638306f325b208e5adae18d35ab4bf4ed
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 60
exit: 0x0
frames shown: 1597 (PresentX 1597)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16182 MB

Local merge, default

xcl-smoke v1
commit: 73de2c26eb525b9c2afedde248fc222e82fb7b41
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 60
exit: 0x0
frames shown: 1641 (PresentX 1641)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16156 MB

Exact PR head, diagnostic enabled

xcl-smoke v1
commit: 5653fd690ba50154b354a9551da29da13683fb89
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 90
exit: 0x0
frames shown: 221 (PresentX 222)
presents per 2 s (last 3): 5 5 5
device removals: 0
crashes: 0
peak commit: 16497 MB
<!-- greyfinch-sync:ivall/xcl:comment:7346563765 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7346563765). Originally posted by [mokkamokacaffe](https://github.com/mokkamokacaffe) on 2026-12-02T13:14:23Z. --- merge-check base: df0cfef638306f325b208e5adae18d35ab4bf4ed head: 5653fd690ba50154b354a9551da29da13683fb89 merge: clean (local merge `73de2c26eb525b9c2afedde248fc222e82fb7b41`) build: `cargo build --locked --workspace` passed on the head and merge (Windows MSVC, debug). tests: `cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture` exited 101 on main, head and merge. On each, 42 completed harnesses reported 148 passed, 0 failed, 20 ignored. The remaining library harness terminated with `0x80004005` after “sparse upload preparation still failed after bounded retries”, before it could report totals. Each run printed 24 SKIPPED notices (22 wave64, 2 heap windows off). The same termination occurred with one test thread on the head and merge. review: With placement stats on, a rejected `VirtualFree` removes the row for a still-live sparse reservation. Reproduced twice on the head with a local test-only addition; steps below. performance: Default-placement 60 s release smokes, base then merge, fresh separate caches and data roots: 1,597 vs 1,641 frames, peak commit 16,182 vs 16,156 MB. Both exited normally with zero crashes or device removals. One pair is insufficient to claim a speedup. verdict: not yet: keep the allocation recorded when a release fails and add a regression test. The workspace abort also reproduces on pinned main. hardware / tool and model: RTX 4080 SUPER (16 GB), NVIDIA 621.40, Core i9-14900KF, Windows 11 24H2 build 26100.9711, Rust 1.100.1 (x86_64-pc-windows-msvc), DXC 1.9.2609.5, Agility SDK 620 / OpenAI Codex (GPT-6) ran the tests, wrote the extra assertion and prepared this report. **Tested on the unmodified PR head** The PR head stayed at `5653fd69` throughout. Upstream `main` advanced from the tested base to `d71578f8` before publication. The clean merge, workspace comparison and default smoke pair below refer to the pinned base above. The placement-table reproduction and diagnostic smoke used the submitted head itself. - With `XCL_HEAP_WINDOWS=1`, `cargo test --locked -p xcl --lib -- --test-threads=4 --nocapture ::shader_mem:: gpu_mem_stats_` returned **10 passed, 0 failed, 0 ignored**, no skips. All four placement-table regressions and all three GPU instrumentation tests executed. - A broader one-thread run with filters `file_reads write_log shader_mem window_stats lower_dxil kernelx gpu_mem_stats_` returned **119 passed, 0 failed, 1 ignored**, including 15 explicit wave64 skips. The kernelx page-mapping test previously reported as intermittent passed. - During the four-thread suite the head also failed `a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads`; main and the merge failed `a_reset_while_the_last_submit_runs_records_on_another_pc_list`. Both tests passed individually on all three trees. An initial run had additional temporary-cache failures; those disappeared with separate writable temp directories. The suite results above use those directories. **Placement-table check** A separate 90 s release smoke on the exact head used default placement with `XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=all XCL_SHADER_MEM_STATS=1 XCL_WINDOW_STATS=10`. All **11** TSVs had the expected ten-column header and row width. The last contained 27 rows, including 23 named allocation rows, with 168,373,549 sampled GPU reads in total. Neither default smoke emitted a table. The 90 s sample did not identify the 1,277 MiB candidate or measure guest CPU reads. Its frame count should not be used as the default-placement comparison. **Reproducing the missing allocation row** 1. In a fresh test process with heap windows and shader-memory stats enabled, call guest `VirtualAlloc(NULL, 65536, MEM_GRAPHICS | MEM_RESERVE, PAGE_READWRITE)`. Confirm the returned address is a sparse reservation and is present in the placement allocation map. 2. Call guest `VirtualFree(base, 4096, MEM_RELEASE)`. It returns 0 as expected. `sparse_reservation(base)` still succeeds, but the placement map has already lost the base. A subsequent valid `VirtualFree(base, 0, MEM_RELEASE)` succeeds. 3. I checked this in a separate checkout with only the local test added. The assertion that the row survived the rejected release failed in **2/2** fresh processes. The production hook calls `shader_mem::freed` before `reservation_part` rejects the nonzero size. Please remove the row only when the corresponding release succeeds. [VirtualFree on the tested head](https://github.com/xcl-dev/xcl/blob/5653fd690ba50154b354a9551da29da13683fb89/crates/xcl/src/hle/kernelx.rs#L1227-L1241) **Regression run** Pinned main, default ``` xcl-smoke v1 commit: df0cfef638306f325b208e5adae18d35ab4bf4ed gpu: NVIDIA GeForce RTX 4080 SUPER title: retail-local seconds: 60 exit: 0x0 frames shown: 1597 (PresentX 1597) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 16182 MB ``` Local merge, default ``` xcl-smoke v1 commit: 73de2c26eb525b9c2afedde248fc222e82fb7b41 gpu: NVIDIA GeForce RTX 4080 SUPER title: retail-local seconds: 60 exit: 0x0 frames shown: 1641 (PresentX 1641) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16156 MB ``` Exact PR head, diagnostic enabled ``` xcl-smoke v1 commit: 5653fd690ba50154b354a9551da29da13683fb89 gpu: NVIDIA GeForce RTX 4080 SUPER title: retail-local seconds: 90 exit: 0x0 frames shown: 221 (PresentX 222) presents per 2 s (last 3): 5 5 5 device removals: 0 crashes: 0 peak commit: 16497 MB ```
Foniass commented 2026-12-02 13:48:13 +00:00 (Migrated from github.com)

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


Follow-up review (head f0fdb029, since 5653fd69, diff read, not a merge-check; checks red):

  • Earlier points: still fixed.

New: none. Rows are now removed only after a release succeeds: the VirtualFree hook calls shader_mem::freed only when the release returned non-zero (kernelx.rs), and XMemFreeDefault only when sparse::free, uma.free or VirtualFree succeeded; a_rejected_release_keeps_the_allocation checks that a refused MEM_RELEASE keeps the row, through a test-only recording() switch. The rest is a rebase onto the current main.

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

<!-- greyfinch-sync:ivall/xcl:comment:7347484945 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7347484945). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T13:48:13Z. --- Follow-up review (head f0fdb029, since 5653fd69, diff read, not a merge-check; checks red): - **Earlier points:** still fixed. New: none. Rows are now removed only after a release succeeds: the `VirtualFree` hook calls `shader_mem::freed` only when the release returned non-zero (`kernelx.rs`), and `XMemFreeDefault` only when `sparse::free`, `uma.free` or `VirtualFree` succeeded; `a_rejected_release_keeps_the_allocation` checks that a refused `MEM_RELEASE` keeps the row, through a test-only `recording()` switch. The rest is a rebase onto the current `main`. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Royalflamejlh commented 2026-12-02 13:57:46 +00:00 (Migrated from github.com)

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


@mokkamokacaffe VirtualFree dropped the row before reservation_part refused the release. Fixed at f0fdb029d, rebased onto main 38ad22da: VirtualFree and XMemFreeDefault in kernelx.rs now forget the allocation only once the release has succeeded. The test is shader_mem::tests::a_rejected_release_keeps_the_allocation. It reserves 64 KiB of sparse graphics memory, has a 4 KiB MEM_RELEASE refused, checks the row is still there, then releases the reservation and checks the row is gone. It failed without the fix and passed with it, 1 run each, under Wine on the CPU; where no sparse window can be made it prints SKIPPED and passes. As you found, the workspace abort is on main too, so this PR does not change it.

Not tested: Windows; the XMemFreeDefault path (the test covers VirtualFree only); the whole workspace suite.

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

<!-- greyfinch-sync:ivall/xcl:comment:7347753218 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7347753218). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T13:57:46Z. --- @mokkamokacaffe `VirtualFree` dropped the row before `reservation_part` refused the release. Fixed at `f0fdb029d`, rebased onto `main` `38ad22da`: `VirtualFree` and `XMemFreeDefault` in `kernelx.rs` now forget the allocation only once the release has succeeded. The test is `shader_mem::tests::a_rejected_release_keeps_the_allocation`. It reserves 64 KiB of sparse graphics memory, has a 4 KiB `MEM_RELEASE` refused, checks the row is still there, then releases the reservation and checks the row is gone. It failed without the fix and passed with it, 1 run each, under Wine on the CPU; where no sparse window can be made it prints SKIPPED and passes. As you found, the workspace abort is on `main` too, so this PR does not change it. **Not tested:** Windows; the `XMemFreeDefault` path (the test covers `VirtualFree` only); the whole workspace suite. AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
bmjask commented 2026-12-02 17:49:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T17:49:14Z.


@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:7353675757 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7353675757). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T17:49:14Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
gut0to commented 2026-12-02 19:55:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T19:55:13Z.

Code review location: crates/xcl/src/hle/d3d12x/window_stats.rs; line 111

@@ -0,0 +1,344 @@
+//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window
+//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and
+//! was filled since the line before; and a line for the addresses the title gave the GPU that lie
+//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by
+//! default: each counter is then one branch.
+
+use std::collections::BTreeMap;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::OnceLock;
+use std::time::Duration;
+
+use super::view_want::{Path, NAMES, PATHS};
+use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS};
+
+fn seconds() -> Option<u64> {
+    static N: OnceLock<Option<u64>> = OnceLock::new();
+    *N.get_or_init(|| {
+        let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1);
+        crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s");
+        Some(n)
+    })
+}
+
+#[inline]
+pub(super) fn enabled() -> bool {
+    seconds().is_some()
+}
+
+#[derive(Clone, Copy)]
+pub(super) enum Traffic {
+    /// bytes copied up from the CPU
+    Up,
+    /// pages the write watch found written
+    Written,
+    /// bytes copied back to the CPU
+    Back,
+    /// GPU-view tiles given video memory and filled from the CPU view
+    Filled,
+}
+
+const TRAFFIC: usize = 4;
+/// the windows', and last what lies in none
+const SLOTS: usize = MAX_HEAP_WINDOWS + 1;
+/// addresses outside every window logged for each path
+const FIRST: u64 = 8;
+
+#[allow(clippy::declare_interior_mutable_const)]
+const ZERO: AtomicU64 = AtomicU64::new(0);
+#[allow(clippy::declare_interior_mutable_const)]
+const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC];
+static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS];
+static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS];
+
+fn on() -> Option<&'static Uma> {
+    if enabled() {
+        crate::gpu::uma::get()
+    } else {
+        None
+    }
+}
+
+fn add(u: &Uma, va: usize, what: Traffic, n: u64) {
+    COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed);
+}
+
+#[inline]
+pub(super) fn count(va: usize, what: Traffic, n: u64) {
+    if let Some(u) = on() {
+        add(u, va, what, n);
+    }
+}
+
+/// The copies of a submitted upload (window address, CPU address, bytes).
+#[inline]
+pub(super) fn uploaded(copies: &[(usize, usize, usize)]) {
+    if let Some(u) = on() {
+        for &(a, _, n) in copies {
+            add(u, a, Traffic::Up, n as u64);
+            if super::shader_mem::enabled() {
+                super::shader_mem::uploaded(u, a, n);
+            }
+        }
+    }
+}
+
+#[inline]
+pub(super) fn written(pages: &[usize]) {
+    if let Some(u) = on() {
+        for &p in pages {
+            add(u, p, Traffic::Written, 1);
+            if super::shader_mem::enabled() {
+                super::shader_mem::written(u, p);
+            }
+        }
+    }
+}
+
+/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and
+/// the first `FIRST` of each path logged.
+#[inline]
+pub(super) fn given(path: Path, va: u64, len: u64) {
+    if va == 0 {
+        return;
+    }
+    if let Some(u) = on() {
+        given_in(u, path, va, len);
+    }
+}
+
+fn given_in(u: &Uma, path: Path, va: u64, len: u64) {
+    if place(u, va as usize).is_some() {

Low: This only classifies the starting address with place(va), so a span beginning near the end of a window and extending past its boundary is treated as fully inside and omitted from OUTSIDE. That hides the out-of-window portion from the stats (for example, va = window_start + window_len - 1, len = 2). Could given_in require the entire half-open range to fit in one window, with a test for a boundary-crossing descriptor? AI-assisted review: GPT-6 helped inspect the telemetry path; I checked place and the UMA window tests.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775146635 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#discussion_r4775146635). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-02T19:55:13Z. **Code review location:** `crates/xcl/src/hle/d3d12x/window_stats.rs`; line 111 ~~~~diff @@ -0,0 +1,344 @@ +//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window +//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and +//! was filled since the line before; and a line for the addresses the title gave the GPU that lie +//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by +//! default: each counter is then one branch. + +use std::collections::BTreeMap; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::OnceLock; +use std::time::Duration; + +use super::view_want::{Path, NAMES, PATHS}; +use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS}; + +fn seconds() -> Option<u64> { + static N: OnceLock<Option<u64>> = OnceLock::new(); + *N.get_or_init(|| { + let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1); + crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s"); + Some(n) + }) +} + +#[inline] +pub(super) fn enabled() -> bool { + seconds().is_some() +} + +#[derive(Clone, Copy)] +pub(super) enum Traffic { + /// bytes copied up from the CPU + Up, + /// pages the write watch found written + Written, + /// bytes copied back to the CPU + Back, + /// GPU-view tiles given video memory and filled from the CPU view + Filled, +} + +const TRAFFIC: usize = 4; +/// the windows', and last what lies in none +const SLOTS: usize = MAX_HEAP_WINDOWS + 1; +/// addresses outside every window logged for each path +const FIRST: u64 = 8; + +#[allow(clippy::declare_interior_mutable_const)] +const ZERO: AtomicU64 = AtomicU64::new(0); +#[allow(clippy::declare_interior_mutable_const)] +const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC]; +static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS]; +static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS]; + +fn on() -> Option<&'static Uma> { + if enabled() { + crate::gpu::uma::get() + } else { + None + } +} + +fn add(u: &Uma, va: usize, what: Traffic, n: u64) { + COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed); +} + +#[inline] +pub(super) fn count(va: usize, what: Traffic, n: u64) { + if let Some(u) = on() { + add(u, va, what, n); + } +} + +/// The copies of a submitted upload (window address, CPU address, bytes). +#[inline] +pub(super) fn uploaded(copies: &[(usize, usize, usize)]) { + if let Some(u) = on() { + for &(a, _, n) in copies { + add(u, a, Traffic::Up, n as u64); + if super::shader_mem::enabled() { + super::shader_mem::uploaded(u, a, n); + } + } + } +} + +#[inline] +pub(super) fn written(pages: &[usize]) { + if let Some(u) = on() { + for &p in pages { + add(u, p, Traffic::Written, 1); + if super::shader_mem::enabled() { + super::shader_mem::written(u, p); + } + } + } +} + +/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and +/// the first `FIRST` of each path logged. +#[inline] +pub(super) fn given(path: Path, va: u64, len: u64) { + if va == 0 { + return; + } + if let Some(u) = on() { + given_in(u, path, va, len); + } +} + +fn given_in(u: &Uma, path: Path, va: u64, len: u64) { + if place(u, va as usize).is_some() { ~~~~ --- **Low**: This only classifies the starting address with `place(va)`, so a span beginning near the end of a window and extending past its boundary is treated as fully inside and omitted from `OUTSIDE`. That hides the out-of-window portion from the stats (for example, `va = window_start + window_len - 1`, `len = 2`). Could `given_in` require the entire half-open range to fit in one window, with a test for a boundary-crossing descriptor? AI-assisted review: GPT-6 helped inspect the telemetry path; I checked `place` and the UMA window tests.
gut0to commented 2026-12-02 19:55:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T19:55:13Z.

Review: COMMENTED


AI-assisted review: GPT-6 helped inspect this change; I verified the range-classification path and the current PR diff.

<!-- greyfinch-sync:ivall/xcl:review:6157873076 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#pullrequestreview-6157873076). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-02T19:55:13Z. **Review:** COMMENTED --- AI-assisted review: GPT-6 helped inspect this change; I verified the range-classification path and the current PR diff.
Royalflamejlh commented 2026-12-02 20:47:14 +00:00 (Migrated from github.com)

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

Code review location: crates/xcl/src/hle/d3d12x/window_stats.rs; line 111

@@ -0,0 +1,344 @@
+//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window
+//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and
+//! was filled since the line before; and a line for the addresses the title gave the GPU that lie
+//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by
+//! default: each counter is then one branch.
+
+use std::collections::BTreeMap;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::OnceLock;
+use std::time::Duration;
+
+use super::view_want::{Path, NAMES, PATHS};
+use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS};
+
+fn seconds() -> Option<u64> {
+    static N: OnceLock<Option<u64>> = OnceLock::new();
+    *N.get_or_init(|| {
+        let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1);
+        crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s");
+        Some(n)
+    })
+}
+
+#[inline]
+pub(super) fn enabled() -> bool {
+    seconds().is_some()
+}
+
+#[derive(Clone, Copy)]
+pub(super) enum Traffic {
+    /// bytes copied up from the CPU
+    Up,
+    /// pages the write watch found written
+    Written,
+    /// bytes copied back to the CPU
+    Back,
+    /// GPU-view tiles given video memory and filled from the CPU view
+    Filled,
+}
+
+const TRAFFIC: usize = 4;
+/// the windows', and last what lies in none
+const SLOTS: usize = MAX_HEAP_WINDOWS + 1;
+/// addresses outside every window logged for each path
+const FIRST: u64 = 8;
+
+#[allow(clippy::declare_interior_mutable_const)]
+const ZERO: AtomicU64 = AtomicU64::new(0);
+#[allow(clippy::declare_interior_mutable_const)]
+const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC];
+static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS];
+static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS];
+
+fn on() -> Option<&'static Uma> {
+    if enabled() {
+        crate::gpu::uma::get()
+    } else {
+        None
+    }
+}
+
+fn add(u: &Uma, va: usize, what: Traffic, n: u64) {
+    COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed);
+}
+
+#[inline]
+pub(super) fn count(va: usize, what: Traffic, n: u64) {
+    if let Some(u) = on() {
+        add(u, va, what, n);
+    }
+}
+
+/// The copies of a submitted upload (window address, CPU address, bytes).
+#[inline]
+pub(super) fn uploaded(copies: &[(usize, usize, usize)]) {
+    if let Some(u) = on() {
+        for &(a, _, n) in copies {
+            add(u, a, Traffic::Up, n as u64);
+            if super::shader_mem::enabled() {
+                super::shader_mem::uploaded(u, a, n);
+            }
+        }
+    }
+}
+
+#[inline]
+pub(super) fn written(pages: &[usize]) {
+    if let Some(u) = on() {
+        for &p in pages {
+            add(u, p, Traffic::Written, 1);
+            if super::shader_mem::enabled() {
+                super::shader_mem::written(u, p);
+            }
+        }
+    }
+}
+
+/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and
+/// the first `FIRST` of each path logged.
+#[inline]
+pub(super) fn given(path: Path, va: u64, len: u64) {
+    if va == 0 {
+        return;
+    }
+    if let Some(u) = on() {
+        given_in(u, path, va, len);
+    }
+}
+
+fn given_in(u: &Uma, path: Path, va: u64, len: u64) {
+    if place(u, va as usize).is_some() {

Right. given_in is #3627's, and it placed only the first byte. A range now counts as outside unless its last byte is in the same window as its first, and its log line says only its start does, in window N. traffic_adds_to_its_window_and_addresses_in_one_are_not_outside now gives a 2-byte range across the coherent window's end (counted) and one that ends on it (not counted); it failed without the fix. The fix is in #3627's commit (2580976a), and this PR's own commit changed only where the commits below moved. Head d39753cb.

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

<!-- greyfinch-sync:ivall/xcl:review-comment:4775814096 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#discussion_r4775814096). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:47:14Z. **Code review location:** `crates/xcl/src/hle/d3d12x/window_stats.rs`; line 111 ~~~~diff @@ -0,0 +1,344 @@ +//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window +//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and +//! was filled since the line before; and a line for the addresses the title gave the GPU that lie +//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by +//! default: each counter is then one branch. + +use std::collections::BTreeMap; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::OnceLock; +use std::time::Duration; + +use super::view_want::{Path, NAMES, PATHS}; +use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS}; + +fn seconds() -> Option<u64> { + static N: OnceLock<Option<u64>> = OnceLock::new(); + *N.get_or_init(|| { + let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1); + crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s"); + Some(n) + }) +} + +#[inline] +pub(super) fn enabled() -> bool { + seconds().is_some() +} + +#[derive(Clone, Copy)] +pub(super) enum Traffic { + /// bytes copied up from the CPU + Up, + /// pages the write watch found written + Written, + /// bytes copied back to the CPU + Back, + /// GPU-view tiles given video memory and filled from the CPU view + Filled, +} + +const TRAFFIC: usize = 4; +/// the windows', and last what lies in none +const SLOTS: usize = MAX_HEAP_WINDOWS + 1; +/// addresses outside every window logged for each path +const FIRST: u64 = 8; + +#[allow(clippy::declare_interior_mutable_const)] +const ZERO: AtomicU64 = AtomicU64::new(0); +#[allow(clippy::declare_interior_mutable_const)] +const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC]; +static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS]; +static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS]; + +fn on() -> Option<&'static Uma> { + if enabled() { + crate::gpu::uma::get() + } else { + None + } +} + +fn add(u: &Uma, va: usize, what: Traffic, n: u64) { + COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed); +} + +#[inline] +pub(super) fn count(va: usize, what: Traffic, n: u64) { + if let Some(u) = on() { + add(u, va, what, n); + } +} + +/// The copies of a submitted upload (window address, CPU address, bytes). +#[inline] +pub(super) fn uploaded(copies: &[(usize, usize, usize)]) { + if let Some(u) = on() { + for &(a, _, n) in copies { + add(u, a, Traffic::Up, n as u64); + if super::shader_mem::enabled() { + super::shader_mem::uploaded(u, a, n); + } + } + } +} + +#[inline] +pub(super) fn written(pages: &[usize]) { + if let Some(u) = on() { + for &p in pages { + add(u, p, Traffic::Written, 1); + if super::shader_mem::enabled() { + super::shader_mem::written(u, p); + } + } + } +} + +/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and +/// the first `FIRST` of each path logged. +#[inline] +pub(super) fn given(path: Path, va: u64, len: u64) { + if va == 0 { + return; + } + if let Some(u) = on() { + given_in(u, path, va, len); + } +} + +fn given_in(u: &Uma, path: Path, va: u64, len: u64) { + if place(u, va as usize).is_some() { ~~~~ --- Right. `given_in` is #3627's, and it placed only the first byte. A range now counts as outside unless its last byte is in the same window as its first, and its log line says `only its start does, in window N`. `traffic_adds_to_its_window_and_addresses_in_one_are_not_outside` now gives a 2-byte range across the coherent window's end (counted) and one that ends on it (not counted); it failed without the fix. The fix is in #3627's commit (`2580976a`), and this PR's own commit changed only where the commits below moved. Head `d39753cb`. AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
Foniass commented 2026-12-02 20:52:29 +00:00 (Migrated from github.com)

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


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

In short: The PR writes placement_<n>.tsv with each XCL_WINDOW_STATS line, and at exit when XCL_SHADER_MEM_STATS=1. The table lists the title's allocations in the memory windows with their GPU accesses, CPU writes and uploads, and suggests video memory or coherent for each. Since f0fdb029 the PR's own commit is unchanged apart from context: it was rebased onto the review fixes in the stacked PRs below it. The description now reports a full workspace run on a GPU. The reading found nothing new. The xcl-smoke block for this PR still names f0fdb029, not this head, which is why PR description is red.

Checked and fine
  • Earlier finding fixed: a commit at a reservation's base no longer replaces the reservation's row (hold, shader_mem.rs ~141). Covered by a_commit_in_a_reservation_counts_as_the_reservation.
  • Earlier finding fixed: a release removes every row whose base lies inside it (release, ~148). Covered by a_release_takes_every_allocation_inside_it_and_the_address_takes_a_new_route.
  • Earlier finding fixed: at DLL_PROCESS_DETACH, take(u, true) only tries SEEN and ALLOCATIONS (~263), releases SEEN before building the table, and never reaches kernelx's STATE / GRAPHICS_RESERVATIONS.
  • Earlier finding fixed: freed runs inside keep_last_error in VirtualFree and XMemFreeDefault (kernelx.rs ~1231, ~1492), and only after a release that succeeded. Covered by a_rejected_release_keeps_the_allocation.
  • Earlier finding fixed: the tests the description lists are in the commit.
  • With the switch off, allocated costs two cached OnceLock reads.
  • table indexes only with page numbers below STAT_PAGES.
  • write_final calls end() only when there is no crash.
  • The PR's own commit is about 290 lines. The rest belongs to the stacked 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:7358454546 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7358454546). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T20:52:29Z. --- **Follow-up review** of `d39753cb`, since `f0fdb029` (code reading only, not a merge-check; `PR description` red) · no new findings **In short:** The PR writes `placement_<n>.tsv` with each `XCL_WINDOW_STATS` line, and at exit when `XCL_SHADER_MEM_STATS=1`. The table lists the title's allocations in the memory windows with their GPU accesses, CPU writes and uploads, and suggests video memory or coherent for each. Since `f0fdb029` the PR's own commit is unchanged apart from context: it was rebased onto the review fixes in the stacked PRs below it. The description now reports a full workspace run on a GPU. The reading found nothing new. The `xcl-smoke` block for this PR still names `f0fdb029`, not this head, which is why `PR description` is red. <details><summary>Checked and fine</summary> - Earlier finding fixed: a commit at a reservation's base no longer replaces the reservation's row (`hold`, `shader_mem.rs` ~141). Covered by `a_commit_in_a_reservation_counts_as_the_reservation`. - Earlier finding fixed: a release removes every row whose base lies inside it (`release`, ~148). Covered by `a_release_takes_every_allocation_inside_it_and_the_address_takes_a_new_route`. - Earlier finding fixed: at `DLL_PROCESS_DETACH`, `take(u, true)` only tries `SEEN` and `ALLOCATIONS` (~263), releases `SEEN` before building the table, and never reaches kernelx's `STATE` / `GRAPHICS_RESERVATIONS`. - Earlier finding fixed: `freed` runs inside `keep_last_error` in `VirtualFree` and `XMemFreeDefault` (`kernelx.rs` ~1231, ~1492), and only after a release that succeeded. Covered by `a_rejected_release_keeps_the_allocation`. - Earlier finding fixed: the tests the description lists are in the commit. - With the switch off, `allocated` costs two cached `OnceLock` reads. - `table` indexes only with page numbers below `STAT_PAGES`. - `write_final` calls `end()` only when there is no crash. - The PR's own commit is about 290 lines. The rest belongs to the stacked 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-02 21:34:53 +00:00 (Migrated from github.com)

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


Follow-up review of f1ae90eb, since d39753cb (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:7359482771 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3642#issuecomment-7359482771). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T21:34:53Z. --- **Follow-up review** of `f1ae90eb`, since `d39753cb` (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>
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/3642:upstream-pr/3642'
git switch 'upstream-pr/3642'

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