The rt platform's indirect command buffer tests need commands that a kernel
encodes on the GPU, as a guest's shaders do. icb_encode encodes indexed
triangles, each with its own colour, into a buffer it reaches through the
gpuResourceID in an argument buffer, and icb_vertex and icb_fragment draw them.
icb_encode_wide binds 29 vertex buffers. icb_vertex_23 to icb_vertex_29 read
23 to 29 of them, so a command of theirs binds 24 to 30 slots, across the most
slots rt's push range carries.
The metallib is the Mac's metal compiler's, built from the source beside it.
What the guest sees changes. Before, a render encoder's useResources: (each
form, with or without stages) never reached metal2vulkan-runtime: the platform
noted its textures and nothing else. So a draw whose vertex or fragment
function wrote a texture beyond its slots (through an argument buffer or a
resource ID) after a declared write of a texture with no storage element ran,
and Vulkan dropped the writes Metal makes. Now each resource it names but nil
is rt's use_resource with the declared usage, as the compute encoder's is (the
two share resource_usage and the declaration's notes, compute::declared). rt
keeps the resource until the command buffer retires and records nothing, and
such a draw is rt's Gap::StorageElement: it draws nothing, is counted under
rt-refused-gap, the process's first on a line of stderr, as the compute
encoder's dispatch is, and the process goes on. Declared textures over a buffer
in an image of their own now take rt's copies around the draws after them, and
a usage no Metal value is (0, or a bit past sample's) is Metal's refusal,
counted under rt-refused-metal, as on the compute side.
The texture notes stay: a tiled texture's take at the commit and a read
through the platform's own index are not retention. rt's keep of its own
buffer or texture until the command buffer retires is inside the platform, as
for every bound resource and the compute encoder's declarations; the guest's
objects go when core drops them, as before, so the order of releases the host
sees is unchanged.
Tests: a_draw_after_a_declared_write_of_a_texture_with_no_storage_element_
is_refused_on_vulkan, over a new fragment function, render_argwrite.metal,
whose metallib build.sh's two steps made on a Mac (metal 32023.922), with the
compute encoder's dispatch of tex_write as the oracle of which textures have
no storage element on the device. render_encoders_on_vulkan now counts a usage
of 8 as Metal's refusal.
On rt, newArgumentEncoderWithArguments: and a function's
newArgumentEncoderWithBufferIndex: were an unbuilt piece
(rt-unbuilt-argument-layout). The host answered ARGUMENT_LAYOUT as refused,
the guest's encoder was nil, and a kernel then read through an argument
buffer whose words nobody wrote. On a guest's probe the RX 550 read zeros,
and the 780M faulted on the null pointers and timed out its gfx ring.
What changes for the guest: both calls now answer metal2vulkan's layout.
That is ArgumentBufferLayout::from_descriptors for descriptors, and
Function::argument_buffer_layout for a function's argument buffer, the
layout the function's translation reads. Every argument kind maps to the
core kind of the same name, nested layouts with their holders. Where Metal
makes no encoder, the call still answers nil, now counted under
rt-refused-metal; the translator's own failures are counted under
rt-refused-translation.
The unbuilt piece and its ledger row go. The tests read
tests/shaders/argument_buffers.metallib. sum_args answers 16 bytes,
aligned to 8, pointers at 0 and 8, from the function and from descriptors.
mixed_args lays out a pointer array, a constant, a texture and a nested
argument buffer. On the Vulkan platform, both kernels read back the words
written at those offsets.
sum_args is the shape a guest's probe reads wrong on the rt platform: two
pointers of an argument buffer, which the guest's encoder writes at the
offsets the host's layout gives. mixed_args holds every kind a kernel reads
through an argument buffer on rt (an array of pointers, a constant, a read
texture, a pointer to a nested argument buffer), for the layout of each kind
and the words the guest writes there. The metallib follows from a Mac.
tessellation_states_tessellate_as_metals draws two triangle patches through a
post-tessellation vertex function of our own, tests/shaders/render_tess_bump.
The function pushes the edge between control points 0 and 1 down by a bump of
its position along that edge, so the target shows where the tessellator put
the edge's vertices. Its fragment function colours front faces blue and back
faces red.
The test draws Metal's defaults and one case for each field that changes
pixels: each other partition mode, a maximum factor of 2, counter-clockwise
winding, a per-patch step function, a factor scale of 2, and UInt16 control
point indices through the stage-in variant. Each 32x16 target must equal
Metal's bytes. The answers were measured on the M3 Max under macOS 27.0.1 by
the recorder beside them, which draws the same cases on Metal itself. They
match on RADV (780M and 7900 XTX) and on NVIDIA (RTX 2080).
The factor format and the call stack depths have no pixel case. Half is the
only factor format Metal has. A call stack depth bounds calls through function
pointers, and going past it is undefined, so no defined result shows it. The
decoder's and the recorder's tests hold that both reach the runtime.
compute_state_answers_are_metals_for_every_kernel_here reads every test
metallib. Its recorder, run on the 53 metallibs the test now reads, printed
the file's 201 answers and three more, None for each of the new library's
functions. Those three are added from its output.
draws.10k's guest bench draws with v_small and f_flat, which take their bytes
as a constant float4 & at buffer 0. draw_cost's 10k drew with render_vbuf and
render_fbuf, which read device pointers, so the runtime bound storage buffers
where the VM's draws bind constant ones: on Iris the VM's lane thread spends
7.7% in the runtime's push_set, and draw_cost's 10k never reached it, with
either kind of upload chunk. The 10k and many shapes now run under the
bench's pair, render_small and render_flat, compiled alone here with Xcode's
metal (no other metallib rebuilt).
The runtime path also takes DRAW_COST_RUNTIME_PASS=fresh, which makes each
pass's descriptor anew inside the count as the platform's and the decoder's
paths do: whether the runtime's extra pass work under the platform comes of a
new descriptor each pass or of what the platform's descriptors carry.
The suite drove apple-gfx's C API as QEMU did and recorded what the paravirt
device did; the owner's ruling deletes apple-gfx and everything of it, the
suite with it, so make test, bless and coverage go too.
Its shader fixtures are the platforms', the graphics device's and the guest
bundle's tests too: they move to tests/shaders. guest/bundle's Makefile, an
input of the prebuilt kexts, still names tests/suite/fixtures/shaders, which
stays as a link to tests/shaders until the kexts are next built. A worktree
no longer clones the suite's 257 MiB, so new-worktree.sh adds it plainly.