vkback: compact tape Op, cache active tape, pool TapeData, atomic batch completion #200
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!200
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-200"
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?
@Mhyster on GitHub · 2026-12-02 07:39 UTC · original
Mhyster:opt/vkback-tape-compact-and-pool→main· +243 −58 · 1 files · 1 commits · openWhat
Reduces renderer CPU and allocator overhead in the parallel command-buffer tape (
greenfield/vkback/src/tape.rs):size_of::<Op>()to<= 48bytes (down from ~112–120 bytes):Barrier,Barrier2,CopyBuffer,CopyBufferToImage,CopyImageToBuffer,CopyImage,ResolveImage,ClearColor,ClearDepth,ClearAttachments, multi-bindingBindVertexBuffers) behind 8-byteBox<...>payloads.BindVertexBuffervariant into 32 bytes (falling back to boxedBindVertexBuffersonly iffirst > u16::MAXorstride > u32::MAX) and adds inlineViewport(vk::Viewport)/Scissor(vk::Rect2D)variants so single-viewport and single-scissor commands do zero heap allocation.Store:(id, TapeData)directly inStoreInner::active, avoiding aHashMaphash + lookup on consecutive commands recorded into the same virtual command buffer.TapeDatabuffers across frames (Store::pool):TapeData(opsandbytesVecs) to a bounded shared pool (capped at 64 tapes, dropping oversized buffers> 65,536ops or> 4 MiB), soStore::openreuses pre-warmed capacities instead of re-allocating and growing on every command list.Batchcompletion counter:Batch::left: Mutex<usize>withAtomicUsize+done_mu: Mutex<()>so only the final worker acquiringfetch_sub(1) == 1locks and notifiescv, andBatch::waitreturns immediately with anAcquireload when workers have already finished.Pure host-side CPU optimization; recorded Vulkan commands and submission order are unchanged.
The reference
tape.rsis vkback's own parallel command-buffer recording layer (VKB_REC_THREADS).Evidence
greenfield/vkback/src/tape.rs(op_is_compact_and_tapes_recycle_across_batches): assertssize_of::<Op>() <= 48, verifies active-tape switching across interleavedopen/push/push_bytescalls, verifiesBatch::waitwith theAtomicUsizecounter, and verifies clearedTapeDatabuffers return toStore::pooland are reused byStore::open.tape::tests(tape_keeps_order_and_values,op_without_tape_is_counted,parallel_replay_keeps_submission_order,real_drops_virtual) all pass.cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked(cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)(169 passed, 3 ignored; 6/6 policy tests)cargo clippy --all-targets --locked -- -D warningson root native crates,greenfield,greenfield/wine, andgreenfield/vkback/translate.frames.py) and Vulkan validation run (house scene) could not be run in this session (no live game run performed);cargo xwin clippyruns in GitHub Actions CI.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)@vktory6 on GitHub · 2026-12-02 15:28 UTC · original
Thanks, but these are four topics (rule 31): boxing the rare
Opvariants, the active-tape cache, theTapeDatapool, and the atomic batch counter. Please split them and measure each with A B B A.One thing to check in the tape cache: command buffers alternate (clamp prologue vs body), so a map remove and insert per switch may make it slower, not faster. The atomic counter's wakeup is correct (the notifier takes
done_mu).View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.