Translator, runtime: an OpenCL-mode kernel's 1D images read their 2D textures under the identity domains

L61. A kernel of OpenCL mode that takes a 1D image stated RuntimeFact::OpenClLineTexture for each
such slot. That fact marks the variant in which the table domains read a 1D texture bound there,
as a Radeon Pro 5300M answers. The identity domains source no such fact, so every such kernel's
pipeline was Unsupported{IdentityDomains} when made, whatever else it did.

Apple's OpenCL binds a 2D texture of height 1 for an image1d_t and a 2D array of that height for an
image1d_array_t, and never a 1D texture. The kernel already reads its 1D images as those 2D textures
at row 0 (canon::opencl_1d), as the M3 Max and the 5300M answer. A 1D texture bound there is
outside documented Metal, and the Macs disagree on it: the M3 Max reads texel 0 at every
coordinate, the 5300M the 1D texture's texels, a UHD Graphics 630 layer 0 of an array.

- Translator: under the identity domains a kernel states no OpenClLineTexture and has no such
  variant; it reads the 2D textures. The table domains keep the fact and the variant.
  identity_unsourced no longer names a fact the identity domains never state.
- Runtime: a state records whether its kernel is of OpenCL mode (RuntimeFact::OpenClMode). A
  dispatch of one with a 1D or 1D array texture bound at any of its texture slots is the new
  typed Gap::OpenClLineTexture { slot }, not a read: Apple's OpenCL binds none, and Metal defines
  no reading of one. It is checked where the swizzle and bicubic checks run, when the state or a
  binding changes. Its doc ends in "Basis: ours".
- Docs: the runtime README's known gap is rewritten for the dispatch's refusal. API.md and the
  fact's doc say what the identity domains do. docs/REFUSALS.md and error/basis.rs are regenerated
  (Gap 30 to 31), and api_signatures.tsv is blessed (one variant).
- The runtime test opencl_lines now also binds a 1D texture at each of the kernel's three slots in
  turn. Each dispatch answers Gap::OpenClLineTexture naming that slot and writes nothing.

A refusal becomes a module, so SEMANTICS_VERSION 2316. The translator's refusal sites are
unchanged.
This commit is contained in:
Anees Iqbal committed 2026-12-02 07:25:18 -08:00
1 parent 283d8d8f50
commit 2f16658ac2
13 files changed
+108 -23

No files matched your search

