fix(gpu): never tell a many-views block clean #428

Manually merged
github merged 1 commit from github-bot/gh-428 into main 2026-12-05 17:30:52 +00:00 AGit
Owner

@⁠Luxuride on GitHub · 2026-12-04 02:21 UTC · original
Luxuride:fix/gpu-many-views-not-clean → main · +55 −0 · 2 files · 1 commits · merged 2026-12-05 17:27 UTC

What is wrong

cover is documented as the place that decides whether a range may be told clean (crates/victory-gpu/src/watch.rs:2296-2303):

Of the blocks [from, to), which are read-only by our hand where they can be: every other view of their pages is made read-only too. Where one cannot be ... that block is not clean.

It implements that by walking elsewhere(...), but crates/victory-gpu/src/inplace.rs:655 leaves out pages shown in very many views:

if (2..=crate::watch::MANY_VIEWS).contains(&shown.len()) {
    out.push((page, …));
}

For a page with more than MANY_VIEWS (64) views, elsewhere yields nothing, cover's loop body never runs, all stays true, and guard_shared records the block clean (crates/victory-gpu/src/watch.rs:2194-2199) although protect_alias was never called for those views. They stay writable (pinned by the existing test a_page_of_many_views_is_guarded_one_view_at_a_time), so a write through one of them raises no guard page, the block keeps answering "not written" (guarded_clean), and inplace::follow_texture (crates/victory-gpu/src/inplace.rs:553-556) skips its writes(...) — the card keeps the pre-write bytes, i.e. a stale texture block, with no diagnostic.

The sibling path already re-checks this for itself: inplace::texture_stamp (crates/victory-gpu/src/inplace.rs:583) tests p.shown.len() <= crate::watch::MANY_VIEWS.

The change

crates/victory-gpu/src/inplace.rs — one query next to pages_of:

pub(crate) fn shown_in_many_views(page: usize) -> bool { … p.shown.len() > crate::watch::MANY_VIEWS }

crates/victory-gpu/src/watch.rs — one predicate above cover, one condition added in guard_shared's clean insert:

fn cleanable(block: usize) -> bool {
    !crate::inplace::shown_in_many_views(block * BLOCK)
}

