GPU: a withheld range whose writes are marked could drop only its marked pages (copies 397 to 232 MB a frame here) #3089

Open
opened 2026-11-26 07:27:08 +00:00 by github-bot · 2 comments
Owner

@⁠Machad3x on GitHub · 2026-11-26 07:25 UTC · original

drop_withheld(address, len) in the copy-back drops every withheld declared range whole, so each of its pages is copied from title memory again at the next refresh. Where the range's writes are marked (the marked flag of Step::GpuWrite), only the pages with a mark hold anything the shaders wrote.

Measured (cell window, Ryzen 7 5700X, RTX 3080 Ti, a fork with other copy changes on top of main):

  • A temporary counter: every withheld range was a marking one (about 148 MB a frame), and about 59 % of the pages in them had no mark.
  • One run with the change against one without, medians: title memory copied 397 to 232 MB a frame, copy time 59 to 43 ms, preparing 147 to 129 ms, frame 384 to 377 ms (the frame difference is within the noise). Marked pages went from 62 to 80 ms in the same run; they have varied 61 to 119 ms between runs of one binary here, so I cannot say whether the change adds to them. Image unchanged at that scene, no draws dropped, no device removal, in a 5-minute run.

The change:

  • When merging declared ranges, keep marked as the AND over the steps naming the range.
  • For a withheld marked range, skip the whole-range drop_withheld.
  • In copy_back_marks, the pages it filters out as withheld are dropped one by one (drop_withheld(page, PAGE)), after the marked pages' copy-backs. Pages from the title-memory bitmap that are held back are already dropped there.
  • Ranges with unmarked writes are dropped whole, as now.

Caveat: this relies on the marks being complete, since a lost mark now leaves the shaders' bytes in the copy. #2269 (marks in the last dword of the bitmap cleared unread) is a prerequisite; here no bits from that dword are handed out any more.

Not tried: longer runs, other scenes, other hardware.

AI-assisted.

**@⁠Machad3x** on GitHub · 2026-11-26 07:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/3089) `drop_withheld(address, len)` in the copy-back drops every withheld declared range whole, so each of its pages is copied from title memory again at the next refresh. Where the range's writes are marked (the `marked` flag of `Step::GpuWrite`), only the pages with a mark hold anything the shaders wrote. **Measured** (cell window, Ryzen 7 5700X, RTX 3080 Ti, a fork with other copy changes on top of `main`): - A temporary counter: every withheld range was a marking one (about 148 MB a frame), and about 59 % of the pages in them had no mark. - One run with the change against one without, medians: title memory copied 397 to 232 MB a frame, copy time 59 to 43 ms, preparing 147 to 129 ms, frame 384 to 377 ms (the frame difference is within the noise). Marked pages went from 62 to 80 ms in the same run; they have varied 61 to 119 ms between runs of one binary here, so I cannot say whether the change adds to them. Image unchanged at that scene, no draws dropped, no device removal, in a 5-minute run. **The change:** - When merging declared ranges, keep `marked` as the AND over the steps naming the range. - For a withheld marked range, skip the whole-range `drop_withheld`. - In `copy_back_marks`, the pages it filters out as withheld are dropped one by one (`drop_withheld(page, PAGE)`), after the marked pages' copy-backs. Pages from the title-memory bitmap that are held back are already dropped there. - Ranges with unmarked writes are dropped whole, as now. **Caveat:** this relies on the marks being complete, since a lost mark now leaves the shaders' bytes in the copy. #2269 (marks in the last dword of the bitmap cleared unread) is a prerequisite; here no bits from that dword are handed out any more. Not tried: longer runs, other scenes, other hardware. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 07:27:09 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 07:57 UTC · original

Picked this up on the fresh upstream/main (63bcca4). Updating only the pages the GPU changed is not safe on this base yet, because of #2269.

Shadow::copy_back_marks (crates/victory-gpu/src/shadow.rs:900) clears the whole last 32-bit word of the written-pages bitmap (bits[words - 1] = 0), so marks for offsets past the bitmap do not leak into a later copy. Marks that legitimately land in bits 0..30 of that word are dropped with it — up to 31 valid marks per pass.

Synthetic WARP test, four 64 KiB pages:

Scenario Pages updated Next GPU read
All writes marked 1 Data matched
Writes without marks 4 Data matched
Mixed writes 4 Data matched
Mark in the last word, on main 0 0x99 instead of 0x20
Same mark with #2269 1 Returned 0x20

Full GPU suite: 247 passed, 1 skipped. Clippy and the repo file checks passed. No in-game measurement repeated.

Conclusion: the working tree keeps the full update. Selective copy stays blocked until the last bitmap word is handled.

Reproduction: branch test/3089-withheld-page-refresh, commit 0f6b078 (on top of 63bcca4), test withheld_view_page_refresh_on_warp, shadow.rs:1565.

