Skip to content

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

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/batch-partial-page-merge
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/batch-partial-page-merge

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

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

@kotekompotek

Copy link
Copy Markdown

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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Ensuring partial refreshes of two parts of one page do not prematurely mark the whole page current builds cleanly and passes all host tests.
  • cargo test -p victory-gpu host::tests:: -- --skip dynamic_slots_are_held_until_released: 12/12 passed on RTX 5090, 12/12 passed on WARP.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refreshes of two parts of one page don't make disjoint copies (+42). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Touches the same refresh-coalescing logic as the #2349/#2419/#2428 triple — 4th overlapping PR now; convergence badly needed in host.rs refreshes.

@BastienRodz
BastienRodz force-pushed the gpu/batch-partial-page-merge branch from 83f282d to 6cacc63 Compare November 25, 2026 15:46
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

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 <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

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

BastienRodz pushed a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
Co-authored-by: borosf <borosf@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants