Files
reims-vgpu/scripts/feature-matrix
Anees Iqbal 2de1663909 metal: the rail presents into the host window, and QEMU's display is no longer the arm64 screen
The Metal rail was the last thing on this device still drawing through QEMU's
Cocoa display. That made the one measurement a `--backend both` binary exists for
— the same guest stream through native Metal and through MoltenVK, with one
variable changed — a comparison across two different display stacks: two
compositors, two present cadences, two input paths, and a frame that differed
between the rails with no way to say which layer changed it.

So the Metal rail gets a presenter of its own. `backend/metal/window.rs` is a
`CAMetalLayer` on the window's own `NSView` and a one-triangle render pass that
fits the published frame into the next drawable; it is reached through the six
`Backend::window_*` methods the previous commit introduced, so the window itself
learns nothing about which rail it is talking to. Both rails now fill one window,
one event loop, one viewport and one input path.

Three decisions worth naming:

* **CPU bytes, always.** This rail retains no texture past the encode that
  produced it, so there is no resident for a present to name and
  `WindowResident` still carries no Metal variant. That is not a step down: the
  Cocoa path read the same frame back through host memory before this window
  existed, so nothing here adds a copy.

* **A render pass, not a blit encoder.** The frame has to be aspect-fitted and
  `MTLBlitCommandEncoder` cannot scale. The viewport is `aspect_fit` — the same
  function the pointer path maps through, so presentation and input stay one
  unit — and the pass's clear colour is the letterbox.

* **A sublayer, not the view's layer.** `setLayer:` makes a view layer-hosted,
  and winit's view is already layer-backed; handing AppKit's own layer over puts
  two owners on one object. Hosting underneath is also what MoltenVK does for a
  `VkSurfaceKHR` here, so the two rails end up presenting through the same kind
  of layer. `addSublayer:` retains, so the presenter removes itself on drop —
  without that, detaching leaves the last frame frozen on a live layer.

`host-window` no longer implies `backend-vulkan`; it names the windowing stack
and nothing else, and each rail's surface half travels with that rail's feature.
The meson `metal` arm builds it, and `vm/boot-arm64.sh` now chooses
`-display none` for the device rather than for one of its rails.

Four raw-Metal calls this needed are added checked, in the module that exists
for exactly that: `newLibraryWithSource:` (metal-0.33 asserts on a nil library,
inside a frame the event loop calls, where a panic aborts the process),
`newFunctionWithName:`, `newRenderPipelineStateWithDescriptor:`. The NSError
text walk the first two need was already written twice and is now written once.

Verified live, arm64/macos-13/reims-vgpu-mmio, `REIMS_VGPU_RAIL=metal` on a
`--backend both` build: `display=reims-host-window backend_rail=metal`, the
window opens at 1920x1080, 144 frames published across the boot with
`dropped=0`, and no `metal_window_*` refusal in the whole run. The guest settles
to `draws=0` at an idle desktop and a QMP pointer move brings it straight back
(`draws=42`) with the window publishing fresh frames — so the quiet is an idle
guest, not a wedged one.

The picture itself is checked by rendering, not by looking: this host's display
was asleep and every screen capture came back black, so the two new tests run the
presenter's real encode into a readable texture. A 2x2 source into a 2x2 target
lands every destination pixel centre on a source texel centre, so orientation is
an exact comparison rather than a tolerance; a 2x1 into a 2x2 proves the fit and
that the bars are the clear. Both would have caught a flipped `uv` or a viewport
that quietly covered the whole target — neither of which any counter reports.

Also: feature matrix green on all five cells, `cargo test` green on metal,
vulkan+host-window and both+host-window (1381 / 2179 / 2260 lib tests).
2026-08-31 20:42:36 +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.