Files
metal2vulkan/docs
Anees Iqbal e3f2c95dfe Draw the kept draw again rebound: after buffer, offset or bytes binds, rewrite those slots alone
A render encoder's kept draw (render/draw_again.rs) drawn again after calls that bound other
buffers, offsets or inline bytes at vertex or fragment buffer slots now rebinds only those slots
(render/draw_again/rebound.rs, WorkCounts::draws_rebound), where it took every step of a draw.

- Translator: BindingPlan::rebind_draw_buffers_into(state, slots, commands) writes again, over
  the same draw's commands of a state of the same shape, only what the buffer slots decide: their
  descriptor ranges at their places, the SlotBindOffset, SlotGuestBase and pulled-stride push
  fields that read them, and their vertex buffers' offsets. Ok(false) for a device-address slot,
  an argument or root table, a per-bind stride's vertex binding, a mesh, patch or de-indexed draw,
  or a uniform view a written slot may alias. docs/API.md says so; api_signatures gains it and
  WorkCounts::draws_rebound.
- Runtime: buffer and bytes binds keep the kept draw (log_keeping); the draw compares its tables'
  stamps with the kept draw's. On a difference, the tables' changes since (argument_table::
  changed_since: buffer slots alone, at most 8) are brought into the kept bind state
  (refresh_changed), and the draw goes on only where its shape stays, its variant and plan then
  the bind state's kept settle (LiveBind::settles_kept). It rewrites the commands
  (rebind_draw_buffers_into), set 0's writes and dynamic offsets (binding::rebind_into), push
  bytes and vertex buffers, and its uses whole (command_uses_into), and takes the checks a draw
  takes of them: a pulled attribute's reach, the stages' function tables, the attachments' reads;
  it stops at a pass whose fragments wrote memory, a shadowed texture among its uses, a barrier
  its fragments need after earlier geometry writes, or a detached buffer. It records with set 0
  as any draw finds or writes it (EncoderCore::set_zero_of), its uses noted as any draw notes
  them, through the kept draw's recording parts against what its command buffer holds; a notice
  met at each occurrence forgets it once recorded, as every step does. The kept parts (set-0
  writes that hold no keeper, dynamic states, the rest of its recording) live in the bind state's
  storage (LiveBind::kept), filled at the keep alone: a draw that takes every step pays one
  KeptStorage::keep and nothing per recording.
- Checked in builds with debug assertions: the first rebound draw of a kept draw and every second
  after it take every step instead, which must keep the draw, with the same commands, set-0
  writes, dynamic offsets, push bytes, vertex buffers and uses.

Tests: tests::draw_again::draws_after_buffer_changes_rebind_what_every_step_binds (MoltenVK, M3):
draws after offset and bytes changes rebind (draws_rebound == the draws again but those the check
takes), with the same commands of every kind, state commands, noted uses and pixels as the same
draws each taking every step, every draw at its own offset and color; a sampler bind between them
takes every step. Negative control: the translator not rewriting a changed slot's range fails it
at the cross-check ("other commands"). metal2vulkan's tests::engine_graphics_binder rebind test:
1360 rebinds over stage-io plans equal a full instantiate, and its negative control fails.

host_ab encode, release, 10k draws per command buffer, us/draw, offset case (one
set_vertex_buffer_offset before each draw), measured on this change before its last revision
(which moved the kept parts' fill from every full draw's recording to the keep and dropped three
Arc clones a keep; its own numbers come with the next landing):
  Apple M3 Max, MoltenVK 1.4.2, three interleaved rounds (median / mean of round p50s / max p90):
    lock fix 1.561 / 1.550 / 1.591  ->  0.550 / 0.548 / 0.592
  RTX 5080 Laptop GPU, thread CPU per draw, host_ab threads workload, one thread:
    lock fix 2.006 (shared PSO), 2.001 (own)  ->  0.541, 0.585; on 8 threads 10.3 Mdraws/s (was 2.9)
The unchanged draw (static) holds: 0.044 -> 0.046 on the M3.

(cherry picked from commit 2ee3520ff104094afde523e2eebf7bc8a9a9626d)
(cherry picked from commit d00975ea7da92da4886a29f1ebda6397f64202b1)
2026-11-03 05:51:18 -08:00
..