Files
metal2vulkan/crates/metal2vulkan-conformance/src/record.rs
T
Anees Iqbal ec72c052dd Answer as one macOS release, 27.0.1, on every host
The owner's ruling: the runtime imitates the latest measured release
only, not the history of releases. Capabilities (GPU family, features,
limits) still follow the GPU; every answer that differs by release is
macOS 27.0.1's (build 26A434, measured on an Apple M3 Max), on every
host, whatever release it runs.

What changed:
- metal_level.rs becomes metal_release.rs: the public const
  MACOS_RELEASE ("27.0.1") and the release's answers in one place
  (heap block placement per family, the nil-texture stack alignment,
  the mipmap rule, a depth/stencil state's resource ID below Apple10).
  The pixel-format table and the private properties hold 27.0.1's
  answers alone.
- Removed the MetalLevel enum and its 26.7 row, the host-release read
  and the level choice, DeviceOptions::metal_level,
  RawDevice::metal_level and DeviceProperties::metal_level.
- Removed what existed only for 26.7: the indirect-dispatch-of-another-
  type refusal and its predication tracking, the depth/stencil resource
  ID refusal, the M3 Max GPU row counting for heap blocks, PVRTC's
  unmeasured heap placement, and the M4 mipmap stand-in emission.
- Problem::HostReleaseUnmeasured (the Unproven site),
  Problem::IndirectDispatchOfAnotherType and
  Problem::DepthStencilResourceId are gone. The Unproven type is
  untouched.
- Degradations metal-level-below-host, metal-level-not-macos and
  mipmaps-as-apple-m4 are retired (RETIRED_CODES, the retired section
  of docs/API.md); mipmap-tie-rounding's trigger and cost drop the 26.7
  clauses.
- Conformance: the recordings keep their "metal_level": "27.0.1" key as
  a fact about the recording; record and replay compare it with
  MACOS_RELEASE. Venue no longer carries a level.
- Validation's runtime_lane tests run on the default device, with the
  26.7-only tests and level loops removed.
- A runtime unit test now holds the block-compressed kind on ASTC 4x2,
  its one remaining trigger, in place of PVRTC at 26.7.

Docs: docs/API.md, docs/FAST-PATHS.md, docs/RUNTIME-PORTING.md and the
runtime README; docs/REFUSALS.md and docs/METAL-COVERAGE.md
regenerated (CONFORMANCE-COVERAGE.md regenerated, unchanged); the
signature table re-blessed with scripts/api-signatures/signatures.py.

Carried onto development from the parked development-performance branch
(a23f8181d9 there). The three conflicts were that branch's pipeline-record
hook (RawDevice and DeviceOptions fields and their Debug impls), which
development lacks: development's side is kept, without the release field.

Verified: cargo check --workspace --all-targets --all-features, plain and
with --cfg m2v_gpu; refusal_surface.py, signatures.py --check and the two
coverage generators leave the committed files unchanged.

Originally 79bb9749d3 (archive/development-linear-2026-10-28).
2026-10-28 17:24:20 +02:00

245 lines
9.7 KiB
Rust

//! Record mode: take a case's Metal answer and write its recording.
//!
//! Record mode runs only where Metal does. It refuses, before anything is encoded, a case whose
//! Metal leg is not safe to run ([`crate::case::ReRecord::Forbidden`]): those cases carry an answer
//! already written down, and a re-record of a whole selection must not walk into one and fault the
//! GPU or end the process.
//!
//! It also refuses to write a recording on a host that is not the oracle the suite names. A
//! recording is keyed by chip, macOS release and macOS build, and a file written under one build
//! and compared under another proves nothing, so the host is checked at the one moment it can be:
//! as the answer is taken.
use crate::case::{Case, Side};
use crate::recording::{self, Answer, Outcome, Provenance, Recording, Validated};
use crate::replay::NOTICES_SITE;
use crate::transcript::{Sites, Transcript};
/// Why an answer could not be recorded.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum RecordError {
/// The case forbids re-recording: running its Metal leg is not safe. The reason is the case's
/// own.
Forbidden { case: String, reason: String },
/// The host is not the oracle the suite names, so a recording taken here would be keyed
/// wrongly.
HostMoved { found: String, named: String },
/// There is no Metal here.
NoMetal,
/// The case could not state its own inputs or shaders.
Case { case: String, why: String },
/// No run produced an answer.
NoRuns { case: String },
/// Metal's own run of the case **stopped** at a site, so the transcript holds part of the case
/// and not its answer. The site and the refusal, in the words a ledger row uses.
Refused {
case: String,
at: String,
refusal: String,
},
}
impl std::fmt::Display for RecordError {
fn fmt(&self, out: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RecordError::Forbidden { case, reason } => write!(
out,
"{case}: its Metal answer is carried and must not be re-recorded: {reason}"
),
RecordError::HostMoved { found, named } => write!(
out,
"this host is {found}, and the suite records on {named}: re-point ORACLE_CHIP, \
ORACLE_OS_VERSION and ORACLE_OS_BUILD, and re-record every case"
),
RecordError::NoMetal => out.write_str("there is no Metal on this host"),
RecordError::Case { case, why } => write!(out, "{case}: {why}"),
RecordError::NoRuns { case } => write!(out, "{case}: no run produced an answer"),
RecordError::Refused { case, at, refusal } => write!(
out,
"{case}: Metal's own run stopped at {at} ({refusal}), so a recording taken here \
would hold part of the case and not its answer. Fix what the Metal leg cannot \
do, or state the answer by hand if Metal does not come back from the call"
),
}
}
}
/// Take `case`'s answer by running it `runs` times on `side`, with
/// `validated` what Metal's API validation did with the same case.
///
/// `side` must be a Metal side. The two Metal facts stay apart: the transcripts are plain Metal's,
/// and `validated` is recorded beside them without ever being compared with our behaviour.
///
/// A run that **stops** is refused rather than written down. [`crate::case::call`] aborts the whole
/// case, so the sites after it are never emitted, and a recording of a truncated Metal run is not a
/// recording of the case: on replay every site past the stop reads as one only our side observed,
/// which is a divergence the case never asked about. Worse, a recorded Metal `Err` our side happens
/// to match compares **exact**, so the case would report as passing where neither side did the
/// work. So the recording is refused, naming the site, and the author either fixes what the Metal
/// leg cannot do or states the answer by hand ([`never_returned`]).
///
/// A refusal a [`crate::case::probe`] sweep records at its own site is the deliberate complement:
/// it emits every other site, so the transcript is the whole case with one query Metal answered nil
/// for, which is Metal's answer and compares as one. Only a stop truncates.
pub fn record(
case: &dyn Case,
side: &mut dyn Side,
runs: u32,
validated: Validated,
) -> Result<Answer, RecordError> {
if let Some(reason) = case.metal_source().forbidden() {
return Err(RecordError::Forbidden {
case: case.name().to_owned(),
reason: reason.to_owned(),
});
}
check_host()?;
let inputs = case.inputs().map_err(|why| RecordError::Case {
case: case.name().to_owned(),
why,
})?;
let mut outcomes: Vec<Outcome> = Vec::new();
for _ in 0..runs {
let mut sites = Sites::new();
sites.push(crate::case::inputs_node(&inputs));
if let Err(stopped) = case.run(side, &mut sites) {
return Err(RecordError::Refused {
case: case.name().to_owned(),
at: stopped.at,
refusal: crate::diff::print(&stopped.failure.recorded()),
});
}
let announced = side.announced();
sites.notices(NOTICES_SITE, &announced);
add(&mut outcomes, sites.finish());
}
if outcomes.is_empty() {
return Err(RecordError::NoRuns {
case: case.name().to_owned(),
});
}
let venue = side.venue();
Ok(Answer {
key: recording::OracleKey::current(),
provenance: Provenance::MetalRun,
device: venue.device,
runs,
outcomes,
validated,
})
}
/// The answer a case carries from a measurement this tree already holds: one outcome, the runs the
/// measurement stands on, where it came from, and the chip it was taken on.
pub fn carried(
from: &str,
measured_on: &str,
device: &str,
runs: u32,
transcript: Transcript,
validated: Validated,
) -> Answer {
Answer {
key: recording::OracleKey::current(),
provenance: Provenance::Carried {
from: from.to_owned(),
measured_on: measured_on.to_owned(),
},
device: device.to_owned(),
runs,
outcomes: vec![Outcome { runs, transcript }],
validated,
}
}
/// The answer a row has where **Metal did not return** from the call: one outcome, which the case
/// states by hand from the probe that died, and a provenance naming the call.
///
/// Nothing here runs anything. This is the one answer in the suite that cannot be taken by running
/// its own shape -- making the call is what ends Metal's process -- so [`record`] refuses such a
/// row ([`crate::case::MetalSource::forbidden`]) and this is the only way one is built. The
/// validated oracle is [`Validated::NotRun`] for the same reason: Metal's API validation layer was
/// never asked either, and the file says so rather than implying it was content.
pub fn never_returned(
from: &str,
call: &str,
device: &str,
runs: u32,
transcript: Transcript,
) -> Answer {
Answer {
key: recording::OracleKey::current(),
provenance: Provenance::NeverReturned {
from: from.to_owned(),
call: call.to_owned(),
},
device: device.to_owned(),
runs,
outcomes: vec![Outcome { runs, transcript }],
validated: Validated::NotRun,
}
}
/// Write `answers` as `case`'s recording.
///
/// Everything a recording already written holds that Metal does not measure is **kept**
/// ([`Recording::carrying_the_answers_of`]): the cost half, and any other half another leg
/// measures on another machine. Re-taking Metal's answer neither refreshes nor invalidates them,
/// and dropping one here would silently empty its gate every time a case was re-recorded.
///
/// The keeping is a default rather than a list, so a half added later is carried without anyone
/// remembering to add it.
pub fn write(case: &dyn Case, answers: Vec<Answer>) -> Result<std::path::PathBuf, String> {
let shaders = case.shaders()?;
let fresh = Recording::new(case.name(), shaders, answers);
let recording = match recording::read(case.name()) {
Ok(held) => held.carrying_the_answers_of(fresh),
Err(_) => fresh,
};
recording::write(&recording)
}
/// Count `transcript` among `outcomes`, as a new outcome or as another run of one already held.
fn add(outcomes: &mut Vec<Outcome>, transcript: Transcript) {
match outcomes
.iter_mut()
.find(|outcome| outcome.transcript == transcript)
{
Some(held) => held.runs += 1,
None => outcomes.push(Outcome {
runs: 1,
transcript,
}),
}
}
/// Refuse to record on a host that is not the oracle the suite names.
#[cfg(target_os = "macos")]
fn check_host() -> Result<(), RecordError> {
let read = |flag: &str| {
std::process::Command::new("/usr/bin/sw_vers")
.arg(flag)
.output()
.ok()
.filter(|output| output.status.success())
.map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned())
.unwrap_or_default()
};
use crate::recording::{ORACLE_CHIP, ORACLE_OS_BUILD, ORACLE_OS_VERSION};
let version = read("-productVersion");
let build = read("-buildVersion");
if version == ORACLE_OS_VERSION && build == ORACLE_OS_BUILD {
return Ok(());
}
Err(RecordError::HostMoved {
found: format!("macOS {version} ({build})"),
named: format!("{ORACLE_CHIP} on macOS {ORACLE_OS_VERSION} ({ORACLE_OS_BUILD})"),
})
}
/// There is no Metal to record from off macOS.
#[cfg(not(target_os = "macos"))]
fn check_host() -> Result<(), RecordError> {
Err(RecordError::NoMetal)
}