Skip to content

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

Open
0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/read-marks-to-view-heaps
Open

0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/read-marks-to-view-heaps

Conversation

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor

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 Tests: the conformance title's GPU frame, cargo conformance and cargo demo (with a stress scale), on Windows and macOS #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.
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
- `cargo demo` is a synthwave drive into the sunset: a neon car, the
  camera following, spinning shapes along the highway (the stress scale),
  and it reports where each frame's time in VIctory goes, by call and by
  submission phase (victory_gpu::submission_totals).
- Read-mark scans stop at the end of the view slots in use, dynamic slots
  counted (as Marvisak#3052 on main).
- Large graphics blocks get write-watched memory of their own, so their
  host copies refresh only the pages written (as Marvisak#3053 on main).

@fuzeofficlal fuzeofficlal 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.

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.

@kotekompotek kotekompotek 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: 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.

Copy link
Copy Markdown
Owner

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

@Dukestar69 Dukestar69 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.

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).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
… onto upstream; already here, with demo's test fix)
@MeMako

MeMako commented Nov 26, 2026

Copy link
Copy Markdown

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.

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
@Jackster

Copy link
Copy Markdown

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.

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.

7 participants