Translator test: half computes in 16 bits under RTE and SignedZeroInfNanPreserve where only 16-bit DenormPreserve is missing (red)

The planner's ruling (T3): on a device with shaderFloat16, 16-bit RoundingModeRTE and 16-bit
SignedZeroInfNanPreserve whose only missing 16-bit control is DenormPreserve, the half
operations narrow::half_controls gates take the 16-bit route, and any other missing control
keeps today's 32-bit form, under today's independence rules.

engine_native_half's new test asks, on the committed lavapipe profile and on the RTX 5080
Laptop GPU's and the Radeon 780M's descriptions without shaderDenormPreserveFloat16, for the
16-bit instructions the full controls give (a sum, a product and a chain of two on 16-bit
floats, the controlled pair for a half narrowed alone), an entry declaring RoundingModeRTE and
SignedZeroInfNanPreserve for 16 bits and no DenormPreserve at any width (the 780M's
independence for 32 bits only would tie a 64-bit one to a 16-bit one, VUID 06289), no
DenormPreserve property required, L3, and each operation rounded on the interpreter. And it
asks that the RTX 5080 Laptop GPU without 16-bit SignedZeroInfNanPreserve too, MoltenVK on the
M3 (denormal and rounding modes not independent), and the 780M without 64-bit DenormPreserve
stay in float.

Red: half_controls asks for 16-bit DenormPreserve, so lavapipe computes half in float.
This commit is contained in:
Anees Iqbal committed 2026-12-02 17:49:16 -08:00
1 parent 4fa543f9e6
commit 306f8b00eb
1 file changed
+148
@@ -972,6 +972,154 @@ fn nvidia_computes_half_on_16_bit_floats_under_the_float_controls() {
}
}
/// A device that offers `shaderFloat16` with 16-bit `RoundingModeRTE` and `SignedZeroInfNanPreserve`
/// but not 16-bit `DenormPreserve` computes `half` in 16 bits under the other two controls: the
/// committed lavapipe profile, the RTX 5080 Laptop GPU's description without
/// `shaderDenormPreserveFloat16` (the shape Turnip reports before the Adreno 8xx series), and the
/// Radeon 780M's without it, whose denormal modes are independent for 32 bits only. Each takes the
/// 16-bit instructions it takes under all three, one an operation, and the controlled pair for a
/// `half` narrowed and widened back alone; its entry declares `RoundingModeRTE` and
/// `SignedZeroInfNanPreserve` for 16 bits (and `RoundingModeRTE` for 64 bits where the 780M's
/// rounding independence ties it) and no denormal mode at any width, not the 64-bit one the 780M's
/// independence would tie to a 16-bit one (VUID 06289), and requires no `DenormPreserve` property.
/// Each passes L3, and on the interpreter rounds each operation to `half`. Any other control
/// missing keeps `half` in `float`, no 16-bit instruction and no 16-bit mode: without 16-bit
/// `SignedZeroInfNanPreserve`; on MoltenVK on the M3, whose denormal and rounding modes are not
/// independent; and where denormal modes are independent for 32 bits only without 64-bit
/// `DenormPreserve`.
#[test]
fn half_without_denorm_preserve_computes_in_16_bits_under_the_other_two_controls() {
use crate::device::requirements::{FloatControl, FloatWidth};
use crate::device::{Device, DeviceDescription};
use crate::lower::arith::narrow::half_controls;
use crate::spv::ExecutionMode as M;
let Some(bc) = assemble("native-half-no-denorm", &module_of(&NATIVE)) else {
return;
};
let of = |desc: DeviceDescription| {
Device::from_queries(desc, DevicePolicy::RESIDENT_TABLES)
.expect("device")
.profile()
.clone()
};
let described = |stem: &str| crate::pipeline::testing::description(stem).expect("profile");
let mut laptop = described("nvidia-rtx5080-laptop");
laptop.float_controls.f16.denorm_preserve = false;
let mut radv = described("amd-780m-radv");
radv.float_controls.f16.denorm_preserve = false;
let shaped = [
(
"lavapipe",
profile("lavapipe", DevicePolicy::RESIDENT_TABLES).expect("profile"),
vec![
(M::RoundingModeRTE as u32, 16),
(M::SignedZeroInfNanPreserve as u32, 16),
],
),
(
"RTX 5080 Laptop GPU without DenormPreserve for 16 bits",
of(laptop.clone()),
vec![
(M::RoundingModeRTE as u32, 16),
(M::SignedZeroInfNanPreserve as u32, 16),
],
),
(
"Radeon 780M without DenormPreserve for 16 bits",
of(radv.clone()),
vec![
(M::RoundingModeRTE as u32, 16),
(M::RoundingModeRTE as u32, 64),
(M::SignedZeroInfNanPreserve as u32, 16),
],
),
];
let one = 1.0 + 2f32.powi(-10);
for (stem, p, modes) in &shaped {
assert!(half_controls(p), "{stem}");
assert_eq!(quantize_form(p), QuantizeForm::Controlled, "{stem}");
for (name, _) in &NATIVE {
let what = format!("{name} on {stem}");
let a = compile(&bc, name, p).unwrap_or_else(|e| panic!("{what}: {e:?}"));
link_and_validate(&a, p).unwrap_or_else(|e| panic!("{what}: L3: {e}"));
let r = rounding(&a.module.words);
let ops = match *name {
"half_chain" => 2,
"half_narrow" => 0,
_ => 1,
};
assert_eq!(r.f16_ops, ops, "{what}: {r:?}");
assert_eq!(r.quantizes, 0, "{what}: {r:?}");
for mode in modes {
assert!(r.modes.contains(mode), "{what}: {mode:?} {r:?}");
}
assert!(
!r.modes.iter().any(|&(m, _)| m == M::DenormPreserve as u32),
"{what}: {r:?}"
);
for width in [FloatWidth::F16, FloatWidth::F32, FloatWidth::F64] {
assert!(
!a.requirements
.properties
.contains(&VkProperty::FloatControl(
FloatControl::DenormPreserve,
width
)),
"{what}: {width:?}"
);
}
for kind in [
FloatControl::RoundingModeRte,
FloatControl::SignedZeroInfNanPreserve,
] {
assert!(
a.requirements
.properties
.contains(&VkProperty::FloatControl(kind, FloatWidth::F16)),
"{what}: {kind:?}"
);
}
}
let run = |name: &str| interpret(&bc, name, p, [one, one]);
assert_eq!(run("half_sum"), 2.0 + 2f32.powi(-9), "{stem}");
assert_eq!(run("half_product"), 1.0 + 2f32.powi(-9), "{stem}");
assert_eq!(
run("half_chain"),
2.0 + 2f32.powi(-8),
"{stem}: each operation rounded"
);
}
// The negative controls: another control missing.
let mut no_szinp = laptop;
no_szinp.float_controls.f16.signed_zero_inf_nan_preserve = false;
let mut radv_no_f64 = radv;
radv_no_f64.float_controls.f64.denorm_preserve = false;
for (stem, p) in [
(
"RTX 5080 Laptop GPU without DenormPreserve or SignedZeroInfNanPreserve for 16 bits",
of(no_szinp),
),
(
"moltenvk-m3",
profile("moltenvk-m3", DevicePolicy::RESIDENT_TABLES).expect("profile"),
),
(
"Radeon 780M without DenormPreserve for 16 or 64 bits",
of(radv_no_f64),
),
] {
assert!(!half_controls(&p), "{stem}");
for (name, _) in &NATIVE {
let what = format!("{name} on {stem}");
let a = compile(&bc, name, &p).unwrap_or_else(|e| panic!("{what}: {e:?}"));
link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{what}: L3: {e}"));
let r = rounding(&a.module.words);
assert_eq!(r.f16_ops, 0, "{what}: {r:?}");
assert!(!r.modes.iter().any(|&(_, w)| w == 16), "{what}: {r:?}");
}
}
}
/// A kernel that reads a `half` from buffer 0 and stores it widened to `float` after the two
/// `float`s the other kernels read (bytes 8 to 12), and the `half` itself after that (bytes 12 to
/// 14).