Files
metal2vulkan/CONTRIBUTING.md
T
Anees Iqbal 61a2efc7d3 Fix the GPU test failures seen on the 3090, 5080, XTX, 780M and M3
What and why, per failure (all release, --cfg m2v_gpu):

AMD RADV, Ubuntu Mesa 26.0.8 (RX 7900 XTX, Radeon 780M):
- generated_executions faulted the GPU (amdgpu gfxhub page fault, ring
  reset): RADV before 26.2 skips re-emitting a compute pipeline it thinks
  is bound, so the second execution's implicit preprocess ran our kernel.
  New RuntimeDriverDefect::ImplicitPreprocessAfterExecutionSet (RADV at
  every identity but the measured clean 780M at 26.2.4): the runtime
  preprocesses every execution of a range explicitly, then a barrier, then
  runs them preprocessed. RUNTIME_VERSION 1183.
- The validation executor's generated-commands replay had the same fault;
  it now preprocesses apart on the same defect (runtime's
  generated_commands::preprocess_apart, now public).
- float_denormals under fast math: the test checked a / b, smoothstep and
  (a / b) * c bit for bit, but without VK_KHR_shader_fma (26.0.8) the fast
  reciprocal is the device's OpFDiv(1, y), within 2.5 ulp. Those words are
  now checked at Metal's edges there, in full elsewhere.

NVIDIA 615.71.09 (RTX 3090, RTX 5080 Laptop):
- render_commands_and_render_states_run_as_the_executor_compiles_them: the
  executor used Vulkan device addresses as Metal addresses, and NVIDIA's lie
  below 2^32, where a record's address names no buffer. An addressed
  allocation's guest address is now its device address read signed (RADV's
  are sign-extended) plus 2^47 + 2^32, one translation for every allocation.
- the_runtime_probe_measures_the_test_device_consistently: two driver
  answers Vulkan does not allow (3090: a buffer read after a linear-image
  copy over the same memory in one submission reads stale bytes; both: an
  explicit linear pitch the driver does not lay out is moved, not refused)
  are listed with their evidence in the test; the runtime records neither.
- exits (5 tests): vkDestroyDevice takes ~55 ms alone and up to 2 s beside
  other processes' GPU work on the 3090, so the exit-timing tests run alone
  (.config/nextest.toml); the 1.5 s limit is unchanged.
- pipeline_records (5080): the test assumed the driver finds a pipeline only
  in byte-identical records, but NVIDIA's bytes vary per compile and the two
  formats share entry keys. It now copies a compute pipeline's record over
  the render state's records, which no driver can hit.
- compile_worker (5080, under load): a worker faster than the 1 ms sampler
  left no peak RSS. Each worker now reports its own peak (VmHWM on Linux,
  ru_maxrss on macOS) and the parent takes the larger.
- tests::completion (both, under load): slow rounds were the GPU starting
  late behind another process's ~200 ms busy kernel, or NVIDIA's
  vkQueueSubmit returning up to 64 ms late; the completion was seen within
  1 ms of the moment it could be. A command buffer is now judged from the
  later of its GPU end and its submission's return where the device
  calibrates timestamps (from the commit elsewhere, as before).
- first_use::new_resources_wait_for_no_gpu_work (both, under load): the
  busy kernel's rate came from one wall-clock run, which collapsed under
  load (3 of 28 calibrations), so the busy work lasted milliseconds. The
  rate is now the fastest of every run at every size by GPU time, for all
  four lanes that share it (gpu_times::read_kinds predicts the notice a GPU
  time read emits, for the neutrals test).

Apple M3 Max, MoltenVK 1.4.1:
- heap_textures allows the shadowed-texture route for depth on drivers that
  lay heap depth textures apart.
- The argument-buffer intersection-table test states Metal's own metadata.
- The indirect lane classifies the deferred pipeline-making failure as
  compile-failed alike and keeps only the failed pipeline's error; Apple's
  33-bit closed-form compiler crash is a known gap in docs/FAST-PATHS.md.

Docs: CONTRIBUTING.md and docs/VALIDATION.md say the golden tables and the
compile census are re-blessed on development.

ENGINE_EXECUTOR_ABI is vulkan-engine-v181 (the RADV replay and the Metal
addresses change what the executor submits): every recorded candidate row
and the authored compile census go stale and need re-recording
(scripts/rerecord-venue per venue, rerecord-commit, corpus-status --c3,
corpus-triage --audit authored-compile --bless).

