GPU: two partial refreshes of one page make it count as current, so a whole-page refresh is skipped and marked writes are dropped #2473

Open
opened 2026-11-26 05:06:54 +00:00 by github-bot · 3 comments
Owner

@⁠BastienRodz on GitHub · 2026-11-25 14:19 UTC · original

What happens

Batch::flush (crates/victory-gpu/src/host.rs) keeps, as a copy's current range for the submission, the union of the ranges it refreshed whenever they touch (from <= b && a <= to). Take two flushes of one submission that each refresh only part of a 64 KiB tracked page, say [p, p + 4 KiB) and then [p + 4 KiB, p + 64 KiB). Tracked::take copies each part, and the page stays changed and unguarded ("A page whose part in the tracked memory lies only partly in [from, to) is copied in part and stays changed", watch.rs). The union [p, p + 64 KiB) still counts as current, so a later refresh of the whole page in the same submission (Batch::add) is skipped and the page is never taken.

After the submission, if shaders marked that page, copy_back_marked finds it changed with nothing saved and keeps the title's bytes, which drops the shaders' writes (copy_back_page does the same for page-table writes). A synthetic run shows it: two partial flushes, then a whole-page refresh and a marked write, and copy_back_marked returns 0.

Expected

A page should count as current only if one refresh covered it whole, so that a later whole-page refresh still takes it. Ranges that meet at a page boundary (whole pages) can keep merging.

Where

crates/victory-gpu/src/host.rs, Batch::flush, with Batch::add's skip of current ranges. #1818, #2349 and #2428 each rework current into range sets; the same rule applies there.

AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.

