The ObjC++ layer Apple's Metal loads as the guest's MTLDevice and that
serialises Metal calls into the reims-graphics wire, built on the existing
serialiser core. This slice lays the foundation the resource, pipeline,
command-buffer and sync slices stack on.
What it adds:
- RgfxMetalPrivate.h: minimal, author-written forward-declarations of the
Apple-private base (IOGPUMetalDevice/_MTLDevice) and the private protocols
(MTLDeviceSPI, MTLCommandQueueSPI, MTLCommandBufferSPI), each with only the
selectors the shell overrides, tagged measured. No Apple header or SPI dump
is copied into the tree.
- RgfxMetalDevice.{h,mm}: RgfxMetalDevice : IOGPUMetalDevice
<MTLDevice, MTLDeviceSPI>. init + wire-handshake stub, device identity, the
family/sample-count/feature queries and the limit getters, answered from
RgfxCaps. The resource-creation methods are left to per-slice categories;
the header documents the +Resources/+Pipelines/+CommandBuffer/+Sync split so
the slices never collide in one .mm.
- RgfxResource.{h,mm} and RgfxBuffer.{h,mm}: the wrapper convention — an
NSObject conforming to a Metal protocol, carrying the guest-picked objId, a
weak device back-pointer and a borrowed serialiser it routes mutating calls
through. RgfxBuffer is the worked example the resource slice replicates.
Being NSObject-based (not the private device base), the wrappers instantiate
and are unit-tested on the Mac.
Checks:
- make bundle compiles all shell .mm for x86_64 (the guest's arch) and
bundle-links the loadable bundle, device class included, with
-undefined dynamic_lookup (the private base/SPI resolve at load in the
guest). It only needs to compile off the guest, not run.
- make test keeps the serialiser check (387, x86_64 under Rosetta) and adds a
native-arch Metal-shell routing check (40): a wrapper's create routes an
RGFX_CMD_BUFFER_CREATE through the serialiser, read back off the ring and
asserted byte for byte — the assertion pattern the later slices copy. The
device shell is excluded from the test binary (it needs the private base at
runtime). The serialiser harness is factored into tests/rgfx_test_ring.hpp,
shared by both checks.
The generated wire header carried only the render op structs: the compute
(ops/compute.rs) and blit (ops/blit.rs) op bodies were built by a local
op_body! macro_rules macro, which cbindgen does not expand, so it never saw
them. Op struct names also collide across the groups in the flat C
namespace (render, compute and blit each define e.g. UpdateFence and
WaitForFence with different fields).
De-macro both files to explicit #[repr(C)] structs matching the render
style, and give each group's op structs a unique prefix: compute's
RgfxOp* become RgfxComputeOp*, blit's RgfxOp* become RgfxBlitOp*. The
element records (RgfxCompute*) and the render op structs (RgfxOp*) are
unchanged. The host decoders and the cbindgen include list follow the new
names; cargo xtask header now emits all 27 compute and 26 blit op structs,
and header --check is green.
Drop the guest encoder's rgfx_compute/rgfx_blit hand-mirror namespaces,
which existed only because the header lacked these types, and point the
encoder, the wire-layout asserts and the serializer tests at the header's
types directly.
RgfxEncoder builds an RGFX_CMD_COMMAND_BUFFER message for a (queue, command
buffer) pair and appends encoder passes and their ops to the op stream, then
fills op_bytes and posts it on the queue's submission ring. One method per op
across all three encoders (render, compute, blit) plus the framing ops writes an
RgfxOpHeader and the op body, 8-byte aligned, mirroring the host decoder
(graphics::decode::{cmdbuf,render,compute,blit}) byte for byte; array-tailed ops
write the head then its element records.
The render-encoder op bodies and the render-pass records are the committed wire
header. The compute-only and blit op bodies and the compute element records are
not emitted into that header (cbindgen reaches only the render-op module), so
they are mirrored here under the rgfx_compute and rgfx_blit namespaces, their
layouts pinned by RgfxWireLayout static_asserts against ops/{compute,blit}.rs.
serializer_tests gains a host-side op-stream consumer that walks a built command
buffer: it checks the begin/end framing, a representative op across each encoder
(including an array-tailed op and a no-arg render op), the fill-texture trailing
bytes, and op_bytes/alignment.
Wire: RgfxRenderPipelineCreate / RgfxComputePipelineCreate (fixed head +
tail for entry-point names, function constants, vertex descriptor and
label; colour attachments inline), their sub-records (RgfxColorAttachmentDesc,
RgfxVertexBufferLayout, RgfxVertexAttribute, RgfxFunctionConstant), and the
RgfxPipelineReflection reply (0x402). Functions are named by library obj_id +
entry-point bytes + function-constant values; size asserts and a round-trip
test guard the layout.
Host: the RENDER/COMPUTE_PIPELINE_CREATE decode arms resolve the functions'
libraries, drive the platform's new_render_pipeline_state /
new_compute_pipeline_state_for_function creators, store the handle, and emit
a reflection reply through a settable reflection sink (mirroring the
completion sink). A non-library reference is a bad reference; a nil function
or a refused descriptor emits a refused reply. Adds the require/get_library
resolver.
Guest: createRenderPipeline / createComputePipeline pack the descriptors into
the wire tail and post them; the serialiser test posts both and reads the
create bytes and the reflection reply back.
The platform's descriptor-value creators carry only the vertex/fragment
functions, colour attachment 0's format and source-over blend, and a label;
the wire carries the whole descriptor for when that value grows, and the
platform exposes no per-argument binding reflection, so the reply carries the
pipeline state's own queries. The cbindgen export and the generated header
are left for the integration pass.
The reims-graphics guest Metal-plugin bundle turns an app's Metal calls into
the device's wire stream. This is its first, validatable slice: the parts that
need no Apple Metal SPI, so they build and are checked on the Mac in user
space.
- RgfxIdSpace: the per-context object-id, resource-id and GPU-address number
lines the guest picks and the host pins (design Decided 6 and 7).
- RgfxCaps: reads the RgfxDeviceInfo caps blob and answers supportsFamily:, the
limits and the feature queries by name, in the host's field order, with a
host gap reported as unsupported, never a spurious yes (Decided 10).
- RgfxRingWriter: the guest producer's reserve-write-publish-doorbell step,
the mirror of the host consumer in reims-graphics/src/ring.rs.
- RgfxSerializer: builds and posts each object-lifecycle message whose wire
struct is fixed in wire.rs (reims_graphics_wire.h) -- queue, heap, buffer,
texture, sampler, depth/stencil, library, event, shared event, fence and
OBJECT_DESTROY -- on the control ring.
- RgfxWireLayout: asserts every wire struct's size at the guest's own compile,
the C-side wall beside wire.rs's.
The command-buffer encoder-op stream, the pipeline creates and
TEXTURE_FROM_IOSURFACE are later increments: their wire schema is not yet
fixed. The Metal device shell that drives this serialiser needs private SPI and
a guest experiment and is not built here.
make -C guest/bundle test builds and runs the serialiser check under Rosetta
(the x86-64 guest ABI); it reads every posted message back and asserts its type,
size and fields. 216 checks pass on x86-64 and arm64.