D3D12.X: remember committed source regions instead of asking Windows per submit #3575

Open
raylitebull wants to merge 1 commit from upstream-pr/3575 into main
raylitebull commented 2026-12-01 14:44:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-12-01T14:44:20Z.


Every submit asked Windows about each CPU-view tile it touched while holding the sparse lock: first K32QueryWorkingSetEx, then VirtualQuery for the pages outside the working set. shader::readable and read_committed_into also walked VirtualQuery for title memory outside the coherent window. This PR keeps the spans found committed and accessible. Whatever takes pages away clears their span both before Windows does it and after. On amd-dev (3a3a8e9c, RX 9070 XT, 5+ minutes in a retail title's world), asking Windows which pages are committed went from 1.513 ms avg / 10.233 ms max to 0.002 / 0.009 ms, and the sparse lock per submit from 1.637 / 10.414 ms to 0.149 / 0.767 ms.

What is in it

  • sparse.rs: SourceRegions (sorted, coalesced spans plus a log of the latest 256 invalidations, so a query that raced one replays it or drops its result). holes_now goes through source_holes_cached, and known_readable / cache_readable_region serve shader::readable. Sparse's own decommit and release paths invalidate. XCL_SOURCE_HOLES_CACHE=0 turns the cache off. sparse::free clears after its decommit too. Each unit test has a cache of its own (tests::SOURCE_REGIONS), on only where a test turns it on (tests::REGION_CACHE), so tests that free memory with plain VirtualFree leave nothing behind for others.
  • kernelx.rs: VirtualFree and VirtualAlloc become wrappers (virtual_free / virtual_alloc hold the old bodies). VirtualFree clears the span before and after every path (placeholders, sparse windows, GPU views, the general one). A free of size 0 clears the whole reservation (whole_len): its length comes from XCL's own records (sparse and view windows, graphics reservations) or from VirtualQuery. A block of a committed window clears nothing, and the whole cache is cleared only when the length is unknown. VirtualAlloc clears it around a commit that leaves pages unreadable. The same before-and-after clearing covers VirtualFreeEx of the process's own memory, non-writable VirtualProtect(Ex), release_at and give_back_homes (physical pages given up), the home block FreeTitlePhysicalPages releases, and GPU-view reservations (mirrors::reserved). The clear after a call happens only when the call succeeded, so the title's GetLastError is untouched.
  • gpu/shader.rs: readable answers from the cache first, and records the regions it finds in UMA windows and graphics reservations.
  • title_textures.rs: read_committed_into copies at once when the range is known readable (from 4d6d4a77).
  • Not ported from amd-dev: the alias hook (main has no kernelx::alias) and the XCL_LOOK_STATS=2 timing lines.
  • Tests: source_holes_cached_reuses_regions_and_invalidates_only_freed_ranges, and the_title_s_frees_and_protections_leave_the_region_cache, which goes through kernelx's VirtualFree (a decommit, then the release of a reservation with holes in it, while another allocation stays cached), VirtualProtect and VirtualAlloc.

Tested

  • No Windows machine or GPU here: a Linux x86_64 cloud machine (Ubuntu 24.04), rustc 1.99.0, debug build.
  • cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: no errors, no new warnings.
  • The lib unit tests of the touched modules, built for x86_64-pc-windows-gnu and run under Wine 9.0 (no GPU) with --test-threads=4, next to the same filters on main b2b1f109:
    • hle::d3d12x::sparse: 92 passed, 50 failed, 1 ignored (main: 90 / 50 / 1)
    • hle::kernelx: 66 passed, 0 failed, 1 ignored (main: 66 / 0 / 1)
    • gpu::shader: 4 passed, 2 failed (main: 4 / 2)
    • hle::d3d12x::title_textures: 64 passed, 1 failed, 1 ignored (main: 64 / 1 / 1)
      The failures are the same tests on both, ones that need a D3D12 device or Windows' working-set queries, which Wine lacks.
  • CI's Build and test (Windows, no GPU) passed on the earlier heads eab0ffba and 15ae499c.

Regression run
Not run yet: there was no Windows machine or title here. scripts/smoke.ps1 still has to run on a title, built from main and from this head, so PR checks fails until those two blocks are added.

Not tested

  • The Windows (MSVC) build and the whole suite (cargo test --workspace -- --test-threads=4) on Windows, with or without a GPU; CI's no-GPU job is the first Windows run.
  • Any title on main, and any performance on main: the numbers above are from amd-dev.
  • The cache against a real title's frees and protection changes on main, whose kernelx differs from amd-dev's (no alias module). The physical-page paths (release_at, FreeTitlePhysicalPages) are not covered by a unit test.
  • The cost of whole_len's VirtualQuery walk on a title's frees of size 0 of plain memory (not UMA blocks or graphics reservations, which need no query).

AI use

  • Capy with Claude Opus 5.5 ported raylitebull's amd-dev commit 3a3a8e9c to main, split it into this PR and five others, and wrote the test, the commit message and this description. The amd-dev measurements are raylitebull's own runs.

Open in Capy

<!-- greyfinch-sync:ivall/xcl:issue:5588046643 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-12-01T14:44:20Z. --- Every submit asked Windows about each CPU-view tile it touched while holding the sparse lock: first `K32QueryWorkingSetEx`, then `VirtualQuery` for the pages outside the working set. `shader::readable` and `read_committed_into` also walked `VirtualQuery` for title memory outside the coherent window. This PR keeps the spans found committed and accessible. Whatever takes pages away clears their span both before Windows does it and after. On `amd-dev` (`3a3a8e9c`, RX 9070 XT, 5+ minutes in a retail title's world), asking Windows which pages are committed went from 1.513 ms avg / 10.233 ms max to 0.002 / 0.009 ms, and the sparse lock per submit from 1.637 / 10.414 ms to 0.149 / 0.767 ms. **What is in it** - `sparse.rs`: `SourceRegions` (sorted, coalesced spans plus a log of the latest 256 invalidations, so a query that raced one replays it or drops its result). `holes_now` goes through `source_holes_cached`, and `known_readable` / `cache_readable_region` serve `shader::readable`. Sparse's own decommit and release paths invalidate. `XCL_SOURCE_HOLES_CACHE=0` turns the cache off. `sparse::free` clears after its decommit too. Each unit test has a cache of its own (`tests::SOURCE_REGIONS`), on only where a test turns it on (`tests::REGION_CACHE`), so tests that free memory with plain `VirtualFree` leave nothing behind for others. - `kernelx.rs`: `VirtualFree` and `VirtualAlloc` become wrappers (`virtual_free` / `virtual_alloc` hold the old bodies). `VirtualFree` clears the span before and after every path (placeholders, sparse windows, GPU views, the general one). A free of size 0 clears the whole reservation (`whole_len`): its length comes from XCL's own records (sparse and view windows, graphics reservations) or from `VirtualQuery`. A block of a committed window clears nothing, and the whole cache is cleared only when the length is unknown. `VirtualAlloc` clears it around a commit that leaves pages unreadable. The same before-and-after clearing covers `VirtualFreeEx` of the process's own memory, non-writable `VirtualProtect(Ex)`, `release_at` and `give_back_homes` (physical pages given up), the home block `FreeTitlePhysicalPages` releases, and GPU-view reservations (`mirrors::reserved`). The clear after a call happens only when the call succeeded, so the title's `GetLastError` is untouched. - `gpu/shader.rs`: `readable` answers from the cache first, and records the regions it finds in UMA windows and graphics reservations. - `title_textures.rs`: `read_committed_into` copies at once when the range is known readable (from `4d6d4a77`). - Not ported from `amd-dev`: the `alias` hook (`main` has no `kernelx::alias`) and the `XCL_LOOK_STATS=2` timing lines. - Tests: `source_holes_cached_reuses_regions_and_invalidates_only_freed_ranges`, and `the_title_s_frees_and_protections_leave_the_region_cache`, which goes through kernelx's `VirtualFree` (a decommit, then the release of a reservation with holes in it, while another allocation stays cached), `VirtualProtect` and `VirtualAlloc`. **Tested** - No Windows machine or GPU here: a Linux x86_64 cloud machine (Ubuntu 24.04), rustc 1.99.0, debug build. - `cargo check --workspace --all-targets --target x86_64-pc-windows-gnu`: no errors, no new warnings. - The lib unit tests of the touched modules, built for `x86_64-pc-windows-gnu` and run under Wine 9.0 (no GPU) with `--test-threads=4`, next to the same filters on `main` `b2b1f109`: - `hle::d3d12x::sparse`: 92 passed, 50 failed, 1 ignored (main: 90 / 50 / 1) - `hle::kernelx`: 66 passed, 0 failed, 1 ignored (main: 66 / 0 / 1) - `gpu::shader`: 4 passed, 2 failed (main: 4 / 2) - `hle::d3d12x::title_textures`: 64 passed, 1 failed, 1 ignored (main: 64 / 1 / 1) The failures are the same tests on both, ones that need a D3D12 device or Windows' working-set queries, which Wine lacks. - CI's `Build and test (Windows, no GPU)` passed on the earlier heads `eab0ffba` and `15ae499c`. **Regression run** Not run yet: there was no Windows machine or title here. `scripts/smoke.ps1` still has to run on a title, built from `main` and from this head, so `PR checks` fails until those two blocks are added. **Not tested** - The Windows (MSVC) build and the whole suite (`cargo test --workspace -- --test-threads=4`) on Windows, with or without a GPU; CI's no-GPU job is the first Windows run. - Any title on `main`, and any performance on `main`: the numbers above are from `amd-dev`. - The cache against a real title's frees and protection changes on `main`, whose kernelx differs from `amd-dev`'s (no `alias` module). The physical-page paths (`release_at`, `FreeTitlePhysicalPages`) are not covered by a unit test. - The cost of `whole_len`'s `VirtualQuery` walk on a title's frees of size 0 of plain memory (not UMA blocks or graphics reservations, which need no query). **AI use** - Capy with Claude Opus 5.5 ported raylitebull's `amd-dev` commit `3a3a8e9c` to `main`, split it into this PR and five others, and wrote the test, the commit message and this description. The `amd-dev` measurements are raylitebull's own runs. <!-- capy-badge:start --> <a href="https://capy.ai/thread/jam_01M8RYX4CVNT8FXPPZSVVY1EFJ"><picture><source media="(prefers-color-scheme: dark)" srcset="https://capy.ai/badge/accent-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://capy.ai/badge/accent-light.svg"><img alt="Open in Capy" src="https://capy.ai/badge/accent-light.svg"></picture></a> <!-- capy-badge:end -->
Foniass commented 2026-12-01 14:53:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T14:53:09Z.


Review (head eab0ffba, diff read, not a merge-check; draft):

  • Freed memory can stay "committed" in the cache. The cache's own doc comment (sparse.rs ~399) says to clear it around any decommit or release. Several paths clear only before Windows decommits:

    • sparse::free (~5148-5157: decommitted, then VirtualFree);
    • kernelx's VirtualFree for sparse windows and GPU views (kernelx.rs ~1216, ~1244);
    • placeholders::free.

    If shader::readable queries in the gap, it caches the span (shader.rs ~237) as committed after the decommit, and a later readable or read_committed_into reads freed memory, which can crash. source_decommit / source_release clear before and after, and these paths need the same.

  • Unmapped physical pages can stay cached. release_at (kernelx.rs ~2307) decommits through source_going, which clears only for paired CPU views or with page mappings on. A page unmapped or moved out of a graphics reservation stays cached, since readable caches those reservations (unverified that a title hits it).

  • Re-committing committed pages with VirtualAlloc(MEM_COMMIT, PAGE_NOACCESS / GUARD) changes protection without clearing (unverified whether a title does it).

  • No test covers the hooks. The cache is off in tests unless turned on, and the one new test clears it by hand, so nothing would catch a missing hook. A test that frees through each path, then asks readable, would.

  • It's on by default (XCL_SOURCE_HOLES_CACHE=0 turns it off), and the gain isn't measured on main. The numbers are from amd-dev, whose kernelx differs, and include the read_committed_into change from 4d6d4a77.

Fine: the lock is never held across a Windows call or around other locks, the replay of the 64 latest clears is right (a query that can't be replayed is dropped), holes are never cached (so commits and lazy commits need no hook), paired CPU views are covered, and memory is bounded. #2772, #1191 and #2544 edit the same kernelx hooks.

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

<!-- greyfinch-sync:ivall/xcl:comment:7314986657 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7314986657). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T14:53:09Z. --- Review (head eab0ffba, diff read, not a merge-check; draft): - **Freed memory can stay "committed" in the cache.** The cache's own doc comment (`sparse.rs` ~399) says to clear it around any decommit or release. Several paths clear only before Windows decommits: - `sparse::free` (~5148-5157: `decommitted`, then `VirtualFree`); - kernelx's `VirtualFree` for sparse windows and GPU views (`kernelx.rs` ~1216, ~1244); - `placeholders::free`. If `shader::readable` queries in the gap, it caches the span (`shader.rs` ~237) as committed after the decommit, and a later `readable` or `read_committed_into` reads freed memory, which can crash. `source_decommit` / `source_release` clear before and after, and these paths need the same. - **Unmapped physical pages can stay cached.** `release_at` (`kernelx.rs` ~2307) decommits through `source_going`, which clears only for paired CPU views or with page mappings on. A page unmapped or moved out of a graphics reservation stays cached, since `readable` caches those reservations (unverified that a title hits it). - Re-committing committed pages with `VirtualAlloc(MEM_COMMIT, PAGE_NOACCESS / GUARD)` changes protection without clearing (unverified whether a title does it). - **No test covers the hooks.** The cache is off in tests unless turned on, and the one new test clears it by hand, so nothing would catch a missing hook. A test that frees through each path, then asks `readable`, would. - **It's on by default** (`XCL_SOURCE_HOLES_CACHE=0` turns it off), and the gain isn't measured on main. The numbers are from `amd-dev`, whose kernelx differs, and include the `read_committed_into` change from 4d6d4a77. Fine: the lock is never held across a Windows call or around other locks, the replay of the 64 latest clears is right (a query that can't be replayed is dropped), holes are never cached (so commits and lazy commits need no hook), paired CPU views are covered, and memory is bounded. #2772, #1191 and #2544 edit the same kernelx hooks. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
capy-ai[bot] commented 2026-12-01 15:06:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by capy-ai[bot] on 2026-12-01T15:06:16Z.


@Foniass thanks, the gaps were real, and most of them are on amd-dev too. Fixed in 15ae499c:

  • Before and after: kernelx VirtualFree is now a wrapper that clears the span before the call and after a successful one, whichever path the free takes (placeholders, sparse windows, GPU views, the general one). VirtualFreeEx of the process's own memory, sparse::free, release_at (which also covers pages moved away from home) and the block FreeTitlePhysicalPages releases now clear before and after too.
  • Whole-reservation releases: a release of size 0 now clears the whole cache. Before, it dropped only the span holding the address, so a reservation with holes left its other spans cached.
  • Commits that leave pages unreadable: VirtualAlloc with MEM_COMMIT and a protection that isn't read-write clears the span around the call, as VirtualProtect does.
  • A test through the hooks: the_title_s_frees_and_protections_leave_the_region_cache decommits, protects, recommits PAGE_NOACCESS and releases through kernelx, and checks the cache after each step. Each unit test now has its own cache, so a parallel test's release can't clear another test's.
  • Still open: the physical-page paths have no unit test (they need UMA and physical pages), there's no measurement on main yet, and the smoke runs are still to come. The size-0 clear may cost hit rate on a title that releases whole reservations often, and the smoke runs will show it.

AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.

<!-- greyfinch-sync:ivall/xcl:comment:7315350336 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7315350336). Originally posted by [capy-ai[bot]](https://github.com/apps/capy-ai) on 2026-12-01T15:06:16Z. --- @Foniass thanks, the gaps were real, and most of them are on `amd-dev` too. Fixed in 15ae499c: - **Before and after:** kernelx `VirtualFree` is now a wrapper that clears the span before the call and after a successful one, whichever path the free takes (placeholders, sparse windows, GPU views, the general one). `VirtualFreeEx` of the process's own memory, `sparse::free`, `release_at` (which also covers pages moved away from home) and the block `FreeTitlePhysicalPages` releases now clear before and after too. - **Whole-reservation releases:** a release of size 0 now clears the whole cache. Before, it dropped only the span holding the address, so a reservation with holes left its other spans cached. - **Commits that leave pages unreadable:** `VirtualAlloc` with `MEM_COMMIT` and a protection that isn't read-write clears the span around the call, as `VirtualProtect` does. - **A test through the hooks:** `the_title_s_frees_and_protections_leave_the_region_cache` decommits, protects, recommits `PAGE_NOACCESS` and releases through kernelx, and checks the cache after each step. Each unit test now has its own cache, so a parallel test's release can't clear another test's. - **Still open:** the physical-page paths have no unit test (they need UMA and physical pages), there's no measurement on `main` yet, and the smoke runs are still to come. The size-0 clear may cost hit rate on a title that releases whole reservations often, and the smoke runs will show it. AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.
Foniass commented 2026-12-01 15:15:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T15:15:31Z.


Re-review (head 15ae499c; the diff from eab0ffba read). Most of my review is addressed:

  • Freed memory staying "committed": fixed for the paths I named. kernelx::VirtualFree now clears before and after the real free (kernelx.rs ~1214-1223), which covers placeholders::free, sparse windows, GPU views, graphics reservations and plain memory. sparse::free clears again after its decommit (sparse.rs ~5159-5162), and VirtualFreeEx on the process itself and FreeTitlePhysicalPages do the same (~1350-1353, ~2466 / ~2476).
  • Unmapped physical pages: fixed for release_at (~2335-2337).
  • Re-commit with another protection: fixed. A fixed-address MEM_COMMIT whose protection isn't read-write clears around the call (~912-924); PAGE_GUARD is caught because STD_PROTECT_MASK keeps the guard bit.

Still open:

  • give_back_homes clears only before (~2128-2132). It's the same pattern as release_at, for pages moved away from home. A home in a sparse window is cleared once by decommitted before the decommit, and source_going clears afterwards only for a paired CPU view or while pages are shown in GPU views. Homes are given back here, not through release_at (unverified that a reader queries a home in that gap).
  • A size-0 release now empties the whole cache (sparse.rs ~350-357, called from kernelx.rs ~1217 / ~1220). VirtualFree(p, 0, MEM_RELEASE) is how a title frees any allocation, UMA blocks included (which in_committed_window answers before the cache is asked), so every such call wipes the cache and drops every query in flight. Each branch already knows the real length (sparse_reservation, view_reservation, block_len, GRAPHICS_RESERVATIONS, the placeholder region), so it can be narrowed. Performance only, but it may eat most of the gain.
  • A sparse decommit now records three clears (decommitted plus the wrapper twice), and the replay list keeps 64, so a burst of frees drops more in-flight queries. Correct, but it costs hit rate.
  • The new test (~12403-12427) goes through kernelx's own calls. Only its PAGE_NOACCESS re-commit assert fails on the old head, and the cache is per thread in tests, so no test can show the cross-thread race the before / after clears are for.
  • No measurement on main and no smoke pair yet (as you say).

Fine: SOURCE_REGIONS is still a leaf lock, and the replay of recent clears is right with clearing before and after (a query that read the revision before or between the two clears is cut back or rejected). The other VirtualFree / VirtualProtect calls in the crate free XCL's own memory, not memory the cache stores.

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

<!-- greyfinch-sync:ivall/xcl:comment:7315609315 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7315609315). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T15:15:31Z. --- Re-review (head 15ae499c; the diff from eab0ffba read). Most of my review is addressed: - **Freed memory staying "committed": fixed for the paths I named.** `kernelx::VirtualFree` now clears before and after the real free (`kernelx.rs` ~1214-1223), which covers `placeholders::free`, sparse windows, GPU views, graphics reservations and plain memory. `sparse::free` clears again after its decommit (`sparse.rs` ~5159-5162), and `VirtualFreeEx` on the process itself and `FreeTitlePhysicalPages` do the same (~1350-1353, ~2466 / ~2476). - **Unmapped physical pages: fixed for `release_at`** (~2335-2337). - **Re-commit with another protection: fixed.** A fixed-address `MEM_COMMIT` whose protection isn't read-write clears around the call (~912-924); `PAGE_GUARD` is caught because `STD_PROTECT_MASK` keeps the guard bit. Still open: - **`give_back_homes` clears only before** (~2128-2132). It's the same pattern as `release_at`, for pages moved away from home. A home in a sparse window is cleared once by `decommitted` before the decommit, and `source_going` clears afterwards only for a paired CPU view or while pages are shown in GPU views. Homes are given back here, not through `release_at` (unverified that a reader queries a home in that gap). - **A size-0 release now empties the whole cache** (`sparse.rs` ~350-357, called from `kernelx.rs` ~1217 / ~1220). `VirtualFree(p, 0, MEM_RELEASE)` is how a title frees any allocation, UMA blocks included (which `in_committed_window` answers before the cache is asked), so every such call wipes the cache and drops every query in flight. Each branch already knows the real length (`sparse_reservation`, `view_reservation`, `block_len`, `GRAPHICS_RESERVATIONS`, the placeholder region), so it can be narrowed. Performance only, but it may eat most of the gain. - A sparse decommit now records three clears (`decommitted` plus the wrapper twice), and the replay list keeps 64, so a burst of frees drops more in-flight queries. Correct, but it costs hit rate. - The new test (~12403-12427) goes through kernelx's own calls. Only its `PAGE_NOACCESS` re-commit assert fails on the old head, and the cache is per thread in tests, so no test can show the cross-thread race the before / after clears are for. - No measurement on main and no smoke pair yet (as you say). Fine: `SOURCE_REGIONS` is still a leaf lock, and the replay of recent clears is right with clearing before and after (a query that read the revision before or between the two clears is cut back or rejected). The other `VirtualFree` / `VirtualProtect` calls in the crate free XCL's own memory, not memory the cache stores. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
capy-ai[bot] commented 2026-12-01 15:18:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by capy-ai[bot] on 2026-12-01T15:18:49Z.


@Foniass thanks for the re-review. In 9fd0f303:

  • give_back_homes now clears before and after, like release_at.
  • A free of size 0 no longer empties the cache. The VirtualFree wrapper takes the reservation's length from whole_len: sparse_reservation / view_reservation, then GRAPHICS_RESERVATIONS, then a VirtualQuery walk over the regions of the allocation at that address. A block of a committed window clears nothing. Only an unknown length still clears everything. VirtualFreeEx uses the same.
  • The replay log keeps the latest 256 clears instead of 64, so a burst of frees drops fewer queries in flight.
  • The hooks test now also checks that releasing one reservation, holes included, leaves another allocation cached.
    Under Wine, the same filtered modules as before fail exactly the tests that fail on main, and both new tests pass.

AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.

<!-- greyfinch-sync:ivall/xcl:comment:7315700759 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7315700759). Originally posted by [capy-ai[bot]](https://github.com/apps/capy-ai) on 2026-12-01T15:18:49Z. --- @Foniass thanks for the re-review. In 9fd0f303: - **`give_back_homes`** now clears before and after, like `release_at`. - **A free of size 0** no longer empties the cache. The `VirtualFree` wrapper takes the reservation's length from `whole_len`: `sparse_reservation` / `view_reservation`, then `GRAPHICS_RESERVATIONS`, then a `VirtualQuery` walk over the regions of the allocation at that address. A block of a committed window clears nothing. Only an unknown length still clears everything. `VirtualFreeEx` uses the same. - **The replay log** keeps the latest 256 clears instead of 64, so a burst of frees drops fewer queries in flight. - **The hooks test** now also checks that releasing one reservation, holes included, leaves another allocation cached. Under Wine, the same filtered modules as before fail exactly the tests that fail on `main`, and both new tests pass. AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.
Foniass commented 2026-12-01 15:19:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T15:19:31Z.


Follow-up (head 9fd0f303; the diff from 15ae499c read). The open points from my re-review are addressed:

  • give_back_homes now clears before and after its decommit (kernelx.rs ~2165-2167).
  • A size-0 release no longer empties the cache. whole_len works out the real span: the sparse or view reservation, a graphics reservation, or the regions of the allocation at that base, read before the free. A block of a committed window is skipped, since the cache never stores those. Only an unknown length still clears everything. The new test checks that another allocation stays cached across a release, and that a release drops the whole span, past its holes too.
  • The replay list holds 256 recent clears instead of 64, which leaves room for the extra clears.

One detail: whole_len reads the allocation's regions with VirtualQuery before the free, so a size-0 release costs a short walk of that allocation's regions. That's cheap next to the free itself.

Still open, as before: no measurement on main and no smoke pair. The test run already queued for this PR will cover this head.

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

<!-- greyfinch-sync:ivall/xcl:comment:7315720707 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7315720707). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T15:19:31Z. --- Follow-up (head 9fd0f303; the diff from 15ae499c read). The open points from my re-review are addressed: - **`give_back_homes`** now clears before and after its decommit (`kernelx.rs` ~2165-2167). - **A size-0 release no longer empties the cache.** `whole_len` works out the real span: the sparse or view reservation, a graphics reservation, or the regions of the allocation at that base, read before the free. A block of a committed window is skipped, since the cache never stores those. Only an unknown length still clears everything. The new test checks that another allocation stays cached across a release, and that a release drops the whole span, past its holes too. - **The replay list** holds 256 recent clears instead of 64, which leaves room for the extra clears. One detail: `whole_len` reads the allocation's regions with `VirtualQuery` before the free, so a size-0 release costs a short walk of that allocation's regions. That's cheap next to the free itself. Still open, as before: no measurement on main and no smoke pair. The test run already queued for this PR will cover this head. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 15:26:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T15:26:43Z.


Test report (not a merge-check: draft, PR description red)
base: b2b1f109d2
head: 9fd0f303e9
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2904 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my follow-up on this head is at https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7315720707 (with the earlier re-review linked from the thread). This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run. The cache is on by default, so the default path changes; a smoke pair on this head is the evidence still missing.
assessment: merges, builds and passes the whole suite on current main at the newest head (9fd0f303), including the new release / re-commit cache tests; still open: a measurement of the gain on main and a smoke pair, since the cache is on by default
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7315920678 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7315920678). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T15:26:43Z. --- Test report (not a merge-check: draft, `PR description` red) base: b2b1f109d27e746a62ec95b04dd1f9924452e682 head: 9fd0f303e94f73aefd772546ccb1aeb8a880a04c merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2904 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: not repeated here; my follow-up on this head is at https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7315720707 (with the earlier re-review linked from the thread). This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main. performance: no smoke run. The cache is on by default, so the default path changes; a smoke pair on this head is the evidence still missing. assessment: merges, builds and passes the whole suite on current main at the newest head (9fd0f303), including the new release / re-commit cache tests; still open: a measurement of the gain on main and a smoke pair, since the cache is on by default hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 08:16:57 +00:00 (Migrated from github.com)

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