@⁠Machad3x

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 07:57 UTC · [original](https://github.com/Marvisak/VIctory/issues/3089#issuecomment-7186022012) Picked this up on the fresh upstream/main (`63bcca4`). **Updating only the pages the GPU changed is not safe on this base yet**, because of #2269. `Shadow::copy_back_marks` (`crates/victory-gpu/src/shadow.rs:900`) clears the whole last 32-bit word of the written-pages bitmap (`bits[words - 1] = 0`), so marks for offsets past the bitmap do not leak into a later copy. Marks that legitimately land in bits 0..30 of that word are dropped with it — up to 31 valid marks per pass. Synthetic WARP test, four 64 KiB pages: | Scenario | Pages updated | Next GPU read | |---|---:|---| | All writes marked | 1 | Data matched | | Writes without marks | 4 | Data matched | | Mixed writes | 4 | Data matched | | Mark in the last word, on main | 0 | `0x99` instead of `0x20` | | Same mark with #2269 | 1 | Returned `0x20` | Full GPU suite: 247 passed, 1 skipped. Clippy and the repo file checks passed. No in-game measurement repeated. Conclusion: the working tree keeps the full update. Selective copy stays blocked until the last bitmap word is handled. Reproduction: branch `test/3089-withheld-page-refresh`, commit `0f6b078` (on top of `63bcca4`), test `withheld_view_page_refresh_on_warp`, `shadow.rs:1565`. @⁠Machad3x
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 08:43 UTC · original

Follow-up on the same base (63bcca4), local only.

The page-selective copy from #3089 has a second blocker besides the last bitmap word (#2269): a declared range that only partly overlaps a withheld range of the same copy is withheld wholesale.

host.rs:1384: every range overlapping a withheld range of the same shadow is marked withheld (b.3 = !held.iter().any(...)), so the bytes of the valid range outside the overlap never go back either.

Reproduction (WARP, one 64 KiB page, one copy, two declared ranges):

  • valid: bytes 0..128, the shader writes 0xaa at offset 0
  • withheld: bytes 64..192 (its list read title memory with no copy), writes 0xbb at offset 64
Byte Expected On 63bcca4
offset 0 (valid, outside the overlap) 0xaa 0x10 (still title memory)
offset 64 (overlap) 0x10 (withheld) 0x10

Branch test/3089-partial-range-overlap, commit f245720, test shadow::tests::withheld_partial_range_overlap_keeps_valid_prefix — it fails on 63bcca4 by design, asserting that the valid prefix goes back.

That is the behaviour #1986 and #1998 change. Until one of them lands, page-selective copying would only move the same wholesale drop from ranges to pages: the measured 397 to 232 MB a frame cannot be taken while valid writes on shared pages are lost.

Also still open: copy_back_marks clears the whole last 32-bit word (bits[words - 1] = 0), dropping up to 31 marks. With the expectation that the tail mark survives, the earlier fixture refreshes 0 pages instead of 1 (0x99 instead of 0x20 at the next GPU read).

@⁠Machad3x

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 08:43 UTC · [original](https://github.com/Marvisak/VIctory/issues/3089#issuecomment-7186946907) Follow-up on the same base (`63bcca4`), local only. The page-selective copy from #3089 has a second blocker besides the last bitmap word (#2269): a declared range that only **partly** overlaps a withheld range of the same copy is withheld wholesale. `host.rs:1384`: every range overlapping a withheld range of the same shadow is marked withheld (`b.3 = !held.iter().any(...)`), so the bytes of the valid range **outside** the overlap never go back either. Reproduction (WARP, one 64 KiB page, one copy, two declared ranges): - valid: bytes 0..128, the shader writes `0xaa` at offset 0 - withheld: bytes 64..192 (its list read title memory with no copy), writes `0xbb` at offset 64 | Byte | Expected | On `63bcca4` | |---|---|---| | offset 0 (valid, outside the overlap) | `0xaa` | `0x10` (still title memory) | | offset 64 (overlap) | `0x10` (withheld) | `0x10` | Branch `test/3089-partial-range-overlap`, commit `f245720`, test `shadow::tests::withheld_partial_range_overlap_keeps_valid_prefix` — it fails on `63bcca4` by design, asserting that the valid prefix goes back. That is the behaviour #1986 and #1998 change. Until one of them lands, page-selective copying would only move the same wholesale drop from ranges to pages: the measured 397 to 232 MB a frame cannot be taken while valid writes on shared pages are lost. Also still open: `copy_back_marks` clears the whole last 32-bit word (`bits[words - 1] = 0`), dropping up to 31 marks. With the expectation that the tail mark survives, the earlier fixture refreshes 0 pages instead of 1 (`0x99` instead of `0x20` at the next GPU read). @⁠Machad3x
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#3089
No description provided.