Commit Graph
2 Commits
Author SHA1 Message Date
Anees Iqbal 4079f17441 Fix the translator review's findings: moved color writes, cubic refusals, bicubic inferences
The translator review's work packet: a moved color write that stores nothing selects no depth or
stencil tests (with the format components it needs generated), a cubic sampler word Metal's bicubic
filter is not measured under is refused when planning, and the extended-range bicubic reading lists
its inferences.

Generate each Vulkan format's color components into its texel block:
vk::FormatBlock gains color_components: the R, G, B and A components the registry's <format>
names for the format (empty for a depth or stencil format), which a color write mask's bits name.
Vulkan writes nothing to a component the mask leaves out or the format lacks, so a plain color
attachment's write stores something exactly where its mask intersects these components; the
binder needs that to decide whether a moved writer stores anything (next part). The data comes
from the pinned registry (Vulkan-Headers vulkan-sdk-1.4.341.0) through
scripts/regen-vk-types: format_blocks reads each format's component names, render_format_blocks
writes them as `components [R G B A]`, and vk_format_blocks! builds the flags in const context.
No hand table.

Verified: the generator's unit tests pass (python3 -m unittest discover -s scripts/regen-vk-types,
9 tests, the FormatBlock expectations updated for the new column); regen_vk_types.py --check
against the pinned registry (SHA-256 verified by the script) reports generated.rs current; the
crate builds and its suites run on homelab-gem10 (with the next parts).

Select no depth or stencil tests for a moved color write that stores nothing:
What: the interlocked storage form's plan counted a moved color's write as a
store under any write mask, and the binder's moved-writer fallback
(RuntimeFact::MovableStorageWrites) ignored the pipeline's write mask. A moved
writer whose mask covers none of its attachment's channels (a depth prepass, a
stencil mask with discard) therefore had depth and stencil tests chosen for a
write that stores nothing: a slower variant, or a refusal under
FragmentTests::Any, a non-D32 depth format or a stencil-only test, and the
runtime then split the pass or ended the shadow. A declared but unused
[[color(n)]] input that is written reached the same path.

Why and how: whether a write stores is decided from the pipeline's state, the
same rule StorageView::stores_nothing applies to the storage view. fetch.rs
counts a write as storing only when its view stores something (the moved
override is gone), and bind/graphics.rs moves a color only when its ordinary
attachment state's write mask meets the format's color components
(vk::FormatBlock::color_components, generated in the previous part). The
MovableStorageWrites and module docs say so, including that a moved plain
writer takes its tests from MovableStorageWrites.

New fixture engine/smw_unread (our MSL, compiled by scripts/regen-air-fixtures
with Metal 32023.921, SDK 27.0) declares a color input it never reads; its
expectations rows and air_input printout are added.

SEMANTICS_VERSION 1694: binding-plan facts and variant choices change for
mask-none moved writers. RUNTIME_VERSION 1190: a run of such a pipeline no
longer selects tests, splits the pass or ends the shadow.

Verified:
- New CPU tests in tests::engine_moved_writers, run before the fix (debug,
  homelab-gem10): a_moved_writer_that_stores_nothing_selects_no_tests failed,
  864 states on 12 profiles: 96 refused (Any), 384 selected tests, 480 asked
  for a variant that states a store before its tests;
  an_unread_color_input_that_stores_nothing_selects_no_tests failed, 72 draws:
  12 stated a store before the tests, 48 asked for a variant, 12 refused (Any).
  Both pass with the fix, and the existing moved-writer test still passes.
- runtime_lane::moved_writers gains a write-mask-none case. Release,
  --cfg m2v_gpu, on AMD Radeon 780M (RADV PHOENIX, Mesa 26.2.4) at the tree
  rebased on fleet/round: all 9 cases keep Metal's answer in the pixel
  interlock with the shadow held; the masked case counted 12 runs.
- Golden hashes are left stale for the round's single bless.
No hot-path loop is added (one write-mask check per color per plan), so no
release translation timing was taken.

