Files
reims-vgpu/scripts/wire-oracle
Anees Iqbal 93c10105fd ✨ The wire format gets an oracle, and driving every selector through it found the records this device was losing in silence
Components: `crates/reims-vgpu-wire` (new derivation crate and its capture
harness), `crates/reims-vgpu` (decode, exec, backends, contract), and
`scripts/wire-oracle`. Both pathways; both backends. 91 files.

Squash of 115 commits. Their individual bodies — each carrying its own
derivation, counters and verification record — are reachable from the reflog and
from the `pre-squash-backup-56a87f3` branch until it is deleted.

## What this is

The wire format had no ground truth. Every offset, width and opcode in
`runtime/decode` was an inference from traffic, and nothing in the repository
said what the right ones were, so an audit could only read the decoders against
themselves. `reims-vgpu-wire` replaces that: the guest-side userspace serializer
ships on every macOS install, `-[PGSerializer initWithDevice:objectRefAllocator:]`
takes a protocol rather than a paravirt device, and its allocator needs exactly
one method — so a harness can call a Metal API on a bare-metal Mac and get back
the exact bytes a guest would put on the wire, in milliseconds, with no VM.

Every layout in the crate traces to the Objective-C type encoding or to
perturbation of that live serializer, and every one is pinned by a fixture of
bytes Apple emitted. Nothing is derived from a corpus.

## What it found

The instrument is `tests/wire_fixtures_reach_the_decoders.rs`, which puts every
fixture through this device's decoders and distinguishes three verdicts: a
record that decoded, an opcode with no implementation (a gap, reported), and a
well-formed record refused for its *shape* (a failure, because that is a layout
this project has wrong). Twenty `:bug:` commits came out of it and out of driving
the selectors, and the shapes repeat:

- **Opcodes that were simply the wrong number.** Render residency at `0x86`/`0x87`
  where Apple emits `0x1b`/`0x89`. The sampler binds carrying LOD clamps,
  `0x80`/`0x71`, reached no arm at all, so the sampler stayed unbound.
- **Records refused for a length four bytes off.** Every compute resource
  barrier, refused wholesale.
- **Fields read wider than the serializer writes**, which is the single most
  common defect here and was invisible before the written-bit measurement:
  `copyFromTexture:toBuffer:` read two bytes of the guest's ring as blit options;
  the heap texture's one-bit `useOffset` was loaded as a `u32`; the ICB
  descriptor's `options` is sixteen bits; a colour attachment's `level` was
  loaded thirty-two bits wide with `slice` immediately above it, so a pass
  rendering into array slice 1 reported mip level 65 536 and lost its slice.
- **Caps with no citation.** A 32-entry bind cap dropped a 40-slot texture bind
  whole; the ICB descriptor's flag word carries ten bits and this device carried
  two.
- **A whole guest feature lost.** Tile shaders: nineteen selectors, nine opcodes,
  every one reaching the render catch-all, so a guest running one lost every bind
  and every dispatch.

The catch-all is the trap that hid several of these: an `Ok` from
`render::decode` is not a decode, because `Kind::OtherAccepted` claims anything
inside the accepted window that no arm matched. It is a `NotImplemented` verdict
to the instrument now.

## Capability flags

All sixteen serializer capability pairs default off, which is measured every
capture rather than assumed. Several selector families emit nothing until their
flag is forced, so silence at the default state is a statement about the harness
and not about Apple — and nineteen manifest rows had claimed "Apple emits no
operation" on exactly that evidence. Driving them found real opcodes behind
`TileShaders`, `BlitEncoderSPI`, `CommandBufferJump`, `DynamicAttributeStride`,
`VertexAmplification`, `ImageBlocks`, `ComputePassDescriptorDispatchType` and
`ProtectionOptionsEnvelope`. Two more — `DispatchThreadsIndirect` and
`InsertCompressedTextureReinterpretationFlush` — had been filed as records Apple
*refuses*, where the refusal was this harness's inputs.