Still open: M3 frees_in_flight, XTX bfloat clears, 780M half NaN blur and
the 5080's one 2 s rebind_bytes_no_copy did not reproduce; the wall-clock
busy calibrations of framebuffer_fetch/storage_forms.rs and queue_storms
remain.

Verified:
- um780 full suites at the AMD fixes (before the executor and NVIDIA
  commits): XTX 3535/3535, 780M 3535/3535, no amdgpu kernel lines.
- Each fix's focused tests before and after on its GPUs (in the agents'
  commits: e.g. generated/indirect 178/178 on XTX and 780M at 26.0.8 and
  26.2.4; candidate 229/229 on 3090, 780M and Iris Xe; the worker peak 0
  of 1440 under 24-way load on the 5080).
- The combined tip: fmt, clippy (with and without --cfg m2v_gpu) and
  rustdoc on ms01; clippy of the validation crate on macOS; a focused run
  on the 3090 was stopped at 333 of 334 passed, none failed. No full suite
  ran on the combined tip.
- The completion and first_use fixes: 3090 load set 1 of 4 runs failed
  before, 4 of 4 passed after (completion) and 12 runs with no first_use
  failure (84 calibrations, 10.19M-11.24M loads); 5080 6 of 6 and 12 of
  12. fmt and clippy (no cfg, m2v_gpu, m2v_cpu_icd) on ms01.
2026-10-13 01:15:18 +03:00

7.9 KiB

Contributing

How to build, test and change metal2vulkan. AGENTS.md holds the project's rules; they bind people too.

Prerequisites

  • Rust stable, at least the rust-version in the crates' manifests (1.98).

  • cargo-nextest: cargo install cargo-nextest --locked.

  • The external tools the tests and validation use (the libraries run none):

    • llvm-as (LLVM 21 or newer) for the .ll fixtures, and llvm-dis for validation's harvest and fixture tooling;
    • spirv-val and spirv-as from SPIRV-Tools;
    • xcrun metal-as on macOS, for the .air.ll fixtures (tests that need it skip elsewhere);
    • spirv-cross, for the checks of the MSL MoltenVK would write. Without it they print SKIPPED; METAL2VULKAN_TEST_REQUIRE_SPIRV_CROSS=1 makes its absence a failure.

    Each is found on PATH or through METAL2VULKAN_<TOOL> (METAL2VULKAN_LLVM_AS, METAL2VULKAN_SPIRV_VAL, ...). With Homebrew on macOS, LLVM is keg-only: PATH=/opt/homebrew/opt/llvm/bin:$PATH.

  • A Vulkan driver or a Mac with Metal only for the device tests and authored-case runs (docs/VALIDATION.md).

Layout

.
├── crates/
│   ├── metal2vulkan/             # the translator library and the CLI (feature `cli`)
│   │   ├── src/                  #   src/tests/: tests that reach internal items
│   │   ├── tests/                #   integration tests through the public API, golden tables
│   │   └── examples/             #   api_preview.rs, which docs/API.md quotes
│   ├── metal2vulkan-air/         # the AIR front end
│   ├── metal2vulkan-runtime/     # the Metal API on Vulkan (README, examples)
│   ├── metal2vulkan-validation/  # unpublished: cases, executors, corpus tools
│   │   ├── fixtures/public/      #   our own synthetic fixtures (.ll, .air.ll, .metal, .spvasm)
│   │   ├── profiles/             #   committed Khronos device profiles
│   │   └── corpus/               #   authored cases and observations (local/ is private, ignored)
│   └── metal2vulkan-devtools/    # unpublished: tool runner, fixture assemblers
├── docs/                         # guides and generated references
├── scripts/                      # developer utilities and generators
├── Cargo.toml                    # the virtual workspace
├── LICENSE                       # the notice: GPL-2.0-or-later OR LGPL-3.0-or-later
└── LICENSE-*                     # the texts it names: GPL v2, LGPL v3, and GPL v3

The loop

cargo fmt --all
cargo clippy --workspace --all-targets --all-features -- -D warnings
RUSTDOCFLAGS='-D warnings' cargo doc --workspace --all-features --no-deps
scripts/api-docs   # the translator's API reference; fails on a link to a hidden item
cargo nextest run -p metal2vulkan -p metal2vulkan-air -p metal2vulkan-runtime -p metal2vulkan-devtools --all-features
cargo nextest run -p metal2vulkan-validation --all-features
cargo test --workspace --all-features --doc

None of these opens a device. Device tests compile only under --cfg m2v_gpu or --cfg m2v_cpu_icd (docs/VALIDATION.md).

