diff --git a/crates/metal2vulkan-rt/src/tests/image_reads.rs b/crates/metal2vulkan-rt/src/tests/image_reads.rs new file mode 100644 index 000000000..aabbe6f78 --- /dev/null +++ b/crates/metal2vulkan-rt/src/tests/image_reads.rs @@ -0,0 +1,171 @@ +//! `read()` of a texture out of range, under a device cfg on every device of the cfg's kind: the +//! engine fixture `oor_texture_reads` reads ten texels of an `RGBA8Unorm` texture of 4 x 4 with +//! two levels, of a view of its first level alone, and of an `R8Unorm` texture, each answering +//! what Metal answered on an Apple M3 Max under macOS 27.0.1 (job m3-max-47527, the same source +//! compiled at run time): the texel inside, and zero with alpha 0 past the width, the height, the +//! texture's levels, a level's own width and the view's levels, where the format has alpha, and +//! zero with alpha 1 where it has none. The device's robustness answers them, with no check in +//! the shader (`robustImageAccess2`). +//! +//! `llvm-as` assembles the kernel; without it the test skips visibly. + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::tests::command::on_device::{each_device, finished, Arena}; + use crate::{ + ComputePipelineDescriptor, Device, DispatchType, FunctionDescriptor, IndexClass, Library, + PixelFormat, Region, StageSource, Texture, TextureDescriptor, TextureType, TextureUsage, + }; + use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError}; + + /// Each read's x, y and level, as the fixture takes them. + const AT: [[u32; 3]; 11] = [ + [1, 1, 0], + [4, 0, 0], + [0, 4, 0], + [0, 0, 2], + [2, 0, 1], + [1, 1, 1], + [u32::MAX, 0, 0], + [0, 0, 1], + [1, 1, 0], + [4, 0, 0], + [0, 0, 1], + ]; + + /// What Metal answered for each read, its channels' bytes (x 255) (job m3-max-47527). + const METAL: [[u8; 4]; 11] = [ + [50, 60, 30, 200], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [55, 57, 99, 150], + [0, 0, 0, 0], + [0, 0, 0, 0], + [69, 0, 0, 255], + [0, 0, 0, 255], + [0, 0, 0, 255], + ]; + + /// The fixture's library, or None where `llvm-as` is missing. + fn library() -> Option { + match llvm_assemble(&engine_dir().join("oor_texture_reads.ll")) { + Ok(bitcode) => Some(Library::from_air(&bitcode).expect("the library")), + Err(AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + None + } + Err(error) => panic!("oor_texture_reads.ll: {error:?}"), + } + } + + /// A 2D texture of `side` texels a side with `levels` levels, shader-read usage, at `index`, + /// each level's texels `texel(level, x, y)`, `bytes` bytes a texel. + fn texture( + device: &Device, + format: PixelFormat, + (side, levels, index): (u32, u32, u32), + bytes: u32, + texel: fn(u32, u32, u32) -> Vec, + ) -> Texture { + let mut d = TextureDescriptor::new(TextureType::Type2D, format, side, side); + d.mipmap_level_count = levels; + d.usage = TextureUsage::SHADER_READ; + let texture = + (device.new_texture(&d, Some(index))).unwrap_or_else(|error| panic!("{d:?}: {error}")); + for level in 0..levels { + let side = side >> level; + let texels: Vec = (0..side) + .flat_map(|y| (0..side).flat_map(move |x| texel(level, x, y))) + .collect(); + let whole = Region { + origin: [0; 3], + size: [side, side, 1], + }; + let (row, image) = (u64::from(side * bytes), u64::from(side * side * bytes)); + (texture.replace_region(whole, level, 0, &texels, row, image)) + .unwrap_or_else(|error| panic!("level {level}: {error}")); + } + texture + } + + #[test] + fn every_device_reads_a_texture_out_of_range_as_metal_does() { + let Some(library) = library() else { + return; + }; + each_device("image reads out of range", |name, _, device| { + let function = library.function("oor_texture_reads").expect("the kernel"); + let descriptor = ComputePipelineDescriptor::new(StageSource::Function( + FunctionDescriptor::new(function), + )); + let state = (device.new_compute_pipeline_state(&descriptor, |_| Ok(Vec::new()))) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let grant = (device.grant_indices(IndexClass::Texture, 1, 3)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + // Level 0's texel (x, y) is (10 + 40x, 20 + 40y, 30, 200), level 1's (5 + 50x, + // 7 + 50y, 99, 150); the red texture's 64 + x + 4y. + let rgba = |level: u32, x: u32, y: u32| match level { + 0 => vec![(10 + 40 * x) as u8, (20 + 40 * y) as u8, 30, 200], + _ => vec![(5 + 50 * x) as u8, (7 + 50 * y) as u8, 99, 150], + }; + let two_levels = texture(&device, PixelFormat::RGBA8Unorm, (4, 2, 1), 4, rgba); + let one_level = (two_levels.new_texture_view( + PixelFormat::RGBA8Unorm, + TextureType::Type2D, + 0..1, + 0..1, + Some(2), + )) + .unwrap_or_else(|error| panic!("{name}: the view: {error}")); + let red = |_: u32, x: u32, y: u32| vec![(64 + x + 4 * y) as u8]; + let red = texture(&device, PixelFormat::R8Unorm, (4, 1, 3), 1, red); + let mut arena = Arena::new(&device); + let (at, out) = (arena.buffer(), arena.buffer()); + let words: Vec = (AT.iter()) + .flat_map(|&[x, y, level]| [x, y, level, 0]) + .flat_map(u32::to_le_bytes) + .collect(); + let contents = at.contents().expect("a Shared buffer"); + // SAFETY: the buffer holds 256 bytes, more than the 176 written, and nothing reads it + // meanwhile. + unsafe { (words.as_ptr()).copy_to_nonoverlapping(contents.as_ptr(), words.len()) }; + let queue = device.new_command_queue(1).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = + (command_buffer.compute_command_encoder(DispatchType::Serial)).expect("an encoder"); + encoder + .set_compute_pipeline_state(&state) + .expect("the state"); + for (texture, index) in [(&two_levels, 0), (&one_level, 1), (&red, 2)] { + encoder + .set_texture(Some(texture), index) + .expect("a texture"); + } + encoder.set_buffer(Some(&at), 0, 0).expect("at"); + encoder.set_buffer(Some(&out), 0, 1).expect("out"); + (encoder.dispatch_threadgroups([1, 1, 1], [1, 1, 1])) + .unwrap_or_else(|error| panic!("{name}: {error}")); + encoder.end_encoding(); + command_buffer.commit().expect("a commit"); + finished(name, &command_buffer); + assert_eq!(command_buffer.error(), None, "{name}"); + let contents = out.contents().expect("a Shared buffer"); + // SAFETY: the dispatch that wrote the buffer completed, and its writes reach the host. + let floats = unsafe { std::slice::from_raw_parts(contents.as_ptr().cast::(), 44) }; + for (read, (texel, metal)) in floats.chunks(4).zip(METAL).enumerate() { + let bytes = texel.iter().map(|&v| (v * 255.0).round() as u8); + assert_eq!( + bytes.collect::>(), + metal, + "{name}: read {read} at {:?}: {texel:?}", + AT[read] + ); + } + drop((two_levels, one_level, red, command_buffer)); + (device.release_indices(grant)).unwrap_or_else(|error| panic!("{name}: {error}")); + println!("image reads out of range: {name}: the 11 reads answer Metal's texels"); + }); + } +} diff --git a/crates/metal2vulkan-rt/src/tests/mod.rs b/crates/metal2vulkan-rt/src/tests/mod.rs index 58ec37cbd..d22eafcc9 100644 --- a/crates/metal2vulkan-rt/src/tests/mod.rs +++ b/crates/metal2vulkan-rt/src/tests/mod.rs @@ -12,6 +12,7 @@ mod floor; mod hazard; mod heap; mod kept; +mod image_reads; mod kernel_map; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod kernels; diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN index 4e43375d3..7928dbbdf 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN +++ b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN @@ -271,6 +271,7 @@ fixture ob3_index_buffer: metal: Apple metal version 32023.921 (metalfe-32023.92 fixture ob3_stage_input: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture ob3_texture_array: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture ob3_vertex_input: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) +fixture oor_texture_reads: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture overlapping_slots: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture pad_simd_shape: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture pdc_compare_clamp: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.air.ll new file mode 100644 index 000000000..51f89390c --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.air.ll @@ -0,0 +1,154 @@ +; Generated by scripts/regen-air-fixtures from oor_texture_reads.metal (typed pointers; xcrun metal-as reassembles it). Do not edit. +; ModuleID = '-' +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._texture_2d_t = type opaque +%struct._sampler_t = type opaque + +; Function Attrs: mustprogress nofree nounwind willreturn +define void @oor_texture_reads(%struct._texture_2d_t addrspace(1)* %0, %struct._texture_2d_t addrspace(1)* %1, %struct._texture_2d_t addrspace(1)* %2, <4 x i32> addrspace(2)* nocapture noundef readonly "air-buffer-no-alias" %3, <4 x float> addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %4) local_unnamed_addr #0 { + %6 = load <4 x i32>, <4 x i32> addrspace(2)* %3, align 16, !alias.scope !23, !noalias !26 + %7 = shufflevector <4 x i32> %6, <4 x i32> poison, <2 x i32> + %8 = extractelement <4 x i32> %6, i64 2 + %9 = tail call %struct._sampler_t addrspace(2)* @air.get_read_sampler() #3 + %10 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* %9, <2 x i32> %7, <2 x i32> zeroinitializer, i32 %8, i32 1) #4 + %11 = extractvalue { <4 x float>, i8 } %10, 0 + store <4 x float> %11, <4 x float> addrspace(1)* %4, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %12 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 1 + %13 = load <4 x i32>, <4 x i32> addrspace(2)* %12, align 16, !alias.scope !23, !noalias !26 + %14 = shufflevector <4 x i32> %13, <4 x i32> poison, <2 x i32> + %15 = extractelement <4 x i32> %13, i64 2 + %16 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* %9, <2 x i32> %14, <2 x i32> zeroinitializer, i32 %15, i32 1) #4 + %17 = extractvalue { <4 x float>, i8 } %16, 0 + %18 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 1 + store <4 x float> %17, <4 x float> addrspace(1)* %18, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %19 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 2 + %20 = load <4 x i32>, <4 x i32> addrspace(2)* %19, align 16, !alias.scope !23, !noalias !26 + %21 = shufflevector <4 x i32> %20, <4 x i32> poison, <2 x i32> + %22 = extractelement <4 x i32> %20, i64 2 + %23 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* %9, <2 x i32> %21, <2 x i32> zeroinitializer, i32 %22, i32 1) #4 + %24 = extractvalue { <4 x float>, i8 } %23, 0 + %25 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 2 + store <4 x float> %24, <4 x float> addrspace(1)* %25, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %26 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 3 + %27 = load <4 x i32>, <4 x i32> addrspace(2)* %26, align 16, !alias.scope !23, !noalias !26 + %28 = shufflevector <4 x i32> %27, <4 x i32> poison, <2 x i32> + %29 = extractelement <4 x i32> %27, i64 2 + %30 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* %9, <2 x i32> %28, <2 x i32> zeroinitializer, i32 %29, i32 1) #4 + %31 = extractvalue { <4 x float>, i8 } %30, 0 + %32 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 3 + store <4 x float> %31, <4 x float> addrspace(1)* %32, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %33 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 4 + %34 = load <4 x i32>, <4 x i32> addrspace(2)* %33, align 16, !alias.scope !23, !noalias !26 + %35 = shufflevector <4 x i32> %34, <4 x i32> poison, <2 x i32> + %36 = extractelement <4 x i32> %34, i64 2 + %37 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* %9, <2 x i32> %35, <2 x i32> zeroinitializer, i32 %36, i32 1) #4 + %38 = extractvalue { <4 x float>, i8 } %37, 0 + %39 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 4 + store <4 x float> %38, <4 x float> addrspace(1)* %39, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %40 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 5 + %41 = load <4 x i32>, <4 x i32> addrspace(2)* %40, align 16, !alias.scope !23, !noalias !26 + %42 = shufflevector <4 x i32> %41, <4 x i32> poison, <2 x i32> + %43 = extractelement <4 x i32> %41, i64 2 + %44 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* %9, <2 x i32> %42, <2 x i32> zeroinitializer, i32 %43, i32 1) #4 + %45 = extractvalue { <4 x float>, i8 } %44, 0 + %46 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 5 + store <4 x float> %45, <4 x float> addrspace(1)* %46, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %47 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 6 + %48 = load <4 x i32>, <4 x i32> addrspace(2)* %47, align 16, !alias.scope !23, !noalias !26 + %49 = shufflevector <4 x i32> %48, <4 x i32> poison, <2 x i32> + %50 = extractelement <4 x i32> %48, i64 2 + %51 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* %9, <2 x i32> %49, <2 x i32> zeroinitializer, i32 %50, i32 1) #4 + %52 = extractvalue { <4 x float>, i8 } %51, 0 + %53 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 6 + store <4 x float> %52, <4 x float> addrspace(1)* %53, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %54 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 7 + %55 = load <4 x i32>, <4 x i32> addrspace(2)* %54, align 16, !alias.scope !23, !noalias !26 + %56 = shufflevector <4 x i32> %55, <4 x i32> poison, <2 x i32> + %57 = extractelement <4 x i32> %55, i64 2 + %58 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._sampler_t addrspace(2)* %9, <2 x i32> %56, <2 x i32> zeroinitializer, i32 %57, i32 1) #4 + %59 = extractvalue { <4 x float>, i8 } %58, 0 + %60 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 7 + store <4 x float> %59, <4 x float> addrspace(1)* %60, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %61 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 8 + %62 = load <4 x i32>, <4 x i32> addrspace(2)* %61, align 16, !alias.scope !23, !noalias !26 + %63 = shufflevector <4 x i32> %62, <4 x i32> poison, <2 x i32> + %64 = extractelement <4 x i32> %62, i64 2 + %65 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, %struct._sampler_t addrspace(2)* %9, <2 x i32> %63, <2 x i32> zeroinitializer, i32 %64, i32 1) #4 + %66 = extractvalue { <4 x float>, i8 } %65, 0 + %67 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 8 + store <4 x float> %66, <4 x float> addrspace(1)* %67, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %68 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 9 + %69 = load <4 x i32>, <4 x i32> addrspace(2)* %68, align 16, !alias.scope !23, !noalias !26 + %70 = shufflevector <4 x i32> %69, <4 x i32> poison, <2 x i32> + %71 = extractelement <4 x i32> %69, i64 2 + %72 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, %struct._sampler_t addrspace(2)* %9, <2 x i32> %70, <2 x i32> zeroinitializer, i32 %71, i32 1) #4 + %73 = extractvalue { <4 x float>, i8 } %72, 0 + %74 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 9 + store <4 x float> %73, <4 x float> addrspace(1)* %74, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %75 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(2)* %3, i64 10 + %76 = load <4 x i32>, <4 x i32> addrspace(2)* %75, align 16, !alias.scope !23, !noalias !26 + %77 = shufflevector <4 x i32> %76, <4 x i32> poison, <2 x i32> + %78 = extractelement <4 x i32> %76, i64 2 + %79 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, %struct._sampler_t addrspace(2)* %9, <2 x i32> %77, <2 x i32> zeroinitializer, i32 %78, i32 1) #4 + %80 = extractvalue { <4 x float>, i8 } %79, 0 + %81 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %4, i64 10 + store <4 x float> %80, <4 x float> addrspace(1)* %81, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + ret void +} + +; Function Attrs: inaccessiblememonly mustprogress nofree nounwind readonly willreturn +declare %struct._sampler_t addrspace(2)* @air.get_read_sampler() local_unnamed_addr #1 + +; Function Attrs: argmemonly mustprogress nofree nounwind readonly willreturn +declare { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly, %struct._sampler_t addrspace(2)*, <2 x i32>, <2 x i32>, i32, i32) local_unnamed_addr #2 + +attributes #0 = { mustprogress nofree nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { inaccessiblememonly mustprogress nofree nounwind readonly willreturn } +attributes #2 = { argmemonly mustprogress nofree nounwind readonly willreturn } +attributes #3 = { inaccessiblememonly nounwind readonly willreturn } +attributes #4 = { argmemonly nounwind readonly willreturn } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9} +!air.compile_options = !{!17, !18, !19} +!llvm.ident = !{!20} +!air.version = !{!21} +!air.language_version = !{!22} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{void (%struct._texture_2d_t addrspace(1)*, %struct._texture_2d_t addrspace(1)*, %struct._texture_2d_t addrspace(1)*, <4 x i32> addrspace(2)*, <4 x float> addrspace(1)*)* @oor_texture_reads, !10, !11} +!10 = !{} +!11 = !{!12, !13, !14, !15, !16} +!12 = !{i32 0, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"two_levels"} +!13 = !{i32 1, !"air.texture", !"air.location_index", i32 1, i32 1, !"air.read", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"one_level"} +!14 = !{i32 2, !"air.texture", !"air.location_index", i32 2, i32 1, !"air.read", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"red"} +!15 = !{i32 3, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"uint4", !"air.arg_name", !"at"} +!16 = !{i32 4, !"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", !"out"} +!17 = !{!"air.compile.denorms_disable"} +!18 = !{!"air.compile.fast_math_enable"} +!19 = !{!"air.compile.framebuffer_fetch_enable"} +!20 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!21 = !{i32 2, i32 8, i32 0} +!22 = !{!"Metal", i32 4, i32 0, i32 0} +!23 = !{!24} +!24 = distinct !{!24, !25, !"air-alias-scope-arg(3)"} +!25 = distinct !{!25, !"air-alias-scopes(oor_texture_reads)"} +!26 = !{!27, !28} +!27 = distinct !{!27, !25, !"air-alias-scope-textures"} +!28 = distinct !{!28, !25, !"air-alias-scope-arg(4)"} +!29 = !{!30, !30, i64 0} +!30 = !{!"omnipotent char", !31, i64 0} +!31 = !{!"Simple C++ TBAA"} +!32 = !{!28} +!33 = !{!27, !24} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.ll b/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.ll new file mode 100644 index 000000000..0855cb14a --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.ll @@ -0,0 +1,151 @@ +; Generated by scripts/regen-air-fixtures from oor_texture_reads.metal (llvm-dis of oor_texture_reads.air). Do not edit. +; ModuleID = '' +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" + +; Function Attrs: mustprogress nofree nounwind willreturn +define void @oor_texture_reads(ptr addrspace(1) %0, ptr addrspace(1) %1, ptr addrspace(1) %2, ptr addrspace(2) noundef readonly captures(none) "air-buffer-no-alias" %3, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %4) local_unnamed_addr #0 { + %6 = load <4 x i32>, ptr addrspace(2) %3, align 16, !alias.scope !23, !noalias !26 + %7 = shufflevector <4 x i32> %6, <4 x i32> poison, <2 x i32> + %8 = extractelement <4 x i32> %6, i64 2 + %9 = tail call ptr addrspace(2) @air.get_read_sampler() #3 + %10 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %0, ptr addrspace(2) %9, <2 x i32> %7, <2 x i32> zeroinitializer, i32 %8, i32 1) #4 + %11 = extractvalue { <4 x float>, i8 } %10, 0 + store <4 x float> %11, ptr addrspace(1) %4, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %12 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 1 + %13 = load <4 x i32>, ptr addrspace(2) %12, align 16, !alias.scope !23, !noalias !26 + %14 = shufflevector <4 x i32> %13, <4 x i32> poison, <2 x i32> + %15 = extractelement <4 x i32> %13, i64 2 + %16 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %0, ptr addrspace(2) %9, <2 x i32> %14, <2 x i32> zeroinitializer, i32 %15, i32 1) #4 + %17 = extractvalue { <4 x float>, i8 } %16, 0 + %18 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 1 + store <4 x float> %17, ptr addrspace(1) %18, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %19 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 2 + %20 = load <4 x i32>, ptr addrspace(2) %19, align 16, !alias.scope !23, !noalias !26 + %21 = shufflevector <4 x i32> %20, <4 x i32> poison, <2 x i32> + %22 = extractelement <4 x i32> %20, i64 2 + %23 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %0, ptr addrspace(2) %9, <2 x i32> %21, <2 x i32> zeroinitializer, i32 %22, i32 1) #4 + %24 = extractvalue { <4 x float>, i8 } %23, 0 + %25 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 2 + store <4 x float> %24, ptr addrspace(1) %25, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %26 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 3 + %27 = load <4 x i32>, ptr addrspace(2) %26, align 16, !alias.scope !23, !noalias !26 + %28 = shufflevector <4 x i32> %27, <4 x i32> poison, <2 x i32> + %29 = extractelement <4 x i32> %27, i64 2 + %30 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %0, ptr addrspace(2) %9, <2 x i32> %28, <2 x i32> zeroinitializer, i32 %29, i32 1) #4 + %31 = extractvalue { <4 x float>, i8 } %30, 0 + %32 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 3 + store <4 x float> %31, ptr addrspace(1) %32, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %33 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 4 + %34 = load <4 x i32>, ptr addrspace(2) %33, align 16, !alias.scope !23, !noalias !26 + %35 = shufflevector <4 x i32> %34, <4 x i32> poison, <2 x i32> + %36 = extractelement <4 x i32> %34, i64 2 + %37 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %0, ptr addrspace(2) %9, <2 x i32> %35, <2 x i32> zeroinitializer, i32 %36, i32 1) #4 + %38 = extractvalue { <4 x float>, i8 } %37, 0 + %39 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 4 + store <4 x float> %38, ptr addrspace(1) %39, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %40 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 5 + %41 = load <4 x i32>, ptr addrspace(2) %40, align 16, !alias.scope !23, !noalias !26 + %42 = shufflevector <4 x i32> %41, <4 x i32> poison, <2 x i32> + %43 = extractelement <4 x i32> %41, i64 2 + %44 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %0, ptr addrspace(2) %9, <2 x i32> %42, <2 x i32> zeroinitializer, i32 %43, i32 1) #4 + %45 = extractvalue { <4 x float>, i8 } %44, 0 + %46 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 5 + store <4 x float> %45, ptr addrspace(1) %46, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %47 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 6 + %48 = load <4 x i32>, ptr addrspace(2) %47, align 16, !alias.scope !23, !noalias !26 + %49 = shufflevector <4 x i32> %48, <4 x i32> poison, <2 x i32> + %50 = extractelement <4 x i32> %48, i64 2 + %51 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %0, ptr addrspace(2) %9, <2 x i32> %49, <2 x i32> zeroinitializer, i32 %50, i32 1) #4 + %52 = extractvalue { <4 x float>, i8 } %51, 0 + %53 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 6 + store <4 x float> %52, ptr addrspace(1) %53, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %54 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 7 + %55 = load <4 x i32>, ptr addrspace(2) %54, align 16, !alias.scope !23, !noalias !26 + %56 = shufflevector <4 x i32> %55, <4 x i32> poison, <2 x i32> + %57 = extractelement <4 x i32> %55, i64 2 + %58 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %1, ptr addrspace(2) %9, <2 x i32> %56, <2 x i32> zeroinitializer, i32 %57, i32 1) #4 + %59 = extractvalue { <4 x float>, i8 } %58, 0 + %60 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 7 + store <4 x float> %59, ptr addrspace(1) %60, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %61 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 8 + %62 = load <4 x i32>, ptr addrspace(2) %61, align 16, !alias.scope !23, !noalias !26 + %63 = shufflevector <4 x i32> %62, <4 x i32> poison, <2 x i32> + %64 = extractelement <4 x i32> %62, i64 2 + %65 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %2, ptr addrspace(2) %9, <2 x i32> %63, <2 x i32> zeroinitializer, i32 %64, i32 1) #4 + %66 = extractvalue { <4 x float>, i8 } %65, 0 + %67 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 8 + store <4 x float> %66, ptr addrspace(1) %67, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %68 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 9 + %69 = load <4 x i32>, ptr addrspace(2) %68, align 16, !alias.scope !23, !noalias !26 + %70 = shufflevector <4 x i32> %69, <4 x i32> poison, <2 x i32> + %71 = extractelement <4 x i32> %69, i64 2 + %72 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %2, ptr addrspace(2) %9, <2 x i32> %70, <2 x i32> zeroinitializer, i32 %71, i32 1) #4 + %73 = extractvalue { <4 x float>, i8 } %72, 0 + %74 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 9 + store <4 x float> %73, ptr addrspace(1) %74, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + %75 = getelementptr inbounds <4 x i32>, ptr addrspace(2) %3, i64 10 + %76 = load <4 x i32>, ptr addrspace(2) %75, align 16, !alias.scope !23, !noalias !26 + %77 = shufflevector <4 x i32> %76, <4 x i32> poison, <2 x i32> + %78 = extractelement <4 x i32> %76, i64 2 + %79 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %2, ptr addrspace(2) %9, <2 x i32> %77, <2 x i32> zeroinitializer, i32 %78, i32 1) #4 + %80 = extractvalue { <4 x float>, i8 } %79, 0 + %81 = getelementptr inbounds <4 x float>, ptr addrspace(1) %4, i64 10 + store <4 x float> %80, ptr addrspace(1) %81, align 16, !tbaa !29, !alias.scope !32, !noalias !33 + ret void +} + +; Function Attrs: mustprogress nofree nounwind willreturn memory(inaccessiblemem: read) +declare ptr addrspace(2) @air.get_read_sampler() local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read) +declare { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none), ptr addrspace(2), <2 x i32>, <2 x i32>, i32, i32) local_unnamed_addr #2 + +attributes #0 = { mustprogress nofree nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { mustprogress nofree nounwind willreturn memory(inaccessiblemem: read) } +attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) } +attributes #3 = { nounwind willreturn memory(inaccessiblemem: read) } +attributes #4 = { nounwind willreturn memory(argmem: read) } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9} +!air.compile_options = !{!17, !18, !19} +!llvm.ident = !{!20} +!air.version = !{!21} +!air.language_version = !{!22} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{ptr @oor_texture_reads, !10, !11} +!10 = !{} +!11 = !{!12, !13, !14, !15, !16} +!12 = !{i32 0, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"two_levels"} +!13 = !{i32 1, !"air.texture", !"air.location_index", i32 1, i32 1, !"air.read", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"one_level"} +!14 = !{i32 2, !"air.texture", !"air.location_index", i32 2, i32 1, !"air.read", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"red"} +!15 = !{i32 3, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"uint4", !"air.arg_name", !"at"} +!16 = !{i32 4, !"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", !"out"} +!17 = !{!"air.compile.denorms_disable"} +!18 = !{!"air.compile.fast_math_enable"} +!19 = !{!"air.compile.framebuffer_fetch_enable"} +!20 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!21 = !{i32 2, i32 8, i32 0} +!22 = !{!"Metal", i32 4, i32 0, i32 0} +!23 = !{!24} +!24 = distinct !{!24, !25, !"air-alias-scope-arg(3)"} +!25 = distinct !{!25, !"air-alias-scopes(oor_texture_reads)"} +!26 = !{!27, !28} +!27 = distinct !{!27, !25, !"air-alias-scope-textures"} +!28 = distinct !{!28, !25, !"air-alias-scope-arg(4)"} +!29 = !{!30, !30, i64 0} +!30 = !{!"omnipotent char", !31, i64 0} +!31 = !{!"Simple C++ TBAA"} +!32 = !{!28} +!33 = !{!27, !24}