diff --git a/crates/metal2vulkan-validation/src/acceptance.rs b/crates/metal2vulkan-validation/src/acceptance.rs index a2be11e22..6c79a30b0 100644 --- a/crates/metal2vulkan-validation/src/acceptance.rs +++ b/crates/metal2vulkan-validation/src/acceptance.rs @@ -5,19 +5,19 @@ //! ([`PipelineLayout`](metal2vulkan::pipeline::PipelineLayout), vertex input, stage modules with //! their specialization and subgroup facts, the graphics state), with nothing bound or drawn. A //! kernel row is made as a guest's kernel is, through the runtime: its pipeline state on the -//! sweep's device and one dispatch of one representative threadgroup encoded, never committed -//! ([`crate::candidate::create_runtime_kernel`]). A row is built as [`PipelineRequest::Row`] says -//! ([`row`]): a kernel's compute pipeline; a vertex function's rasterization-disabled pipeline with -//! a vertex descriptor for the attributes it declares; a fragment function's rasterizing pipeline -//! drawn with its generated passthrough vertex companion ([`crate::companion`], the one the -//! executors draw with). +//! sweep's one runtime device and one dispatch of one representative threadgroup encoded, never +//! committed ([`crate::candidate::RuntimeKernels`]). A row is built as [`PipelineRequest::Row`] +//! says ([`row`]): a kernel's compute pipeline; a vertex function's rasterization-disabled +//! pipeline with a vertex descriptor for the attributes it declares; a fragment function's +//! rasterizing pipeline drawn with its generated passthrough vertex companion +//! ([`crate::companion`], the one the executors draw with). //! This module is the device-free half: compiling a row and deciding whether the opened device //! enabled and provides what the pipeline requires ([`unenabled`] for the API version, features, //! and extensions, by the product's `DeviceDescription::required_enables` on the opened //! description; [`unmet_device_facts`] for properties, limits, formats, stage create flags, and //! float-controls independence, against the opened device's queried profile). The device half is //! [`crate::candidate::create_acceptance_pipeline`] for a render row and -//! [`crate::candidate::create_runtime_kernel`] for a kernel row. +//! [`crate::candidate::RuntimeKernels`] for a kernel row. //! //! The sweep compiles every row in a killable worker ([`compile_row_in_worker`]), never in the //! process that holds the device; [`compile_pipeline`] is the compile the worker runs, and it @@ -103,7 +103,7 @@ fn stage_precision_notes(stages: &[StageModule]) -> Vec { /// An L4 row compiled: a kernel's compute pipeline, its module the words the sweep counts (the /// driver is asked for the pipeline the runtime makes of the row's AIR, -/// [`crate::candidate::create_runtime_kernel`]), or a render pipeline, created at its stages' +/// [`crate::candidate::RuntimeKernels`]), or a render pipeline, created at its stages' /// default specializations, of a `row` function. #[derive(Clone, Debug)] pub enum RowPipeline { @@ -913,7 +913,7 @@ pub enum Acceptance { NoEffect, } -/// A kernel row as the runtime makes it ([`crate::candidate::create_runtime_kernel`]): its AIR, +/// A kernel row as the runtime makes it ([`crate::candidate::RuntimeKernels`]): its AIR, /// its kernel, and the function-constant values the function is made with. pub struct RuntimeRow<'a> { pub bitcode: &'a [u8], diff --git a/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs b/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs index 6819ab724..c8a3d3ede 100644 --- a/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs +++ b/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs @@ -14,11 +14,12 @@ //! carries** (set layouts, push ranges, specialization, subgroup size, vertex input, graphics //! state), its stages at their default specialization, not the graphics plan's (a limit). A //! fragment function's attachments have no more channels than its outputs write. A kernel row is -//! made as a guest's kernel is, through the runtime (`candidate::create_runtime_kernel`): its -//! `ComputePipelineState` on the sweep's device, with the row's function-constant values, and one -//! dispatch of one representative threadgroup (the state's thread execution width of threads, or -//! its `maxTotalThreadsPerThreadgroup` where fewer) encoded into a command buffer that is never -//! committed, so the runtime asks the driver for the pipeline that threadgroup runs on. The +//! made as a guest's kernel is, through the runtime (`candidate::RuntimeKernels`): its +//! `ComputePipelineState` on the sweep's one runtime device, opened once for all its kernel rows, +//! with the row's function-constant values, and one dispatch of one representative threadgroup +//! (the state's thread execution width of threads, or its `maxTotalThreadsPerThreadgroup` where +//! fewer) encoded into a command buffer that is never committed, so the runtime asks the driver +//! for the pipeline that threadgroup runs on. The //! runtime's typed refusal (the translator's, a known gap, a device limit) is `RUNTIME_REFUSED`, //! counted; a kernel that writes no memory, whose dispatch the runtime runs as Metal's without //! effects and makes no pipeline for, is `NO_EFFECT`, counted. The make runs in this process, @@ -86,6 +87,7 @@ use metal2vulkan_validation::acceptance::{ }; use metal2vulkan_validation::budgets::PIPELINE_CREATION_CEILING; use metal2vulkan_validation::candidate::engine::graphics::RenderTemplate; +use metal2vulkan_validation::candidate::RuntimeKernels; use metal2vulkan_validation::engine::{self, FailureKind, Outcome, RowInput, RowSource}; use metal2vulkan_validation::gpu::wait::{parse_wait_timeout, set_wait_timeout}; use metal2vulkan_validation::gpu::DeviceType; @@ -765,6 +767,8 @@ fn sweep_new( } = sweep; let mut out = rows_output()?; let mut tally = Tally::default(); + // Opened at the sweep's first kernel row, and finished once the last row is done. + let mut kernels = None; let mut attempt = |row: NewRow| -> Result<(), String> { if tally.rows >= options.limit { return Ok(()); @@ -774,6 +778,7 @@ fn sweep_new( tally.row_compile = None; let (status, detail, create_ms) = attempt_row( device, + &mut kernels, worker, compiler, projection, @@ -865,6 +870,12 @@ fn sweep_new( }) })?; } + if let Some(kernels) = kernels { + if let Err(error) = kernels.finish() { + eprintln!("corpus-pipeline: the kernel rows' runtime device: {error}"); + tally.errors += 1; + } + } let (slowest_key, slowest_ms) = tally .slowest .as_ref() @@ -965,10 +976,12 @@ fn rows_output() -> Result, String> { } /// Compile one row in a compile worker and create its pipeline (a kernel row's, made through the -/// runtime from the row's AIR): `(STATUS, detail, create_ms)`. With `keep`, the compiled row's -/// stage modules are written there first ([`keep_modules`]). +/// runtime from the row's AIR on the sweep's one runtime device, `kernels`, opened at the first +/// kernel row): `(STATUS, detail, create_ms)`. With `keep`, the compiled row's stage modules are +/// written there first ([`keep_modules`]). fn attempt_row( device: Option, + kernels: &mut Option, worker: &CompileWorker, compiler: &WorkerDevice, projection: Projection, @@ -1080,7 +1093,14 @@ fn attempt_row( entry: &input.entry, constants: &constants, }; - metal2vulkan_validation::candidate::create_runtime_kernel(device, &kernel) + let kernels = match kernels { + Some(kernels) => kernels, + None => match RuntimeKernels::open(device) { + Ok(opened) => kernels.insert(opened), + Err(error) => return tally.record(key, detail, Err(error)), + }, + }; + kernels.accept(&kernel) } (RowPipeline::Compute { .. }, RowWork::Draw { .. }) => { return Err(format!( diff --git a/crates/metal2vulkan-validation/src/candidate.rs b/crates/metal2vulkan-validation/src/candidate.rs index 12b637a9d..2c8b485a1 100644 --- a/crates/metal2vulkan-validation/src/candidate.rs +++ b/crates/metal2vulkan-validation/src/candidate.rs @@ -30,15 +30,11 @@ pub fn create_acceptance_pipeline( platform::create_acceptance_pipeline(device, pipeline) } -/// Make a kernel row's pipeline state through the runtime on `device`, as a guest's kernel is -/// made, and encode one dispatch of one representative threadgroup of it, never committed, under -/// the validation layer: what the runtime and the driver answered. -pub fn create_runtime_kernel( - device: DeviceType, - row: &crate::acceptance::RuntimeRow<'_>, -) -> Result { - platform::create_runtime_kernel(device, row) -} +/// The sweep's one runtime device of a kind, opened under the validation layer: each kernel row's +/// pipeline state made on it, as a guest's kernel is made, and one dispatch of one representative +/// threadgroup of it encoded, never committed; what the runtime, the driver and the layer +/// answered. +pub use platform::RuntimeKernels; /// Restrict every Vulkan context this process opens to committed device profile `stem` through /// `VK_LAYER_KHRONOS_profiles` (a command's `--profiles-layer P`). Call it once, before any device @@ -139,13 +135,28 @@ mod platform { )) } - pub fn create_runtime_kernel( - _device: DeviceType, - _row: &crate::acceptance::RuntimeRow<'_>, - ) -> Result { - Err(crate::acceptance::AcceptanceError::DeviceUnavailable( - "pipeline creation is supported only on Linux and macOS".into(), - )) + /// No device opens here. + pub struct RuntimeKernels(std::convert::Infallible); + + impl RuntimeKernels { + pub fn open( + _device: DeviceType, + ) -> Result { + Err(crate::acceptance::AcceptanceError::DeviceUnavailable( + "pipeline creation is supported only on Linux and macOS".into(), + )) + } + + pub fn accept( + &mut self, + _row: &crate::acceptance::RuntimeRow<'_>, + ) -> Result { + match self.0 {} + } + + pub fn finish(self) -> Result<(), String> { + match self.0 {} + } } pub fn execute_engine( diff --git a/crates/metal2vulkan-validation/src/candidate/platform.rs b/crates/metal2vulkan-validation/src/candidate/platform.rs index 4603c184e..429061614 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform.rs @@ -30,7 +30,7 @@ pub use device::{capture_formats, echo_validation_messages, venue_check}; pub use profiles::{requested_restriction, restrict_devices_to}; pub use render::execute_engine_render; pub use runtime::execute_runtime; -pub use runtime_acceptance::create_runtime_kernel; +pub use runtime_acceptance::RuntimeKernels; pub use runtime_probe::probe_runtime; pub use runtime_render::execute_runtime_render; diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs index 83229dd42..e0bf6ad0f 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs @@ -72,7 +72,7 @@ use metal2vulkan::pipeline::{ use metal2vulkan_runtime as rt; use std::collections::BTreeMap; use std::ffi::CStr; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::time::{Duration, Instant}; /// The executor a row's environment names. @@ -139,16 +139,31 @@ pub(super) fn under_validation(on: impl FnOnce() -> Result) /// The layer's variables are put back as they were once `on` returns, so an instance the process /// makes after it (`corpus-pipeline`'s own context for its next render row) reads none of them. pub(super) fn validated(on: impl FnOnce() -> T) -> (T, Option) { - let log = std::env::temp_dir().join(format!( + let log = validation_log(); + let _ = std::fs::remove_file(&log); + let value = under_validation_variables(&log, on); + let messages = std::fs::read_to_string(&log); + let _ = std::fs::remove_file(&log); + let messages = messages.ok().filter(|messages| !messages.trim().is_empty()); + (value, messages) +} + +/// The one path this process's validation layer logs to. +pub(super) fn validation_log() -> PathBuf { + std::env::temp_dir().join(format!( "metal2vulkan-validation-runtime-{}.log", std::process::id() - )); - let _ = std::fs::remove_file(&log); + )) +} + +/// What `on` returns, every instance it makes under the validation layer with its messages logged +/// to `log` ([`validate_process`]), the layer's variables put back as they were once `on` returns. +pub(super) fn under_validation_variables(log: &Path, on: impl FnOnce() -> T) -> T { let before: Vec<_> = VALIDATION_VARIABLES .iter() .map(|&name| (name, std::env::var_os(name))) .collect(); - validate_process(&log); + validate_process(log); let value = on(); for (name, value) in before { match value { @@ -156,10 +171,7 @@ pub(super) fn validated(on: impl FnOnce() -> T) -> (T, Option) { None => std::env::remove_var(name), } } - let messages = std::fs::read_to_string(&log); - let _ = std::fs::remove_file(&log); - let messages = messages.ok().filter(|messages| !messages.trim().is_empty()); - (value, messages) + value } /// Enable the validation layer for this process's next instance, through the loader's and the @@ -234,28 +246,48 @@ pub(super) fn opened( body: impl FnOnce(&rt::Device, &Identity, &serde_json::Value) -> T, ) -> Result { let value = { - let (physical, identity) = select(instance, device_type, layered.profile())?; - let tools = runtime_restriction::tools_on(instance, &physical)?; - if !tools.iter().any(|tool| tool.layer == VALIDATION_LAYER) { - return Err(format!( - "{} lists no active validation tool: the loader found no {VALIDATION_LAYER}, and \ - a run never proceeds without it", - identity.device - )); - } - layered.checked(instance, &physical, &tools)?; - let environment = environment(&identity, &tools, executor, layered.record(&tools)); - let device = metal2vulkan_runtime::Device::new(&physical, rt::DeviceOptions::default()) - .map_err(|error| format!("the runtime's device on {}: {error}", identity.device))?; + let (device, identity, environment) = + made_device(instance, device_type, executor, layered)?; body(&device, &identity, &environment) }; - if !instance.wait_until_devices_torn_down(TEARDOWN) { + torn_down(instance)?; + Ok(value) +} + +/// The runtime's device of `device_type` from `instance`, made under `layered`, with the identity +/// and environment a row of `executor` records of it. `Err` where no device of the kind opens +/// under the layers, or the validation layer is not active on it. +pub(super) fn made_device( + instance: &rt::Instance, + device_type: DeviceType, + executor: &'static str, + layered: &Layered, +) -> Result<(rt::Device, Identity, serde_json::Value), String> { + let (physical, identity) = select(instance, device_type, layered.profile())?; + let tools = runtime_restriction::tools_on(instance, &physical)?; + if !tools.iter().any(|tool| tool.layer == VALIDATION_LAYER) { return Err(format!( - "the runtime's device did not tear down within {} s", - TEARDOWN.as_secs() + "{} lists no active validation tool: the loader found no {VALIDATION_LAYER}, and a run \ + never proceeds without it", + identity.device )); } - Ok(value) + layered.checked(instance, &physical, &tools)?; + let environment = environment(&identity, &tools, executor, layered.record(&tools)); + let device = metal2vulkan_runtime::Device::new(&physical, rt::DeviceOptions::default()) + .map_err(|error| format!("the runtime's device on {}: {error}", identity.device))?; + Ok((device, identity, environment)) +} + +/// `Ok` once every device made from `instance` is torn down, `Err` past [`TEARDOWN`]. +pub(super) fn torn_down(instance: &rt::Instance) -> Result<(), String> { + if instance.wait_until_devices_torn_down(TEARDOWN) { + return Ok(()); + } + Err(format!( + "the runtime's device did not tear down within {} s", + TEARDOWN.as_secs() + )) } /// What a row records of the device that ran it. diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime_acceptance.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime_acceptance.rs index 6b25a1d96..456e7a21d 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime_acceptance.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime_acceptance.rs @@ -1,7 +1,8 @@ -//! Driver acceptance (L4) of a kernel row through the runtime, as a guest's kernel is made: the -//! row's AIR as a library, its function specialized with the row's function-constant values, one -//! `ComputePipelineState` on the sweep's device (restricted to the process's profile where it is, -//! `runtime_restriction`), and one dispatch of one representative threadgroup, encoded into a +//! Driver acceptance (L4) of kernel rows through the runtime, as a guest's kernels are made: on +//! the sweep's one runtime device ([`RuntimeKernels`], opened once for the sweep's device kind, +//! restricted to the process's profile where it is, `runtime_restriction`), each row's AIR as a +//! library, its function specialized with the row's function-constant values, one +//! `ComputePipelineState`, and one dispatch of one representative threadgroup, encoded into a //! command buffer that is never committed, so nothing executes. //! //! The representative threadgroup is the state's thread execution width of threads (32), or its @@ -12,57 +13,154 @@ //! no pipeline (`Metrics::dispatches_without_effects`): [`Acceptance::NoEffect`]. //! //! The make is held to the per-attempt ceilings (`runtime::within_ceilings`), either past it a -//! tooling error. Each attempt opens its own device under `VK_LAYER_KHRONOS_validation` -//! (`runtime::validated`); any message the layer logs makes the row [`Acceptance::InvalidUsage`]. -//! The runtime's typed refusal of the row on the device (the translator's, a known gap, a limit) -//! is [`Acceptance::RuntimeRefused`]; a Vulkan error of the make or the dispatch, the driver's, -//! [`Acceptance::Refused`]. +//! tooling error. The device's instance is made under `VK_LAYER_KHRONOS_validation`, whose +//! variables are set only while it is made (`runtime::under_validation_variables`); the layer logs +//! to the process's one log for the device's life. A row's messages are what the log gained while +//! the row's state was made and dispatched and its objects dropped: any makes the row +//! [`Acceptance::InvalidUsage`]. A message logged while the device opens stops the sweep before +//! any row, since no row on that device would be evidence; one logged at its teardown fails the +//! sweep ([`RuntimeKernels::finish`]). The runtime's typed refusal of a row on the device (the +//! translator's, a known gap, a limit) is [`Acceptance::RuntimeRefused`]; a Vulkan error of the +//! make or the dispatch, the driver's, [`Acceptance::Refused`]. -use super::runtime::{self, sampler_grant}; +use super::runtime::{self, sampler_grant, VALIDATION_LAYER}; use super::runtime_restriction; use crate::acceptance::{Acceptance, AcceptanceError, RuntimeRow}; +use crate::engine::bounded_detail; use crate::gpu::DeviceType; use metal2vulkan::library::Library; use metal2vulkan::pipeline::{ComputePipelineDescriptor, FunctionDescriptor, StageSource}; use metal2vulkan_runtime as rt; +use std::io::{Read, Seek, SeekFrom}; +use std::path::PathBuf; use std::time::Duration; /// The executor a row's environment names. const EXECUTOR: &str = "runtime-acceptance"; -/// Make `row`'s pipeline state on the runtime's device of `device_type` and encode one dispatch of -/// it, as the module documentation says, and report what the runtime and the driver did. Only -/// opening the device (none of the kind, the hang tripwire, a restriction it cannot take) is -/// [`AcceptanceError::DeviceUnavailable`]. -pub fn create_runtime_kernel( +/// The sweep's one runtime device of its kind, every kernel row's state made and dispatched on +/// it, as the module documentation says. +pub struct RuntimeKernels { + // Dropped before its instance. + device: rt::Device, + instance: rt::Instance, device_type: DeviceType, - row: &RuntimeRow<'_>, -) -> Result { - let (created, messages) = runtime::validated(|| attempt(device_type, row)); - match (created, messages) { - (Ok(_), Some(messages)) => Ok(Acceptance::InvalidUsage(vec![ - crate::engine::bounded_detail(&messages), - ])), - (created, _) => created, + log: Log, +} + +impl RuntimeKernels { + /// The runtime's device of `device_type`, under the validation layer and the process's + /// restriction. Only a device that cannot be used (none of the kind, the hang tripwire, a + /// restriction it cannot take, a message the layer logs while it opens) is + /// [`AcceptanceError::DeviceUnavailable`]. + pub fn open(device_type: DeviceType) -> Result { + let unavailable = AcceptanceError::DeviceUnavailable; + if device_type == DeviceType::Gpu { + crate::gpu::tripwire::refuse_if_tripped().map_err(unavailable)?; + } + let layered = + match runtime_restriction::layered(device_type, EXECUTOR).map_err(unavailable)? { + Ok(layered) => layered, + Err(refused) => return Err(unavailable(refused.to_string())), + }; + let log = Log::new(); + let (instance, device) = runtime::under_validation_variables(&log.path, || { + layered.instance(|instance| { + let (device, _, _) = + runtime::made_device(instance, device_type, EXECUTOR, &layered)?; + Ok((instance.clone(), device)) + }) + }) + .map_err(unavailable)?; + let mut kernels = RuntimeKernels { + device, + instance, + device_type, + log, + }; + if let Some(messages) = kernels.log.unread().map_err(unavailable)? { + return Err(unavailable(format!( + "{VALIDATION_LAYER} reported messages while the runtime's device opened, so no \ + row on it is evidence: {}", + bounded_detail(&messages) + ))); + } + Ok(kernels) + } + + /// Make `row`'s pipeline state on the sweep's device and encode one dispatch of it, and report + /// what the runtime, the driver and the layer answered. The hang tripwire set is + /// [`AcceptanceError::DeviceUnavailable`]. + pub fn accept(&mut self, row: &RuntimeRow<'_>) -> Result { + if self.device_type == DeviceType::Gpu { + crate::gpu::tripwire::refuse_if_tripped() + .map_err(AcceptanceError::DeviceUnavailable)?; + } + let result = made(&self.device, row); + match (result, self.log.unread().map_err(AcceptanceError::Tooling)?) { + (Ok(_), Some(messages)) => { + Ok(Acceptance::InvalidUsage(vec![bounded_detail(&messages)])) + } + (result, _) => result, + } + } + + /// Drop the device and wait for its teardown: `Err` past the wait, or with what the layer + /// logged after the last row. + pub fn finish(self) -> Result<(), String> { + let RuntimeKernels { + device, + instance, + mut log, + .. + } = self; + drop(device); + runtime::torn_down(&instance)?; + match log.unread()? { + None => Ok(()), + Some(messages) => Err(format!( + "{VALIDATION_LAYER} reported messages at the runtime's device's teardown: {}", + bounded_detail(&messages) + )), + } } } -/// [`create_runtime_kernel`]'s attempt, under the validation layer. -fn attempt(device_type: DeviceType, row: &RuntimeRow<'_>) -> Result { - let unavailable = AcceptanceError::DeviceUnavailable; - if device_type == DeviceType::Gpu { - crate::gpu::tripwire::refuse_if_tripped().map_err(unavailable)?; +/// The validation layer's log for the device's life, removed with it, and how much of it the +/// sweep has read. +struct Log { + path: PathBuf, + read: u64, +} + +impl Log { + fn new() -> Log { + let path = runtime::validation_log(); + let _ = std::fs::remove_file(&path); + Log { path, read: 0 } + } + + /// What the layer logged since the last read, if anything. + fn unread(&mut self) -> Result, String> { + let failed = |error: std::io::Error| format!("read {}: {error}", self.path.display()); + let mut file = match std::fs::File::open(&self.path) { + Ok(file) => file, + Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None), + Err(error) => return Err(failed(error)), + }; + file.seek(SeekFrom::Start(self.read)).map_err(failed)?; + let mut bytes = Vec::new(); + file.read_to_end(&mut bytes).map_err(failed)?; + self.read += bytes.len() as u64; + let text = String::from_utf8_lossy(&bytes); + Ok((!text.trim().is_empty()).then(|| text.into_owned())) + } +} + +impl Drop for Log { + fn drop(&mut self) { + let _ = std::fs::remove_file(&self.path); } - let layered = match runtime_restriction::layered(device_type, EXECUTOR).map_err(unavailable)? { - Ok(layered) => layered, - Err(refused) => return Err(AcceptanceError::DeviceUnavailable(refused.to_string())), - }; - let opened = layered.instance(|instance| { - runtime::opened(instance, device_type, EXECUTOR, &layered, |device, _, _| { - made(device, row) - }) - }); - opened.map_err(unavailable)? } /// `row`'s state made on `device`, and its dispatch encoded. diff --git a/crates/metal2vulkan-validation/src/candidate/tests/acceptance_pipelines.rs b/crates/metal2vulkan-validation/src/candidate/tests/acceptance_pipelines.rs index e5f62ddab..65741a27f 100644 --- a/crates/metal2vulkan-validation/src/candidate/tests/acceptance_pipelines.rs +++ b/crates/metal2vulkan-validation/src/candidate/tests/acceptance_pipelines.rs @@ -1,7 +1,8 @@ //! L4 driver acceptance on a device: the unsafe creation path of [`create_acceptance_pipeline`] //! (set layouts, binding flags, specialization, subgroup size, render pass, graphics pipeline) runs -//! against the lane's Vulkan device for a render row, and a kernel row is made through the runtime -//! ([`create_runtime_kernel`]). Nothing is bound or submitted, so no shader executes. +//! against the lane's Vulkan device for a render row, and kernel rows are made through the runtime +//! on one runtime device ([`RuntimeKernels`]). Nothing is bound or submitted, so no shader +//! executes. //! `G-linux`'s `m2v_cpu_icd` step runs it on lavapipe. //! //! Each render row compiles for the opened device's own `Device` (its queried description @@ -53,21 +54,34 @@ fn assert_accepted(pipeline: &RowPipeline) { } #[cfg(target_os = "linux")] -/// What the runtime answered for kernel row `entry` of the owned fixture `file`, made on the -/// lane's device as `corpus-pipeline` makes a kernel row, with no function-constant values. A +/// What the runtime answered for each kernel row `(file, entry)` of the owned fixtures, made one +/// after another on one runtime device of the lane, as `corpus-pipeline` makes its kernel rows, +/// with no function-constant values; the device finished with nothing logged at its teardown. A /// device lane has `llvm-as`, so a missing assembler fails the test. -fn made(file: &str, entry: &str) -> Acceptance { - let bitcode = llvm_assemble(&engine_dir().join(file)) - .unwrap_or_else(|error| panic!("assemble {file}: {error:?}")); +fn made(rows: &[(&str, &str)]) -> Vec { + let mut kernels = RuntimeKernels::open(crate::gpu::TEST_DEVICE) + .unwrap_or_else(|error| panic!("open the lane's runtime device: {error}")); let constants = FunctionConstantValues::defaults(); - let row = RuntimeRow { - bitcode: &bitcode, - entry, - constants: &constants, - }; - let made = create_runtime_kernel(crate::gpu::TEST_DEVICE, &row) - .unwrap_or_else(|error| panic!("{entry}: {error}")); - eprintln!("{entry}: {made:?}"); + let made = rows + .iter() + .map(|&(file, entry)| { + let bitcode = llvm_assemble(&engine_dir().join(file)) + .unwrap_or_else(|error| panic!("assemble {file}: {error:?}")); + let row = RuntimeRow { + bitcode: &bitcode, + entry, + constants: &constants, + }; + let made = kernels + .accept(&row) + .unwrap_or_else(|error| panic!("{entry}: {error}")); + eprintln!("{entry}: {made:?}"); + made + }) + .collect(); + kernels + .finish() + .unwrap_or_else(|error| panic!("finish the lane's runtime device: {error}")); made } @@ -92,12 +106,19 @@ fn accepted(acceptance: Result) } } -/// A kernel row is made through the runtime, and the driver creates the pipeline its dispatch -/// runs on; a vertex function alone is created from the binder layout. +/// Kernel rows are made through the runtime one after another on one runtime device, and the +/// driver creates the pipeline each one's dispatch runs on; a vertex function alone is created +/// from the binder layout. #[cfg(target_os = "linux")] #[test] -fn a_kernel_row_is_made_through_the_runtime_and_a_vertex_only_pipeline_is_created() { - accepted(Ok(made("store_const.ll", "store_const"))); +fn kernel_rows_are_made_through_the_runtime_on_one_device_and_a_vertex_only_pipeline_is_created() { + let rows = [ + ("store_const.ll", "store_const"), + ("a1_pack_rounding.ll", "a1_pack_rounding"), + ]; + for made in made(&rows) { + accepted(Ok(made)); + } let vertex = compiled( "stage_io.ll", @@ -116,7 +137,9 @@ fn a_kernel_row_is_made_through_the_runtime_and_a_vertex_only_pipeline_is_create #[cfg(target_os = "linux")] #[test] fn a_full_subgroup_kernel_row_is_made_through_the_runtime() { - accepted(Ok(made("simd_ops.ll", "simd_shuffle_k"))); + for made in made(&[("simd_ops.ll", "simd_shuffle_k")]) { + accepted(Ok(made)); + } } /// A kernel with an explicit imageblock is the runtime's typed refusal, as a guest's is: its @@ -124,7 +147,7 @@ fn a_full_subgroup_kernel_row_is_made_through_the_runtime() { #[cfg(target_os = "linux")] #[test] fn an_imageblock_kernel_row_is_the_runtimes_refusal() { - let made = made("a4_imageblock_extent.ll", "a4_imageblock_extent"); + let made = made(&[("a4_imageblock_extent.ll", "a4_imageblock_extent")]).remove(0); assert!( matches!(&made, Acceptance::RuntimeRefused(why) if why.contains("mageblock")), "{made:?}" diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 6a85176f1..7e0c24f66 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -415,9 +415,11 @@ Other corpus tools: the real cards. It compiles each row in a compile worker, then asks the device's driver for its pipeline. A render row's pipeline is created from the binder layout its artifact carries, with nothing drawn. A kernel row is made as a guest's kernel is, through the runtime: its - `ComputePipelineState` on the device, and one dispatch of one representative threadgroup (the - state's thread execution width of threads) encoded into a command buffer that is never - committed, so the driver is asked for the pipeline that dispatch runs on and nothing executes. + `ComputePipelineState` on the one runtime device the sweep opens for all its kernel rows, and + one dispatch of one representative threadgroup (the state's thread execution width of threads) + encoded into a command buffer that is never committed, so the driver is asked for the pipeline + that dispatch runs on and nothing executes. A message the validation layer logs during a row + makes that row `INVALID_USAGE`. The runtime's typed refusal of a kernel row is `RUNTIME_REFUSED`, and a kernel that writes no memory, which the runtime makes no pipeline for, is `NO_EFFECT`; both are counted. - `--profiles-layer P` (on `corpus-vulkan` and `corpus-pipeline`) runs every context through