Translator: a half vector joined from read lanes keeps their bits; 20 NaN ledger rows
The RTX 5080 Laptop's replay at2953064a1c(NVIDIA 615.71.09, job m3-max-68835) read 34 sites of attribute-format-fetches that known-gaps-rt.tsv does not list. The 29 at attribute3 (`half2 h`, read as Half or Half2) were ours. The case's inputs there are half NaNs: attribute_coding.rs's Half codes 0x7E01 and 0xFE01, at threads 9 and 10 in component 0 and 6 and 7 in component 1. Metal's recording returns every attribute3 input unchanged at all 29 leaves. The 5080 differs at as many elements as there are NaNs (2 at Half, 4 at Half2), first at a NaN (Metal 0x7e01, ours 0x7fff), and its largest difference, 32258, is 0xFE01 - 0x7FFF. That every differing element is a NaN is read from the counts, the first element and the largest difference, not from a full print. The kernel only reinterprets the fetched value (`bitcast <2 x half> to <2 x i16>`), which the module's own contract keeps as the field's bits (PrecisionNote:: NativeNanEncoding: "a `half` stored back unchanged keeps its bits"), so no note covered it. The cause: fetch::decode joins the lanes it widened with one OpCompositeConstruct. from_bits noted each lane's bits, but narrow::known_bits looked through struct members and lane inserts only, so the bitcast's to_bits found no bits for the vector and encoded it: the device's narrowing of the device's widening. On NVIDIA a half NaN widens to 0x7fffffff (attribute0's answer on all three NVIDIA cards) and narrows to 0x7fff. Mesa's widening keeps the payload and its narrowing gives it back, so the Mesa cards showed nothing; the RTX 3090 and RTX 2080 (620.70.06) showed nothing either (expected: that compiler folds the round trip; unverified). The class, at the base: three product sites join half lanes whose bits are noted with a vector construct and lose them there: the pulled fetch (fetch::decode, for a kernel's [[stage_in]], a pulled vertex attribute and a post-tessellation attribute), math::unpack_float (air.unpack of the 11/11/10 float formats into half lanes) and chunk::from_words (a chunked bitcast's half lanes), and one test-only one, the arith tests' own load of a narrow vector. Texture reads, ops::of_lanes_bits and narrow::unpacked_from_bits widen the whole vector at once and note it; lane inserts were already followed. So the fix is in known_bits, for the whole class at once: - spirv::builder records the parts of every OpCompositeConstruct of an f32 vector (ModuleBuilder::vector_parts, FunctionBuilder::vector_parts), counted in the builder's footprint. - narrow::constructed_bits: a vector constructed of parts whose bits are each known (noted, a constant's, or a lane of a vector's noted bits) has the construct of those bits. Nothing is emitted when a part's bits are unknown. known_bits tries it before the lane inserts. - SEMANTICS_VERSION 2275 -> 2276: the modules of every such vector's store or reinterpretation change (the encode becomes the construct of the known bits). The golden table is re-blessed on development. - docs/API.md's native-nan-encoding entry and NativeNanEncoding's doc name the vector join among the paths that keep a half's bits. The other 5 sites (attribute0, the `float4` widening of Half, Half2, Half3, Half4 and FloatRG11B10) are the device's own answer under device-nan-encoding, as the 3090's rows. The ledger takes each card's rows from the replays of the round at2953064a1c, named no wider than the card that ran, each row's detail equal to what the replay printed and its text the template card's whose answer it shares: - RTX 5080 Laptop GPU (job m3-max-68835): every payload bit set (0x7fffffff), as the RTX 3090. - RTX 2080 (NVIDIA 620.70.06, job m3-max-68939): the same 5 answers as the RTX 3090. - "AMD Radeon 780M Graphics (RADV PHOENIX)" (Mesa 26.2.6): the PHOENIX run (job m3-max-68941) and the HawkPoint run (job m3-max-68942) print that one venue and answer as the RX 7900 XTX: 0x7fc02000 for the halves, 0x7ffe0000 at 9 RG11B10 elements. - "AMD Radeon RX 550 / 550 Series (RADV POLARIS12)" (Mesa 26.2.6, job m3-max-68993): the same answers as the RX 7900 XTX. The 2080, 780M and RX 550 runs show no attribute3 site. docs/CONFORMANCE-COVERAGE.md regenerated (ledger rows 7968 -> 7988). Tests, each failing at the base's product code and passing with the fix: - lower::arith::tests::narrow::a_constructed_narrow_vector_keeps_its_lanes_bits (interpreter): four decoded lanes, two beside the constants 0 and 1.0, and the harness's loaded vector keep 0x7E01, 0xFE01, 0x7C01, 0xFDFF and the rest bit for bit, where the encode answers 0x7E00. - tests::engine_kernel_stage_in::a_half_attribute_reinterpreted_unchanged_encodes_no_half: stage_in_fetch with Half2 and Half at attribute 3 holds no OpFConvert to a 16-bit float and no PackHalf2x16 on any committed profile, with each half form among them (Controlled, Converted, and Device, the profiles without shaderFloat16). Verified: - This change on5f93a64342(probe 73dead9f70, tree 56642f49), compile job m3-max-69015: the two tests against 5f93a64342's product code FAIL, with the fix PASS; fmt, signatures, clippy --workspace --all-targets --all-features -D warnings plain, under --cfg m2v_gpu and under --cfg m2v_cpu_icd, and workspace Rustdoc -D warnings exit 0; the metal2vulkan and metal2vulkan-air suites: 3348 tests passed, 22 skipped, peak 11.3 GiB. - The tree at 8134bb4201 (on c38852d665; its crates/metal2vulkan/src and metal2vulkan-air equal 73dead9f70's), recheck m3-max-68965: against the base's product code the engine test reads "30 of 30 modules encode a half": every committed profile with Half2 and with Half, one OpFConvert to 16 bits each, two PackHalf2x16 each on nvidia-pascal-linux and runtime-floor (no shaderFloat16). Compile job m3-max-68956 at 9f921a841c (the same translator code): the metal2vulkan and metal2vulkan-air suites 3348 passed, 22 skipped, peak 11.9 GiB. golden_hashes_match_the_table passed at SEMANTICS 2276 in both suite runs: 0 cells of those it compares on Linux moved, so no "bless due"; the cells that need metal-as are compared at development's bless. - RTX 5080 Laptop GPU (NVIDIA 615.71.09), the conformance replay on rt: at 8134bb4201, job m3-max-68961, and at 73dead9f70, job m3-max-69047: exit 0, no unlisted site; attribute-format-fetches differs only at its listed rows (the 8-bit unsigned normalized formats' 1-ulp rows and the 5 new attribute0 rows), none of the 29 attribute3 sites differs, and "the 4607 row(s) above are exactly the open gaps known-gaps-rt.tsv expects on this venue". - States-only play on lavapipe, 9 streams, every MODE line states-only: 8134bb4201 (job m3-max-69001) againstc38852d665(job m3-max-68979). In each stream both made the same render and compute states and pipelines (gb-3090-r2: 10643 render, 15299 compute, 568 pipelines; glbench-780m-r4-recnil: 3756, 484, 498), refused 0 and left 0 unattempted. 8134bb4201's translator code equals 73dead9f70's. - Not run: the RTX 2080's, the 780M's and the RX 550's rows are as those cards' replays printed at 2953064a1c; their replays with this change are the next round's. "The RTX 3090 shows nothing at attribute3" stays unverified. The branch is rebased onto development after the jobs; the commits between5f93a64342and its base change runtime files alone (crates/metal2vulkan-runtime), none of this change's.
This commit is contained in:
1 parent
333adf36cf
commit
6adfe028d8
11 files changed
+304
-9
No files matched your search
@@ -8023,3 +8023,23 @@ attribute-format-fetches NVIDIA GeForce RTX 3090 divergent case/MTLAttributeForm
|
||||
attribute-format-fetches NVIDIA GeForce RTX 3090 divergent case/MTLAttributeFormatHalf2/attribute0/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 3090 divergent case/MTLAttributeFormatHalf3/attribute0/MTLAttributeFormatHalf3 6 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 3090 divergent case/MTLAttributeFormatHalf4/attribute0/MTLAttributeFormatHalf4 8 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 5080 Laptop GPU divergent case/MTLAttributeFormatFloatRG11B10/attribute0/MTLAttributeFormatFloatRG11B10 10 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 5080 Laptop GPU divergent case/MTLAttributeFormatHalf/attribute0/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 5080 Laptop GPU divergent case/MTLAttributeFormatHalf2/attribute0/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 5080 Laptop GPU divergent case/MTLAttributeFormatHalf3/attribute0/MTLAttributeFormatHalf3 6 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 5080 Laptop GPU divergent case/MTLAttributeFormatHalf4/attribute0/MTLAttributeFormatHalf4 8 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 2080 divergent case/MTLAttributeFormatFloatRG11B10/attribute0/MTLAttributeFormatFloatRG11B10 10 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 2080 divergent case/MTLAttributeFormatHalf/attribute0/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 2080 divergent case/MTLAttributeFormatHalf2/attribute0/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 2080 divergent case/MTLAttributeFormatHalf3/attribute0/MTLAttributeFormatHalf3 6 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches NVIDIA GeForce RTX 2080 divergent case/MTLAttributeFormatHalf4/attribute0/MTLAttributeFormatHalf4 8 elements differ (U32), the largest difference 4194303 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set where Metal reads the canonical NaN, at each NaN element Metal answers. Metal reads 0x7fc00000, the device 0x7fffffff at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon 780M Graphics (RADV PHOENIX) divergent case/MTLAttributeFormatFloatRG11B10/attribute0/MTLAttributeFormatFloatRG11B10 9 elements differ (U32), the largest difference 4063232 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7ffe0000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon 780M Graphics (RADV PHOENIX) divergent case/MTLAttributeFormatHalf/attribute0/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon 780M Graphics (RADV PHOENIX) divergent case/MTLAttributeFormatHalf2/attribute0/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon 780M Graphics (RADV PHOENIX) divergent case/MTLAttributeFormatHalf3/attribute0/MTLAttributeFormatHalf3 6 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon 780M Graphics (RADV PHOENIX) divergent case/MTLAttributeFormatHalf4/attribute0/MTLAttributeFormatHalf4 8 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon RX 550 / 550 Series (RADV POLARIS12) divergent case/MTLAttributeFormatFloatRG11B10/attribute0/MTLAttributeFormatFloatRG11B10 9 elements differ (U32), the largest difference 4063232 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7ffe0000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon RX 550 / 550 Series (RADV POLARIS12) divergent case/MTLAttributeFormatHalf/attribute0/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon RX 550 / 550 Series (RADV POLARIS12) divergent case/MTLAttributeFormatHalf2/attribute0/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon RX 550 / 550 Series (RADV POLARIS12) divergent case/MTLAttributeFormatHalf3/attribute0/MTLAttributeFormatHalf3 6 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
attribute-format-fetches AMD Radeon RX 550 / 550 Series (RADV POLARIS12) divergent case/MTLAttributeFormatHalf4/attribute0/MTLAttributeFormatHalf4 8 elements differ (U32), the largest difference 2147491840 The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal reads the canonical NaN. Metal reads 0x7fc00000, the device 0x7fc02000 at the first differing element. Note `device-nan-encoding`.
|
||||
|
Can't render this file because it is too large.
|
Vendored
+1
-1
@@ -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 = 2275;
|
||||
pub const SEMANTICS_VERSION: u32 = 2276;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
|
||||
@@ -538,10 +538,11 @@ pub fn to_bits(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult<Value
|
||||
/// The format bits of `x` (form `f`, format `fmt`) when they are known without encoding the
|
||||
/// value ([`encode`]), cleared above each lane's 16 bits: the bits `x` was decoded from
|
||||
/// ([`from_bits`] notes them) or computed with earlier in the open block, a constant's bits
|
||||
/// computed at translation time ([`constant_bits`]), or, for a vector built by lane inserts
|
||||
/// ([`note_insert`]), the inserts repeated on the lanes' known bits. A member extracted from a
|
||||
/// struct the module built from it (a texel's `{T, i8}`, `FunctionBuilder::member_source`) is
|
||||
/// that value, and has its known bits. `None` otherwise.
|
||||
/// computed at translation time ([`constant_bits`]), or, for a vector the builder constructed of
|
||||
/// parts ([`constructed_bits`]), the construct of the parts' known bits, and for a vector built
|
||||
/// by lane inserts ([`note_insert`]), the inserts repeated on the lanes' known bits. A member
|
||||
/// extracted from a struct the module built from it (a texel's `{T, i8}`,
|
||||
/// `FunctionBuilder::member_source`) is that value, and has its known bits. `None` otherwise.
|
||||
fn known_bits(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
fmt: NarrowFmt,
|
||||
@@ -559,11 +560,79 @@ fn known_bits(
|
||||
return Ok(Some(k));
|
||||
}
|
||||
if f.lanes > 1 {
|
||||
if let Some(b) = constructed_bits(fb, fmt, f, x)? {
|
||||
return Ok(Some(b));
|
||||
}
|
||||
return inserted_bits(fb, fmt, f, x);
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Where one part of a vector construct gets its bits from, for [`constructed_bits`].
|
||||
enum PartBits {
|
||||
/// Noted bits, and their dirty lanes.
|
||||
Noted(Value, u32),
|
||||
/// A constant's lanes' bits.
|
||||
Const(Vec<u64>),
|
||||
/// Lane `.2` of a vector's noted bits (dirty in the lanes `.1` has a bit for).
|
||||
Of(Value, u32, u32),
|
||||
}
|
||||
|
||||
/// The bits of vector `x` (form `f`) built by one `OpCompositeConstruct` of parts
|
||||
/// (`FunctionBuilder::vector_parts`) whose bits are each known (noted, a constant's, or a lane of
|
||||
/// a vector's noted bits): the construct of the parts' bits, so a vector the lowering joins from
|
||||
/// decoded lanes (a pulled attribute's fetch, a packed float's unpack, a chunked bitcast's lanes)
|
||||
/// keeps every lane's bits. Each lane then holds the bits of the lane `x` holds, so they are
|
||||
/// `x`'s bits. Checked before anything is emitted; `None` (nothing emitted) when a part's bits are
|
||||
/// unknown.
|
||||
fn constructed_bits(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
fmt: NarrowFmt,
|
||||
f: Form,
|
||||
x: Value,
|
||||
) -> BResult<Option<Value>> {
|
||||
let Some(parts) = fb.vector_parts(x) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let mut known = Vec::with_capacity(parts.len());
|
||||
for mut p in parts {
|
||||
while let Some(member) = fb.member_source(p) {
|
||||
p = member;
|
||||
}
|
||||
let lanes = vector_lanes(fb, p)?.unwrap_or(1);
|
||||
let part = Form { lanes, ..f };
|
||||
let bits = if let Some((b, d)) = fb.bits_of(fmt, p) {
|
||||
PartBits::Noted(b, d)
|
||||
} else if let Some(k) = constant_lanes(fb, part, p)? {
|
||||
PartBits::Const(k)
|
||||
} else if let (1, Some((w, j))) = (lanes, fb.lane_of(p)) {
|
||||
match fb.bits_of(fmt, w) {
|
||||
Some((wb, wd)) => PartBits::Of(wb, wd, j),
|
||||
None => return Ok(None),
|
||||
}
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
known.push((bits, part));
|
||||
}
|
||||
let (mut part_bits, mut dirty, mut at) = (Vec::with_capacity(known.len()), 0u32, 0u32);
|
||||
for (bits, part) in known {
|
||||
let (b, d) = match bits {
|
||||
PartBits::Noted(b, d) => (b, d),
|
||||
PartBits::Const(k) => (materialize(fb, part, &k)?, 0),
|
||||
PartBits::Of(wb, wd, j) => (fb.composite_extract(wb, &[j])?, wd >> j & 1),
|
||||
};
|
||||
let own = u32::MAX >> (32 - u32::from(part.lanes).clamp(1, 32));
|
||||
dirty |= (d & own).checked_shl(at).unwrap_or(0);
|
||||
at += u32::from(part.lanes);
|
||||
part_bits.push(b);
|
||||
}
|
||||
let t = ty(fb, u32_form(f))?;
|
||||
let rb = fb.composite_construct(t, &part_bits)?;
|
||||
fb.note_bits(fmt, x, rb, dirty, false);
|
||||
clean(fb, fmt, f, x, rb, dirty).map(Some)
|
||||
}
|
||||
|
||||
/// `bits` (the noted bits of `x`, dirty in the lanes `dirty` has a bit for) cleared above each
|
||||
/// lane's 16 bits, noted for `x` as clean in the open block.
|
||||
fn clean(
|
||||
|
||||
@@ -215,6 +215,64 @@ fn narrow_members_move_as_bits_through_structs() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A narrow vector the builder constructs of decoded lanes (`FunctionBuilder::vector_parts`), as a
|
||||
/// pulled attribute's fetch, a packed float's unpack and a chunked bitcast join them, is those
|
||||
/// lanes with their bits (`narrow::to_bits`): stored unchanged, every lane keeps its bits, a NaN's
|
||||
/// sign and payload and a signalling NaN included, through a construct of four decoded lanes, of
|
||||
/// two beside the constants `0` and `1.0` (a fetch's missing lanes), and through the parent's
|
||||
/// own load of a vector, which constructs it from its lanes. An encode of the device's widening
|
||||
/// would answer the interpreter's canonical NaN (`0x7E00`) instead.
|
||||
#[test]
|
||||
fn a_constructed_narrow_vector_keeps_its_lanes_bits() {
|
||||
let codes = [
|
||||
0x7E01u64, 0xFE01, 0x7C01, 0xFDFF, 0x7C00, 0x8000, 0x0001, 0x3C00,
|
||||
];
|
||||
let quads: Vec<Case> = (0..codes.len())
|
||||
.map(|i| (0..4).map(|k| vec![codes[(i + k) % codes.len()]]).collect())
|
||||
.collect();
|
||||
let four = |fb: &mut FunctionBuilder<'_>, x: &[Value]| -> BResult<Value> {
|
||||
let t = ops::ty(fb, vec(half(), 4))?;
|
||||
fb.composite_construct(t, x)
|
||||
};
|
||||
check_accept(
|
||||
"four decoded lanes",
|
||||
&[half(); 4],
|
||||
vec(half(), 4),
|
||||
&four,
|
||||
&quads,
|
||||
&|c| Some(c.iter().map(|lane| lane[0]).collect()),
|
||||
&|g, w| g == w,
|
||||
);
|
||||
let padded = |fb: &mut FunctionBuilder<'_>, x: &[Value]| -> BResult<Value> {
|
||||
let zero = ops::fsplat(fb, float(32), 0.0)?;
|
||||
let one = ops::fsplat(fb, float(32), 1.0)?;
|
||||
let t = ops::ty(fb, vec(half(), 4))?;
|
||||
fb.composite_construct(t, &[x[0], x[1], zero, one])
|
||||
};
|
||||
check_accept(
|
||||
"two decoded lanes and the constants 0 and 1.0",
|
||||
&[half(); 2],
|
||||
vec(half(), 4),
|
||||
&padded,
|
||||
&quads.iter().map(|c| c[..2].to_vec()).collect::<Vec<_>>(),
|
||||
&|c| Some(vec![c[0][0], c[1][0], 0, 0x3C00]),
|
||||
&|g, w| g == w,
|
||||
);
|
||||
let loaded: Vec<Case> = quads
|
||||
.iter()
|
||||
.map(|c| vec![c.iter().map(|lane| lane[0]).collect()])
|
||||
.collect();
|
||||
check_accept(
|
||||
"a loaded vector",
|
||||
&[vec(half(), 4)],
|
||||
vec(half(), 4),
|
||||
&|_, x| Ok(x[0]),
|
||||
&loaded,
|
||||
&|c| Some(c[0].clone()),
|
||||
&|g, w| g == w,
|
||||
);
|
||||
}
|
||||
|
||||
/// One half round trip through its format bits, `to_bits` then `from_bits` (their types and
|
||||
/// constants shared with the kernel's own load and store), is the device's narrowing and widening
|
||||
/// alone: at most 40 words. A load also decodes
|
||||
|
||||
@@ -1594,7 +1594,8 @@ pub enum PrecisionNote {
|
||||
/// every `half` NaN to `0x7fc00000` and moves one it does not widen with its bits, so a `half`
|
||||
/// NaN the module moves as a value (through the program's select, phi or sign operation) may
|
||||
/// leave with the device's bits; a `half` stored back unchanged keeps its bits, through a
|
||||
/// containment check or the choice among a pointer's candidate buffers too. And by every module
|
||||
/// vector the module joins from read lanes, a containment check or the choice among a
|
||||
/// pointer's candidate buffers too. And by every module
|
||||
/// that encodes a `half` to its bits where they are not the bits it was read from (a store, a
|
||||
/// reinterpretation, a texel's bits), on every device: the encode is the device's narrowing
|
||||
/// (an `OpFConvert` to 16 bits with `shaderFloat16`, `PackHalf2x16` without it), and a NaN
|
||||
|
||||
@@ -228,6 +228,22 @@ impl<'m> FunctionBuilder<'m> {
|
||||
self.m.inserts.get(&y).copied()
|
||||
}
|
||||
|
||||
/// Record that vector `y`, of `f32` lanes, is the construct of `parts`
|
||||
/// ([`FunctionBuilder::vector_parts`]).
|
||||
pub(super) fn note_vector_parts(&mut self, y: Value, parts: &[Value]) {
|
||||
self.m.vector_part_bytes = self
|
||||
.m
|
||||
.vector_part_bytes
|
||||
.saturating_add(std::mem::size_of_val(parts));
|
||||
self.m.vector_parts.insert(y, parts.into());
|
||||
}
|
||||
|
||||
/// The parts, scalars or vectors, of `f32` vector `y` where the builder made it by
|
||||
/// `OpCompositeConstruct`, in lane order: each dominates `y`.
|
||||
pub fn vector_parts(&self, y: Value) -> Option<Vec<Value>> {
|
||||
self.m.vector_parts.get(&y).map(|parts| parts.to_vec())
|
||||
}
|
||||
|
||||
/// Record how struct `y` holds its members, or which member of a struct it reads
|
||||
/// ([`FunctionBuilder::member_source`]).
|
||||
pub(super) fn note_struct(&mut self, y: Value, op: StructOp) {
|
||||
|
||||
@@ -111,6 +111,13 @@ pub struct ModuleBuilder {
|
||||
/// The vector, lane value, and lane index of each narrow lane insert the lowering noted
|
||||
/// (`FunctionBuilder::note_insert`).
|
||||
pub(super) inserts: HashMap<Value, (Value, Value, u32)>,
|
||||
/// The parts of each `OpCompositeConstruct` of a vector of `f32` lanes, the type a narrow
|
||||
/// float is held in, by result (`FunctionBuilder::vector_parts`), so a narrow vector's bits
|
||||
/// can be read from its parts' (`lower::arith::narrow::to_bits`). Nothing here changes the IR.
|
||||
pub(super) vector_parts: HashMap<Value, Box<[Value]>>,
|
||||
/// The heap bytes of [`ModuleBuilder::vector_parts`]' part lists, for
|
||||
/// [`ModuleBuilder::footprint`].
|
||||
pub(super) vector_part_bytes: usize,
|
||||
/// The value and constant each 32-bit unsigned sum of a value and a constant the lowering
|
||||
/// noted adds (`FunctionBuilder::note_sum`). Nothing here changes the IR.
|
||||
pub(super) sums: HashMap<Value, (Value, u32)>,
|
||||
@@ -325,6 +332,8 @@ impl ModuleBuilder {
|
||||
+ map_bytes(&self.bits)
|
||||
+ map_bytes(&self.lanes)
|
||||
+ map_bytes(&self.inserts)
|
||||
+ map_bytes(&self.vector_parts)
|
||||
+ self.vector_part_bytes
|
||||
+ map_bytes(&self.sums)
|
||||
+ map_bytes(&self.structs)
|
||||
+ self.struct_bytes
|
||||
|
||||
@@ -23,6 +23,12 @@ impl FunctionBuilder<'_> {
|
||||
}
|
||||
let ty_def = self.mb().types().get(ty)?.clone();
|
||||
let is_struct = matches!(ty_def, Type::Struct { .. });
|
||||
let f32_lanes = match ty_def {
|
||||
Type::Vector { elem, .. } => {
|
||||
matches!(self.mb().types().get(elem)?, Type::Float { width: 32 })
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
let expected: Vec<TypeId> = match ty_def {
|
||||
Type::Vector { elem, len } => {
|
||||
if parts.len() < 2 {
|
||||
@@ -72,6 +78,8 @@ impl FunctionBuilder<'_> {
|
||||
)?;
|
||||
if is_struct {
|
||||
self.note_struct(y, StructOp::Construct(parts.into()));
|
||||
} else if f32_lanes {
|
||||
self.note_vector_parts(y, parts);
|
||||
}
|
||||
Ok(y)
|
||||
}
|
||||
|
||||
@@ -588,3 +588,95 @@ fn a_step_by_thread_position_records_the_region() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A `half` attribute read into the kernel's `half2` and reinterpreted unchanged keeps the field's
|
||||
/// own bits, as Metal's fetch does: `stage_in_fetch`'s `as_type<ushort>(in.h.x)` and `.y` reuse
|
||||
/// the bits the fetch widened, through the vector the fetch constructs of its lanes
|
||||
/// (`narrow::to_bits`), so its module encodes no `half` (no `OpFConvert` to a 16-bit float, no
|
||||
/// `PackHalf2x16`) on any committed profile, with the attribute's format `Half2` (both lanes read)
|
||||
/// or `Half` (the second lane missing, `0`). An encode there narrows the device's widening of a
|
||||
/// NaN field to the device's NaN: the RTX 5080 Laptop read `0x7E01` and `0xFE01` as `0x7FFF`
|
||||
/// (job m3-max-68835).
|
||||
#[test]
|
||||
fn a_half_attribute_reinterpreted_unchanged_encodes_no_half() {
|
||||
use crate::lower::arith::narrow::quantize_form;
|
||||
let Some(bc) = fixture() else { return };
|
||||
let (mut compiled, mut encoding) = (Vec::new(), Vec::new());
|
||||
for format in [AttributeFormat::Half2, AttributeFormat::Half] {
|
||||
let mut d = fetch_descriptor(
|
||||
(StepFunction::ThreadPositionInGridX, 1),
|
||||
(StepFunction::ThreadPositionInGridY, 1),
|
||||
IndexType::UInt16,
|
||||
);
|
||||
d.attributes
|
||||
.insert(3, StageInputAttributeDescriptor::new(format, 16, 1));
|
||||
for (stem, p) in committed_profiles().expect("profiles") {
|
||||
let consts = FunctionConstantValues::defaults();
|
||||
let a = match compile_bitcode(
|
||||
&bc,
|
||||
EntryRef::Name("stage_in_fetch"),
|
||||
&consts,
|
||||
&p,
|
||||
&inputs(&d),
|
||||
&mut meter(),
|
||||
SPIRV_WORDS,
|
||||
) {
|
||||
Ok(a) => a,
|
||||
Err(Error::Unsupported(u)) if u.needs != Needs::NotImplemented => continue,
|
||||
Err(e) => panic!("{stem} {format:?}: {e}"),
|
||||
};
|
||||
let encodes = half_encodes(&a.module.words);
|
||||
if encodes > 0 {
|
||||
encoding.push((stem.clone(), format, encodes));
|
||||
}
|
||||
compiled.push((stem, format, quantize_form(&p)));
|
||||
}
|
||||
}
|
||||
// Each `half` form of the profiles is among the modules: with `shaderFloat16` under the float
|
||||
// controls and without them, and without it.
|
||||
let forms: std::collections::BTreeSet<_> =
|
||||
compiled.iter().map(|(_, _, q)| format!("{q:?}")).collect();
|
||||
assert_eq!(forms.len(), 3, "a profile of each form: {compiled:?}");
|
||||
assert!(
|
||||
encoding.is_empty(),
|
||||
"{} of {} modules encode a half: {encoding:?}",
|
||||
encoding.len(),
|
||||
compiled.len()
|
||||
);
|
||||
}
|
||||
|
||||
/// The module's encodes of a `half` to its bits by the device: its `OpFConvert`s to a 16-bit
|
||||
/// float (or a vector of them) and its `GLSL.std.450 PackHalf2x16`s.
|
||||
fn half_encodes(words: &[u32]) -> usize {
|
||||
use crate::spirv::ir::GlslOp;
|
||||
use crate::spirv_binary::{parse_bytes, Operand};
|
||||
use crate::spv::Op;
|
||||
let bytes: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
|
||||
let parsed = parse_bytes(&bytes).expect("parse");
|
||||
let id = |o: Option<&Operand>| match o {
|
||||
Some(Operand::Word(w) | Operand::IdRef(w)) => Some(*w),
|
||||
_ => None,
|
||||
};
|
||||
let pack = GlslOp::PackHalf2x16.to_spirv() as u32;
|
||||
let mut halves = std::collections::HashSet::new();
|
||||
let mut encodes = 0;
|
||||
for i in &parsed.instructions {
|
||||
match i.opcode {
|
||||
Op::TypeFloat if id(i.operands.first()) == Some(16) => halves.extend(i.result_id),
|
||||
Op::TypeVector if id(i.operands.first()).is_some_and(|e| halves.contains(&e)) => {
|
||||
halves.extend(i.result_id)
|
||||
}
|
||||
Op::FConvert if i.result_type.is_some_and(|t| halves.contains(&t)) => encodes += 1,
|
||||
Op::ExtInst
|
||||
if matches!(
|
||||
i.operands.get(1),
|
||||
Some(Operand::LiteralExtInstInteger(n)) if *n == pack
|
||||
) =>
|
||||
{
|
||||
encodes += 1
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
encodes
|
||||
}
|
||||
+4
-2
@@ -2202,8 +2202,10 @@ bound.
|
||||
the device's, where Metal widens every `half` NaN to `0x7fc00000` and moves one it does not
|
||||
widen with its bits. And wherever a `half` is encoded to its bits (a store, a reinterpretation, a
|
||||
texel's bits) where they are not the bits it was read from (a `half` moved unchanged from its
|
||||
read keeps them, through a struct's member, a containment check and the choice among a
|
||||
pointer's candidate buffers too), on every device, since the encode is
|
||||
read keeps them, through a struct's member, a vector the translation joins from read lanes (a
|
||||
stage-in or pulled vertex attribute's fetch, a packed float's unpack, a bitcast's lanes), a
|
||||
containment check and the choice among a pointer's candidate buffers too), on every device,
|
||||
since the encode is
|
||||
the device's narrowing (its conversion with `shaderFloat16`, `PackHalf2x16` without): a NaN's
|
||||
bits the device's, where Metal keeps a `half` NaN's sign and payload. And wherever the entry
|
||||
reaches a `float` constant whose bits are a signalling NaN (every exponent bit set, the quiet bit
|
||||
|
||||
@@ -42,7 +42,7 @@ Its limits, measured rather than asserted:
|
||||
| committed recordings | 1325 |
|
||||
| distinct SDK items the Metal leg reaches, of any status | 808 |
|
||||
| of those, reached only where this cannot name the family | 5 |
|
||||
| ledger rows (a case whose gap is recorded) | 7968 |
|
||||
| ledger rows (a case whose gap is recorded) | 7988 |
|
||||
| declared crossings of the option space (pairs put to Metal at once) | 26 |
|
||||
| declared crossings that are no pair of it (a boolean or numeric field, or one type in two slots) | 30 |
|
||||
|
||||
@@ -10032,4 +10032,24 @@ A case whose difference from Metal is recorded rather than compared away. The le
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device reads with every payload bit set… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
| `attribute-format-fetches` | The device's own answer (rule 1): a NaN of a `half` or `RG11B10` stage-in attribute widened by the shader's fetch on the device keeps its payload where Metal re… |
|
||||
|
||||
Reference in new issue
Block a user