Files
metal2vulkan/docs
Anees Iqbal a2ac4433ca SEMANTICS 2094: One input, one answer: a compile past the stage bound is charged once, by either path
A kernel planned again past the stage bound (stage_bound::emit, WidestPin::Kept) ran plan_one a
second time: decode, specialization, lockstep order, lowering inputs and memory analysis, all
charged to the meter again. And Device::compile_function_from_entries charged nothing for an entry
a creation had already specialized (StageEntries handed out an uncharged copy). So one input got
two answers under one budget: compiled alone, a large kernel past the bound on the Iris Xe was
refused LimitExceeded(WorkUnits); compiled from a creation's entries, Unsupported(StageSize).

- stage_bound::emit analyzes the entry once (analyze_one, the part of plan_one before selection,
  kept as Analyzed) and only selects, emits and rolls again. What the dropped plan and module hold
  of the ledger is released, measured from before the selection.
- Meter::measured runs work and states what it charged (Spent: work units, its ledger peak above
  where it began, the bytes it still holds); Meter::spend charges that to another meter, work units
  first, then the peak, keeping the held bytes.
- StageEntries keeps each entry's, decode's and plain answer's Spent and charges it to every ask
  that finds them, so a found entry costs what making it cost. The object spares time, never
  budget: compile_function_from_entries charges what compile_function charges, unit for unit.

For a consumer: Spent, Meter::measured and Meter::spend are new public items of
metal2vulkan-air's budget module (api_signatures.tsv blessed); nothing was removed. A creation
that shares a StageEntries is now charged its found entries' work units against each compile's
budget, as a compile that shares nothing always was.

Tests:
- budget: spent_work_charges_another_meter_as_the_work_did (work, ledger and peak equal to the
  work itself; refused alike one unit under either cap).
- engine_simd_lockstep: a_kernel_past_the_stage_bound_gets_one_answer_through_either_path. The
  pressured kernel under a bound its emulated module passes (planned again, Direct) and under one
  its pinned module passes too (StageSize): alone, from entries that make the entry and from
  entries that find it, the same answer and the same work units W; at exactly W both paths answer
  the bound's way, at W - 1 both are refused WorkUnits; the negative control, a meter also charged
  one more plan of the entry (what the plan made again used to charge), is refused WorkUnits at W.
- library_entries_decode_once, stage_input_siblings: the work units through a shared decode or
  entry now equal the unshared compile's (they asserted fewer before); the decode counts still
  show the sharing.

Also in this commit: crates/metal2vulkan-air/tests/api_surface.txt gains the four rate-map items
b31ce16c85 made public and left out of it (canon::rate_map_data BOUNDARY_MASK, GRANULE_SHIFT,
shader_physical_to_screen_integer, shader_screen_to_physical_integer): the_table_matches_the_source
failed on development without them, the same four lines at d5620581d5 (job m3-max-26042).

Verified, on msi, read from inside each job:
- m3-max-25972 (21ff252584, this change on d5620581d5 before the surface lines): cargo clippy
  --workspace --all-targets --all-features -D warnings exit 0; cargo nextest -p metal2vulkan
  -p metal2vulkan-air -p metal2vulkan-runtime --all-features: 5,645 run, 5,643 passed, 2 failed:
  metal2vulkan-air::api_surface (the four rate-map lines above, failing alike at the base) and
  golden_hashes_match_the_table.
- m3-max-26018: golden_hashes_match_the_table lists 360 changed cells at this change and 360 at
  d5620581d5, the same cells line for line, 180 in each of the nvidia-rtx50-linux and
  nvidia-rtx5080-laptop columns: development's own pending re-bless, none of this change's.
- m3-max-26001: budget::tests::spent_work_charges_another_meter_as_the_work_did passed.

Not landed beside it: the handle-table search as a loop (memory::handles::define_lookup), measured
and dropped. On the RX 7900 XTX (RADV, release, shader cache off), a synthetic kernel of 1,408
heap handle loads: the loop cut cold creation from 224.6 ms to 129.4 ms and the driver's code from
24,512 instructions (118,512 bytes, 28 spilled SGPRs) to 15,441 (78,004 bytes, 11), but a kernel
of 64 handle loads a thread over 2^20 threads took 33 to 38% more GPU time (median of 20 runs,
two rounds: 0.604 and 0.625 ms against 0.829 and 0.832 at 65 resident textures; 0.666 and 0.644
against 0.883 and 0.866 at 4,097). Creation is paid once and cached; the GPU time on every
lookup-heavy dispatch. The unrolled search stays.

Correction to c53ea4164e's message: its "reproduced ... with a synthetic 360k-FMA chain" was wrong.
That chain faults on another ANV defect, through a pipeline and through a shader object alike
(job m3-max-25842), so it is no reproduction of the serialized-index wrap.

SEMANTICS_VERSION 2093 -> 2094: an input near the work budget past the stage bound now gets the
bound's answer where it was refused at the work cap, so cached LimitExceeded(WorkUnits) refusals
must be recomputed. Landed before its own check (m3-max-26047) reported.
2026-11-13 10:36:44 -08:00
..