Skip to content

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

Open
Jackster wants to merge 3 commits into
Marvisak:mainfrom
Jackster:gpu/mirror-outcomes
Open

Jackster wants to merge 3 commits into
Marvisak:mainfrom
Jackster:gpu/mirror-outcomes

Conversation

@Jackster

@Jackster Jackster commented Nov 26, 2026 •

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown
Author

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants