lavapipe stores small-float NaNs as Metal does: its MetalSmallFloatNans row, and the lanes that gate it
What: driver_facts::DEVIATIONS gains MetalSmallFloatNans for MESA_LLVMPIPE (every
CPU). A half or float texel's write that may reach an RG11B10Float storage image
on lavapipe then records no DeviceNanEncoding for it and requires
VkProperty::MetalSmallFloatNans, as on MoltenVK's Apple9 identity. Two lane tests
measure the deviation on every venue and gate it where a driver is listed:
half_storage_writes::every_nan_a_kernel_writes_to_a_small_float_texture_is_metal_s_where_measured
(32,766 float NaNs: every top-13 payload pattern, low bits clear and set, both
signs; write, read_write, texture buffer and argument buffer forms) and
half_write_nans::every_half_nan_written_to_a_small_float_texture_is_metal_s_where_measured
(all 2,046 half NaNs; write, read_write, held). Each requires every NaN field
Metal's canonical one and no device-nan-encoding where the profile takes the
deviation, and device-nan-encoding where any field differs elsewhere. half_write_nans'
stored() takes its texels. The existing half_write_nans lane's measured branch
no longer requires native-nan-encoding absent where the device's widening is
unmeasured (no MetalNanMoves): that note is the kernel making's, for its widening of
the half whatever texture it writes, and a 32-bit float store shows it.
Why: lavapipe announced device-nan-encoding on every RG11B10Float half write of
runtime_lane::half_write_nans (write, read_write and held) with 0 of 25 lanes
differing from Metal's (msi, Mesa 26.2.4, LLVM 23.1.1, at 7d7085f9d0), and the
conformance case half-write-nans-rg11b10f differed only in its notices. The note
fires because the profile lacked the deviation, not because the store differs:
llvmpipe packs a small float in its shader code and writes every NaN as the
field's quiet NaN with its sign dropped, which is Metal's. RADV and NVIDIA keep
payload bits, so they stay unlisted. No SEMANTICS_VERSION bump: the deviation is
an enabled property the profile fingerprint hashes, so lavapipe's keys change
(golden_hashes' lavapipe cells re-key; re-blessed on development).
Test that fails without it: device::tests::driver_facts::
the_profile_takes_the_deviations_its_driver_is_measured_with now expects
MetalSmallFloatNans on lavapipe, gate-lavapipe and gate-lavapipe-x86_64.
Verified: the lavapipe, PHOENIX and M3 runs in the branch's report.
This commit is contained in:
1 parent
2566b388b5
commit
08ff006256
6 files changed
+192
-22
No files matched your search
@@ -450,3 +450,73 @@ fn kernel_writes_store_metals_small_floats() {
|
||||
"kernel small-float writes not Metal's: {differ:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Every NaN class of a `float` that a kernel writes to an `RG11B10Float` storage texture, through
|
||||
/// every form: each of the 8,192 patterns of a NaN's top 13 payload bits, its 10 low bits clear and
|
||||
/// set (pattern 0 with them set alone, which is no infinity), of both signs, every channel of a
|
||||
/// texel the same NaN. Metal stores each field as its canonical NaN (`0x7e0`, `0x3f0`), whatever
|
||||
/// the NaN's sign and payload (`DriverDeviation::MetalSmallFloatNans`'s measurement on the M3
|
||||
/// Max). On a device that takes that deviation every field is Metal's and nothing announces
|
||||
/// `device-nan-encoding`: the deviation's gate on each driver it lists. Elsewhere the fields
|
||||
/// stored as another code are counted and printed, and where any is, the case announces
|
||||
/// `device-nan-encoding`.
|
||||
#[test]
|
||||
fn every_nan_a_kernel_writes_to_a_small_float_texture_is_metal_s_where_measured() {
|
||||
let mut values = Vec::new();
|
||||
for sign in [0, 0x8000_0000u32] {
|
||||
for top in 0..1u32 << 13 {
|
||||
for low in [0, 0x3ff] {
|
||||
if top << 10 | low != 0 {
|
||||
values.push(f32::from_bits(sign | 0x7f80_0000 | top << 10 | low));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut failed = Vec::new();
|
||||
for form in Form::ALL {
|
||||
on_device(|device, messages| {
|
||||
let name = device.name().to_owned();
|
||||
let label = format!("RG11B10Float by {}", form.kernel());
|
||||
messages.take_notices();
|
||||
let Some(stored) = written(device, form, PixelFormat::RG11B10Float, 4, &values) else {
|
||||
return;
|
||||
};
|
||||
let noted = messages.take_notices().iter().any(|m| {
|
||||
m.degradation
|
||||
.as_ref()
|
||||
.is_some_and(|n| n.degradation == Degradation::DeviceNanEncoding)
|
||||
});
|
||||
let measured = device
|
||||
.compile_device()
|
||||
.profile()
|
||||
.takes_driver_deviation(DriverDeviation::MetalSmallFloatNans);
|
||||
// Each code stored in place of the field's canonical NaN, and how many times.
|
||||
let mut other = BTreeMap::new();
|
||||
for (i, x) in values.iter().enumerate() {
|
||||
assert!(x.is_nan());
|
||||
let texel = u32::from_le_bytes(stored[i * 4..i * 4 + 4].try_into().unwrap());
|
||||
for (offset, mantissa) in SMALL_FLOAT_FIELDS {
|
||||
let got = (texel >> offset) & ((1 << (mantissa + 5)) - 1);
|
||||
if got != (0x1f << mantissa | 1 << (mantissa - 1)) {
|
||||
*other.entry((offset, got)).or_insert(0usize) += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
let differ: usize = other.values().sum();
|
||||
let fields = values.len() * SMALL_FLOAT_FIELDS.len();
|
||||
eprintln!(
|
||||
"every small-float NaN {label} on {name}: {differ} of {fields} NaN fields not \
|
||||
Metal's {other:x?}; MetalSmallFloatNans {measured}, device-nan-encoding {noted}"
|
||||
);
|
||||
if (measured && (differ > 0 || noted)) || (differ > 0 && !noted) {
|
||||
failed.push(format!(
|
||||
"{label}: {differ} of {fields}, measured {measured}, announced {noted}"
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
assert!(
|
||||
failed.is_empty(),
|
||||
"small-float NaN writes against MetalSmallFloatNans: {failed:#?}"
|
||||
);
|
||||
}
|
||||
@@ -24,8 +24,11 @@
|
||||
//! Metal's on a device with `VkProperty::MetalSmallFloatNans`; elsewhere the NaN is the device's,
|
||||
//! and a pipeline whose stores differ announces `device-nan-encoding`. On a device with those
|
||||
//! properties a write into such a texture, through a texture slot or an argument buffer whose
|
||||
//! command makes no texture of another family resident (`SpecKey::HeapNanFamilies`), announces
|
||||
//! neither `device-nan-encoding` nor `native-nan-encoding`.
|
||||
//! command makes no texture of another family resident (`SpecKey::HeapNanFamilies`), announces no
|
||||
//! `device-nan-encoding`, nor `native-nan-encoding` where the device's widening is measured
|
||||
//! (`VkProperty::MetalNanMoves`). Where it is not (lavapipe), the kernel's making announces
|
||||
//! `native-nan-encoding` for its widening of the half, whatever texture it writes: a packed small
|
||||
//! float store of Metal's hides that NaN's bits, a 32-bit float one does not.
|
||||
|
||||
use super::degrade_notices::{counts, on_device_with};
|
||||
use super::{at_plan, buffer_with, layer_reported_nothing, read_buffer, WAIT};
|
||||
@@ -250,22 +253,28 @@ fn nan_word(f: &Format, w: u32) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// The words texel by texel that `state` (of `access`) stored into a `Private` texture of `f`.
|
||||
/// The words texel by texel that `state` (of `access`) stored into a `Private` texture of `f`, one
|
||||
/// texel a thread for each of `texels`: at most 64 of them, or a whole number of threadgroups of 64.
|
||||
fn stored(
|
||||
device: &Device,
|
||||
(state, access): (&ComputePipelineState, &str),
|
||||
f: &Format,
|
||||
texels: &[[u16; 4]],
|
||||
) -> Vec<Vec<u32>> {
|
||||
let mut d = TextureDescriptor::texture_2d(f.format, N, 1, false);
|
||||
let n = texels.len() as u64;
|
||||
let group = n.min(64);
|
||||
assert_eq!(n % group, 0, "{n} texels in threadgroups of {group}");
|
||||
let mut d = TextureDescriptor::texture_2d(f.format, n, 1, false);
|
||||
d.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE;
|
||||
d.resource_options = ResourceOptions::private();
|
||||
let texture = device.new_texture(&d).unwrap();
|
||||
let row = N * f.bytes;
|
||||
let row = n * f.bytes;
|
||||
let fill = buffer_with(device, &vec![FILL; row as usize]).unwrap();
|
||||
let out = buffer_with(device, &vec![0; row as usize]).unwrap();
|
||||
let bits: Vec<u8> = (0..V.len())
|
||||
.flat_map(texel)
|
||||
.flat_map(u16::to_le_bytes)
|
||||
let bits: Vec<u8> = texels
|
||||
.iter()
|
||||
.flatten()
|
||||
.flat_map(|h| h.to_le_bytes())
|
||||
.collect();
|
||||
let input = buffer_with(device, &bits).unwrap();
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
@@ -276,7 +285,7 @@ fn stored(
|
||||
0,
|
||||
row,
|
||||
row,
|
||||
Size::new(N, 1, 1),
|
||||
Size::new(n, 1, 1),
|
||||
&texture,
|
||||
0,
|
||||
0,
|
||||
@@ -298,7 +307,7 @@ fn stored(
|
||||
encoder.set_texture(Some(&texture), 0).unwrap();
|
||||
}
|
||||
encoder
|
||||
.dispatch_threads(Size::new(N, 1, 1), Size::new(N, 1, 1))
|
||||
.dispatch_threads(Size::new(n, 1, 1), Size::new(group, 1, 1))
|
||||
.unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
@@ -307,7 +316,7 @@ fn stored(
|
||||
0,
|
||||
0,
|
||||
Origin::new(0, 0, 0),
|
||||
Size::new(N, 1, 1),
|
||||
Size::new(n, 1, 1),
|
||||
&out,
|
||||
0,
|
||||
row,
|
||||
@@ -364,7 +373,8 @@ fn half_writes_store_their_nans_as_metal_or_announce() {
|
||||
for f in &FORMATS {
|
||||
{
|
||||
let state = kernel(device, access);
|
||||
let texels = stored(device, (&state, access), f);
|
||||
let lanes: Vec<[u16; 4]> = (0..N as usize).map(texel).collect();
|
||||
let texels = stored(device, (&state, access), f, &lanes);
|
||||
let announced = counts(&messages.take_notices());
|
||||
let properties = &device.compile_device().profile().enabled().properties;
|
||||
let keeps = properties.contains(&VkProperty::MetalHalfTexelWrites);
|
||||
@@ -421,9 +431,12 @@ fn half_writes_store_their_nans_as_metal_or_announce() {
|
||||
f.name,
|
||||
differ.len()
|
||||
);
|
||||
// The widening's note, the making's whatever texture the kernel writes,
|
||||
// stands where the device's widening is not measured to be Metal's.
|
||||
let moves = properties.contains(&VkProperty::MetalNanMoves);
|
||||
if measured {
|
||||
assert!(
|
||||
differ.is_empty() && !noted && !widened_own,
|
||||
differ.is_empty() && !noted && !(widened_own && moves),
|
||||
"{access} {}: {} lanes differ from Metal's, device-nan-encoding \
|
||||
{noted}, native-nan-encoding {widened_own}",
|
||||
f.name,
|
||||
@@ -454,3 +467,66 @@ fn half_writes_store_their_nans_as_metal_or_announce() {
|
||||
);
|
||||
eprintln!("half write NaNs: {report:#?}");
|
||||
}
|
||||
|
||||
/// Every `half` NaN (each payload of both signs: 2,046) that a kernel writes, in all four lanes of
|
||||
/// a texel, to an `RG11B10Float` storage texture through `write`, `read_write` and `held`. Metal
|
||||
/// stores each field as its canonical NaN (`0x7e0`, `0x3f0`: [`METAL_RG11B10`]'s first texel, whose
|
||||
/// lanes are all NaNs); on a device that takes `DriverDeviation::MetalSmallFloatNans` every texel
|
||||
/// is so and no write announces `device-nan-encoding`, the deviation's gate on each driver it
|
||||
/// lists. Elsewhere the texels stored otherwise are printed, and a write that stores one announces
|
||||
/// `device-nan-encoding`.
|
||||
#[test]
|
||||
fn every_half_nan_written_to_a_small_float_texture_is_metal_s_where_measured() {
|
||||
let mut nans: Vec<u16> = (0..=u16::MAX)
|
||||
.filter(|h| h & 0x7c00 == 0x7c00 && h & 0x3ff != 0)
|
||||
.collect();
|
||||
assert_eq!(nans.len(), 2046);
|
||||
// Whole threadgroups of 64, the first NaN again past the last.
|
||||
nans.resize(nans.len().div_ceil(64) * 64, nans[0]);
|
||||
let lanes: Vec<[u16; 4]> = nans.iter().map(|&h| [h; 4]).collect();
|
||||
let rg11b10f = FORMATS
|
||||
.iter()
|
||||
.find(|f| f.format == PixelFormat::RG11B10Float)
|
||||
.unwrap();
|
||||
let mut failed = Vec::new();
|
||||
on_device_with(
|
||||
|options| {
|
||||
options.announce_each.insert(Degradation::DeviceNanEncoding);
|
||||
at_plan(options)
|
||||
},
|
||||
|device, messages| {
|
||||
let properties = &device.compile_device().profile().enabled().properties;
|
||||
let measured = properties.contains(&VkProperty::MetalSmallFloatNans);
|
||||
for access in ["write", "read_write", "held"] {
|
||||
let state = kernel(device, access);
|
||||
let texels = stored(device, (&state, access), rg11b10f, &lanes);
|
||||
let noted =
|
||||
counts(&messages.take_notices()).contains_key(&Degradation::DeviceNanEncoding);
|
||||
let mut other: Vec<String> = texels
|
||||
.iter()
|
||||
.zip(&nans)
|
||||
.filter(|(words, _)| words[0] != METAL_RG11B10[0])
|
||||
.map(|(words, h)| format!("{h:04x}->{:x}", words[0]))
|
||||
.collect();
|
||||
let differ = other.len();
|
||||
other.truncate(8);
|
||||
eprintln!(
|
||||
"every half NaN {access} rg11b10f on {}: {differ} of {} texels not Metal's \
|
||||
{other:?}; MetalSmallFloatNans {measured}, device-nan-encoding {noted}",
|
||||
device.name(),
|
||||
nans.len()
|
||||
);
|
||||
if (measured && (differ > 0 || noted)) || (differ > 0 && !noted) {
|
||||
failed.push(format!(
|
||||
"{access}: {differ} texels, measured {measured}, announced {noted}"
|
||||
));
|
||||
}
|
||||
layer_reported_nothing(messages, &format!("every half NaN {access} rg11b10f"));
|
||||
}
|
||||
},
|
||||
);
|
||||
assert!(
|
||||
failed.is_empty(),
|
||||
"half NaN writes to RG11B10Float against MetalSmallFloatNans: {failed:#?}"
|
||||
);
|
||||
}
|
||||
@@ -489,7 +489,18 @@ pub(crate) fn among<F: Copy + Ord>(
|
||||
/// Metal's bytes in every texel, as the same writes do into `RGBA32Float`, `RG32Float` and
|
||||
/// `R32Float` (a `half` widened by Metal's own `float(half)`, `MetalNanMoves`). Into `R16Float`
|
||||
/// and `RGBA16Float` a `half` NaN's payload differs (the device stores `0x7e00`), which
|
||||
/// `MetalHalfTexelWrites` would state, so outside it. One row per GPU, as measured.
|
||||
/// `MetalHalfTexelWrites` would state, so outside it. One row per GPU, as measured. lavapipe
|
||||
/// (`MESA_LLVMPIPE`) packs a small float in its shader code, which writes every NaN as the
|
||||
/// field's quiet NaN with its sign dropped, Metal's: Mesa 26.2.4 on LLVM 23.1.1, x86_64 (an
|
||||
/// Ultra 9 275HX), through a kernel's `write`, `read_write`, texture buffer and argument buffer
|
||||
/// forms, stored Metal's field for each of 32,766 `float` NaNs (every pattern of the top 13
|
||||
/// payload bits, its 10 low bits clear and set, both signs) and each of the 2,046 `half` NaNs
|
||||
/// (the gate lanes
|
||||
/// `runtime_lane::half_storage_writes::every_nan_a_kernel_writes_to_a_small_float_texture_is_metal_s_where_measured`
|
||||
/// and
|
||||
/// `runtime_lane::half_write_nans::every_half_nan_written_to_a_small_float_texture_is_metal_s_where_measured`).
|
||||
/// One row, of the driver on every CPU. Measured to keep a NaN's payload bits, so not listed: RADV
|
||||
/// on the Radeon 780M and NVIDIA's 615.71.09 on the RTX 5080 Laptop GPU.
|
||||
///
|
||||
/// `MetalUnaryDenormals`: MoltenVK 1.4.2's `OpFNegate`, `FAbs`, `Floor` and `Ceil` on 32-bit
|
||||
/// floats, which SPIRV-Cross writes as Metal's `-x`, `fabs`, `floor` and `ceil`. On the M3 Max
|
||||
@@ -705,6 +716,12 @@ pub(crate) const DEVIATIONS: &[Measured<DriverDeviation>] = &[
|
||||
device: Some(APPLE9),
|
||||
..moltenvk_on_apple(DriverDeviation::MetalSmallFloatNans)
|
||||
},
|
||||
Measured {
|
||||
fact: DriverDeviation::MetalSmallFloatNans,
|
||||
driver: DriverId::MESA_LLVMPIPE,
|
||||
vendor: None,
|
||||
device: None,
|
||||
},
|
||||
Measured {
|
||||
device: Some(APPLE9),
|
||||
..moltenvk_on_apple(DriverDeviation::MetalUnaryDenormals)
|
||||
|
||||
@@ -183,7 +183,8 @@ fn taken(p: &crate::device::DeviceProfile) -> Vec<crate::error::DriverDeviation>
|
||||
/// sampler, compute cube route and the rest of the seventeen), with the graphics cube route and the
|
||||
/// per-sample depth of macOS 27's Apple9 identity, that identity's normalized
|
||||
/// storage writes, full quads, normalized vertex fetch, alpha to coverage, moved NaNs, pack conversions, half conversions, small-float NaN stores and unary denormals, and every Apple GPU's 16-bit unorm depth stores, interpolation
|
||||
/// and first-vertex indices; lavapipe's `float` color NaNs and half-float storage writes; RADV's
|
||||
/// and first-vertex indices; lavapipe's `float` color NaNs, half-float storage writes and
|
||||
/// small-float NaN stores; RADV's
|
||||
/// half-float storage writes on every GPU and its others on the Radeon 780M, ANV's on the Iris Xe
|
||||
/// of RPL-P and the UHD 770 of RPL-S, and NVIDIA's on the RTX 3090 and the RTX 5080 Laptop GPU, as
|
||||
/// measured there; the 8-bit linear filter's bound where measured. Every other committed profile
|
||||
@@ -277,7 +278,11 @@ fn the_profile_takes_the_deviations_its_driver_is_measured_with() {
|
||||
(true, _) => want_all,
|
||||
(false, "nvidia-rtx5080-laptop") => nvidia_measured.clone(),
|
||||
(false, "lavapipe" | "gate-lavapipe" | "gate-lavapipe-x86_64") => {
|
||||
vec![D::MetalFloatColorNans, D::MetalHalfStorageWrites]
|
||||
vec![
|
||||
D::MetalFloatColorNans,
|
||||
D::MetalHalfStorageWrites,
|
||||
D::MetalSmallFloatNans,
|
||||
]
|
||||
}
|
||||
// The per-sample `FragCoord.z` last, in `taken`'s order. The 780M under Phoenix's
|
||||
// `deviceID` and Hawk Point's alike.
|
||||
|
||||
@@ -964,10 +964,11 @@ pub enum PrecisionNote {
|
||||
/// plain color fill to a NaN of a half or small-float texture the device's clear writes: the
|
||||
/// device converts the NaN as it likes, where Metal's fill keeps a half NaN's sign and payload
|
||||
/// and makes a small float's all ones. Not recorded by a texture write of a constant texel none
|
||||
/// of whose lanes is a NaN, nor where the write's stored NaN is measured to be Metal's (MoltenVK
|
||||
/// on the Apple M3 Max's macOS 27 identity): a `half` texel's write to a 32-bit float format on
|
||||
/// a profile that takes `DriverDeviation::MetalNanMoves`, and a `float` or `half` texel's write
|
||||
/// to `RG11B10Float` on one that takes `DriverDeviation::MetalSmallFloatNans` (the module then
|
||||
/// of whose lanes is a NaN, nor where the write's stored NaN is measured to be Metal's: a
|
||||
/// `half` texel's write to a 32-bit float format on a profile that takes
|
||||
/// `DriverDeviation::MetalNanMoves` (MoltenVK on the Apple M3 Max's macOS 27 identity), and a
|
||||
/// `float` or `half` texel's write to `RG11B10Float` on one that takes
|
||||
/// `DriverDeviation::MetalSmallFloatNans` (that identity and lavapipe) (the module then
|
||||
/// requires the matching `VkProperty`). Validation derives no tolerance and no explanation from
|
||||
/// it, as for `DeviceDenormals`.
|
||||
DeviceNanEncoding,
|
||||
|
||||
+3
-2
@@ -3706,9 +3706,10 @@ bound.
|
||||
`DriverDeviation::MetalNanMoves` (the image stores the widened `float`'s bits, Metal's
|
||||
`0x7fc00000`; the module requires `VkProperty::MetalNanMoves`), and a `float` or `half` texel's
|
||||
write to a packed small float one (`RG11B10Float`) on a profile that takes
|
||||
`DriverDeviation::MetalSmallFloatNans`, MoltenVK on Apple's GPUs of the Apple M3 Max's macOS 27
|
||||
`DriverDeviation::MetalSmallFloatNans`: MoltenVK on Apple's GPUs of the Apple M3 Max's macOS 27
|
||||
identity, measured byte for byte against plain Metal over every `half` and 33,792 `float` words,
|
||||
16,446 NaNs among them (the module requires `VkProperty::MetalSmallFloatNans`); and a `half`
|
||||
16,446 NaNs among them, and lavapipe, whose stores of 32,766 `float` NaNs and every `half` NaN
|
||||
are Metal's canonical field NaN (the module requires `VkProperty::MetalSmallFloatNans`); and a `half`
|
||||
read, sample or gather of a texture slot bound to a 32-bit float or packed small float format
|
||||
(`RG11B10Float`, `RGB9E5Float`) on a profile that takes `DriverDeviation::MetalHalfConversion`,
|
||||
the same identity, whose `half` of such a texel is Metal's, its NaN `0x7e00` (the module
|
||||
|
||||
Reference in new issue
Block a user