GPU: refreshes of two parts of one page do not make it current whole #2474

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

@⁠BastienRodz on GitHub · 2026-11-25 14:19 UTC · original
BastienRodz:gpu/batch-partial-page-merge → main · +42 −3 · 1 files · 1 commits · open

What's wrong

Batch::flush merged a copy's refreshed ranges into its current range whenever they touched. Two flushes of one submission can each refresh part of a 64 KiB page. Neither takes the page then: Tracked::take leaves a partly covered page changed and unguarded. Their union still counted as current, so Batch::add skipped a later refresh of the whole page and the page was never taken. If shaders marked it, copy_back_marked then found it changed with nothing saved and dropped their writes (copy_back_page too).

What the fix does

One condition in Batch::flush: a refreshed range joins the current one only when the two meet across a page boundary (max(a, from).div_ceil(PAGE) <= min(b, to) / PAGE). Otherwise the larger one is kept, as before. Every page inside the current range has then been covered whole by one refresh. Whole-page refreshes still join; two halves of one page no longer do.

Tests

New host::batch::partial_flushes_do_not_hide_a_whole_page_refresh: two partial flushes of a page, then a whole-page refresh, a marked shader write and copy_back_marked. It also checks that whole pages meeting at a boundary still merge, with nothing copied twice.

  • On main (940d32f) it fails: marked write goes back, left: 0, right: 65536.
  • With the fix, host::batch::, shadow:: and watch:: pass (14, 1 benchmark ignored). Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe; the test returns early without a host device.
  • windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45632736100

Not tested

No title run, and no AMD/NVIDIA GPU. How often a submission refreshes one page in parts and then whole is not measured. #1818, #2349 and #2428 each rewrite current as range sets and will conflict with this one-line change. Whichever lands, the rule is the same: touching ranges inside one page are not a whole-page refresh.

Fixes #2473

AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-25 14:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2474) `BastienRodz:gpu/batch-partial-page-merge` → `main` · +42 −3 · 1 files · 1 commits · open ### What's wrong `Batch::flush` merged a copy's refreshed ranges into its current range whenever they touched. Two flushes of one submission can each refresh part of a 64 KiB page. Neither takes the page then: `Tracked::take` leaves a partly covered page changed and unguarded. Their union still counted as current, so `Batch::add` skipped a later refresh of the whole page and the page was never taken. If shaders marked it, `copy_back_marked` then found it changed with nothing saved and dropped their writes (`copy_back_page` too). ### What the fix does One condition in `Batch::flush`: a refreshed range joins the current one only when the two meet across a page boundary (`max(a, from).div_ceil(PAGE) <= min(b, to) / PAGE`). Otherwise the larger one is kept, as before. Every page inside the current range has then been covered whole by one refresh. Whole-page refreshes still join; two halves of one page no longer do. ### Tests New `host::batch::partial_flushes_do_not_hide_a_whole_page_refresh`: two partial flushes of a page, then a whole-page refresh, a marked shader write and `copy_back_marked`. It also checks that whole pages meeting at a boundary still merge, with nothing copied twice. - On `main` (940d32f) it fails: `marked write goes back`, `left: 0`, `right: 65536`. - With the fix, `host::batch::`, `shadow::` and `watch::` pass (14, 1 benchmark ignored). Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe; the test returns early without a host device. - windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45632736100 ### Not tested No title run, and no AMD/NVIDIA GPU. How often a submission refreshes one page in parts and then whole is not measured. #1818, #2349 and #2428 each rewrite `current` as range sets and will conflict with this one-line change. Whichever lands, the rule is the same: touching ranges inside one page are not a whole-page refresh. Fixes #2473 AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Batch::flush kept, as a copy's current range, the union of the ranges it
refreshed whenever they touched. Two flushes of one submission that each
refresh part of a 64 KiB page ([p, p + 4 KiB), then the rest) leave the
page changed and unguarded: Tracked::take copies a page held in part and
"stays changed". Their union still covered the whole page, so a later
refresh of all of it in the same submission (Batch::add) was skipped and
the page was never taken. After the submission copy_back_marked found it
changed with nothing saved and kept the title's bytes, dropping the
shaders' writes to it (copy_back_page too).

Ranges now join only where they meet across a page boundary, so no page
is current unless one refresh covered it whole; whole pages still join.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:56 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 14:28 UTC · original

Verified the merge condition carefully — it is exactly right:

  • Merge iff the intersection contains a whole page (max(a,from).div_ceil(PAGE) <= min(b,to)/PAGE): then every page in the union was covered whole by at least one of the two refreshes, so the union's taken claim is honest.
  • Two halves of one page have an empty intersection — no merge — the larger stays and the later whole-page refresh still flushes, take guards the page, and marked writes go back. That is the reported failure exactly.
  • Two ranges meeting at a page boundary share the boundary page (div_ceil == /) and still merge, as the issue asked.
  • Under-merging is the safe direction anyway: keeping the larger range can only refresh more, never claim more coverage than a refresh took.

