CLI: the device file a runtime repro bundle held is gone; a bundle holds the profile

`metal2vulkan --device <device.json>` read a ReproDevice (a device description and policy), the
device file a runtime's FALLBACK bundle would hold, and repro.rs said "a runtime may write one
for a library or pipeline creation it refuses". No runtime writes one: metal2vulkan-runtime has
no repro or env_vars use and reads no METAL2VULKAN_* variable (git grep at 5a7c262577), and the
consumer's walks capture refused libraries as replay streams. So the option read a file nothing
writes. Deleted with it: ReproDevice (new, to_json, from_json), the command line's DeviceFile and
its `--device` arm, usage and help lines, the cli test a_device_file_takes_the_place_of_a_profile,
and the README's sentence on it. A bundle now always holds `profile.json`, the file `--profile`
read. The module is gated on `cli`, its only user, rather than `serde`.

The consumer's checkout (reims-vgpu at f8212794e7) names none of it: 0 hits each for
ReproDevice, ReproBundle, shell_join, metal2vulkan::repro, METAL2VULKAN_REPRO_DIR and `--device`.

Verified: m3-max-61727 (msi) at c48e3113db (this change and the README commit after it, on
bcc417bc08): clippy -p metal2vulkan --all-targets with all features, with none and with serde
alone, -D warnings, all 0; rustdoc -D warnings 0; the cli binary's tests and the READMEs' tests,
9 of 9 pass.
This commit is contained in:
Anees Iqbal committed 2026-11-20 21:44:38 -08:00
1 parent d6d56b8a7c
commit 06a35ed9e4
5 files changed
+30 -178

No files matched your search

+1 -2
View File
@@ -79,8 +79,7 @@ metal2vulkan kernel.ll kernel.spv --profile device.json --emit-meta kernel.json
- `--profile` is required: the crate ships no device description. Any Khronos profiles JSON works;
[`crates/metal2vulkan-validation/profiles/`](crates/metal2vulkan-validation/profiles) has
examples, from a bare Vulkan 1.2 device to desktop GPUs and MoltenVK. `--device FILE` takes its
place with the `device.json` a runtime repro bundle holds (a device description and policy).
examples, from a bare Vulkan 1.2 device to desktop GPUs and MoltenVK.
- Without `--function` it compiles the library's only kernel or vertex function. A kernel with
`--color-format` compiles as a tile pipeline. A post-tessellation vertex function adds
`.tesc.spv` and `.tese.spv` modules; on a device without `tessellationShader` it answers
+2 -2
View File
@@ -52,8 +52,8 @@ pub mod env_vars;
pub(crate) mod float16;
pub(crate) mod indirect_commands;
// The FALLBACK repro bundles the `metal2vulkan` binary writes (under
// feature `serde`): `pub` and hidden, as `env_vars` is, not API.
#[cfg(feature = "serde")]
// feature `cli`): `pub` and hidden, as `env_vars` is, not API.
#[cfg(feature = "cli")]
#[doc(hidden)]
pub mod repro;
#[cfg(test)]
+21 -75
View File
@@ -3,8 +3,7 @@
//! the library's API (`Device::compile_compute_pipeline`, `compile_render_pipeline`, and
//! `compile_tile_pipeline`).
//!
//! Usage: `metal2vulkan <in.metallib|in.air|in.ll> [out.spv] --profile <profile.json> [options]`,
//! or `--device <device.json>` in place of `--profile` (the device a runtime repro bundle names).
//! Usage: `metal2vulkan <in.metallib|in.air|in.ll> [out.spv] --profile <profile.json> [options]`.
//! A success prints a line containing `PASS`. Any failure prints `metal2vulkan: FALLBACK (why)`
//! and exits with status 2; a failure after the inputs are read also writes a repro bundle
//! (`metal2vulkan::repro`; `METAL2VULKAN_REPRO_DIR`, by default `$TMPDIR/metal2vulkan-repros`).
@@ -30,14 +29,13 @@ use metal2vulkan::pipeline::{
SpecializationLayout, StageEntries, StageInputDescriptor, StageModule, StageSource,
TileRenderPipelineDescriptor, VertexDescriptor, VertexInputState,
};
use metal2vulkan::repro::{shell_join, ReproBundle, ReproDevice};
use metal2vulkan::repro::{shell_join, ReproBundle};
use metal2vulkan::{vk, Budget};
const USAGE: &str =
"usage: metal2vulkan <in.metallib|in.air|in.ll> [out.spv] --profile <profile.json> [options]";
const HELP: &str = r#"usage: metal2vulkan <in.metallib|in.air|in.ll> [out.spv] --profile <profile.json> [options]
metal2vulkan <in.metallib|in.air|in.ll> [out.spv] --device <device.json> [options]
Compiles one pipeline of the input library for the device a Khronos profile describes, and writes
its SPIR-V. A kernel writes out.spv; a render pipeline writes one module per stage, named by
@@ -47,13 +45,9 @@ output is <input-without-extension>.vk.spv. A .ll input is assembled with llvm-a
newer).
options:
--profile FILE Khronos profiles JSON for the target device (this or --device is
required; the repository's crates/metal2vulkan-validation/profiles/
holds examples)
--profile FILE Khronos profiles JSON for the target device (required; the
repository's crates/metal2vulkan-validation/profiles/ holds examples)
--profile-name NAME the profile to read when FILE holds more than one
--device FILE the target device as a runtime repro bundle's device.json holds it: the
JSON form of metal2vulkan::device::DeviceDescription and DevicePolicy,
{"description": ..., "policy": ...}, in place of --profile
--function NAME the kernel or vertex function (default: the library's only one)
--fragment NAME the fragment function of a render pipeline
--constant ID:TYPE:VALUE function-constant value (repeatable): ID is an index or a name, TYPE a
@@ -82,29 +76,6 @@ const DESCRIPTOR_FILES: [(&str, &str); 2] = [
("--vertex-descriptor", "vertex-descriptor.json"),
];
/// The device the command compiles for, as its file reads: a Khronos profiles document
/// (`--profile`), or a device description and policy (`--device`).
enum DeviceFile {
Profile(String),
Device(String),
}
impl DeviceFile {
/// The device file's name in a repro bundle, and the options that name it there.
fn bundled(&self) -> (&'static str, [&'static str; 2], &[u8]) {
match self {
DeviceFile::Profile(json) => (
"profile.json",
["--profile", "profile.json"],
json.as_bytes(),
),
DeviceFile::Device(json) => {
("device.json", ["--device", "device.json"], json.as_bytes())
}
}
}
}
/// What the command line asks for.
#[derive(Default)]
struct Args {
@@ -112,7 +83,6 @@ struct Args {
output: Option<String>,
profile: Option<String>,
profile_name: Option<String>,
device: Option<String>,
function: Option<String>,
fragment: Option<String>,
constants: Vec<(String, FunctionConstantValue)>,
@@ -126,8 +96,7 @@ struct Args {
timeout: Option<Duration>,
emit_meta: Option<String>,
spirv_val: bool,
/// The options a repro bundle replays: every one but `--profile`, `--device` and
/// `--emit-meta`, with each descriptor file named as the bundle's copy of it
/// The options a repro bundle replays: every one but `--profile` and `--emit-meta`, with each descriptor file named as the bundle's copy of it
/// ([`DESCRIPTOR_FILES`]).
replay: Vec<String>,
}
@@ -179,27 +148,20 @@ fn main() {
let read = |path: &str| {
fs::read_to_string(path).unwrap_or_else(|e| fail(&format!("cannot read {path}: {e}")))
};
let device_file = match (&args.profile, &args.device) {
(Some(profile), None) => DeviceFile::Profile(read(profile)),
(None, Some(device)) => {
if args.profile_name.is_some() {
fail("--profile-name names a profile of --profile's document; --device has none");
}
DeviceFile::Device(read(device))
}
(Some(_), Some(_)) => fail("--profile and --device each name the device: give one"),
(None, None) => fail(
let Some(profile) = &args.profile else {
fail(
"no --profile: name a Khronos profiles JSON for the target device (the repository's \
crates/metal2vulkan-validation/profiles/ holds examples, and the Vulkan SDK and \
vulkaninfo --json produce more), or a repro bundle's device.json with --device",
),
vulkaninfo --json produce more)",
)
};
let profile = read(profile);
let source = fs::read(&input).unwrap_or_else(|e| fail(&format!("cannot read {input}: {e}")));
let output = args
.output
.clone()
.unwrap_or_else(|| default_output_path(&input));
match run(&args, &source, &device_file, &input, &output) {
match run(&args, &source, &profile, &input, &output) {
Ok(line) => println!("{line}"),
Err(failure) => {
if let Some(detail) = &failure.detail {
@@ -209,7 +171,7 @@ fn main() {
original: &original,
input: &input,
source: &source,
device_file: &device_file,
profile: &profile,
args: &args,
output: &output,
};
@@ -226,25 +188,14 @@ fn main() {
fn run(
args: &Args,
source: &[u8],
device_file: &DeviceFile,
profile: &str,
input: &str,
output: &str,
) -> Result<String, Failure> {
let device = match device_file {
DeviceFile::Profile(json) => {
let description =
DeviceDescription::from_khronos_json(json, args.profile_name.as_deref())
.map_err(|e| Failure::detailed("profile not read", e.to_string()))?;
Device::from_queries(description, DevicePolicy::default())
.map_err(|e| Failure::detailed("profile refused", e.to_string()))?
}
DeviceFile::Device(json) => {
let device = ReproDevice::from_json(json)
.map_err(|e| Failure::detailed("device not read", e))?;
Device::from_queries(device.description, device.policy)
.map_err(|e| Failure::detailed("device refused", e.to_string()))?
}
};
let description = DeviceDescription::from_khronos_json(profile, args.profile_name.as_deref())
.map_err(|e| Failure::detailed("profile not read", e.to_string()))?;
let device = Device::from_queries(description, DevicePolicy::default())
.map_err(|e| Failure::detailed("profile refused", e.to_string()))?;
let assembled;
let bitcode: &[u8] = if input.ends_with(".ll") {
assembled = assemble(source)?;
@@ -742,10 +693,6 @@ fn parse_args(args: &[String]) -> Args {
parsed.profile = Some(value());
replayed = false;
}
"--device" => {
parsed.device = Some(value());
replayed = false;
}
"--profile-name" => parsed.profile_name = Some(value()),
"--function" => parsed.function = Some(value()),
"--fragment" => parsed.fragment = Some(value()),
@@ -996,23 +943,22 @@ struct Bundle<'a> {
original: &'a [String],
input: &'a str,
source: &'a [u8],
device_file: &'a DeviceFile,
profile: &'a str,
args: &'a Args,
output: &'a str,
}
impl Bundle<'_> {
/// A bundle (`metal2vulkan::repro`) holding the input, the device file, the descriptor files,
/// A bundle (`metal2vulkan::repro`) holding the input, the profile, the descriptor files,
/// the command that replays the failure on them, and why it failed, under
/// `METAL2VULKAN_REPRO_DIR` or `$TMPDIR/metal2vulkan-repros`.
fn write(&self, failure: &Failure) -> Result<PathBuf, String> {
let base = metal2vulkan::env_vars::repro_dir()
.map(PathBuf::from)
.unwrap_or_else(|| env::temp_dir().join("metal2vulkan-repros"));
let (device_name, device_options, device_bytes) = self.device_file.bundled();
let mut bundle = ReproBundle::new(repro_input_name(self.input), self.source)
.file(device_name, device_bytes.to_vec())
.options(device_options);
.file("profile.json", self.profile.as_bytes().to_vec())
.options(["--profile", "profile.json"]);
let descriptors = [&self.args.stage_input, &self.args.vertex_descriptor];
for (path, (_, name)) in descriptors.into_iter().zip(DESCRIPTOR_FILES) {
// A descriptor file that cannot be read is the failure the bundle records: its replay
+6 -40
View File
@@ -1,13 +1,10 @@
//! FALLBACK repro bundles (feature `serde`): a directory that replays one refusal with the
//! `metal2vulkan` command line. The command line writes one for a failure after it read its
//! inputs; a runtime may write one for a library or pipeline creation it refuses, where
//! `METAL2VULKAN_REPRO_DIR` names a directory (`env_vars`). Not consumer API: the binary's and a
//! runtime's, hidden as `env_vars` is.
//! FALLBACK repro bundles (feature `cli`): a directory that replays one refusal with the
//! `metal2vulkan` command line, which writes one for a failure after it read its inputs, under
//! `METAL2VULKAN_REPRO_DIR` (`env_vars`). Not consumer API: the binary's, hidden as `env_vars` is.
//!
//! A bundle holds the input (`input.metallib`, `input.air`, `input.ll` or `input.bin`), the device
//! file (`profile.json`, which `--profile` reads, or `device.json`, which `--device` reads: a
//! [`ReproDevice`]), the descriptor files the command names (`stage-input.json`,
//! `vertex-descriptor.json`), the command (`repro-command.txt`, and `repro.sh`, which runs it from
//! A bundle holds the input (`input.metallib`, `input.air`, `input.ll` or `input.bin`), the
//! profile (`profile.json`, which `--profile` reads), the descriptor files the command names
//! (`stage-input.json`, `vertex-descriptor.json`), the command (`repro-command.txt`, and `repro.sh`, which runs it from
//! the bundle's directory) and `failure.txt`: why it failed, and each part of the request the
//! command does not replay ([`ReproBundle::unreplayed`]).
//!
@@ -24,37 +21,6 @@ use std::sync::atomic::{AtomicU64, Ordering};
use sha2::{Digest, Sha256};
use crate::cache::Hash256;
use crate::device::{DeviceDescription, DevicePolicy};
/// The device a runtime bundle's command compiles for, as `device.json` holds it and the command
/// line's `--device` reads it: the description and policy the runtime's compile device was built
/// from, which build the same `Device` (`Device::from_queries`).
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct ReproDevice {
pub description: DeviceDescription,
pub policy: DevicePolicy,
}
impl ReproDevice {
/// The device of `description` and `policy`.
pub fn new(description: DeviceDescription, policy: DevicePolicy) -> ReproDevice {
ReproDevice {
description,
policy,
}
}
/// The device's `device.json`.
pub fn to_json(&self) -> Result<Vec<u8>, String> {
serde_json::to_vec_pretty(self).map_err(|e| e.to_string())
}
/// The device a `device.json` holds.
pub fn from_json(json: &str) -> Result<ReproDevice, String> {
serde_json::from_str(json).map_err(|e| e.to_string())
}
}
/// One bundle, built in memory and written by [`write`](Self::write).
#[derive(Clone, Debug)]
-59
View File
@@ -15,7 +15,6 @@ use metal2vulkan::pipeline::{
ComputePipelineDescriptor, FunctionDescriptor, StageSource, VertexAttributeDescriptor,
VertexBufferLayoutDescriptor, VertexDescriptor,
};
use metal2vulkan::repro::ReproDevice;
use metal2vulkan::Budget;
fn repo() -> &'static Path {
@@ -458,61 +457,3 @@ fn a_bundle_carries_its_descriptor_files_and_replays_the_failure() {
"{replayed}"
);
}
/// `--device` reads a device description and policy as a runtime bundle's `device.json` holds
/// them, in place of `--profile`, and compiles the same pipeline the profile's device does; the
/// two together, or `--profile-name` with `--device`, are usage errors.
#[test]
fn a_device_file_takes_the_place_of_a_profile() {
let scratch = Scratch::new();
let json = std::fs::read_to_string(profile("moltenvk-m3")).unwrap();
let description = DeviceDescription::from_khronos_json(&json, None).unwrap();
let device_file = scratch.join("device.json");
std::fs::write(
&device_file,
ReproDevice::new(description, DevicePolicy::default())
.to_json()
.unwrap(),
)
.unwrap();
let input = fixture("ob3_texture_array.air");
let by_profile = scratch.join("profile.spv");
let by_device = scratch.join("device.spv");
for (output, flag, file) in [
(&by_profile, "--profile", profile("moltenvk-m3")),
(&by_device, "--device", device_file.clone()),
] {
let result = cli(
&scratch,
&[
input.as_os_str(),
output.as_os_str(),
os(flag),
file.as_os_str(),
os("--no-spirv-val"),
],
&[],
);
assert!(result.status.success(), "{}", text(&result.stderr));
}
assert_eq!(
std::fs::read(&by_profile).unwrap(),
std::fs::read(&by_device).unwrap()
);
let profile_path = profile("moltenvk-m3");
for extra in [
[os("--profile"), profile_path.as_os_str()],
[os("--profile-name"), os("any")],
] {
let mut args = vec![
input.as_os_str(),
by_device.as_os_str(),
os("--device"),
device_file.as_os_str(),
];
args.extend(extra);
let result = cli(&scratch, &args, &[]);
assert_eq!(result.status.code(), Some(2), "{}", text(&result.stderr));
assert!(text(&result.stderr).contains("--device"));
}
}