GPU: the frame line splits a heap sync's slots by outcome #3231

Open
Jackster wants to merge 3 commits from upstream-pr/3233 into main
Jackster commented 2026-11-26 14:03:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T14:03:02Z.


The frame line reports the time a heap sync takes and the slots it looks at, but not what it does with them. On the world's frames a sync looks at ~400,000-600,000 slots and mirrors ~160,000 of them; which of those get a view, which are already current and which name nothing decides whether a change to the sync can help — batching (#3139) only gains where many slots are unchanged — and today it can only be guessed.

This splits the clause. Measured line from a 300 s world run of the retail title on main (63bcca4), diagnostics build:

heap slots the title copied 129.6 ms (590,643 slots); slot mirrors 161,892
(64,340 made (2,695 textures, 9,439 buffer reads, 8,150 buffer writes,
44,056 other), 828 deferred, 74,847 current, 21,877 nulled, 0 empty, 0 past)

HostHeap::mirror counts what it does with a slot, on every path it can take:

  • made — a host view was created. Of those, from a texture view, from a buffer view a shader reads, from a buffer view it writes through, and other (a constant buffer, or a memory view).
  • deferred — a placed texture left for its read mark (later), which creates nothing.
  • current — the record the slot already held, both before and after prepare.
  • nulled — a record that names no view of ours, over a slot that held one.
  • empty, past — a record that names nothing over a slot that held nothing, and a slot past the heap.

The outcomes sum to the calls by construction (made + deferred + current + nulled + empty + past == mirrors), which the two samples above show exactly: 64,340 + 828 + 74,847 + 21,877 = 161,892. That invariant is the property the first version of this change lacked, and it is why the counters are now reported against the mirror calls rather than against the sync's slot count: mirror also runs from descriptor writes, table binding and make_read, so only the call count is a valid denominator.

What it shows

In this run 68% of the views made are "other" — constant buffers and memory views — not textures (already made lazily on their read marks) and not the per-page scan. That is the number to look at before changing the sync.

Cost and behaviour

No runtime change: the counters and the two predicates they use are #[cfg(feature = "diagnostics")], and the enum's length is now asserted by construction (COUNTERS is the exact variant count, so a counter added without its slot fails to compile rather than reading past the array).

Testing

  • cargo clippy -p victory-gpu --all-targets --features diagnostics -- -D warnings
  • cargo build --release -p victory --features diagnostics
  • the world run above; the line prints with each five-second frame report.

No game data is included in this PR.

Written with an AI assistant.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5511433346 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3233). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T14:03:02Z. --- The frame line reports the time a heap sync takes and the slots it looks at, but not what it does with them. On the world's frames a sync looks at ~400,000-600,000 slots and mirrors ~160,000 of them; which of those get a view, which are already current and which name nothing decides whether a change to the sync can help — batching (#3139) only gains where many slots are unchanged — and today it can only be guessed. This splits the clause. Measured line from a 300 s world run of the retail title on `main` (`63bcca4`), diagnostics build: ``` heap slots the title copied 129.6 ms (590,643 slots); slot mirrors 161,892 (64,340 made (2,695 textures, 9,439 buffer reads, 8,150 buffer writes, 44,056 other), 828 deferred, 74,847 current, 21,877 nulled, 0 empty, 0 past) ``` `HostHeap::mirror` counts what it does with a slot, on every path it can take: - **made** — a host view was created. Of those, from a texture view, from a buffer view a shader reads, from a buffer view it writes through, and **other** (a constant buffer, or a memory view). - **deferred** — a placed texture left for its read mark (`later`), which creates nothing. - **current** — the record the slot already held, both before and after `prepare`. - **nulled** — a record that names no view of ours, over a slot that held one. - **empty**, **past** — a record that names nothing over a slot that held nothing, and a slot past the heap. The outcomes sum to the calls by construction (`made + deferred + current + nulled + empty + past == mirrors`), which the two samples above show exactly: 64,340 + 828 + 74,847 + 21,877 = 161,892. That invariant is the property the first version of this change lacked, and it is why the counters are now reported against the mirror calls rather than against the sync's slot count: `mirror` also runs from descriptor writes, table binding and `make_read`, so only the call count is a valid denominator. ### What it shows In this run **68% of the views made are "other"** — constant buffers and memory views — not textures (already made lazily on their read marks) and not the per-page scan. That is the number to look at before changing the sync. ### Cost and behaviour No runtime change: the counters and the two predicates they use are `#[cfg(feature = "diagnostics")]`, and the enum's length is now asserted by construction (`COUNTERS` is the exact variant count, so a counter added without its slot fails to compile rather than reading past the array). ### Testing - `cargo clippy -p victory-gpu --all-targets --features diagnostics -- -D warnings` - `cargo build --release -p victory --features diagnostics` - the world run above; the line prints with each five-second frame report. No game data is included in this PR. Written with an AI assistant.
Dukestar69 commented 2026-11-26 14:07:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:07:22Z.

Review: APPROVED


Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 14/14 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings & --features diagnostics: clean.
  • cargo xtask policy: 191 files ok.

Cleanly splits heap-sync slot counts by outcome in the frame summary line.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6075506962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3233#pullrequestreview-6075506962). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T14:07:22Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 14/14 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` & `--features diagnostics`: clean. - `cargo xtask policy`: 191 files ok. Cleanly splits heap-sync slot counts by outcome in the frame summary line. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Jackster commented 2026-11-26 22:34:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:34:12Z.


Windows 11, 63bcca4 + this PR:

  • cargo test -p victory-gpu --lib: 231 passed / 0 failed / 1 ignored — same counts as unpatched 63bcca4 here.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