Note the issue's caveat that #2428's disjoint-range rework has the same hole: its push_range(gap=0) merges touching ranges in current, so two halves of one page still coalesce into full-page coverage. Whichever of these lands second, the touching-merge in push_range needs the same whole-page condition.

The test pins it end-to-end: partial flushes → whole-page refresh actually flushes → copy_back_marked returns the page.

**@⁠kotekompotek** on GitHub · 2026-11-25 14:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2474#issuecomment-7165335026) Verified the merge condition carefully — it is exactly right: - Merge iff the *intersection* contains a whole page (`max(a,from).div_ceil(PAGE) <= min(b,to)/PAGE`): then every page in the union was covered whole by at least one of the two refreshes, so the union's `taken` claim is honest. - Two halves of one page have an empty intersection — no merge — the larger stays and the later whole-page refresh still flushes, `take` guards the page, and marked writes go back. That is the reported failure exactly. - Two ranges meeting at a page boundary share the boundary page (div_ceil == /) and still merge, as the issue asked. - Under-merging is the safe direction anyway: keeping the larger range can only refresh more, never claim more coverage than a refresh took. Note the issue's caveat that #2428's disjoint-range rework has the same hole: its `push_range(gap=0)` merges *touching* ranges in `current`, so two halves of one page still coalesce into full-page coverage. Whichever of these lands second, the touching-merge in `push_range` needs the same whole-page condition. The test pins it end-to-end: partial flushes → whole-page refresh actually flushes → `copy_back_marked` returns the page.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 15:47 UTC · original

Rebased onto main da82e44 (main reworked the mod batch tests; ours now sits at the end of it). The one-condition fix in Batch::flush applied as is. On the new main the test still fails without it (left: 0, right: 65536) and passes with it.

**@⁠BastienRodz** on GitHub · 2026-11-25 15:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2474#issuecomment-7167322169) Rebased onto main da82e44 (main reworked the `mod batch` tests; ours now sits at the end of it). The one-condition fix in `Batch::flush` applied as is. On the new main the test still fails without it (`left: 0`, `right: 65536`) and passes with it.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:30 UTC · original

Automated triage for the maintainers.

This PR changes one condition in Batch::flush (crates/victory-gpu/src/host.rs). A refreshed range now joins the copy's current range only when the two share a page boundary. Before, any touching ranges joined. I checked it against Tracked::take in watch.rs, which guards only pages covered whole and leaves a partly covered page changed. On main, two halves of one 64 KiB page merged into a current range that covered the page, so Batch::add skipped a later whole-page refresh and the page was never taken. With the new condition, every page inside a merged range is covered whole by one of the two refreshes. Whole pages meeting at a boundary still merge, and not merging only costs a re-check, since take copies only changed pages.

The new test batch::partial_flushes_do_not_hide_a_whole_page_refresh covers the failing sequence and uses existing test helpers. It returns early without a host device, so CI alone does not show it ran. The author reports it fails on main and passes with the fix. As the PR body says, it will conflict with the open range-set reworks (#1818, #2349, #2428), which need the same rule.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2474#issuecomment-7171003462) <!-- victory-triage v1 head=0de47436b14b2ccef26f427092297e46b1c8ec0d verdict=merge-candidate at=2026-11-25T18:30:21Z --> Automated triage for the maintainers. This PR changes one condition in `Batch::flush` (`crates/victory-gpu/src/host.rs`). A refreshed range now joins the copy's `current` range only when the two share a page boundary. Before, any touching ranges joined. I checked it against `Tracked::take` in `watch.rs`, which guards only pages covered whole and leaves a partly covered page changed. On main, two halves of one 64 KiB page merged into a `current` range that covered the page, so `Batch::add` skipped a later whole-page refresh and the page was never taken. With the new condition, every page inside a merged range is covered whole by one of the two refreshes. Whole pages meeting at a boundary still merge, and not merging only costs a re-check, since `take` copies only changed pages. The new test `batch::partial_flushes_do_not_hide_a_whole_page_refresh` covers the failing sequence and uses existing test helpers. It returns early without a host device, so CI alone does not show it ran. The author reports it fails on main and passes with the fix. As the PR body says, it will conflict with the open range-set reworks (#1818, #2349, #2428), which need the same rule. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2474/head:github-bot/gh-2474'
git switch 'github-bot/gh-2474'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2474'
git switch 'github-bot/gh-2474'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2474'
git switch 'github-bot/gh-2474'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2474'
git switch 'main'
git merge --squash 'github-bot/gh-2474'
git switch 'main'
git merge --ff-only 'github-bot/gh-2474'
git switch 'main'
git merge 'github-bot/gh-2474'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!2474
No description provided.