Files
metal2vulkan/crates/metal2vulkan-validation/src/lib.rs
T
Anees Iqbal 0175289314 Batch the development-fast round: tessellation without tessellationShader, primitive ids, mesh tooling, color groups, the vk12 floor, runtime timing and teardown fixes
One commit of the 247 on development-fast (720ef1ce9a..9f46fdf80d), squashed at the user's request.

Translator:
- Tessellation on a device without tessellationShader: Metal's tessellator emitted as SPIR-V, a
  one-workgroup scan placing each patch's triangles in Metal's order, and the post-tessellation
  function as a plain vertex stage (EmulatedTessellationDraws; SEMANTICS 1739, ARTIFACT_FORMAT 419).
- [[primitive_id]] on a device without geometry or tessellation shaders, as a flat varying the
  vertex function writes; indexed lists, lines and points drawn de-indexed (RuntimeGap::PrimitiveIdIndices).
- Fragment functions of more colors than the device draws at once, compiled in color groups
  (PrecisionNote::ColorAttachmentGroups).
- Object functions' threadgroup memory from the render encoder; a kernel's mesh draws from an
  indirect command buffer; mesh payload sizing.
- The Vulkan 1.2 floor profile (vk12-floor) and the gates it needs; Metal 27.0.1 answers as the M3 Max.
- Overflow tests in the runtime-built modules by the product's high word (NVIDIA's compiler fails
  the division form), guarded crate-wide by tests::owned_divisions.

Runtime:
- Color-group passes replayed per group over twin depth/stencil; snapshot and copy-back cost cuts.
- Command buffers finish on the queue waiter that saw them; the waiter holds no device handle, so
  a program's drop after its wait is the device's last.
- Every object an encoder was handed held until its command buffer completes; deallocator order
  and announcements.
- Driver defects recorded and announced: ANV counts a visibility sample once per color output
  (visibility-count-per-color); MoltenVK fails pending work when memory that held a device-address
  buffer is freed, so freed memory waits for the work in flight (host-deallocator-delayed).
- RenderCommandEncoder::set_object_threadgroup_memory_length; Visibility::counting().

Validation: mesh tooling (object, mesh and ICB-mesh cases on both executors), the authoring
census closed, the queue storm judged in Metal's unit, load-robust exits and indirect-census
bounds, and the golden hashes, printouts, fixture inventory and authored compile census blessed.

Docs: FAST-PATHS.md trimmed to a ledger of what is true now; API.md's catalogue and accepted
differences, REFUSALS.md and METAL-COVERAGE.md current.

Verified on development-fast before the squash: the full suites on the RTX 5080, RTX 3090,
RX 7900 XTX, Radeon 780M, Iris Xe, lavapipe and the M3 (MoltenVK and the Metal oracle), lint in
every configuration, rustdoc, doc tests, packaging and public case qualification; the timing and
teardown lanes x5 on every venue; the authoring-capability census 16656/16656 with 0 unresolved,
the vk12-floor translation census at 6139 translated with the slowest row 794 ms and peak 126 MiB.
The tree is development-fast's at 9f46fdf80d.
2026-10-16 11:12:03 +03:00

143 lines
3.5 KiB
Rust

//! Authored-case validation infrastructure for metal2vulkan.
//!
//! Harvesting, manifests, observations, and translation A/B are deliberately separate. Nothing in
//! this crate infers execution inputs or repairs a manifest.
pub mod acceptance;
pub mod air;
pub mod air_library;
pub mod air_writer;
pub mod authored_compile;
pub mod bitcode_audit;
pub mod budgets;
pub mod c1;
pub mod c3;
pub mod call_targets;
pub mod candidate;
pub mod case;
pub mod census;
pub mod check;
pub mod companion;
pub mod coverage;
pub mod cutover;
pub mod engine;
pub mod executor_contract;
pub mod gpu;
pub mod hash;
pub mod index;
pub mod jsonl;
pub mod l3;
pub mod library_module;
pub mod literal;
#[cfg(test)]
mod mesh_cases;
pub mod metal;
pub mod msl_portability;
pub mod no_effect;
pub mod observation;
pub mod observation_contract;
pub mod oracle_fuel;
#[cfg(test)]
mod parity;
pub mod pool;
pub mod refusal;
pub mod requirement;
pub mod runtime_lane;
pub mod source;
pub mod specialization;
pub mod spirv_tools;
pub mod store;
pub mod translation_audit;
pub mod triage;
pub mod vulkan_batch;
pub mod worker;
// The build's own fingerprint functions (this crate's `build.rs`), so tests can show which files
// feed each fingerprint.
#[cfg(test)]
#[path = "../build_support.rs"]
mod build_support;
#[cfg(test)]
mod build_support_tests;
#[cfg(test)]
#[path = "../product_fingerprint.rs"]
mod product_fingerprint;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
static SCRATCH_COUNTER: AtomicU64 = AtomicU64::new(0);
pub struct ScratchDir {
path: PathBuf,
}
impl ScratchDir {
pub fn new(purpose: &str) -> Result<Self, String> {
let safe: String = purpose
.chars()
.map(|ch| {
if ch.is_ascii_alphanumeric() || matches!(ch, '-' | '_') {
ch
} else {
'_'
}
})
.collect();
loop {
let serial = SCRATCH_COUNTER.fetch_add(1, Ordering::Relaxed);
let path = std::env::temp_dir().join(format!(
"metal2vulkan-validation-{}-{serial}-{safe}",
std::process::id()
));
match fs::create_dir(&path) {
Ok(()) => return Ok(Self { path }),
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(error) => return Err(format!("create {}: {error}", path.display())),
}
}
}
pub fn path(&self) -> &Path {
&self.path
}
}
impl Drop for ScratchDir {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.path);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn scratch_directory_is_removed_on_drop() {
let path = {
let scratch = ScratchDir::new("cleanup-test").unwrap();
let path = scratch.path().to_path_buf();
fs::write(path.join("file"), b"temporary").unwrap();
path
};
assert!(!path.exists());
}
#[test]
fn scratch_directory_skips_a_stale_process_serial() {
let serial = SCRATCH_COUNTER.load(Ordering::Relaxed);
let stale = std::env::temp_dir().join(format!(
"metal2vulkan-validation-{}-{serial}-stale-serial-test",
std::process::id()
));
fs::create_dir(&stale).unwrap();
let scratch = ScratchDir::new("stale-serial-test").unwrap();
assert_ne!(scratch.path(), stale);
fs::remove_dir(&stale).unwrap();
}
}