Fix physical page mapping and GPU test assumptions #153

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

@⁠ceracty on GitHub · 2026-11-25 17:31 UTC · original
ceracty:fix/physical-page-mapping-tests → main · +23 −21 · 3 files · 1 commits · open

Why

The whole-reservation mapping shortcut was also applied to small reservations. This broke partial unmaps and could merge placeholders that the title had split explicitly. Zero-length alias requests could also fail when the destination was inside a whole-mapped reservation.

Changes

  • Use the regular page mapping path below 4 MiB and keep the whole-reservation shortcut for eligible reservations from 4 MiB to 1 GiB, including the documented 185 MB GPU heap.
  • Return success immediately for zero-length physical page and alias mapping requests.
  • Use Cell for memory that the command-list synchronization test updates through a raw pointer.
  • Derive the first dynamic descriptor slot from the actual host heap instead of assuming it always starts at slot 4.

Validation

On Windows, all 102 active victory-hle tests and all 111 active victory-gpu tests passed. This includes the five previously failing physical memory tests.

The full workspace suite still reports 23 shader test failures on the test machine and one repository policy failure because lower.rs exceeds the file-size limit. In-game performance on Radeon was not measured.

**@⁠ceracty** on GitHub · 2026-11-25 17:31 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153) `ceracty:fix/physical-page-mapping-tests` → `main` · +23 −21 · 3 files · 1 commits · open ## Why The whole-reservation mapping shortcut was also applied to small reservations. This broke partial unmaps and could merge placeholders that the title had split explicitly. Zero-length alias requests could also fail when the destination was inside a whole-mapped reservation. ## Changes - Use the regular page mapping path below 4 MiB and keep the whole-reservation shortcut for eligible reservations from 4 MiB to 1 GiB, including the documented 185 MB GPU heap. - Return success immediately for zero-length physical page and alias mapping requests. - Use `Cell` for memory that the command-list synchronization test updates through a raw pointer. - Derive the first dynamic descriptor slot from the actual host heap instead of assuming it always starts at slot 4. ## Validation On Windows, all 102 active `victory-hle` tests and all 111 active `victory-gpu` tests passed. This includes the five previously failing physical memory tests. The full workspace suite still reports 23 shader test failures on the test machine and one repository policy failure because `lower.rs` exceeds the file-size limit. In-game performance on Radeon was not measured.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:45 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 17:46 UTC · original

Tested PR head 0f373ac on Bazzite Linux 45 using GE-Proton 10-34 / Wine 10.0 and vkd3d-proton 3.0.0, on an NVIDIA GeForce RTX 3090 (host driver 620.73.04).

The targeted test descriptor::host::tests::dynamic_slots_are_held_until_released passed under Proton (1 passed, 0 failed). The D3D12 host reported the 1,000,000-slot heap cap, and the test now correctly uses the actual heap count as the first dynamic slot. This is a Windows test binary under Proton, not a native Windows result.

**@⁠KernelSmoker** on GitHub · 2026-11-25 17:46 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153#issuecomment-7169970420) Tested PR head `0f373ac` on Bazzite Linux 45 using GE-Proton 10-34 / Wine 10.0 and vkd3d-proton 3.0.0, on an NVIDIA GeForce RTX 3090 (host driver 620.73.04). The targeted test `descriptor::host::tests::dynamic_slots_are_held_until_released` passed under Proton (1 passed, 0 failed). The D3D12 host reported the 1,000,000-slot heap cap, and the test now correctly uses the actual heap count as the first dynamic slot. This is a Windows test binary under Proton, not a native Windows result.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 18:57 UTC · original

Tested head 0f373ac on an RX 7900 XT (Windows 11 build 26300, Rust 1.98.1), with separate target dirs. I did not run the game.

