Translator: a half-float or RG11B10Float texel held as words converts only values in range

lower/texture/words.rs's small_float_bits, which gives the codes of a half-float or RG11B10Float
texel a texture buffer held as words stores, computed every lane's denormal code (the lane's
value times 2^(14 + m), converted by OpConvertFToU) before a select kept it only for a denormal
lane. A normal lane of 2^(18 - m) or more (256 for a half float, 4096 for an 11-bit float, 8192
for a 10-bit one), and every infinity or NaN, reached the conversion past u32, which SPIR-V leaves
undefined; the select dropped what it gave, so no device was seen to store a wrong code, but the
module relied on an undefined operation for every such write.

Now a normal lane (an infinity and a NaN included) converts zero: the lane's magnitude bits are
selected to zero before the multiply, so every conversion takes a value below 2^m. A denormal
lane's code is unchanged, and the select still takes a normal lane's code from its exponent and
fraction. One select more per texel write.

SEMANTICS_VERSION moves above development's: the module of a write to a texture buffer held as
words changes.

Verified on the CPU with no device (job m3-max-83575): with words.rs at 16777dc811 the test
half_and_small_float_words_convert_only_values_in_range fails, the interpreter trapping
ConversionOutOfRange, and with this commit's words.rs it passes. The golden table differs from
development's (semantics 2334) in 109 cells at this commit and in 80 at 126ee4fdf5.
This commit is contained in:
Anees Iqbal committed 2026-12-03 05:55:05 -08:00
1 parent 5458510f15
commit aa2355716b
2 files changed
+9 -5

No files matched your search

+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 = 2343;
pub const SEMANTICS_VERSION: u32 = 2344;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
@@ -1487,13 +1487,17 @@ fn small_float_bits(
let normal = fb.binary(BinOp::ISub, a, rebias)?;
let down = ku4(fb, m.map(|m| 23 - m))?;
let normal = fb.binary(BinOp::ShiftRightLogical, normal, down)?;
// A denormal: the value times `2^(14 + m)`, an exact integer.
let af = fb.convert(ConvOp::Bitcast, a, fv)?;
// A denormal: the value times `2^(14 + m)`, an exact integer below `2^m`. A normal lane (an
// infinity and a NaN included) converts zero instead, since its product may be past `u32`,
// where `OpConvertFToU` is undefined; the select below drops the code it gives.
let smallest = ku4(fb, [113; 4])?;
let is_normal = fb.binary(BinOp::UGreaterThanEqual, e, smallest)?;
let none = ku4(fb, [0; 4])?;
let small = fb.select(is_normal, none, a)?;
let af = fb.convert(ConvOp::Bitcast, small, fv)?;
let scale = kf4(fb, m.map(|m| 2f32.powi(14 + m as i32)))?;
let den = fb.binary(BinOp::FMul, af, scale)?;
let den = fb.convert(ConvOp::ConvertFToU, den, uv)?;
let smallest = ku4(fb, [113; 4])?;
let is_normal = fb.binary(BinOp::UGreaterThanEqual, e, smallest)?;
let bits = fb.select(is_normal, normal, den)?;
let fraction = ku4(fb, [0x007f_ffff; 4])?;
let f = fb.binary(BinOp::BitwiseAnd, a, fraction)?;