Files
metal2vulkan/docs
Anees Iqbal 8fcff2117f Put a host step's copy of a chunk's records off where they changed at two steps in a row
On the 5080, a page whose GPU-written records change at every frame (replayed_frames at K=0,
5000 records, CHANGE_EACH) paid about 0.9 ms more a host step than the baseline: base 19.15 ms,
the tip 20.05, means of 3 interleaved runs of 22 warm frames each (b5080 entry icb-p-010218).
The same tip with the host step's keeping cut off (no comparison, no copy) ran 19.31. perf of
the steps thread put the difference in memmove: each step copied every chunk's records, 11 MB,
into the copy the next step compares with, 575 KB a chunk, past the caches (h 501 Mcycles of
memmove against 416 with no keeping). The comparison itself is a few hundred microseconds less
than that and the single read (ff4610cd46) already left one read a record.

A host step that records inline now copies a chunk's records only where it needs them
(kept_commands::StepCopy, held in each chunk's state beside the bytes it last read):

- where the records hold the bytes the last step read, it records from those bytes and copies
  nothing (ReadFrom::Held);
- where they changed since, it copies them again, as before;
- where they changed at the step before too, it reads them in place, record by record, as an
  execution that keeps nothing does (ReadFrom::InPlace, RecordSource::Storage), and copies them
  at one step in eight only (COPY_EVERY), each chunk at a step of its own among the eight, until
  a comparison finds them as the step before read them. A CPU write to the chunk, or a recording
  of it kept or forgotten, starts it over.

So records that change at each step are copied for an eighth of their chunks a step, and a chunk
whose records stop changing is copied again within eight steps and compared at the next. What a
step keeps is unchanged: a chunk is kept only where its records compared equal, byte for byte.
WorkCounts::host_step_chunk_copies_put_off counts the chunks read in place.

Tests: kept_commands::tests::records_that_change_at_each_step_are_copied_at_one_step_in_eight_a_chunk
(the schedule: chunk 0 copied at steps 0, 1, 10, 18, 26, chunk 7 at 0, 1, 3, 11, 19, 27, one
chunk in eight a step from step 3, a held comparison and a write start it over). The kept-steps
lane's changing case asserts each chunk's copy put off from the records' second change on, each
record still read once (indirect_record_bytes_copied), the pixels a fresh page's, and that once
the records hold again a step within ten records apart and keeps every chunk, the next running
them kept. replayed_frames' split prints host_step_chunk_copies_put_off and
indirect_record_bytes_copied.

Verified: nothing yet; the M3 clippy, units and lanes, the negative control (always copy) and the
5080 timings follow.

(cherry picked from commit cd7b2a7e74f2a6aeef4e8080689bb4bab50c0a2f)
2026-11-05 02:08:25 -08:00
..