cargo test -p victory-hle --lib:

  • main (000ffdd): 97 passed, 5 failed (the five xmem tests from #8).
  • This PR: 102 passed, 0 failed, both in parallel and with --test-threads=1. There were also no failures in 40 more parallel runs of xmem and 40 of the whole crate.

In victory-gpu lib, run serially, the only failure is the known #102 watch flake.

Compared with the other open fixes for these failures (#14, #16, #93, #99, and #154, which carries #93):

  • The size check only applies when no whole view covers the range yet. A later small call into a reservation already shown whole therefore still goes to that view, which is the case that broke #93's first version at startup (see the comments there). No test in this crate uses a reservation large enough to be shown whole, so the whole-view path is no longer tested. I copied #93's two tests onto this branch:
    • a_large_run_of_pages_is_shown_whole (65 pages)
    • a_small_run_into_a_reservation_shown_whole_is_mapped (70 then 10 of 80 pages)
      Both pass with --test-threads=1. In parallel runs the first one sometimes fails, for the shared-state reason #93 serialises them. Adding tests like these would keep the path covered.
  • #14 uses a 16 MiB minimum, which matches shadow.rs: a mapped view is used in place only from 16 MiB (end - start < 16 << 20 returns None). With 4 MiB, reservations between 4 and 16 MiB are coalesced into one view that the GPU side never uses in place.
  • The n == 0 early return in XMemMapPhysicalPages does not change behaviour. On main, n == 0 already returns address, because unmap returns at once for length 0 and the mapping loop does nothing.
  • On dynamic_slots_are_held_until_released: KernelSmoker's Proton run shows the test passing with a 1,000,000-slot cap. On a capped host, though, main gives the small 4-slot heap 933,440 title slots (see my comment on #52). This change makes the test accept that count. #52 instead makes HostHeap::new give at most the requested slots, so the original assertion holds again. If #52 is merged, this part is not needed. If this part is merged without #52, the test no longer detects that heap being enlarged on capped hosts. This card is not capped, so here the test passes either way.

Not tested: NVIDIA, Proton, the game.

**@⁠adrianmjim** on GitHub · 2026-11-25 18:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153#issuecomment-7171625396) Tested head 0f373ac on an RX 7900 XT (Windows 11 build 26300, Rust 1.98.1), with separate target dirs. I did not run the game. `cargo test -p victory-hle --lib`: - main (000ffdd): 97 passed, 5 failed (the five xmem tests from #8). - This PR: 102 passed, 0 failed, both in parallel and with `--test-threads=1`. There were also no failures in 40 more parallel runs of `xmem` and 40 of the whole crate. In `victory-gpu` lib, run serially, the only failure is the known #102 watch flake. Compared with the other open fixes for these failures (#14, #16, #93, #99, and #154, which carries #93): - The size check only applies when no whole view covers the range yet. A later small call into a reservation already shown whole therefore still goes to that view, which is the case that broke #93's first version at startup (see the comments there). No test in this crate uses a reservation large enough to be shown whole, so the whole-view path is no longer tested. I copied #93's two tests onto this branch: - `a_large_run_of_pages_is_shown_whole` (65 pages) - `a_small_run_into_a_reservation_shown_whole_is_mapped` (70 then 10 of 80 pages) Both pass with `--test-threads=1`. In parallel runs the first one sometimes fails, for the shared-state reason #93 serialises them. Adding tests like these would keep the path covered. - #14 uses a 16 MiB minimum, which matches `shadow.rs`: a mapped view is used in place only from 16 MiB (`end - start < 16 << 20` returns `None`). With 4 MiB, reservations between 4 and 16 MiB are coalesced into one view that the GPU side never uses in place. - The `n == 0` early return in `XMemMapPhysicalPages` does not change behaviour. On main, `n == 0` already returns `address`, because `unmap` returns at once for length 0 and the mapping loop does nothing. - On `dynamic_slots_are_held_until_released`: KernelSmoker's Proton run shows the test passing with a 1,000,000-slot cap. On a capped host, though, main gives the small 4-slot heap 933,440 title slots (see my comment on #52). This change makes the test accept that count. #52 instead makes `HostHeap::new` give at most the requested slots, so the original assertion holds again. If #52 is merged, this part is not needed. If this part is merged without #52, the test no longer detects that heap being enlarged on capped hosts. This card is not capped, so here the test passes either way. Not tested: NVIDIA, Proton, the game.
Author
Owner

@⁠qtLkz on GitHub · 2026-11-25 22:09 UTC · original

Tested on NVIDIA: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, this PR on main 4f62c2a.

  • cargo test -p victory-hle --lib --locked: 102 passed, 0 failed. The 5 xmem failures on main (a_run_keeps_the_placeholders_it_spans, a_run_maps_across_two_placeholders, a_run_maps_again_after_a_partial_unmap, mapping_no_pages_changes_nothing, physical_pages_map_alias_and_unmap) are gone.
  • victory-gpu: dynamic_slots_are_held_until_released now passes on this capped (1,000,000) heap.
  • One thing to check: watch::tests::written_pages_are_reported_to_every_asker fails (before.is_empty(), watch.rs:1097) in the full cargo test -p victory-gpu --lib run with this PR, with or without --test-threads=1. It passes with watch:: run alone, and in the full run on plain main. It looks like a test-ordering interaction.

Details and the combined run with #128 / #201: #74.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-25 22:09 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153#issuecomment-7175999016) Tested on NVIDIA: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, this PR on main `4f62c2a`. - `cargo test -p victory-hle --lib --locked`: **102 passed, 0 failed**. The 5 xmem failures on main (`a_run_keeps_the_placeholders_it_spans`, `a_run_maps_across_two_placeholders`, `a_run_maps_again_after_a_partial_unmap`, `mapping_no_pages_changes_nothing`, `physical_pages_map_alias_and_unmap`) are gone. - victory-gpu: `dynamic_slots_are_held_until_released` now passes on this capped (1,000,000) heap. - One thing to check: `watch::tests::written_pages_are_reported_to_every_asker` fails (`before.is_empty()`, watch.rs:1097) in the full `cargo test -p victory-gpu --lib` run with this PR, with or without `--test-threads=1`. It passes with `watch::` run alone, and in the full run on plain main. It looks like a test-ordering interaction. Details and the combined run with #128 / #201: #74. AI-assisted (Claude).
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 22:12 UTC · original

@⁠qtLkz on watch::tests::written_pages_are_reported_to_every_asker: it also fails on plain main here, intermittently, in full victory-gpu --lib runs. RX 7900 XT, Windows 11 26300, default test threads. On 000ffdd, whose watch.rs is the same as 4f62c2a's, it failed in 5 of 100 full runs (same assert, before.is_empty()). In the 140-run comparison on #175 it failed on both trees. So a pass on main in one run does not rule it out there. It looks like an interaction between tests in the same binary rather than something this PR adds, although this PR may make it more likely. A few full runs each way on your card would tell.

**@⁠adrianmjim** on GitHub · 2026-11-25 22:12 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153#issuecomment-7176067128) @⁠qtLkz on `watch::tests::written_pages_are_reported_to_every_asker`: it also fails on plain `main` here, intermittently, in full `victory-gpu --lib` runs. RX 7900 XT, Windows 11 26300, default test threads. On `000ffdd`, whose `watch.rs` is the same as `4f62c2a`'s, it failed in 5 of 100 full runs (same assert, `before.is_empty()`). In the 140-run comparison on #175 it failed on both trees. So a pass on main in one run does not rule it out there. It looks like an interaction between tests in the same binary rather than something this PR adds, although this PR may make it more likely. A few full runs each way on your card would tell.
Author
Owner

@⁠qtLkz on GitHub · 2026-11-26 10:59 UTC · original

Follow-up on the one failure left with this PR on NVIDIA, watch::tests::written_pages_are_reported_to_every_asker: it is not caused by this PR. It is a test-order dependence that is already on main.

RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, main 4f62c2a and main + this PR.

What happens. watch::JOURNAL.written is process-global and keeps page entries after the memory is freed. texture::tests::warp_write_watched_texture_uploads_only_when_written allocates one write-watched 64 KiB page, writes it, has watch::writes record it, and frees it. When written_pages_are_reported_to_every_asker runs next in the same process, VirtualAlloc can hand it a 4-page range that covers the freed page, so its first writes() already returns that page and assert!(before.is_empty()) fails.

A temporary print in both tests (not committed) shows the overlap on every failing run:

DIAG texture alloc raw=0x1e8f3420000 size=0x10000
DIAG watch alloc p=0x1e8f3400000 before=[(32043842, 3)]    // 32043842 * 0x10000 = 0x1e8f3420000

Reproduction, just the two tests, single-threaded:

cargo test -p victory-gpu --lib --locked -- --exact --test-threads=1 texture::tests::warp_write_watched_texture_uploads_only_when_written watch::tests::written_pages_are_reported_to_every_asker
  • main 4f62c2a: watch test fails 3 of 5 runs.
  • main + this PR: fails 3 of 3. In the full single-threaded victory-gpu run it fails every time (2 of 2) with this PR, and passes on main, presumably because the PR changes the address layout so the reuse always lands. The full run in parallel passes.

A bisection over all 116 earlier tests (each subset followed by the watch test) points to that texture test alone.

Possible fixes (test-only; for the title, a stale entry only means an extra upload, not a missed one):

  • in the watch test, drop the before.is_empty() assumption and check only what the test is about: after the write, page p / PAGE + 1 is reported with now, and a later asker still sees it with now; or
  • forget journal entries for a range when it is freed (e.g. a watch::forget(start, end) called from the texture test before VirtualFree), which would also keep the journal from growing in long runs.

I can put either one on a branch if that helps.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-26 10:59 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153#issuecomment-7190121269) Follow-up on the one failure left with this PR on NVIDIA, `watch::tests::written_pages_are_reported_to_every_asker`: it is not caused by this PR. It is a test-order dependence that is already on `main`. RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, `main` `4f62c2a` and `main` + this PR. **What happens.** `watch::JOURNAL.written` is process-global and keeps page entries after the memory is freed. `texture::tests::warp_write_watched_texture_uploads_only_when_written` allocates one write-watched 64 KiB page, writes it, has `watch::writes` record it, and frees it. When `written_pages_are_reported_to_every_asker` runs next in the same process, `VirtualAlloc` can hand it a 4-page range that covers the freed page, so its first `writes()` already returns that page and `assert!(before.is_empty())` fails. A temporary print in both tests (not committed) shows the overlap on every failing run: ``` DIAG texture alloc raw=0x1e8f3420000 size=0x10000 DIAG watch alloc p=0x1e8f3400000 before=[(32043842, 3)] // 32043842 * 0x10000 = 0x1e8f3420000 ``` **Reproduction**, just the two tests, single-threaded: ``` cargo test -p victory-gpu --lib --locked -- --exact --test-threads=1 texture::tests::warp_write_watched_texture_uploads_only_when_written watch::tests::written_pages_are_reported_to_every_asker ``` - `main` `4f62c2a`: watch test fails 3 of 5 runs. - `main` + this PR: fails 3 of 3. In the full single-threaded `victory-gpu` run it fails every time (2 of 2) with this PR, and passes on `main`, presumably because the PR changes the address layout so the reuse always lands. The full run in parallel passes. A bisection over all 116 earlier tests (each subset followed by the watch test) points to that texture test alone. **Possible fixes** (test-only; for the title, a stale entry only means an extra upload, not a missed one): - in the watch test, drop the `before.is_empty()` assumption and check only what the test is about: after the write, page `p / PAGE + 1` is reported with `now`, and a later asker still sees it with `now`; or - forget journal entries for a range when it is freed (e.g. a `watch::forget(start, end)` called from the texture test before `VirtualFree`), which would also keep the journal from growing in long runs. I can put either one on a branch if that helps. AI-assisted (Claude).
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 11:01 UTC · original

Thanks @⁠qtLkz, that explains it. It also fits our RX 7900 XT numbers (5 of 100 full parallel runs on 000ffdd): it only fails when the allocator happens to hand back the freed page. #102 is the open issue for this flake, so the cause and the two-test reproduction would be worth adding there.

Of the two fixes I'd lean towards the second, forgetting a range's journal entries when it is freed. The first makes the test pass. The second also keeps a stale entry from ever being reported for new memory at a reused address, and keeps the journal from growing over a long run, as you note.

**@⁠adrianmjim** on GitHub · 2026-11-26 11:01 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153#issuecomment-7190155782) Thanks @⁠qtLkz, that explains it. It also fits our RX 7900 XT numbers (5 of 100 full parallel runs on `000ffdd`): it only fails when the allocator happens to hand back the freed page. #102 is the open issue for this flake, so the cause and the two-test reproduction would be worth adding there. Of the two fixes I'd lean towards the second, forgetting a range's journal entries when it is freed. The first makes the test pass. The second also keeps a stale entry from ever being reported for new memory at a reused address, and keeps the journal from growing over a long run, as you note.
Author
Owner

@⁠qtLkz on GitHub · 2026-11-26 15:43 UTC · original

@⁠adrianmjim Agreed on the second fix. It already exists as #112 (adritoyalser), which forgets the journal entries of fully covered pages in title_memory_remapped. I shouldn't have offered a new branch without checking. I've added the cause, the two-test reproduction and NVIDIA results to #102. On the RTX 4070 Ti, main + this PR + #112 gives 114 passed, 0 failed for victory-gpu --lib --test-threads=1 (2 of 2 runs), and the pair reproduction fails 0/10 with #112, against 7/10 with this PR alone.

One correction to my comment above: I wrote that the full single-threaded run passes on main. Rerunning today on the same 4f62c2a, the watch test fails there too (2 of 2 full runs, 9 of 10 pair runs). It depends on the address VirtualAlloc returns and not on this PR, so the conclusion stands, but "passes on main" did not hold up.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-26 15:43 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/153#issuecomment-7196656900) @⁠adrianmjim Agreed on the second fix. It already exists as #112 (adritoyalser), which forgets the journal entries of fully covered pages in `title_memory_remapped`. I shouldn't have offered a new branch without checking. I've added the cause, the two-test reproduction and NVIDIA results to #102. On the RTX 4070 Ti, `main` + this PR + #112 gives **114 passed, 0 failed** for `victory-gpu --lib --test-threads=1` (2 of 2 runs), and the pair reproduction fails 0/10 with #112, against 7/10 with this PR alone. One correction to my comment above: I wrote that the full single-threaded run passes on `main`. Rerunning today on the same `4f62c2a`, the watch test fails there too (2 of 2 full runs, 9 of 10 pair runs). It depends on the address `VirtualAlloc` returns and not on this PR, so the conclusion stands, but "passes on `main`" did not hold up. AI-assisted (Claude).
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/153/head:github-bot/gh-153'
git switch 'github-bot/gh-153'

Merge

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