Three passes now run every capture: all flags forced, each flag alone (which
attributes a gated selector to the flag that unlocks it), and a byte-level diff
of each pass against the default (which catches a flag that changes what an
existing record *contains* — including one that changes the record's **opcode**,
not its length).

## Consolidation

Roughly 230 wire facts were declared once in each crate, agreeing, with nothing
comparing them; every one now reads the wire crate's declaration, and where a
device offset names a field a wire struct declares it uses `offset_of!` so a
rename fails the build. The x86 GVA page-table format and its multi-level walk
moved to `reims_vgpu_wire::page_table` over a two-method `GuestMemory` seam,
leaving the translation cache and typed refusals in the device. Each tier grew a
roster test comparing the device's opcode set against the manifest.

Separately, `contract/iosurface_pages::build_table_plan`'s two-candidate page
table chase was measured across 223 resolves on two deliberately different driven
arm64 workloads — both fields populated every time, one winning every time — and
deleted as a fallback, with the field test kept as a refusal and a third boot
taken after the deletion to confirm it.

## Verification

Per-change verification lived in the squashed commits. What holds at this tree:

- `cargo test -p reims-vgpu-wire --lib -- --test-threads=1` — 133 passed, 0 failed.
- `cargo clippy -p reims-vgpu-wire --all-targets -- -D warnings` — clean.
- `cargo clippy -p reims-vgpu --all-targets --no-default-features --features
  backend-vulkan,host-window -- -D warnings` — clean. The x86 Linux arm's tests
  had not been compiling and now do; the `backend-metal` clippy arm went from 128
  errors to zero, 31 of them exempted at three module declarations with the
  reason recorded rather than boxed.
- Driven boots on both pathways produced the counters cited in the module docs.

Not verified at squash time: the `backend-metal` test arm still reports six
pre-existing failures, all in `runtime::storage_flush::tests` and all exercising
`flush_render_one`, which is a fail-visible stub without `backend-vulkan` — these
are Vulkan-rail tests compiled unconditionally, not a Metal defect. No VM boot was
taken for this squash itself. Fixtures are Apple-host-only and are not committed;
no third-party bytes are in this tree.
2026-08-04 15:42:33 +03:00
..

wire-oracle

Regenerates ground-truth fixtures for crates/reims-vgpu-wire by driving Apple's own paravirtualized GPU serializer on the host.

scripts/wire-oracle/wire-oracle.sh --fixtures    # wire bytes + expectations
scripts/wire-oracle/wire-oracle.sh --inventory   # every selector Apple ships
scripts/wire-oracle/wire-oracle.sh --all

Output lands in crates/reims-vgpu-wire/fixtures/, which is gitignored — the bytes are Apple's serializer output and are regenerated rather than committed. Override with REIMS_WIRE_FIXTURES_DIR.

Requirements

  • An Apple host. The serializer only exists on macOS. The script refuses elsewhere rather than producing an empty result.
  • Rosetta. AppleParavirtGPUMetal.bundle ships x86_64 and arm64e slices with no plain-arm64 one, and third-party arm64e needs a preview-ABI boot-arg, so the harness builds -arch x86_64 and runs under arch -x86_64. Install with softwareupdate --install-rosetta.

No paravirtualized GPU is needed. PGSerializer takes an id<MTLDevice> and an object-ref allocator, neither of which touches IOKit, so it runs on bare metal. AppleParavirtDevice, which does need an AppleParavirtGPU IOService, is never instantiated.

Consuming the output

REIMS_WIRE_FIXTURES_REQUIRED=1 cargo test -p reims-vgpu-wire -- --test-threads=1

Without that variable a missing fixture set makes the oracle tests skip with a printed reason. With it, a missing set is a failure — set it on any Apple host, where there is no excuse for not having them.

The procedure for turning a new capture into a checked view is in crates/reims-vgpu-wire/AGENTS.md.