Files
reims-vgpu/conformance/suite/cases/MultisampleStore.swift
T
Anees IqbalandClaude Opus 5 8449a30394 conformance: one result line could not say whether the bind was refused or the sample count was one
Component: conformance suite. Pathway: x86 macOS / Linux Vulkan. Rail: macos-15.
Test-only; no product behavior changes.

## The contract, and why one case could not witness it

A Metal kernel may declare `texture2d_ms<T, access::read>` and call
`read(coord, sample)`. Two independent obligations stand behind that: the device
must serve the multisample sampled bind from the retained target that holds the
samples, and the texture's own `get_num_samples()` must report that target's
sample count.

`msaa4_color_store_no_resolve` reads all four samples back through a kernel that
loops over `min(samples, tex.get_num_samples())`, so its result depends on both.
And the two failures are indistinguishable in it: a refused bind writes nothing,
and a served bind whose query folds to 1 writes only sample 0 — in both cases
samples 1..3 keep the readback buffer's 0xEE fill. The case cannot be the red
witness for either half, which is exactly what it was being asked to be.

## What this adds

`read_ms_texels_host_count` is `read_ms_texels` with the sample count taken from
the host constant the caller already has, never from the texture. It is a
separate kernel rather than a flag inside the first because the difference is
the whole point of the pair: the shared one would have to keep both spellings
anyway, and a reader has to be able to see that one of them does not query.

`readBackMultisample` gains `countFromTexture:` and selects between the two
pipelines. `msaa4_color_store_host_sample_count` runs the same render, the same
four unequal samples and the same comparison through it, so a difference between
the two cases is the query and nothing else.

## Results

Native oracle `scaleway-m4-macos15` (Apple M4, macOS 15.6.1), full battery:
294 cases, 0 failures, 0 skipped. Both multisample cases PASS. The tracked
baseline gains exactly one line and its SUMMARY count; no existing native
expectation moved.

Guest, rail macos-15, identified control `84452de4` (= a65348ed), full battery,
294 cases, no NOT-RUN, no panic:

  CASE msaa4_color_store_host_sample_count FAIL the readback dispatch produced
       nothing — the device refused it, or refused a bind in it

with the owning rung named on the device's own channel, the same one the sibling
case refuses at:

  compute_linux texture_shape fail reason=unstageable_multisampled pipe=164 ref=152 bind=32
  compute_record reason=texture_shape_unstageable class=unsupported kind=DispatchThreadgroups

So the new case is recorded as classified driver debt beside its sibling. It is a
coverage-and-isolation case on this build, not a repair witness: both cases refuse
at the same rung today, and the new one is the one that can move first once the
bind is served.

## Not verified

Two further control batteries of the three-run repetition were still running when
this was committed; the first is the evidence above. Because HEAD moved, their
manifests will record a different `harness_tracked_diff_sha256` than the first —
the suite, expectation and guest-binary content hashes in the same manifests are
the identity that matters and are unchanged.

No candidate boot exists for this change: it changes no product behavior, so
there is nothing to score a candidate transition against.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 19:29:52 +03:00

102 lines
4.3 KiB
Swift

import Metal
import Foundation
/// A Store-only multisample attachment remains a multisample texture after its
/// encoder ends. Four unequal samples make preservation distinguishable from
/// an implicit resolve, and the later command buffer forces the observation
/// across the encoder/submission lifetime boundary.
/// Both multisample-store cases run the same render and differ only in where the
/// readback kernel's sample count comes from. See `read_ms_texels_host_count`
/// for why that difference is worth two cases: one result line cannot say
/// whether a device served the `texture2d_ms` bind, because a bind that was
/// refused and a bind whose sample count came back as 1 both leave samples 1
/// and up unwritten.
func multisampleStoreCase() {
multisampleStoreCase(label: "msaa4_color_store_no_resolve", countFromTexture: true)
multisampleStoreCase(label: "msaa4_color_store_host_sample_count", countFromTexture: false)
}
func multisampleStoreCase(label: String, countFromTexture: Bool) {
let w = 8, h = 8, samples = 4
guard dev.supportsTextureSampleCount(samples) else {
skip(label, "device does not report 4x texture sampling")
return
}
let descriptor = MTLRenderPipelineDescriptor()
descriptor.vertexFunction = library.makeFunction(name: "quad_vs")
descriptor.fragmentFunction = library.makeFunction(name: "sample_id_fs")
descriptor.colorAttachments[0].pixelFormat = .rgba8Unorm
descriptor.rasterSampleCount = samples
guard let renderPipeline = try? dev.makeRenderPipelineState(descriptor: descriptor) else {
report(label, false, "4x render pipeline creation failed")
return
}
let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(
pixelFormat: .rgba8Unorm, width: w, height: h, mipmapped: false)
textureDescriptor.textureType = .type2DMultisample
textureDescriptor.sampleCount = samples
textureDescriptor.storageMode = .private
textureDescriptor.usage = [.renderTarget, .shaderRead]
guard let texture = dev.makeTexture(descriptor: textureDescriptor),
let vertices = dev.makeBuffer(bytes: quadVerts,
length: quadVerts.count * MemoryLayout<Float>.size,
options: .storageModeShared) else {
report(label, false, "4x resource creation failed")
return
}
let pass = MTLRenderPassDescriptor()
pass.colorAttachments[0].texture = texture
pass.colorAttachments[0].loadAction = .clear
pass.colorAttachments[0].clearColor = MTLClearColor(red: 1, green: 0, blue: 1, alpha: 1)
pass.colorAttachments[0].storeAction = .store
let producer = queue.makeCommandBuffer()!
let render = producer.makeRenderCommandEncoder(descriptor: pass)!
render.setRenderPipelineState(renderPipeline)
render.setVertexBuffer(vertices, offset: 0, index: 0)
render.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: 4)
render.endEncoding()
producer.commit()
producer.waitUntilCompleted()
guard let got = readBackMultisample(texture, w, h, samples: samples,
countFromTexture: countFromTexture) else {
refused(label)
return
}
let expected = [
pack(255, 0, 0, 255),
pack(0, 255, 0, 255),
pack(0, 0, 255, 255),
pack(255, 255, 255, 255),
]
var wrong = 0
var first: (pixel: Int, sample: Int, got: UInt32, want: UInt32)?
var badPixels: [(Int, Int)] = []
for pixel in 0..<(w * h) {
var pixelWrong = false
for sample in 0..<samples {
let index = pixel * samples + sample
if got[index] != expected[sample] {
wrong += 1
pixelWrong = true
if first == nil {
first = (pixel, sample, got[index], expected[sample])
}
}
}
if pixelWrong { badPixels.append((pixel % w, pixel / w)) }
}
if let first {
report(label, false,
"wrong=\(wrong)/\(got.count) first_pixel=\(first.pixel) "
+ "sample=\(first.sample) got=\(hex(first.got)) want=\(hex(first.want)) "
+ badMap(badPixels, w, h))
} else {
report(label, true, "\(w * h) pixels retained four distinct samples")
}
}