vkback + frame: avoid View clones, Vec allocs, and double cache lookups in slot_reads #116
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!116
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-116"
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-12-01 15:54 UTC · original
olafix52:perf/slot-reads-zero-copy→main· +347 −140 · 7 files · 3 commits · merged 2026-12-01 16:09 UTCWhat
Fixes part of
docs/TASKS.mditem "Renderer CPU: index slots" (pure performance / allocation cleanup; preserves exact console slot resolution and nulling semantics).greenfield/frame/src/views.rs:[u64; 2]instead of allocatingVec<u64>inView::resources().ViewRef<'a>,ResolvedRef<'a>, andViewTable::resolve_refsolive: slot_readsborrows table/shape slices directly without cloningViewor copying 16-wordPlacedarrays;ViewTable::resolvedelegates toresolve_ref(slot).to_owned()(single source of truth).greenfield/vkback/src/slotcache.rs:Paged::slot_mutso hits and warm-page cache updates/invalidations complete in a single lookup; drop the redundant null check inPaged::page(u64::MAXsentinel never matchesaddr / PAGE).greenfield/vkback/src/live/slots.rs,greenfield/vkback/src/live.rs:slot_mut,resolve_ref,slot_read_at, andensure_obj(split borrow alongside&self.table) inslot_reads_inner.greenfield/vkback/src/slotwrite.rs,greenfield/vkback/src/bufview.rs,greenfield/vkback/src/lib.rs:VulkanBackend::write_slot_uncountedtakingResolvedRef<'_>, avoiding copies on theViewRef::Placedpath and parsingResourceDesconce instead of three times;write_slot(&SlotView)delegates to it.slot_dbg.get_mutwith!self.slot_dbg.is_empty().AGENTS.mdrule 24): removes per-miss heap allocations and large struct copies cleanly, cuts ~1.2-1.3 ms/frame renderer CPU in steady state, and scales with higher slot-read scenes and once GPU/title bottlenecks drop.The reference
No counterpart:
slot_reads_inner,ViewTable, andSlotCacheare live-stream decoding/caching infrastructure specific tovkback(docs/AGENTS.mdrule 12). All descriptor-resolution semantics,write_slotexit invariants, andResourceDescparsing remain unchanged.Evidence
-j 6):cargo test -p frame -p vkback --lib -j 6:frame12 passed,vkback155 passed (3 ignored), 0 failed (includes newresolve_ref_and_resources_match_owned_across_all_variantsandpaged_slot_mut_updates_existing_without_allocating_new_pagescalling production paths).cargo test -p vkback --test policy -j 6: 6 passed, 0 failed.cargo clippy --workspace --all-targets -j 6 -- -D warnings: 0 warnings.cargo xtask policy: 516 files ok.docs/AGENTS.mdrule 30):VK_LAYER_KHRONOS_validation1.4.363 (VK_KHRONOS_VALIDATION_REPORT_FLAGS=error,VK_KHRONOS_VALIDATION_DUPLICATE_MESSAGE_LIMIT=3) on the available world save (153.1 s startup + 66.0 s in the world):docs/TASKS.md("Vulkan validation errors"); 4 distinct VUIDs observed:VUID-VkBufferCreateInfo-size-06409VUID-VkComputePipelineCreateInfo-layout-01687VUID-VkGraphicsPipelineCreateInfo-layout-01688VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428VKB_LAT+greenfield/tools/frec/frames.py 0 140 --no-perf,maindab263dvsperf/slot-reads-zero-copy49bcc44):main)new)new)main)live: slot_reads at Executelive: slot_reads in listsns/miss)renderer busy(whole run)renderer busy(last 240)vk.log)Whole-frame FPS stays within variance because GPU busy (~27 ms) and title wait absorb the slack; all renderer CPU metrics separate cleanly across every arm, and
loud.txtshows 0 newrule32errors across all runs.Checklist (docs/AGENTS.md)
docs/TASKS.mdnot edited, the fixed item named above (rule 29)unsafeblock has a// SAFETY:comment; no raw pointer around the borrow checker (rule 36)TRANSLATOR_VERSIONbumped if the translator's output changes (rule 27)Remove per-miss heap allocations, large `View` clones, and redundant lookups on the renderer `live: slot_reads` hot path (`docs/TASKS.md`: "Renderer CPU: index slots"): - `greenfield/frame/src/views.rs`: - Return `[u64; 2]` instead of allocating `Vec<u64>` in `View::resources()`. - Add borrowed `ViewRef<'a>`, `ResolvedRef<'a>`, and `ViewTable::resolve_ref` so live slot reads borrow table/shape slices directly without cloning `View` or copying 16-word `Placed` arrays; `ViewTable::resolve` delegates to `resolve_ref(slot).to_owned()` (single source of truth). - `greenfield/vkback/src/slotcache.rs`: - Add `Paged::slot_mut` so hits and warm-page cache updates/invalidations complete in a single page lookup, and drop the redundant null check in `Paged::page` (u64::MAX sentinel never matches `addr / PAGE`). - `greenfield/vkback/src/live/slots.rs`, `live.rs`: - Use `slot_mut`, `resolve_ref`, `slot_read_at`, and `ensure_obj` (clean split borrow alongside `&self.table`) in `slot_reads_inner`. - `greenfield/vkback/src/slotwrite.rs`, `bufview.rs`, `lib.rs`: - Add `VulkanBackend::write_slot_uncounted` taking `ResolvedRef<'_>`, avoiding copies on the `ViewRef::Placed` path and parsing `ResourceDesc` once instead of three times; keep `write_slot(&SlotView)` delegating to it. - Guard `slot_dbg.get_mut` with `!self.slot_dbg.is_empty()`. - Kept (`AGENTS.md` rule 24): eliminates per-miss heap allocation and large struct copies cleanly, saves ~1.2-1.3 ms/f renderer CPU in steady state, and scales with higher slot-read scenes and once GPU/title bottlenecks drop. Measured (reference scene, steady state, 0..140 world s, A/B/B/A vs `main` `dab263d`, 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 (index slots)`: 8.68 / 8.61 ms/f (A mean 8.64) -> 7.80 / 8.02 ms/f (B mean 7.91, -0.73 ms/f, -8.5%), cleanly separated. - `live: slot_reads in lists`: 2.69 / 2.69 ms/f -> 2.59 / 2.64 ms/f (B mean 2.62). - Steady miss cost: 147.2 / 151.9 ns/miss (A mean 149.6) -> 142.0 / 134.3 ns/miss (B mean 138.1, -7.7%), cleanly separated. - Whole-run renderer busy: 27.5 / 27.0 ms/f (A mean 27.25) -> 25.8 / 26.1 ms/f (B mean 25.95, -1.30 ms/f); `last 240` renderer busy: 25.6 / 25.8 ms (25.70) -> 24.8 / 24.5 ms (24.65, -1.05 ms/f). - Renderer thread on CPU: 25.43 / 24.98 ms/f (25.20) -> 23.78 / 24.19 ms/f (23.98, -1.22 ms/f), cleanly separated. - Whole-frame FPS stayed within variance (A: 25.52 / 24.93, mean 25.23 fps, 39.65 ms vs B: 25.30 / 25.19, mean 25.25 fps, 39.60 ms) alongside ~27 ms GPU busy and title wait. Verification: - `cargo test -p frame -p vkback --lib -j 6`: frame 12 passed, vkback 155 passed (3 ignored), 0 failed. - `cargo test -p vkback --test policy -j 6`: 6 passed, 0 failed. - `cargo clippy --workspace --all-targets -j 6 -- -D warnings`: 0 warnings. - `cargo xtask policy`: 516 files ok. - Vulkan validation run (`VK_LAYER_KHRONOS_validation` 1.4.363, 153.1 s startup + 66.0 s in the world): 4 distinct VUIDs (`VUID-VkBufferCreateInfo-size-06409`, `VUID-VkComputePipelineCreateInfo-layout-01687`, `VUID-VkGraphicsPipelineCreateInfo-layout-01688`, `VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428`), 0 unlisted VUIDs, 0 new loud (`rule32`) errors across all runs.@vktory6 on GitHub · 2026-12-01 16:09 UTC · original
Merged as
28ccd9f, thanks! Clean change, and the A/B/B/A table made it easy to judge.I pushed one small commit first (
90f3651): when a slot has to be tried again, the cache entry is now removed (Paged::remove) instead of set to zeros throughslot_mut. For addresses off the 16-byte grid, zeros would later count as a hit for empty words. That never happens in practice, but now it behaves exactly as before. The validation run on the merged tree showed no new VUIDs.