Component: conformance; x86 macOS guest on the Linux Vulkan PCI pathway, rail macos-15.
Add a 290-case Metal battery, native Apple M4 oracle, split driver and translation ownership inventories, focused modes, boot manifests, artifact hashing, typed failure scoring, and catastrophic-run gates. This is test-only and changes no device behavior.
The API invariant is monotonic, oracle-backed compatibility: native results establish each Metal relation, while guest failures remain explicit debt owned by either translation or the device. Missing, duplicate, unexplained, and uncovered results fail the scorer.
Verification:
- Apple M4, macOS 15.6.1 build 24G90: full native oracle 290/290 PASS, zero skips.
- verdict unit tests: 5/5 PASS.
- run-native.sh and run-guest.sh: bash syntax clean.
- baseline file matches the final full native result byte-for-byte.
- current focused VM runs: integer clear and topology repeated clean; RGBA32Float clean with guest import on and off; indexed draw repeated with three classified driver failures and zero unexplained results.
- focused candidate boots loaded QEMU SHA-256 0b4ed961deaac18886b4e1ca8eb1db2a34c7e7f06e46b53652167e6dba61951d and static library SHA-256 512fa87458223053e3ca1a58e49501d28705f26b95984c211581d74ee91d195c from source fa29b2e527.
Not verified: there is no single complete 290-case guest run. The earlier 276-case full candidate emitted four stamp-wait timeouts and is not a passing validation. The consolidated macos-15 ledger is 184 pass, 77 classified driver failure, and 29 capability skip. Other guest rails and Apple-host backends were not run.
130 lines
6.1 KiB
Swift
130 lines
6.1 KiB
Swift
import Metal
|
|
import Foundation
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Where an argument binding stops being in force.
|
|
//
|
|
// Metal scopes argument tables to the *encoder*: a binding set on one render
|
|
// command encoder is not in force on the next one, and every encoder starts
|
|
// with nothing bound. Every case in this battery so far rebinds inside one
|
|
// encoder, so nothing here has ever asked what happens at the boundary.
|
|
//
|
|
// # Why this is a case and not a comment
|
|
//
|
|
// A device that wants to stop re-resolving an argument table every draw has to
|
|
// decide when a table is "the same as last time". The cheap and exact test is
|
|
// pointer identity on the table the guest presented -- and pointer identity is
|
|
// blind to encoder boundaries. The same table re-presented in a *new* encoder
|
|
// is the same allocation and a wholly different binding state, so a device that
|
|
// compares only the table skips a bind that Metal requires, and the draw reads
|
|
// whatever the descriptor happened to hold.
|
|
//
|
|
// That failure is silent. It needs the same allocation to be presented twice
|
|
// across a boundary, which is exactly what a compositor does and exactly what
|
|
// no existing case here constructs. The three checks below are the boundaries a
|
|
// per-draw dirty flag can be wrong about, in increasing order of how likely a
|
|
// device is to carry state across them:
|
|
//
|
|
// 1. a second encoder in the SAME command buffer, identical bind re-issued
|
|
// 2. a second encoder in the same command buffer, DIFFERENT bind
|
|
// 3. a second encoder in a DIFFERENT command buffer, identical bind re-issued
|
|
//
|
|
// Each second encoder clears the target first, so the first encoder's pixels
|
|
// cannot stand in for the second's. A device that drops the second bind renders
|
|
// the clear colour or a stale slot, and both are distinguishable from the
|
|
// answer.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
func encoderBindingLifetimeCase() {
|
|
let w = 64, h = 64
|
|
let fmt = MTLPixelFormat.bgra8Unorm
|
|
guard let pipe = makeRenderPipeline("solid_fs", fmt) else {
|
|
report("ebl_pipeline", false, "pipeline failed"); return
|
|
}
|
|
let td = MTLTextureDescriptor.texture2DDescriptor(
|
|
pixelFormat: fmt, width: w, height: h, mipmapped: false)
|
|
td.usage = [.renderTarget, .shaderRead]
|
|
td.storageMode = .private
|
|
guard let rt = dev.makeTexture(descriptor: td) else {
|
|
report("ebl_target", false, "no render target"); return
|
|
}
|
|
let verts = dev.makeBuffer(bytes: quadVerts,
|
|
length: quadVerts.count * 4,
|
|
options: .storageModeShared)!
|
|
|
|
// Two slots, exact under the unorm conversion so the expectation is a byte
|
|
// and not a rounding argument. The clear colour is a third value, so
|
|
// "the second encoder did not draw" is distinguishable from either slot.
|
|
let stride = 256
|
|
let slots: [(UInt8, UInt8, UInt8)] = [(64, 128, 192), (192, 64, 128)]
|
|
let colours = dev.makeBuffer(length: stride * slots.count, options: .storageModeShared)!
|
|
for (i, c) in slots.enumerated() {
|
|
var rgba: [Float] = [Float(c.0) / 255, Float(c.1) / 255, Float(c.2) / 255, 1]
|
|
memcpy(colours.contents().advanced(by: i * stride), &rgba, 16)
|
|
}
|
|
func want(_ i: Int) -> UInt32 { pack(slots[i].0, slots[i].1, slots[i].2, 255) }
|
|
let clearPixel = pack(255, 0, 255, 255)
|
|
|
|
// One encoder that clears, binds `slot`, and covers the target.
|
|
func encode(_ cb: MTLCommandBuffer, slot: Int) {
|
|
let pass = MTLRenderPassDescriptor()
|
|
pass.colorAttachments[0].texture = rt
|
|
pass.colorAttachments[0].loadAction = .clear
|
|
pass.colorAttachments[0].clearColor = MTLClearColor(red: 1, green: 0, blue: 1, alpha: 1)
|
|
pass.colorAttachments[0].storeAction = .store
|
|
let enc = cb.makeRenderCommandEncoder(descriptor: pass)!
|
|
enc.setRenderPipelineState(pipe)
|
|
enc.setVertexBuffer(verts, offset: 0, index: 0)
|
|
enc.setFragmentBuffer(colours, offset: slot * stride, index: 0)
|
|
enc.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: 4)
|
|
enc.endEncoding()
|
|
}
|
|
|
|
func judge(_ label: String, _ wantSlot: Int) {
|
|
guard let got = readBack(readPipe, rt, w, h) else { refused(label); return }
|
|
let px = got[(h / 2) * w + (w / 2)]
|
|
let ok = px == want(wantSlot)
|
|
let why: String
|
|
if px == clearPixel {
|
|
why = "the second encoder's draw produced nothing — its bind was dropped"
|
|
} else if px == want(1 - wantSlot) {
|
|
why = "the second encoder rendered the other encoder's slot"
|
|
} else {
|
|
why = "unrecognised"
|
|
}
|
|
report(label, ok,
|
|
ok ? "the binding re-issued on the second encoder is the one that drew"
|
|
: "got=\(hex(px)) want=\(hex(want(wantSlot))) — \(why)")
|
|
}
|
|
|
|
// 1. Two encoders, one command buffer, the *same* bind re-issued. A device
|
|
// keyed on the table's identity alone sees "unchanged" and skips it.
|
|
var cb = queue.makeCommandBuffer()!
|
|
encode(cb, slot: 0)
|
|
encode(cb, slot: 0)
|
|
cb.commit(); cb.waitUntilCompleted()
|
|
judge("ebl_same_bind_second_encoder", 0)
|
|
|
|
// 2. Two encoders, one command buffer, a different bind on the second. The
|
|
// opposite error: state carried across the boundary rather than dropped.
|
|
cb = queue.makeCommandBuffer()!
|
|
encode(cb, slot: 0)
|
|
encode(cb, slot: 1)
|
|
cb.commit(); cb.waitUntilCompleted()
|
|
judge("ebl_changed_bind_second_encoder", 1)
|
|
|
|
// 3. The same bind re-issued from a *different* command buffer. Metal fixes
|
|
// the order at commit, so the second buffer's clear-and-draw is what the
|
|
// target holds; a device that carries per-draw state across command
|
|
// buffers is wrong here in the same way as 1 and harder to notice,
|
|
// because the two buffers are resolved at different times.
|
|
let first = queue.makeCommandBuffer()!
|
|
encode(first, slot: 1)
|
|
first.commit()
|
|
let second = queue.makeCommandBuffer()!
|
|
encode(second, slot: 1)
|
|
second.commit()
|
|
second.waitUntilCompleted()
|
|
judge("ebl_same_bind_second_command_buffer", 1)
|
|
}
|