watch: the write-watch test counts only the writes since its first asking (#102) #115

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

@⁠ySKELLETONX on GitHub · 2026-11-25 14:30 UTC · original
ySKELLETONX:fix/watch-test-stale-journal → main · +11 −4 · 1 files · 1 commits · open

Fixes #102.

Why

watch::tests::written_pages_are_reported_to_every_asker starts by asserting that a fresh write-watched allocation has no journaled writes (before.is_empty()). JOURNAL is process-wide, though, and keeps each page's last write after its memory is freed. When an earlier test's allocation sat at the address VirtualAlloc now returns, its writes are still there and the assertion fails. It depends on order and address reuse, which is why #102 saw it once in a full serial run.

Deterministic repro, as a temporary test placed before it (not committed):

#[test]
fn repro_stale_journal() {
    let p = unsafe { VirtualAlloc(null(), 4 * PAGE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) } as usize;
    unsafe { ((p + 2 * PAGE) as *mut u8).write(1) };
    writes(p, p + 4 * PAGE, false).expect("watched");
    unsafe { VirtualFree(p as *mut _, 0, MEM_RELEASE) };
    written_pages_are_reported_to_every_asker(); // VirtualAlloc returns the same address
}

On main this fails every time at assert!(before.is_empty()).

What

Only the test changes. It keeps the stamp of its first asking and checks only the writes since then, which is how the callers read the journal: texture.rs and shadow.rs compare each entry with their own last asking. Older entries are allowed in the first answer as long as they are older than that asking.

I left the journal as it is. A stale entry can only be older than any asking made after the memory came back, so a caller with an earlier asking does not see it as new. A caller that has never asked copies the whole range anyway.

Testing

RX 7600 XT, Windows 11 build 26300, Rust 1.98.1:

  • The repro above, with three earlier allocations at the same address (stale writes on pages 1, 2 and 3, including the page the test writes): fails on main, passes with this change.
  • cargo test -p victory-gpu --lib -- --test-threads=1: 111 passed.
  • cargo test -p victory-gpu --lib, 80 parallel runs: this test never failed. Three other tests did, 4 times in total, and they are unrelated to this change: queue::tests::present_runs_after_a_queues_wait (queue.rs:833, left: 0) twice, query::tests::queries_not_run_keep_their_stand_in_values (query.rs:597) once, and query::tests::occlusion_queries_around_draws_not_run_stay_visible (query.rs:533) once. I'll look at those separately.
**@⁠ySKELLETONX** on GitHub · 2026-11-25 14:30 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/115) `ySKELLETONX:fix/watch-test-stale-journal` → `main` · +11 −4 · 1 files · 1 commits · open Fixes #102. ## Why `watch::tests::written_pages_are_reported_to_every_asker` starts by asserting that a fresh write-watched allocation has no journaled writes (`before.is_empty()`). `JOURNAL` is process-wide, though, and keeps each page's last write after its memory is freed. When an earlier test's allocation sat at the address `VirtualAlloc` now returns, its writes are still there and the assertion fails. It depends on order and address reuse, which is why #102 saw it once in a full serial run. Deterministic repro, as a temporary test placed before it (not committed): ```rust #[test] fn repro_stale_journal() { let p = unsafe { VirtualAlloc(null(), 4 * PAGE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) } as usize; unsafe { ((p + 2 * PAGE) as *mut u8).write(1) }; writes(p, p + 4 * PAGE, false).expect("watched"); unsafe { VirtualFree(p as *mut _, 0, MEM_RELEASE) }; written_pages_are_reported_to_every_asker(); // VirtualAlloc returns the same address } ``` On `main` this fails every time at `assert!(before.is_empty())`. ## What Only the test changes. It keeps the stamp of its first asking and checks only the writes since then, which is how the callers read the journal: `texture.rs` and `shadow.rs` compare each entry with their own last asking. Older entries are allowed in the first answer as long as they are older than that asking. I left the journal as it is. A stale entry can only be older than any asking made after the memory came back, so a caller with an earlier asking does not see it as new. A caller that has never asked copies the whole range anyway. ## Testing RX 7600 XT, Windows 11 build 26300, Rust 1.98.1: - The repro above, with three earlier allocations at the same address (stale writes on pages 1, 2 and 3, including the page the test writes): fails on `main`, passes with this change. - `cargo test -p victory-gpu --lib -- --test-threads=1`: 111 passed. - `cargo test -p victory-gpu --lib`, 80 parallel runs: this test never failed. Three other tests did, 4 times in total, and they are unrelated to this change: `queue::tests::present_runs_after_a_queues_wait` (queue.rs:833, `left: 0`) twice, `query::tests::queries_not_run_keep_their_stand_in_values` (query.rs:597) once, and `query::tests::occlusion_queries_around_draws_not_run_stay_visible` (query.rs:533) once. I'll look at those separately.
The journal is the process's and keeps a page's last write after its
memory is freed. When an earlier test's allocation was at the address
VirtualAlloc gives this test, its first asking found those writes and
`before.is_empty()` failed (#102). Callers compare stamps with their own
last asking, so entries older than it are not reported as new: the test
now does the same, and the code is unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:03 +00:00
Author
Owner

@⁠Adika713 on GitHub · 2026-11-25 16:04 UTC · original

Verified on AMD Radeon RX 6950 XT, Ryzen 5 3600, 32 GB RAM, Windows 11,
Rust 1.98.1 / Cargo 1.98.1. No game data; the title was not run.

Each tree used an isolated CARGO_TARGET_DIR.

Before, at upstream/main 01aadd193d57e71fb4d57810eb2fdd1bc95c950b, from
F:\VIctory-Belobug-AMD with
CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-gpu-main-verify:

cargo test -q -p victory-gpu --lib --locked -- --test-threads=1 warp_write_watched_texture written_pages_are_reported

20 runs: 18 failed, 2 passed. Every failure was
watch::tests::written_pages_are_reported_to_every_asker panicking at
watch.rs:998:9 with assertion failed: before.is_empty().

After, at PR head c866e7a, from a detached worktree at
F:\VIctory-Belobug-AMD\_agent_tmp\watch-115 with
CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-watch-115:

cargo test -q --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\watch-115\Cargo.toml -p victory-gpu --lib --locked -- --test-threads=1 warp_write_watched_texture written_pages_are_reported
cargo test -q --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\watch-115\Cargo.toml -p victory-gpu --lib --locked -- --test-threads=1
  • Deterministic repro: 20/20 runs passed; each
    test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 113 filtered out.
  • Full serial lib: 20/20 runs passed; each
    test result: ok. 111 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out.

Overlap: PR #112 head a1e531b also passes the same two commands (20/20 each),
with 112 passed; 0 failed; 4 ignored in the full lib because it adds its own
regression test. #112 clears the stale JOURNAL.written entries; this PR only
changes the test's expectations. PR #127 head c9e45b4 touches watch.rs and
texture.rs but does not compile here (error[E0425]: cannot find type 'F' in this scope at host.rs:3134 and host.rs:3138). I wrote no competing fix.

Not tested: the game, or the full workspace suite.

AI-assisted: OpenCode, model Big Pickle. No game data.

**@⁠Adika713** on GitHub · 2026-11-25 16:04 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/115#issuecomment-7167575433) Verified on AMD Radeon RX 6950 XT, Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1. No game data; the title was not run. Each tree used an isolated `CARGO_TARGET_DIR`. Before, at `upstream/main` `01aadd193d57e71fb4d57810eb2fdd1bc95c950b`, from `F:\VIctory-Belobug-AMD` with `CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-gpu-main-verify`: ```powershell cargo test -q -p victory-gpu --lib --locked -- --test-threads=1 warp_write_watched_texture written_pages_are_reported ``` 20 runs: **18 failed, 2 passed**. Every failure was `watch::tests::written_pages_are_reported_to_every_asker` panicking at `watch.rs:998:9` with `assertion failed: before.is_empty()`. After, at PR head `c866e7a`, from a detached worktree at `F:\VIctory-Belobug-AMD\_agent_tmp\watch-115` with `CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-watch-115`: ```powershell cargo test -q --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\watch-115\Cargo.toml -p victory-gpu --lib --locked -- --test-threads=1 warp_write_watched_texture written_pages_are_reported cargo test -q --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\watch-115\Cargo.toml -p victory-gpu --lib --locked -- --test-threads=1 ``` - Deterministic repro: 20/20 runs passed; each `test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 113 filtered out`. - Full serial lib: 20/20 runs passed; each `test result: ok. 111 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out`. Overlap: PR #112 head `a1e531b` also passes the same two commands (20/20 each), with `112 passed; 0 failed; 4 ignored` in the full lib because it adds its own regression test. #112 clears the stale `JOURNAL.written` entries; this PR only changes the test's expectations. PR #127 head `c9e45b4` touches `watch.rs` and `texture.rs` but does not compile here (`error[E0425]: cannot find type 'F' in this scope` at `host.rs:3134` and `host.rs:3138`). I wrote no competing fix. Not tested: the game, or the full workspace suite. AI-assisted: OpenCode, model Big Pickle. No game data.
github-bot force-pushed github-bot/gh-115 from c866e7a50d to 419732ff5f 2026-11-26 13:08:59 +00:00 Compare
This pull request can be merged automatically.
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/115/head:github-bot/gh-115'
git switch 'github-bot/gh-115'

Merge

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