Files
reims-vgpu/scripts/feature-matrix
Anees Iqbal 76db0dec46 backend: one binary carries both rails, and the running one is chosen at run time
This is what the branch was for. An Apple host reaches its GPU natively through
Metal and through MoltenVK, and those two paths translate the guest's command
stream by completely different means — so when a frame is wrong, "is this a
metal2vulkan defect or a defect in this device" is the first question, and it
was unanswerable without a rebuild that changes the binary, the caches and the
boot. It is now one binary, one guest stream, and one variable.

`lib.rs` no longer rejects `backend-metal,backend-vulkan`. The remaining rule is
"at least one".

`backend::resolve_rail` is the decision, and it is a **pure total function** —
`(Compiled, metal_available, RailRequest) -> RailChoice` — compiled on every arm
so its table is tested on every arm. Needing two live GPUs present to check a
narrowing rule would have put its tests on no arm at all, which is exactly how
the `not(backend-vulkan)` gates this seam replaced went stale unnoticed.
`Compiled` is an enum, not two bools, because "neither rail" is not a build
`lib.rs` permits and a bool pair would make that state representable in the very
table that decides what executes guest work.

The rules, in order of authority:

* What the build carries. One rail compiled is chosen even with no device
  behind it — there is nothing to fall back to, and refusing here would replace
  "the draw found no Metal device", which names the missing device where it was
  needed, with a failure at device create.
* What the host was measured able to run. Metal's probe is one
  `MTLCreateSystemDefaultDevice`. Vulkan has no equivalent by design: its
  context is created lazily at the first encode so protocol tests need no ICD,
  and asking whether an ICD exists *is* that creation. So Vulkan is the fallback
  rather than the preference, and that asymmetry is stated rather than implied.
* What the operator asked, through the new `REIMS_VGPU_RAIL`. **It narrows and
  never widens.** `rail=metal` on a host with no `MTLDevice` is refused, not
  obeyed — obeying it would put every draw in front of an absent device. Naming
  an uncompiled rail, naming an unavailable one, and misspelling one are three
  refusals and not one, because they are three operator mistakes with three
  different fixes.

`env::choice` is the third parse kind beside `switch` and `count`, with its own
registry so `report_line` prints `rail=metal` rather than
`rail=unrecognized(metal)`. `Rail::name` is the single spelling: the env value,
the boot line, every refusal and `Backend::name` all read it.

`REIMS_VGPU_RAIL` is deliberately *not* the build-time `REIMS_VGPU_BACKEND` that
`scripts/qemu-build` and `vm/` read. Two owners, two lifetimes; one name would
make "I set it and nothing changed" ambiguous between "this build has no such
rail" and "the device declined the ask".

Six tests keyed an expectation or a stimulus on `cfg` where they meant the
running rail, and eight more reached `backend::selected()` where they meant a
specific one. Each now says which: `VulkanBackend`/`MetalBackend` by name where
the test is about a rail, `selected().rail()` where the answer legitimately
differs. The mapper's alias test split in two — the rail hands an alias back
once, the heartbeat unmaps what it is handed — because those are two contracts
with two owners and testing them together only worked while a build had one
rail.

`scripts/feature-matrix` gains a fourth cell. It is not a fourth flavour of the
other three: it is the only cell where "which rail did this build compile" and
"which rail is running" differ, so it is what catches a `cfg` that conflates
them — the class that `emit_object_cache_levels`, `mipmap` and `exec`'s
preflight each fell into.

Verified: feature matrix (all four arms, both workspaces rustfmt-clean), clippy
`-D warnings` on metal / vulkan / both, and the full suite serially on metal
(1332), vulkan (2274), both-default (2353), both with `REIMS_VGPU_RAIL=vulkan`
(2353) and with `=metal` (2353). The forced-rail runs are the ones that matter:
the same binary executes the same 2353 tests through either GPU API.

Not verified: no VM boot. Nothing here changes what a single-rail build does —
`resolve_rail` returns that build's only rail for every input — so the shipping
pathways are unaffected, but the both-rails binary has not been run against a
guest and the QEMU build plumbing does not yet offer it.
2026-08-31 19:09:15 +03:00
..
2026-07-26 15:24:53 +03:00

feature-matrix.sh

Compile every supported reims-vgpu arm and fail if any of them does not build.

Why

The project supports three arms, one per host GPU API actually available:

Arm feature set host
Metal --features backend-metal macOS only
Vulkan / MoltenVK --no-default-features --features backend-vulkan,host-window macOS
Vulkan / native same Linux

vendor/qemu/hw/display/meson.build picks the feature set from REIMS_VGPU_BACKEND, and day-to-day work compiles exactly one arm. The crate spells all(feature = "backend-metal", target_os = "macos") well over a hundred times, so a rename or a cfg change can break an arm nobody builds and stay broken indefinitely — which is what happened to the default build. Running this script is part of "done" for any change that touches cfg-gated code.

There is deliberately no fourth arm. backend-metal off macOS has no Metal to call, so it is a compile_error! in src/lib.rs rather than a host stub that links and cannot draw.

Run

scripts/feature-matrix/feature-matrix.sh              # check + per-arm test counts
scripts/feature-matrix/feature-matrix.sh --no-counts  # compile gate only (faster)
scripts/feature-matrix/feature-matrix.sh --build      # cargo build (link-level)

Output is one line per arm, then the test census:

[feature-matrix] PASS metal / aarch64-apple-darwin                   warnings=108
[feature-matrix] PASS vulkan,host-window / aarch64-apple-darwin      warnings=0
[feature-matrix] PASS vulkan,host-window / x86_64-unknown-linux-gnu  warnings=0

[feature-matrix] tests enumerated per arm:
[feature-matrix]   metal / aarch64-apple-darwin       lib=672   all_targets=685
[feature-matrix]   vulkan,host-window / aarch64…      lib=920   all_targets=992
[feature-matrix]   vulkan,host-window / x86_64…       (cross-compiled — cannot run here)

Which arms a host can build depends on the host. An Apple host builds all three (the Linux one by cross check). A Linux host builds only the native Vulkan arm: Metal is Apple-only and cannot be cross-checked to a host that has no Metal, so it is reported n/a rather than skipped silently.

Notes

  • Warnings do not fail an arm. The count is printed on every run so a jump stays visible. cargo replays nothing for an up-to-date unit, so an arm that was already built reports warnings=cached rather than a false 0.
  • The cross target defaults to x86_64-unknown-linux-gnu. Override with CROSS_TARGET=.... The script fails with the rustup target add command when the target is missing rather than silently skipping the arm.
  • This is a compile gate only. It says nothing about runtime behavior on any arm; a Vulkan change still needs a live boot on the host that owns the pathway.
  • It checks --all-targets, so the test modules are covered too. A bare cargo check can leave arm-specific test code uncompiled while product code still compiles green.
  • Compiling is not testing, which is why the counts are printed. A test that compiles on an arm but is cfg'd out still tests nothing, so a cfg change can empty an arm while every arm stays green. Watch for a dropped count. The gap between the arms (248 lib tests) is the genuinely Vulkan-only surface, not drift.
  • Counting links the test binaries, which is slower than checking; use --no-counts when you only need the compile gate. The cross-compiled arm cannot be counted because its binaries do not run on this host.