Skip to content

Kernel.X: preserve GPU texture data when a physical page moves from home (stacked on #1182) - #2177

Open
Filip722 wants to merge 2 commits into
xcl-dev:mainfrom
Filip722:fix/home-mapped-targets-on-1182
Open

Filip722 wants to merge 2 commits into
xcl-dev:mainfrom
Filip722:fix/home-mapped-targets-on-1182

Conversation

@Filip722

@Filip722 Filip722 commented Nov 25, 2026 •

Copy link
Copy Markdown

Stacked on #1182 at 5fa695050a0ccaa82298e45799224422f5e2781e. Only the top commit belongs to this PR. Request for a separate PR.

A render target created at the address returned by MapTitlePhysicalPages(NULL, …) could read stale pixels after the same physical page moved to a second address. A 128×128 RGBA8 readback on the RTX 5060 Laptop reproduced the problem in both directions while both textures were alive.

What is in it

  • Remember explicitly mapped home addresses so a GPU-owned target can use the same physical tile as subsequent aliases. Remove the recorded identity on unmap or free, and preserve the existing owner if another page already occupies that address.
  • Exercise moves, partial releases and occupied addresses in a kernel test. In the GPU test, write different patterns through both live targets, transition them through fenced aliasing barriers and read both back. A third page provides an independent control.

Tested

  • Windows MSVC release cross-build using Rust 1.98.1. Bazzite 44.20261011.0, kernel 7.2.9-ogc2.1.fc44.x86_64, Intel Core 7 240H, RTX 5060 Laptop GPU (8 GB), NVIDIA 615.78.08, Proton Experimental 11.0-20261112, vkd3d-proton 3.1.0 (4522cc1a8b1347f+).
  • The two tests failed on the original test-only control 5763f5a. Cross-address reads matched 0/16,384 patterned texels in each direction, while all direct reads and independent-page checks matched 16,384/16,384. With the original fix d3887f2, both directions and all controls matched 16,384/16,384. An independent native Windows tester reproduced this on an RTX 3080 Ti. Proton result · Windows result.
  • On this stacked commit 244aa780, both alias directions, both direct checks and the independent target again matched 16,384/16,384 texels. All ten exact tests passed individually with one test thread and no reported skips. These included the new mapping lifecycle test, the parent’s updated sparse tile-accounting test and seven neighboring mapping cases.
  • Cross-built the full Windows workspace in release mode and ran every test executable serially with one test thread. Current main 568e7db ran 20 executables, 1,148 passed, 6 failed, 46 ignored. The stacked PR ran 19 executables, 972 passed, 6 failed, 45 ignored. Its parent uses an older main revision with fewer tests. All harnesses completed. Both revisions failed the same six cases covering depth-buffer UAV flags, Opus and XMA2 voice playback, the synthetic title end-to-end test, PLS disk quota and predication.
  • Main printed 27 SKIPPED subcases across 17 test names. The PR printed 25 across 15 test names. Capability skips include wave64, unsupported shader forms, driver-cache disabling and optional GPU/debug features. Those subcases are excluded from hardware coverage.

Regression run

Both clean checkouts ran their own scripts/smoke.ps1 against the same offline title for 15 seconds with independent Proton prefixes, an RTX 5060 filter and a 512 MiB coherent window. Wine returned 0 MB for the process commit measurement in both runs.

Main

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 5060 Laptop GPU
title: retail-offline
seconds: 15
exit: 0x0
frames shown: 121 (PresentX 121)
presents per 2 s (last 3): 0 45 56
device removals: 0
crashes: 0
peak commit: 0 MB

PR head

xcl-smoke v1
commit: 244aa780c9519e315725052958923d617eeac8bf
gpu: NVIDIA GeForce RTX 5060 Laptop GPU
title: retail-offline
seconds: 15
exit: 0x0
frames shown: 120 (PresentX 120)
presents per 2 s (last 3): 0 46 56
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

Native Windows on this stacked revision, AMD and Intel adapters, and sustained world rendering. In a longer matched comparison of the earlier PR head and its home-mapping fix, both builds produced black native present-source samples before the external host-memory guard stopped them. Retail use of this specific mapping sequence remains unverified.

AI use

OpenAI Codex (GPT-6.2-Sol, high) wrote the fix and tests, ran them on this laptop, and prepared this PR.

3L1A5-1 and others added 2 commits November 25, 2026 02:30
A retail game maps one physical page under render targets at two
addresses at once (aliasing targets that are never live together, as the
console allows). kernelx keeps a page at one address (`map_pages` moves
it), and `vram::Pages` keyed its video memory by title address, so each
alias got pages of its own: in its first 40 s the game placed 422 targets
(2.1 GB) whose pages it then mapped under 276 others (1.85 GB), and kept
using both sets (barriers, views). The duplicate cost 1.85 GB of video
memory, and what the GPU wrote through one alias never showed in the other.

A GPU-owned texture's owned pages are now keyed by the physical page
mapped at their address (`kernelx::physical_pages`, asked before `PAGES`
is taken), else by the address as before. Sampled textures keep address
keys.

Measured on GTA VI, RTX 2060 SUPER 8 GB, 90 s at the menus, 3 runs each:
target pages 3597 -> 1738 MB, local video memory 6652 -> 4796 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gets

Keep explicitly mapped home addresses associated with their live physical pages across moves, unmaps and partial releases. Verify the mapping lifecycle and GPU readback in both directions with an independent target.

Assisted by OpenAI Codex.
@thehollowedone

Copy link
Copy Markdown

Native Windows verification of 244aa780 stacked on #1182. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug.

Tested

  • Clean head: cargo build --offline --locked --workspace -j 3 passed. cargo test --offline --locked --workspace --no-fail-fast -j 3 -- --nocapture --test-threads=4 reported 978 passed, 0 failed, 45 ignored. Separately, 23 runtime skip notices (18 no native wave64, three unsupported per-lane forms, one driver-cache toggle, one no heap windows).
  • The home-address readback, mapping lifecycle, and parent tile-accounting tests all ran without skips. Both alias directions, both direct writes, and the independent texture each matched all 16,384 texels.
  • Control: substituted only kernelx.rs from 5fa6950, keeping the fixture and parent changes. cargo test --offline --locked -p xcl --lib render_target_at_physical_page_home_inherits_texels_after_move -j 3 -- --nocapture --test-threads=1 reported 0 passed, 1 failed, 0 ignored, 0 runtime skips. Both alias directions matched 0/16,384. Both direct writes and the independent texture still matched 16,384/16,384.

Not tested
Retail load, memory savings, or other adapters. Synthetic inputs only.

AI use
Codex (GPT-6.2 Sol) ran the tests and control and drafted this report.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows RX 6800M verification of exact stacked head 244aa780c9519e315725052958923d617eeac8bf (base 568e7db7729c8fa6c8f0f4b32d798faaf11462bb, parent 5fa695050a0ccaa82298e45799224422f5e2781e). Final worktree is clean.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M, driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. For the GPU test executable I temporarily set Windows' per-app high-performance GPU preference; the test printed GPU: AMD Radeon RX 6800M in both control and fixed runs.

Fixed head: render_target_at_physical_page_home_inherits_texels_after_move passed, 1/0/0, with no skip. The A and B direct reads, A-to-B and B-to-A alias reads, and independent-page control each matched 16,384/16,384 patterned texels. mapped_home_page_identity_follows_moves_and_partial_frees also passed, 1/0/0 with no skip.

Test-only negative control: I kept the current GPU fixture and replaced only crates/xcl/src/hle/kernelx.rs with the parent commit's file, then rebuilt and ran the same GPU test on the RX 6800M. It failed, 0/1/0: A-to-B and B-to-A each matched 0/16,384, while both direct reads and the independent-page control still matched 16,384/16,384. I restored kernelx.rs, rebuilt, and repeated the green RX 6800M result above. The control and fixed logs both identify the RX 6800M.

Scope: Focused debug-build regression and mapping-lifecycle tests. I did not run the full workspace suite or a retail-title smoke on this stacked head; the test demonstrates the synthetic two-target alias sequence, not title-world rendering.

AI use: OpenAI Codex prepared the test-only control, ran the AMD tests, compared per-direction texel counts, restored the exact clean PR head, and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@pickles976

Copy link
Copy Markdown

RTX 4060 Laptop / Wine integration verification of the top commit 244aa780c9519e315725052958923d617eeac8bf, applied on the updated #1182 (de4d1f676146ac58b4c11037bed9d0c1b5789d0c), rather than replacing it with the older stacked parent.

This is a mixed local integration based on 06c9f5505f63f10c5ec49ef932d75b2c28177324, also including #867/#1395, #1069, #1916, #615 and #495. In particular, the port preserves #1916's Away::sparse_homes tracking and its free-time cleanup alongside the new explicit-home identities. This is not a clean-head result or a competing implementation. One obsolete test import was removed after extracting the shared readback helper.

Environment: RTX 4060 Laptop 8 GiB, NVIDIA 590.48.01, i7-13620H, 16 GiB RAM; Linux 6.17.0-40-generic, Wine 11.0, stock/assert-enabled vkd3d-proton 3.2.0 (2576c0b4adfae4a), DXVK 3.1.1-209; Rust 1.98.1 Windows MSVC cross-target. The GPU fixture printed the actual NVIDIA adapter, despite the configured DXGI vendor spoof.

Focused tests: cargo +1.98.1 test -p xcl --lib --target x86_64-pc-windows-msvc <filter> -- --test-threads=1 --nocapture, through Wine, with XCL_REQUIRE_GPU=mesh XCL_DEFER_PRIVATE_HOME_TILES=1:

  • mapped_home_page_identity_follows_moves_and_partial_frees
  • render_target_at_physical_page_home_inherits_texels_after_move
  • render_targets_on_one_physical_page_share_its_video_memory
  • a_page_away_moves_on_without_going_home
  • a_page_whose_move_fails_stays_mapped_where_it_was
  • placed_title_textures_share_vram_and_preserve_pixels

Six unique tests passed, no failures or skip notices. A→B and B→A each matched 16,384/16,384 patterned texels; both direct writes and the independent-page control also matched 16,384/16,384. Release build passed. After the test-only import cleanup, cargo test ... --no-run compiled without warnings. I did not repeat the already reported negative control or run the full suite.

Bounded title check: retail 1.0.2.1, offline, Series S profile, saved first-run settings, XCL_COHERENT_MB=3408 XCL_PSO_PRELOAD=1 XCL_DEFER_PRIVATE_HOME_TILES=1 XCL_PRESS_A_AT=40,55. Account picker and intro artwork rendered, with setup menus skipped. At 100.3 s, the external 7,200 MiB board-usage safety guard observed 7363 MiB and terminated the run (launcher exit 143). Minimum available RAM was 3620.8 MiB, free disk 13.307 GiB. No unhandled-exception or device-loss marker was recorded, but offline dependency errors and command-list resubmission warnings remained. This was a guard stop, not an observed out-of-memory failure; the run did not establish gameplay or stability.

Not tested: retail use of this specific alias sequence, memory savings attributable to this fix, sustained world rendering, native Windows, clean PR head, or other GPUs.

AI assistance: omp / openai-codex/gpt-6-astra performed the integration, verification and report. Credit for the fix and fixtures remains with this PR's authors.

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.

6 participants