Diagnostics-only change (the frame line splits a heap sync's slots by outcome), no test added. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204795329 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3233#issuecomment-7204795329). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:34:12Z. --- Windows 11, `63bcca4` + this PR: - `cargo test -p victory-gpu --lib`: 231 passed / 0 failed / 1 ignored — same counts as unpatched `63bcca4` here. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. Diagnostics-only change (the frame line splits a heap sync's slots by outcome), no test added. Synthetic only. AI-assisted.
fuzeofficlal commented 2026-11-27 01:11:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:11:08Z.

Review: CHANGES_REQUESTED


Two concrete counting bugs in HostHeap::mirror reproduce directly under --features diagnostics and break the stated counter breakdown:

  1. Recursive retry double-counts MirrorCalls, breaking the sum invariant (crates/victory-gpu/src/descriptor/host.rs:724, 815):
    copystat.rs:107-108 documents that the outcome counters sum to MirrorCalls on every path HostHeap::mirror can take. However, MirrorCalls is incremented at entry (:724), and when a title thread overwrites the slot while prepare(&view) runs without the lock, line 815 calls return self.mirror(index, handle, for_draw);, incrementing MirrorCalls again without recording an outcome for the outer call.
    Reproduced live via the WHILE_PREPARING hook: a single heap.mirror(...) call records d_calls = 2 while the sum of all outcome counters (MirrorMade + MirrorDeferred + MirrorCurrent + MirrorNull + MirrorEmpty + MirrorPast) increments by 1. Using a loop for the retry (or an inner helper so MirrorCalls is incremented once per top-level call) keeps the invariant exact.

  2. Non-placed texture UAVs are misclassified as MirrorBufferWrite, and placed buffers fall into MirrorOther (crates/victory-gpu/src/descriptor/host.rs:850-860, 1664-1679):

    • is_texture(view) (:1664-1667) only checks is_placed_texture(view) and View::Shader(r, _) — unlike prepare() (:1623), it does not check View::Unordered(r, _, _) when texture_memory(r).is_some(). As a result, buffer_write(view) (matches!(view, View::Unordered(..)) && !is_texture(view)) returns true for every non-placed texture UAV (RWTexture*), counting texture UAVs as MirrorBufferWrite instead of MirrorTexture. Reproduced live on RTX 5090: mirroring a texture created via create_uav incremented MirrorTexture by 0 and MirrorBufferWrite by 1.
    • Similarly, placed buffer views (View::Placed(false/true, resource, _) with resource[0] == 1) match neither View::Shader(..) nor View::Unordered(..), so both placed buffer SRVs and UAVs fall through into MirrorOther instead of MirrorBufferRead / MirrorBufferWrite.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082188645 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3233#pullrequestreview-6082188645). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T01:11:08Z. **Review:** CHANGES_REQUESTED --- Two concrete counting bugs in `HostHeap::mirror` reproduce directly under `--features diagnostics` and break the stated counter breakdown: 1. **Recursive retry double-counts `MirrorCalls`, breaking the sum invariant (`crates/victory-gpu/src/descriptor/host.rs:724`, `815`)**: `copystat.rs:107-108` documents that the outcome counters sum to `MirrorCalls` on every path `HostHeap::mirror` can take. However, `MirrorCalls` is incremented at entry (`:724`), and when a title thread overwrites the slot while `prepare(&view)` runs without the lock, line `815` calls `return self.mirror(index, handle, for_draw);`, incrementing `MirrorCalls` again without recording an outcome for the outer call. Reproduced live via the `WHILE_PREPARING` hook: a single `heap.mirror(...)` call records `d_calls = 2` while the sum of all outcome counters (`MirrorMade + MirrorDeferred + MirrorCurrent + MirrorNull + MirrorEmpty + MirrorPast`) increments by `1`. Using a `loop` for the retry (or an inner helper so `MirrorCalls` is incremented once per top-level call) keeps the invariant exact. 2. **Non-placed texture UAVs are misclassified as `MirrorBufferWrite`, and placed buffers fall into `MirrorOther` (`crates/victory-gpu/src/descriptor/host.rs:850-860`, `1664-1679`)**: - `is_texture(view)` (`:1664-1667`) only checks `is_placed_texture(view)` and `View::Shader(r, _)` — unlike `prepare()` (`:1623`), it does not check `View::Unordered(r, _, _)` when `texture_memory(r).is_some()`. As a result, `buffer_write(view)` (`matches!(view, View::Unordered(..)) && !is_texture(view)`) returns `true` for every non-placed texture UAV (`RWTexture*`), counting texture UAVs as `MirrorBufferWrite` instead of `MirrorTexture`. Reproduced live on RTX 5090: mirroring a texture created via `create_uav` incremented `MirrorTexture` by `0` and `MirrorBufferWrite` by `1`. - Similarly, placed buffer views (`View::Placed(false/true, resource, _)` with `resource[0] == 1`) match neither `View::Shader(..)` nor `View::Unordered(..)`, so both placed buffer SRVs and UAVs fall through into `MirrorOther` instead of `MirrorBufferRead` / `MirrorBufferWrite`.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3233:upstream-pr/3233'
git switch 'upstream-pr/3233'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3233'
git switch 'upstream-pr/3233'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3233'
git switch 'upstream-pr/3233'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3233'
git switch 'main'
git merge --squash 'upstream-pr/3233'
git switch 'main'
git merge --ff-only 'upstream-pr/3233'
git switch 'main'
git merge 'upstream-pr/3233'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3231
No description provided.