Files
metal2vulkan/crates
Anees Iqbal db2bdfbe95 Draw an encoder's last direct draw again: a draw that repeats it with no call between records its Vulkan draw alone
A render encoder keeps its last plain direct draw (render/draw_again.rs): the call, what it
assembled, its draw and in-place index source, what it read of the state that changes with no
call of the encoder (no-copy moves, residency generation, host aliases, the parts and holds its
noting reads), its command buffer and its Vulkan draw command. Every call but the two direct
draws forgets it as it logs itself, refused or not. A draw that matches it records the kept
vkCmdDraw* alone, notes its uses' reads of fresh textures, keeps itself for recording again,
adds its execution record where the device keeps them, and counts itself in encoder-local
counts that reach the device's at the next call, the pass's end or an error
(WorkCounts::draws_as_before, new). Only a draw that recorded one Vulkan draw into its
instance as it stood, through a pipeline made ahead, with no barrier, write, split, shadow,
snapshot, rewrite pass, set 1, root table or push hole, and no notice announced at every
occurrence, is kept.

Exact: the same Vulkan commands and barriers, the same notices, retains and refusals. A draw
again repeats only steps whose answer is provably the kept draw's; the rest are idempotent
(the drawn area, coverage, gathered uses, noted uses, retains); PassStartReads' Written::add now
skips an equal range already held, so a repeated read adds nothing. In builds with debug
assertions the first draw again of a kept draw and every second after it take every step and
assert they announced nothing, recorded no state command, kept an equal draw, retained only the
index buffer again, and left drawn area, coverage, reads, gathered uses, noted uses and the
instance as they were.

Tests: src/tests/draw_again.rs (5 device tests: draws again record the commands, barriers and
pixels the same draws record with a do-nothing call between; indexed draws of the same indices;
other draws take every step (base instance, indirect, a fragment-write draw); a draw after a
no-copy buffer moved takes every step; a notice announced at each occurrence is announced at
every draw). draw_shape_notices and the draw_work lane count draws_as_before beside
draw_shapes_reused. Runtime GPU suite on MoltenVK (M3 Max) passes, the cross-check on.

host_ab encode, release, 10k draws per command buffer, 200 timed, us/draw, three interleaved
rounds: median of round medians / mean of round medians / max of round p90s.

Apple M3 Max, MoltenVK 1.4.2:
  static   1.260 / 1.251 / 1.290  ->  0.042 / 0.042 / 0.047
  offset   1.464 / 1.455 / 1.521  ->  1.493 / 1.480 / 1.545
  bind     1.645 / 1.647 / 1.713  ->  1.693 / 1.687 / 1.742

The offset and bind draws take every step and pay the keep (+29 and +48 ns on the M3). The
RTX 5080 rounds follow in the next commit's message.

(cherry picked from commit 8e6b49b8c371ec2e3c2aa6031a3a09145997cd2e)
2026-11-02 23:03:18 -08:00
..