Test report (not a merge-check: draft)
base: 1c8b551475
head: 3e04ddb464
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: re-check of 3e04ddb4, rebased from 9fd0f303 (the head of my test report above) onto main 1c8b5514, which now has #3608's per-page physical-page release. The only change in the PR's own commit is where its two sparse::invalidate_source_range(home, count * PHYS_PAGE) calls sit: they now run in FreeTitlePhysicalPages' loop over the emptied blocks after AWAY is dropped (kernelx.rs ~2537-2550), once before and once after source_going releases the home, which keeps the PR's rule (forget a cached committed region before its memory can go, and again after) on main's new free path. The findings in my earlier re-review still stand as they were.
performance: 60 s smoke of a retail title, main 1c8b5514 vs this merge (3e04ddb4): 1370 -> 1672 frames shown (122 %; last presents per 2 s: 60 60 60), peak commit 17058 -> 18037 MB, 0 device removals, 0 crashes. Main's run on this base was low (1370 frames; main usually gives about 1650-1680 here), so the difference isn't a gain from this PR; against the usual main numbers this run is about even. A 60 s run capped at 60 presents per second can't show a per-submit saving.
assessment: on the rebased head, merges cleanly into main 1c8b5514, builds and passes the whole suite (the two e2e failures in an earlier attempt came from another XCL run on this machine at the same time, not from this PR), and the smoke run with the cache on (the default) is clean; still open: a measurement of the gain, and the findings in my earlier re-review
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7339239558 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3575#issuecomment-7339239558). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T08:16:57Z. --- Test report (not a merge-check: draft) base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: 3e04ddb46472bdb326d7d2411bf3116b2abace60 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: re-check of 3e04ddb4, rebased from 9fd0f303 (the head of my test report above) onto main 1c8b5514, which now has #3608's per-page physical-page release. The only change in the PR's own commit is where its two `sparse::invalidate_source_range(home, count * PHYS_PAGE)` calls sit: they now run in `FreeTitlePhysicalPages`' loop over the emptied blocks after `AWAY` is dropped (`kernelx.rs` ~2537-2550), once before and once after `source_going` releases the home, which keeps the PR's rule (forget a cached committed region before its memory can go, and again after) on main's new free path. The findings in my earlier re-review still stand as they were. performance: 60 s smoke of a retail title, main 1c8b5514 vs this merge (3e04ddb4): 1370 -> 1672 frames shown (122 %; last presents per 2 s: 60 60 60), peak commit 17058 -> 18037 MB, 0 device removals, 0 crashes. Main's run on this base was low (1370 frames; main usually gives about 1650-1680 here), so the difference isn't a gain from this PR; against the usual main numbers this run is about even. A 60 s run capped at 60 presents per second can't show a per-submit saving. assessment: on the rebased head, merges cleanly into main 1c8b5514, builds and passes the whole suite (the two e2e failures in an earlier attempt came from another XCL run on this machine at the same time, not from this PR), and the smoke run with the cache on (the default) is clean; still open: a measurement of the gain, and the findings in my earlier re-review hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
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/3575:upstream-pr/3575'
git switch 'upstream-pr/3575'

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