Files
metal2vulkan/crates
Anees Iqbal b2d50435c7 OpenCL mode images: format queries read the third hidden buffer, 1D images read their 2D bindings
A guest's OpenCL programs run as Metal compute pipelines of OpenCL mode. Two of their image
paths failed where Metal runs them:

- get_image_channel_order and get_image_channel_data_type compile to
  air.get_channel_{order,data_type}_texture_<kind>(tex), which decoded as unknown. They now
  decode as Query::ChannelOrder / ChannelDataType for the 1d, 1d_array, 2d, 2d_array and 3d
  kinds. canon::opencl reads each one of an image argument at a constant texture index t from
  the third hidden buffer (__image_order_data_type_table): word 2t+1 for the order, 2t for the
  data type. Outside OpenCL mode lowering refuses the query (Unsupported, Lowering(Texture)).
  Metal refuses an OpenCL-mode pipeline that queries a buffer or depth image ("Failed to process
  function bitcode(2) in plugin"), so those kinds stay undecoded.
- Apple's OpenCL binds a 2D texture of height 1 for an image1d_t and a 2D array texture of
  height 1 for an image1d_array_t, while the AIR declares texture1d / texture1d_array. The
  runtime declared 1D slots, the binder found the 2D textures incompatible and wrote neutrals,
  and the kernel read zeros. canon::opencl_1d (OpenCL-mode kernels only, before SCCP) makes each
  read, sample, write, get_width and get_array_size of a 1D texture the 2D operation, coordinate
  (x, 0), sampled coordinate (x, 0.5), offset (o, 0) or zero, through a built function inlined
  as block_read's are, so the slot is the 2D (array) texture the binder binds. Every other path
  is unchanged.

The call-then-inline tail block_read and async_copy each carried is inline::inline_calls,
shared by the three expansions.

Measured with a probe of our own OpenCL C kernels (Metal's OpenCL mode driven directly, the
hidden table word i = i*0x10000 + 0x1234) on an M3 Max (macOS 27.0.1, jobs m3-max-15462,
m3-max-15473) and a Radeon Pro 5300M (macOS 26.7.1, jobs m3-max-15469, m3-max-15475): each
format query answers its word as stated (q_1d, q_1da, q_2da, q_3d, q_w2d, q_w1d: 0x31234,
0x21234 for texture 1); the reflection states image1d_t as MTLTextureType2D and image1d_array_t
as 2DArray; over 2D bindings of height 1 every read, sample (integer, unnormalized, and
normalized linear at a border-clamped edge), write and size query answers the 1D image's value.
Two queries through one wrapper of the same kind answer one shared word on both GPUs (the M3
Max's and the 5300M's from different calls); here each answers its own image's. The AIR shapes
of both macOS versions' compilers are identical (declarations diffed).

Tests: canon::tests::opencl (the words read, the 2D operations and the (x, 0.5) pair, the
undecoded kinds), families_tests' observed declarations, the translator's engine_opencl_mode
(2D slot types in the mode, Lowering(Texture) without it), and the runtime's opencl_images
device tests (formats, reads and writes against the measured answers).

SEMANTICS_VERSION 2030.
2026-11-11 07:04:32 -08:00
..