diff --git a/crates/metal2vulkan-runtime/src/tests/chroma_makes.rs b/crates/metal2vulkan-runtime/src/tests/chroma_makes.rs index 3f93e870f..0b16c9159 100644 --- a/crates/metal2vulkan-runtime/src/tests/chroma_makes.rs +++ b/crates/metal2vulkan-runtime/src/tests/chroma_makes.rs @@ -1,10 +1,13 @@ //! The driver's make of a render content lowered for a 4:2:2 texture //! (`LoweringInputs::chroma_pairs`) beside the same state's own content, under a device cfg on //! every device of the cfg's kind: `colored_vertex` with the owned fixture `device_level`'s -//! `dl_runtime`, one sample of texture 0 through the runtime sampler at sampler 0. Each content's +//! `dl_runtime`, one sample of texture 0 through the runtime sampler at sampler 0, decoded at +//! texture 0; and `grd_half_many_samples` drawn by `grd_many_vertex`, 40 samples of each of its +//! eight textures through one runtime sampler, decoded at texture 3 (40 sites). Each content's //! main pipeline is made by `finish_pipeline`, and the test prints its `vkCreateGraphicsPipelines` -//! time (`Metrics::pipeline_creation_nanos`) and its modules' SPIR-V bytes. The driver's own -//! shader cache is the job's: a job that times a cold make gives the process an empty one. +//! time (`Metrics::pipeline_creation_nanos`), its translation's and its modules' SPIR-V bytes. The +//! driver's own shader cache is the job's: a job that times a cold make gives the process an empty +//! one. //! //! `llvm-as` assembles the functions; without it the test skips visibly. @@ -13,54 +16,72 @@ mod on_device { use crate::kernel_map::Chroma; use crate::tests::command::on_device::each_device; use crate::tests::draw::on_device::{descriptor, examples, library}; - use crate::{FunctionDescriptor, PixelFormat, RenderPipelineState, StageSource}; + use crate::{ + ColorAttachmentDescriptor, FunctionDescriptor, PixelFormat, RenderPipelineDescriptor, + RenderPipelineState, StageSource, + }; use metal2vulkan_devtools::engine_dir; #[test] fn four_two_two_content_make_time() { - let (Some(examples), Some(levels)) = - (examples(), library(&engine_dir().join("device_level.ll"))) - else { + let (Some(examples), Some(levels), Some(many)) = ( + examples(), + library(&engine_dir().join("device_level.ll")), + library(&engine_dir().join("grd_half_many_samples.ll")), + ) else { return; }; - let mut d = descriptor(&examples, "colored_fragment", PixelFormat::RGBA8Unorm); - d.fragment = Some(StageSource::Function(FunctionDescriptor::new( - levels.function("dl_runtime").expect("the function"), - ))); + let function = |library: &crate::Library, name| { + StageSource::Function(FunctionDescriptor::new( + library.function(name).expect("the function"), + )) + }; + let mut one = descriptor(&examples, "colored_fragment", PixelFormat::RGBA8Unorm); + one.fragment = Some(function(&levels, "dl_runtime")); + let mut forty = RenderPipelineDescriptor::new(function(&many, "grd_many_vertex")); + forty.fragment = Some(function(&many, "grd_half_many_samples")); + for color in &mut forty.color_attachments[..2] { + *color = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA16Float)); + } + let cases = [("1 site", one, 1u128), ("40 sites", forty, 1 << 3)]; each_device("4:2:2 content make time", |name, _, device| { - let made = |what: &str, state: &RenderPipelineState| { + for (case, d, slots) in &cases { + let made = |what: &str, state: &RenderPipelineState| { + let before = device.counters().metrics(); + (state.finish_pipeline()) + .unwrap_or_else(|error| panic!("{name}: {case}: {what}: {error}")); + let after = device.counters().metrics(); + let created = after.pipelines_created - before.pipelines_created; + let nanos = after.pipeline_creation_nanos - before.pipeline_creation_nanos; + println!( + "{name}: {case}: {what}: {created} pipeline in {:.1} ms, {} bytes of SPIR-V", + nanos as f64 / 1e6, + state.allocated_size() + ); + assert_eq!(created, 1, "{name}: {case}: {what}: the pipelines made"); + }; + let state = (device.new_render_pipeline_state(d, |samplers| { + assert!(samplers.is_empty(), "{name}: {case}: {samplers:?}"); + Ok(Vec::new()) + })) + .unwrap_or_else(|error| panic!("{name}: {case}: {error}")); + made("plain", &state); let before = device.counters().metrics(); - (state.finish_pipeline()).unwrap_or_else(|error| panic!("{name}: {what}: {error}")); + let chroma = Chroma { + slots: [0, *slots], + handles: false, + }; + let decoded = (state.for_draws(&device, (0, [0; 2], chroma))) + .unwrap_or_else(|error| panic!("{name}: {case}: {error}")); let after = device.counters().metrics(); - let created = after.pipelines_created - before.pipelines_created; - let nanos = after.pipeline_creation_nanos - before.pipeline_creation_nanos; + let contents = after.chroma_contents - before.chroma_contents; + assert_eq!(contents, 1, "{name}: {case}"); println!( - "{name}: {what}: {created} pipeline in {:.1} ms, {} bytes of SPIR-V", - nanos as f64 / 1e6, - state.allocated_size() + "{name}: {case}: 4:2:2 content translated in {:.1} ms", + (after.translation_nanos - before.translation_nanos) as f64 / 1e6 ); - assert_eq!(created, 1, "{name}: {what}: the pipelines made"); - }; - let state = (device.new_render_pipeline_state(&d, |samplers| { - assert!(samplers.is_empty(), "{name}: {samplers:?}"); - Ok(Vec::new()) - })) - .unwrap_or_else(|error| panic!("{name}: {error}")); - made("plain", &state); - let before = device.counters().metrics(); - let chroma = Chroma { - slots: [0, 1], - handles: false, - }; - let decoded = (state.for_draws(&device, (0, [0; 2], chroma))) - .unwrap_or_else(|error| panic!("{name}: {error}")); - let after = device.counters().metrics(); - assert_eq!(after.chroma_contents - before.chroma_contents, 1, "{name}"); - println!( - "{name}: 4:2:2 content translated in {:.1} ms", - (after.translation_nanos - before.translation_nanos) as f64 / 1e6 - ); - made("4:2:2", &decoded); + made("4:2:2", &decoded); + } }); } } diff --git a/crates/metal2vulkan/src/tests/engine_chroma_pairs.rs b/crates/metal2vulkan/src/tests/engine_chroma_pairs.rs index 79fa26ca7..b465c4ad4 100644 --- a/crates/metal2vulkan/src/tests/engine_chroma_pairs.rs +++ b/crates/metal2vulkan/src/tests/engine_chroma_pairs.rs @@ -100,29 +100,40 @@ fn chroma_handles_decode_only_a_function_that_reaches_textures_through_handles() assert!(ran > 0); } -/// A module's instructions, and of them its texel fetches (`OpImageFetch`). -fn sizes(words: &[u32]) -> (usize, usize) { - let (mut at, mut instructions, mut fetches) = (5, 0, 0); +/// A module's instructions, texel fetches (`OpImageFetch`), samples (`OpImageSample*`), +/// selection merges and loop merges. +fn sizes(words: &[u32]) -> String { + let (mut at, mut instructions) = (5, 0); + let (mut fetches, mut samples, mut selections, mut loops) = (0, 0, 0, 0); while at < words.len() { - let count = (words[at] >> 16) as usize; - if words[at] & 0xffff == 95 { - fetches += 1; + match words[at] & 0xffff { + 95 => fetches += 1, + 87..=94 => samples += 1, + 247 => selections += 1, + 246 => loops += 1, + _ => {} } instructions += 1; - at += count.max(1); + at += ((words[at] >> 16) as usize).max(1); } - (instructions, fetches) + format!( + "{} words, {instructions} instructions, {fetches} fetches, {samples} samples, \ + {selections} selections, {loops} loops", + words.len() + ) } /// The size of each module a 4:2:2 decode lowers, beside the module lowered without it: a /// kernel's read, sample through a runtime sampler and gather of slot 0 (`fpv_swizzled_reads`), -/// a fragment function's sample through a runtime sampler (`device_level`'s `dl_runtime`), and -/// `a4_heap_sample`'s samples through a handle. +/// a fragment function's sample through a runtime sampler (`device_level`'s `dl_runtime`), the 40 +/// samples of fragment texture 3 of `grd_half_many_samples`, and `a4_heap_sample`'s samples +/// through a handle. #[test] fn four_two_two_module_sizes() { - let (Some(slots), Some(levels), Some(heap)) = ( + let (Some(slots), Some(levels), Some(many), Some(heap)) = ( fixture("fpv_swizzled_reads"), fixture("device_level"), + fixture("grd_half_many_samples"), fixture("a4_heap_sample"), ) else { return; @@ -135,13 +146,19 @@ fn four_two_two_module_sizes() { kernel_inputs.chroma_pairs.insert(SLOT); let mut fragment_inputs = LowerInputs::new(); fragment_inputs.chroma_pairs.insert(fragment); + let mut third_inputs = LowerInputs::new(); + third_inputs.chroma_pairs.insert(SlotRef { + index: 3, + ..fragment + }); let mut handle_inputs = LowerInputs::new(); handle_inputs.chroma_handles = true; - let rows: [(&[u8], &str, &LowerInputs); 5] = [ + let rows: [(&[u8], &str, &LowerInputs); 6] = [ (&slots, "fpv_swz_read", &kernel_inputs), (&slots, "fpv_swz_sample", &kernel_inputs), (&slots, "fpv_swz_gather_x", &kernel_inputs), (&levels, "dl_runtime", &fragment_inputs), + (&many, "grd_half_many_samples", &third_inputs), (&heap, "a4_heap_sample", &handle_inputs), ]; for (stem, p) in committed_profiles().expect("profiles") { @@ -150,15 +167,13 @@ fn four_two_two_module_sizes() { compile_with(bc, entry, &p, &LowerInputs::new()), compile_with(bc, entry, &p, inputs), ) else { + println!("{stem}: {entry}: not compiled"); continue; }; - let (pi, pf) = sizes(&plain.module.words); - let (di, df) = sizes(&decoded.module.words); println!( - "{stem}: {entry}: plain {pi} instructions, {pf} fetches, {} words; decoded {di} \ - instructions, {df} fetches, {} words", - plain.module.words.len(), - decoded.module.words.len() + "{stem}: {entry}: plain {}; decoded {}", + sizes(&plain.module.words), + sizes(&decoded.module.words) ); } }