Refuse a cubic sampler word Metal's bicubic filter is not measured under when planning:
What: a runtime sampler whose min or mag filter is Cubic, bound at an
extended-range slot, makes the plan name the cubic-sampler variant
(VariantKey::cubic_samplers) for any word. A word with a mip filter,
anisotropy or another reduction (or an unnamed border color, or a
MirrorClampToEdge axis) is one the variant's function always refuses
(lower::sampler::bicubic's cubic_state and check), so the refusal arrived only
after a variant compile, and since the runtime keeps only compiled variants,
every draw under that word translated the variant again.

Why and how: metal::bicubic::runtime_cubic_measured states the words Metal's
bicubic filter is measured under, whatever the function samples: no mip
filter, isotropic, the weighted-average reduction, a border color Metal names,
and address modes the bicubic readings cover. bind::plan::slots::cubic_variant
now refuses any other bound cubic word with
NotImplemented(SamplerBicubicFilter), the class the variant's compile gives,
so graphics and compute plans refuse the draw before any variant.
cubic_state applies the same rule first, so the binder and the lowering
cannot drift; the state it builds is therefore always mip-filter none,
isotropic, weighted average.

SEMANTICS_VERSION 1695: a plan for such a word is now a refusal instead of a
variant request. RUNTIME_VERSION 1191: a draw under such a word is refused at
planning, with no variant compile.

Verified (debug, homelab-gem10):
- New test tests::engine_extended_range::bicubic::
  an_unmeasured_cubic_sampler_is_refused_before_any_variant (mip filter
  Nearest, max anisotropy 4, reduction Minimum, at BGRA10_XR,
  RGB10A8_2P_XR10 and RGBA8Unorm, on every committed profile) failed before
  the fix: the plan named the variant with cubic_samplers {sampler 0: 8}. It
  passes with the fix; a device without sampler anisotropy refuses the
  anisotropic word earlier with SamplerAnisotropy, which the test counts and
  requires to leave other refusals.
- The extended-range bicubic tests and runtime_lane::extended_range_bicubic
  (release, --cfg m2v_gpu, AMD Radeon 780M, RADV PHOENIX, Mesa 26.2.4) pass.
- Golden hashes are left stale for the round's single bless.
No hot-path loop is added (one predicate per bound cubic sampler per plan),
so no release translation timing was taken.

List the inferences in the extended-range formats' bicubic reading:
What: lower/sampler/extended.rs states Metal's bicubic reading on the
extended-range formats as one paragraph, without saying which parts no reading
of those formats covers. bicubic.rs keeps such an "except inferences" list for
its own formats; this adds the same list here: a runtime Cubic sampler with a
non-Cubic other filter; a runtime sampler under another address mode, a border
color or pixel coordinates; a half result outside clamp to edge; explicit
level, bias, gradient and fragment implicit-level samples; and textures of more
than one level. Each is the other formats' reading carried to these formats'
decoded taps.

Why: a reviewer of the extended-range bicubic work asked for the inferences to
be named where a reader of the module meets them. No Metal measurement was
taken for this change.

Verified: documentation only (a module comment); cargo fmt --all is clean and
the translator suite passes at the branch tip (see the branch's last commit).

Versions: SEMANTICS_VERSION 1694 -> 1695 and RUNTIME_VERSION 1200 -> 1202. SEMANTICS_VERSION and
RUNTIME_VERSION move: translated modules and their planned refusals change under unchanged keys.
crates/metal2vulkan-validation/runtime-sources.sha256 holds
a090937f1eca50599031bb56159f5d0ece5b30d133251621f54fc645dc4f167a, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
2026-10-14 20:17:37 +03:00
Anees Iqbal 13b279df1b Squash 11203 commits of translator, runtime, and validation work
Rolls up everything since 43c46ac8 into a single commit. Its tree is
identical to the tree of private master at
b3c77f2d2b20a432be10591a2129547c10b1c24b.

- A Cargo workspace of five crates under crates/: metal2vulkan (the
  translator and the metal2vulkan command), metal2vulkan-runtime (the
  Metal API on Vulkan), metal2vulkan-air (the AIR front end),
  metal2vulkan-validation and metal2vulkan-devtools.
- Dual license: GPL-2.0-or-later OR LGPL-3.0-or-later.
- docs/: API, architecture, fast paths, how-to, Metal coverage,
  refusals, runtime porting and validation guides.

Private-Commit: b3c77f2d2b20a432be10591a2129547c10b1c24b
2026-10-11 20:09:13 +03:00