diff --git a/crates/metal2vulkan-runtime/src/pipeline/creation_log.rs b/crates/metal2vulkan-runtime/src/pipeline/creation_log.rs index 2b184a74f..6176dea58 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/creation_log.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/creation_log.rs @@ -7,7 +7,10 @@ //! id, its meaning and its value), the precision notes the stage holds under that //! specialization (`notes`, as a render line names a stage's), the creation's wall time, and //! what the kernel was made from (`descriptor:`, as a render state's first line names each -//! function: its name, its bitcode's SHA-256 and the constant values it was made with). A +//! function: its name, its bitcode's SHA-256 and the constant values it was made with). Before +//! the driver's call, a line of the making's start ([`compute_started`]) names the kernel, its +//! SPIR-V and its specialization, and the dump directory takes its module then: a making that +//! never returns is that line without its made line, its module on disk. A //! compute state's pipelines differ by their specialization alone (the threadgroup size, an //! edge region), so each line prints it whole: no numbering, no diff and no split. A kernel //! whose compile is refused, at its state's creation or at a dispatch's variant, takes a line of @@ -706,22 +709,39 @@ pub(crate) fn compute_kernel( }) } -/// Deliver the line of a compute `VkPipeline` `device` made of `kernel` under `specialization`, -/// its creation `took` long (the module's documentation, "Compute pipelines"). -pub(crate) fn compute( +/// Deliver the line of a compute `VkPipeline` `device` starts making of `kernel` under +/// `specialization`, before the driver's call, and write its module into the dump directory where +/// one is set: a making that never returns is this line without its made line ([`compute`]), and +/// its module is on disk (the module's documentation, "Compute pipelines"). +pub(crate) fn compute_started( device: &Device, kernel: &LoggedKernel, specialization: &SpecializationKey, - took: Duration, ) { let stage = &kernel.stage; + let hash = spirv_hash(&stage.spirv); + let dumped = dump_modules(std::iter::once((hash, &stage.spirv[..]))).unwrap_or_default(); + deliver( + device, + format!( + "metal2vulkan: pipeline creation: compute pipeline `{}`: making, spirv {hash:016x} \ + ({} words), specialization [{}]{dumped}", + kernel.name, + stage.spirv.len(), + constants(stage, specialization).join(", "), + ), + ); +} + +/// Each of `specialization`'s constants of `stage`: its id, its meaning and its value. +fn constants(stage: &StageModule, specialization: &SpecializationKey) -> Vec { let meanings: BTreeMap = stage .specialization .constants .iter() .map(|c| (c.id, c.key)) .collect(); - let constants: Vec = specialization + specialization .entries .iter() .map(|e| { @@ -735,19 +755,30 @@ pub(crate) fn compute( .map_or_else(String::new, |k| format!(" {k:?}")); format!("{}{meaning} = {}", e.constant_id, u64::from_le_bytes(word)) }) - .collect(); + .collect() +} + +/// Deliver the line of a compute `VkPipeline` `device` made of `kernel` under `specialization`, +/// its creation `took` long (the module's documentation, "Compute pipelines"). Its module was +/// dumped as the making started ([`compute_started`]). +pub(crate) fn compute( + device: &Device, + kernel: &LoggedKernel, + specialization: &SpecializationKey, + took: Duration, +) { + let stage = &kernel.stage; let notes = stage.precision_notes_under(specialization); let hash = spirv_hash(&stage.spirv); - let dumped = dump_modules(std::iter::once((hash, &stage.spirv[..]))).unwrap_or_default(); deliver( device, format!( "metal2vulkan: pipeline creation: compute pipeline `{}`: {:.3} ms, spirv {hash:016x} \ - ({} words), specialization [{}], notes {notes:?}; descriptor: {}{dumped}", + ({} words), specialization [{}], notes {notes:?}; descriptor: {}", kernel.name, took.as_secs_f64() * 1000.0, stage.spirv.len(), - constants.join(", "), + constants(stage, specialization).join(", "), kernel.function, ), ); diff --git a/crates/metal2vulkan-runtime/src/pipeline/objects.rs b/crates/metal2vulkan-runtime/src/pipeline/objects.rs index 472c8c9eb..9212412f8 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/objects.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/objects.rs @@ -1231,6 +1231,11 @@ impl VariantObjects { // A large kernel's words of the process's limit, waited for without the turn // (`compile_memory.rs`). let words = shared.compile_memory(c.object.words()); + // The line and the module before the driver's call, so a making that never returns is + // named. + if let Some(kernel) = &self.logged { + creation_log::compute_started(&self.device, kernel, c.specialization); + } let started = std::time::Instant::now(); // With what the driver reports of the making: a pipeline found in its record's cache // reads no data back (`shader_cache/driver.rs`). diff --git a/crates/metal2vulkan-runtime/src/tests/opencl_data.rs b/crates/metal2vulkan-runtime/src/tests/opencl_data.rs index f0428701c..0832fca0d 100644 --- a/crates/metal2vulkan-runtime/src/tests/opencl_data.rs +++ b/crates/metal2vulkan-runtime/src/tests/opencl_data.rs @@ -473,9 +473,10 @@ const LOG_LINE: &str = "metal2vulkan: pipeline creation: compute pipeline `__ent /// makes has its line in the pipeline creation log (`pipeline/creation_log.rs`), naming the /// kernel, its module, its specialization, its precision notes (`NativeNanEncoding` among them, /// but where the device's narrowing is measured to move a NaN as Metal's) and what it was made -/// from (the function, its bitcode's SHA-256 and its constant values); with +/// from (the function, its bitcode's SHA-256 and its constant values), after the line of its +/// making's start, which names the kernel, the same module and its specialization; with /// `METAL2VULKAN_DUMP_PIPELINES` naming a directory, its module is written there by the hash the -/// line names it by. A child process of this test binary ([`compute_log_child`]) dispatches it +/// lines name it by. A child process of this test binary ([`compute_log_child`]) dispatches it /// with the log on. #[test] fn the_pipeline_creation_log_names_a_compute_pipeline_and_its_notes() { @@ -496,10 +497,12 @@ fn the_pipeline_creation_log_names_a_compute_pipeline_and_its_notes() { .unwrap(); let stderr = String::from_utf8_lossy(&output.stderr); assert!(output.status.success(), "the child failed: {stderr}"); - let logged = stderr - .lines() - .find(|l| l.starts_with(LOG_LINE)) + let lines: Vec<&str> = stderr.lines().filter(|l| l.starts_with(LOG_LINE)).collect(); + let made = lines + .iter() + .position(|l| l.contains(" ms, spirv ")) .unwrap_or_else(|| panic!("no compute pipeline's line: {stderr}")); + let logged = lines[made]; assert!(logged.contains(" words), specialization ["), "{logged}"); assert!( logged.contains("; descriptor: `__entry_vsh_round` air ") @@ -512,6 +515,13 @@ fn the_pipeline_creation_log_names_a_compute_pipeline_and_its_notes() { .and_then(|(_, rest)| rest.split_once(' ')) .map(|(hash, _)| hash) .unwrap_or_else(|| panic!("no module hash: {logged}")); + let started = format!("{LOG_LINE}making, spirv {hash} ("); + assert!( + lines[..made] + .iter() + .any(|l| l.starts_with(&started) && l.contains(" words), specialization [")), + "no line of the making's start before {logged}: {stderr}" + ); let module = std::fs::read(dumped.join(format!("{hash}.spv"))).unwrap(); assert_eq!( module.get(..4), diff --git a/crates/metal2vulkan/src/env_vars.rs b/crates/metal2vulkan/src/env_vars.rs index cf58bdce3..798c01422 100644 --- a/crates/metal2vulkan/src/env_vars.rs +++ b/crates/metal2vulkan/src/env_vars.rs @@ -40,7 +40,8 @@ pub const REGISTRY: &[EnvVar] = &[ effect: "metal2vulkan-runtime's diagnostics: one line per compute VkPipeline a device \ makes (its kernel, its SPIR-V, its specialization constants, its precision notes, \ the creation's time and the descriptor it was made from: the function's name, \ - the SHA-256 of its bitcode and the constant values it was made with) and one per \ + the SHA-256 of its bitcode and the constant values it was made with), after one \ + as its making starts (its kernel, its SPIR-V and its specialization), and one per \ render VkPipeline, through the device's \ message sink or on stderr: its state, its key, the \ key's fields that differ from the state's closest earlier pipeline (a state's \ @@ -61,8 +62,8 @@ pub const REGISTRY: &[EnvVar] = &[ name: "METAL2VULKAN_DUMP_PIPELINES", default: "unset (off)", effect: "metal2vulkan-runtime's diagnostics: a directory (made where missing) each device \ - writes the SPIR-V modules of every render and compute VkPipeline it makes into, \ - one file per \ + writes the SPIR-V modules of every render and compute VkPipeline it makes into \ + (a compute pipeline's as its making starts), one file per \ module, `.spv`, the hash METAL2VULKAN_LOG_PIPELINES's lines name the \ module by, each written once; setting it turns that log on too; empty or 0 is \ off", diff --git a/docs/API.md b/docs/API.md index 337be1006..cf4ad312d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1839,7 +1839,9 @@ With `METAL2VULKAN_LOG_PIPELINES` set, a device also logs one line per compute ` makes (id name `metal2vulkan-pipeline-creation`, `Info` severity): its kernel, its SPIR-V (a hash and its length), each specialization constant, the precision notes the stage holds under that specialization, the creation's time and the descriptor the kernel was made from (the function's -name, the SHA-256 of its bitcode and the constant values it was made with). And one line per +name, the SHA-256 of its bitcode and the constant values it was made with), after a line as the +making starts, before the driver's call, naming its kernel, its SPIR-V and its specialization: a +making that never returns is that line without its made line. And one line per render `VkPipeline` it makes (the same id name and severity), with where its time went: the wait for its turn, the digests that name its parts, each library (made by this making, its @@ -1851,8 +1853,8 @@ differ only in formats no translation reads share one); a state's first line als descriptor it was made from (each function's name, the SHA-256 of its bitcode and the constant values it was made with, each color attachment's format, blend and write mask, the depth and stencil formats and the raster samples). With `METAL2VULKAN_DUMP_PIPELINES` naming a directory, a -device writes each such pipeline's SPIR-V modules there, render and compute, one file per module -named by the hash +device writes each such pipeline's SPIR-V modules there, render and compute (a compute module as +its making starts), one file per module named by the hash the line prints it by (`.spv`), and the log is on too. And, once per reason, why a draw that reads its own pass's color attachment after a barrier took the split rather than a snapshot (id name `metal2vulkan-snapshot-fallback`, `Info` severity; `WorkCounts::reading_draws_snapshotted`