Files
reims-vgpu/conformance/suite/cases/CpuWriteThenSample.swift
T
Anees Iqbal 3c019bf8b2 conformance: add the macOS 15 Metal compatibility battery
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.
2026-08-29 18:20:50 +03:00

63 lines
3.1 KiB
Swift

import Metal
import Foundation
import IOSurface
// L. A whole-surface blit of a target the GPU has only just rendered into.
//
// The guest never reads the layer here — it hands both endpoints to a blit and
// asks the device to move the pixels. Metal orders that copy against the render
// before it: two command buffers on one queue execute in the order they were
// committed, so the copy sees everything the render wrote.
//
// A device that decomposes the pair does not get that ordering for free. If the
// render is submitted to the GPU and the copy is then serviced by reading the
// source's bytes on the CPU, the two are racing, and the reader wins whenever
// the GPU has not finished — which is most of the time, because submission is
// asynchronous and the copy is decoded immediately behind it.
//
// # The shape is measured, not chosen
//
// Which copies the guest driver emits as a whole-surface texture-to-texture
// copy, rather than staging through a buffer, is the driver's decision and not
// something this file can assume. Earlier attempts at this case used a
// `.bgra8Unorm` pair at 512x512 and never produced one: the driver staged every
// one of them, so the case exercised a different rail and passed for the wrong
// reason.
//
// The shape below is what a driven compositor actually emits — a linear source,
// an IOSurface-backed destination, `BGRA8Unorm_sRGB`, one level and one slice,
// at window and screen size. That is the pair a compositor produces when it
// draws a layer and then copies it into the surface the window server owns.
//
// # Why two passes
//
// The first pass lands red and is waited on, so the source's bytes are known
// and are *not* the answer. The second lands green and is not waited on before
// the copy. A correct device puts green in the destination; one that reads the
// source without ordering puts **red** there — the previous frame, whole and
// undamaged, which is why this class reads as a layer showing stale content
// rather than as corruption. `stale_previous_frame` in the failure counts
// exactly those texels, so the report distinguishes this defect from a copy
// that simply moved nothing.
//
// Full-intensity red and green round-trip an 8-bit sRGB encode exactly (0 and 1
// are both fixed points), so the expectation is unaffected by the transfer
// function on the attachment.
func makeSrgbIOSurfaceTarget(_ w: Int, _ h: Int, _ label: String) -> MTLTexture? {
let bgra: UInt32 = 0x4247_5241 // 'BGRA' as an OSType
let props: [IOSurfacePropertyKey: Any] = [
.width: w, .height: h, .bytesPerElement: 4, .pixelFormat: bgra,
]
guard let surface = IOSurface(properties: props) else {
report(label, false, "IOSurface(properties:) nil for \(w)x\(h)"); return nil
}
let td = MTLTextureDescriptor.texture2DDescriptor(
pixelFormat: .bgra8Unorm_srgb, width: w, height: h, mipmapped: false)
td.usage = [.renderTarget, .shaderRead]
td.storageMode = .shared
guard let tex = dev.makeTexture(descriptor: td, iosurface: surface, plane: 0) else {
report(label, false, "makeTexture(iosurface:) nil for \(w)x\(h)"); return nil
}
return tex
}