GPU: a page a refresh took in part is not current #2540

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

@⁠Calvix2k on GitHub · 2026-11-25 15:31 UTC · original
Calvix2k:codex/gpu-batch-current-pages → main · +64 −13 · 1 files · 1 commits · open

Fixes #2473.

The failure

Batch::flush kept a copy's refreshed ranges as the union of the ones that touch, and Batch::add skipped a later refresh covered by it. Two partial refreshes of one 64 KiB page ÔÇö [p, p + 4 KiB) then [p + 4 KiB, p + 64 KiB) ÔÇö union to the whole page, so a later whole-page refresh was skipped. Tracked::take had copied only parts of it, so the page stayed changed; after the submission a marked page then found it changed with nothing saved, and copy_back_marked kept the title's bytes instead of the shaders' writes.

What the change does

The set holds the pages a refresh took whole (from.div_ceil(PAGE) .. to / PAGE), and add skips a request only when every page it spans is in it. A page counted in parts is not there, so the rest of it is copied when it is asked for. Pages are the write watch's own unit, which is what decides whether a page is taken.

Two things the old form got for free and this keeps: a copy's refresh in a submission is still done once per range (not once per draw), and a step that writes title memory still clears the set (title_written).

Verification

  • partial_refreshes_do_not_make_a_page_current is the issue's scenario: two partial refreshes that together cover a page, then a title write, then a whole-page refresh. With the union the refresh copied 0 bytes (the page was never taken); now it copies the page. I did not keep a separate red run of the old code, but the two branches are one condition apart: with the union [p, p + PAGE) is in current and add returns before flush.
  • cargo test -p victory-gpu --features diagnostics --lib on Windows 10 19045 / RX 7800 XT after rebasing onto da82e44: 198 passed, 1 ignored, plus the known placed-view failure on a runtime without ID3D12Device10 (#1999, identical on main); clippy -D warnings clean.
**@⁠Calvix2k** on GitHub · 2026-11-25 15:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2540) `Calvix2k:codex/gpu-batch-current-pages` → `main` · +64 −13 · 1 files · 1 commits · open Fixes #2473. ### The failure `Batch::flush` kept a copy's refreshed ranges as the union of the ones that touch, and `Batch::add` skipped a later refresh covered by it. Two partial refreshes of one 64 KiB page ÔÇö `[p, p + 4 KiB)` then `[p + 4 KiB, p + 64 KiB)` ÔÇö union to the whole page, so a later whole-page refresh was skipped. `Tracked::take` had copied only parts of it, so the page stayed changed; after the submission a **marked** page then found it changed with nothing saved, and `copy_back_marked` kept the title's bytes instead of the shaders' writes. ### What the change does The set holds the pages a refresh took **whole** (`from.div_ceil(PAGE) .. to / PAGE`), and `add` skips a request only when every page it spans is in it. A page counted in parts is not there, so the rest of it is copied when it is asked for. Pages are the write watch's own unit, which is what decides whether a page is taken. Two things the old form got for free and this keeps: a copy's refresh in a submission is still done once per range (not once per draw), and a step that writes title memory still clears the set (`title_written`). ### Verification - `partial_refreshes_do_not_make_a_page_current` is the issue's scenario: two partial refreshes that together cover a page, then a title write, then a whole-page refresh. With the union the refresh copied 0 bytes (the page was never taken); now it copies the page. I did not keep a separate red run of the old code, but the two branches are one condition apart: with the union `[p, p + PAGE)` is in `current` and `add` returns before `flush`. - `cargo test -p victory-gpu --features diagnostics --lib` on Windows 10 19045 / RX 7800 XT after rebasing onto `da82e44`: **198 passed**, 1 ignored, plus the known placed-view failure on a runtime without `ID3D12Device10` (#1999, identical on `main`); clippy `-D warnings` clean.
`Batch` kept, per copy, the union of the ranges it refreshed when they
touched, and skipped a later refresh covered by it. Two partial refreshes of
one 64 KiB page — `[p, p + 4 KiB)` then `[p + 4 KiB, p + 64 KiB)` — unioned
to the whole page, so a later whole-page refresh was skipped and the page was
never taken. `Tracked::take` had copied only parts of it, so it stayed
changed; after the submission a marked page then found it changed with
nothing saved, and `copy_back_marked` kept the title's bytes instead of the
shaders' (#2473).

The set holds the pages one refresh took **whole**; a page counted in parts is
not in it, so the rest of it is copied when it is asked for. Pages are the
write watch's own unit, which is what decides whether a page is taken.

