Files
reims-vgpu/conformance/suite/cases/IndirectCompute.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

68 lines
2.9 KiB
Swift

import Metal
import Foundation
// The indirect buffer begins one word into the allocation so this covers the
// byte offset as well as the three MTLDispatchThreadgroupsIndirectArguments
// counts. Metal multiplies those counts by threadsPerThreadgroup to form the
// shader-visible grid.
func indirectComputeDispatchCase() {
let label = "compute_dispatch_threadgroups_indirect"
let capacity = 64
let expectedThreads = 12 * 4
let byteCount = capacity * MemoryLayout<UInt32>.size
guard let output = dev.makeBuffer(length: byteCount, options: .storageModeShared),
let observedGrid = dev.makeBuffer(length: 3 * MemoryLayout<UInt32>.size,
options: .storageModeShared),
let ran = dev.makeBuffer(length: MemoryLayout<UInt32>.size,
options: .storageModeShared),
let indirect = dev.makeBuffer(length: 5 * MemoryLayout<UInt32>.size,
options: .storageModeShared) else {
report(label, false, "buffer creation failed")
return
}
memset(output.contents(), 0, byteCount)
memset(observedGrid.contents(), 0, 3 * MemoryLayout<UInt32>.size)
memset(ran.contents(), 0, MemoryLayout<UInt32>.size)
let arguments = indirect.contents().bindMemory(to: UInt32.self, capacity: 5)
arguments[0] = 0xdeadbeef
arguments[1] = 3
arguments[2] = 2
arguments[3] = 1
arguments[4] = 0xcafebabe
let cb = queue.makeCommandBuffer()!
let enc = cb.makeComputeCommandEncoder()!
enc.setComputePipelineState(pipeline("indirect_threadgroups_write"))
enc.setBuffer(output, offset: 0, index: 0)
enc.setBuffer(observedGrid, offset: 0, index: 1)
var outputCapacity = UInt32(capacity)
enc.setBytes(&outputCapacity, length: MemoryLayout<UInt32>.size, index: 2)
enc.setBuffer(ran, offset: 0, index: 4)
enc.dispatchThreadgroups(
indirectBuffer: indirect,
indirectBufferOffset: MemoryLayout<UInt32>.size,
threadsPerThreadgroup: MTLSize(width: 4, height: 2, depth: 1))
enc.endEncoding()
cb.commit()
cb.waitUntilCompleted()
let ranWord = ran.contents().bindMemory(to: UInt32.self, capacity: 1)[0]
guard ranWord != 0 else {
report(label, false, "the indirect dispatch produced nothing — the device refused it")
return
}
let gridWords = observedGrid.contents().bindMemory(to: UInt32.self, capacity: 3)
let grid = Array(UnsafeBufferPointer(start: gridWords, count: 3))
let outputWords = output.contents().bindMemory(to: UInt32.self, capacity: capacity)
let firstBad = (0..<capacity).first { index in
let expected: UInt32 = index < expectedThreads ? 0xa5000000 | UInt32(index) : 0
return outputWords[index] != expected
}
report(label, grid == [12, 4, 1] && firstBad == nil,
"groups=[3,2,1] local=[4,2,1] grid=\(grid) first_bad=\(firstBad.map(String.init) ?? "none")")
}