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

Open
b3IKK wants to merge 1 commit from upstream-pr/1294 into main
b3IKK commented 2026-11-24 14:24:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T14:24:34Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5474006095 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1294). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T14:24:34Z. --- `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.
DavidM1911 commented 2026-11-24 15:05:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:33:32Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7134572763 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1294#issuecomment-7134572763). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T14:33:32Z. --- 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!
futurepro62 commented 2026-11-24 15:06:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T14:39:32Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7134735657 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1294#issuecomment-7134735657). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T14:39:32Z. --- 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.
DavidM1911 commented 2026-11-24 16:07:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:02:01Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7137011433 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1294#issuecomment-7137011433). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T16:02:01Z. --- 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!
thehollowedone commented 2026-11-25 11:09:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-25T10:55:59Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7160365739 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1294#issuecomment-7160365739). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-25T10:55:59Z. --- 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://github.com/xcl-dev/xcl/pull/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.
github-actions[bot] commented 2026-11-29 07:41:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:41:56Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7252634482 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1294#issuecomment-7252634482). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T07:41:56Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:21:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:21:14Z.


Triage (#1607) – head 554cf14

No open PR makes the same change: the 26 lines shared with #3099 come from that branch's stale base, and #3099 does not touch recheck_source's PENDING accounting.
The bug is still on main: recheck_source bumps PENDING for shadowed entries too, and Table::remove returns 0 for a shadowed entry and +1 when it is uncovered, so the count leaks or doubles. Main also restructured recheck_gpu_view_sources since, and mapping_changed now does the same PENDING.fetch_add for a shadowed (!active) entry; the rebase has to cover that path too.
The PR conflicts with main.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301681806 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1294#issuecomment-7301681806). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:21:14Z. --- **Triage (#1607)** – head 554cf14 No open PR makes the same change: the 26 lines shared with #3099 come from that branch's stale base, and #3099 does not touch `recheck_source`'s PENDING accounting. The bug is still on main: `recheck_source` bumps `PENDING` for shadowed entries too, and `Table::remove` returns 0 for a shadowed entry and +1 when it is uncovered, so the count leaks or doubles. Main also restructured `recheck_gpu_view_sources` since, and `mapping_changed` now does the same `PENDING.fetch_add` for a shadowed (`!active`) entry; the rebase has to cover that path too. The PR conflicts with main. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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/1294:upstream-pr/1294'
git switch 'upstream-pr/1294'

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