A float write through an argument buffer notes the half-float and small-float NaN only where the heap can name such a texture

What: lower::texture::stored_where gave a heap element one clause of no test, so a
`float` texel's write through an argument buffer recorded DeviceNanEncoding (and,
off MetalHalfStorageWrites, DeviceColorConversion) unconditionally, whatever the
command made resident. It now gives the clause the family the caller asks about:
may_store_half the 16-bit float family (bind::heap::NAN_SIXTEEN), small_float_storage
the packed small float one (NAN_SMALL), tested on SpecKey::HeapNanFamilies, which
the runtime reads at each draw or dispatch, as a `half` write's heap note already
does (half_write_nans). SEMANTICS_VERSION 2021: the notes change under unchanged
keys on every profile without MetalHalfStorageNans.

Why: with lavapipe's MetalSmallFloatNans row, runtime_lane::half_storage_writes::
every_nan_a_kernel_writes_to_a_small_float_texture_is_metal_s_where_measured failed
on lavapipe (gem10, Mesa 26.2.6, LLVM 23.1.4) in its argument-buffer form alone:
every one of 98,298 NaN fields was Metal's, yet the dispatch, whose only resident
texture is RG11B10Float, announced device-nan-encoding for the half-float family
the heap might have held. The same over-note as the reported one, through the
argument buffer's float write.

Test that fails without it: tests::engine_handles::a_heap_texel_write_is_the_devices_write
now requires a float texel's DeviceNanEncoding to hold only under HeapNanFamilies
clauses of NAN_SIXTEEN (profile without MetalHalfStorageNans) and NAN_SMALL (without
MetalSmallFloatNans); and the lane above on lavapipe.
This commit is contained in:
Anees Iqbal committed 2026-11-11 01:30:36 -08:00
1 parent f9d09e715d
commit 7aefa49b7f
6 files changed
+71 -27

No files matched your search

+3 -1
View File
@@ -324,7 +324,9 @@ pub(crate) const HELD: u32 = 1;
pub(crate) const FILTERED: u32 = 2;
/// The bit of `SpecKey::HeapNanFamilies` of a 16-bit float format: its written `half` NaN is
/// Metal's on a device of `DriverDeviation::MetalHalfTexelWrites`.
/// Metal's on a device of `DriverDeviation::MetalHalfTexelWrites`, a written `float`'s NaN on one of
/// `DriverDeviation::MetalHalfStorageNans` and its rounding on one of
/// `DriverDeviation::MetalHalfStorageWrites`.
pub(crate) const NAN_SIXTEEN: u32 = 1;
/// The bit of `SpecKey::HeapNanFamilies` of a 32-bit float format: its written `half` NaN is
+1 -1
View File
@@ -377,7 +377,7 @@ fn heap_raw(
/// The `SpecKey::HeapNanFamilies` of `stage` for `shape`: the bit of each family
/// (`bind::heap::nan_family`) of the heap members of `shape` that reach `stage` (as for
/// [`heap_ycbcr`]), whose texels a stage's `half` write may store a NaN in.
/// [`heap_ycbcr`]), whose texels a stage's `half` or `float` write may store a NaN in.
fn heap_nan_families(
shape: &BindShape,
stage: Stage,
+1 -1
View File
@@ -60,7 +60,7 @@ mod tests;
/// unchanged version, and its bless records the version. Independent of the crate's version and of
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
/// history.
pub const SEMANTICS_VERSION: u32 = 2022;
pub const SEMANTICS_VERSION: u32 = 2023;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+29 -16
View File
@@ -2185,8 +2185,9 @@ pub const HEAP_CLASS_CENSUS: &str = "sampler.heap.texel_class";
/// another NaN's payload bits; a device of `DriverDeviation::MetalSmallFloatNans` stores Metal's
/// (the module requires its property). A texel that holds no NaN (`nans` false: a constant none
/// of whose lanes is one) records neither NaN's note. A slot declared without a format records each
/// note under the format bound there (`m` charged for the clauses), which the runtime announces at
/// a draw or dispatch that binds such a texture.
/// note under the format bound there, and a heap element under the families of the textures the
/// stage's handles can name (`SpecKey::HeapNanFamilies`) (`m` charged for the clauses), which the
/// runtime announces at a draw or dispatch that binds or makes resident such a texture.
pub(super) fn half_storage_facts(
cx: &mut SelectCx<'_>,
image: ImageRef,
@@ -2246,9 +2247,10 @@ pub(super) fn half_storage_facts(
/// Where a write to texture `image` may store into a packed small float format (`RG11B10Float`;
/// `RGB9E5Float` is written through its word alias, whose word is Metal's), as the clauses of
/// [`stored_where`]: a heap element's, whose handle may name one, a slot's whose storage choice
/// declares one, and a slot's declared without a format where the texture bound there is of the
/// small floats' class (`metal::texel_format::PackedTexels::SmallFloat`).
/// [`stored_where`]: a heap element's where the stage's handles can name one
/// (`bind::heap::NAN_SMALL`), a slot's whose storage choice declares one, and a slot's declared
/// without a format where the texture bound there is of the small floats' class
/// (`metal::texel_format::PackedTexels::SmallFloat`).
fn small_float_storage(cx: &SelectCx<'_>, image: ImageRef) -> Result<Vec<NoteClause>, Error> {
use crate::metal::texel_format::{PackedTexels, TexelFormat};
let small = PackedTexels::SmallFloat.class().0;
@@ -2257,24 +2259,33 @@ fn small_float_storage(cx: &SelectCx<'_>, image: ImageRef) -> Result<Vec<NoteCla
image,
|f| f == crate::vk::Format::B10G11R11_UFLOAT_PACK32,
|index| NoteTest::equal(NoteOn::Bound(index), TexelFormat::PACKED_MASK, small),
crate::bind::heap::NAN_SMALL,
)
}
/// Where a write to texture `image` left to the device's conversion stores into a format
/// `declared` accepts, as clauses for [`SelectCx::note_when`]: always (one clause of no test) for
/// a heap element, whose handle may name any format; for a slot whose storage choice declares a
/// format, always where `declared` accepts it, else never (no clause); and for a slot declared
/// without a format (a formatless choice, or a variant that states no choice, which
/// `slot::storage_format` declares formatless), where the format bound there passes `bound`'s
/// test of its class (`NoteOn::Bound`), which the runtime reads at each draw or dispatch.
/// `declared` accepts, as clauses for [`SelectCx::note_when`]: for a heap element, whose handle
/// may name any format, where the stage's handles can name a texture of the heap NaN family
/// `family` (`SpecKey::HeapNanFamilies`, `bind::heap::nan_family`: the formats `declared` and
/// `bound` accept); for a slot whose storage choice declares a format, always where `declared`
/// accepts it, else never (no clause); and for a slot declared without a format (a formatless
/// choice, or a variant that states no choice, which `slot::storage_format` declares formatless),
/// where the format bound there passes `bound`'s test of its class (`NoteOn::Bound`). The runtime
/// reads a heap's or a bound format's clause at each draw or dispatch.
fn stored_where(
cx: &SelectCx<'_>,
image: ImageRef,
declared: impl Fn(crate::vk::Format) -> bool,
bound: impl Fn(u32) -> NoteTest,
family: u32,
) -> Result<Vec<NoteClause>, Error> {
let ImageRef::Slot(index) = image else {
return Ok(vec![NoteClause::new()]);
return Ok(vec![[NoteTest::equal(
NoteOn::HeapNan(cx.stage),
family,
family,
)]
.into()]);
};
let slot = slot_of(cx, index)?.slot;
Ok(
@@ -2763,10 +2774,11 @@ fn mode_rounded_write(
}
/// Where a write to `image` left to the device's conversion may store a half-float texel, as the
/// clauses of [`stored_where`]: a heap element's may, a slot's whose storage choice declares a
/// half-float format does, and a slot's declared without a format does where the texture bound
/// there is of a half-float class (`BicubicTexels::HALF` without a packed field, which the small
/// floats' class carries).
/// clauses of [`stored_where`]: a heap element's where the stage's handles can name a 16-bit float
/// texture (`bind::heap::NAN_SIXTEEN`), a slot's whose storage choice declares a half-float format
/// does, and a slot's declared without a format does where the texture bound there is of a
/// half-float class (`BicubicTexels::HALF` without a packed field, which the small floats' class
/// carries).
fn may_store_half(cx: &SelectCx<'_>, image: ImageRef) -> Result<Vec<NoteClause>, Error> {
use crate::metal::bicubic::BicubicTexels;
use crate::metal::texel_format::TexelFormat;
@@ -2777,6 +2789,7 @@ fn may_store_half(cx: &SelectCx<'_>, image: ImageRef) -> Result<Vec<NoteClause>,
image,
|f| matches!(f, F::R16_SFLOAT | F::R16G16_SFLOAT | F::R16G16B16A16_SFLOAT),
|index| NoteTest::equal(NoteOn::Bound(index), mask, BicubicTexels::HALF),
crate::bind::heap::NAN_SIXTEEN,
)
}
@@ -1776,10 +1776,12 @@ declare void @air.write_texture_2d.{elem}(ptr addrspace(1), <2 x i32>, {ty}, i32
/// packed small float texture, whose stored NaN is the device's; but for a `float` texel on a
/// profile whose stores of a `float` NaN into the half-float and the packed small float formats
/// are measured to be Metal's (`DriverDeviation::MetalHalfStorageNans` and
/// `DriverDeviation::MetalSmallFloatNans`: MoltenVK on the M3 Max's identity). A `half` texel's
/// note holds under the families the heap can name (`SpecKey::HeapNanFamilies`, held in
/// `tests::engine_extended_range::heap`). Either texel requires `VkProperty::MetalSmallFloatNans`
/// where the profile takes `DriverDeviation::MetalSmallFloatNans`.
/// `DriverDeviation::MetalSmallFloatNans`: MoltenVK on the M3 Max's identity). Either texel's note
/// holds under the families the heap can name (`SpecKey::HeapNanFamilies`; a `half` texel's held
/// in `tests::engine_extended_range::heap`), never whatever the heap holds: a `float` texel's under
/// a 16-bit float texture's where the profile lacks `MetalHalfStorageNans` and a packed small
/// float one's where it lacks `MetalSmallFloatNans`. Either texel requires
/// `VkProperty::MetalSmallFloatNans` where the profile takes `DriverDeviation::MetalSmallFloatNans`.
#[test]
fn a_heap_texel_write_is_the_devices_write() {
for float in [false, true] {
@@ -1813,6 +1815,32 @@ fn a_heap_texel_write_is_the_devices_write() {
"{what}: {:?}",
a.precision
);
if float && !metal_s {
use crate::bind::heap::{NAN_SIXTEEN, NAN_SMALL};
let halves = !takes(crate::error::DriverDeviation::MetalHalfStorageNans);
let mut families: Vec<u32> = a
.specialized
.iter()
.filter(|n| n.note == PrecisionNote::DeviceNanEncoding)
.flat_map(|n| &n.when)
.map(|c| match c.all.as_slice() {
[t] if t.key
== crate::pipeline::sym::SpecKey::HeapNanFamilies(Stage::Kernel)
&& t.equal
&& t.bits == t.mask =>
{
t.mask
}
other => panic!("{what}: a clause of the heap's NaN note: {other:?}"),
})
.collect();
families.sort_unstable();
let mut want = Vec::new();
want.extend(halves.then_some(NAN_SIXTEEN));
want.extend((!small).then_some(NAN_SMALL));
want.sort_unstable();
assert_eq!(families, want, "{what}: {:?}", a.specialized);
}
assert_eq!(
a.requirements
.properties
+5 -4
View File
@@ -3696,10 +3696,11 @@ bound.
a fragment function computes into a 16-bit float attachment through the pixel interlock: a NaN
of the blend is the device's arithmetic's, which the storage image's store converts, where Metal
stores every NaN of the blend as `0x7e00`. A texture write records it where the stored NaN is the
device's: a constant texel none of whose lanes is a NaN records nothing, and a `half` write
through an argument buffer is announced only at a draw or dispatch whose command can name a
texture of a format family whose stored NaN is the device's (on MoltenVK on the Apple M3 Max,
a 16-bit float one; a 32-bit float or `RG11B10Float` one stores Metal's). So does a fragment
device's: a constant texel none of whose lanes is a NaN records nothing, and a `half` or
`float` write through an argument buffer is announced only at a draw or dispatch whose command
can name a texture of a format family whose stored NaN is the device's (for a `half` write on
MoltenVK on the Apple M3 Max, a 16-bit float one; a 32-bit float or `RG11B10Float` one stores
Metal's; for a `float` write, a 16-bit float or `RG11B10Float` one). So does a fragment
function's color output where the device's conversion stores its NaN, but one every return of
which holds such a constant records nothing. **Exempt:** a `half`
texel's write to a 32-bit float storage image on a profile that takes