Skip to content

kernelx: track paired 64 KiB views across sparse reservations - #879

Draft
JFyuhong wants to merge 2 commits into
xcl-dev:mainfrom
JFyuhong:codex/track-sparse-mirrors
Draft

JFyuhong wants to merge 2 commits into
xcl-dev:mainfrom
JFyuhong:codex/track-sparse-mirrors

Conversation

@JFyuhong

@JFyuhong JFyuhong commented Nov 24, 2026 •

Copy link
Copy Markdown

A retail title reserves two 24 GiB views of the same physical pages. When its CPU view fits in the sparse windows, the early return in VirtualAlloc leaves that view out of mirror tracking. The Bink decoder writes the CPU view, but the texture upload reads empty memory. Part of #697, found while testing #822 and investigating #675.

What is in it

  • Register reserve-only CPU and GPU views of 64 KiB pages on both the sparse and Windows fallback paths. A GPU view pairs with the most recent unmatched CPU view of the same size. The measured title reserves the CPU view first and the GPU view second. Simultaneous commit-and-reserve and interleaved same-size streams from different owners are outside that observation.
  • Notify texture uploads when a pair forms or disappears. A texture registered while the original pair was live can reacquire its CPU backing after the GPU address is reused. A fixed-address registry test checks reuse with a different CPU backing. The allocator integration test uses the returned addresses and explicitly exercises a sparse CPU view paired with a Windows GPU reservation.