A block of such a page is simply never told clean; it is re-covered (and re-asked) at the next asking. That is the safe direction — more syncing for pages with 65+ views, never a missed write. The other two clean-insert sites (protect_here, protect's note) are deliberately untouched: they mark a range clean only after having protected that whole range.

Validation

The module is Windows-only (guard pages, VirtualProtect), so its tests cannot run on this Linux host:

  • cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --lib: no errors, the 27 pre-existing style warnings unchanged.
  • cargo check -p victory-gpu --tests --target x86_64-pc-windows-msvc: the added test type-checks.
  • The new test a_page_of_many_views_is_not_cleanable pins the predicate: cleanable is true for a two-view page, false once 64 more views are made. It is a unit test of the new gate rather than a guard-page test, because the latter needs a Windows host.

Overlap

I checked every open PR that touches crates/victory-gpu/src/watch.rs and inplace.rs (the guard-bitmap and ray-tracing series): none adds or changes MANY_VIEWS, cover, elsewhere, or a clean insert. No issue mentions the many-views case.

**@⁠Luxuride** on GitHub · 2026-12-04 02:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/428) `Luxuride:fix/gpu-many-views-not-clean` → `main` · +55 −0 · 2 files · 1 commits · merged 2026-12-05 17:27 UTC ### What is wrong `cover` is documented as the place that decides whether a range may be told clean (`crates/victory-gpu/src/watch.rs:2296-2303`): > Of the blocks `[from, to)`, which are read-only by our hand where they can be: every other view of their pages is made read-only too. Where one cannot be ... that block is not clean. It implements that by walking `elsewhere(...)`, but `crates/victory-gpu/src/inplace.rs:655` leaves out pages shown in very many views: ```rust if (2..=crate::watch::MANY_VIEWS).contains(&shown.len()) { out.push((page, …)); } ``` For a page with more than `MANY_VIEWS` (64) views, `elsewhere` yields nothing, `cover`'s loop body never runs, `all` stays `true`, and `guard_shared` records the block clean (`crates/victory-gpu/src/watch.rs:2194-2199`) although `protect_alias` was never called for those views. They stay writable (pinned by the existing test `a_page_of_many_views_is_guarded_one_view_at_a_time`), so a write through one of them raises no guard page, the block keeps answering "not written" (`guarded_clean`), and `inplace::follow_texture` (`crates/victory-gpu/src/inplace.rs:553-556`) skips its `writes(...)` — the card keeps the pre-write bytes, i.e. a stale texture block, with no diagnostic. The sibling path already re-checks this for itself: `inplace::texture_stamp` (`crates/victory-gpu/src/inplace.rs:583`) tests `p.shown.len() <= crate::watch::MANY_VIEWS`. ### The change `crates/victory-gpu/src/inplace.rs` — one query next to `pages_of`: ```rust pub(crate) fn shown_in_many_views(page: usize) -> bool { … p.shown.len() > crate::watch::MANY_VIEWS } ``` `crates/victory-gpu/src/watch.rs` — one predicate above `cover`, one condition added in `guard_shared`'s clean insert: ```rust fn cleanable(block: usize) -> bool { !crate::inplace::shown_in_many_views(block * BLOCK) } ``` A block of such a page is simply never told clean; it is re-covered (and re-asked) at the next asking. That is the safe direction — more syncing for pages with 65+ views, never a missed write. The other two clean-insert sites (`protect_here`, `protect`'s `note`) are deliberately untouched: they mark a range clean only after having protected that whole range. ### Validation The module is Windows-only (guard pages, `VirtualProtect`), so its tests cannot run on this Linux host: - `cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --lib`: no errors, the 27 pre-existing style warnings unchanged. - `cargo check -p victory-gpu --tests --target x86_64-pc-windows-msvc`: the added test type-checks. - The new test `a_page_of_many_views_is_not_cleanable` pins the predicate: `cleanable` is true for a two-view page, false once 64 more views are made. It is a unit test of the new gate rather than a guard-page test, because the latter needs a Windows host. ### Overlap I checked every open PR that touches `crates/victory-gpu/src/watch.rs` and `inplace.rs` (the guard-bitmap and ray-tracing series): none adds or changes `MANY_VIEWS`, `cover`, `elsewhere`, or a clean insert. No issue mentions the many-views case.
cover() walks elsewhere(), which leaves out pages shown in more than
MANY_VIEWS views, so its loop body never runs for them and it returns true
without having made any other view read-only. guard_shared then records the
block clean, no fault is raised by a write through those views, and the
block keeps answering 'not written' (guarded_clean), so inplace::follow_texture
skips its writes() and the card keeps the pre-write bytes.

Gate the clean insert on cleanable(), which asks inplace::shown_in_many_views:
a block of such a page is simply never clean, which is the safe direction
(it is re-covered at the next asking).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 02:27:50 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 03:00 UTC · original

Ran this natively on Windows 11 (MSVC) with real D3D12, one NVIDIA desktop card plus WARP, against the merge base.

The gate does what it says for the branch it sits in. I got there with a local test (not pushed). Two real views of a pagefile section plus 62 registered filler views, so the page has 64 views and cover still walks it. Guard one, which leaves two protected as an alias but not clean. Then map a third real view, which takes the page to 65. views_mapped doesn't open anything at that point because views_of_section already skips pages past MANY_VIEWS. Guard two, write through the third view, guard two again. On the base the last guard returns nothing because two was told clean in guard_shared. With this PR it reports the page. So that's a fail on base and a pass here.

