diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index b77331ea0..8b0b15ae4 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -3950,6 +3950,13 @@ cache is answered compile-required on both. (`Gap::KernelInput`, whose `KernelInputKind` names what the runtime found: `Slot` for an intersection-function table). So is a state for indirect command buffers (`Gap::IndirectCommandBuffers`, `IndirectCommandsKind::ComputeCommands`). +- An OpenCL program's kernel that takes a 1D image (`image1d_t` or `image1d_array_t`) cannot be + made into a compute pipeline state of OpenCL mode (`open_cl_mode_enabled`), where Metal makes + it: Apple's OpenCL binds such an image as a 2D texture of height 1 (a 1D array as a 2D array of + that height), and the translator's form of the kernel depends on whether the texture bound for + the image is 1D (`RuntimeFact::OpenClLineTexture`), state of the bound texture beyond its + resource ID, which the runtime does not supply. The making fails with `Error::Translation` + (`Unsupported{IdentityDomains, NotImplemented}`), whatever else the kernel does. - A visible-function table's words take a Shared block of their own, 64 KiB at the least, for a table of any size. - A state whose kernel the consumer compiled (`StageSource::Compiled`) holds no linked functions diff --git a/crates/metal2vulkan-runtime/src/tests/opencl_mode.rs b/crates/metal2vulkan-runtime/src/tests/opencl_mode.rs index a49cfdb3d..b2b142f4a 100644 --- a/crates/metal2vulkan-runtime/src/tests/opencl_mode.rs +++ b/crates/metal2vulkan-runtime/src/tests/opencl_mode.rs @@ -29,6 +29,14 @@ //! toward zero, up and down; `float` to integers of 8 to 64 bits to nearest even, up and down; //! and `.sat` between integers. //! +//! Not run here: a kernel of OpenCL mode that takes a 1D image (`image1d_t` or `image1d_array_t`, +//! which Apple's OpenCL binds as a 2D texture of height 1 or a 2D array of that height), whose +//! channel queries, reads, samples and writes the M3 Max and the Radeon Pro 5300M answer. The +//! runtime refuses each such kernel's pipeline state at its making: "the translator made no +//! pipeline of __entry_: unsupported: IdentityDomains (state of a bound texture or sampler +//! beyond its resource ID (OpenClLineTexture { slot: SlotRef { stage: Kernel, class: Texture, +//! index: } })); needs NotImplemented" (the runtime's README, Known gaps of pipeline states). +//! //! The modules are LLVM text written here; `llvm-as` assembles them, and without it the tests skip //! visibly. diff --git a/crates/metal2vulkan-runtime/src/tests/opencl_swizzles.rs b/crates/metal2vulkan-runtime/src/tests/opencl_swizzles.rs index 21b400486..597f539db 100644 --- a/crates/metal2vulkan-runtime/src/tests/opencl_swizzles.rs +++ b/crates/metal2vulkan-runtime/src/tests/opencl_swizzles.rs @@ -6,19 +6,22 @@ //! Each view is 4 by 2, of an `RGBA8Unorm` or `R8Unorm` texture, made with the swizzle of one of //! OpenCL's channel orders (`BGRA`, `ARGB`, `A`, `INTENSITY`, `LUMINANCE`; the identity as a //! control). Texel `i` (`x + 4y`) of a filled texture holds bytes `(0x10 + i, 0x50 + i, 0x90 + i, -//! 0xd0 + i)` (`R8Unorm`: `0x10 + i`); a write stores `(0x11 + i, 0x51 + i, 0x91 + i, 0xd1 + i) / -//! 255` into a texture filled with `0xee`. The M3 Max answers, on every view, for plain Metal and +//! 0xd0 + i)` (`R8Unorm`: `0x10 + i`). The M3 Max answers, on every view, for plain Metal and //! for OpenCL mode alike: //! //! - **query**: a write-only image the kernel only queries answers the view's width and height //! and, for its channel order and data type, the third hidden buffer's words, which no swizzle //! reaches (`4, 2, 0x11234, 0x1234`); -//! - **write**: a write-only image's write stores channel `c` from the first lane whose source is -//! `c`, and lane `c` where no lane names it: the swizzle undone; //! - **read**: a read-only image's read, without a sampler and through one (nearest, at the //! texel's centre), answers the texel swizzled: lane `l` the channel the swizzle's `l` names (a //! format's missing green and blue 0, its missing alpha 1), `Zero` 0 and `One` 1. //! +//! Not run here: a `read_write` image of a swizzled view (Metal's `read_write` texture, read then +//! written, in OpenCL mode; Apple's OpenCL compiler takes no `__read_write` image), which the M3 +//! Max reads through the swizzle and writes with the swizzle undone. The runtime refuses its +//! dispatch as `Gap::SwizzledReadWrite`: "a read_write texture slot 0 bound to a swizzled texture +//! is not built". +//! //! Under a device cfg, on every device of the cfg's kind. The modules are LLVM text written here; //! `llvm-as` assembles them, and without it the tests skip visibly. @@ -138,13 +141,6 @@ const TEXEL: &str = " %g = tail call fastcc i64 @_Z13get_global_idj(i32 0)\n\ %p0 = insertelement <2 x i32> poison, i32 %x, i64 0\n\ %p = insertelement <2 x i32> %p0, i32 %y, i64 1\n"; -/// The value thread `i` writes, `%v`: `(0x11 + i, 0x51 + i, 0x91 + i, 0xd1 + i) / 255`. -const VALUE: &str = " %fi = uitofp i32 %i to float\n\ - %v0 = insertelement <4 x float> poison, float %fi, i64 0\n\ - %vs = shufflevector <4 x float> %v0, <4 x float> poison, <4 x i32> zeroinitializer\n\ - %va = fadd <4 x float> %vs, \n\ - %v = fdiv <4 x float> %va, \n"; - /// `__kernel void sw_query(__write_only image2d_t img, __global int *o)`: `o[0..4]` take the /// image's width, height, channel order and channel data type. fn query() -> String { @@ -183,24 +179,6 @@ declare i32 @air.get_channel_data_type_texture_2d(ptr addrspace(1)) #0\n"; format!("{body}{}", kernel_list("__entry_sw_query", &args)) } -/// `__kernel void sw_write(__write_only image2d_t img)`: thread `i` writes its value to its texel. -fn write() -> String { - let body = format!( - "define void @__entry_sw_write(ptr addrspace(1) %0) #0 {{\n\ -entry:\n\ - tail call fastcc void @sw_write(ptr addrspace(1) %0)\n\ - ret void\n}}\n\ -define internal fastcc void @sw_write(ptr addrspace(1) %img) #1 {{\n\ -entry:\n\ -{TEXEL}{VALUE}\ - tail call void @air.write_texture_2d.v4f32(ptr addrspace(1) %img, <2 x i32> %p, <4 x float> %v, i32 0, i32 2)\n\ - ret void\n}}\n\ -declare void @air.write_texture_2d.v4f32(ptr addrspace(1), <2 x i32>, <4 x float>, i32, i32) #0\n" - ); - let args = [image(0, 0, "write", "texture2d", "img")]; - format!("{body}{}", kernel_list("__entry_sw_write", &args)) -} - /// `__kernel void sw_read(__read_only image2d_t img, sampler_t s, __global float4 *o)`: thread `i` /// stores its texel read without a sampler to `o[2i]`, and sampled through `s` at its centre to /// `o[2i + 1]`. @@ -281,11 +259,6 @@ fn filled(i: usize, c: usize) -> u8 { (0x10 + 0x40 * c + i) as u8 } -/// Lane `l` of the value thread `i` writes, as a byte. -fn written(i: usize, l: usize) -> u8 { - (0x11 + 0x40 * l + i) as u8 -} - /// The channel a swizzle source names, if any. fn channel(s: TextureSwizzle) -> Option { match s { @@ -307,21 +280,9 @@ fn read_rule(v: &View, i: usize) -> [u8; 4] { }) } -/// The bytes texel `i` holds after its write through `v`: the write rule. -fn write_rule(v: &View, i: usize) -> Vec { - (0..v.channels) - .map(|c| { - let lane = (0..4) - .find(|&l| channel(v.swizzle[l]) == Some(c)) - .unwrap_or(c); - written(i, lane) - }) - .collect() -} - -/// A Shared texture of `v`'s format, 4 by 2, at texture index 1, every byte `fill` or the filled -/// texels, and its view through `v`'s swizzle at texture index 2. -fn swizzled(device: &Device, v: &View, fill: Option) -> (Texture, Texture) { +/// A Shared texture of `v`'s format, 4 by 2, at texture index 1, of the filled texels, and its +/// view through `v`'s swizzle at texture index 2. +fn swizzled(device: &Device, v: &View) -> (Texture, Texture) { let mut descriptor = TextureDescriptor::new(TextureType::Type2D, v.format, W, H); descriptor.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE | TextureUsage::PIXEL_FORMAT_VIEW; @@ -329,7 +290,7 @@ fn swizzled(device: &Device, v: &View, fill: Option) -> (Texture, Texture) { let texture = (device.new_texture(&descriptor, Some(1))) .unwrap_or_else(|error| panic!("{}: {error}", v.name)); let bytes: Vec = (0..N as usize) - .flat_map(|i| (0..v.channels).map(move |c| fill.unwrap_or(filled(i, c)))) + .flat_map(|i| (0..v.channels).map(move |c| filled(i, c))) .collect(); let row = u64::from(W) * v.channels as u64; (texture.replace_region( @@ -368,15 +329,6 @@ fn whole() -> Region { } } -/// The bytes of `texture`, of `v`'s format. -fn bytes(texture: &Texture, v: &View) -> Vec { - let row = u64::from(W) * v.channels as u64; - let mut out = vec![0u8; (row * u64::from(H)) as usize]; - (texture.get_bytes(&mut out, row, row * u64::from(H), whole(), 0, 0)) - .unwrap_or_else(|error| panic!("{}: {error}", v.name)); - out -} - /// The bytes of the `float4` at `at` of `got`: each lane times 255, rounded. fn lanes(got: &[f32], at: usize) -> [u8; 4] { std::array::from_fn(|l| (got[4 * at + l] * 255.0).round() as u8) @@ -392,7 +344,7 @@ fn opencl_mode_queries_of_a_swizzled_write_only_image_answer_the_view() { .unwrap_or_else(|error| panic!("{name}: {error}")); let query = state(&device, &query, "__entry_sw_query"); for v in views() { - let (_texture, view) = swizzled(&device, &v, None); + let (_texture, view) = swizzled(&device, &v); let o = words_buffer(&device, &[0xcdcd_cdcd; 4]); let bound = Bound { textures: &[&view], @@ -406,30 +358,6 @@ fn opencl_mode_queries_of_a_swizzled_write_only_image_answer_the_view() { }); } -#[test] -fn opencl_mode_writes_through_a_swizzled_image_undo_the_swizzle() { - let Some(write) = library(&write()) else { - return; - }; - each_device("opencl-swizzles-write", |name, _, device| { - let _grant = (device.grant_indices(IndexClass::Texture, 1, 2)) - .unwrap_or_else(|error| panic!("{name}: {error}")); - let write = state(&device, &write, "__entry_sw_write"); - for v in views() { - let (texture, view) = swizzled(&device, &v, Some(0xee)); - let bound = Bound { - textures: &[&view], - samplers: &[], - out: None, - }; - run(name, &device, &write, N, &bound); - let want: Vec = (0..N as usize).flat_map(|i| write_rule(&v, i)).collect(); - assert_eq!(bytes(&texture, &v), want, "{name}: {}", v.name); - } - println!("{name}: writes through each swizzled view undo the swizzle"); - }); -} - #[test] fn opencl_mode_reads_of_a_swizzled_image_answer_the_swizzled_texel() { let Some(read) = library(&read()) else { @@ -449,7 +377,7 @@ fn opencl_mode_reads_of_a_swizzled_image_answer_the_swizzled_texel() { 1, ); for v in views() { - let (_texture, view) = swizzled(&device, &v, None); + let (_texture, view) = swizzled(&device, &v); let o = floats_buffer(&device, &vec![-1.0; (2 * N * 4) as usize]); let bound = Bound { textures: &[&view],