+7 -7
View File
@@ -4057,13 +4057,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 kernel of OpenCL mode (`open_cl_mode_enabled`) reads a 1D image (`image1d_t` or
`image1d_array_t`) as the 2D texture of height 1, or the 2D array texture of that height, that
Apple's OpenCL binds for it. A dispatch with a 1D or 1D array texture bound at any of its texture
slots, which Apple's OpenCL never binds, is `Gap::OpenClLineTexture`: no reading of it is
documented Metal, and Macs answer differently (a Radeon Pro 5300M, macOS 26.7.1, reads the 1D
texture's texels, an Intel UHD Graphics 630 layer 0 of an array, an M3 Max texel 0 at every
coordinate). Test: `tests::opencl_lines`.
- 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
+16 -1
View File
@@ -980,7 +980,7 @@ impl ComputeCommandEncoder {
/// [`Refusal::BufferOffsetAlignment`] for a buffer the kernel reaches bound off the alignment
/// its function holds it to, which nothing records (a function kernel's argument of 8 or 16
/// bound at a multiple of 4 runs on its kernel's variant that holds it to 4);
/// [`Gap::SwizzledReadWrite`]; [`Gap::BicubicTexels`];
/// [`Gap::SwizzledReadWrite`]; [`Gap::OpenClLineTexture`]; [`Gap::BicubicTexels`];
/// [`Limit::LevelElements`] where no run of level elements holds a texture of several levels
/// the kernel writes or reads at a level other than the constant 0;
/// [`Limit::ThreadgroupMemory`], the imageblock's cells at the size
@@ -1101,6 +1101,21 @@ impl ComputeCommandEncoder {
}
}
let interface = &inner.whole.interface;
// A 1D texture bound for a kernel of OpenCL mode, which reads each 1D image as the 2D
// texture Apple's OpenCL binds for it and never a 1D one.
if interface.open_cl_mode {
for &(slot, _) in &interface.textures {
if let Some(Some(texture)) = self.textures.get(slot as usize) {
let line = matches!(
texture.descriptor().texture_type,
crate::TextureType::Type1D | crate::TextureType::Type1DArray
);
if line {
return Err(Error::Unsupported(Gap::OpenClLineTexture { slot }));
}
}
}
}
// A bicubic sample's texture, of a format the filter's treatment is known for.
for field in &interface.fields {
if let FieldValue::BicubicTexels(slot) = field.value {
+20
View File
@@ -1417,6 +1417,21 @@ pub enum Gap {
/// The function's texture slot.
slot: u32,
},
/// A dispatch of a kernel of OpenCL mode
/// ([`ComputePipelineDescriptor::open_cl_mode_enabled`](crate::ComputePipelineDescriptor::open_cl_mode_enabled))
/// whose texture slot `slot` is bound to a 1D or 1D array texture. Apple's OpenCL binds an
/// `image1d_t` as a 2D texture of height 1 and an `image1d_array_t` as a 2D array texture of
/// that height, and binds a 1D texture for no image, so the kernel reads each 1D image as that
/// 2D texture at row 0. What it reads from a 1D texture bound there is outside documented
/// Metal, and Macs answer it differently: a Radeon Pro 5300M (macOS 26.7.1) reads the 1D
/// texture's texels, an Intel UHD Graphics 630 layer 0 of an array, an M3 Max texel 0 at every
/// coordinate. Found when the pipeline state or a binding changes.
///
/// Basis: ours (no reading of it is documented Metal).
OpenClLineTexture {
/// The kernel's texture slot.
slot: u32,
},
/// A draw or dispatch whose function writes a texture slot, or reads one through its storage
/// image (`access::read_write`), bound to a texture made for shader writes with no storage
/// element, or, at a slot declared without a format (`TextureSlot::declared_format`; a texture
@@ -2958,6 +2973,11 @@ impl fmt::Display for Gap {
f,
"a read_write texture slot {slot} bound to a swizzled texture is not built"
),
Gap::OpenClLineTexture { slot } => write!(
f,
"an OpenCL-mode kernel's texture slot {slot} bound to a 1D texture, which Apple's \
OpenCL never binds, is not built"
),
Gap::StorageElement {
slot: Some(slot),
pixel_format,
@@ -157,6 +157,7 @@ impl Gap {
Gap::FillAlignment { .. } => RefusalBasis::Ours,
Gap::RenderPipeline { .. } => RefusalBasis::Ours,
Gap::SwizzledReadWrite { .. } => RefusalBasis::Ours,
Gap::OpenClLineTexture { .. } => RefusalBasis::Ours,
Gap::StorageElement { .. } => RefusalBasis::Ours,
Gap::BicubicTexels { .. } => RefusalBasis::Ours,
Gap::TextureView { .. } => RefusalBasis::Ours,
+9 -2
View File
@@ -717,6 +717,10 @@ pub(crate) struct Interface {
/// `read_write` slot it reads), which takes no swizzle: a swizzled texture bound there is
/// `Gap::SwizzledReadWrite`.
pub(crate) storage_reads: Vec<u32>,
/// Whether the kernel is of OpenCL mode (`RuntimeFact::OpenClMode`), which reads each 1D image
/// as the 2D texture Apple's OpenCL binds for it: a 1D or 1D array texture bound at any of its
/// texture slots, which Apple's OpenCL never binds, is `Gap::OpenClLineTexture`.
pub(crate) open_cl_mode: bool,
/// Each texture slot whose storage image the kernel declares without a format
/// (`TextureSlot::declared_format`), whose reads and writes the bound texture's format answers
/// without one: a slot declared with one (a texture atomic's) takes neither answer.
@@ -1699,6 +1703,7 @@ pub(crate) fn interface(
let mut private_arena = None;
let mut imageblock = None;
let mut own = OwnMemory::Static(pipeline.metal_info.static_threadgroup_memory_length);
let mut open_cl_mode = false;
for dependency in &pipeline.dependencies {
match dependency.fact {
RuntimeFact::LocalSizeConstraint { multiple } => multiples.push(multiple),
@@ -1745,8 +1750,9 @@ pub(crate) fn interface(
// The stage-in region, which the encoder pushes (`FieldValue::StageInRegion`).
RuntimeFact::StageInRegion => {}
// What the translator checks against the descriptor when it compiles, and nothing on
// the device reads.
RuntimeFact::CallStackDepth { .. } | RuntimeFact::OpenClMode => {}
// the device reads; OpenCL mode decides which textures a dispatch takes.
RuntimeFact::CallStackDepth { .. } => {}
RuntimeFact::OpenClMode => open_cl_mode = true,
// `RuntimeFact` is non-exhaustive: a fact this match does not name is one the encoder
// does not supply, and the refusal names it.
fact => {
@@ -1990,6 +1996,7 @@ pub(crate) fn interface(
views,
textures,
storage_reads,
open_cl_mode,
formatless,
numbered,
constexprs,
@@ -44,6 +44,7 @@ pub(crate) mod on_device {
views: Vec::new(),
textures: Vec::new(),
storage_reads: Vec::new(),
open_cl_mode: false,
formatless: Vec::new(),
numbered: Vec::new(),
constexprs: Vec::new(),
@@ -6,6 +6,11 @@
//! 4 × 1 reads `a` at its thread's `x`, the array `b` at `(x, 1)`, writes their sum to `w` and
//! `b`'s texel to `o[x]`.
//!
//! A 1D or 1D array texture bound at any of its texture slots, which Apple's OpenCL never binds,
//! is `Gap::OpenClLineTexture` at the dispatch: no reading of it is documented Metal, and the
//! Macs answer it differently (the M3 Max reads texel 0 at every coordinate, the 5300M the 1D
//! texture's texels, a UHD Graphics 630 layer 0 of an array).
//!
//! The module is LLVM text written here; `llvm-as` assembles it, and without it the test skips
//! visibly.
@@ -16,7 +21,7 @@ mod on_device {
floats, floats_buffer, kernel_list, library, state, words_buffer,
};
use crate::{
ComputePipelineState, Device, DispatchType, Error, IndexClass, PixelFormat, Region,
ComputePipelineState, Device, DispatchType, Error, Gap, IndexClass, PixelFormat, Region,
StorageMode, Texture, TextureDescriptor, TextureType, TextureUsage,
};
@@ -168,14 +173,16 @@ declare void @air.write_texture_1d.v4f32(ptr addrspace(1), i32, <4 x float>, i32
answer
}
/// Over 2D textures of height 1 the kernel reads row 0 of each and writes row 0 of `w`.
/// Over 2D textures of height 1 the kernel reads row 0 of each and writes row 0 of `w`; a 1D
/// texture, or a 1D array, bound at any of its texture slots is `Gap::OpenClLineTexture`
/// naming that slot, and nothing is written.
#[test]
fn every_device_reads_an_opencl_1d_image_as_its_2d_texture() {
let Some(library) = library(&lines()) else {
return;
};
each_device("opencl_lines", |name, _, device| {
let _textures = (device.grant_indices(IndexClass::Texture, 1, 3))
let _textures = (device.grant_indices(IndexClass::Texture, 1, 6))
.unwrap_or_else(|error| panic!("{name}: {error}"));
let state = state(&device, &library, "__entry_ol");
let a = texture(name, &device, (TextureType::Type2D, 1, false), 1);
@@ -206,7 +213,29 @@ declare void @air.write_texture_1d.v4f32(ptr addrspace(1), i32, <4 x float>, i32
})
.collect();
assert_eq!(written, sums, "{name}: w, a + b");
println!("{name}: OpenCL 1D images read as 2D textures");
// A 1D texture at each slot, the others as before: the dispatch's refusal names it.
let line = texture(name, &device, (TextureType::Type1D, 1, false), 4);
let lines = texture(name, &device, (TextureType::Type1DArray, 2, false), 5);
let line_w = texture(name, &device, (TextureType::Type1D, 1, true), 6);
let out = floats_buffer(&device, &[-7.0; 4 * W as usize]);
for (slot, bound) in [
(0, [&line, &b, &w]),
(1, [&a, &lines, &w]),
(2, [&a, &b, &line_w]),
] {
match dispatch(name, &device, &state, bound, &out) {
Err(Error::Unsupported(Gap::OpenClLineTexture { slot: s })) if s == slot => {}
other => panic!("{name}: a 1D texture at slot {slot}: {other:?}"),
}
}
assert_eq!(
floats(&out),
[-7.0; 4 * W as usize],
"{name}: a refused dispatch writes nothing"
);
println!(
"{name}: OpenCL 1D images read as 2D textures; 1D textures refused at 3 slots"
);
});
}
}
+1 -1
View File
@@ -60,7 +60,7 @@ mod tests;
/// unchanged version, and its bless records the version. Independent of the crate's version and of
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
/// history.
pub const SEMANTICS_VERSION: u32 = 2315;
pub const SEMANTICS_VERSION: u32 = 2316;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+6 -4
View File
@@ -1219,13 +1219,16 @@ pub fn select(
values: mp.values,
push: BTreeSet::new(),
// A call stack's depth, and OpenCL mode, which a compiled kernel's pipeline must match,
// and the mode's 1D images, which a 1D texture bound there reads in a variant.
// and the mode's 1D images, which a 1D texture bound there reads in a variant. Under the
// identity domains no variant is chosen: each 1D image reads the 2D texture Apple's
// OpenCL binds for it, and the consumer refuses a 1D texture there, whose read Metal does
// not define (Macs answer it differently).
facts: (e.call_stack.into_iter())
.map(|stack| RuntimeFact::CallStackDepth { depth: stack.depth })
.chain(inputs.open_cl_mode.then_some(RuntimeFact::OpenClMode))
.chain(
e.open_cl_1d_images
.iter()
(e.open_cl_1d_images.iter())
.filter(|_| !access::identity(p))
.map(|&index| RuntimeFact::OpenClLineTexture {
slot: SlotRef {
stage,
@@ -1831,7 +1834,6 @@ fn identity_unsourced(f: &RuntimeFact) -> bool {
| RuntimeFact::BicubicTexels { .. }
| RuntimeFact::SparseTexture { .. }
| RuntimeFact::SrgbTexture { .. }
| RuntimeFact::OpenClLineTexture { .. }
| RuntimeFact::SparseTextureWrites { .. }
| RuntimeFact::TextureSwizzle { .. }
| RuntimeFact::ConstantLanes { .. }
+5 -1
View File
@@ -243,7 +243,11 @@ pub enum RuntimeFact {
/// (`VariantKey::open_cl_lines`, `LoweringInputs::open_cl_lines`), under which the kernel
/// declares the slot as that 1D texture and reads it: each read, sample and size query answers
/// the 1D texture's values, of the layer an array access names, as a Radeon Pro 5300M (macOS
/// 26.7.1) answers. Any other texture bound there leaves the variant.
/// 26.7.1) answers. Any other texture bound there leaves the variant. Under the identity
/// domains a kernel states no such fact and has no such variant: it reads each 1D image as the
/// 2D texture, and the consumer refuses a 1D texture bound for it, whose read Metal does not
/// define (an M3 Max reads texel 0 at every coordinate, an Intel UHD Graphics 630 layer 0 of an
/// array).
OpenClLineTexture { slot: SlotRef },
/// The kernel's only simdgroup semantics are the barriers its lockstep order took
/// (`lower::simd::lockstep`), on a flattened tier, and they order only pairs whose threads meet
@@ -8423,6 +8423,7 @@ variant metal2vulkan-runtime::Gap::KernelInput KernelInput { kind: KernelInputKi
variant metal2vulkan-runtime::Gap::MemorylessTexture MemorylessTexture
variant metal2vulkan-runtime::Gap::MipmapFilter MipmapFilter { pixel_format: PixelFormat }
variant metal2vulkan-runtime::Gap::NoStageInRegion NoStageInRegion
variant metal2vulkan-runtime::Gap::OpenClLineTexture OpenClLineTexture { slot: u32 }
variant metal2vulkan-runtime::Gap::OverlappingCopy OverlappingCopy { pixel_format: PixelFormat }
variant metal2vulkan-runtime::Gap::PartialSimdgroups PartialSimdgroups { threads_per_threadgroup: [u32; 3], width: u32 }
variant metal2vulkan-runtime::Gap::PartialThreadgroups PartialThreadgroups { threads_per_grid: [u32; 3], threads_per_threadgroup: [u32; 3], site: PartialThreadgroupsSite }
Can't render this file because it is too large.
+4 -1
View File
@@ -828,7 +828,10 @@ through buffer arguments it reads at any index.
(`RuntimeFact::OpenClLineTexture`, `VariantKey::open_cl_lines`): each read, sample and size
query answers the 1D texture's values, of the layer an array access names, as a Radeon Pro
5300M (macOS 26.7.1) answers (an Intel UHD Graphics 630 reads layer 0 of the array, an M3 Max
texel 0 at every coordinate). Apple's OpenCL binds an image of most
texel 0 at every coordinate). Under the identity domains no variant is made: the kernel states
no `OpenClLineTexture`, reads each 1D image as the 2D texture, and a consumer refuses a 1D
texture bound for it (the runtime's `Gap::OpenClLineTexture`), since no reading of one is
documented Metal. Apple's OpenCL binds an image of most
channel orders as a swizzled view (on an M3 Max, macOS 27.0.1, with `CL_UNORM_INT8`: `CL_R`,
`CL_RG`, `CL_A`, `CL_RA` and `CL_INTENSITY` as `R8Unorm` or `RG8Unorm` views, `CL_BGRA`,
`CL_ARGB` and `CL_RGB` as `RGBA8Unorm` views). A read (with a sampler or without) answers the
+4 -2
View File
@@ -33,7 +33,7 @@ Columns:
| Devices below the runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Refusal` | 86 | 86 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Limit` | 21 | 21 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Gap` | 30 | 30 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Gap` | 31 | 31 | 0 | 0 | 0 | 0 | 0 |
## Totals by basis
@@ -46,7 +46,7 @@ Columns:
| Devices below the runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 |
| The runtime's `Refusal` | 23 | 25 | 0 | 0 | 38 | 0 | 0 | 0 |
| The runtime's `Limit` | 0 | 0 | 0 | 15 | 6 | 0 | 0 | 0 |
| The runtime's `Gap` | 0 | 0 | 0 | 2 | 28 | 0 | 0 | 0 |
| The runtime's `Gap` | 0 | 0 | 0 | 2 | 29 | 0 | 0 | 0 |
## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`)
@@ -368,6 +368,7 @@ Columns:
| `FillAlignment` | `BlitCommandEncoder::fill_buffer` of a range that does not start and end on whole 4-byte words of the bytes shaders reach, which Metal fills byte... | every device (a public call's own check of its arguments) | `ours`: `vkCmdFillBuffer` writes whole words; a byte fill is built when a replay stream makes one | 1: `crates/metal2vulkan-runtime/src/blit.rs (fill_range)` | `-` |
| `RenderPipeline` | A render pipeline state of something the runtime does not build yet | every device (a public call's own check of its arguments) | `ours`: the replay streams' render pipelines draw into colour, depth and stencil attachments of one sample, with no tessellation and no framebuffer fetch; each other kind is built when a replay stream makes one | 5: `crates/metal2vulkan-runtime/src/render.rs (draw_input)`, `crates/metal2vulkan-runtime/src/render.rs (of, 3 sites)` (+1) | `-` |
| `SwizzledReadWrite` | A draw or dispatch whose function declares `access::read_write` at texture slot `slot` and reads it, where the texture bound there has a swizzle... | every device (a public call's own check of its arguments) | `ours`: built when a replay stream counts one | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` |
| `OpenClLineTexture` | A dispatch of a kernel of OpenCL mode (`ComputePipelineDescriptor::open_cl_mode_enabled`) whose texture slot `slot` is bound to a 1D or 1D array... | every device (a public call's own check of its arguments) | `ours`: no reading of it is documented Metal | 1: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)` | `-` |
| `StorageElement` | A draw or dispatch whose function writes a texture slot, or reads one through its storage image (`access::read_write`), bound to a texture made... | every device (a public call's own check of its arguments) | `ours`: the storage element through a view of the nearest format whose storage Vulkan requires of every device, with the translator's conversion, is the form to build | 4: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch, 2 sites)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find, 2 sites)` | `-` |
| `BicubicTexels` | A dispatch or a draw whose function samples texture slot `slot` through a constexpr sampler with Metal's bicubic filter (`filter::bicubic`), where... | every device (a public call's own check of its arguments) | `ours`: each refused format's treatment is built when a guest binds one | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` |
| `TextureView` | `Texture::new_texture_view` of a kind Metal makes and the runtime does not build | every device (a public call's own check of its arguments) | `ours`: the replay streams' views that compute binds are same-format views of every slice, 2D views of one slice of a 2D array, and level subranges, swizzled or not; each other kind is built when a replay stream binds one | 1: `crates/metal2vulkan-runtime/src/texture.rs (view)` | `-` |
@@ -655,6 +656,7 @@ Each refusal's sites, with the function that builds it.
- `rt:Gap::FillAlignment`: `crates/metal2vulkan-runtime/src/blit.rs (fill_range)`
- `rt:Gap::RenderPipeline`: `crates/metal2vulkan-runtime/src/render.rs (draw_input)`; `crates/metal2vulkan-runtime/src/render.rs (of, 3 sites)`; `crates/metal2vulkan-runtime/src/render.rs (refuse)`
- `rt:Gap::SwizzledReadWrite`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find)`
- `rt:Gap::OpenClLineTexture`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`
- `rt:Gap::StorageElement`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch, 2 sites)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find, 2 sites)`
- `rt:Gap::BicubicTexels`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find)`
- `rt:Gap::TextureView`: `crates/metal2vulkan-runtime/src/texture.rs (view)`