To build the command:

cargo build --release -p metal2vulkan --features cli

Where tests go

  • A test that names an internal item is a unit test of its crate: under src/tests/ (or its module's own tests), naming items through crate::. Run one file with cargo nextest run -p metal2vulkan --all-features --lib -E 'test(/^tests::<file>::/)'.
  • crates/metal2vulkan/tests/ holds integration tests through the public API only.
  • crates/metal2vulkan/tests/api_surface.rs pins every public name of the translator. A new public item gets its row there.
  • Fixtures are synthetic and ours, under crates/metal2vulkan-validation/fixtures/public/. A new fixture lands with its rows in crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv (in inventory order) and its golden printout under tests/air_input/, blessed with cargo test -p metal2vulkan --all-features --lib tests::air_input -- --ignored (on macOS, for the .air.ll fixtures).
  • The manifests set autobins = false: a new binary needs its own [[bin]] table.

Golden output hashes and SEMANTICS_VERSION

src/tests/golden_hashes.rs pins a hash of the final SPIR-V (or the refusal class) of every public fixture entry point on every committed profile, in crates/metal2vulkan/tests/golden_hashes.tsv. cache::SEMANTICS_VERSION is part of every cache key, so a change that moves a cell while its fixture and profile are unchanged must bump SEMANTICS_VERSION (crates/metal2vulkan/src/cache/mod.rs) in the same change. New, removed or edited fixtures and profiles need only the bless. The table records cells only, no version: a SEMANTICS_VERSION bump alone leaves it unchanged, and the bless on development refuses a cell that moved under an unchanged fixture and profile when SEMANTICS_VERSION is still its value at the table's last bless.

The table is re-blessed on development after merges, so a change need not carry its own bless. To bless by hand (on macOS, which has xcrun metal-as):

PATH=/opt/homebrew/opt/llvm/bin:$PATH cargo nextest run -p metal2vulkan --all-features \
  --run-ignored ignored-only -E 'test(bless_golden_hashes)'

Never merge the table by hand: after a merge take development's table and bless again. The other versions move the same way when their behavior changes: ARTIFACT_FORMAT_VERSION (the artifact encoding) and RUNTIME_VERSION (what the runtime does with an unchanged artifact).

Generated docs

Edit the source, then regenerate:

Doc Generator Source
docs/REFUSALS.md python3 scripts/refusal-surface/refusal_surface.py (--check to verify) the code's refusal types; reach.tsv beside the script
docs/METAL-COVERAGE.md python3 scripts/metal-coverage/coverage.py (--check to verify) scripts/metal-coverage/coverage.tsv
crates/metal2vulkan/src/spv.rs, crates/metal2vulkan/src/spirv_binary/table.rs scripts/regen-spirv-grammar/regen-spirv-grammar.sh Khronos SPIRV-Headers' grammar JSON, and items.txt beside the script
crates/metal2vulkan-validation/profiles/*.json scripts/regen-device-profiles/ gpuinfo reports and local captures

Three docs are checked by tests: docs/FAST-PATHS.md must name every DevicePolicy accuracy choice and the notes it records (tests::fast_paths); docs/API.md must list every degrade code with its category and quote examples/api_preview.rs verbatim in its rust blocks; and docs/METAL-COVERAGE.md must carry the coverage table's totals.

Changes

  • Follow AGENTS.md: structure over names, honest refusals, fast defaults with exact switches (and their row in docs/FAST-PATHS.md), tests for every fixed bug class.
  • One concern per commit when practical; run cargo fmt --all first.
  • Update the docs a consumer reads when what they describe changes: docs/API.md and examples/api_preview.rs for the translator's API, the runtime's README and rustdoc for the runtime, docs/HOWTO.md for integration, docs/ARCHITECTURE.md for the translator's stages, README.md for the command line.
  • CHANGELOG.md lists releases in a few lines each; add to the top, unreleased version.

License

metal2vulkan is dual-licensed, GPL-2.0-or-later OR LGPL-3.0-or-later, at the recipient's choice (LICENSE). Contributions are accepted under the same dual license: a change you submit can be redistributed and modified under either.

The license files sit at the root and, because cargo packages each crate from its own directory, as copies in every published crate (crates/metal2vulkan, crates/metal2vulkan-air and crates/metal2vulkan-runtime). Change them at the root and copy them over; a validation test (published_crates) holds every copy equal to the root's file and the notice's SPDX line equal to the manifests' license.