diff --git a/crates/metal2vulkan-runtime/src/counters.rs b/crates/metal2vulkan-runtime/src/counters.rs index ebfb83ac5..e1fde8c2b 100644 --- a/crates/metal2vulkan-runtime/src/counters.rs +++ b/crates/metal2vulkan-runtime/src/counters.rs @@ -275,6 +275,8 @@ pub(crate) enum Metric { RenderRecordsRead, /// [`Metrics::render_records_stale`]. RenderRecordsStale, + /// [`Metrics::word_contents`]. + WordContents, /// [`Metrics::creations_before_seed`]. CreationsBeforeSeed, /// [`Metrics::cache_writes_dropped`]. @@ -398,6 +400,7 @@ const METRIC_ORDER: [Metric; METRICS] = [ Metric::TranslationsLoaded, Metric::RenderRecordsRead, Metric::RenderRecordsStale, + Metric::WordContents, Metric::CreationsBeforeSeed, Metric::CacheWritesDropped, Metric::PipelineCachesReplaced, @@ -863,6 +866,7 @@ struct Atomics { translations_loaded: AtomicU64, render_records_read: AtomicU64, render_records_stale: AtomicU64, + word_contents: AtomicU64, creations_before_seed: AtomicU64, pipeline_cache_looks_skipped: AtomicU64, pipeline_cache_lock_waits: AtomicU64, @@ -1058,6 +1062,9 @@ struct Atomics { /// Reads of the pipeline cache's data for a blob write, for the tests. #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] cache_data_reads: AtomicU64, + /// Dispatches and draws that ran a words twin, for the tests. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + twin_runs: AtomicU64, } impl Counters { @@ -1121,6 +1128,7 @@ impl Counters { Metric::TranslationsLoaded => &a.translations_loaded, Metric::RenderRecordsRead => &a.render_records_read, Metric::RenderRecordsStale => &a.render_records_stale, + Metric::WordContents => &a.word_contents, Metric::CreationsBeforeSeed => &a.creations_before_seed, Metric::CacheWritesDropped => &a.cache_writes_dropped, Metric::PipelineCachesReplaced => &a.pipeline_caches_replaced, @@ -1882,6 +1890,18 @@ impl Counters { self.atomics.cache_data_reads.load(Relaxed) } + /// One more dispatch or draw that ran a words twin. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn ran_twin(&self) { + self.atomics.twin_runs.fetch_add(1, Relaxed); + } + + /// The dispatches and draws that ran a words twin. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn twin_runs(&self) -> u64 { + self.atomics.twin_runs.load(Relaxed) + } + /// One more live resource of `gauge`'s kind. pub(crate) fn rise(&self, gauge: Gauge) { self.gauge(gauge).fetch_add(1, Relaxed); @@ -2201,6 +2221,7 @@ impl Counters { translations_loaded: a.translations_loaded.load(Relaxed), render_records_read: a.render_records_read.load(Relaxed), render_records_stale: a.render_records_stale.load(Relaxed), + word_contents: a.word_contents.load(Relaxed), creations_before_seed: a.creations_before_seed.load(Relaxed), pipeline_cache_looks_skipped: a.pipeline_cache_looks_skipped.load(Relaxed), pipeline_cache_lock_waits: a.pipeline_cache_lock_waits.load(Relaxed), @@ -3065,6 +3086,11 @@ pub struct Metrics { /// a content with no record, decoding and specializing its functions, and kept the record /// again. pub render_records_stale: u64, + /// Contents made, compute and render, one of whose modules declares + /// `SpecKey::TexelBufferWords`: each makes a words twin of every `VkPipeline` it makes + /// ([`Gauges::word_pipelines`]). Only a device that holds some format's texture buffer as words + /// makes them. + pub word_contents: u64, /// `VkPipeline` creations that went through the device's empty pipeline cache while the /// reaper read and took in the device's blob ([`DeviceOptions::pipeline_cache_dir`]): each /// compiled without the blob's data, and those pipelines are not in this run's blob, so a diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index edd45f5d3..695561eb7 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -1319,6 +1319,10 @@ impl ComputeCommandEncoder { core, |slot| matches!(textures.get(slot as usize), Some(Some(t)) if t.held_as_words()), ); + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + if words { + core.counters.ran_twin(); + } let vk_pipeline = match self.last { Some(last) if (last.content, last.module, last.local, last.words) diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs index 3f849a6c4..7a51df711 100644 --- a/crates/metal2vulkan-runtime/src/pipeline.rs +++ b/crates/metal2vulkan-runtime/src/pipeline.rs @@ -1525,6 +1525,9 @@ impl Compiled { (notes, answers): (Vec, Answers), ) -> Compiled { core.counters.rise(Gauge::Kernels); + if whole.interface.words.is_some() { + core.counters.count(Metric::WordContents); + } Compiled { core, id: CONTENTS.fetch_add(1, Relaxed), diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index d52bc2a9b..b672a2ebe 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -1536,6 +1536,7 @@ impl RenderCompiled { // The words twin's modules: each stage's specialized with the constant true. let words = match handles { Some(handles) => { + core.counters.count(Metric::WordContents); let mut twin = Vec::new(); for stage in &pipeline.stages { match stage_module(core, stage, samples, true) { diff --git a/crates/metal2vulkan-runtime/src/render_encoder.rs b/crates/metal2vulkan-runtime/src/render_encoder.rs index d3aa6dbb2..9f0dd67c2 100644 --- a/crates/metal2vulkan-runtime/src/render_encoder.rs +++ b/crates/metal2vulkan-runtime/src/render_encoder.rs @@ -3001,6 +3001,10 @@ impl RenderCommandEncoder { .texture(slot) .is_some_and(|t| t.held_as_words()) }); + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + if words { + self.core.counters.ran_twin(); + } let pipeline = compiled.pipeline(topology, self.raster, words)?; let discards = compiled.discards(); let writes_memory = draws.writes_memory; diff --git a/crates/metal2vulkan-runtime/src/tests/texture_buffer_words.rs b/crates/metal2vulkan-runtime/src/tests/texture_buffer_words.rs index 85713a83c..363a71535 100644 --- a/crates/metal2vulkan-runtime/src/tests/texture_buffer_words.rs +++ b/crates/metal2vulkan-runtime/src/tests/texture_buffer_words.rs @@ -21,6 +21,11 @@ //! rest of its word among them, keep theirs; //! - each texture buffer's width is five. //! +//! Its `tb_word_formats_args` then reads the read one and writes the written one again, through an +//! argument buffer's handles, under the same checks. The dispatch through slots runs the kernel's +//! words twin (`pipeline::Twins`) exactly where the device holds the format as words; the one +//! through handles runs it there too. +//! //! `llvm-as` assembles the fixture; without it the test skips visibly. #[cfg(any(m2v_gpu, m2v_cpu_icd))] @@ -529,6 +534,8 @@ mod on_device { Ok(state) => state, Err(error) => return vec![format!("no state: {error}")], }; + let counters = &device.core().counters; + let twins = counters.twin_runs(); if let Err(error) = dispatch( device, &state, @@ -537,6 +544,18 @@ mod on_device { ) { return vec![format!("not dispatched: {error}")]; } + // The words twin runs where the device holds the format as words, the plain pipeline + // elsewhere. + let held = matches!( + formats::texel_buffer_form(case.format, device.translator().profile()), + Some(formats::TexelBufferForm::Words(_)) + ); + let ran = counters.twin_runs() - twins; + if ran != u64::from(held) { + wrong.push(format!( + "{ran} dispatches ran the words twin, held as words: {held}" + )); + } let out_of_bounds = [0.0, 0.0, 0.0, if case.alpha { 0.0 } else { 1.0 }]; let (reads, rw_reads) = (floats(&reads), floats(&rw_reads)); for t in 0..THREADS { @@ -584,6 +603,76 @@ mod on_device { if widths != [5, 5, 5] { wrong.push(format!("widths {widths:?}")); } + // Through an argument buffer's handles: the written one cleared first. + let args_reads = place((13312, 256)); + let args_widths = place((13568, 16)); + let ids: Vec = [&src, &dst] + .iter() + .flat_map(|t| t.gpu_resource_id().to_bits().to_le_bytes()) + .collect(); + let args = place((13824, 16)); + set_bytes(&args, 0, &ids); + set_bytes(&args_reads, 0, &[0; 256]); + set_bytes(&args_widths, 0, &[0; 16]); + set_bytes(&data, dst_at, &vec![SENTINEL; len]); + let function = library + .function("tb_word_formats_args") + .expect("the kernel"); + let descriptor = ComputePipelineDescriptor::new(StageSource::Function( + FunctionDescriptor::new(function), + )); + let state = match device.new_compute_pipeline_state(&descriptor, |s| Ok(vec![0; s.len()])) { + Ok(state) => state, + Err(error) => { + wrong.push(format!("no state of the handles' kernel: {error}")); + return wrong; + } + }; + let twins = counters.twin_runs(); + if let Err(error) = dispatch( + device, + &state, + &[], + &[&values, &args_reads, &rw_reads, &args_widths, &args], + ) { + wrong.push(format!("not dispatched through handles: {error}")); + return wrong; + } + // A texture buffer held as words lives while this one dispatches, so it runs the twin. + let ran = counters.twin_runs() - twins; + if held && ran != 1 { + wrong.push(format!( + "{ran} dispatches through handles ran the words twin" + )); + } + let args_reads = floats(&args_reads); + for t in 0..THREADS { + let (want, decode) = match t < WIDTH { + true => ((case.value)(&texel(&case.texels, t)), case.decode), + false => (out_of_bounds, Decode::Exact), + }; + if let Some(d) = differs(&args_reads[4 * t..4 * t + 4], want, decode) { + wrong.push(format!("texel {t} read through a handle: {d}")); + } + } + let all = bytes(&data); + if all[dst_at..dst_at + len] != case.texels[..] { + let got = &all[dst_at..dst_at + len]; + wrong.push(format!("written through a handle: {got:02x?}")); + } + if all[dst_at + len..dst_at + len + 64] + .iter() + .any(|&b| b != SENTINEL) + { + wrong.push("past the texels written through a handle".to_owned()); + } + let args_widths = bytes(&args_widths); + let args_widths: Vec = (args_widths.as_chunks::<4>().0.iter().take(2)) + .map(|&c| u32::from_le_bytes(c)) + .collect(); + if args_widths != [5, 5] { + wrong.push(format!("widths through handles {args_widths:?}")); + } wrong } diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.air.ll index 674687a20..91e72641e 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.air.ll +++ b/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.air.ll @@ -6,6 +6,9 @@ target triple = "air64_v28-apple-macosx26.0.0" %struct._texture_buffer_1d_t = type opaque %struct._sampler_t = type opaque +%struct.TbArgs = type { %"struct.metal::texture_buffer", %"struct.metal::texture_buffer.0" } +%"struct.metal::texture_buffer" = type { %struct._texture_buffer_1d_t addrspace(1)* } +%"struct.metal::texture_buffer.0" = type { %struct._texture_buffer_1d_t addrspace(1)* } ; Function Attrs: mustprogress nounwind willreturn define void @tb_word_formats(<4 x float> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %0, %struct._texture_buffer_1d_t addrspace(1)* %1, %struct._texture_buffer_1d_t addrspace(1)* %2, %struct._texture_buffer_1d_t addrspace(1)* %3, <4 x float> addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %4, <4 x float> addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %5, i32 addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %6, i32 noundef %7) local_unnamed_addr #0 { @@ -14,33 +17,63 @@ define void @tb_word_formats(<4 x float> addrspace(1)* nocapture noundef readonl %11 = extractvalue { <4 x float>, i8 } %10, 0 %12 = zext i32 %7 to i64 %13 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 %12 - store <4 x float> %11, <4 x float> addrspace(1)* %13, align 16, !tbaa !26, !alias.scope !29, !noalias !32 + store <4 x float> %11, <4 x float> addrspace(1)* %13, align 16, !tbaa !35, !alias.scope !38, !noalias !41 %14 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %0, i64 %12 - %15 = load <4 x float>, <4 x float> addrspace(1)* %14, align 16, !tbaa !26, !alias.scope !37, !noalias !38 - tail call void @air.write_texture_buffer_1d.v4f32(%struct._texture_buffer_1d_t addrspace(1)* nocapture %2, i32 %7, <4 x float> %15, i32 2) #6, !alias.scope !39, !noalias !40 + %15 = load <4 x float>, <4 x float> addrspace(1)* %14, align 16, !tbaa !35, !alias.scope !46, !noalias !47 + tail call void @air.write_texture_buffer_1d.v4f32(%struct._texture_buffer_1d_t addrspace(1)* nocapture %2, i32 %7, <4 x float> %15, i32 2) #6, !alias.scope !48, !noalias !49 %16 = tail call { <4 x float>, i8 } @air.read_texture_buffer_1d.v4f32(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %3, %struct._sampler_t addrspace(2)* %9, i32 %7, i32 3) #5 %17 = extractvalue { <4 x float>, i8 } %16, 0 %18 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %5, i64 %12 - store <4 x float> %17, <4 x float> addrspace(1)* %18, align 16, !tbaa !26, !alias.scope !41, !noalias !42 - tail call void @air.write_texture_buffer_1d.v4f32(%struct._texture_buffer_1d_t addrspace(1)* nocapture %3, i32 %7, <4 x float> %15, i32 3) #6, !alias.scope !39, !noalias !40 + store <4 x float> %17, <4 x float> addrspace(1)* %18, align 16, !tbaa !35, !alias.scope !50, !noalias !51 + tail call void @air.write_texture_buffer_1d.v4f32(%struct._texture_buffer_1d_t addrspace(1)* nocapture %3, i32 %7, <4 x float> %15, i32 3) #6, !alias.scope !48, !noalias !49 %19 = icmp eq i32 %7, 0 br i1 %19, label %20, label %26 20: ; preds = %8 - %21 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %1) #5, !alias.scope !39, !noalias !40 - store i32 %21, i32 addrspace(1)* %6, align 4, !tbaa !43, !alias.scope !45, !noalias !46 - %22 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %2) #5, !alias.scope !39, !noalias !40 + %21 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %1) #5, !alias.scope !48, !noalias !49 + store i32 %21, i32 addrspace(1)* %6, align 4, !tbaa !52, !alias.scope !54, !noalias !55 + %22 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %2) #5, !alias.scope !48, !noalias !49 %23 = getelementptr inbounds i32, i32 addrspace(1)* %6, i64 1 - store i32 %22, i32 addrspace(1)* %23, align 4, !tbaa !43, !alias.scope !45, !noalias !46 - %24 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %3) #5, !alias.scope !39, !noalias !40 + store i32 %22, i32 addrspace(1)* %23, align 4, !tbaa !52, !alias.scope !54, !noalias !55 + %24 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %3) #5, !alias.scope !48, !noalias !49 %25 = getelementptr inbounds i32, i32 addrspace(1)* %6, i64 2 - store i32 %24, i32 addrspace(1)* %25, align 4, !tbaa !43, !alias.scope !45, !noalias !46 + store i32 %24, i32 addrspace(1)* %25, align 4, !tbaa !52, !alias.scope !54, !noalias !55 br label %26 26: ; preds = %20, %8 ret void } +; Function Attrs: mustprogress nounwind willreturn +define void @tb_word_formats_args(<4 x float> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %0, <4 x float> addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %1, i32 addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %2, %struct.TbArgs addrspace(2)* nocapture noundef readonly align 8 dereferenceable(16) "air-buffer-no-alias" %3, i32 noundef %4) local_unnamed_addr #0 { + %6 = getelementptr inbounds %struct.TbArgs, %struct.TbArgs addrspace(2)* %3, i64 0, i32 0, i32 0 + %7 = load %struct._texture_buffer_1d_t addrspace(1)*, %struct._texture_buffer_1d_t addrspace(1)* addrspace(2)* %6, align 8, !tbaa !56, !alias.scope !59, !noalias !62 + %8 = tail call %struct._sampler_t addrspace(2)* @air.get_read_sampler() #4 + %9 = tail call { <4 x float>, i8 } @air.read_texture_buffer_1d.v4f32(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %7, %struct._sampler_t addrspace(2)* %8, i32 %4, i32 1) #5 + %10 = extractvalue { <4 x float>, i8 } %9, 0 + %11 = zext i32 %4 to i64 + %12 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %1, i64 %11 + store <4 x float> %10, <4 x float> addrspace(1)* %12, align 16, !tbaa !35, !alias.scope !66, !noalias !67 + %13 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %0, i64 %11 + %14 = load <4 x float>, <4 x float> addrspace(1)* %13, align 16, !tbaa !35, !alias.scope !68, !noalias !69 + %15 = getelementptr inbounds %struct.TbArgs, %struct.TbArgs addrspace(2)* %3, i64 0, i32 1, i32 0 + %16 = load %struct._texture_buffer_1d_t addrspace(1)*, %struct._texture_buffer_1d_t addrspace(1)* addrspace(2)* %15, align 8, !tbaa !70, !alias.scope !59, !noalias !62 + tail call void @air.write_texture_buffer_1d.v4f32(%struct._texture_buffer_1d_t addrspace(1)* nocapture %16, i32 %4, <4 x float> %14, i32 2) #6 + %17 = icmp eq i32 %4, 0 + br i1 %17, label %18, label %22 + +18: ; preds = %5 + %19 = getelementptr inbounds i32, i32 addrspace(1)* %2, i64 1 + %20 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %7) #5 + store i32 %20, i32 addrspace(1)* %2, align 4, !tbaa !52, !alias.scope !72, !noalias !73 + %21 = tail call i32 @air.get_width_texture_buffer_1d(%struct._texture_buffer_1d_t addrspace(1)* nocapture readonly %16) #5 + store i32 %21, i32 addrspace(1)* %19, align 4, !tbaa !52, !alias.scope !72, !noalias !73 + br label %22 + +22: ; preds = %18, %5 + ret void +} + ; Function Attrs: inaccessiblememonly mustprogress nofree nounwind readonly willreturn declare %struct._sampler_t addrspace(2)* @air.get_read_sampler() local_unnamed_addr #1 @@ -62,11 +95,11 @@ attributes #5 = { argmemonly nounwind readonly willreturn } attributes #6 = { argmemonly nounwind willreturn } !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} -!air.kernel = !{!9} -!air.compile_options = !{!20, !21, !22} -!llvm.ident = !{!23} -!air.version = !{!24} -!air.language_version = !{!25} +!air.kernel = !{!9, !20} +!air.compile_options = !{!29, !30, !31} +!llvm.ident = !{!32} +!air.version = !{!33} +!air.language_version = !{!34} !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} !1 = !{i32 1, !"wchar_size", i32 4} @@ -88,30 +121,57 @@ attributes #6 = { argmemonly nounwind willreturn } !17 = !{i32 5, !"air.buffer", !"air.location_index", i32 2, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"rw_reads"} !18 = !{i32 6, !"air.buffer", !"air.location_index", i32 3, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"widths"} !19 = !{i32 7, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} -!20 = !{!"air.compile.denorms_disable"} -!21 = !{!"air.compile.fast_math_enable"} -!22 = !{!"air.compile.framebuffer_fetch_enable"} -!23 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} -!24 = !{i32 2, i32 8, i32 0} -!25 = !{!"Metal", i32 4, i32 0, i32 0} -!26 = !{!27, !27, i64 0} -!27 = !{!"omnipotent char", !28, i64 0} -!28 = !{!"Simple C++ TBAA"} -!29 = !{!30} -!30 = distinct !{!30, !31, !"air-alias-scope-arg(4)"} -!31 = distinct !{!31, !"air-alias-scopes(tb_word_formats)"} -!32 = !{!33, !34, !35, !36} -!33 = distinct !{!33, !31, !"air-alias-scope-arg(0)"} -!34 = distinct !{!34, !31, !"air-alias-scope-textures"} -!35 = distinct !{!35, !31, !"air-alias-scope-arg(5)"} -!36 = distinct !{!36, !31, !"air-alias-scope-arg(6)"} -!37 = !{!33} -!38 = !{!34, !30, !35, !36} -!39 = !{!34} -!40 = !{!33, !30, !35, !36} -!41 = !{!35} -!42 = !{!33, !34, !30, !36} -!43 = !{!44, !44, i64 0} -!44 = !{!"int", !27, i64 0} -!45 = !{!36} -!46 = !{!33, !34, !30, !35} +!20 = !{void (<4 x float> addrspace(1)*, <4 x float> addrspace(1)*, i32 addrspace(1)*, %struct.TbArgs addrspace(2)*, i32)* @tb_word_formats_args, !10, !21} +!21 = !{!12, !22, !23, !24, !28} +!22 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"reads"} +!23 = !{i32 2, !"air.buffer", !"air.location_index", i32 3, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"widths"} +!24 = !{i32 3, !"air.indirect_buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 4, i32 1, !"air.read", !"air.address_space", i32 2, !"air.struct_type_info", !25, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"TbArgs", !"air.arg_name", !"args"} +!25 = !{i32 0, i32 8, i32 0, !"texture_buffer", !"src", !"air.indirect_argument", !26, i32 8, i32 8, i32 0, !"texture_buffer", !"dst", !"air.indirect_argument", !27} +!26 = !{i32 0, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read", !"air.arg_type_name", !"texture_buffer", !"air.arg_name", !"src"} +!27 = !{i32 1, !"air.texture", !"air.location_index", i32 1, i32 1, !"air.write", !"air.arg_type_name", !"texture_buffer", !"air.arg_name", !"dst"} +!28 = !{i32 4, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} +!29 = !{!"air.compile.denorms_disable"} +!30 = !{!"air.compile.fast_math_enable"} +!31 = !{!"air.compile.framebuffer_fetch_enable"} +!32 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!33 = !{i32 2, i32 8, i32 0} +!34 = !{!"Metal", i32 4, i32 0, i32 0} +!35 = !{!36, !36, i64 0} +!36 = !{!"omnipotent char", !37, i64 0} +!37 = !{!"Simple C++ TBAA"} +!38 = !{!39} +!39 = distinct !{!39, !40, !"air-alias-scope-arg(4)"} +!40 = distinct !{!40, !"air-alias-scopes(tb_word_formats)"} +!41 = !{!42, !43, !44, !45} +!42 = distinct !{!42, !40, !"air-alias-scope-arg(0)"} +!43 = distinct !{!43, !40, !"air-alias-scope-textures"} +!44 = distinct !{!44, !40, !"air-alias-scope-arg(5)"} +!45 = distinct !{!45, !40, !"air-alias-scope-arg(6)"} +!46 = !{!42} +!47 = !{!43, !39, !44, !45} +!48 = !{!43} +!49 = !{!42, !39, !44, !45} +!50 = !{!44} +!51 = !{!42, !43, !39, !45} +!52 = !{!53, !53, i64 0} +!53 = !{!"int", !36, i64 0} +!54 = !{!45} +!55 = !{!42, !43, !39, !44} +!56 = !{!57, !58, i64 0} +!57 = !{!"_ZTSN5metal14texture_bufferIfLNS_6accessE1ELNS_16memory_coherenceE0EvEE", !58, i64 0} +!58 = !{!"__metal_texture_buffer_1d_t", !36, i64 0} +!59 = !{!60} +!60 = distinct !{!60, !61, !"air-alias-scope-arg(3)"} +!61 = distinct !{!61, !"air-alias-scopes(tb_word_formats_args)"} +!62 = !{!63, !64, !65} +!63 = distinct !{!63, !61, !"air-alias-scope-arg(0)"} +!64 = distinct !{!64, !61, !"air-alias-scope-arg(1)"} +!65 = distinct !{!65, !61, !"air-alias-scope-arg(2)"} +!66 = !{!64} +!67 = !{!63, !65, !60} +!68 = !{!63} +!69 = !{!64, !65, !60} +!70 = !{!71, !58, i64 0} +!71 = !{!"_ZTSN5metal14texture_bufferIfLNS_6accessE2ELNS_16memory_coherenceE0EvEE", !58, i64 0} +!72 = !{!65} +!73 = !{!63, !64, !60} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.ll b/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.ll index 57acc3c5b..817f57a1b 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.ll +++ b/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.ll @@ -4,6 +4,10 @@ source_filename = "-" target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" target triple = "air64_v28-apple-macosx26.0.0" +%struct.TbArgs = type { %"struct.metal::texture_buffer", %"struct.metal::texture_buffer.0" } +%"struct.metal::texture_buffer" = type { ptr addrspace(1) } +%"struct.metal::texture_buffer.0" = type { ptr addrspace(1) } + ; Function Attrs: mustprogress nounwind willreturn define void @tb_word_formats(ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %0, ptr addrspace(1) %1, ptr addrspace(1) %2, ptr addrspace(1) %3, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %4, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %5, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %6, i32 noundef %7) local_unnamed_addr #0 { %9 = tail call ptr addrspace(2) @air.get_read_sampler() #4 @@ -11,33 +15,63 @@ define void @tb_word_formats(ptr addrspace(1) noundef readonly captures(none) "a %11 = extractvalue { <4 x float>, i8 } %10, 0 %12 = zext i32 %7 to i64 %13 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 %12 - store <4 x float> %11, ptr addrspace(1) %13, align 16, !tbaa !26, !alias.scope !29, !noalias !32 + store <4 x float> %11, ptr addrspace(1) %13, align 16, !tbaa !35, !alias.scope !38, !noalias !41 %14 = getelementptr inbounds <4 x float>, ptr addrspace(1) %0, i64 %12 - %15 = load <4 x float>, ptr addrspace(1) %14, align 16, !tbaa !26, !alias.scope !37, !noalias !38 - tail call void @air.write_texture_buffer_1d.v4f32(ptr addrspace(1) captures(none) %2, i32 %7, <4 x float> %15, i32 2) #6, !alias.scope !39, !noalias !40 + %15 = load <4 x float>, ptr addrspace(1) %14, align 16, !tbaa !35, !alias.scope !46, !noalias !47 + tail call void @air.write_texture_buffer_1d.v4f32(ptr addrspace(1) captures(none) %2, i32 %7, <4 x float> %15, i32 2) #6, !alias.scope !48, !noalias !49 %16 = tail call { <4 x float>, i8 } @air.read_texture_buffer_1d.v4f32(ptr addrspace(1) readonly captures(none) %3, ptr addrspace(2) %9, i32 %7, i32 3) #5 %17 = extractvalue { <4 x float>, i8 } %16, 0 %18 = getelementptr inbounds <4 x float>, ptr addrspace(1) %5, i64 %12 - store <4 x float> %17, ptr addrspace(1) %18, align 16, !tbaa !26, !alias.scope !41, !noalias !42 - tail call void @air.write_texture_buffer_1d.v4f32(ptr addrspace(1) captures(none) %3, i32 %7, <4 x float> %15, i32 3) #6, !alias.scope !39, !noalias !40 + store <4 x float> %17, ptr addrspace(1) %18, align 16, !tbaa !35, !alias.scope !50, !noalias !51 + tail call void @air.write_texture_buffer_1d.v4f32(ptr addrspace(1) captures(none) %3, i32 %7, <4 x float> %15, i32 3) #6, !alias.scope !48, !noalias !49 %19 = icmp eq i32 %7, 0 br i1 %19, label %20, label %26 20: ; preds = %8 - %21 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %1) #5, !alias.scope !39, !noalias !40 - store i32 %21, ptr addrspace(1) %6, align 4, !tbaa !43, !alias.scope !45, !noalias !46 - %22 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %2) #5, !alias.scope !39, !noalias !40 + %21 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %1) #5, !alias.scope !48, !noalias !49 + store i32 %21, ptr addrspace(1) %6, align 4, !tbaa !52, !alias.scope !54, !noalias !55 + %22 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %2) #5, !alias.scope !48, !noalias !49 %23 = getelementptr inbounds i32, ptr addrspace(1) %6, i64 1 - store i32 %22, ptr addrspace(1) %23, align 4, !tbaa !43, !alias.scope !45, !noalias !46 - %24 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %3) #5, !alias.scope !39, !noalias !40 + store i32 %22, ptr addrspace(1) %23, align 4, !tbaa !52, !alias.scope !54, !noalias !55 + %24 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %3) #5, !alias.scope !48, !noalias !49 %25 = getelementptr inbounds i32, ptr addrspace(1) %6, i64 2 - store i32 %24, ptr addrspace(1) %25, align 4, !tbaa !43, !alias.scope !45, !noalias !46 + store i32 %24, ptr addrspace(1) %25, align 4, !tbaa !52, !alias.scope !54, !noalias !55 br label %26 26: ; preds = %20, %8 ret void } +; Function Attrs: mustprogress nounwind willreturn +define void @tb_word_formats_args(ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %0, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %1, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %2, ptr addrspace(2) noundef readonly align 8 captures(none) dereferenceable(16) "air-buffer-no-alias" %3, i32 noundef %4) local_unnamed_addr #0 { + %6 = getelementptr inbounds %struct.TbArgs, ptr addrspace(2) %3, i64 0, i32 0, i32 0 + %7 = load ptr addrspace(1), ptr addrspace(2) %6, align 8, !tbaa !56, !alias.scope !59, !noalias !62 + %8 = tail call ptr addrspace(2) @air.get_read_sampler() #4 + %9 = tail call { <4 x float>, i8 } @air.read_texture_buffer_1d.v4f32(ptr addrspace(1) readonly captures(none) %7, ptr addrspace(2) %8, i32 %4, i32 1) #5 + %10 = extractvalue { <4 x float>, i8 } %9, 0 + %11 = zext i32 %4 to i64 + %12 = getelementptr inbounds <4 x float>, ptr addrspace(1) %1, i64 %11 + store <4 x float> %10, ptr addrspace(1) %12, align 16, !tbaa !35, !alias.scope !66, !noalias !67 + %13 = getelementptr inbounds <4 x float>, ptr addrspace(1) %0, i64 %11 + %14 = load <4 x float>, ptr addrspace(1) %13, align 16, !tbaa !35, !alias.scope !68, !noalias !69 + %15 = getelementptr inbounds %struct.TbArgs, ptr addrspace(2) %3, i64 0, i32 1, i32 0 + %16 = load ptr addrspace(1), ptr addrspace(2) %15, align 8, !tbaa !70, !alias.scope !59, !noalias !62 + tail call void @air.write_texture_buffer_1d.v4f32(ptr addrspace(1) captures(none) %16, i32 %4, <4 x float> %14, i32 2) #6 + %17 = icmp eq i32 %4, 0 + br i1 %17, label %18, label %22 + +18: ; preds = %5 + %19 = getelementptr inbounds i32, ptr addrspace(1) %2, i64 1 + %20 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %7) #5 + store i32 %20, ptr addrspace(1) %2, align 4, !tbaa !52, !alias.scope !72, !noalias !73 + %21 = tail call i32 @air.get_width_texture_buffer_1d(ptr addrspace(1) readonly captures(none) %16) #5 + store i32 %21, ptr addrspace(1) %19, align 4, !tbaa !52, !alias.scope !72, !noalias !73 + br label %22 + +22: ; preds = %18, %5 + ret void +} + ; Function Attrs: mustprogress nofree nounwind willreturn memory(inaccessiblemem: read) declare ptr addrspace(2) @air.get_read_sampler() local_unnamed_addr #1 @@ -59,11 +93,11 @@ attributes #5 = { nounwind willreturn memory(argmem: read) } attributes #6 = { nounwind willreturn memory(argmem: readwrite) } !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} -!air.kernel = !{!9} -!air.compile_options = !{!20, !21, !22} -!llvm.ident = !{!23} -!air.version = !{!24} -!air.language_version = !{!25} +!air.kernel = !{!9, !20} +!air.compile_options = !{!29, !30, !31} +!llvm.ident = !{!32} +!air.version = !{!33} +!air.language_version = !{!34} !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} !1 = !{i32 1, !"wchar_size", i32 4} @@ -85,30 +119,57 @@ attributes #6 = { nounwind willreturn memory(argmem: readwrite) } !17 = !{i32 5, !"air.buffer", !"air.location_index", i32 2, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"rw_reads"} !18 = !{i32 6, !"air.buffer", !"air.location_index", i32 3, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"widths"} !19 = !{i32 7, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} -!20 = !{!"air.compile.denorms_disable"} -!21 = !{!"air.compile.fast_math_enable"} -!22 = !{!"air.compile.framebuffer_fetch_enable"} -!23 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} -!24 = !{i32 2, i32 8, i32 0} -!25 = !{!"Metal", i32 4, i32 0, i32 0} -!26 = !{!27, !27, i64 0} -!27 = !{!"omnipotent char", !28, i64 0} -!28 = !{!"Simple C++ TBAA"} -!29 = !{!30} -!30 = distinct !{!30, !31, !"air-alias-scope-arg(4)"} -!31 = distinct !{!31, !"air-alias-scopes(tb_word_formats)"} -!32 = !{!33, !34, !35, !36} -!33 = distinct !{!33, !31, !"air-alias-scope-arg(0)"} -!34 = distinct !{!34, !31, !"air-alias-scope-textures"} -!35 = distinct !{!35, !31, !"air-alias-scope-arg(5)"} -!36 = distinct !{!36, !31, !"air-alias-scope-arg(6)"} -!37 = !{!33} -!38 = !{!34, !30, !35, !36} -!39 = !{!34} -!40 = !{!33, !30, !35, !36} -!41 = !{!35} -!42 = !{!33, !34, !30, !36} -!43 = !{!44, !44, i64 0} -!44 = !{!"int", !27, i64 0} -!45 = !{!36} -!46 = !{!33, !34, !30, !35} +!20 = !{ptr @tb_word_formats_args, !10, !21} +!21 = !{!12, !22, !23, !24, !28} +!22 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"reads"} +!23 = !{i32 2, !"air.buffer", !"air.location_index", i32 3, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"widths"} +!24 = !{i32 3, !"air.indirect_buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 4, i32 1, !"air.read", !"air.address_space", i32 2, !"air.struct_type_info", !25, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"TbArgs", !"air.arg_name", !"args"} +!25 = !{i32 0, i32 8, i32 0, !"texture_buffer", !"src", !"air.indirect_argument", !26, i32 8, i32 8, i32 0, !"texture_buffer", !"dst", !"air.indirect_argument", !27} +!26 = !{i32 0, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read", !"air.arg_type_name", !"texture_buffer", !"air.arg_name", !"src"} +!27 = !{i32 1, !"air.texture", !"air.location_index", i32 1, i32 1, !"air.write", !"air.arg_type_name", !"texture_buffer", !"air.arg_name", !"dst"} +!28 = !{i32 4, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} +!29 = !{!"air.compile.denorms_disable"} +!30 = !{!"air.compile.fast_math_enable"} +!31 = !{!"air.compile.framebuffer_fetch_enable"} +!32 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!33 = !{i32 2, i32 8, i32 0} +!34 = !{!"Metal", i32 4, i32 0, i32 0} +!35 = !{!36, !36, i64 0} +!36 = !{!"omnipotent char", !37, i64 0} +!37 = !{!"Simple C++ TBAA"} +!38 = !{!39} +!39 = distinct !{!39, !40, !"air-alias-scope-arg(4)"} +!40 = distinct !{!40, !"air-alias-scopes(tb_word_formats)"} +!41 = !{!42, !43, !44, !45} +!42 = distinct !{!42, !40, !"air-alias-scope-arg(0)"} +!43 = distinct !{!43, !40, !"air-alias-scope-textures"} +!44 = distinct !{!44, !40, !"air-alias-scope-arg(5)"} +!45 = distinct !{!45, !40, !"air-alias-scope-arg(6)"} +!46 = !{!42} +!47 = !{!43, !39, !44, !45} +!48 = !{!43} +!49 = !{!42, !39, !44, !45} +!50 = !{!44} +!51 = !{!42, !43, !39, !45} +!52 = !{!53, !53, i64 0} +!53 = !{!"int", !36, i64 0} +!54 = !{!45} +!55 = !{!42, !43, !39, !44} +!56 = !{!57, !58, i64 0} +!57 = !{!"_ZTSN5metal14texture_bufferIfLNS_6accessE1ELNS_16memory_coherenceE0EvEE", !58, i64 0} +!58 = !{!"__metal_texture_buffer_1d_t", !36, i64 0} +!59 = !{!60} +!60 = distinct !{!60, !61, !"air-alias-scope-arg(3)"} +!61 = distinct !{!61, !"air-alias-scopes(tb_word_formats_args)"} +!62 = !{!63, !64, !65} +!63 = distinct !{!63, !61, !"air-alias-scope-arg(0)"} +!64 = distinct !{!64, !61, !"air-alias-scope-arg(1)"} +!65 = distinct !{!65, !61, !"air-alias-scope-arg(2)"} +!66 = !{!64} +!67 = !{!63, !65, !60} +!68 = !{!63} +!69 = !{!64, !65, !60} +!70 = !{!71, !58, i64 0} +!71 = !{!"_ZTSN5metal14texture_bufferIfLNS_6accessE2ELNS_16memory_coherenceE0EvEE", !58, i64 0} +!72 = !{!65} +!73 = !{!63, !64, !60} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.metal b/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.metal index b92843d5c..8d007035b 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.metal +++ b/crates/metal2vulkan-validation/fixtures/public/engine/tb_word_formats.metal @@ -4,10 +4,16 @@ // writes values[t] to texel t of dst, and reads texel t of rw into rw_reads[t] before writing // values[t] there; thread 0 writes the three widths. A thread past the width reads Metal's // out-of-bounds texel and writes nothing. Neighbouring threads write neighbouring texels, which -// share a word where a texel is smaller than one. Loop-free. +// share a word where a texel is smaller than one. tb_word_formats_args reads src and writes dst +// through an argument buffer's handles instead of slots. Loop-free. #include using namespace metal; +struct TbArgs { + texture_buffer src; + texture_buffer dst; +}; + kernel void tb_word_formats(device const float4 *values [[buffer(0)]], texture_buffer src [[texture(0)]], texture_buffer dst [[texture(1)]], @@ -26,3 +32,16 @@ kernel void tb_word_formats(device const float4 *values [[buffer(0)]], widths[2] = rw.get_width(); } } + +kernel void tb_word_formats_args(device const float4 *values [[buffer(0)]], + device float4 *reads [[buffer(1)]], + device uint *widths [[buffer(3)]], + constant TbArgs &args [[buffer(4)]], + uint t [[thread_position_in_grid]]) { + reads[t] = args.src.read(t); + args.dst.write(values[t], t); + if (t == 0) { + widths[0] = args.src.get_width(); + widths[1] = args.dst.get_width(); + } +} diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs index a602b8745..0802c4b71 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs @@ -3356,6 +3356,7 @@ impl Backend for NewRuntime { ("texture_clear_barriers", metrics.texture_clear_barriers), ("pipelines_created", metrics.pipelines_created), ("pipeline_creation_nanos", metrics.pipeline_creation_nanos), + ("word_contents", metrics.word_contents), ("word_pipelines_created", metrics.word_pipelines_created), ("word_pipeline_nanos", metrics.word_pipeline_nanos), ("first_use_waits", metrics.first_use_waits), diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 19af2a465..f16db88a6 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -1667,6 +1667,7 @@ field metal2vulkan-runtime::Metrics.upload_barriers pub upload_barriers: u64 field metal2vulkan-runtime::Metrics.upload_waits pub upload_waits: u64 field metal2vulkan-runtime::Metrics.visibility_interrupts_refused pub visibility_interrupts_refused: u64 field metal2vulkan-runtime::Metrics.waits_behind_counter pub waits_behind_counter: u64 +field metal2vulkan-runtime::Metrics.word_contents pub word_contents: u64 field metal2vulkan-runtime::Metrics.word_pipeline_nanos pub word_pipeline_nanos: u64 field metal2vulkan-runtime::Metrics.word_pipelines_created pub word_pipelines_created: u64 field metal2vulkan-runtime::Metrics.zero_source_allocations pub zero_source_allocations: SiteAllocations