An execution of an indirect command buffer read, decoded and recorded every
command again at every commit, so an unchanged execution of 16384 draws cost
about 44 ms of commit on the M3 Max and 64 ms on the RTX 5080 laptop, where
Metal's costs 2 ms. A profile of the render case put a third of it in the
records' decode and moves and the rest in recording the draws.
Now an execution of commands the CPU encoded records them in chunks of 256
(kept_commands.rs). A render chunk records into a secondary of its own, begun
for simultaneous use against the instance's compatible pass, through an
encoder over a core of its own whose effects the pass's core takes
(EncoderCore::capture, absorb); a compute chunk records as a segment of its
own, behind a barrier from everything before. Each chunk takes its command
pool, descriptor arena and uploads from a context of its own, lent to the
command buffer while it records and held by every command buffer that runs
it. A chunk whose recording is plain (every draw passes draw_again's keep
test but for being replayed, no step outside its command buffer, nothing its
command buffer alone holds, no released state) is kept on the buffer with
what it was recorded from: the encoder's inputs (RenderKey, ComputeKey: the
inherited state, the pass's compatible pass, shape, extent and sample
positions, the encoder's state and scissors, the resident resources), each
address its commands named and what it resolved to, and the no-copy moves.
A later execution of the chunk under equal inputs, every address resolving
as before, nothing detached and every held object alive, runs the kept
command buffer and notes its uses, keys, holds and executions again
(EncoderCore::run_kept), reading no record. Every CPU write of a command
forgets its chunk under the lock the write takes; the buffer's first GPU
write forgets them all; a recording from records written meanwhile is not
kept. A chunk that is not plain records the rest of the range as before and
is noted, so later executions of it record as before until a write reaches
it. The buffer's per-command state moves to a map, so a buffer of commands
never encoded holds nothing for them.
WorkCounts::indirect_chunks_kept and indirect_commands_kept count the kept
path. docs/FAST-PATHS.md's known gaps list the executions that still record
every command at every commit.
Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under the
validation layer: runtime_lane::kept_commands, 5 tests: unchanged render
commands run 3 kept chunks of 600 commands reading no record, into another
target and twice in one pass; a command written again or reset records its
chunk alone; a blit's reset runs no kept chunk and its commands draw nothing;
another residency or range records again; compute commands the same, with a
command written again and a blit reset. 446 of 448 tests of the 33 lanes
that execute indirect commands pass; the two others
(extended_range_blends half outputs, padded_loads loading pass) are among
the MoltenVK reds the parent already has. clippy -D warnings, plain and
--cfg m2v_gpu, for the runtime and validation crates; the runtime's
kept_commands unit test; the translator's fast_paths, api_signatures and
api_surface tests.
Needs a RUNTIME_VERSION bump and a runtime-sources pin.
(cherry picked from commit 21b9438ec5b8cbf7a1e79c5dfbf84cdad7b43d91)
(cherry picked from commit 922caf3199378b029bafc201429f80b0d43bb048)