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

Open
ySKELLETONX wants to merge 1 commit from upstream-pr/115 into main
ySKELLETONX commented 2026-11-25 14:30:03 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-25T14:30:03Z.


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.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6606811146 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/115). Originally posted by [ySKELLETONX](https://github.com/ySKELLETONX) on 2026-11-25T14:30:03Z. --- 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.
Adika713 commented 2026-11-25 16:04:51 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Adika713 on 2026-11-25T16:04:51Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7167575433 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/115#issuecomment-7167575433). Originally posted by [Adika713](https://github.com/Adika713) on 2026-11-25T16:04:51Z. --- 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.
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/115:upstream-pr/115'
git switch 'upstream-pr/115'

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