mipmap_chains: a half's allowance below the float filter follows the announced device filter's direction

Orchestrator review of 1ced2a372b: the two-unit bound was not keyed and had no direction. The
780M's halves lie only below the filter (job m3-max-11026: 274 one below, 9 two below, none
above), so the device truncates its blit's filter of a half, and the lane should follow the
notice that says the level is the device's filter.

A half now lies within one unit in the last place above the filter, as before. Below it, it lies
within HALF_BELOW_ULPS (2) where the run announced device-filtered-mipmaps, else within one. Each
RGBA16Float level prints how many halves lie one and two below and one above, and the most each
way. The 8-bit formats keep their one-code bound both ways. The lane's docs state the measured
rule.

(cherry picked from commit fbfc2f492dc4d0711e7efd30a443286d5d329dba)
This commit is contained in:
Anees Iqbal committed 2026-11-09 01:29:15 -08:00
1 parent 9fed9dec1a
commit c8a8f0dbe6
1 file changed
+62 -35
@@ -4,9 +4,10 @@
//!
//! - **The blit chain** of formats every Vulkan device blits and filters linearly, in 2D, 2D
//! array, cube and 3D textures: one `vkCmdBlitImage` a level (the work counts say so), the
//! compute filter never, each level of a halving chain within a code (a half within two units
//! in the last place: [`HALF_BLIT_ULPS`]) of the bilinear filter in `float` of the level above as
//! the device read it back, and `device-filtered-mipmaps` announced once. On a driver whose blits do not filter a
//! compute filter never, each level of a halving chain within a code of the bilinear filter in
//! `float` of the level above as the device read it back (a half within a unit in the last place
//! above it and, where the device announced its filter, [`HALF_BELOW_ULPS`] below it), and
//! `device-filtered-mipmaps` announced once. On a driver whose blits do not filter a
//! volume (`RuntimeDriverDefect::VolumeBlitsUnfiltered`, MoltenVK's) the 3D textures take the
//! compute filter instead, each level within a code of the same filter.
//! - **The compute filter** of every format it computes that the device's blits cannot filter
@@ -181,19 +182,22 @@ fn filtered(
levels.swap_remove(1)
}
/// How far a half a device's blit filters may lie from the bilinear filter in `float` of the level
/// above, in units in the last place: the device's filter, whose precision Vulkan leaves to it.
/// The Radeon 780M under RADV filters an `RGBA16Float` cube's level 1 at most two below it (job
/// m3-max-11026 at development 1c7a75be62: of its 384 halves, 274 one below and 9 two below).
const HALF_BLIT_ULPS: u16 = 2;
/// How far below the bilinear filter in `float` of the level above a half the device's blit
/// filters may lie, in units in the last place, where the device announced that the level is its
/// filter (`device-filtered-mipmaps`); above it, a half lies within one. The device's filter is
/// the answer, and its precision is the device's: the Radeon 780M under RADV truncates its filter
/// of a half (job m3-max-11026 at development 1c7a75be62, an `RGBA16Float` cube's level 1: of its
/// 384 halves, 274 one unit below the filter, 9 two below, none above).
const HALF_BELOW_ULPS: u16 = 2;
/// The device's blit chain of formats every Vulkan device blits and filters linearly (`R8Unorm`,
/// `RGBA8Unorm`, `BGRA8Unorm`, `RGBA16Float`), in 2D textures (halving and not, one two texels
/// high), a 2D array, a cube and 3D textures: one blit a level and no compute filter (but a 3D
/// texture's compute filter on a driver whose blits do not filter a volume,
/// `RuntimeDriverDefect::VolumeBlitsUnfiltered`), each level of a halving chain within a code (a
/// half within [`HALF_BLIT_ULPS`] units in the last place) of the bilinear filter in `float` of
/// the level above as the device read it back, and `device-filtered-mipmaps` announced once, naming the first
/// `RuntimeDriverDefect::VolumeBlitsUnfiltered`), each level of a halving chain within a code of
/// the bilinear filter in `float` of the level above as the device read it back (a half within a
/// unit in the last place above it and [`HALF_BELOW_ULPS`] below it, the device's filter
/// announced), and `device-filtered-mipmaps` announced once, naming the first
/// texture.
#[test]
fn the_device_s_blit_chain_filters_each_level_and_is_announced() {
@@ -230,6 +234,8 @@ fn the_device_s_blit_chain_filters_each_level_and_is_announced() {
];
let mut seed = 0x626c_6974_6368_6169u64;
let mut checked = 0usize;
// Each `RGBA16Float` level's most units in the last place below the filter, and the level.
let mut halves_below: Vec<(i32, String)> = Vec::new();
for (pf, texel, ty, extent, slices, levels, halving) in cases {
let t = texture(&device, pf, ty, extent, levels, slices);
let texels = |l: usize| level_extent(extent, l).iter().product::<usize>();
@@ -266,40 +272,61 @@ fn the_device_s_blit_chain_filters_each_level_and_is_announced() {
let above = read(l - 1);
let want = filtered(pf, ty, level_extent(extent, l - 1), slices, &above);
let got = read(l);
let near = match pf {
P::RGBA16Float => {
let apart: Vec<u16> = (got.as_chunks::<2>().0.iter())
.zip(want.as_chunks::<2>().0)
.map(|(a, b)| u16::from_le_bytes(*a).abs_diff(u16::from_le_bytes(*b)))
.collect();
let most = apart.iter().copied().max().unwrap_or(0);
let ulps = |n: u16| apart.iter().filter(|&&d| d == n).count();
eprintln!(
"blit chain {pf:?} {ty:?} {extent:?} level {l} on {}: of {} halves, \
{} one unit in the last place from the filter, {} two, the most {most}",
device.name(),
apart.len(),
ulps(1),
ulps(2)
);
most <= HALF_BLIT_ULPS
}
_ => got.iter().zip(&want).all(|(a, b)| a.abs_diff(*b) <= 1),
};
assert!(
near,
let what = format!(
"{pf:?} {ty:?} {extent:?} level {l}: the blit {got:02x?}, the filter {want:02x?}"
);
match pf {
// Finite halves in [0, 1): their bits order as their values.
P::RGBA16Float => {
let apart: Vec<i32> = (got.as_chunks::<2>().0.iter())
.zip(want.as_chunks::<2>().0)
.map(|(a, b)| {
i32::from(u16::from_le_bytes(*a))
- i32::from(u16::from_le_bytes(*b))
})
.collect();
let below = -apart.iter().copied().min().unwrap_or(0).min(0);
let above = apart.iter().copied().max().unwrap_or(0).max(0);
let count = |d: i32| apart.iter().filter(|&&a| a == d).count();
eprintln!(
"blit chain {pf:?} {ty:?} {extent:?} level {l} on {}: of {} halves, \
{} one unit in the last place below the filter, {} two below, {} \
one above; the most {below} below and {above} above",
device.name(),
apart.len(),
count(-1),
count(-2),
count(1)
);
assert!(above <= 1, "{what}");
halves_below.push((below, what));
}
_ => assert!(
got.iter().zip(&want).all(|(a, b)| a.abs_diff(*b) <= 1),
"{what}"
),
}
checked += got.len();
}
}
eprintln!(
"the blit chain on {}: {checked} bytes of halving chains, each within a code (a half \
within {HALF_BLIT_ULPS} units in the last place) of the bilinear filter in float",
"the blit chain on {}: {checked} bytes of halving chains, each within a code of the \
bilinear filter in float (a half within one above it and {HALF_BELOW_ULPS} below)",
device.name()
);
let notices = messages.take_notices();
assert_once(&notices, &MIPMAPS);
// A half more than a unit below the filter: the device's own filter, which it announced.
let announced = (notices.iter())
.filter_map(|message| message.degradation.as_ref())
.any(|notice| notice.degradation == Degradation::DeviceFilteredMipmaps);
let most_below = match announced {
true => i32::from(HALF_BELOW_ULPS),
false => 1,
};
for (below, what) in &halves_below {
assert!(*below <= most_below, "{what}");
}
let notice = notices
.iter()
.filter_map(|message| message.degradation.as_ref())