Core Image's own kernel libraries (ci_stdlib, ci_filters, ci_raw: file
type 1, extern functions over one module) were refused as
Container(HashMismatch), so Library::from_metallib, the runtime's
new_library_with_data and the command line ("FALLBACK (input not read)")
refused what Metal reads, in every process that uses Core Image. The
function table, metadata, extended header (HDYN, UUID) and shared module
were all in the shape the reader already takes; only the HASH check
failed.
What the HASH is, measured with libraries written from scratch under
Xcode 27.2's toolchain (metal -fcikernel, metallib -cikernel) on an M3
Max under macOS 27.0.1:
- metallib -cikernel writes one HASH for every function. For some modules
it is the SHA-256 of the module it writes (the two-kernel library the
file-type-1 support was first measured with, kernels with short
loops); for others it is not, e.g. one kernel with a three-iteration
loop of sin and cos. Not the digest of the input .air, of the stream
without the wrapper, of the module without its zero padding or with
other padding, or of the module round-tripped through metal-opt.
metallib is deterministic, and feeding the written module back through
it gives the same module and the same HASH. What it is a digest of is
not known, so it is not interpreted.
- Metal checks no HASH: the new probe
(crates/metal2vulkan-conformance/probes/metallib_function_hashes.m)
loads an executable library and a Core Image kernel library with one
bit of every HASH flipped exactly as written (the kernel's pipeline
stores 1,4,7,10 both ways), and the Core Image library whose HASH is
not its module's digest as well.
So a Core Image kernel library's HASH is read as 32 bytes, once, present
(as before), kept as read in LibraryFunction::raw_tags, and each
function's content key (LibraryFunction::hash, FunctionInfo::air_hash)
is its module's SHA-256, computed once for the shared range. Every other
library's HASH stays verified (HashMismatch), which is stricter than
Metal; docs/API.md says so.
The same probe found that Metal's externFunctionNames order is not the
reverse of the table's in general: a two-kernel library (tint, shift)
answers it, but a four-kernel library written from scratch, libraries of
10 to 200 kernels and Core Image's own answer the same names in an order
that is neither the table's, its reverse, nor sorted. The runtime keeps
the reverse; Library::extern_function_names' doc now says the order
differs from Metal's (doc only).
No cache version moves: a type-1 library whose HASH matched keeps the
same content key, and one whose HASH did not was refused before. No
translation output changes. The runtime-sources pin moves for the doc
comment in the runtime's library.rs (no behaviour): re-pinned to
d000eb23746160492052af4ff3e62bb81ab598b44fc8684b3cf36105d2c67026.
Verified (M3 Max, macOS 27.0.1):
- New test container::tests::a_core_image_library_hash_is_kept_as_read:
a synthetic type-1 library of three extern functions over one module
whose HASH is not the module's SHA-256 parses, each function's hash is
the module's digest and its HASH is kept raw; one whose HASH is the
digest reads the same; a missing, duplicate or 31-byte HASH is still
MissingTag, DuplicateTag, BadTag; the same table as a dynamic library
is HashMismatch. Negative control: with the exception disabled
(every library verified) the test fails (HashMismatch at parse), the
other 18 container tests pass.
- cargo nextest -p metal2vulkan-air --all-features: 482 passed.
- Locally only, nothing of it committed: Core Image's ci_stdlib,
ci_filters, ci_raw (and ci_stdlib_h) now read through the command line
and through the runtime on MoltenVK: each lists only extern functions
(as many as its table holds), function_names empty, every name made by
new_extern_function_with_name and new_function_with_name with
FunctionType::Extern, a sample of six per library refused as a compute
pipeline (Compile, EntryNotFound), as Metal answers; Metal's own answers
for the same files through the probe agree (type executable, no
function names, the same count of extern names, functionType 4 for
each).
- metal2vulkan core_image_libraries and api_signatures (3), the
validation runtime-sources guard after the re-pin: pass. clippy
--workspace --all-targets --all-features -D warnings, plain and under
--cfg m2v_gpu (own target): clean. rustdoc -D warnings for the three
published crates: clean.
- Not run: the other suites, the device tests, golden tables (no
translation output changes), a corpus census. Core Image's link of
these extern functions into ciKernelMain was not reached locally:
rendering ten built-in filters did not go through Metal's image-filter
link calls on this Mac.
(Carried to development from steelbrain/reims-graphics-kext 2d3259adbf.)