diff --git a/crates/metal2vulkan-validation/README.md b/crates/metal2vulkan-validation/README.md index 25244dd45..c19c89985 100644 --- a/crates/metal2vulkan-validation/README.md +++ b/crates/metal2vulkan-validation/README.md @@ -136,7 +136,9 @@ vertex or primitive and writes no device memory: it has no effect a stage observ without rasterization and its case observes the empty output (`"output": {"kind": "none"}`). The Metal oracle draws a case through `MTLMeshRenderPipelineDescriptor` and the case's own stage's setters. The engine's candidate does not draw one: an object or mesh case requires `mesh_render_pipeline`, which no candidate -runs, so its Metal observation stands with its Vulkan side unsupported. An object case's +runs, so its Metal observation stands with its Vulkan side unsupported. The authored compile +census still compiles its mesh render pipeline, as the candidate would build it, on each +profile-leg. An object case's `threadgroup_memory` sets its arguments' lengths through `setObjectThreadgroupMemoryLength:atIndex:`. Dynamic Metal `threadgroup` arguments are declared through `threadgroup_memory` binding/length diff --git a/crates/metal2vulkan-validation/src/authored_compile.rs b/crates/metal2vulkan-validation/src/authored_compile.rs index b04d4965d..a1b96365e 100644 --- a/crates/metal2vulkan-validation/src/authored_compile.rs +++ b/crates/metal2vulkan-validation/src/authored_compile.rs @@ -9,7 +9,9 @@ //! census closes that gap: //! //! - **The request.** A case is admitted and prepared by the executor's own device-free half -//! (`engine::prepare_case`), and every pipeline a run compiles before it reads device output +//! (`engine::prepare_compile`: its run's preparation, except that an object or mesh case, whose +//! mesh render pipeline the executor does not draw, is prepared to compile it), and every +//! pipeline a run compiles before it reads device output //! comes from `engine::case_compiles`: the case's own, and on a device where the device //! replay runs, each registered replay variant. Each compiles in a compile worker (the 20-s and //! 500-MiB per-attempt ceilings, a process-group kill). The pipelines of host-replayed commands @@ -46,7 +48,8 @@ use crate::candidate::engine::artifact::CaseArtifact; use crate::candidate::engine::{ - case_compiles, prepare_case, CompileFailure, CompileSubject, PreparedCase, ENGINE_EXECUTOR_ABI, + case_compiles, prepare_compile, CompileFailure, CompileSubject, PreparedCase, + ENGINE_EXECUTOR_ABI, }; use crate::case::AuthoredCase; use crate::check::admission::{admit, ExecutionRequest, ExecutorError, NotSupported}; @@ -86,7 +89,10 @@ mod tests; /// replay its templates, each executed command buffer uncovered (`engine::case_compiles`). /// 5: an object or mesh case compiles its mesh render pipeline, where it was refused /// (`engine::mesh::mesh_request`). -pub const AUTHORED_COMPILE_CENSUS_VERSION: u32 = 5; +/// 6: an object or mesh case whose only stop is that the executor draws no mesh render pipeline +/// (`mesh_render_pipeline`) compiles it, where the run's preparation refuses it +/// (`engine::prepare_compile`). +pub const AUTHORED_COMPILE_CENSUS_VERSION: u32 = 6; /// The expectation file's name under the corpus root (`validation/corpus`). pub const EXPECTATIONS: &str = "authored-compile.tsv"; @@ -461,9 +467,9 @@ pub trait CaseCompiler: Sync { fn compile(&self, case: &AuthoredCase, profiles: &[&CensusProfile]) -> CaseResult; } -/// The executor's admission and preparation of `case` over the corpus at `root`, then every -/// pipeline [`case_compiles`] lists for each of `devices`, each in a compile worker of `worker`: -/// one cell per device, in order. +/// The executor's admission and compile preparation ([`prepare_compile`]) of `case` over the +/// corpus at `root`, then every pipeline [`case_compiles`] lists for each of `devices`, each in a +/// compile worker of `worker`: one cell per device, in order. pub fn compile_case( root: &Path, worker: &CompileWorker, @@ -478,7 +484,7 @@ pub fn compile_case( case.clone(), ExecutionRequest::EngineCandidate { device }, ) - .and_then(|admitted| prepare_case(device, admitted)); + .and_then(|admitted| prepare_compile(device, admitted)); match prepared { Ok(prepared) => devices .iter() diff --git a/crates/metal2vulkan-validation/src/candidate/engine.rs b/crates/metal2vulkan-validation/src/candidate/engine.rs index 6454c67e5..77aa9f797 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine.rs @@ -1992,7 +1992,8 @@ pub fn execute_case( ) } -/// An admitted case that passed the executor's device-free checks ([`prepare_case`]). +/// An admitted case that passed the executor's device-free checks ([`prepare_case`]), or the +/// compile census's ([`prepare_compile`]). pub struct PreparedCase { device: DeviceType, checked: CheckedCase, @@ -2378,9 +2379,34 @@ enum Mapped { pub fn prepare_case( device: DeviceType, admitted: AdmittedCase, +) -> Result { + prepare(device, admitted, false) +} + +/// [`prepare_case`] for the authored compile census (`authored_compile`): a case whose only stop +/// is the mesh render pipeline the executor does not draw +/// ([`ToolingRequirement::MeshRenderPipeline`]) is prepared too, its draw mapped +/// ([`mesh::mesh_case`]), so [`case_compiles`] lists the pipeline a run of it would compile. A +/// run's preparation refuses such a case before any device, its device worker's included. +pub fn prepare_compile( + device: DeviceType, + admitted: AdmittedCase, +) -> Result { + prepare(device, admitted, true) +} + +/// [`prepare_case`], or with `compile_only` [`prepare_compile`]. +fn prepare( + device: DeviceType, + admitted: AdmittedCase, + compile_only: bool, ) -> Result { let checked = admitted.into_checked_for(ExecutionRequest::EngineCandidate { device })?; - crate::executor_contract::require_executor(&checked.requirements(), Executor::EngineCandidate) + let mut requirements = checked.requirements(); + if compile_only { + requirements.remove(&ToolingRequirement::MeshRenderPipeline); + } + crate::executor_contract::require_executor(&requirements, Executor::EngineCandidate) .map_err(NotSupported::Requirements)?; let case = &checked.primary.case; let mapped = match case.stage { @@ -2876,7 +2902,8 @@ fn run_on_context(prepared: &PreparedCase, backend: Backend, worker: &CompileWor backend, ) } - // The checker's requirements refuse a mesh case before it maps (`prepare_case`). + // A run's preparation refuses a mesh case before it maps (`prepare_case`); only the + // compile census prepares one (`prepare_compile`). Mapped::Mesh(_) => RunAttempt::of(Err(NotSupported::Requirements( [ToolingRequirement::MeshRenderPipeline].into(), ) diff --git a/crates/metal2vulkan-validation/src/requirement.rs b/crates/metal2vulkan-validation/src/requirement.rs index 8e51e6c36..e3f4c6f8f 100644 --- a/crates/metal2vulkan-validation/src/requirement.rs +++ b/crates/metal2vulkan-validation/src/requirement.rs @@ -125,7 +125,9 @@ pub enum ToolingRequirement { DepthOutsideUnitRange, /// An object or mesh function's row or case (`executor_contract::mesh`), or a case that runs a /// pipeline template of one: the engine's candidate draws no mesh render pipeline. The Metal - /// oracle draws it, so a case of it stays Metal-qualified ([`Self::qualifies_on_metal`]). + /// oracle draws it, so a case of it stays Metal-qualified ([`Self::qualifies_on_metal`]), and + /// the authored compile census still compiles an object or mesh case's pipeline + /// (`engine::prepare_compile`). MeshRenderPipeline, /// A replayed pipeline template the engine's candidate does not replay /// (`candidate::engine::replay_templates`): a compute template that binds more than buffers diff --git a/crates/metal2vulkan-validation/tests/integration/authored_compile_census.rs b/crates/metal2vulkan-validation/tests/integration/authored_compile_census.rs index 9fa4ea56f..3c5ce26aa 100644 --- a/crates/metal2vulkan-validation/tests/integration/authored_compile_census.rs +++ b/crates/metal2vulkan-validation/tests/integration/authored_compile_census.rs @@ -328,3 +328,71 @@ fn case_compiles_lists_the_replay_variants_where_the_device_replay_runs() { assert_eq!(drawn.host_replayed, 1); assert_eq!(drawn.compiles.len(), 1); } + +/// An object or mesh case, which no candidate draws (`mesh_render_pipeline`), still compiles its +/// mesh render pipeline in the census: a run's preparation refuses the committed public mesh and +/// object cases by that requirement alone, the census's prepares them, and each one's pipeline, +/// its partners' stages with it, compiles in the worker as its one compile. +#[test] +fn the_census_compiles_the_mesh_pipelines_no_candidate_draws() { + use metal2vulkan_validation::authored_compile::{compile_case, CensusProfile}; + use metal2vulkan_validation::candidate::engine::{ + case_compiles, prepare_case, prepare_compile, CompileSubject, + }; + use metal2vulkan_validation::check::admission::{ + admit, ExecutionRequest, ExecutorError, NotSupported, + }; + use metal2vulkan_validation::gpu::DeviceType; + use metal2vulkan_validation::requirement::ToolingRequirement; + if !llvm_as_available() { + return; + } + let worker = { + let program = bin_exe!("corpus-triage"); + let _ = Command::new(&program).arg("--help").output(); + CompileWorker::program(program) + }; + let lavapipe = CensusProfile::load(&ProfileLeg::parse("lavapipe").unwrap()).unwrap(); + let device = DeviceType::Cpu; + for name in [ + "a-mesh-grid-of-threadgroups-draws-through-its-fragment", + "an-object-function-launches-its-mesh-partner-with-a-payload", + ] { + let (scratch, case) = corpus_with_templates(name); + let admitted = || { + admit( + scratch.path(), + case.clone(), + ExecutionRequest::EngineCandidate { device }, + ) + .unwrap_or_else(|error| panic!("{name}: admission: {error}")) + }; + let refused = prepare_case(device, admitted()).err(); + assert!( + matches!(&refused, Some(ExecutorError::NotSupported(NotSupported::Requirements(stops))) + if stops.iter().eq([&ToolingRequirement::MeshRenderPipeline])), + "{name}: {refused:?}" + ); + let prepared = prepare_compile(device, admitted()) + .unwrap_or_else(|error| panic!("{name}: preparation: {error}")); + let planned = case_compiles(&prepared, &lavapipe.device).unwrap(); + assert_eq!(planned.host_replayed, 0, "{name}"); + assert_eq!( + planned + .compiles + .iter() + .map(|compile| compile.subject) + .collect::>(), + [CompileSubject::Case], + "{name}" + ); + let cells = compile_case(scratch.path(), &worker, &case, &[&lavapipe.device]); + assert_eq!(cells.len(), 1, "{name}"); + assert_eq!( + cells[0].outcome, + Ok(CellOutcome::Compiled), + "{name}: {cells:?}" + ); + assert_eq!(cells[0].compiles, 1, "{name}"); + } +}