Files
metal2vulkan/scripts
Anees Iqbal 5dc5ea3315 Translator: a seq_cst atomic operation takes the sequentially consistent fence
A seq_cst atomic operation on memory another thread reaches (an AIR 2.9 air.atomic.* buffer
atomic of order 5, its success order for a compare-exchange; an LLVM atomic load, store,
atomicrmw or cmpxchg of seq_cst) now takes the fence the landed seq_cst fence lowers to: an
acquire-release memory barrier at the operation's scope over the memories its order applies to,
then lower::sync::barrier's add of 1 on the device's fence word at Device scope with the
barrier's semantics. A store, a read-modify-write and a compare-exchange take it after the
operation; a load takes it before. Thread memory's atomics take none (no other invocation
observes their order); texture atomics of any order but relaxed stay refused; relaxed, acquire,
release and acq_rel operations are unchanged.

The fence before a load, derived: the stores' fences alone order every pair of fenced stores and
forbid store buffering and the R and 2+2W shapes, but two readers may still see two independent
seq_cst stores in opposite orders (IRIW), since a reader's two acquire loads synchronize with
nothing between them. MSL's single total order forbids that outcome. With an add on the one
fence word before each load, the two readers' second adds are ordered on that word; the earlier
reader's first load acquired its store, which then happens before the later reader's add and so
its second load, which must see it. A fence after a load would order nothing more.

Each such operation now costs one contended add on the device word: the runtime README's fence
known-gap line says so (every non-explicit atomic of MSL 4.1 is one), read from the fence's
measured rows. msl_4_1_orders_reach_spirv expects the fence's add after a27_wide_and_float's
float add and after each of a27_fragment_atomics' three atomics. reach.tsv drops the SeqCstFence
row, whose refusal no longer exists. The identity harness maps the device's fence word
(with_fence_word: its 4 bytes past the zero range, the rest still unmapped), and
engine_atomics' run_orders binds every kernel with it: the interpreter trapped on the fence's
add in the two contention tests whose kernels hold LLVM seq_cst atomics. SEMANTICS_VERSION
2367 (renumbered at landing; 2363-2366 went to arm 9, the blob move, the 1D bicubic and
the shared slice): a module holding a seq_cst atomic operation changes.

Verified:
- red 389e7cf44e, job m3-max-85066: a_seq_cst_atomic_operation_takes_the_fence fails at "a
  fence's barrier" (no add follows the store); the fence tests and msl_4_1_orders_reach_spirv
  pass. Green there: 4 passed.
- the product suite at the fix without the harness's fence word (85066): 3495 passed, 3 failed,
  24 skipped. The failures were golden_hashes_match_the_table (re-blessed on development) and
  engine_atomics' llvm_ and narrow_atomics_are_exact_under_contention, whose interpreter trapped
  on the unmapped fence word. With it (85271): engine_atomics, engine_seq_cst and
  engine_air_2_9 28 passed.
- validation 1344 passed, 2 skipped; conformance 1053 passed, 0 skipped; doctests EXIT=0
  (85066).
- clippy plain 85270, m2v_gpu 85269 and m2v_cpu_icd 85268 EXIT=0 at this tree. Rustdoc and
  api-docs 85093 EXIT=0 at the fix without the harness change, which adds test code only.
2026-12-03 13:12:57 -08:00
..