Tested

  • Windows 11 build 26300, Core i7-14650HX, RTX 4060 Laptop 8 GB, NVIDIA 616.92, MSVC Rust 1.93.1, DXC 1.8.2502.11. Debug tests and release smoke. Optional XCL_SAMPLE_* inputs were unset.
  • cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4. Clean main 09940bb: 713 reported passed, 3 failed, 41 ignored (2 GPU cases reported SKIPPED within the pass count). PR head 1b2b636: 714 reported passed, 3 failed, 41 ignored (2 GPU cases reported SKIPPED within the pass count). The native-wave64 cases were skipped on this adapter.
  • The four-thread main and head runs both failed the cubemap reuse assertion (Tests: placed_title_textures_share_vram_and_preserve_pixels fails now and then at its cubemap reuse check (main 9ce2070) #718) followed by two poisoned-lock errors. A second four-thread head run returned the same 714 reported passed, 3 failed and 41 ignored. With cargo test --workspace --no-fail-fast -- --test-threads=1, the same head reported 717 passed, 0 failed and 41 ignored, including the same two GPU skips.
  • cargo test -p xcl --test sparse_mirrors -- --nocapture: both revised cases failed on the old notification behavior and passed on the revision. The existing GPU texture-upload test, extended to hold its texture across unpair/re-pair, also failed on the old code and passed after the notification change.
  • Additional four-thread GPU control: applying only Tests: check cubemap tile reuse independently of idle page reclamation #447 (48e7434, cfg(test) tile-identity assertions) to 1b2b636 in a separate checkout, tree 41906742e26b, gave 717 reported passed, 0 failed and 41 ignored, with 2 wave64 skips, using the same workspace build and four-thread test commands. The PR branch itself retains the original cubemap test and the results above.
  • Retail release A/B on Memory/configurable uma windows #822 (e9705bb) with eight windows, the same saved profile and initial shader cache. Frames 830, 920 and 1010 of the opening movie were uniformly green before the patch. With this runtime change on that same build, those frames showed the full-colour movie and XCL logged the 24 GiB pair. Four windows on unmodified Memory/configurable uma windows #822 also showed the movie.
  • On the original PR head b54f6fe with four windows, the title reached intro Prestream and ended at +0x23cf683 after 222.211 s and 1,625 presents. The four out-of-range RT SRVs all belonged to a distinct 2,199 MiB write-watched allocation. Allocation measurements on #585.

Regression run

Release scripts/smoke.ps1 -Game <read-only retail executable> -Seconds 60, with matching DXC settings.

Main:

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 510 (PresentX 510)
presents per 2 s (last 3): 23 24 23
device removals: 0
crashes: 0
peak commit: 15245 MB

PR head:

xcl-smoke v1
commit: 1b2b636a034faba6dafb0e3ed37cb0cffb286d4a
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 902 (PresentX 902)
presents per 2 s (last 3): 37 40 43
device removals: 0
crashes: 0
peak commit: 15254 MB

Not tested

AI use

  • OpenAI Codex (GPT-6) diagnosed the bug, implemented the patch and review follow-up, wrote the tests, ran the Windows and retail checks, and drafted the description.

A successful sparse reservation returned before mirror tracking saw it. When a CPU view fit the sparse windows and its GPU view fell back to host address space, texture uploads read the empty GPU view. Register the reservation on each allocation path and invalidate cached texture sources when either end is released.

Assisted-by: Codex (GPT-6)
@iggyvilla

Copy link
Copy Markdown
Contributor

Read of b54f6fe (nothing built or run by me).

1. Creating a pair does not bump GPU_VIEW_MAP_GEN. reserved inserts into s.gpu (kernelx.rs:190-197) and released bumps the generation when it removes one (:203-211). recheck_gpu_view_sources skips work while the generation is unchanged, and a texture registered at that address after released(gpu) was moved back to its own va. If the title then reserves the same address again and reserved pairs it, nothing tells those entries that backing memory exists again, so they keep reading the empty GPU view until an unrelated mapping change moves the generation. One GPU_VIEW_MAP_GEN.fetch_add(1, Release) when the pair is inserted would close it, and sparse_mirrors.rs:28-47 (the release / re-reserve sequence) could then assert the generation moved on the second pairing too.

2. The integration test depends on the machine's memory layout. assert_eq!(replacement, gpu) (line 36) needs VirtualAlloc to hand back the address it just released, which is usual but not guaranteed, and assert!(!uma.contains(gpu) && in_graphics_reservation(gpu)) (line 58) asserts which allocator took the second view. With a UMA that has more or larger windows, or after note_coherent_need grows the coherent window, that view lands in the UMA, which still registers and pairs (kernelx.rs:296) but fails the assert. Asserting the pairing unconditionally and skipping the host-fallback case when uma.contains(gpu) would keep the test meaning the same on other layouts.

3. Two assumptions worth a sentence in the PR. reserved returns at once for MEM_COMMIT reservations (t & 0x1000), so a title that commits at reservation time gets no pair; and a GPU view is paired with the most recent unpaired CPU view of the same size, so two interleaved reservation streams of one size would pair the wrong views silently. The retail order (CPU view, then GPU view, reserve only) fits both, and the description could say so.

AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine.

A texture registered while a mirror pair was live kept the bare GPU address after the title released that view and paired its address again. Publish the mapping generation on insertion too, so the next texture submit can pick up the CPU backing. Cover same-address reuse independently of allocator placement and exercise the surviving texture on D3D12.

Assisted-by: Codex (GPT-6)
@iggyvilla

Copy link
Copy Markdown
Contributor

Read of the 1b2b636 delta on top of b54f6fe (nothing built or run by me); it answers the three points of my earlier read.

1. The generation gap is closed. reserved now bumps GPU_VIEW_MAP_GEN when it inserts a pair (kernelx.rs:195), and released already bumped on removal (:204-211), so the pair table and the generation move together on every insert, replace and removal; a CPU view alone does not bump. recheck_gpu_view_sources runs first in refresh_once (title_textures.rs:691), so after the release a texture falls back to its own va and after the re-pair it follows the CPU view again. Both directions are asserted: the counter in sparse_mirrors.rs (:45 no bump for a CPU view, :62 release, :71 re-pair), and a live texture in title_textures.rs:1349-1355 (src == va after the release, the CPU view after the reuse), which fails without the bump because the recheck returns early on an unchanged generation.

2. The layout dependence is gone. The two assert_eq!s on returned addresses are removed; replacement and gpu_again are used as returned. The one remaining allocator assertion, !uma.contains(gpu) && in_graphics_reservation(gpu) (sparse_mirrors.rs:87), follows from the flags: two reservations of sparse_bytes / 2 + 64 KiB cannot both be sparse, and the flags have neither MEM_COMMIT nor MEM_GRAPHICS (0x1000_0000, kernelx.rs:105), so the second cannot take the coherent window and goes to the watched fallback (gpu_visible_fallback, kernelx.rs:350-353). The new comment in the test says this.

3. The two assumptions are in the description ("interleaved same-size streams from different owners are outside that observation"). The silent MEM_COMMIT early return in reserved (kernelx.rs:186-188) is still only in the code; a clause in its comment would save the next reader the derivation.

One test-only coupling. The registry test's mirrors::reserved(gpu.0, SIZE, ...) pairs with the most recent unpaired CPU view of exactly SIZE in the process-global table. In the same lib-test binary, gpu_view_reservations_name_their_cpu_view (kernelx.rs:2410) registers a 24 GiB CPU view at 0x7000_0000_0000 and takes no lock, while the registry test holds only title_textures' own TEST_LOCK and VRAM_TEST_LOCK, so they can run together. What keeps them apart today is SIZE = 24 GiB + 64 KiB (title_textures.rs:1231); if either size moves, the failure depends on interleaving. A #[cfg(test)] lock shared by the two tests, or a size asserted unique on both sides, would turn the comment into a guarantee.

AI use: Claude Code, Claude Sonnet 5.5, read both heads and checked each line reference; the points are mine.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head 1b2b636 onto main 077ce40, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 707 passed, 11 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows plus this rig's title-textures flake family (see #718). paired 64 KiB sparse-view tracking green; mirror-upload flake hit.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@tiagonleal

tiagonleal commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Windows / NVIDIA retail test of 1b2b636 merged onto main 47efa2e (clean merge, merged tree 2fb8df8).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (32-lane waves), driver 32.0.16.1742; Ryzen 7 9800X3D, 32 GB RAM; Windows 11 Pro 26300; rustc 1.100.0 MSVC.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug) on the merged tree: 743 passed, 0 failed, 41 ignored. SKIPPED: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64). Same tree without the PR (47efa2e + an unrelated one-file netoff change): 742 passed, 0 failed, 41 ignored.
  • Retail title 1.0.2.1, scripts/smoke.ps1 -Seconds 60, release, one run each, back to back:
xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1656 (PresentX 1656)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14426 MB
xcl-smoke v1
commit: 2fb8df8523cfbdc656df4f45abac2a9891830338
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1656 (PresentX 1656)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14434 MB

Not tested

Run and written with Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants