GPU: read-mark scans stop at the end of the view slots in use #3052

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

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 05:35 UTC · original
0xkn0wh3r3:gpu/read-marks-to-view-heaps → main · +55 −4 · 4 files · 1 commits · open

After every submission, take_reads scans the texture-view read marks of every slot a shader can index: HEAP_VIEWS is 2^21 slots, so that's 64 Ki words in each of two bitmaps, plus the record of slots seen, whatever the title's view heaps actually hold. reads_since, which feeds the eviction stamps, does the same. This makes both scans stop at the end of the view slots in use.

Changes

  • descriptor::view_slots(): the end of the view slots in use. It only grows. It's raised to a shader-visible view heap's size when the heap is created, and to the end of any dynamic slots a host heap hands out. Dynamic slots hold tables made afresh; shaders read texture views there too, and the eviction stamps look them up, so they have to be counted.
  • take_reads and reads_since scan only up to it. A mark past it names no slot that make_read or the eviction stamps act on, and it stays set, so a larger heap created later still finds it.
  • A host copy's pairs aren't counted: they're buffer views, which take no read marks.

Testing

  • read_marks_of_both_bitmaps_are_taken now marks slots of a heap it creates, plus a dynamic slot past them, instead of the last two possible slots. It also checks that a mark past every slot in use isn't taken.
  • victory-gpu's read-mark, eviction and paged-heap tests pass: cross-compiled for Windows in release and run under Wine and CrossOver on macOS. Not run on Windows.
  • Measured with the conformance demo from #3021 (under CrossOver, 720p, 129 submissions a frame, on the fork's demo): take_reads fell from 0.061 to about 0.001 ms a submission, and the copy-back phase from 0.070 to 0.030 ms. The gain in a game depends on the size of its view heap and how many dynamic slots it uses; a heap near 2^21 slots gains little.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 05:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/3052) `0xkn0wh3r3:gpu/read-marks-to-view-heaps` → `main` · +55 −4 · 4 files · 1 commits · open After every submission, `take_reads` scans the texture-view read marks of every slot a shader can index: `HEAP_VIEWS` is 2^21 slots, so that's 64 Ki words in each of two bitmaps, plus the record of slots seen, whatever the title's view heaps actually hold. `reads_since`, which feeds the eviction stamps, does the same. This makes both scans stop at the end of the view slots in use. ## Changes - `descriptor::view_slots()`: the end of the view slots in use. It only grows. It's raised to a shader-visible view heap's size when the heap is created, and to the end of any dynamic slots a host heap hands out. Dynamic slots hold tables made afresh; shaders read texture views there too, and the eviction stamps look them up, so they have to be counted. - `take_reads` and `reads_since` scan only up to it. A mark past it names no slot that `make_read` or the eviction stamps act on, and it stays set, so a larger heap created later still finds it. - A host copy's pairs aren't counted: they're buffer views, which take no read marks. ## Testing - `read_marks_of_both_bitmaps_are_taken` now marks slots of a heap it creates, plus a dynamic slot past them, instead of the last two possible slots. It also checks that a mark past every slot in use isn't taken. - `victory-gpu`'s read-mark, eviction and paged-heap tests pass: cross-compiled for Windows in release and run under Wine and CrossOver on macOS. Not run on Windows. - Measured with the conformance demo from #3021 (under CrossOver, 720p, 129 submissions a frame, on the fork's `demo`): `take_reads` fell from 0.061 to about 0.001 ms a submission, and the copy-back phase from 0.070 to 0.030 ms. The gain in a game depends on the size of its view heap and how many dynamic slots it uses; a heap near 2^21 slots gains little.
After every submission take_reads scanned the texture-view read marks of
every slot a shader can index (HEAP_VIEWS, 2^21: 64 Ki words in each of
two bitmaps, plus the record of slots seen), whatever the title's view
heaps hold; reads_since (eviction stamps) did the same. Both now stop at
the end of the view slots in use (descriptor::view_slots): the most slots
any shader-visible view heap has had, raised to the end of the dynamic
slots a host heap hands out (tables made afresh, whose texture views
shaders read too and the eviction stamps look up). A mark past it names
no slot make_read or the eviction stamps act on, and stays set for a
larger heap to find. A host copy's pairs are buffer views, which take no
read marks.

read_marks_of_both_bitmaps_are_taken marks slots of a heap it makes and a
dynamic slot past them, instead of the last two possible slots, and checks
that a mark past every slot in use is not taken.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:27:36 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 05:45 UTC · original · approved these changes

Reviewed head 4552cb4d line-by-line (CI green):

  • VIEW_SLOTS grows monotonically via fetch_max on shader-visible view heap creation (desc.kind == VIEWS_KIND) and dynamic slot allocation (HostHeap::dynamic), covering every view-heap index that can hold a texture view (HostHeap::pair only allocates buffer views, which do not emit texture read marks).
  • Both shadow::take_reads and shadow::reads_since bound their scans by (descriptor::view_slots().div_ceil(32) as usize).min(words) while forgotten still drains unconditionally.
  • The updated read_marks_of_both_bitmaps_are_taken test covers a mark past view_slots(), a dynamic slot past the title heap's size, and both bitmaps.

Clean, surgical hot-path win.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 05:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/3052#pullrequestreview-6069120511) · **approved these changes** Reviewed head `4552cb4d` line-by-line (CI green): - `VIEW_SLOTS` grows monotonically via `fetch_max` on shader-visible view heap creation (`desc.kind == VIEWS_KIND`) and dynamic slot allocation (`HostHeap::dynamic`), covering every view-heap index that can hold a texture view (`HostHeap::pair` only allocates buffer views, which do not emit texture read marks). - Both `shadow::take_reads` and `shadow::reads_since` bound their scans by `(descriptor::view_slots().div_ceil(32) as usize).min(words)` while `forgotten` still drains unconditionally. - The updated `read_marks_of_both_bitmaps_are_taken` test covers a mark past `view_slots()`, a dynamic slot past the title heap's size, and both bitmaps. Clean, surgical hot-path win.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 06:00 UTC · original · approved these changes

Verified: the truncation is conservative in the right direction — marks past view_slots are neither taken nor cleared, so a heap created later covering those slots still finds them; div_ceil(32).min(words) bounds to actual bitmap size, and view_slots_reach from HostHeap::dynamic covers tables made afresh (the doc's claim that buffer views take no read marks is consistent with the shadow code). The test exercises all three regions: inside the title heap, a dynamic slot past it, and a mark beyond every slot in use left untaken.

**@⁠kotekompotek** on GitHub · 2026-11-26 06:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/3052#pullrequestreview-6069244597) · **approved these changes** Verified: the truncation is conservative in the right direction — marks past `view_slots` are neither taken nor cleared, so a heap created later covering those slots still finds them; `div_ceil(32).min(words)` bounds to actual bitmap size, and `view_slots_reach` from `HostHeap::dynamic` covers tables made afresh (the doc's claim that buffer views take no read marks is consistent with the shadow code). The test exercises all three regions: inside the title heap, a dynamic slot past it, and a mark beyond every slot in use left untaken.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:18 UTC · original

Automated triage for the maintainers.

Verdict: merge candidate. In crates/victory-gpu/src/shadow.rs, take_reads and reads_since now stop at descriptor::view_slots() instead of HEAP_VIEWS. That value only grows. It is raised in descriptor::create_heap for shader-visible CBV/SRV/UAV heaps (VIEWS_KIND) and in HostHeap::dynamic for dynamic slots. I checked that this also covers our own view heap (memory::heap(), a HostHeap with 0 title slots whose slots are all dynamic), and the dynamic slots used by tables made afresh. Marks past the limit stay set rather than being lost, and forgotten slots are still cleared over the whole bitmap. The updated test creates a 64-slot heap and checks three things: a dynamic slot past it is taken, the two title slots are taken, and a mark at HEAP_VIEWS - 1 is not. The test leaves that heap alive, which is harmless.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 06:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3052#issuecomment-7184296681) <!-- victory-triage v1 head=4552cb4d1cdbf58c1805dd10df4bfc5066e19d7e verdict=merge-candidate at=2026-11-26T06:20:10Z --> Automated triage for the maintainers. **Verdict: merge candidate.** In `crates/victory-gpu/src/shadow.rs`, `take_reads` and `reads_since` now stop at `descriptor::view_slots()` instead of `HEAP_VIEWS`. That value only grows. It is raised in `descriptor::create_heap` for shader-visible CBV/SRV/UAV heaps (`VIEWS_KIND`) and in `HostHeap::dynamic` for dynamic slots. I checked that this also covers our own view heap (`memory::heap()`, a `HostHeap` with 0 title slots whose slots are all dynamic), and the dynamic slots used by tables made afresh. Marks past the limit stay set rather than being lost, and forgotten slots are still cleared over the whole bitmap. The updated test creates a 64-slot heap and checks three things: a dynamic slot past it is taken, the two title slots are taken, and a mark at `HEAP_VIEWS - 1` is not. The test leaves that heap alive, which is harmless. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 06:32 UTC · original · approved these changes

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Tracking the highest view slot in use via descriptor::view_slots() (including dynamic overflow slots) and stopping read-mark scans there cleanly avoids scanning unused tail words of the read-mark bitmaps.
  • cargo test -p victory-gpu read_marks_of_both_bitmaps_are_taken -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • cargo test -p victory-gpu shadow::tests -- --test-threads=1 (RTX 5090): 9 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 06:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/3052#pullrequestreview-6069532157) · **approved these changes** Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - Diff review: Tracking the highest view slot in use via `descriptor::view_slots()` (including dynamic overflow slots) and stopping read-mark scans there cleanly avoids scanning unused tail words of the read-mark bitmaps. - `cargo test -p victory-gpu read_marks_of_both_bitmaps_are_taken -- --test-threads=1` (RTX 5090 & WARP): 1 passed, 0 failed on both. - `cargo test -p victory-gpu shadow::tests -- --test-threads=1` (RTX 5090): 9 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠MeMako on GitHub · 2026-11-26 07:50 UTC · original

Verified #3052 (4552cb4) on native Windows 11 (10.0.26200) + AMD Radeon RX 9070 XT (RDNA 4, driver 32.0.32029.2010, Ryzen 9 7950X, 32 GB RAM).

  • cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings: clean; cargo test -p victory-gpu --lib --locked -- --test-threads=1: 274/274 passed (including read_marks_of_both_bitmaps_are_taken).
  • Live title run (local integration stack on main 63bcca4 + #2051 + #2472 + #2918 + #1010 + #2130 with VRAM upload flags off + #3055 + #2914 + #2985 + #2849 + #3035 + #2958, adding #2940 + #3052 + #3061 together): 0 crashes, 0 regressions; local take_reads timer dropped 2.10 → 1.70 ms across the first 26 heavy frames and 2.40 → 1.65 ms (-31%) across the last 8 heavy frames.

Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.

**@⁠MeMako** on GitHub · 2026-11-26 07:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/3052#issuecomment-7185900763) Verified `#3052` (`4552cb4`) on native Windows 11 (`10.0.26200`) + AMD Radeon RX 9070 XT (RDNA 4, driver `32.0.32029.2010`, Ryzen 9 7950X, 32 GB RAM). - `cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings`: clean; `cargo test -p victory-gpu --lib --locked -- --test-threads=1`: **274/274 passed** (including `read_marks_of_both_bitmaps_are_taken`). - Live title run (local integration stack on `main` `63bcca4` + `#2051` + `#2472` + `#2918` + `#1010` + `#2130` with VRAM upload flags off + `#3055` + `#2914` + `#2985` + `#2849` + `#3035` + `#2958`, adding `#2940` + `#3052` + `#3061` together): 0 crashes, 0 regressions; local `take_reads` timer dropped **2.10 → 1.70 ms** across the first 26 heavy frames and **2.40 → 1.65 ms** (**-31%**) across the last 8 heavy frames. *Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.*
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 16:24 UTC · original

Windows 11, 63bcca4 + this PR:

  • cargo test -p victory-gpu: 231 passed / 0 failed / 1 ignored — the same numbers as unpatched 63bcca4 here, with your modified read-mark, eviction and paged-heap tests included.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

Synthetic only. AI-assisted.

**@⁠Jackster** on GitHub · 2026-11-26 16:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3052#issuecomment-7197612736) Windows 11, `63bcca4` + this PR: - `cargo test -p victory-gpu`: 231 passed / 0 failed / 1 ignored — the same numbers as unpatched `63bcca4` here, with your modified read-mark, eviction and paged-heap tests included. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. Synthetic only. AI-assisted.
This pull request can be merged automatically.
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/3052/head:github-bot/gh-3052'
git switch 'github-bot/gh-3052'

Merge

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