Files
metal2vulkan/crates
Anees Iqbal dc7b3d5dae Compare a state's used resources listed in token order with a shape's in place
BindState::is_shape made the used resources' shape, a BTreeMap by token, before it compared it
with a shape's, at most once per position_of_shape. The runtime's kept_shape (GraphicsState) asks
it for each draw whose state the live bind and its recent shapes did not hold, a few times a
frame: on the replayed textured page about 20 000 used resources each time, 63 of the steps
thread's 2039 samples in a 6 s window on the M3 at 3a4b3e74e2 (kept_shape -> position_of_shape ->
is_shape and used_shape, the map's eq and free).

A consumer that lists them in token order (used_in_token_order, which the runtime sets) lies a
token's entries together, so is_shape now walks them beside the shape's map, unions each token's
entries as used_shape does (the first entry's class kept) and compares entry by entry, making
nothing. A list in no order still makes the map once.

Verified (M3, potluck): the new test
tests::bind_shape_of::a_state_listed_in_token_order_compares_its_used_resources_in_place passes:
over 13 listings (a token moved, a usage, a stage, a class, a token listed twice four ways, one
less, one more, one only) each ordered state answers has_shape as state.shape() == shape and as
the unordered state does, against every shape, and position_of_shape finds the same, with 0
allocations. Negative control: is_shape making the map for an ordered list fails it
(its "made" assertion, state 0 against shape 0).

Timing, the replayed textured page on the M3 (5001 draws a frame), this commit with the next
(they were measured together), against 3a4b3e74e2, interleaved, two rounds of 3 frames: warm
host_step_ms 33.7-35.3 -> 28.5-30.9, encoding to completion 66.6-70.3 -> 59.6-63.8 ms, peak
resident 309-311 -> 289-291 MB, pixels e3306dc52a1c9e86 at every frame of both. Sampled (macOS
sample, 6 s, steps thread): kept_shape 63 -> 15 samples, used_shape 50 -> 0. The runtime's suite
1656/1656 with --cfg m2v_gpu; the frame-cost lane passes (debug 19.38 allocations a draw, bound
20; release 7.55, bound 9); the residency and draw lanes 247/248, the one other
(indirect_executions::...as_its_dispatch_17) stalled past 180 s once and passed in 4.6 s on a
rerun of its 64 shards (64/64). clippy -D warnings with --cfg m2v_gpu over the translator, the
runtime and validation.

(cherry picked from commit 241946905eb8d5c89113d9b09fce348f4629f38e)
2026-11-05 06:06:00 -08:00
..