D3D12.X: keep PENDING accurate for shadowed entries in recheck_gpu_view_sources #1294

Open
github-bot wants to merge 1 commit from github-bot/gh-1294 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 14:24 UTC · original
b3IKK:d3d12x/title-textures-pending-leak → main · +120 −18 · 1 files · 1 commits · open

Table maintains the invariant that PENDING counts only active (by_res) entries with pending == true: Table::insert subtracts 1 when moving a pending entry into shadowed, Table::remove / retire_range do not subtract when removing a shadowed entry, and Table::remove adds 1 when uncovering a pending shadowed entry.

recheck_gpu_view_sources previously called recheck_source() on both by_res and shadowed and incremented PENDING directly for both, permanently leaking PENDING whenever a shadowed GPU-view texture's source changed (both when later removed while shadowed and when uncovered and counted a second time), permanently disabling the dirty_len == 0 && PENDING == 0 fast path in refresh_once.

This moves source rechecking into Table::recheck_sources -> (changed, pending_delta) counting only by_res entries, and applies delta through adjust_pending (matching Table::insert / Table::remove).

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: add Table::recheck_sources, return (changed, newly_pending) from recheck_source, and apply pending_delta in recheck_gpu_view_sources; add unit test recheck_sources_keeps_pending_exact_for_shadowed_entries covering both shadowed-removal and uncover-then-remove paths.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib recheck_sources_keeps_pending_exact_for_shadowed_entries and a_lazily_mapped_page_in_a_gpu_view_is_its_own_source: both pass

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 554cf1404ceeb6e8e5a328ffc44e020817aabba4
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1644 (PresentX 1645)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14478 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited title_textures.rs, wrote the fix and regression test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 14:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/1294) `b3IKK:d3d12x/title-textures-pending-leak` → `main` · +120 −18 · 1 files · 1 commits · open `Table` maintains the invariant that `PENDING` counts only active (`by_res`) entries with `pending == true`: `Table::insert` subtracts 1 when moving a pending entry into `shadowed`, `Table::remove` / `retire_range` do not subtract when removing a shadowed entry, and `Table::remove` adds 1 when uncovering a pending shadowed entry. `recheck_gpu_view_sources` previously called `recheck_source()` on both `by_res` and `shadowed` and incremented `PENDING` directly for both, permanently leaking `PENDING` whenever a shadowed GPU-view texture's source changed (both when later removed while shadowed and when uncovered and counted a second time), permanently disabling the `dirty_len == 0 && PENDING == 0` fast path in `refresh_once`. This moves source rechecking into `Table::recheck_sources -> (changed, pending_delta)` counting only `by_res` entries, and applies `delta` through `adjust_pending` (matching `Table::insert` / `Table::remove`). **What is in it** - `crates/xcl/src/hle/d3d12x/title_textures.rs`: add `Table::recheck_sources`, return `(changed, newly_pending)` from `recheck_source`, and apply `pending_delta` in `recheck_gpu_view_sources`; add unit test `recheck_sources_keeps_pending_exact_for_shadowed_entries` covering both shadowed-removal and uncover-then-remove paths. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`) - `cargo test -p xcl --lib recheck_sources_keeps_pending_exact_for_shadowed_entries` and `a_lazily_mapped_page_in_a_gpu_view_is_its_own_source`: both pass **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 554cf1404ceeb6e8e5a328ffc44e020817aabba4 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1644 (PresentX 1645) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14478 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `title_textures.rs`, wrote the fix and regression test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
Table maintains the invariant that PENDING counts only active (`by_res`)
entries with `pending == true`: Table::insert subtracts 1 when moving a
pending entry into `shadowed`, Table::remove / retire_range do not
subtract when deleting a shadowed entry, and Table::remove adds 1 when
uncovering a pending shadowed entry.

recheck_gpu_view_sources previously called recheck_source() on both
`by_res` and `shadowed` and incremented PENDING directly for both,
leaking PENDING permanently whenever a shadowed GPU-view texture's
source changed (whether later removed while shadowed or uncovered and
counted a second time).

Move source rechecking into Table::recheck_sources -> (changed,
pending_delta) counting only `by_res` entries, and apply the delta via
adjust_pending, with a unit test covering both shadowed-removal and
uncover-then-remove paths.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:49 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 14:33 UTC · original

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

  • cargo test -p xcl --lib lib title_textures: 14 passed, 0 failed.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 14:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1294#issuecomment-7134572763) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - cargo test -p xcl --lib lib title_textures: 14 passed, 0 failed. Thanks!
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 14:39 UTC · original

Full-suite run on NVIDIA and AMD to go with the subset check above. Tested exact head 554cf14 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: recheck_sources_keeps_pending_exact_for_shadowed_entries.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 14:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/1294#issuecomment-7134735657) Full-suite run on NVIDIA and AMD to go with the subset check above. Tested exact head `554cf14` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `recheck_sources_keeps_pending_exact_for_shadowed_entries`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**, no skips. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 16:02 UTC · original

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

  • cargo test -p xcl --lib -- --test-threads=1: all passed, 0 failed, 21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 16:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1294#issuecomment-7137011433) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib -- --test-threads=1`: all passed, 0 failed, 21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-25 10:55 UTC · original · edited 2026-11-25 11:49 UTC