`partial_refreshes_do_not_make_a_page_current` is the issue's scenario: two
partial refreshes that together cover a page, then a title write, then a
whole-page refresh — with the union it copied 0 bytes and the page was never
taken; now it copies the page.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:40 +00:00
Author
Owner

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

Automated triage for the maintainers.

This fixes #2473: Batch::flush (crates/victory-gpu/src/host.rs) merged touching partial refreshes of one page into a "current" range, so a later whole-page refresh was skipped. The fix replaces the range with a per-copy BTreeSet of whole pages. The change is safe, because it can only refresh more. CI passes.

However, #2474 fixes the same issue in the same function and is the better candidate:

  • It changes only the merge condition: ranges merge only when their overlap contains a whole page.
  • It was opened first, and its CI passes.
  • Its test goes end to end: two partial flushes, a whole-page refresh, a marked shader write, then copy_back_marked returning the page. It also checks that whole pages meeting at a boundary still merge without a second copy. This PR's test only checks that flush() copies something.

This PR also has two costs #2474 avoids:

  • from.div_ceil(PAGE)..to / PAGE uses raw page boundaries rather than the tracked range that Tracked::take_split clamps to. Edge pages of buffers that are not page-aligned (including every sub-page buffer) are never recorded as current, so they are re-added on each list.
  • add now walks pages.range(first..=last).count() for every request.

Proposed for closing as a duplicate of #2474. The PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2540#issuecomment-7171079564) <!-- victory-triage v1 head=67f4bb4b0ea4b87785288fd8a67d4882976005a5 verdict=proposed-close at=2026-11-25T18:33:36Z --> Automated triage for the maintainers. This fixes #2473: `Batch::flush` (`crates/victory-gpu/src/host.rs`) merged touching partial refreshes of one page into a "current" range, so a later whole-page refresh was skipped. The fix replaces the range with a per-copy `BTreeSet` of whole pages. The change is safe, because it can only refresh more. CI passes. However, #2474 fixes the same issue in the same function and is the better candidate: - It changes only the merge condition: ranges merge only when their overlap contains a whole page. - It was opened first, and its CI passes. - Its test goes end to end: two partial flushes, a whole-page refresh, a marked shader write, then `copy_back_marked` returning the page. It also checks that whole pages meeting at a boundary still merge without a second copy. This PR's test only checks that `flush()` copies something. This PR also has two costs #2474 avoids: - `from.div_ceil(PAGE)..to / PAGE` uses raw page boundaries rather than the tracked range that `Tracked::take_split` clamps to. Edge pages of buffers that are not page-aligned (including every sub-page buffer) are never recorded as current, so they are re-added on each list. - `add` now walks `pages.range(first..=last).count()` for every request. Proposed for closing as a duplicate of #2474. The PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Kajanos on GitHub · 2026-11-26 00:07 UTC · original

Windows 11 / NVIDIA test run, head 67f4bb4b0e merged onto main 63bcca43c6.

Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (dxil.dll from the SDK).

  • cargo test --locked -p victory-gpu: 232 passed, 0 failed, 1 ignored (main: 231).
  • One note: in the first run, draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view failed once (round 0: a copy only where not shared, left true, right false, draw.rs:2876). It did not come back in 5 runs of that test alone or in 18 more full runs, and 18 full runs on main were clean too. So I can't attribute it to this PR, but it's worth knowing in case the sharing decision depends on timing.

Not run: the retail title, clippy, and other crates.

AI-assisted (Claude Code)

**@⁠Kajanos** on GitHub · 2026-11-26 00:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2540#issuecomment-7178416494) **Windows 11 / NVIDIA test run**, head `67f4bb4b0e` merged onto `main` `63bcca43c6`. Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (`dxil.dll` from the SDK). - `cargo test --locked -p victory-gpu`: 232 passed, 0 failed, 1 ignored (`main`: 231). - One note: in the first run, `draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view` failed once (`round 0: a copy only where not shared`, left `true`, right `false`, draw.rs:2876). It did not come back in 5 runs of that test alone or in 18 more full runs, and 18 full runs on `main` were clean too. So I can't attribute it to this PR, but it's worth knowing in case the sharing decision depends on timing. Not run: the retail title, clippy, and other crates. AI-assisted (Claude 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/2540/head:github-bot/gh-2540'
git switch 'github-bot/gh-2540'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2540'
git switch 'github-bot/gh-2540'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2540'
git switch 'github-bot/gh-2540'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2540'
git switch 'main'
git merge --squash 'github-bot/gh-2540'
git switch 'main'
git merge --ff-only 'github-bot/gh-2540'
git switch 'main'
git merge 'github-bot/gh-2540'
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!2540
No description provided.