The case I'd expect to be more common is still open though. On a page that already has more than MANY_VIEWS views, the first guard of a view sends the block through protect_claimed -> protect_here -> protect_mapped, and note sets the clean bit there. cover finds nothing in elsewhere and leaves that bit alone. Second local test, same setup as a_page_of_many_views_is_guarded_one_view_at_a_time. Guard one twice (the second returns nothing), write through two, which is still writable, then guard one again. It returns nothing on the base and on this branch too. I printed the clean bit right after the first guard and it's set on both. So the line in the description saying those two sites only mark a range clean after protecting the whole range doesn't hold for these pages, because the other views were never protected.

What I tried locally was putting the check into cover instead, so every caller gets it:

for block in from..to {
    if !cleanable(block) {
        all = false;
        g.clean.remove(block);
    }
}

With that, both local tests pass, and so do a_page_of_many_views_is_guarded_one_view_at_a_time and your new test. The block just reads as written at every asking. The full victory-gpu lib suite with it applied gives the same result as your branch (same 5 known failures, nothing new). It also adds one views() lookup per block on every protect run, which might matter on big runs. A cheaper check is probably possible.

On impact, texture_stamp never seals a many-views page, so the texture upload path copies and hashes those levels anyway. I'd expect the visible effect to be in what guard/writes report for that view rather than in a stale texture. I didn't trace a real case of that.

The new test a_page_of_many_views_is_not_cleanable doesn't build on the base since cleanable isn't there. It pins the predicate and doesn't exercise the guard path.

Other runs on this branch

  • cargo test -p victory-gpu --lib (4 threads, skipping descriptor::tests::views_die_with_their_resource) gave 340 passed, 5 failed. Those 5 are the ones that already fail on main on this machine, the two indirect::tests::host_list_*, two pipeline::host library loads and the flaky watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own.
  • watch:: five times each. The flaky test failed 2 of 5 on the base and 1 of 5 here. I don't read anything into that difference. views_die_with_their_resource alone crashes with 0xc0000005 5 of 5 on both, so nothing changed there.
  • clippy --all-targets has the same warnings before and after, nothing new.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 03:00 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/428#issuecomment-7399588111) Ran this natively on Windows 11 (MSVC) with real D3D12, one NVIDIA desktop card plus WARP, against the merge base. The gate does what it says for the branch it sits in. I got there with a local test (not pushed). Two real views of a pagefile section plus 62 registered filler views, so the page has 64 views and `cover` still walks it. Guard `one`, which leaves `two` protected as an alias but not clean. Then map a third real view, which takes the page to 65. `views_mapped` doesn't open anything at that point because `views_of_section` already skips pages past `MANY_VIEWS`. Guard `two`, write through the third view, guard `two` again. On the base the last guard returns nothing because `two` was told clean in `guard_shared`. With this PR it reports the page. So that's a fail on base and a pass here. The case I'd expect to be more common is still open though. On a page that already has more than `MANY_VIEWS` views, the first `guard` of a view sends the block through `protect_claimed` -> `protect_here` -> `protect_mapped`, and `note` sets the clean bit there. `cover` finds nothing in `elsewhere` and leaves that bit alone. Second local test, same setup as `a_page_of_many_views_is_guarded_one_view_at_a_time`. Guard `one` twice (the second returns nothing), write through `two`, which is still writable, then guard `one` again. It returns nothing on the base and on this branch too. I printed the clean bit right after the first guard and it's set on both. So the line in the description saying those two sites only mark a range clean after protecting the whole range doesn't hold for these pages, because the other views were never protected. What I tried locally was putting the check into `cover` instead, so every caller gets it: ```rust for block in from..to { if !cleanable(block) { all = false; g.clean.remove(block); } } ``` With that, both local tests pass, and so do `a_page_of_many_views_is_guarded_one_view_at_a_time` and your new test. The block just reads as written at every asking. The full `victory-gpu` lib suite with it applied gives the same result as your branch (same 5 known failures, nothing new). It also adds one `views()` lookup per block on every protect run, which might matter on big runs. A cheaper check is probably possible. On impact, `texture_stamp` never seals a many-views page, so the texture upload path copies and hashes those levels anyway. I'd expect the visible effect to be in what `guard`/`writes` report for that view rather than in a stale texture. I didn't trace a real case of that. The new test `a_page_of_many_views_is_not_cleanable` doesn't build on the base since `cleanable` isn't there. It pins the predicate and doesn't exercise the guard path. Other runs on this branch - `cargo test -p victory-gpu --lib` (4 threads, skipping `descriptor::tests::views_die_with_their_resource`) gave 340 passed, 5 failed. Those 5 are the ones that already fail on main on this machine, the two `indirect::tests::host_list_*`, two `pipeline::host` library loads and the flaky `watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own`. - `watch::` five times each. The flaky test failed 2 of 5 on the base and 1 of 5 here. I don't read anything into that difference. `views_die_with_their_resource` alone crashes with 0xc0000005 5 of 5 on both, so nothing changed there. - clippy `--all-targets` has the same warnings before and after, nothing new. AI-assisted: yes