Independent Windows run on 554cf14. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, debug.

cargo build --offline --locked --workspace passed. cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture reported 752 passed, 0 failed, 41 ignored, with two wave64 skips included in Cargo's pass count.

I extended the synthetic GPU mirror test in a scratch copy. Two committed D3D12 textures had independent GPU allocations and overlapping title-memory ranges. I mapped a new source while the older texture was shadowed, let the covering texture's uploads finish, then removed it. The restored texture read back 4,096/4,096 new pixels. The pending upload count was 0 → 0 → 0 before the map, while shadowed, and after the restored texture uploaded.

The same fixture on #1733’s 44089a2 left all 4,096 old pixels in place with counts of 0 → 0 → 0. Restoring the original pending update in that checkout refreshed all pixels and left the count at 0 → 1 → 1.

cargo test --offline --locked -p xcl --lib gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes -- --nocapture --test-threads=1 passed 1/0/0 with zero fixture skips on #1294. Synthetic coverage only. AI-assisted. Codex (GPT-6, exact variant unavailable) extended the fixture, ran the tests, and drafted this report.

Recheck after #2029 merged. I reran the same native RTX fixture on main at 1a0bbe3, then with each PR merged separately into that revision. Each run used the default streaming recheck setting and advanced no frames.

Tree New pixels after reactivation Pending uploads before, while shadowed, after
Main 4,096/4,096 0 → 1 → 1
Main + #1733 0/4,096 0 → 0 → 0
Main + #1294 4,096/4,096 0 → 0 → 0

cargo test --offline --locked -p xcl --lib gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes -- --nocapture --test-threads=1 passed with #1294. Main failed the pending-count assertion. #1733 failed the pixel assertion. Zero fixture skips. AI-assisted. Codex (GPT-6, exact variant unavailable) ran the comparison and drafted this update.

**@⁠thehollowedone** on GitHub · 2026-11-25 10:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1294#issuecomment-7160365739) · edited 2026-11-25 11:49 UTC Independent Windows run on [554cf14](https://github.com/xcl-dev/xcl/commit/554cf1404ceeb6e8e5a328ffc44e020817aabba4). Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, debug. `cargo build --offline --locked --workspace` passed. `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture` reported **752 passed, 0 failed, 41 ignored**, with two wave64 skips included in Cargo's pass count. I extended the synthetic GPU mirror test in a scratch copy. Two committed D3D12 textures had independent GPU allocations and overlapping title-memory ranges. I mapped a new source while the older texture was shadowed, let the covering texture's uploads finish, then removed it. The restored texture read back **4,096/4,096 new pixels**. The pending upload count was **0 → 0 → 0** before the map, while shadowed, and after the restored texture uploaded. The same fixture on [#1733’s 44089a2](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1733/commits/44089a2db11e8d50ec9cf5ccf397b629c7bceda6) left all 4,096 old pixels in place with counts of 0 → 0 → 0. Restoring the original pending update in that checkout refreshed all pixels and left the count at 0 → 1 → 1. `cargo test --offline --locked -p xcl --lib gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes -- --nocapture --test-threads=1` passed 1/0/0 with zero fixture skips on #1294. Synthetic coverage only. AI-assisted. Codex (GPT-6, exact variant unavailable) extended the fixture, ran the tests, and drafted this report. **Recheck after #2029 merged.** I reran the same native RTX fixture on [main at 1a0bbe3](https://github.com/xcl-dev/xcl/commit/1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6), then with each PR merged separately into that revision. Each run used the default streaming recheck setting and advanced no frames. | Tree | New pixels after reactivation | Pending uploads before, while shadowed, after | | --- | ---: | --- | | Main | 4,096/4,096 | 0 → 1 → 1 | | Main + #1733 | 0/4,096 | 0 → 0 → 0 | | Main + #1294 | 4,096/4,096 | 0 → 0 → 0 | `cargo test --offline --locked -p xcl --lib gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes -- --nocapture --test-threads=1` passed with #1294. Main failed the pending-count assertion. #1733 failed the pixel assertion. Zero fixture skips. AI-assisted. Codex (GPT-6, exact variant unavailable) ran the comparison and drafted this update.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1294/head:github-bot/gh-1294'
git switch 'github-bot/gh-1294'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1294'
git switch 'github-bot/gh-1294'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1294'
git switch 'github-bot/gh-1294'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1294'
git switch 'main'
git merge --squash 'github-bot/gh-1294'
git switch 'main'
git merge --ff-only 'github-bot/gh-1294'
git switch 'main'
git merge 'github-bot/gh-1294'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.