**@⁠BastienRodz** on GitHub · 2026-11-25 14:19 UTC · [original](https://github.com/Marvisak/VIctory/issues/2473) ### What happens `Batch::flush` (`crates/victory-gpu/src/host.rs`) keeps, as a copy's current range for the submission, the union of the ranges it refreshed whenever they touch (`from <= b && a <= to`). Take two flushes of one submission that each refresh only part of a 64 KiB tracked page, say `[p, p + 4 KiB)` and then `[p + 4 KiB, p + 64 KiB)`. `Tracked::take` copies each part, and the page stays changed and unguarded ("A page whose part in the tracked memory lies only partly in [from, to) is copied in part and stays changed", `watch.rs`). The union `[p, p + 64 KiB)` still counts as current, so a later refresh of the whole page in the same submission (`Batch::add`) is skipped and the page is never taken. After the submission, if shaders marked that page, `copy_back_marked` finds it changed with nothing saved and keeps the title's bytes, which drops the shaders' writes (`copy_back_page` does the same for page-table writes). A synthetic run shows it: two partial flushes, then a whole-page refresh and a marked write, and `copy_back_marked` returns 0. ### Expected A page should count as current only if one refresh covered it whole, so that a later whole-page refresh still takes it. Ranges that meet at a page boundary (whole pages) can keep merging. ### Where `crates/victory-gpu/src/host.rs`, `Batch::flush`, with `Batch::add`'s skip of current ranges. #1818, #2349 and #2428 each rework `current` into range sets; the same rule applies there. AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:54 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:56 UTC · original · edited 2026-11-26 06:48 UTC

Automated triage for the maintainers.

Still on main (63bcca4), crates/victory-gpu/src/host.rs: Batch::flush merges each refreshed range into current whenever it touches what is already there, whether or not the ranges cover whole tracked pages. Batch::add then skips any refresh inside current. Tracked::take in crates/victory-gpu/src/watch.rs leaves a page that is only partly in range changed and unguarded, so two adjacent partial refreshes make the whole page count as current without it ever being taken.

Open PRs, all conflicting with each other in host.rs: #2474 (joins current ranges only when their overlap holds a page boundary; smallest change), #2540 (a set of whole pages per copy) and #2428 (a larger performance rework using the same join rule as #2474).

New since the last triage: a comparison on an RTX 4070 against main 63bcca4 found all three merge cleanly and pass each other's tests, but #2540's regression test also passes on unpatched main (an early shadow.clean() return means nothing is flushed), so it needs a test that fails on main; one of #2428's tests has the same problem. #2474's test fails on main and passes with the fix.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:56 UTC · [original](https://github.com/Marvisak/VIctory/issues/2473#issuecomment-7167443685) · edited 2026-11-26 06:48 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-26T04:06:41Z at=2026-11-26T07:21:30Z --> Automated triage for the maintainers. Still on `main` (63bcca4), `crates/victory-gpu/src/host.rs`: `Batch::flush` merges each refreshed range into `current` whenever it touches what is already there, whether or not the ranges cover whole tracked pages. `Batch::add` then skips any refresh inside `current`. `Tracked::take` in `crates/victory-gpu/src/watch.rs` leaves a page that is only partly in range changed and unguarded, so two adjacent partial refreshes make the whole page count as current without it ever being taken. Open PRs, all conflicting with each other in `host.rs`: #2474 (joins `current` ranges only when their overlap holds a page boundary; smallest change), #2540 (a set of whole pages per copy) and #2428 (a larger performance rework using the same join rule as #2474). **New since the last triage:** a comparison on an RTX 4070 against `main` `63bcca4` found all three merge cleanly and pass each other's tests, but **#2540's regression test also passes on unpatched `main`** (an early `shadow.clean()` return means nothing is flushed), so it needs a test that fails on `main`; one of #2428's tests has the same problem. #2474's test fails on `main` and passes with the fix. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠shawshanker18 on GitHub · 2026-11-25 16:41 UTC · original

Tested both fixes for this, each merged onto main (67e8ae1), on Windows 11 with an RTX 4050 Laptop. Command: cargo test -p victory-gpu --lib.

  • #2474: merges clean; partial_flushes_do_not_hide_a_whole_page_refresh passes; no failures beyond main's 2 (NVIDIA view-heap cap).
  • #2540: merges clean; partial_refreshes_do_not_make_a_page_current passes; same 2.
  • The two conflict with each other.

#2474 changes one condition: current ranges are joined only when their overlap holds a page boundary.

I checked that this keeps the property the issue asks for: every whole page inside current was taken whole by a single refresh.

  • Say the union of U (current) and a new refresh R covers a page P whole, and they were joined at a boundary C. C cannot lie strictly inside P.
  • If C <= P.start, both ranges contain C, and the one that ends at or past P.end starts at or before C. So it covers P whole.
  • If C >= P.end, the same argument holds from the other side.
  • If that range is U, the property holds by induction.

#2540 keeps a set of whole pages per copy instead. It is more code, and partial ranges never count as current, so a repeated partial refresh within a submission is no longer skipped (a small amount of extra work, no correctness difference).

#2474's test also checks the end result: the marked write reaches title memory.

**@⁠shawshanker18** on GitHub · 2026-11-25 16:41 UTC · [original](https://github.com/Marvisak/VIctory/issues/2473#issuecomment-7168376332) Tested both fixes for this, each merged onto `main` (`67e8ae1`), on Windows 11 with an RTX 4050 Laptop. Command: `cargo test -p victory-gpu --lib`. - **#2474:** merges clean; `partial_flushes_do_not_hide_a_whole_page_refresh` passes; no failures beyond `main`'s 2 (NVIDIA view-heap cap). - **#2540:** merges clean; `partial_refreshes_do_not_make_a_page_current` passes; same 2. - The two conflict with each other. **#2474 changes one condition:** `current` ranges are joined only when their overlap holds a page boundary. I checked that this keeps the property the issue asks for: every whole page inside `current` was taken whole by a single refresh. - Say the union of `U` (current) and a new refresh `R` covers a page `P` whole, and they were joined at a boundary `C`. `C` cannot lie strictly inside `P`. - If `C <= P.start`, both ranges contain `C`, and the one that ends at or past `P.end` starts at or before `C`. So it covers `P` whole. - If `C >= P.end`, the same argument holds from the other side. - If that range is `U`, the property holds by induction. **#2540** keeps a set of whole pages per copy instead. It is more code, and partial ranges never count as current, so a repeated partial refresh within a submission is no longer skipped (a small amount of extra work, no correctness difference). #2474's test also checks the end result: the marked write reaches title memory.
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 04:06 UTC · original

Comparative check of the three open PRs for this issue. All runs were against main at 63bcca4 on an NVIDIA GeForce RTX 4070 with Windows 11, using cargo test -p victory-gpu --lib -- --test-threads=1 and cargo clippy -p victory-gpu --all-targets -- -D warnings. On this card main itself has 2 failures (descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, the NVIDIA view-heap cap). Every run below has those same 2 and no others.

For the cross-tests, the batch tests that only use Batch::add/flush were copied word for word into one module and run on each tree. Each test's "no host GPU" early return was changed to a panic!, so a test cannot pass by skipping.

PR Head Own test(s) Own test fails on main without the fix Cross-tests (4) on PR merged into main Clippy -D warnings Merges into main Defects found
#2474 0de4743 pass (230 passed after merge) yes: marked write goes back, left 0, right 65536 4/4 pass clean clean none
#2428 3a2279f pass (234 passed after merge; 6 host::batch tests) yes for a_page_copied_in_two_halves_is_refreshed_whole (left 0, right 65536). a_page_between_flushed_ranges_is_refreshed_when_asked_for also passes on main, so it is not a regression test for this issue. The pure push_range/push_copied tests do not compile without the PR. 4/4 pass clean clean none found. Mainly a performance rework (disjoint refresh ranges, about 250 changed lines); the #2473 fix comes from push_copied, which uses the same join rule as #2474.
#2540 67f4bb4 pass (230 passed after merge) no: partial_refreshes_do_not_make_a_page_current passes on unpatched main 4/4 pass clean clean The regression test does not reproduce the bug (see below)

The three PRs conflict with each other in crates/victory-gpu/src/host.rs (git merge-tree reports a conflict for every pair).

Why #2540's test passes on main. The test calls copy.update(pool, len) first, which takes the page and guards it. The two partial batch.add calls then return at the if shadow.clean() { return; } check at the top of Batch::add (host.rs, on main), so nothing is flushed and current stays empty. The title write that follows makes the page changed, and the whole-page refresh copies it whether or not the fix is present. The fix itself is correct: it only ever refreshes more, and all four cross-tests pass with it. Two smaller notes: pages are recorded by raw 64 KiB boundaries, so the edge pages of a copy that is not page-aligned never count as current (extra copies, not a correctness problem), and the test never frees its pool or drops its copy.

Join rule. #2474 (host.rs, Batch::flush) and #2428 (push_copied) both join two ranges only when max(a, from).div_ceil(PAGE) <= min(b, to) / PAGE. With that rule, every whole page inside a joined range was covered whole by one flushed range. On all three PR trees, the end-to-end test from #2474 passes: two partial flushes, a whole-page refresh, a marked shader write, then copy_back_marked returns the page.

Recommendation. If this issue is fixed on its own, #2474 is the smallest change: one condition, with an end-to-end regression test that fails on main and passes with the fix. #2428 contains the same fix inside a larger performance change. If the maintainers want that change, it closes this issue too, and #2474 would then be redundant. #2540 fixes the bug, but its test would need a scenario that fails on main (for example, #2474's sequence) before it adds regression coverage.

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 04:06 UTC · [original](https://github.com/Marvisak/VIctory/issues/2473#issuecomment-7182303334) Comparative check of the three open PRs for this issue. All runs were against `main` at `63bcca4` on an NVIDIA GeForce RTX 4070 with Windows 11, using `cargo test -p victory-gpu --lib -- --test-threads=1` and `cargo clippy -p victory-gpu --all-targets -- -D warnings`. On this card `main` itself has 2 failures (`descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, the NVIDIA view-heap cap). Every run below has those same 2 and no others. For the cross-tests, the batch tests that only use `Batch::add`/`flush` were copied word for word into one module and run on each tree. Each test's "no host GPU" early `return` was changed to a `panic!`, so a test cannot pass by skipping. | PR | Head | Own test(s) | Own test fails on `main` without the fix | Cross-tests (4) on PR merged into `main` | Clippy `-D warnings` | Merges into `main` | Defects found | |---|---|---|---|---|---|---|---| | #2474 | `0de4743` | pass (230 passed after merge) | **yes**: `marked write goes back`, left 0, right 65536 | 4/4 pass | clean | clean | none | | #2428 | `3a2279f` | pass (234 passed after merge; 6 `host::batch` tests) | **yes** for `a_page_copied_in_two_halves_is_refreshed_whole` (left 0, right 65536). `a_page_between_flushed_ranges_is_refreshed_when_asked_for` also passes on `main`, so it is not a regression test for this issue. The pure `push_range`/`push_copied` tests do not compile without the PR. | 4/4 pass | clean | clean | none found. Mainly a performance rework (disjoint refresh ranges, about 250 changed lines); the #2473 fix comes from `push_copied`, which uses the same join rule as #2474. | | #2540 | `67f4bb4` | pass (230 passed after merge) | **no**: `partial_refreshes_do_not_make_a_page_current` passes on unpatched `main` | 4/4 pass | clean | clean | The regression test does not reproduce the bug (see below) | The three PRs conflict with each other in `crates/victory-gpu/src/host.rs` (`git merge-tree` reports a conflict for every pair). **Why #2540's test passes on `main`.** The test calls `copy.update(pool, len)` first, which takes the page and guards it. The two partial `batch.add` calls then return at the `if shadow.clean() { return; }` check at the top of `Batch::add` (`host.rs`, on `main`), so nothing is flushed and `current` stays empty. The title write that follows makes the page changed, and the whole-page refresh copies it whether or not the fix is present. The fix itself is correct: it only ever refreshes more, and all four cross-tests pass with it. Two smaller notes: pages are recorded by raw 64 KiB boundaries, so the edge pages of a copy that is not page-aligned never count as current (extra copies, not a correctness problem), and the test never frees its pool or drops its copy. **Join rule.** #2474 (`host.rs`, `Batch::flush`) and #2428 (`push_copied`) both join two ranges only when `max(a, from).div_ceil(PAGE) <= min(b, to) / PAGE`. With that rule, every whole page inside a joined range was covered whole by one flushed range. On all three PR trees, the end-to-end test from #2474 passes: two partial flushes, a whole-page refresh, a marked shader write, then `copy_back_marked` returns the page. **Recommendation.** If this issue is fixed on its own, #2474 is the smallest change: one condition, with an end-to-end regression test that fails on `main` and passes with the fix. #2428 contains the same fix inside a larger performance change. If the maintainers want that change, it closes this issue too, and #2474 would then be redundant. #2540 fixes the bug, but its test would need a scenario that fails on `main` (for example, #2474's sequence) before it adds regression coverage. AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#2473
No description provided.