github-bot force-pushed github-bot/gh-428 from 07a3bf1f1b to a5e6ee1f4f 2026-12-04 10:26:28 +00:00 Compare
github-bot force-pushed github-bot/gh-428 from a5e6ee1f4f to 4850199638 2026-12-04 11:13:28 +00:00 Compare
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 11:12 UTC · original

Thank you — the second case is real and the PR as pushed was not enough. I have adopted your shape: cover now starts with

for block in from..to {
    if !cleanable(block) {
        all = false;
        g.clean.remove(block);
    }
}

so every caller gets it, including protect_run -> protect_here, which is exactly the path that set the bit on a page elsewhere never walked. The cleanable gate on guard_shared's own insert stays, because that insert happens after its cover call and would otherwise put the bit straight back; the two together are what your two local tests check.

I kept the predicate test and added your guard-path assertion to the existing many-views test instead: after one guard of a view of a 66-view page, guards().clean must not hold the block — the same check you printed by hand, now pinned.

On the views() cost: yes, one lookup per block on every protect run, and I do not have a cheaper correct one either — the block has to know how many views its page has at that moment, and that set changes under it. If it shows up on a big run, the fix is a cached count per page, which is a different (and bigger) change.

On impact, I agree the visible effect is more likely in what guard/writes report for a many-views view than in a stale texture; I could not trace a stale-texture case either, and the description now says the guard's answer rather than a texture.

**@⁠Luxuride** on GitHub · 2026-12-04 11:12 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/428#issuecomment-7409771091) Thank you — the second case is real and the PR as pushed was not enough. I have adopted your shape: `cover` now starts with ```rust for block in from..to { if !cleanable(block) { all = false; g.clean.remove(block); } } ``` so every caller gets it, including `protect_run` -> `protect_here`, which is exactly the path that set the bit on a page `elsewhere` never walked. The `cleanable` gate on `guard_shared`'s own insert stays, because that insert happens *after* its `cover` call and would otherwise put the bit straight back; the two together are what your two local tests check. I kept the predicate test and added your guard-path assertion to the existing many-views test instead: after one `guard` of a view of a 66-view page, `guards().clean` must not hold the block — the same check you printed by hand, now pinned. On the `views()` cost: yes, one lookup per block on every protect run, and I do not have a cheaper correct one either — the block has to know how many views its page has at that moment, and that set changes under it. If it shows up on a big run, the fix is a cached count per page, which is a different (and bigger) change. On impact, I agree the visible effect is more likely in what `guard`/`writes` report for a many-views view than in a stale texture; I could not trace a stale-texture case either, and the description now says the guard's answer rather than a texture.
github-bot force-pushed github-bot/gh-428 from 4850199638 to 009e89213a 2026-12-04 11:19:06 +00:00 Compare
github manually merged commit db5096a605 into main 2026-12-05 17:30:51 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.