Files
metal2vulkan/docs
Anees Iqbal 493178c82e Keep a draw's heap part while what it is made of holds
A replayed page's host step costs about 400 ns per replayed draw per
resident texture (reims: 14 s a frame). Each draw works its heap part
out again for every texture its encoder made resident, though the
residency did not change and the command rebinds only a buffer:
- the handle tables, at every heap member (bind::heap::member_id,
  table_bytes);
- where the heap writes go (heap_elements, member_id again);
- each heap entry's view check (bound_view, view_reading,
  binding_view, Image::view);
- for every member, a neutral image descriptor in each heap image
  array whose class it does not fit (neutral_view, border_texel,
  BicubicTexels::with_border). heap_sets::bind then dropped every one
  of those.

Now:
- The translator splits the heap part from the rest of a draw's
  commands:
  - BindingPlan::instantiate_draw_apart_into writes every command but
    the heap tables;
  - heap_tables_into writes the heap tables alone (handle tables,
    sampler tables, function-table directories);
  - heap_slots names the texture slots they read besides the used
    resources.
  instantiate_draw_into is unchanged. A consumer breaks nowhere: all
  three are additions. docs/API.md says when the tables may be kept.
- The runtime keeps each draw's heap part in its encoder's LiveBind
  (render/heap_part.rs): the heap tables, where the heap writes go
  (Arc<HeapElements>), and the writes past the heap's entries
  (binding::PastHeap). The first draw that checks every entry's view
  lists those writes, and meets no notice the device announces at each
  occurrence (EachWatch) while it does.
- What a part is made of:
  - the plan, by address;
  - the variant's heap capacity;
  - the residency's generation;
  - the argument samplers: the count of sampler-ID slot changes they
    were listed at, else compared state by state;
  - the function tables, compared;
  - what the plan's heap slots bind, compared;
  - the heap placement and the token order.
- Parts are kept for the last 8 plans, so pipeline states drawn in
  turn and the plans a draw's primitive type picks each keep their
  own. They go as the encoder ends.
- Builds with debug assertions check every kept part against one
  worked out whole, and every listing of writes past the heap against
  one listed again.
- bind_into writes no heap image element at all, whatever the plan
  reads: the device's heap set holds each one. One predicate,
  heap_sets::holds_element, now says this for bind_into and
  heap_sets::bind.
- WorkCounts::draw_heap_parts_made counts the parts worked out. The
  replayed-frames lanes print it, and the resident uses' walk counters.

Builds with debug assertions check a kept listing against the writes
listed again in place, allocating nothing.

Measured, release, the replayed textured page
(runtime_lane::replayed_textured, 3 frames, interleaved with the
commit before over two rounds):
- Apple M3 Max, MoltenVK 1.4.2:
  - host_step_ms 10363-10491 a frame before, 1489-1621 after;
  - test time 31.7-32.5 s before, 5.1-5.3 s after;
  - pixels e3306dc52a1c9e86 in both;
  - peak RSS 306-317 MiB in both.
- RTX 5080 Laptop (b5080 entry resident-x-heap-part-004402, kind t):
  - host_step_ms 8800-8931 before, 1309-1359 after;
  - pixels 8e977e2bb4582473 in both.
- After, in both: draw_heap_parts_made 2 a frame (the point draws'
  plan and the other draws'). resident_uses_made stays 10,009,006 a
  frame; the next commit addresses it.

The 5080 binaries came from build-only commits. Their release code
equals this tree's but for the Deferred Send and Sync below this
commit and the lane's extra counter print.

Verified:
- On the M3 (potluck), clippy, plain and --cfg m2v_gpu, all targets,
  of the translator, the runtime and the validation crate; Rustdoc
  -D warnings; scripts/api-docs.
- The translator's heap, binder, instantiate and api tests, 143 of
  143. Among them, graphics tests check that instantiate_draw_apart_into
  plus heap_tables_into equals instantiate_draw_into wherever the
  latter succeeds.
- The runtime's suite, debug, --cfg m2v_gpu, hazard filter: 1626 of
  1627. The one failure, exit_guard's
  only_the_listed_modules_keep_the_device_s_functions, fails on the
  base too: a547d0ce33's command_buffer Parts shares a name with the
  device's Parts.
- The validation lanes over residency, draws and notices, debug,
  --cfg m2v_gpu, hazard filter: 246 of 247. The one failure is
  runtime_lane::frame_costs::a_frame_s_draws_and_pass_ends_allocate_
  within_their_bounds: 21.50 allocations a draw on the M3 against
  DRAW_ALLOCATIONS_DEBUG, 20. Whether that comes from this change or
  from its base is not yet measured. The release bound
  (DRAW_ALLOCATIONS) was not run.
- Negative control: with the kept part never kept, the new test fails
  at draw 1 (heap_parts 1, expected 0).

(cherry picked from commit 12f8301c62ffbbc149c04792007895649b8fe9ed)
2026-11-05 02:08:26 -08:00
..