vkback: speed up slot_reads cache, packed SlotFlags, and write_slot #13
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/vktory6--VKtory!13
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-13"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@olafix52 on GitHub · 2026-11-30 17:45 UTC · original
olafix52:perf/slot-reads-hotpath→main· +217 −114 · 11 files · 2 commits · merged 2026-11-30 20:46 UTCSummary
Optimizes the
live: slot_reads at Executeandlive: slot_reads in listshot paths on the renderer thread.Changes
slotcache.rs:lastpage cache inPaged<T>with a 16-entry direct-mappedrecentcache (accelerating bothslot_cacheandview_addr), inlineinsert/remove, and skip redundant zero-stores inremove.SlotBitswith nibble-packed 4-bitSlotFlags(FLAG_HOOK,FLAG_BUFFER,FLAG_IMAGE,FLAG_RETRY; 1 MiB for2^21slots) soslot_read_at,slot_reset,write_null_slot, andslot_exithit one byte/cache line instead of multiple maps or separate bitsets.slotwrite.rs,lib.rs,bufview.rs,placed.rs,texback.rs,twin.rs,srclife.rs:primary_view_heap(largest shader-visible view heap) and moveslot_indexintoslotwrite.rsusing>> 5.slot_read_at's cold hook path out-of-line (#[cold] slot_read_hook) guarded byFLAG_HOOK.twin_slots,texback,exact,slot_img,shown, andslot_retrywork inslot_reset/write_null_slot/slot_exit/retry_droppedwithSlotFlags, and skiptwin_slotslookup on image SRVs.live/slots.rs,lib.rs:resolved.clone()and the duplicateslot_cache.holdslookup on cache misses, add an early return toforget_slots, and batchpf_count_n("be: write_view (descriptor writes; count only)", written)once perslot_readscall.notes.rs:IssuesfromBTreeMaptoFxMap(sorting keys alphabetically only inwindow_lines).greenfield/tools/policy/oversize.txt: lowergreenfield/vkback/src/lib.rscount from 4378 to 4375.AGENTS.mdrule 24): cuts per-slot bookkeeping cleanly and improves both renderer CPU time and whole-frame throughput.Invalidation & visual check (
AGENTS.mdrules 17, 18)FLAG_IMAGEis set whenever eitherslot_set(index, Some(..))orshow_image(index, Some(..))populates a slot, and cleared only inslot_reset(index)alongsideslot_set(index, None)andshow_image(index, None).write_null_slotkeepsFLAG_IMAGEintact sosupersede_placed/hold_lower/srclifenulling a slot beforeslot_resetdoes not drop image tracking.0..140world s runs passed with zero rendering differences or artifacts.Measurements
experimental-11.0-20261123b).0..140world s, warm shader store,VKTORY_LOCK=1 MEASURE=1,VKB_LAT+greenfield/tools/frec/frames.py 0 140 --no-perf), interleavedA B B A(measured pre-rebaseb112b59vsmain7403bee; rebased cleanly onto8a3cb80with identical code diff):slot_reads@Exec(ms/f)main(7403bee)slot-reads-hotpathslot-reads-hotpathmain(7403bee)slot_reads@Exec10.33 -> 8.54 ms/f (-17.3%), unit cost 59.35 -> 51.10 ns/slot_read (-13.9%) & 177.3 -> 153.6 ns/miss (-13.4%),renderer busy29.85 -> 28.55 ms/f (-1.30 ms/f; last 240: 28.15 -> 26.40 ms/f, -1.75 ms/f), settledlast 240frame 38.25 -> 37.20 ms (-1.05 ms), whole-frame throughput 25.06 -> 25.25 fps, and max spike 285.0 -> 218.6 ms.Verification (rebased
eaaaeabon8a3cb80)cargo test -p vkback --lib -j 6: 145 passed, 0 failed, 3 ignored.cargo test -p vkback --test policy -j 6: 6 passed, 0 failed.cargo xtask policy:asset policy: 533 files ok.Optimize the `live: slot_reads at Execute` and `live: slot_reads in lists` hot paths on the renderer thread. Changes: - `slotcache.rs`: replace 1-entry `last` page cache in `Paged<T>` with a 16-entry direct-mapped `recent` cache (accelerating both `slot_cache` and `view_addr`), inline `insert`/`remove`, skip redundant stores in `remove`, and replace `SlotBits` with packed 4-bit `SlotFlags` (`FLAG_HOOK`, `FLAG_BUFFER`, `FLAG_IMAGE`, `FLAG_RETRY`; 1 MiB for 2^21 slots so `slot_read_at`, `slot_reset`, `write_null_slot`, and `slot_exit` hit one byte/cache line). - `slotwrite.rs`, `lib.rs`, `bufview.rs`, `placed.rs`, `texback.rs`, `twin.rs`, `srclife.rs`: cache `primary_view_heap` (largest view heap) for inline `slot_index`, move `slot_read_at`'s cold hook path out of line, guard `twin_slots`/`texback`/`exact`/`slot_img`/`shown`/`slot_retry` lookups in `slot_reset`/`write_null_slot`/`slot_exit` with `SlotFlags`, and skip `twin_slots` lookup on image SRVs. - `live/slots.rs`, `lib.rs`: remove `resolved.clone()` and redundant second `slot_cache.holds` on misses, fast-path empty `forget_slots`, and batch `pf_count_n("be: write_view (descriptor writes; count only)")` once per `slot_reads` call. - `notes.rs`: switch `Issues` from `BTreeMap` to `FxMap` (sorting keys alphabetically only in `window_lines`). - `oversize.txt`: lower `greenfield/vkback/src/lib.rs` from 4378 to 4375. - Kept (`AGENTS.md` rule 24): reduces per-slot bookkeeping and improves both renderer CPU time and frame throughput cleanly. Measured (prison cell, steady state, 0..140 world s, A/B/B/A vs `main`7403bee, AMD Ryzen 9 7900X + RX 9070 XT RADV Mesa 26.3.1, `VKB_LAT` + `frames.py 0 140 --no-perf`): - `live: slot_reads at Execute`: 10.44 / 10.21 ms/f (A mean 10.33) -> 8.55 / 8.53 ms/f (B mean 8.54, -1.79 ms/f, -17.3%), cleanly separated. - Unit cost: 59.5 / 59.2 -> 51.3 / 50.9 ns/slot_read (-13.9%); 177.3 / 177.3 -> 154.3 / 152.9 ns/miss (-13.4%). - Renderer busy: 29.8 / 29.9 -> 28.5 / 28.6 ms/f (-1.30 ms/f; `last 240`: 28.1 / 28.2 -> 26.5 / 26.3 ms/f, -1.75 ms/f), cleanly separated. - Settled `last 240 frames` frame time: 38.5 / 38.0 -> 37.1 / 37.3 ms (-1.05 ms/f). - Whole-frame throughput & tail: 24.97 / 25.15 (A mean 25.06 fps, mean 39.90 ms, max 267.5 / 302.4 ms) -> 25.26 / 25.23 (B mean 25.25 fps, mean 39.60 ms, max 225.1 / 212.0 ms), cleanly separated. - Verified locally with zero visual artifacts across the full 0..140 s run. Verification: - `cargo test -p vkback --lib -j 6` + `cargo test -p vkback --test policy -j 6` + `cargo xtask policy`: all pass.@vktory6 on GitHub · 2026-11-30 20:46 UTC · original
Thanks, nice work, and the A B B A measurements made it easy to judge. Merging.
I checked the flag gating against every place that creates per-slot state (twin slots, texture write-back, unaligned-view copies, shown images, buffer stride entries, retries): each sets its flag, and a flag left set only costs a cleanup, so nothing can go stale. I pushed one small commit onto your branch: the module comment of
slotcache.rsstill described the single-page cache (AGENTS.md rule 3: comments say what is true now).Since today, changes to Vulkan code need a validation run with no new errors (AGENTS.md rule 30, roadmap "Vulkan validation errors"). I ran it for this PR (house scene, about 50 s in the world): nothing new.
#14 and #15 change the same files, so they need a rebase onto main after this one. Please also add the validation run to them (rule 30 explains how).