diff --git a/README.md b/README.md index 087f39458..f92df0dc2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/crates/metal2vulkan/src/lib.rs b/crates/metal2vulkan/src/lib.rs index fce85eebd..cc41504d0 100644 --- a/crates/metal2vulkan/src/lib.rs +++ b/crates/metal2vulkan/src/lib.rs @@ -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)] diff --git a/crates/metal2vulkan/src/main.rs b/crates/metal2vulkan/src/main.rs index a514b0873..064d11a35 100644 --- a/crates/metal2vulkan/src/main.rs +++ b/crates/metal2vulkan/src/main.rs @@ -3,8 +3,7 @@ //! the library's API (`Device::compile_compute_pipeline`, `compile_render_pipeline`, and //! `compile_tile_pipeline`). //! -//! Usage: `metal2vulkan [out.spv] --profile [options]`, -//! or `--device ` in place of `--profile` (the device a runtime repro bundle names). +//! Usage: `metal2vulkan [out.spv] --profile [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 [out.spv] --profile [options]"; const HELP: &str = r#"usage: metal2vulkan [out.spv] --profile [options] - metal2vulkan [out.spv] --device [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 .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, profile: Option, profile_name: Option, - device: Option, function: Option, fragment: Option, constants: Vec<(String, FunctionConstantValue)>, @@ -126,8 +96,7 @@ struct Args { timeout: Option, emit_meta: Option, 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, } @@ -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 { - 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 { 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 diff --git a/crates/metal2vulkan/src/repro.rs b/crates/metal2vulkan/src/repro.rs index ec602251c..39868f58d 100644 --- a/crates/metal2vulkan/src/repro.rs +++ b/crates/metal2vulkan/src/repro.rs @@ -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, 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 { - 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)] diff --git a/crates/metal2vulkan/tests/cli.rs b/crates/metal2vulkan/tests/cli.rs index 258c61a49..a03f3989c 100644 --- a/crates/metal2vulkan/tests/cli.rs +++ b/crates/metal2vulkan/tests/cli.rs @@ -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")); - } -}