Files
metal2vulkan/docs
Anees Iqbal 6c1dff3f09 Translator: under the identity domains, constexpr samplers a lane chooses among beside an argument buffer's texture are one sample through the set-1 sampler array (SEMANTICS 2265)
Some kernels sample a texture their argument buffer holds through a sampler that the run picks
among constexpr samplers with consecutive handles: a program-scope table of samplers read at an
index only the run knows. Under the identity domains, the runtime's, each such sampling was a
switch over the candidates: one arm per candidate, each a NonUniform sample of the heap element
through that candidate's set-1 sampler, and a null arm. RADV wraps each NonUniform sample in its
own waterfall loop (read_first_invocation). The 780M library's heaviest kernel holds 284 such
switches of eight arms, so 2,272 samples and 2,272 driver loops. Its cold create on a 780M peaked
at 7.8 GiB.

select_heap_array now takes the identity domains too. Where every candidate is a constexpr sampler,
their handles are consecutive, the use is not tangled (no fragment implicit level), and every
candidate's sampling is the same but for its sampler, the sampling is one sample. It reads the
set-1 sampler array of its use, NonUniform, at the pushed index (PushField::ConstexprSampler) of
the candidate the handle names. emit::identity_element selects that index among the candidates'
at run time. A handle outside the array still reads zero. finish pushes each candidate's index
and records the use in SamplerPlan::heap_array_identity in place of a binding. Sampling::words
counts each candidate's selection (Source::HeapArray::pushed, 0 outside the identity domains, so
the resident-table domains' weights are unchanged).

Under the identity domains the switch stays where the sampling compares, reads an integer class,
or reads pixel coordinates. Metal's bicubic filter on an argument buffer's texture is refused
before this (bicubic::check). Raw-texel states do not arise here, because the element is read in
its declared class. The resident-table domains keep their form unchanged.

One form for every device: the runtime's floor requires
shaderSampledImageArrayNonUniformIndexing (floor.rs), every committed profile reports it, and a
heap image sampled at all already needs it (texture/slot.rs).

The form is ported from 4b7d9d48ef (steelbrain/privarena-sampler-b, unlanded) and narrowed to the
ruled domain.

SEMANTICS_VERSION 2264 -> 2265. The golden table and the old render descriptor key get
re-blessed at the pin: m3-max-65203 shows "bless due" with exactly 16 cells changed, all
engine/sampler_table.ll sampler_table_held, one per committed profile.

Tests:
- engine_identity's
  chosen_constexpr_samplers_beside_an_argument_buffer_texture_are_one_sample_where_alike
  (replaces ..._is_a_switch_over_them). On every committed profile under the identity domains, a
  kernel's float sample through three chosen constexpr samplers is one sample: one sampled image,
  no switch, one ConstexprSampler pushed per candidate, and L3 passes. The switch stays, with a
  sampled image per candidate, for pixel coordinates (two linear pixel samplers that differ only
  in their border color), an integer texture, a comparison and a fragment's implicit level. The
  resident-table domains take their set-0 array for all but the fragment case, which shows the
  candidates' samplings are alike and only the identity domains' rule keeps the switch.
- argument_sampling's
  every_device_samples_an_argument_buffers_texture_through_a_table_of_constexpr_samplers now reads
  the module the device's translator gives sampler_table_held, asserts 1 sample and 0 switches,
  and prints that, then compares each of the 20 texels with Metal's answer as measured on an
  Apple M3 Max. The fixture has four candidates. The form is the same for any count of two or
  more, so it covers the eight-arm sites, and its texels are M3-measured.

Verified:
- Compile: m3-max-65200 (fmt, signatures, refusal surface, clippy plain / m2v_gpu / m2v_cpu_icd,
  workspace Rustdoc -D warnings), m3-max-65203 (translator suite 3210 passed, lavapipe runtime
  suite 625 passed).
- The execution test passed on llvmpipe (65203), RTX 3090 (65223), RX 7900 XTX (65224) and Iris
  Xe (65225).
- Rows: development 21baf79e79 against this tree, one runner (probe 7faf595d33 / 88125605ae, its
  probe variable choosing the arm), every run cold, validation layer off, arms A B B A in one
  exclusive job per card:
  - ec13339c (780M library, 284 sampler switches) on a Radeon 780M, RADV, job m3-max-65216:
    helper peak 7,772 / 7,773 MiB -> 816 / 819 MiB (89.5% less), driver compile 63.39 / 62.34 s
    -> 21.94 / 21.55 s (65.4% less). Final NIR (RADV_DEBUG=nir): loops 2,571 -> 583,
    read_first_invocation 2,272 -> 568, blocks 34,289 -> 17,533, phis 27,537 -> 13,526.
  - The same kernel on an RTX 3090, job m3-max-65238: 2,447 / 2,443 MiB -> 1,975 / 1,976 MiB
    (19.2% less), 57.72 / 57.70 s -> 51.88 / 51.85 s (10.1% less).
  - d45af8b7 (780M library, 70 sampler switches) on an Iris Xe, ANV, job m3-max-65240:
    4,528 / 4,530 MiB -> 2,622 / 2,622 MiB (42.1% less), 135.54 / 136.55 s -> 67.17 / 67.28 s
    (50.6% less).
- Our module for ec13339c on the 780M's profile (job m3-max-65215): blocks 22,746 -> 19,906,
  explicit-level samples 2,272 -> 284, OpSwitch 625 -> 341, spirv-val clean.
- The ledger over both libraries' 252 rows, plain and partial, both arms (job m3-max-65215): every
  row translates on both arms, none past 20 s, slowest 5.19 s, k12 unchanged at 440.2 MiB, and no
  rise. 20 rows of 10 kernels change, all of the 780M library. The Iris library's kernels sample
  through the program's own switches, one constexpr sampler per case, so no lane chooses a
  sampler there and its modules are byte-equal (probes m3-max-65233, 65241, 65246).
2026-11-21 17:15:11 -08:00
..