Argument-buffer textures read through a sampler: border texels from the handle-table entry

What: a Metal 4.1 read(sampler, ...) of a texture held in an argument buffer now hands back
Metal's border texel of the resident texture, its pixel format's through its swizzle, for every
sampler: a constexpr one of any border colour, a runtime [[sampler(n)]] and an argument buffer's
sampler (the colour from the sampler's word).
- The binder writes each texture's border texels (metal::sampler::border_texels of its format
  and swizzle, the layout of a slot's BorderTexels specialization) in its handle-table entry's
  flags, bits 3 to 14 (memory::handles::FLAG_BORDER_TEXELS); handle_entry_flags carries them, so
  a consumer's own table of every ID gets them too.
- A module with such a read searches the table in a new indexed form (Lookup::Indexed): the
  handle is the element with the found entry's index in its top 16 bits (HANDLE_ENTRY). The read
  loads the entry's border texels by it (handles::border_texels); every use that reads another of
  the entry's flags (texel class, red-blue order, out-of-bounds alpha) loads them from the entry
  into the flagged handle's layout (handles::flagged_handle), through one typed value
  (texture::emit::HeapFlags) so no reader sees the entry index in those bits.
- through::finish selects the border texel for slots and heap elements alike; a heap member read
  by its raw texels (an extended-range form) takes its border and its zero past the level or
  layer from its own image's addressing inside the raw arm, not the float array's neutral's.
- The old heap path, which selected the out-of-bounds texel (transparent black, unswizzled) and
  refused every other border colour and runtime sampler NotImplemented(ArgumentBufferTextures),
  is gone, with ReadSampler::transparent and the forced alpha flag of such reads.

Why: the M3 runs all three (conformance cases read-through-heap-border, read-through-heap-sampler,
and read-through-rgba8-swizzled's rt_heap_zero, where (G, R, 1, 0) reads (0, 0, 1, 0) past the
edge and we read (0, 0, 0, 0)). A 32-bit heap handle had no room for 12 border bits beside the
element, class, red-blue and alpha fields; the entry does (bits 3 to 14 were unused).

SEMANTICS_VERSION 2017 (translation output changes). ARTIFACT_FORMAT_VERSION unchanged: no
encoded type changed. RUNTIME (for the orchestrator's bump): the runtime's handle tables
(heap_sets.rs, through bind::handle_entry_flags) now carry the border-texel bits.

Ledger: the three rows of these gaps go; llvmpipe's rt_heap_zero row of the swizzled case keeps
only llvmpipe's 8-bit unorm conversion. FAST-PATHS known gap removed; REFUSALS.md,
CONFORMANCE-COVERAGE.md regenerated (METAL-COVERAGE.md unchanged).

Verified: not yet built (next: Linux build, clippy and the touched tests).
(cherry picked from commit bc000fa475e572131248b908541dbe29f1f5996c)
This commit is contained in:
Anees Iqbal committed 2026-11-10 04:45:05 -08:00
1 parent acfb2e8d70
commit 24025b3866
15 files changed
+888 -226

No files matched your search

@@ -3443,9 +3443,6 @@ ycbcr-minify-band-x NAVI31 divergent case/samples the digest is c3c7fb23a2e0967d
ycbcr-minify-band-x NAVI31 divergent case/samples/ends the digest is 4357ed31b7cedf0354f0a19f06dfd475707aab6943932bbea506a947fa25531c on Metal and f2b732d0507a76bebef20afbc38408784a3a5f31e0e7bbc42fdcba2ba47ad92b here The site is the first and last 256 samples of the band, held by their digest alone: a 4K `x420` (`YCBCR10_420_2P`) surface minified along x through a linear sampler, at the 2,048 places along the axis where a footprint's rounding decides which side of a 1/256 step a sample reads. Metal reads the planes in place and its filter puts the switches where the recording holds them. The RX 7900 XTX's memory is not the host's, so the slot binds the texture's image of converted texels; RADV does not convert this 10-bit format (`RuntimeDriverDefect::TenBitCodesReadAsWords`, which `ycbcr_device.rs` names for RADV), so the texels hold Metal's fixed-point conversion, and each sample is the device's own linear filter of them, off the grid Metal sums the format's steps on, so the switches fall elsewhere. The filter is the device's native answer, announced for this case as `device-sampling`, a suite native note that loosens no value (`replay::NATIVE_NOTES`), and no other form is built. The site compares by its digest, so how many samples moved and by how much is not separated here. On the Radeon 780M (RADV PHOENIX), whose memory is the host's, this case does not diverge. Measured on the RX 7900 XTX, 2026-11-07.
ycbcr-minify-band-y NAVI31 divergent case/samples the digest is 536bb62bdfb366a18744a10f34682339739b789ee08d08d2d6d601731baf7533 on Metal and 733759338deb22e41d9b3dd2f0ac1b32a54f6ff7216b68a1bc4cede5b0b6b9c4 here The site is the whole band's 34,816 samples, held by their digest alone: a 4K `x420` (`YCBCR10_420_2P`) surface minified along y through a linear sampler, at the 2,048 places along the axis where a footprint's rounding decides which side of a 1/256 step a sample reads. Metal reads the planes in place and its filter puts the switches where the recording holds them. The RX 7900 XTX's memory is not the host's, so the slot binds the texture's image of converted texels; RADV does not convert this 10-bit format (`RuntimeDriverDefect::TenBitCodesReadAsWords`, which `ycbcr_device.rs` names for RADV), so the texels hold Metal's fixed-point conversion, and each sample is the device's own linear filter of them, off the grid Metal sums the format's steps on, so the switches fall elsewhere. The filter is the device's native answer, announced for this case as `device-sampling`, a suite native note that loosens no value (`replay::NATIVE_NOTES`), and no other form is built. The site compares by its digest, so how many samples moved and by how much is not separated here. On the Radeon 780M (RADV PHOENIX), whose memory is the host's, this case does not diverge. Measured on the RX 7900 XTX, 2026-11-07.
ycbcr-minify-band-y NAVI31 divergent case/samples/ends the digest is 74811b9b801f4e14f0642cb23504778fc1e4fd8d899d6bd2aad19483bc8b034a on Metal and eb74d8208949347c126eb1c44f97ba10c33b4c9a6b192506949a370cfedd40b5 here The site is the first and last 256 samples of the band, held by their digest alone: a 4K `x420` (`YCBCR10_420_2P`) surface minified along y through a linear sampler, at the 2,048 places along the axis where a footprint's rounding decides which side of a 1/256 step a sample reads. Metal reads the planes in place and its filter puts the switches where the recording holds them. The RX 7900 XTX's memory is not the host's, so the slot binds the texture's image of converted texels; RADV does not convert this 10-bit format (`RuntimeDriverDefect::TenBitCodesReadAsWords`, which `ycbcr_device.rs` names for RADV), so the texels hold Metal's fixed-point conversion, and each sample is the device's own linear filter of them, off the grid Metal sums the format's steps on, so the switches fall elsewhere. The filter is the device's native answer, announced for this case as `device-sampling`, a suite native note that loosens no value (`replay::NATIVE_NOTES`), and no other form is built. The site compares by its digest, so how many samples moved and by how much is not separated here. On the Radeon 780M (RADV PHOENIX), whose memory is the host's, this case does not diverge. Measured on the RX 7900 XTX, 2026-11-07.
read-through-rgba8-swizzled Apple M3 Max divergent case/words/rt_heap_zero 12 elements differ (U32), the largest difference 1065353216 An argument buffer's texture read through clamp_to_zero past its edge: Metal reads the transparent-black border texel through the texture's swizzle ((G, R, 1, 0) reads (0, 0, 1, 0)); we read the out-of-bounds texel, whose alpha is the format's, unswizzled, because a heap handle carries the format's alpha alone (lower/texture/emit/through.rs). The fix is a handle or table field holding the element's border texels.
read-through-heap-border * refused case/pipeline/rt_heap_ow Err(Error::Unsupported("unsupported: Unsupported { feature: ArgumentBufferTextures, needs: NotImplemented, location: Some(Function { func: \"rt_heap_ow\", block: Some(0), inst: Some(7) }), symbol: None }")) An argument buffer's texture read through clamp_to_border with an opaque border: Metal reads the border colour in the texture's channels through its swizzle; we refuse it, because a heap handle carries no border texel (lower/texture/mod.rs select_through). The fix is a handle or table field holding the element's border texels.
read-through-heap-sampler * refused case/pipeline/rt_heap_arg Err(Error::Unsupported("unsupported: Unsupported { feature: ArgumentBufferTextures, needs: NotImplemented, location: Some(Function { func: \"rt_heap_arg\", block: Some(0), inst: Some(7) }), symbol: None }")) An argument buffer's texture read through a runtime sampler: Metal addresses it by the sampler's state, a border mode reading the border colour in the texture's channels; we refuse it, because the runtime sampler may name any border colour and a heap handle carries no border texel (lower/texture/mod.rs select_through). The fix is a handle or table field holding the element's border texels.
read-through-rgba8 llvmpipe divergent case/words/rt_alpha 6 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8 llvmpipe divergent case/words/rt_arg/border-black 8 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8 llvmpipe divergent case/words/rt_arg/border-mip 6 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
@@ -3493,7 +3490,7 @@ read-through-rgba8-swizzled llvmpipe divergent case/words/rt_arg/zero-white 3 el
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_border_ob 2 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_border_ow 2 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_filtered 6 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_heap_zero 14 elements differ (U32), the largest difference 1065353216 An argument buffer's texture read through clamp_to_zero past its edge: Metal reads the transparent-black border texel through the texture's swizzle ((G, R, 1, 0) reads (0, 0, 1, 0)); we read the out-of-bounds texel, whose alpha is the format's, unswizzled, because a heap handle carries the format's alpha alone (lower/texture/emit/through.rs). The fix is a handle or table field holding the element's border texels. Two more elements are llvmpipe's 8-bit unorm conversion, one f32 ulp high.
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_heap_zero 2 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_mip 5 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_mip_zero 1 element differs (U32): Metal 1052951235 (0x3ec2c2c3), ours 1052951236 (0x3ec2c2c4) A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
read-through-rgba8-swizzled llvmpipe divergent case/words/rt_mirrored_offset 7 elements differ (U32), the largest difference 1 A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal reads 0x3ec2c2c3), the device's native texel conversion (rule 1); the addressing and every border texel agree.
Can't render this file because it is too large.
@@ -19,8 +19,8 @@
//! **One case per texture**, so a venue that cannot make one kind (a 1D texture, a texture buffer)
//! answers its own typed refusal at its own row. The two kernels that read an argument buffer's
//! texture through a border colour other than transparent black, or through a runtime sampler, are
//! cases of their own: the translator refuses them (`NotImplemented(ArgumentBufferTextures)`: a
//! heap texture's handle carries no border texel), and a refusal stops its case at the pipeline.
//! cases of their own, so a venue that refuses one (a device without the handle heap's
//! descriptor-indexing features) stops only its own case at the pipeline.
//!
//! Every output word holds [`BLANK`] before its dispatch, so a word a kernel did not write is a
//! recorded value. Nothing here can fault a GPU: one compute pass a read, at most 20 threads, no
@@ -776,19 +776,14 @@ impl Case for ReadThrough {
// A read through an argument buffer's sampler or texture takes the handle heap, whose set
// MoltenVK's layout query refuses though it runs it: measured on the M3 Max through
// MoltenVK, where all four plane cases announced `set-past-layout-support` and nothing
// else, every value exact but the swizzled case's argument-buffer texture. A case whose
// read is refused stops at its pipeline and announces nothing.
// else.
let heap = self.reads.iter().any(|read| {
matches!(
read.through,
Through::Table(..) | Through::HeapTexture | Through::HeapTextureSlot(..)
)
});
let refused = self
.reads
.iter()
.any(|read| matches!(read.entry, "rt_heap_ow" | "rt_heap_arg"));
match heap && !refused {
match heap {
true => vec![crate::replay::set_past_layout_notice()],
false => Vec::new(),
}
+14 -5
View File
@@ -65,8 +65,10 @@
//! names misses. A member's flags are [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`] where its pixel format
//! has no alpha (`metal::format::out_of_bounds_alpha_one`): a module whose shader-checked heap
//! read observes the alpha takes Metal's out-of-bounds alpha from it; [`FLAG_RED_BLUE`] where
//! its pixel format is blue-first (`metal::format::red_blue_exchanged`); and its texel class in
//! [`FLAG_TEXEL_CLASS`]. Every other bit is 0.
//! its pixel format is blue-first (`metal::format::red_blue_exchanged`); its border texels in
//! [`FLAG_BORDER_TEXELS`] (`metal::sampler::border_texels` of its pixel format and swizzle, a
//! placeholder format's those of the neutral it reads), which a read through a sampler hands
//! back at a border; and its texel class in [`FLAG_TEXEL_CLASS`]. Every other bit is 0.
//! - **Heap samplers**. A heap image is sampled through a separate sampler binding
//! (`BindingSource::HeapSampler`) in set 0: a constexpr sampler is the layout's immutable sampler
//! and takes no write; a runtime `[[sampler(n)]]` is written with the sampler bound at slot `n`
@@ -142,7 +144,7 @@ use crate::device::requirements::FormatUsage;
use crate::device::DeviceProfile;
use crate::error::{BindError, Feature, Unsupported};
use crate::memory::handles::{
lookup_host, ENTRY_ELEMENT, ENTRY_FLAGS, ENTRY_ID_HI, ENTRY_ID_LO,
lookup_host, ENTRY_ELEMENT, ENTRY_FLAGS, ENTRY_ID_HI, ENTRY_ID_LO, FLAG_BORDER_TEXELS,
FLAG_OUT_OF_BOUNDS_ALPHA_ONE, FLAG_RED_BLUE, FLAG_TEXEL_CLASS, NEUTRAL_ELEMENT, TABLE_CAPACITY,
TABLE_ENTRY_BYTES,
};
@@ -469,7 +471,9 @@ pub fn heap_element(
/// where its pixel format has no alpha, so a shader-checked read past the texture takes Metal's
/// out-of-bounds alpha of 1; bit 2 where its pixel format is blue-first
/// (`metal::format::red_blue_exchanged`), so a storage access exchanges red and blue where the
/// heap views it through its RGBA-order twin; bits 16 to 28 the index of the texture's texel class
/// heap views it through its RGBA-order twin; bits 3 to 14 its border texels
/// (`metal::sampler::border_texels` of its pixel format and swizzle), which a Metal 4.1 read
/// through a sampler hands back at a border; bits 16 to 28 the index of the texture's texel class
/// (`metal::texel_format::heap_class_index` of its pixel format and swizzle), by which the shader
/// emulates Metal's linear filter of the texture's texels, 0 for a swizzled texture; every other
/// bit 0. A caller passes the word through as is.
@@ -489,9 +493,14 @@ fn entry_flags(shape: &TextureShape) -> u32 {
true => FLAG_RED_BLUE,
false => 0,
};
// A placeholder pixel format's member reads its neutral, whose border texels a slot bound to
// one takes too.
let border = crate::metal::sampler::border_texels(pixel_format, swizzle)
.unwrap_or(crate::metal::sampler::NEUTRAL_BORDER_TEXELS)
<< FLAG_BORDER_TEXELS.trailing_zeros();
let index = crate::metal::texel_format::heap_class_index(pixel_format, swizzle);
let class = index << FLAG_TEXEL_CLASS.trailing_zeros();
alpha | red_blue | (class & FLAG_TEXEL_CLASS)
alpha | red_blue | (border & FLAG_BORDER_TEXELS) | (class & FLAG_TEXEL_CLASS)
}
/// A conversion a storage access through a heap handle makes of the texels of a member its
@@ -34,9 +34,12 @@
//! Merges of heap handles are the integer operations above; a texture operation on one indexes its
//! group's heap array ([`heap_target`], the texture family). The function then reads the handle
//! table, one more storage descriptor of the stage. Where a shader-checked heap read observes its
//! alpha, the search also carries the entry's out-of-bounds-alpha flag in the handle's bit 31, and
//! where the shader makes a heap depth comparison its depth flags in bits 29 and 30
//! (`memory::handles::Lookup::Flagged`).
//! alpha, the search also carries the entry's out-of-bounds-alpha flag in the handle's bit 31,
//! where a heap access reads its texel class the class's index in bits 16 to 28, and where a heap
//! storage access converts by its red-blue order that flag in bit 30
//! (`memory::handles::Lookup::Flagged`); where a heap read through a sampler may hand back its
//! border texels, the search carries the entry's index in bits 16 to 31 instead, and every use
//! reads the entry's flags it needs from the table (`memory::handles::Lookup::Indexed`).
//!
//! **Heap samplers** (the sampler half). A sampler handle loaded from an argument buffer is
//! searched the same way in the stage's sampler table ([`HandleStrategy::SamplerLookup`],
+20 -6
View File
@@ -785,6 +785,12 @@ pub struct AccessPlan {
/// red-blue order (`lower::texture::heap_storage_conversions`): the handle-table search
/// carries the entry's `FLAG_RED_BLUE` too (`memory::handles::Lookup::Flagged`).
pub heap_red_blue: bool,
/// A heap texture's read through a sampler may hand back its border texels
/// (`lower::texture::Through`), which its handle-table entry holds
/// (`memory::handles::FLAG_BORDER_TEXELS`): the search yields each heap handle's entry index
/// beside its element (`memory::handles::Lookup::Indexed`), by which the read loads them, and
/// every use reads the entry's other flags it needs from the entry.
pub heap_border: bool,
/// The relaxed atomic loads an exit of a loop holding them depends on ([`atomic::spin`]): each
/// acquires its memory. Planned before any instruction is selected.
pub spins: BTreeSet<InstId>,
@@ -802,14 +808,22 @@ impl AccessPlan {
/// What the function's handle-table search yields.
pub fn lookup(&self) -> crate::memory::handles::Lookup {
if self.heap_alpha || self.carries_class() || self.heap_red_blue {
crate::memory::handles::Lookup::Flagged {
alpha: self.heap_alpha,
class: self.carries_class(),
red_blue: self.heap_red_blue,
use crate::memory::handles::Lookup;
let (alpha, class, red_blue) = (self.heap_alpha, self.carries_class(), self.heap_red_blue);
if self.heap_border {
Lookup::Indexed {
alpha,
class,
red_blue,
}
} else if alpha || class || red_blue {
Lookup::Flagged {
alpha,
class,
red_blue,
}
} else {
crate::memory::handles::Lookup::Element
Lookup::Element
}
}
}
@@ -149,7 +149,8 @@ pub(crate) fn emit(
}
let t = Tys::new(fb)?;
let h = cx.operand(fb, handle)?;
let (form, member) = crate::lower::texture::heap_raw_form(fb, h)?;
let flags = crate::lower::texture::heap_flags(cx, fb, h)?;
let (form, member) = crate::lower::texture::heap_raw_form(fb, flags)?;
let bfloat = bfloat_form(fb, &t, form)?;
// A runtime sampler's word, and whether it states a filter the emulation answers.
let word = match &raw.state {
+107 -55
View File
@@ -384,8 +384,8 @@ struct Loaded {
live: Option<SValue>,
/// The level of a slot's level views is one of the bound texture's.
within: Option<SValue>,
/// A heap element's handle, where it carries the out-of-bounds-alpha flag.
flagged: Option<SValue>,
/// A heap element's flags, where its handle carries the out-of-bounds-alpha flag.
flagged: Option<HeapFlags>,
}
/// The declaration of `image`.
@@ -536,15 +536,15 @@ pub(crate) struct HeapElement {
pub img: SValue,
/// The handle is live (not the null element).
pub live: SValue,
/// The handle, where the function's handle-table search carries the element's
/// out-of-bounds-alpha flag in it (`memory::handles::Lookup::Flagged`): `heap_alpha_one` reads
/// The handle's flags, where the function's handle-table search carries the element's
/// out-of-bounds-alpha flag (`memory::handles::Lookup`'s `alpha`): `heap_alpha_one` reads
/// the flag.
pub flagged: Option<SValue>,
pub flagged: Option<HeapFlags>,
}
/// The element of heap handle `h`: the handle masked to its element where the function's
/// handle-table search carries flags in it (`memory::handles::Lookup::element_mask`), else the
/// handle itself.
/// The element of heap handle `h` (as the function's handle-table search yields it): the handle
/// masked to its element where the search carries anything beside it
/// (`memory::handles::Lookup::element_mask`), else the handle itself.
fn heap_element_index(cx: &EmitCx<'_>, fb: &mut FunctionBuilder<'_>, h: SValue) -> BResult<SValue> {
let Some(element) = cx.plan.families.access.lookup().element_mask() else {
return Ok(h);
@@ -553,11 +553,60 @@ fn heap_element_index(cx: &EmitCx<'_>, fb: &mut FunctionBuilder<'_>, h: SValue)
fb.binary(BinOp::BitwiseAnd, h, mask)
}
/// Whether the flagged heap handle `h` ([`HeapElement::flagged`]) has [`HANDLE_ALPHA_ONE`] set:
/// The flags of a heap handle its uses read (its texel class, red-blue order and
/// out-of-bounds-alpha flag, as the function's search reads them), in the layout of the handle
/// a flagged search yields (`memory::handles::Lookup::Flagged`: `HANDLE_TEXEL_CLASS`,
/// `HANDLE_RED_BLUE`, `HANDLE_ALPHA_ONE`). The texture family makes one only through
/// [`heap_flags`], so a handle that carries its entry's index in those bits (`Lookup::Indexed`)
/// never reaches a reader of them.
#[derive(Clone, Copy)]
pub(crate) struct HeapFlags(pub(super) SValue);
/// The flags of heap handle `h` (as the function's handle-table search yields it): the handle
/// itself where the search carries them in it, else, where it carries the entry's index
/// (`memory::handles::Lookup::Indexed`), the handle a flagged search would have yielded, the
/// entry's flags read from the handle table (`memory::handles::flagged_handle`).
pub(crate) fn heap_flags(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
h: SValue,
) -> BResult<HeapFlags> {
use crate::memory::handles::Lookup;
let form = cx.plan.families.access.lookup();
if !matches!(form, Lookup::Indexed { .. }) {
return Ok(HeapFlags(h));
}
let Some(table) = cx.decl.families.access.handle_table else {
return Err(cx.fail("an indexed heap handle without its table"));
};
let flagged = crate::memory::handles::flagged_handle(fb, table.table, h, form)?;
Ok(HeapFlags(flagged))
}
/// The border texels of the texture of heap handle `h` (as the function's handle-table search
/// yields it, `memory::handles::Lookup::Indexed`), from the entry it names
/// (`memory::handles::border_texels`): a `u32` in the layout of a slot's `BorderTexels`
/// specialization.
pub(super) fn heap_border_texels(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
h: SValue,
) -> BResult<SValue> {
use crate::memory::handles::Lookup;
if !matches!(cx.plan.families.access.lookup(), Lookup::Indexed { .. }) {
return Err(cx.fail("a heap read's border texels without its entry's index"));
}
let Some(table) = cx.decl.families.access.handle_table else {
return Err(cx.fail("an indexed heap handle without its table"));
};
crate::memory::handles::border_texels(fb, table.table, h)
}
/// Whether heap handle flags `h` ([`HeapElement::flagged`]) have [`HANDLE_ALPHA_ONE`] set:
/// its texture's pixel format has no alpha, so Metal reads alpha 1 out of bounds.
fn heap_alpha_one(fb: &mut FunctionBuilder<'_>, h: SValue) -> BResult<SValue> {
fn heap_alpha_one(fb: &mut FunctionBuilder<'_>, h: HeapFlags) -> BResult<SValue> {
let bit = u32s(fb, 1, HANDLE_ALPHA_ONE)?;
let flag = fb.binary(BinOp::BitwiseAnd, h, bit)?;
let flag = fb.binary(BinOp::BitwiseAnd, h.0, bit)?;
let zero = u32s(fb, 1, 0)?;
fb.binary(BinOp::INotEqual, flag, zero)
}
@@ -611,7 +660,10 @@ fn heap_element_of(
let base = fb.module().global_value(g)?;
let h = cx.operand(fb, handle)?;
let element = heap_element_index(cx, fb, h)?;
let flagged = cx.plan.families.access.heap_alpha.then_some(h);
let flagged = match cx.plan.families.access.heap_alpha {
true => Some(heap_flags(cx, fb, h)?),
false => None,
};
let p = fb.access_chain_non_uniform(base, element)?;
let img = fb.load(p, MemAccess::default())?;
let null = u32s(fb, 1, NEUTRAL_ELEMENT)?;
@@ -818,6 +870,7 @@ fn heap_key_among(
) -> BResult<SValue> {
use crate::memory::handles::{HANDLE_RED_BLUE, HANDLE_TEXEL_CLASS};
let h = cx.operand(fb, handle)?;
let HeapFlags(h) = heap_flags(cx, fb, h)?;
let field = u32s(fb, 1, HANDLE_TEXEL_CLASS | HANDLE_RED_BLUE)?;
let key = fb.binary(BinOp::BitwiseAnd, h, field)?;
let mut among = None;
@@ -1095,7 +1148,8 @@ pub(crate) fn heap_half_class(
return Ok(None);
};
let h = cx.operand(fb, handle)?;
let class = super::heap_texel_class(cx, fb, h)?;
let flags = heap_flags(cx, fb, h)?;
let class = super::heap_texel_class(cx, fb, flags)?;
Ok(Some(HalfClass {
routine,
class: ClassOf::Heap(class),
@@ -1613,6 +1667,7 @@ fn heap_class_among(
) -> BResult<SValue> {
use crate::memory::handles::HANDLE_TEXEL_CLASS;
let h = cx.operand(fb, handle)?;
let HeapFlags(h) = heap_flags(cx, fb, h)?;
let shift = u32s(fb, 1, HANDLE_TEXEL_CLASS.trailing_zeros())?;
let mask = u32s(
fb,
@@ -1887,7 +1942,7 @@ pub(super) fn out_of_bounds_texel(
decl: &ImageDecl,
image: &ImageRef,
alpha: bool,
flagged: Option<SValue>,
flagged: Option<HeapFlags>,
) -> BResult<SValue> {
// An extended-range slot's out-of-bounds texel is Metal's value, selected after the decode.
let (elem, one) = match decl.held_class() {
@@ -2409,18 +2464,6 @@ fn read_texel(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BR
(true, None) => in_range,
(false, w) => w,
};
// A heap element read through a sampler, outside on a border axis, hands back the transparent
// black border texel, its out-of-bounds texel (`texture::select_through`).
let inb = match (&through, r.image) {
(Some((_, a)), ImageRef::Heap { .. }) => match a.border {
Some(out) => {
let kept = fb.unary(UnOp::LogicalNot, out)?;
Some(and(fb, inb, kept)?)
}
None => inb,
},
_ => inb,
};
let ops = ImageOperands {
lod: level,
sample,
@@ -2513,16 +2556,18 @@ fn read_texel(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BR
},
};
// A heap member of a form a heap reads: its raw texel's value, Metal's out-of-bounds texel
// selected against its own image, which the float array's test below then leaves.
let texel = match r.heap_raw {
// selected against its own image, which the float array's test below then leaves, and a read
// through a sampler's border texel and zero past its level or layer there too, which the
// float array's addressing below then leaves.
let (texel, raw_member) = match r.heap_raw {
true => {
let (texel, member) = heap_raw_texel(cx, fb, r, texel)?;
if let Some(i) = inb {
inb = Some(fb.binary(BinOp::LogicalOr, member, i)?);
}
texel
(texel, Some(member))
}
false => texel,
false => (texel, None),
};
// An `A8Unorm` storage member's texel held in red, Metal's `(0, 0, 0, r)` before Metal's
// out-of-bounds texel is selected.
@@ -2588,9 +2633,10 @@ fn read_texel(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BR
(true, ImageRef::Slot(index)) => constant_lanes(cx, fb, index, texel, None)?,
_ => texel,
};
// A read through a sampler's border texel, and its zero past its level or layer.
// A read through a sampler's border texel, and its zero past its level or layer, but where a
// heap member's raw texel already holds them.
let texel = match &through {
Some((state, a)) => through::finish(cx, fb, r, (state, a), texel)?,
Some((state, a)) => through::finish(cx, fb, r, (state, a), texel, raw_member)?,
None => texel,
};
// A texture of another class: its own texel's words, out of bounds too, as declared.
@@ -2606,7 +2652,9 @@ fn read_texel(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BR
/// `texel`, the float array's: that element's raw texel fetched from the group's unsigned integer
/// class (`HeapPlan::raw`), its level and coordinate (a read through a sampler's addressed in it)
/// tested against that image and clamped into it, decoded by the form, Metal's out-of-bounds
/// texel outside it (`heap_raw::define`). With whether the handle names such a form (a `bool`).
/// texel outside it (`heap_raw::define`), and a read through a sampler's border texel and zero
/// past its level or layer as that image's addressing says (`through::finish`). With whether the
/// handle names such a form (a `bool`).
fn heap_raw_texel(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
@@ -2631,7 +2679,8 @@ fn heap_raw_texel(
return Err(cx.fail("a raw heap read without its routine"));
};
let h = cx.operand(fb, handle)?;
let (form, member) = heap_raw_form(fb, h)?;
let flags = heap_flags(cx, fb, h)?;
let (form, member) = heap_raw_form(fb, flags)?;
let raw_arm: ArmFn<'_, EmitCx<'_>> = Box::new(move |fb, cx| {
let img = heap_raw_image(cx, fb, group, h)?;
let level = match r.level {
@@ -2639,23 +2688,17 @@ fn heap_raw_texel(
None => None,
};
let n = coord_len(&decl);
let (coord, level, ok) = match r.through {
let (coord, level, ok, through) = match r.through {
// A read through a sampler, addressed in this image: its layer clamped into it,
// Metal's out-of-bounds texel outside it or on a border axis, the transparent black
// border texel there (`texture::select_through`).
// Metal's out-of-bounds texel outside it, and the border texel on a border axis
// (`through::finish`).
Some(t) => {
let state = through::state(cx, fb, t.sampler)?;
let a = through::address(cx, fb, (&decl, img), r, level, &state)?;
let lt = fb.binary(BinOp::ULessThan, a.coord, a.size)?;
let inside = if n == 1 { lt } else { fb.unary(UnOp::All, lt)? };
let ok = match a.border {
Some(out) => {
let kept = fb.unary(UnOp::LogicalNot, out)?;
fb.binary(BinOp::LogicalAnd, inside, kept)?
}
None => inside,
};
(clamp_below(fb, a.coord, a.size, n)?, a.level, Some(ok))
let coord = clamp_below(fb, a.coord, a.size, n)?;
(coord, a.level, Some(inside), Some((state, a)))
}
None => {
let c = coordinate(cx, fb, &decl, &r.at)?;
@@ -2672,7 +2715,7 @@ fn heap_raw_texel(
let lt = fb.binary(BinOp::ULessThan, c, size)?;
let inside = if n == 1 { lt } else { fb.unary(UnOp::All, lt)? };
let ok = and(fb, ok, inside)?;
(clamp_below(fb, c, size, n)?, level, Some(ok))
(clamp_below(fb, c, size, n)?, level, Some(ok), None)
}
};
let ops = ImageOperands {
@@ -2694,6 +2737,10 @@ fn heap_raw_texel(
let v = fb
.call(routine, &[texel, form, ok])?
.ok_or_else(|| cx.fail("the raw heap routine returned nothing"))?;
let v = match &through {
Some((state, a)) => through::finish(cx, fb, r, (state, a), v, None)?,
None => v,
};
Ok(ArmEnd::FallThrough(vec![v]))
});
let own_arm: ArmFn<'_, EmitCx<'_>> =
@@ -2705,10 +2752,13 @@ fn heap_raw_texel(
}
}
/// The form heap handle `h` (a `u32`) names by its class index past the heap's own classes
/// (`metal::texel_format::heap_extended_base`): its index in `ExtendedRange::HEAP_READ` (a `u32`,
/// wrapped past the forms where it names none), and whether it names one (a `bool`).
pub(crate) fn heap_raw_form(fb: &mut FunctionBuilder<'_>, h: SValue) -> BResult<(SValue, SValue)> {
/// The form heap handle flags `h` ([`heap_flags`]) name by their class index past the heap's own
/// classes (`metal::texel_format::heap_extended_base`): its index in `ExtendedRange::HEAP_READ` (a
/// `u32`, wrapped past the forms where it names none), and whether it names one (a `bool`).
pub(crate) fn heap_raw_form(
fb: &mut FunctionBuilder<'_>,
HeapFlags(h): HeapFlags,
) -> BResult<(SValue, SValue)> {
use crate::memory::handles::HANDLE_TEXEL_CLASS;
let shift = u32s(fb, 1, HANDLE_TEXEL_CLASS.trailing_zeros())?;
let mask = u32s(
@@ -2729,9 +2779,9 @@ pub(crate) fn heap_raw_form(fb: &mut FunctionBuilder<'_>, h: SValue) -> BResult<
Ok((form, member))
}
/// The index heap handle `h` (a `u32`) carries in its class field
/// The index heap handle flags `h` ([`heap_flags`]) carry in their class field
/// (`memory::handles::HANDLE_TEXEL_CLASS`).
fn heap_class_field(fb: &mut FunctionBuilder<'_>, h: SValue) -> BResult<SValue> {
fn heap_class_field(fb: &mut FunctionBuilder<'_>, HeapFlags(h): HeapFlags) -> BResult<SValue> {
use crate::memory::handles::HANDLE_TEXEL_CLASS;
let shift = u32s(fb, 1, HANDLE_TEXEL_CLASS.trailing_zeros())?;
let mask = u32s(
@@ -2797,7 +2847,8 @@ fn read_crossed(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) ->
return read(cx, fb, r);
}
let h = cx.operand(fb, handle)?;
let index = heap_class_field(fb, h)?;
let flags = heap_flags(cx, fb, h)?;
let index = heap_class_field(fb, flags)?;
if r.texel.conv != TexelConv::F16 {
return read_arms(cx, fb, index, (&r.heap_cross, r), ArmValue::Read);
}
@@ -3229,7 +3280,8 @@ fn query(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, q: &QueryOp) -> BRes
};
if raw.is_some() || !cross.is_empty() {
let h = cx.operand(fb, handle)?;
let index = heap_class_field(fb, h)?;
let flags = heap_flags(cx, fb, h)?;
let index = heap_class_field(fb, flags)?;
let global = |cx: &mut EmitCx<'_>, class| {
cx.decl
.families
@@ -3246,7 +3298,7 @@ fn query(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, q: &QueryOp) -> BRes
// A heap member of a form a heap reads is queried in the group's unsigned integer
// class, which holds it: one arm with the unsigned integer members' where both are.
if let Some((class, _)) = raw {
let (_, member) = heap_raw_form(fb, h)?;
let (_, member) = heap_raw_form(fb, flags)?;
let g = global(cx, class)?;
match arms.iter_mut().find(|(_, at)| *at == g) {
Some(arm) => arm.0 = fb.binary(BinOp::LogicalOr, arm.0, member)?,
@@ -271,25 +271,40 @@ pub(super) fn address(
}
/// `texel`, read `r`'s texel in its result form, with what the read hands back in place of it
/// ([`Addressed`]): a slot's border texel where the plane coordinate is outside on a border axis
/// (a heap element's selects the out-of-bounds texel instead, before converting it), and zero in
/// every lane where its level or layer is not the image's.
/// ([`Addressed`]): the texture's border texel where the plane coordinate is outside on a border
/// axis, and zero in every lane where its level or layer is not the image's; but `texel` itself
/// where `held` holds (a `bool`: a heap member's raw texel, which its own image's addressing
/// already gave them).
pub(super) fn finish(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
r: &Read,
(s, a): (&State, &Addressed),
texel: SValue,
held: Option<SValue>,
) -> BResult<SValue> {
let texel = match (a.border, r.image) {
(Some(out), ImageRef::Slot(index)) => {
let border = border_texel(cx, fb, index, s, texel)?;
let unheld = match held {
Some(h) => Some(fb.unary(UnOp::LogicalNot, h)?),
None => None,
};
let texel = match a.border {
Some(out) => {
let out = match unheld {
Some(u) => fb.binary(BinOp::LogicalAnd, out, u)?,
None => out,
};
let bits = border_bits(cx, fb, r.image)?;
let border = border_texel(cx, fb, bits, s, texel)?;
fb.select(out, border, texel)?
}
_ => texel,
None => texel,
};
match a.inside {
Some(inside) => {
let inside = match held {
Some(h) => fb.binary(BinOp::LogicalOr, inside, h)?,
None => inside,
};
let ty = fb.value_ty(texel)?;
let zero = fb.module().constant(Constant::Null { ty })?;
let zero = fb.module().const_value(zero)?;
@@ -299,21 +314,41 @@ pub(super) fn finish(
}
}
/// Metal's border texel of texture slot `index` for the color of `s`, in the form of `like` (a
/// `float`, `half` or 32-bit integer scalar or vector of up to four lanes): lane `c` is 1 where bit
/// `3c + color` of the slot's `BorderTexels` specialization is set, else 0.
/// The border texels of `image` (a `u32`, bit `3c + b` set where channel `c` of Metal's border
/// texel for border color `b` reads 1): a slot's `BorderTexels` specialization, or a heap
/// element's handle-table entry's (`memory::handles::FLAG_BORDER_TEXELS`), which the entry index
/// its handle carries names.
fn border_bits(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
image: ImageRef,
) -> BResult<SValue> {
match image {
ImageRef::Slot(index) => {
let bits = cx.decl.families.texture.border_texels.get(&index).copied();
bits.ok_or_else(|| {
cx.fail(format!(
"texture slot {index} has no border texels constant"
))
})
}
ImageRef::Heap { handle, .. } => {
let h = cx.operand(fb, handle)?;
super::heap_border_texels(cx, fb, h)
}
}
}
/// Metal's border texel of border texels `bits` ([`border_bits`]) for the color of `s`, in the
/// form of `like` (a `float`, `half` or 32-bit integer scalar or vector of up to four lanes): lane
/// `c` is 1 where bit `3c + color` of `bits` is set, else 0.
fn border_texel(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
index: u32,
bits: SValue,
s: &State,
like: SValue,
) -> BResult<SValue> {
let Some(bits) = cx.decl.families.texture.border_texels.get(&index).copied() else {
return Err(cx.fail(format!(
"texture slot {index} has no border texels constant"
)));
};
let ty = fb.value_ty(like)?;
let (elem, lanes) = match fb.module().types().get(ty)? {
SType::Vector { elem, len } => (*elem, *len),
+35 -35
View File
@@ -86,13 +86,14 @@
//! - The filters, coordinates, comparison, anisotropy, reduction and LOD clamp change nothing.
//!
//! So the level, plane coordinate and layer are addressed before the access, and only a sample
//! index can be out of bounds as a plain read's, contained as above. A heap element's handle
//! states whether its format has alpha, which gives the transparent black border texel (the
//! out-of-bounds texel) alone, and not through the element's swizzle (`docs/FAST-PATHS.md`'s
//! known gaps): a heap element read through a sampler that may read another border color is not
//! implemented, nor is a `ulong` texel's border. A cube's read through a sampler
//! (unclamped on the M3), a sparse one's (its residency unmeasured) and a `read_write` texture's
//! at a computed level (Metal 4.1 has no such overload) are refused.
//! index can be out of bounds as a plain read's, contained as above. A heap element's border
//! texels are its handle-table entry's (`memory::handles::FLAG_BORDER_TEXELS`, the binder's
//! `border_texels` of the resident texture's format and swizzle), which the read loads from the
//! entry its handle names (`memory::handles::Lookup::Indexed`), for a constexpr sampler's color
//! or a runtime or argument-buffer sampler's word's alike. A `ulong` texel's border is not
//! implemented. A cube's read through a sampler (unclamped on the M3), a sparse one's (its
//! residency unmeasured) and a `read_write` texture's at a computed level (Metal 4.1 has no such
//! overload) are refused.
//!
//! **Storage levels**. A storage access reaches its view's base level only
//! (`OpImageRead`/`OpImageWrite` take no `Lod`). A storage slot that is read or written at a level
@@ -162,11 +163,11 @@ pub(crate) use absent::absent_arm;
pub use absent::ABSENT_ARM;
pub use atomic::TexAtomic;
pub(crate) use emit::{
constant_lanes, dispatch, half_class, heap_element, heap_half_class, heap_raw_form,
constant_lanes, dispatch, half_class, heap_element, heap_flags, heap_half_class, heap_raw_form,
heap_raw_image, live_or_zero, reinterpret, resident_access, rgb9e5_word, slot_image,
sparse_spec, srgb_raw_tap, srgb_texel, swizzled_float, swizzled_gather, swizzled_held,
tile_map, tiled_word, with_word, NullLeaf, TileLevel, RGB9E5_WORDS, SRGB_DECODE_WORDS,
SRGB_TAP_WORDS, SRGB_TEXEL,
tile_map, tiled_word, with_word, HeapFlags, NullLeaf, TileLevel, RGB9E5_WORDS,
SRGB_DECODE_WORDS, SRGB_TAP_WORDS, SRGB_TEXEL,
};
pub use emit::{emit, held_texel, to_image};
pub(crate) use slot::depth_comparison;
@@ -377,10 +378,12 @@ pub struct Read {
/// specialized alpha); the level views' count, index clamp, level test, and select; a heap
/// element's access chain, load, and null select or guard; the sparse arm ([`RESIDENCY_WORDS`]) and
/// the word's select outside the image, with its own in-bounds test where the shader has none; a
/// read through a sampler's addressing ([`Through::words`]); a `half` texel's call of the
/// conversion routine or exact rounding, or an sRGB texel's raw decode; the lanes Metal reads as
/// constants; the reinterpretation of another class's words; and each sibling of a heap read with
/// its class test and branch, and a `half` read's merge of its arms' bits.
/// read through a sampler's addressing ([`Through::words`]), and a heap element's border texels
/// and the flags its uses then read from its handle-table entry
/// (`memory::handles::INDEXED_FLAGS_WORDS`); a `half` texel's call of the conversion routine or
/// exact rounding, or an sRGB texel's raw decode; the lanes Metal reads as constants; the
/// reinterpretation of another class's words; and each sibling of a heap read with its class test
/// and branch, and a `half` read's merge of its arms' bits.
fn read_words(r: &Read) -> u32 {
let own = 64
+ if r.checked() { 80 } else { 0 }
@@ -405,6 +408,12 @@ fn read_words(r: &Read) -> u32 {
}
+ r.heap_conversions.words(true)
+ r.through.map_or(0, Through::words)
+ match r.through {
Some(t) if r.image.heap() && t.sampler.bordered() => {
2 * crate::memory::handles::INDEXED_FLAGS_WORDS
}
_ => 0,
}
+ if r.raw || r.srgb_codes {
SRGB_DECODE_WORDS
} else if r.extended.is_some() {
@@ -484,12 +493,6 @@ impl ReadSampler {
ReadSampler::Slot(_) | ReadSampler::Heap(_) => true,
}
}
/// Whether the border texel it may read is the transparent black one, whatever the bound
/// format: the out-of-bounds texel, which a heap element's handle states.
fn transparent(self) -> bool {
matches!(self, ReadSampler::Constant { color, .. } if color == crate::metal::SamplerBorderColor::TransparentBlack.as_raw())
}
}
impl Read {
@@ -1445,14 +1448,14 @@ pub(crate) fn heap_classes_words() -> u64 {
}
/// The texel class (`metal::texel_format::TexelFormat`'s bits, a `u32`) of the heap texture
/// whose handle is `h`, a handle of a module whose search carries the class's index
/// ([`HANDLE_TEXEL_CLASS`](crate::memory::handles::HANDLE_TEXEL_CLASS)): the module's table's
/// element at that index, clamped into the table. A null handle's, or a missed id's, is index 0,
/// `TexelFormat::OTHER`.
/// whose handle's flags are `h` ([`heap_flags`]), of a module whose search carries the class's
/// index ([`HANDLE_TEXEL_CLASS`](crate::memory::handles::HANDLE_TEXEL_CLASS)): the module's
/// table's element at that index, clamped into the table. A null handle's, or a missed id's, is
/// index 0, `TexelFormat::OTHER`.
pub(crate) fn heap_texel_class(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
h: SValue,
HeapFlags(h): HeapFlags,
) -> BResult<SValue> {
use crate::memory::handles::HANDLE_TEXEL_CLASS;
let Some(table) = cx.decl.families.texture.heap_classes else {
@@ -3215,10 +3218,7 @@ fn select_read_as(
// A `ulong` read's lanes past the first are Metal's constants `(0, 0, 1)` in and out of
// bounds, never the image's. A swizzled read may return the alpha in any lane, so it observes
// the alpha wherever the function reads a lane.
// A heap element read through a sampler selects that texel as its transparent black border
// texel too (`select_through`).
let bordered_heap = image.heap() && through.is_some_and(|t| t.sampler.bordered());
let observed = (check == ReadCheck::Shader || level_views || residency || bordered_heap)
let observed = (check == ReadCheck::Shader || level_views || residency)
&& texel.lanes == 4
&& !matches!(texel.conv, TexelConv::U64Words { .. })
&& (swizzle || storage_swizzle || alpha_read(cx, at));
@@ -3434,10 +3434,10 @@ fn constant_read_sampler(state: &crate::air::abi::SamplerState) -> ReadSampler {
/// Plan what read through a sampler `t` of `image` reads besides the image: a runtime slot's
/// word (`RuntimeSlot::reads`), and where an index outside the level may read the border texel, a
/// slot's `BorderTexels` specialization (`RuntimeFact::BorderTexels`). A heap element's handle
/// states only whether its format has alpha, which gives the transparent black border texel
/// alone, so a read of one that may read another border color is not implemented; nor is a
/// `ulong` texel's border, which is not measured.
/// slot's `BorderTexels` specialization (`RuntimeFact::BorderTexels`), or a heap element's
/// handle-table entry's (`memory::handles::FLAG_BORDER_TEXELS`), which the module's search then
/// names by its index in the handle (`AccessPlan::heap_border`). A `ulong` texel's border, which
/// is not measured, is not implemented.
fn select_through(
cx: &mut SelectCx<'_>,
image: ImageRef,
@@ -3467,9 +3467,9 @@ fn select_through(
.insert(crate::pipeline::facts::RuntimeFact::BorderTexels { slot });
Ok(())
}
ImageRef::Heap { .. } if t.sampler.transparent() => Ok(()),
ImageRef::Heap { .. } => {
Err(Unsupported::not_implemented(Feature::ArgumentBufferTextures).into())
cx.families.access.heap_border = true;
Ok(())
}
}
}
+287 -40
View File
@@ -48,6 +48,16 @@
//! read selects its out-of-bounds alpha by. An element is below [`TABLE_CAPACITY`], so the bit is
//! never an element's.
//!
//! **Border texels**. A texture entry's flags also hold Metal's border texels of the resident
//! texture, its pixel format's and swizzle's ([`FLAG_BORDER_TEXELS`]), which a Metal 4.1 read
//! through a sampler hands back at an index outside the level on a border axis. A module with such
//! a read of a heap texture calls the search's indexed form ([`Lookup::Indexed`]): the handle is
//! the element with the found entry's index in its top 16 bits ([`HANDLE_ENTRY`]), by which the
//! read loads the entry's border texels ([`border_texels`]), and each use that reads another of
//! the entry's flags loads them there too ([`flagged_handle`]): the handle has no room for the
//! border texels beside the flags the flagged form carries. An entry's index is below
//! [`TABLE_CAPACITY`] as an element is, so the two never overlap.
//!
//! **Heap samplers** (the sampler half). A sampler handle loaded from an argument buffer is the
//! guest's resource id of an `MTLSamplerState`, searched in the stage's **sampler table**
//! (`Synthetic(SamplerTable)`), the handle table's layout over the argument buffers' samplers: a
@@ -382,8 +392,9 @@ pub const ENTRY_ID_HI: u32 = 1;
pub const ENTRY_ELEMENT: u32 = 2;
/// Word of an entry holding the flags: for a sampler, its
/// [`SamplerWord`](crate::metal::sampler::SamplerWord); for a texture,
/// [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`], [`FLAG_RED_BLUE`], and the index of its texel class in
/// [`FLAG_TEXEL_CLASS`], every other bit 0.
/// [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`], [`FLAG_RED_BLUE`], its border texels in
/// [`FLAG_BORDER_TEXELS`], and the index of its texel class in [`FLAG_TEXEL_CLASS`], every other
/// bit 0.
pub const ENTRY_FLAGS: u32 = 3;
/// The flag of a texture entry whose pixel format has no alpha
/// (`metal::format::out_of_bounds_alpha_one`): Metal's out-of-bounds read of such a texture
@@ -415,13 +426,30 @@ pub const HANDLE_ALPHA_ONE: u32 = 1 << 31;
/// The bit of a heap handle that carries its entry's [`FLAG_RED_BLUE`], in a module whose search
/// carries the texel class ([`Lookup::Flagged`]'s `class`).
pub const HANDLE_RED_BLUE: u32 = 1 << 30;
/// The field of a texture entry's flags holding Metal's border texels of its texture
/// (`metal::sampler::border_texels` of its pixel format and swizzle, the layout of a slot's
/// `BorderTexels` specialization moved up by the field's first bit): bit `3c + b` of the field is
/// set where channel `c` (red 0 to alpha 3) of the border texel for border color `b`
/// (`MTLSamplerBorderColor`'s value) reads 1. A Metal 4.1 read through a sampler of an argument
/// buffer's texture hands it back at an index outside the level on a border axis, from the entry
/// its handle names ([`Lookup::Indexed`], [`border_texels`]).
pub const FLAG_BORDER_TEXELS: u32 = 0xfff << 3;
/// The field of a heap handle holding the index of the handle-table entry its search found, in a
/// module whose search yields it beside the element ([`Lookup::Indexed`]).
pub const HANDLE_ENTRY: u32 = 0xffff << 16;
// Every element is below the table's capacity, so no carried bit is an element's, and the
// carried fields do not overlap.
// carried fields do not overlap; an entry's index is below the capacity too, so it fits its field,
// above every element's bits.
const _: () = assert!(TABLE_CAPACITY <= 1 << HANDLE_TEXEL_CLASS.trailing_zeros());
const _: () = assert!(HANDLE_TEXEL_CLASS & HANDLE_ALPHA_ONE == 0);
const _: () = assert!((HANDLE_TEXEL_CLASS | HANDLE_ALPHA_ONE) & HANDLE_RED_BLUE == 0);
const _: () = assert!(FLAG_TEXEL_CLASS & FLAG_OUT_OF_BOUNDS_ALPHA_ONE == 0);
const _: () = assert!((FLAG_TEXEL_CLASS | FLAG_OUT_OF_BOUNDS_ALPHA_ONE) & FLAG_RED_BLUE == 0);
const _: () = assert!(
(FLAG_TEXEL_CLASS | FLAG_OUT_OF_BOUNDS_ALPHA_ONE | FLAG_RED_BLUE) & FLAG_BORDER_TEXELS == 0
);
const _: () = assert!(TABLE_CAPACITY <= 1 << HANDLE_ENTRY.trailing_zeros());
const _: () = assert!(TABLE_CAPACITY <= 1 << HANDLE_ENTRY.count_ones());
/// Unrolled steps of the handle-table search.
pub const SEARCH_STEPS: u32 = 16;
@@ -1323,20 +1351,38 @@ pub enum Lookup {
class: bool,
red_blue: bool,
},
/// The entry's element with the entry's index beside it, in [`HANDLE_ENTRY`] (0 for a miss,
/// the null entry's): the handle of a module whose read through a sampler of a heap texture
/// may hand back its border texels, which its entry holds ([`FLAG_BORDER_TEXELS`],
/// [`border_texels`]). The handle has no room for them beside the flags `Flagged` carries, so
/// it carries none: a use reads the ones its module reads (`alpha`, `class` and `red_blue`
/// as `Flagged`'s) from the entry, in the handle `Flagged` would have yielded
/// ([`flagged_handle`]). Every heap access masks the index off ([`Lookup::element_mask`]).
Indexed {
alpha: bool,
class: bool,
red_blue: bool,
},
/// The index of the entry found, 0 (the null entry) for a miss: the handle of an argument
/// buffer's sampler, whose uses read the entry's element and word ([`entry_field`]).
Entry,
}
impl Lookup {
/// The entry flags this form carries into the handle, each with the left shift that moves it
/// there.
/// The entry flags this form's uses read in the handle, each with the left shift that moves it
/// there: the ones `Flagged`'s search carries into it, and those `Indexed`'s uses read from
/// the entry ([`flagged_handle`]).
fn carried(self) -> Vec<(u32, u32)> {
let Lookup::Flagged {
let (Lookup::Flagged {
alpha,
class,
red_blue,
} = self
}
| Lookup::Indexed {
alpha,
class,
red_blue,
}) = self
else {
return Vec::new();
};
@@ -1352,10 +1398,14 @@ impl Lookup {
alpha.into_iter().chain(class).chain(red_blue).collect()
}
/// The bits of a handle this form yields that are its element, where it carries flags beside
/// it: every bit but the carried ones. An element is below [`TABLE_CAPACITY`], so no carried
/// bit is ever an element's.
/// The bits of a handle this form yields that are its element, where it carries anything
/// beside it: every bit but the carried flags (`Flagged`), or but the entry's index
/// (`Indexed`). An element is below [`TABLE_CAPACITY`], so no carried bit is ever an
/// element's.
pub fn element_mask(self) -> Option<u32> {
if let Lookup::Indexed { .. } = self {
return Some(!HANDLE_ENTRY);
}
let carried = self
.carried()
.into_iter()
@@ -1364,6 +1414,68 @@ impl Lookup {
}
}
/// `word` with each of `form`'s carried fields of the entry flags `flags` (both `u32`) moved into
/// its handle bits ([`Lookup::carried`]).
fn carry(
fb: &mut FunctionBuilder<'_>,
word: SValue,
flags: SValue,
form: Lookup,
) -> BResult<SValue> {
let mut word = word;
for (carried_flags, shift) in form.carried() {
let mask = k32(fb, carried_flags)?;
let carried = fb.binary(BinOp::BitwiseAnd, flags, mask)?;
let shift = k32(fb, shift)?;
let carried = fb.binary(BinOp::ShiftLeftLogical, carried, shift)?;
word = fb.binary(BinOp::BitwiseOr, word, carried)?;
}
Ok(word)
}
/// The index of the entry an [`Lookup::Indexed`] handle `h` (a `u32`) names: its
/// [`HANDLE_ENTRY`], 0 (the null entry) for a null handle or a missed id.
fn indexed_entry(fb: &mut FunctionBuilder<'_>, h: SValue) -> BResult<SValue> {
let shift = k32(fb, HANDLE_ENTRY.trailing_zeros())?;
fb.binary(BinOp::ShiftRightLogical, h, shift)
}
/// The handle a [`Lookup::Flagged`] search of `form`'s fields would have yielded for the
/// [`Lookup::Indexed`] handle `h` (a `u32`) of the handle table `t`: its element, with the flags
/// `form`'s uses read of the entry its [`HANDLE_ENTRY`] names moved where `Flagged` carries them
/// (the null entry's, all clear, for a null handle).
pub fn flagged_handle(
fb: &mut FunctionBuilder<'_>,
t: Table,
h: SValue,
form: Lookup,
) -> BResult<SValue> {
let k = indexed_entry(fb, h)?;
let mask = k32(fb, !HANDLE_ENTRY)?;
let element = fb.binary(BinOp::BitwiseAnd, h, mask)?;
let flags = entry_field(fb, t, k, EntryField::Flags)?;
carry(fb, element, flags, form)
}
/// The border texels of the texture of the [`Lookup::Indexed`] handle `h` (a `u32`) of the
/// handle table `t`: its entry's [`FLAG_BORDER_TEXELS`], moved down to bit 0 (the layout of a
/// slot's `BorderTexels` specialization); 0 for a null handle (the null entry's).
pub fn border_texels(fb: &mut FunctionBuilder<'_>, t: Table, h: SValue) -> BResult<SValue> {
let k = indexed_entry(fb, h)?;
let flags = entry_field(fb, t, k, EntryField::Flags)?;
let shift = k32(fb, FLAG_BORDER_TEXELS.trailing_zeros())?;
let bits = fb.binary(BinOp::ShiftRightLogical, flags, shift)?;
let mask = k32(
fb,
FLAG_BORDER_TEXELS >> FLAG_BORDER_TEXELS.trailing_zeros(),
)?;
fb.binary(BinOp::BitwiseAnd, bits, mask)
}
/// An upper estimate of [`flagged_handle`]'s or [`border_texels`]'s words: the entry's index, its
/// flags word ([`ENTRY_FIELD_WORDS`]), and the fields' moves with their constants.
pub const INDEXED_FLAGS_WORDS: u32 = ENTRY_FIELD_WORDS + 64;
/// A field of a handle-table entry that a use reads by the entry's index.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EntryField {
@@ -1425,9 +1537,9 @@ pub fn last_entry(fb: &mut FunctionBuilder<'_>, t: Table) -> BResult<SValue> {
/// [`NEUTRAL_ELEMENT`]. Entry 0 is the null entry (id 0), so the search always finds an entry,
/// and every entry it reads is below the table's length (`OpArrayLength`). An entry array
/// compares each id as one `u64`; a word view compares its two words. [`Lookup::Flagged`] also
/// moves the found entry's flags it carries into their handle bits (a miss is
/// [`NEUTRAL_ELEMENT`] without them), and [`Lookup::Entry`] yields the found entry's index in
/// place of its element, 0 for a miss.
/// moves the found entry's flags it carries into their handle bits, [`Lookup::Indexed`] the found
/// entry's index into [`HANDLE_ENTRY`] (a miss is [`NEUTRAL_ELEMENT`] without either), and
/// [`Lookup::Entry`] yields the found entry's index in place of its element, 0 for a miss.
pub fn lookup(
fb: &mut FunctionBuilder<'_>,
t: Table,
@@ -1497,20 +1609,22 @@ pub fn lookup(
// The null entry, index 0, for a miss.
return fb.select(hit, base, zero);
}
let mut element = entry_field(fb, t, base, EntryField::Element)?;
let carried = form.carried();
if !carried.is_empty() {
let flags = entry_field(fb, t, base, EntryField::Flags)?;
for (carried_flags, shift) in carried {
let mask = k32(fb, carried_flags)?;
let carried = fb.binary(BinOp::BitwiseAnd, flags, mask)?;
let shift = k32(fb, shift)?;
let carried = fb.binary(BinOp::ShiftLeftLogical, carried, shift)?;
element = fb.binary(BinOp::BitwiseOr, element, carried)?;
let element = entry_field(fb, t, base, EntryField::Element)?;
let handle = match form {
// The entry's index beside the element.
Lookup::Indexed { .. } => {
let shift = k32(fb, HANDLE_ENTRY.trailing_zeros())?;
let entry = fb.binary(BinOp::ShiftLeftLogical, base, shift)?;
fb.binary(BinOp::BitwiseOr, element, entry)?
}
}
_ if form.carried().is_empty() => element,
_ => {
let flags = entry_field(fb, t, base, EntryField::Flags)?;
carry(fb, element, flags, form)?
}
};
let neutral = k32(fb, NEUTRAL_ELEMENT)?;
fb.select(hit, element, neutral)
fb.select(hit, handle, neutral)
}
/// An upper estimate of [`define_lookup`]'s words, counted once per module: per search step, over
@@ -1518,10 +1632,14 @@ pub fn lookup(
/// a word view, two word reads (about 20 words each) and a five-instruction compare; then the
/// entry's id and element, and the function's own instructions and types. The flagged form also
/// reads the entry's flags (a word read) and moves each carried field (three instructions and two
/// constants); the entry form reads no element.
/// constants); the indexed form moves the entry's index (two instructions and a constant); the
/// entry form reads no element.
pub fn lookup_routine_words(int64: bool, form: Lookup) -> u32 {
let step = if int64 { 48 } else { 96 };
let carried = 48 * form.carried().len() as u32;
let carried = match form {
Lookup::Indexed { .. } => 16,
_ => 48 * form.carried().len() as u32,
};
SEARCH_STEPS * step + 160 + carried
}
@@ -1747,6 +1865,16 @@ mod tests {
/// `form`, and writes each element after them. The table is an entry array when `int64`, else
/// a word view.
fn lookup_module(int64: bool, form: Lookup) -> BResult<crate::spirv::ir::TypedModule> {
search_module(int64, form, |_, _, h| Ok(vec![h]))
}
/// [`lookup_module`] writing the words `per_key` makes of each key's handle (`per_key` of the
/// function, the table and the handle), each key's words after the keys in turn.
fn search_module(
int64: bool,
form: Lookup,
per_key: impl Fn(&mut FunctionBuilder<'_>, Table, SValue) -> BResult<Vec<SValue>>,
) -> BResult<crate::spirv::ir::TypedModule> {
use crate::pipeline::sym::{ResourceKind, ResourceSlot, Stage};
use crate::spirv::builder::ModuleBuilder;
use crate::spirv::ir::{ExecMode, ExecModel, MemAccess, Type};
@@ -1761,6 +1889,7 @@ mod tests {
let search = define_lookup(&mut b, t, form)?;
let void = b.ty(Type::Void)?;
let mut f = b.function(void)?;
let mut at = 2 * KEYS;
for i in 0..KEYS {
let at_lo = k32(&mut f, 2 * i)?;
let at_hi = k32(&mut f, 2 * i + 1)?;
@@ -1769,9 +1898,12 @@ mod tests {
let e = f
.call(search, &[lo, hi])?
.expect("the search returns the element");
let at = k32(&mut f, 2 * KEYS + i)?;
let p = views::word_ptr(&mut f, io, at)?.expect("a storage view is writable");
f.store(p, e, MemAccess::default())?;
for word in per_key(&mut f, t, e)? {
let to = k32(&mut f, at)?;
let p = views::word_ptr(&mut f, io, to)?.expect("a storage view is writable");
f.store(p, word, MemAccess::default())?;
at += 1;
}
}
f.ret(None)?;
let id = f.finish()?;
@@ -1789,7 +1921,8 @@ mod tests {
/// word view. [`Lookup::Flagged`] also carries a found entry's [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`]
/// in [`HANDLE_ALPHA_ONE`] where it carries the alpha, its texel class where it carries that,
/// and its [`FLAG_RED_BLUE`] in [`HANDLE_RED_BLUE`] where it carries that, carrying no other
/// bit of the entry, and [`Lookup::Entry`] yields the index
/// bit of the entry; [`Lookup::Indexed`] carries the found entry's index in [`HANDLE_ENTRY`]
/// beside the element, whatever flags its uses read; and [`Lookup::Entry`] yields the index
/// of the last entry of the key's id, 0 for a miss.
#[test]
fn the_emitted_search_matches_the_host_model() {
@@ -1806,6 +1939,11 @@ mod tests {
flagged(false, false, true),
flagged(true, true, false),
flagged(true, true, true),
Lookup::Indexed {
alpha: true,
class: true,
red_blue: false,
},
Lookup::Entry,
] {
emitted_search_matches_the_host_model(int64, form);
@@ -1836,6 +1974,18 @@ mod tests {
Some(!(HANDLE_ALPHA_ONE | HANDLE_TEXEL_CLASS | HANDLE_RED_BLUE)),
"every carried field is masked off, and the element's 16 bits stay"
);
for (alpha, class, red_blue) in [(false, false, false), (true, true, true)] {
let indexed = Lookup::Indexed {
alpha,
class,
red_blue,
};
assert_eq!(
indexed.element_mask(),
Some(0xffff),
"an indexed handle's entry is masked off, whatever flags its uses read"
);
}
}
/// The flags of the test tables' entry of `element`: none on the null entry, else its low six
@@ -1845,7 +1995,107 @@ mod tests {
if element == NEUTRAL_ELEMENT {
return 0;
}
(element % 64) | ((element.wrapping_mul(2_654_435_761) >> 7) & FLAG_TEXEL_CLASS)
(element % 64)
| ((element.wrapping_mul(2_654_435_761) >> 7) & FLAG_TEXEL_CLASS)
| ((element.wrapping_mul(40_503) << 3) & FLAG_BORDER_TEXELS)
}
/// The bytes of table `t`, each entry's flags [`flags`] of its element.
fn table_bytes(t: &[(u64, u32)]) -> Vec<u8> {
t.iter()
.flat_map(|(id, e)| {
[*id as u32, (*id >> 32) as u32, *e, flags(*e)]
.into_iter()
.flat_map(u32::to_le_bytes)
})
.collect()
}
/// An indexed handle's uses read its entry's flags: over the CPU interpreter, every key of a
/// table gets, from [`flagged_handle`], the handle the flagged search of the same fields yields
/// (its element and the fields carried, nothing else), and from [`border_texels`] its entry's
/// [`FLAG_BORDER_TEXELS`] moved down to bit 0; a missed or null id the null entry's, all 0.
#[test]
fn an_indexed_handle_reads_its_entry_s_flags() {
use crate::pipeline::sym::{ResourceKind, ResourceSlot, Stage};
use crate::spirv::interp::{run, Buffer, Config, Resources};
let sym = |index| ResourceSlot {
stage: Stage::Kernel,
kind: ResourceKind::Buffer,
index,
};
for int64 in [true, false] {
for (alpha, class, red_blue) in [(true, true, true), (false, true, false)] {
let indexed = Lookup::Indexed {
alpha,
class,
red_blue,
};
let flagged = Lookup::Flagged {
alpha,
class,
red_blue,
};
let m = search_module(int64, indexed, |fb, t, h| {
Ok(vec![
flagged_handle(fb, t, h, indexed)?,
border_texels(fb, t, h)?,
])
})
.expect("module");
let t = table(17);
let bytes = table_bytes(&t);
for chunk in keys(&t).chunks(KEYS as usize) {
let mut io: Vec<u8> = Vec::new();
for i in 0..KEYS as usize {
let id = chunk.get(i).copied().unwrap_or(0);
io.extend((id as u32).to_le_bytes());
io.extend(((id >> 32) as u32).to_le_bytes());
}
io.extend(vec![0xAA; 8 * KEYS as usize]);
let res = Resources {
buffers: vec![
Buffer {
slot: Some(sym(0)),
address: None,
bytes: bytes.clone(),
},
Buffer {
slot: Some(sym(1)),
address: None,
bytes: io,
},
],
push: Vec::new(),
spec: Default::default(),
};
let out = run(&m, &Config::default(), res).expect("run");
let io = &out.buffers[1];
let word = |w: usize| {
let at = 4 * (2 * KEYS as usize + w);
u32::from_le_bytes(io[at..at + 4].try_into().expect("word"))
};
for (i, id) in chunk.iter().enumerate() {
let e = lookup_host(&t, *id);
let carried = |on: bool, flag: u32, bit: u32| match on {
true if flags(e) & flag != 0 => bit,
_ => 0,
};
let want = e
| carried(alpha, FLAG_OUT_OF_BOUNDS_ALPHA_ONE, HANDLE_ALPHA_ONE)
| carried(red_blue, FLAG_RED_BLUE, HANDLE_RED_BLUE)
| match class {
true => flags(e) & FLAG_TEXEL_CLASS,
false => 0,
};
assert_eq!(flagged.element_mask().map(|m| want & m), Some(e));
assert_eq!(word(2 * i), want, "int64 {int64} {indexed:?} id {id:#x}");
let border = (flags(e) & FLAG_BORDER_TEXELS) >> 3;
assert_eq!(word(2 * i + 1), border, "int64 {int64} id {id:#x}");
}
}
}
}
}
fn emitted_search_matches_the_host_model(int64: bool, form: Lookup) {
@@ -1859,14 +2109,7 @@ mod tests {
};
for n in [1, 2, 3, 5, 17, 100, TABLE_CAPACITY as usize] {
let t = table(n);
let bytes: Vec<u8> = t
.iter()
.flat_map(|(id, e)| {
[*id as u32, (*id >> 32) as u32, *e, flags(*e)]
.into_iter()
.flat_map(u32::to_le_bytes)
})
.collect();
let bytes = table_bytes(&t);
assert_eq!(bytes.len(), n * TABLE_ENTRY_BYTES as usize);
let all = keys(&t);
// The interesting keys of the large table: its ends, its middle, and absent ones.
@@ -1925,6 +2168,10 @@ mod tests {
false => 0,
}
}
Lookup::Indexed { .. } => match t.iter().rposition(|(k, _)| k == id) {
Some(i) => e | (i as u32) << HANDLE_ENTRY.trailing_zeros(),
None => NEUTRAL_ELEMENT,
},
Lookup::Entry => {
t.iter().rposition(|(k, _)| k == id).map_or(0, |i| i as u32)
}
@@ -51,8 +51,9 @@ use crate::device::{Device, DeviceDescription, DevicePolicy};
use crate::error::{BindError, Capability, Feature, Needs, Unsupported};
use crate::library::{FunctionArtifact, Library};
use crate::memory::handles::{
declare_table, define_lookup, lookup_host, Lookup, FLAG_OUT_OF_BOUNDS_ALPHA_ONE, FLAG_RED_BLUE,
FLAG_TEXEL_CLASS, HANDLE_ALPHA_ONE, TABLE_ENTRY_BYTES,
declare_table, define_lookup, lookup_host, Lookup, FLAG_BORDER_TEXELS,
FLAG_OUT_OF_BOUNDS_ALPHA_ONE, FLAG_RED_BLUE, FLAG_TEXEL_CLASS, HANDLE_ALPHA_ONE, HANDLE_ENTRY,
TABLE_ENTRY_BYTES,
};
use crate::memory::leaf::k32;
use crate::memory::views;
@@ -247,8 +248,8 @@ fn table(bytes: &[DescriptorBytes], set: u32, binding: u32) -> Vec<(u64, u32)> {
}
/// The entries `(id, element, flags)` of the table bytes at `(set, binding)`: a texture entry's
/// flags hold its out-of-bounds-alpha flag, its red-blue order and its texel class's index alone,
/// and the null entry's none.
/// flags hold its out-of-bounds-alpha flag, its red-blue order, its border texels and its texel
/// class's index alone, and the null entry's none.
fn entries(bytes: &[DescriptorBytes], set: u32, binding: u32) -> Vec<(u64, u32, u32)> {
let b = &bytes
.iter()
@@ -260,11 +261,11 @@ fn entries(bytes: &[DescriptorBytes], set: u32, binding: u32) -> Vec<(u64, u32,
.map(|e| {
let w = |i: usize| u32::from_le_bytes(e[4 * i..4 * i + 4].try_into().expect("word"));
let id = u64::from(w(0)) | (u64::from(w(1)) << 32);
assert_eq!(
w(3) & !(FLAG_OUT_OF_BOUNDS_ALPHA_ONE | FLAG_RED_BLUE | FLAG_TEXEL_CLASS),
0,
"other flags are reserved"
);
let fields = FLAG_OUT_OF_BOUNDS_ALPHA_ONE
| FLAG_RED_BLUE
| FLAG_BORDER_TEXELS
| FLAG_TEXEL_CLASS;
assert_eq!(w(3) & !fields, 0, "other flags are reserved");
if id == 0 {
assert_eq!(w(3), 0, "the null entry has no flags");
}
@@ -571,13 +572,13 @@ fn a_sampled_heap_writes_each_member_and_its_table() {
.bytes;
assert_eq!(emitted_lookup(bytes, &keys), want.to_vec());
// Each entry's flags are its member's out-of-bounds alpha: token 2's `R32Uint` has no alpha,
// every other member's format has one, and the null entries have none (beside its texel class,
// which `table_entries_state_each_members_texel_class` reads).
// every other member's format has one, and the null entries have none (beside its texel class
// and border texels, which `table_entries_state_each_members_texel_class` reads).
let flag = FLAG_OUT_OF_BOUNDS_ALPHA_ONE;
let listed = entries(&cmds.descriptor_bytes, set, binding);
let flags: Vec<u32> = listed
.iter()
.map(|e| e.2 & !(FLAG_TEXEL_CLASS | FLAG_RED_BLUE))
.map(|e| e.2 & !(FLAG_TEXEL_CLASS | FLAG_RED_BLUE | FLAG_BORDER_TEXELS))
.collect();
assert_eq!(flags, vec![0, 0, 0, 0, 0, 0, flag, 0, 0]);
// And its red-blue order: `[[texture(3)]]`'s `BGRA8Unorm` (element 8) is blue-first, every
@@ -1058,9 +1059,11 @@ fn a_compared_depth_member_is_held_by_the_depth_comparison_class() {
}
/// Each member's table entry states its texel class's index (`heap_class_index`, in
/// [`FLAG_TEXEL_CLASS`]) beside its out-of-bounds alpha (a depth format has no alpha). The
/// [`FLAG_TEXEL_CLASS`]) and its border texels (`metal::sampler::border_texels`, in
/// [`FLAG_BORDER_TEXELS`]) beside its out-of-bounds alpha (a depth format has no alpha). The
/// search's flagged form carries the alpha in the handle's bit 31 and the class in place where it
/// carries them; a miss carries nothing.
/// carries them, and its indexed form the entry's index in the top 16 bits; a miss carries
/// nothing.
#[test]
fn table_entries_state_each_members_texel_class() {
let dev = m3();
@@ -1113,6 +1116,11 @@ fn table_entries_state_each_members_texel_class() {
crate::metal::TextureSwizzleChannels::DEFAULT,
) << FLAG_TEXEL_CLASS.trailing_zeros()
};
let border = |pf| {
crate::metal::sampler::border_texels(pf, crate::metal::TextureSwizzleChannels::DEFAULT)
.expect("border texels")
<< FLAG_BORDER_TEXELS.trailing_zeros()
};
let (d16, d32, d32s8, rgba8) = (
class(PixelFormat::Depth16Unorm),
class(PixelFormat::Depth32Float),
@@ -1120,14 +1128,21 @@ fn table_entries_state_each_members_texel_class() {
class(PixelFormat::RGBA8Unorm),
);
assert!(d16 != 0 && d32 != 0 && rgba8 != 0 && d16 != rgba8);
// A depth format's border texel is `(b, b, b, 1)`, a four-channel one's the color itself.
let (depth, four) = (
border(PixelFormat::Depth16Unorm),
border(PixelFormat::RGBA8Unorm),
);
assert_eq!(depth >> 3, 0b111_100_100_100);
assert_eq!(four >> 3, 0b110_100_100_100);
assert_eq!(
entries(&cmds.descriptor_bytes, set, binding),
vec![
(0, 0, 0),
(D, 4, rgba8),
(A, 1, alpha | d16),
(B, 2, alpha | d32),
(C, 3, alpha | d32s8),
(D, 4, rgba8 | four),
(A, 1, alpha | depth | d16),
(B, 2, alpha | depth | d32),
(C, 3, alpha | depth | d32s8),
]
);
let bytes = &cmds
@@ -1156,6 +1171,16 @@ fn table_entries_state_each_members_texel_class() {
emitted_lookup_in(bytes, &keys, classes),
vec![4 | rgba8, 1 | d16, 2 | d32, 3 | d32s8, 0, 0]
);
let indexed = Lookup::Indexed {
alpha: true,
class: true,
red_blue: false,
};
let entry = |k: u32| k << HANDLE_ENTRY.trailing_zeros();
assert_eq!(
emitted_lookup_in(bytes, &keys, indexed),
vec![4 | entry(1), 1 | entry(2), 2 | entry(3), 3 | entry(4), 0, 0]
);
}
/// A heap texture sampled through a constexpr sampler reads a set-0 heap sampler: a `SAMPLER`
@@ -710,10 +710,9 @@ fn a_clamp_to_edge_read_clamps_its_coordinate_into_the_texture() {
/// Every read through a sampler translates, links and passes `spirv-val` where it translates:
/// the constexpr, runtime and argument-buffer samplers' (`rt_table`), and an argument buffer's
/// texture through `clamp_to_zero` (`rt_heap_zero`), whose border texel is its handle's
/// out-of-bounds texel. An argument buffer's texture through `clamp_to_border` with an opaque
/// white border (`rt_heap_ow`), or through a runtime sampler (`rt_heap_arg`), whose border color
/// the handle cannot give, is refused on every profile as not implemented.
/// texture through `clamp_to_zero` (`rt_heap_zero`), `clamp_to_border` with an opaque white border
/// (`rt_heap_ow`) and a runtime sampler (`rt_heap_arg`), whose border texels its handle-table entry
/// holds.
#[test]
fn every_read_through_a_sampler_validates_or_is_refused_typed() {
let Some(bc) = read_through() else {
@@ -743,39 +742,336 @@ fn every_read_through_a_sampler_validates_or_is_refused_typed() {
"rt_arg_volume",
"rt_table",
"rt_heap_zero",
"rt_heap_ow",
"rt_heap_arg",
];
let mut validated = 0;
let want = Unsupported::not_implemented(Feature::ArgumentBufferTextures);
let mut heap = 0;
let not_implemented = Unsupported::not_implemented(Feature::ArgumentBufferTextures);
for (stem, p) in profiles() {
for entry in entries {
match compile(&bc, entry, &p) {
Ok(a) => {
link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{stem}: {entry}: {e}"));
validated += 1;
if entry.starts_with("rt_heap") {
heap += 1;
}
}
Err(Error::NeedsInput(_)) => {}
// A device without the descriptor-indexing features a handle heap needs refuses
// an argument buffer's texture whatever reads it.
Err(Error::Unsupported(u))
if entry == "rt_heap_zero"
if entry.starts_with("rt_heap")
&& u.feature == Feature::ArgumentBufferTextures
&& u.needs != want.needs => {}
Err(e) => panic!("{stem}: {entry}: {e}"),
}
}
for entry in ["rt_heap_ow", "rt_heap_arg"] {
match typed_module(&bc, entry, &p) {
Err(Error::Unsupported(u)) => assert_eq!(
(u.feature, u.needs),
(want.feature.clone(), want.needs.clone()),
"{stem}: {entry}"
),
Ok(_) => panic!("{stem}: {entry} translated"),
&& u.needs != not_implemented.needs => {}
Err(e) => panic!("{stem}: {entry}: {e}"),
}
}
}
assert!(validated > 0);
assert!(heap > 0, "no argument buffer's texture read translated");
}
/// The handle table's entry `(id, element, flags)` list of `bytes`.
fn table_entries(bytes: &[u8]) -> Vec<(u64, u32, u32)> {
use crate::memory::handles::TABLE_ENTRY_BYTES;
bytes
.chunks_exact(TABLE_ENTRY_BYTES as usize)
.map(|e| {
let w = |i: usize| u32::from_le_bytes(e[4 * i..4 * i + 4].try_into().expect("word"));
(u64::from(w(0)) | u64::from(w(1)) << 32, w(2), w(3))
})
.collect()
}
/// An argument buffer's texture read through a sampler hands back Metal's border texels of the
/// resident texture, its pixel format's and swizzle's, which the binder writes in the texture's
/// handle-table entry (`memory::handles::FLAG_BORDER_TEXELS`) and the read loads from the entry its
/// handle names (the search's indexed form, `memory::handles::Lookup::Indexed`). End to end on the
/// interpreter: the binder's table bytes for two resident textures of two levels, an `RGBA32Float`
/// made with the swizzle `(G, R, 1, 0)` and an `R32Float`, the emitted search, and reads in and
/// past each through `clamp_to_zero` (`rt_heap_zero`), an opaque white `clamp_to_border`
/// (`rt_heap_ow`), and a runtime sampler (`rt_heap_arg`) of each border color, of `clamp_to_edge`,
/// and of a border with a mip filter; a missed id reads zero in every lane. Before the entry held
/// them, the swizzled texture read `(0, 0, 0, 0)` past its edge through `clamp_to_zero`, where the
/// M3 reads `(0, 0, 1, 0)`, and the other two reads were refused.
#[test]
fn an_argument_buffer_texture_reads_its_border_texels_from_its_table_entry() {
use crate::memory::handles::Lookup;
use crate::metal::TextureSwizzle as S;
let Some(bc) = read_through() else {
return;
};
const SWIZZLED: u64 = 0x0000_0001_0000_0010;
const RED: u64 = 0x0000_0001_0000_0020;
const MISSED: u64 = 0x0000_0002_0000_0000;
let swizzle = TextureSwizzleChannels {
red: S::Green,
green: S::Red,
blue: S::One,
alpha: S::Zero,
};
let textures = [
(SWIZZLED, PixelFormat::RGBA32Float, swizzle),
(RED, PixelFormat::R32Float, TextureSwizzleChannels::DEFAULT),
];
let unrobust = [
VkFeature::RobustImageAccess,
VkFeature::RobustImageAccess2,
VkFeature::RobustBufferAccess,
VkFeature::RobustBufferAccess2,
];
let devices = [
("moltenvk-m3", device("moltenvk-m3", &[])),
(
"moltenvk-m3 robust1",
device("moltenvk-m3", &[VkFeature::RobustImageAccess2]),
),
("moltenvk-m3 unrobust", device("moltenvk-m3", &unrobust)),
("lavapipe", device("lavapipe", &[])),
("amd-780m-radv", device("amd-780m-radv", &[])),
];
// Inside, past each edge, at level 1 (the base level's texel without a mip filter), past the
// last level.
let base = |border: Want| {
vec![
([1, 2, 0, 0], at(0, [1, 2, 0])),
([4, 0, 0, 0], border),
([int(-1), 3, 0, 0], border),
([3, 3, 0, 1], at(0, [3, 3, 0])),
([0, 0, 0, 2], Want::Zero),
]
};
let edge = vec![
([1, 2, 0, 0], at(0, [1, 2, 0])),
([4, 0, 0, 0], at(0, [3, 0, 0])),
([int(-1), 3, 0, 0], at(0, [0, 3, 0])),
([0, 0, 0, 2], Want::Zero),
];
// Under a mip filter the read reads its own level, 2 x 2.
let mip = |border: Want| {
vec![
([1, 0, 0, 1], at(1, [1, 0, 0])),
([3, 3, 0, 1], border),
([0, 0, 0, 2], Want::Zero),
]
};
let mut reads: Vec<(&str, Option<u32>, Vec<([u32; 4], Want)>)> = vec![
("rt_heap_zero", None, base(Want::Border(TB))),
("rt_heap_ow", None, base(Want::Border(OW))),
("rt_heap_arg", Some(word([EDGE; 3], OW, 0)), edge),
(
"rt_heap_arg",
Some(word([ZERO; 3], OB, 0)),
base(Want::Border(OB)),
),
(
"rt_heap_arg",
Some(word([BORDER, ZERO, BORDER], OW, 1)),
mip(Want::Border(OW)),
),
];
for b in [TB, OB, OW] {
reads.push((
"rt_heap_arg",
Some(word([BORDER; 3], b, 0)),
base(Want::Border(b)),
));
}
let mut ran = Vec::new();
for (stem, dev) in devices {
for (entry, sampler, rows) in &reads {
let lib = Library::from_air(&bc).expect("library");
let f = lib.function(entry).expect("entry");
let desc =
ComputePipelineDescriptor::new(StageSource::Function(FunctionDescriptor::new(f)));
let pipe = match dev.compile_compute_pipeline(&desc, &Budget::standard()) {
Ok(p) => p,
Err(Error::Unsupported(u)) if u.feature == Feature::ArgumentBufferTextures => {
continue
}
Err(e) => panic!("{stem}: {entry}: {e}"),
};
let used = |token, (id, pf, swizzle): (u64, PixelFormat, TextureSwizzleChannels)| {
let mut facts = TextureFacts::new(TextureType::Type2D, pf);
facts.mipmap_level_count = 2;
facts.swizzle = swizzle;
let mut u = UsedResource::new(ResourceClass::Texture(facts), token);
u.resource_id = Some(id);
u
};
let state = BindState {
used_resources: vec![used(1, textures[0]), used(2, textures[1])],
..Default::default()
};
let bplan = pipe.plan(&dev, &state.shape()).expect("plan");
let dispatch = Dispatch::Threadgroups {
groups: [rows.len() as u32, 1, 1],
threads_per_group: [1, 1, 1],
};
let cmds = bplan
.instantiate_dispatch(&state, &dispatch)
.expect("dispatch");
let (set, binding) = bplan
.descriptors
.iter()
.find_map(|d| {
matches!(d.source, WriteSource::HandleTable { .. })
.then_some((d.set, d.binding))
})
.expect("a handle table");
let table = cmds
.descriptor_bytes
.iter()
.find(|b| (b.set, b.binding) == (set, binding))
.expect("table bytes")
.bytes
.clone();
let entries = table_entries(&table);
let element = |id: u64| {
entries
.iter()
.find(|e| e.0 == id)
.map(|e| e.1)
.expect("a listed id")
};
let (plan, m) = typed_module(&bc, entry, dev.profile()).expect("module");
assert!(
matches!(plan.families.access.lookup(), Lookup::Indexed { .. }),
"{stem}: {entry}: the search names each handle's entry"
);
let class = class(dev.profile(), false);
let heap = plan
.families
.texture
.heap
.values()
.find_map(|h| h.class)
.expect("a heap class");
let slot = ResourceSlot {
stage: Stage::Kernel,
kind: ResourceKind::Heap(HandleClass::Image(heap)),
index: 0,
};
// Element 0 is the class's neutral; each texture's element views it (the swizzled
// one's texels as its view reads them), 4 x 4 and 2 x 2, each texel naming itself.
let image = |e: u32, pf: PixelFormat| {
let mut img = Image::new(slot, [4, 4, 1], 1, 2, 1).at_element(e);
for (i, t) in img.texels.iter_mut().enumerate() {
let i = i as f32;
*t = match pf {
PixelFormat::R32Float => [fl(1.0 + i), 0, 0, fl(1.0)],
_ => [fl(1.0 + i), fl(100.0 + i), fl(200.0 + i), fl(300.0 + i)],
};
}
let alpha = match pf {
PixelFormat::R32Float => fl(1.0),
_ => 0,
};
img.robust = robust(class, alpha);
img
};
let mut neutral = Image::new(slot, [1, 1, 1], 1, 1, 1).at_element(0);
neutral.robust = robust(class, 0);
let mut images = vec![neutral];
for (id, pf, _) in textures {
images.push(image(element(id), pf));
}
images.sort_by_key(|i| i.element);
let ids = textures
.iter()
.map(|&(id, pf, swizzle)| (id, Some((pf, swizzle))))
.chain([(MISSED, None)]);
for (id, texture) in ids {
let bits = texture.map_or(0, |(pf, swizzle)| {
border_texels(pf, swizzle).expect("border texels")
});
let img = match texture {
Some(_) => images.iter().find(|i| i.element == element(id)),
None => None,
};
let mut spec = BTreeMap::new();
for axis in [Axis::X, Axis::Y, Axis::Z] {
spec.insert(SpecKey::LocalSize(axis), 1);
}
spec.insert(SpecKey::FlatLocalSize, 1);
if let Some(w) = sampler {
let fields = SamplerWord::READ_STATE;
let key = SpecKey::SamplerState {
slot: SAMPLER,
fields,
};
spec.insert(key, u64::from(w & fields));
}
let buffer = |kind, index, bytes| Buffer {
slot: Some(ResourceSlot {
stage: Stage::Kernel,
kind,
index,
}),
address: None,
bytes,
};
let p_rows: Vec<u8> = rows
.iter()
.flat_map(|(r, _)| r.iter().flat_map(|w| w.to_le_bytes()))
.collect();
let res = Resources {
buffers: vec![
buffer(ResourceKind::Buffer, 0, p_rows),
buffer(ResourceKind::Buffer, 1, vec![0xAB; rows.len() * 16]),
buffer(ResourceKind::Buffer, 2, id.to_le_bytes().to_vec()),
buffer(
ResourceKind::Synthetic(SyntheticBinding::HandleTable),
0,
table.clone(),
),
],
push: vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)],
spec,
};
let (bufs, _) = run_both(&m, &res, &images, rows.len() as u32, stem);
let want: Vec<u8> = rows
.iter()
.flat_map(|(_, want)| {
let t = match (want, img) {
(_, None) | (Want::Zero, _) => [0; 4],
(Want::At((level, layer, sample, xyz)), Some(img)) => {
let i =
img.index(*level, *layer, *sample, *xyz).expect("in bounds");
img.texels[i]
}
(Want::Border(b), Some(_)) => {
std::array::from_fn(|c| match bits >> (3 * c as u32 + b) & 1 {
1 => fl(1.0),
_ => 0,
})
}
(Want::Oob, Some(_)) => panic!("no sample index here"),
};
Out::Vec4.bytes(t)
})
.collect();
for (i, (got, want)) in bufs[1]
.chunks_exact(16)
.zip(want.chunks_exact(16))
.enumerate()
{
assert_eq!(
got, want,
"{stem}: {entry} {sampler:?} id {id:#x} row {i} {:?}",
rows[i].0
);
}
}
ran.push(class);
}
}
ran.sort();
ran.dedup();
assert_eq!(ran, ALL);
}
/// Metal's border texels per format (`metal::sampler::border_texels`), as the M3 Max read them
+2 -5
View File
@@ -44,7 +44,7 @@ Its limits, measured rather than asserted:
| committed recordings | 1276 |
| distinct SDK items the Metal leg reaches, of any status | 821 |
| of those, reached only where this cannot name the family | 3 |
| ledger rows (a case whose gap is recorded) | 3586 |
| ledger rows (a case whose gap is recorded) | 3583 |
| declared crossings of the option space (pairs put to Metal at once) | 26 |
| declared crossings that are no pair of it (a boolean or numeric field, or one type in two slots) | 30 |
@@ -5574,9 +5574,6 @@ A case whose difference from Metal is recorded rather than compared away. The le
| `ycbcr-minify-band-x` | The site is the first and last 256 samples of the band, held by their digest alone: a 4K `x420` (`YCBCR10_420_2P`) surface minified along x through a linear sam… |
| `ycbcr-minify-band-y` | The site is the whole band's 34,816 samples, held by their digest alone: a 4K `x420` (`YCBCR10_420_2P`) surface minified along y through a linear sampler, at th… |
| `ycbcr-minify-band-y` | The site is the first and last 256 samples of the band, held by their digest alone: a 4K `x420` (`YCBCR10_420_2P`) surface minified along y through a linear sam… |
| `read-through-rgba8-swizzled` | An argument buffer's texture read through clamp_to_zero past its edge: Metal reads the transparent-black border texel through the texture's swizzle ((G, R, 1, 0… |
| `read-through-heap-border` | An argument buffer's texture read through clamp_to_border with an opaque border: Metal reads the border colour in the texture's channels through its swizzle; we… |
| `read-through-heap-sampler` | An argument buffer's texture read through a runtime sampler: Metal addresses it by the sampler's state, a border mode reading the border colour in the texture's… |
| `read-through-rgba8` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
@@ -5624,7 +5621,7 @@ A case whose difference from Metal is recorded rather than compared away. The le
| `read-through-rgba8-swizzled` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8-swizzled` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8-swizzled` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8-swizzled` | An argument buffer's texture read through clamp_to_zero past its edge: Metal reads the transparent-black border texel through the texture's swizzle ((G, R, 1, 0… |
| `read-through-rgba8-swizzled` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8-swizzled` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8-swizzled` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
| `read-through-rgba8-swizzled` | A read of an 8-bit unorm texel through the device's own conversion: llvmpipe's value of an 8-bit code is one f32 ulp high of Metal's (0x3ec2c2c4 where Metal rea… |
-9
View File
@@ -440,15 +440,6 @@ recorded here.
Open differences from Metal that no note announces yet, and runtime costs still above the
driver's. Each is open work.
- **An argument buffer's texture read through a sampler's border reads the transparent black
border alone, and not through the texture's swizzle** (`lower/texture/emit/through.rs`): a heap
handle carries its format's alpha and nothing else of its border texels, so such a read through
`clamp_to_zero` or a transparent black `clamp_to_border` reads the out-of-bounds texel, which is
Metal's border texel for every texture without a swizzle. Through a swizzled texture Metal
swizzles the border texel and we do not (`(G, R, 1, 0)` reads `(0, 0, 1, 0)` on Metal and
`(0, 0, 0, 0)` here: the conformance case `read-through-rgba8-swizzled`). A read through an
opaque border colour or a runtime sampler is refused (`NotImplemented(ArgumentBufferTextures)`).
- **A heap texture Metal keeps uncompressed lies in its driver's layout, not Metal's tiles, where
its image fits Metal's answer in the heap's memory** (`texture/heap.rs`,
`heap-texture-untiled-layout`): on every driver whose colour images are not measured to lie as
+2 -2
View File
@@ -77,7 +77,7 @@ Columns:
| `QuadOperations` | Quad operations in a stage without quad support | devices without VkLimit::MinSubgroupSize; devices without VkProperty::SubgroupQuadOperationsInAllStages | `device` | 2: `crates/metal2vulkan/src/device/subgroup.rs (subgroup_tier, 2 sites)` | `app`: quad shuffles in kernels on devices without quad operations there |
| `SimdgroupMatrix` | Simdgroup matrix operations | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/lower/simd/matrix.rs (not_implemented)` | `rare`: simdgroup matrix kernels |
| `ArgumentBufferPointers` | Argument buffers holding buffer pointers (dynamic roots) | devices without buffer device addresses (`addressed_needs`) | `device` | 1: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)` | `app`: argument buffers holding buffer pointers |
| `ArgumentBufferTextures` | Argument buffers holding textures or samplers (handle domain) | devices short of a device limit the site names; devices without a capability the site computes (`gaps`); devices without a capability the site computes (`missing`); devices without a capability the site computes (`needs`); every device (not implemented) | `ours` | 18: `crates/metal2vulkan-runtime/src/families/features.rs (tier2)`, `crates/metal2vulkan-runtime/src/pipeline/objects.rs (create_set_layout)` (+11) | `app`: argument buffers holding textures and samplers (bindless) |
| `ArgumentBufferTextures` | Argument buffers holding textures or samplers (handle domain) | devices short of a device limit the site names; devices without a capability the site computes (`gaps`); devices without a capability the site computes (`missing`); devices without a capability the site computes (`needs`); every device (not implemented) | `ours` | 17: `crates/metal2vulkan-runtime/src/families/features.rs (tier2)`, `crates/metal2vulkan-runtime/src/pipeline/objects.rs (create_set_layout)` (+10) | `app`: argument buffers holding textures and samplers (bindless) |
| `ArgumentBufferObjects` | Argument-buffer members that are pipeline states, ICBs, function tables, or acceleration structures | every device (not implemented) | `ours` | 5: `crates/metal2vulkan/src/lower/access/encode.rs (select_command, 3 sites)`, `crates/metal2vulkan/src/memory/provenance.rs (access)` (+1) | `rare`: pipeline states and ICBs in argument buffers |
| `DereferenceLoadedPointer` | Dereferencing a pointer loaded from memory or made from an integer | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism) | `device` | 4: `crates/metal2vulkan/src/lower/access/dynamic.rs (plan_misses)`, `crates/metal2vulkan/src/lower/access/local.rs (access_ptr)` (+2) | `app`: pointers loaded from argument buffers |
| `PointerToInteger` | Storing a pointer or converting it to an integer | - | `-` | via a helper: 1: `crates/metal2vulkan/src/lower/access/dynamic.rs (require_addresses)` | `rare`: pointer to integer casts |
@@ -598,7 +598,7 @@ Each refusal's sites, with the function that builds it.
- `feature::QuadOperations`: `crates/metal2vulkan/src/device/subgroup.rs (subgroup_tier, 2 sites)`
- `feature::SimdgroupMatrix`: `crates/metal2vulkan/src/lower/simd/matrix.rs (not_implemented)`
- `feature::ArgumentBufferPointers`: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)`
- `feature::ArgumentBufferTextures`: `crates/metal2vulkan-runtime/src/families/features.rs (tier2)`; `crates/metal2vulkan-runtime/src/pipeline/objects.rs (create_set_layout)`; `crates/metal2vulkan-runtime/src/resource_ids.rs (check_capacity, 2 sites)`; `crates/metal2vulkan/src/bind/heap.rs (array)`; `crates/metal2vulkan/src/bind/heap.rs (member_view, 4 sites)`; `crates/metal2vulkan/src/lower/access/handle.rs (select)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_heap_sampling)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_sampling)`; `crates/metal2vulkan/src/lower/texture/atomic.rs (select)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_through)`; `crates/metal2vulkan/src/lower/texture/slot.rs (declare_heap, 2 sites)`; `crates/metal2vulkan/src/pipeline/link.rs (heap_set)`
- `feature::ArgumentBufferTextures`: `crates/metal2vulkan-runtime/src/families/features.rs (tier2)`; `crates/metal2vulkan-runtime/src/pipeline/objects.rs (create_set_layout)`; `crates/metal2vulkan-runtime/src/resource_ids.rs (check_capacity, 2 sites)`; `crates/metal2vulkan/src/bind/heap.rs (array)`; `crates/metal2vulkan/src/bind/heap.rs (member_view, 4 sites)`; `crates/metal2vulkan/src/lower/access/handle.rs (select)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_heap_sampling)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_sampling)`; `crates/metal2vulkan/src/lower/texture/atomic.rs (select)`; `crates/metal2vulkan/src/lower/texture/slot.rs (declare_heap, 2 sites)`; `crates/metal2vulkan/src/pipeline/link.rs (heap_set)`
- `feature::ArgumentBufferObjects`: `crates/metal2vulkan/src/lower/access/encode.rs (select_command, 3 sites)`; `crates/metal2vulkan/src/memory/provenance.rs (access)`; `crates/metal2vulkan/src/memory/provenance.rs (classify)`
- `feature::DereferenceLoadedPointer`: `crates/metal2vulkan/src/lower/access/dynamic.rs (plan_misses)`; `crates/metal2vulkan/src/lower/access/local.rs (access_ptr)`; `crates/metal2vulkan/src/lower/access/local.rs (threadgroup_constant_refusal)`; `crates/metal2vulkan/src/memory/plan.rs (analyze)`
- `feature::PointerToInteger`: `crates/metal2vulkan/src/lower/access/dynamic.rs (require_addresses)`